Browse Source

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
parent
commit
91de82f020
  1. 4
      src/main/java/com/sothr/imagetools/App.java
  2. 3
      src/main/resources/documents/about
  3. 30
      src/main/resources/fxml/mainapp/MainApp.fxml
  4. 58
      src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

4
src/main/java/com/sothr/imagetools/App.java

@ -66,8 +66,12 @@ public class App extends Application
try { try {
Parent root = FXMLLoader.load(cl.getResource(MAINGUI_FXML)); Parent root = FXMLLoader.load(cl.getResource(MAINGUI_FXML));
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
//config main scene
primaryStage.setTitle("Image Tools"); primaryStage.setTitle("Image Tools");
primaryStage.setMinHeight(600.0);
primaryStage.setMinWidth(800.0);
primaryStage.setResizable(true); primaryStage.setResizable(true);
//show main scene
primaryStage.show(); primaryStage.show();
} catch (IOException ioe) { } catch (IOException ioe) {
String message = String.format("Unable to load FXML file: %s", MAINGUI_FXML); String message = String.format("Unable to load FXML file: %s", MAINGUI_FXML);

3
src/main/resources/documents/about

@ -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.

30
src/main/resources/fxml/mainapp/MainApp.fxml

@ -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>

58
src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

@ -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"
} }
} }
Loading…
Cancel
Save