Browse Source
Working basic interface with menubar partially implemented. Next step, include simple cli and cli flags for running without creating gui
master
Working basic interface with menubar partially implemented. Next step, include simple cli and cli flags for running without creating gui
master
Drew Short
11 years ago
4 changed files with 82 additions and 13 deletions
-
4src/main/java/com/sothr/imagetools/App.java
-
3src/main/resources/documents/about
-
30src/main/resources/fxml/mainapp/MainApp.fxml
-
58src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala
@ -0,0 +1,3 @@ |
|||||
|
This is a simple about script. It demonstrates loading the about text from a file. |
||||
|
|
||||
|
It supports simple text, and nothing fancy. |
@ -1,11 +1,27 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||
<?language javascript?> |
|
||||
|
|
||||
|
<?import java.lang.*?> |
||||
<?import javafx.scene.control.*?> |
<?import javafx.scene.control.*?> |
||||
<?import javafx.scene.layout.*?> |
<?import javafx.scene.layout.*?> |
||||
|
|
||||
<StackPane fx:id="root" xmlns:fx="http://javafx.com/fxml" fx:controller="com.sothr.imagetools.ui.controller.AppController"> |
|
||||
<children> |
|
||||
<Button fx:id="printBtn" onAction="controller.print()" /> |
|
||||
<fx:script>printBtn.text = 'Click Me ' + controller.print() + '!';</fx:script> |
|
||||
</children> |
|
||||
</StackPane> |
|
||||
|
<AnchorPane minHeight="-Infinity" minWidth="0.0" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sothr.imagetools.ui.controller.AppController"> |
||||
|
<children><MenuBar fx:id="rootMenuBar" minWidth="-Infinity" prefHeight="29.0" prefWidth="600.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml"> |
||||
|
<menus> |
||||
|
<Menu mnemonicParsing="false" text="File"> |
||||
|
<items> |
||||
|
<MenuItem fx:id="" mnemonicParsing="false" onAction="#closeAction" text="Close" /> |
||||
|
</items> |
||||
|
</Menu> |
||||
|
<Menu mnemonicParsing="false" text="Edit"> |
||||
|
<items> |
||||
|
<MenuItem mnemonicParsing="false" text="Delete" /> |
||||
|
</items> |
||||
|
</Menu> |
||||
|
<Menu mnemonicParsing="false" text="Help"> |
||||
|
<items> |
||||
|
<MenuItem mnemonicParsing="false" onAction="#aboutAction" text="About" /> |
||||
|
</items> |
||||
|
</Menu> |
||||
|
</menus> |
||||
|
</MenuBar> |
||||
|
</children></AnchorPane> |
@ -1,19 +1,65 @@ |
|||||
package com.sothr.imagetools.ui.controller |
package com.sothr.imagetools.ui.controller |
||||
|
|
||||
import javafx.fxml.Initializable |
|
||||
|
import javafx.fxml.FXML |
||||
|
import javafx.event.ActionEvent |
||||
|
import org.slf4j.LoggerFactory |
||||
|
import org.slf4j.Logger |
||||
|
import javafx.stage.{StageStyle, Stage} |
||||
|
import javafx.scene.Scene |
||||
|
import javafx.scene.Group |
||||
|
import javafx.scene.text.Text |
||||
|
import java.io.{IOException, File} |
||||
import java.net.URL |
import java.net.URL |
||||
import java.util.ResourceBundle |
|
||||
|
import java.util.Scanner |
||||
|
|
||||
/** |
/** |
||||
* Created by drew on 12/31/13. |
* Created by drew on 12/31/13. |
||||
*/ |
*/ |
||||
class AppController extends Initializable { |
|
||||
|
class AppController { |
||||
|
|
||||
def print():String = { |
|
||||
return "This method works"; |
|
||||
|
val logger:Logger = LoggerFactory.getLogger(this.getClass) |
||||
|
|
||||
|
//Define controls |
||||
|
@FXML var rootMenuBar : javafx.scene.control.MenuBar = null |
||||
|
|
||||
|
//region MenuItem Actions |
||||
|
|
||||
|
@FXML |
||||
|
def aboutAction(event:ActionEvent) = { |
||||
|
logger.debug("Displaying about screen") |
||||
|
var aboutMessage = "Simple About Message" |
||||
|
try { |
||||
|
val cl = this.getClass.getClassLoader |
||||
|
val url = cl.getResource("documents/about") |
||||
|
val uri = url.toURI |
||||
|
aboutMessage = new Scanner(new File(uri)).useDelimiter("\\A").next() |
||||
|
} catch { |
||||
|
case ioe:IOException => |
||||
|
logger.error("Unable to read about file") |
||||
} |
} |
||||
|
|
||||
def initialize(p1: URL, p2: ResourceBundle): Unit = { |
|
||||
|
val dialog:Stage = new Stage() |
||||
|
dialog.initStyle(StageStyle.UTILITY) |
||||
|
val parent:Group = new Group(); |
||||
|
parent.getChildren.add(new Text(25, 25, aboutMessage)) |
||||
|
val scene:Scene = new Scene(parent) |
||||
|
dialog.setScene(scene) |
||||
|
dialog.setResizable(false) |
||||
|
dialog.setMinHeight(400.0) |
||||
|
dialog.setMinWidth(400.0) |
||||
|
dialog.show() |
||||
|
} |
||||
|
|
||||
|
@FXML |
||||
|
def closeAction(event:ActionEvent ) = { |
||||
|
logger.debug("Closing application from the menu bar") |
||||
|
val stage:Stage = this.rootMenuBar.getScene.getWindow.asInstanceOf[Stage] |
||||
|
stage.close() |
||||
|
} |
||||
|
|
||||
|
//endregion |
||||
|
|
||||
|
def print():String = { |
||||
|
return "This method works" |
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue