Browse Source

Started work on basic JavaFX implementation, also got some scala included to create the prerequisite folder in src.

master
Drew Short 11 years ago
parent
commit
4308b163d8
  1. 5
      pom.xml
  2. 39
      src/main/java/com/sothr/imagetools/App.java
  3. 13
      src/main/java/com/sothr/imagetools/errors/ImageToolsException.java
  4. 11
      src/main/resources/fxml/mainapp/MainApp.fxml
  5. 19
      src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

5
pom.xml

@ -51,11 +51,6 @@
<artifactId>scala-library</artifactId>
<version>${lib.scala-library.version}</version>
</dependency>
<dependency>
<groupId>org.scalafx</groupId>
<artifactId>scalafx_2.10</artifactId>
<version>${lib.scalafx.version}</version>
</dependency>
</dependencies>
<build>

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

@ -1,23 +1,34 @@
package com.sothr.imagetools;
import com.sothr.imagetools.errors.ImageToolsException;
import com.sothr.imagetools.ui.controller.AppController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
/**
* Hello world!
*
*/
public class App
public class App extends Application
{
private static Logger logger = LoggerFactory.getLogger(App.class);
private static final String MAINGUI_FXML = "fxml/mainapp/MainApp.fxml";
public static void main( String[] args )
{
//Logging Config
File file = new File("log4j.properties");
if (file.exists()) {
PropertyConfigurator.configure("log4j.properties");
@ -38,7 +49,8 @@ public class App
logger.info("Image-Tools is starting");
try {
System.out.println( "Hello World!" );
//try to run the UI
launch(args);
} catch (Exception ex) {
logger.error("A fatal error has occurred: ", ex);
//show popup about the error to the user then exit
@ -46,4 +58,27 @@ public class App
logger.info("Image-Tools is shutting down");
}
@Override
public void start(Stage primaryStage) throws Exception {
logger.info(String.format("Launching GUI with FXML file %s", MAINGUI_FXML));
ClassLoader cl = this.getClass().getClassLoader();
try {
Parent root = FXMLLoader.load(cl.getResource(MAINGUI_FXML));
primaryStage.setScene(new Scene(root));
primaryStage.setTitle("Image Tools");
primaryStage.setResizable(true);
primaryStage.show();
} catch (IOException ioe) {
String message = String.format("Unable to load FXML file: %s", MAINGUI_FXML);
ImageToolsException ite = new ImageToolsException(message, ioe);
logger.error(message, ioe);
throw ite;
} catch (Exception ex) {
String message = "An unhandled exception was thrown by the GUI";
ImageToolsException ite = new ImageToolsException(message, ex);
logger.error(message, ex);
throw ite;
}
}
}

13
src/main/java/com/sothr/imagetools/errors/ImageToolsException.java

@ -0,0 +1,13 @@
package com.sothr.imagetools.errors;
/**
* Created by drew on 12/31/13.
*/
public class ImageToolsException extends Exception {
public ImageToolsException() { super(); }
public ImageToolsException(String message) { super(message); }
public ImageToolsException(String message, Throwable cause) { super(message, cause); }
public ImageToolsException(Throwable cause) { super(cause); }
}

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

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import javafx.scene.control.*?>
<?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>

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

@ -0,0 +1,19 @@
package com.sothr.imagetools.ui.controller
import javafx.fxml.Initializable
import java.net.URL
import java.util.ResourceBundle
/**
* Created by drew on 12/31/13.
*/
class AppController extends Initializable {
def print():String = {
return "This method works";
}
def initialize(p1: URL, p2: ResourceBundle): Unit = {
}
}
Loading…
Cancel
Save