From 632fc5ddfd1f69f72a4b18ee71c7f14947072367 Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Fri, 31 Oct 2014 18:01:39 +0100
Subject: [PATCH] Maven prototype

---
 .../maven-prototype-javafx/.gitignore         |   5 +
 .../Archetypes/maven-prototype-javafx/pom.xml | 103 ++++++++++++++++++
 .../hdm_stuttgart/mi/sda2/account/Conf.java   |  21 ++++
 .../mi/sda2/account/GuiDriver.java            |  97 +++++++++++++++++
 .../mi/sda2/account/GuiHelper/Dialog.java     |  79 ++++++++++++++
 .../sda2/account/GuiHelper/NumberField.java   |  37 +++++++
 .../mi/sda2/account/config.properties         |   2 +
 .../src/main/resources/log4j.properties       |  15 +++
 .../mi/sda2/account/SimpleTest.java           |  15 +++
 9 files changed, 374 insertions(+)
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/.gitignore
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/pom.xml
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/Conf.java
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiDriver.java
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/Dialog.java
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/NumberField.java
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/de/hdm_stuttgart/mi/sda2/account/config.properties
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/log4j.properties
 create mode 100644 Sd1/P/Archetypes/maven-prototype-javafx/src/test/java/de/hdm_stuttgart/mi/sda2/account/SimpleTest.java

diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/.gitignore b/Sd1/P/Archetypes/maven-prototype-javafx/.gitignore
new file mode 100644
index 000000000..06864be7f
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/.gitignore
@@ -0,0 +1,5 @@
+/target/
+/.settings/
+.classpath
+.project
+dependency-reduced-pom.xml
\ No newline at end of file
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/pom.xml b/Sd1/P/Archetypes/maven-prototype-javafx/pom.xml
new file mode 100644
index 000000000..b9e1f8561
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/pom.xml
@@ -0,0 +1,103 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>de.hdm-stuttgart.mi.sda2</groupId>
+	<artifactId>maven-prototype-javafx</artifactId>
+	<version>1.0</version>
+	<packaging>jar</packaging>
+
+	<name>account</name>
+
+	<!--Fixme: Add a sensible project related domain here -->
+	<url>http://somedomain.org</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.17</version>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>5.1.33</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.controlsfx</groupId>
+			<artifactId>controlsfx</artifactId>
+			<version>8.20.8</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.controlsfx</groupId>
+			<artifactId>openjfx-dialogs</artifactId>
+			<version>1.0.2</version>
+		</dependency>
+
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.1</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+			<plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>2.3</version>
+        <executions>
+          <execution>
+            <id>transfer-driver</id>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <transformers>
+                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                  <manifestEntries>
+                    <Main-Class>de.hdm_stuttgart.mi.sda2.account.TransferDriver</Main-Class>
+                  </manifestEntries>
+                </transformer>
+              </transformers>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+<!--  
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>2.4</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<mainClass>de.hdm_stuttgart.mi.sda2.account.TransferDriver</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+-->
+		</plugins>
+	</build>
+</project>
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/Conf.java b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/Conf.java
new file mode 100644
index 000000000..f6edf698d
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/Conf.java
@@ -0,0 +1,21 @@
+package de.hdm_stuttgart.mi.sda2.account;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Conf {
+	private static final String BUNDLE_NAME = "de.hdm_stuttgart.mi.sda2.account.config";
+
+	private static final ResourceBundle RESOURCE_BUNDLE =
+			ResourceBundle.getBundle(BUNDLE_NAME);
+
+	private Conf() {}
+
+	public static String get(String key) {
+		try {
+			return RESOURCE_BUNDLE.getString(key);
+		} catch (MissingResourceException e) {
+			return '!' + key + '!';
+		}
+	}
+}
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiDriver.java b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiDriver.java
new file mode 100644
index 000000000..c28c811d4
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiDriver.java
@@ -0,0 +1,97 @@
+package de.hdm_stuttgart.mi.sda2.account;
+
+import javafx.application.Application;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.GridPane;
+import javafx.scene.text.Font;
+import javafx.scene.text.FontWeight;
+import javafx.scene.text.Text;
+import javafx.stage.Stage;
+
+import org.apache.log4j.Logger;
+
+import de.hdm_stuttgart.mi.sda2.account.GuiHelper.Dialog;
+import de.hdm_stuttgart.mi.sda2.account.GuiHelper.NumberField;
+
+public class GuiDriver extends Application {
+
+	private final static Logger log = Logger.getLogger(GuiDriver.class);
+
+	final static int
+		colIndex_0 = 0,
+		colIndex_1 = 1;
+	
+    final Button resetBtn = new Button(Conf.get("resetButton.text"));
+    final TextField nameField = new TextField();
+    final NumberField ageField = new NumberField();
+    
+    public static void main( String[] args ) {
+    	launch(args);
+    }
+
+    public GuiDriver() {
+    	
+		resetBtn.setDisable(true);
+    	
+    	nameField.textProperty().addListener(event -> {
+    		log.info("Name value '" + nameField.getText() + "' has been entered");
+    		resetBtn.setDisable(false);
+    	});
+    	
+    	ageField.textProperty().addListener(event -> {
+    		log.info("Age value '" + nameField.getText() + "' has been entered");
+    		resetBtn.setDisable(false);
+    	});
+    	
+    	resetBtn.setOnAction(event-> {
+    		nameField.setText("");
+    		ageField.setText("");
+    		resetBtn.setDisable(true);
+    		Dialog.showInfo(Conf.get("infoFieldReset"));
+    		log.info("re-setting name field");
+    		});
+    }
+    
+    @Override
+    public void start(final Stage primaryStage) {
+
+        primaryStage.setTitle("Sample GUI");
+        
+        final GridPane grid = new GridPane();
+        grid.setAlignment(Pos.CENTER);
+        grid.setHgap(10);
+        grid.setVgap(10);
+        grid.setPadding(new Insets(25, 25, 25, 25));
+        
+        int currentRowIndex = 0;
+        final Text scenetitle = new Text("Simple GUI example");
+        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
+        grid.add(scenetitle, colIndex_0, currentRowIndex, 2, 1);
+        
+        currentRowIndex++;
+        grid.add(new Label("Your name:"), colIndex_0, currentRowIndex);
+        grid.add(nameField,               colIndex_1, currentRowIndex);
+
+        currentRowIndex++;
+        grid.add(new Label("Your age:"),  colIndex_0, currentRowIndex);
+        grid.add(ageField,                colIndex_1, currentRowIndex);
+
+        currentRowIndex++;
+        grid.add(resetBtn,                colIndex_0, currentRowIndex);
+        
+        Scene scene = new Scene(grid, 300, 250);
+        primaryStage.setScene(scene);
+        primaryStage.show();
+    }
+    
+    @Override
+	public void stop() throws Exception {
+		super.stop();
+		log.info("Terminating application");
+    }
+}
\ No newline at end of file
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/Dialog.java b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/Dialog.java
new file mode 100644
index 000000000..a93c06651
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/Dialog.java
@@ -0,0 +1,79 @@
+package de.hdm_stuttgart.mi.sda2.account.GuiHelper;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextArea;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.Priority;
+
+/**
+ * See http://code.makery.ch/blog/javafx-dialogs-official
+ * for further explanations.
+ *
+ */
+public class Dialog {
+	
+	
+	/**
+	 * Show a modal info box
+	 * @param msg A message to be displayed
+	 */
+	public static void showInfo(final String msg) {
+		final Alert alert = new Alert(AlertType.INFORMATION);
+		alert.setTitle("Info");
+		alert.setContentText(msg);
+		alert.showAndWait();
+	}
+
+	/**
+	 * Showing an error box and terminating without any further error processing
+	 * 
+	 * @param msg An informative message
+	 * @param ex The exception to be interpreted by an expert
+	 * @param exitCode The exit code to be used by e.g. the calling process.
+	 * 
+	 */
+	public static void showExceptionAndExit(final String msg, final Exception ex, int exitCode) {
+
+		final Alert alert = new Alert(AlertType.ERROR);
+		alert.setTitle("Unrecoverable error");
+		alert.setHeaderText("Application will be terminated!");
+		alert.setContentText(msg);
+
+
+		// Create expandable Exception.
+
+		if (null != ex) {
+			StringWriter sw = new StringWriter();
+			PrintWriter pw = new PrintWriter(sw);
+			ex.printStackTrace(pw);
+			String exceptionText = sw.toString();
+
+			Label label = new Label("You may copy and forward this exception stacktrace to an expert:");
+
+			TextArea textArea = new TextArea(exceptionText);
+			textArea.setEditable(false);
+			textArea.setWrapText(true);
+
+			textArea.setMaxWidth(Double.MAX_VALUE);
+			textArea.setMaxHeight(Double.MAX_VALUE);
+			GridPane.setVgrow(textArea, Priority.ALWAYS);
+			GridPane.setHgrow(textArea, Priority.ALWAYS);
+
+			GridPane expContent = new GridPane();
+			expContent.setMaxWidth(Double.MAX_VALUE);
+			expContent.add(label, 0, 0);
+			expContent.add(textArea, 0, 1);
+
+			// Set expandable Exception into the dialog pane.
+			alert.getDialogPane().setExpandableContent(expContent);
+		}
+
+		alert.showAndWait();
+		System.exit(exitCode);
+	}
+}
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/NumberField.java b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/NumberField.java
new file mode 100644
index 000000000..ff73cfe55
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/java/de/hdm_stuttgart/mi/sda2/account/GuiHelper/NumberField.java
@@ -0,0 +1,37 @@
+package de.hdm_stuttgart.mi.sda2.account.GuiHelper;
+
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.scene.control.TextField;
+
+public class NumberField extends TextField {
+
+	int value = 0;
+
+	public NumberField() {
+
+		setText("0");
+		textProperty().addListener(new ChangeListener<String>() {
+
+			@Override
+			public void changed(ObservableValue<? extends String> observable,
+					String oldValue, String newValue) {
+				switch (newValue) {
+				case "":
+				case "-":
+					return;
+				}
+
+				try {
+					value = Integer.parseInt(newValue);
+				} catch (NumberFormatException e) {
+					setText(oldValue);
+				}
+			}
+		});
+	}
+
+	public int getValue() {
+		return value;
+	}
+}
\ No newline at end of file
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/de/hdm_stuttgart/mi/sda2/account/config.properties b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/de/hdm_stuttgart/mi/sda2/account/config.properties
new file mode 100644
index 000000000..3507ddea7
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/de/hdm_stuttgart/mi/sda2/account/config.properties
@@ -0,0 +1,2 @@
+resetButton.text=Reset
+infoFieldReset=Fields have been resetted
\ No newline at end of file
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/log4j.properties b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/log4j.properties
new file mode 100644
index 000000000..a81103b6e
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/main/resources/log4j.properties
@@ -0,0 +1,15 @@
+#Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=DEBUG, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout comforting Eclipse's debugger.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%p: %m at %c.%M(%C{1}.java:%L)%n
+
+# Activate per-class or package logging rules if required. For example
+# reducing logging to INFO level for class de.hdm-stuttgart.mi.sda2.account.App
+# can be achieved by un-commenting the following line:
+
+#log4j.logger.de.hdm-stuttgart.mi.sda2.account.App.parse.Group=INFO
diff --git a/Sd1/P/Archetypes/maven-prototype-javafx/src/test/java/de/hdm_stuttgart/mi/sda2/account/SimpleTest.java b/Sd1/P/Archetypes/maven-prototype-javafx/src/test/java/de/hdm_stuttgart/mi/sda2/account/SimpleTest.java
new file mode 100644
index 000000000..65e4eb647
--- /dev/null
+++ b/Sd1/P/Archetypes/maven-prototype-javafx/src/test/java/de/hdm_stuttgart/mi/sda2/account/SimpleTest.java
@@ -0,0 +1,15 @@
+package de.hdm_stuttgart.mi.sda2.account;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ * Unit test for simple App.
+ */
+public class SimpleTest {
+    @Test
+    public void testApp() {
+    	Assert.assertEquals(1, 1);
+    }
+}
-- 
GitLab