Skip to content

Commit 0ba5231

Browse files
committed
Add part_4: i18n
1 parent e61afdc commit 0ba5231

14 files changed

+169
-0
lines changed

part_4/pom.xml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>de.roskenet.spring-fx-examples</groupId>
5+
<artifactId>part_4</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
8+
<parent>
9+
<groupId>org.springframework.boot</groupId>
10+
<artifactId>spring-boot-starter-parent</artifactId>
11+
<version>1.5.2.RELEASE</version>
12+
<relativePath /> <!-- lookup parent from repository -->
13+
</parent>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<java.version>1.8</java.version>
18+
<springboot-javafx.version>1.3.0</springboot-javafx.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>de.roskenet</groupId>
28+
<artifactId>springboot-javafx-support</artifactId>
29+
<version>${springboot-javafx.version}</version>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-maven-plugin</artifactId>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example;
2+
3+
public interface AwesomeActionService {
4+
String processName(String name);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package example;
2+
3+
import java.text.MessageFormat;
4+
import java.util.ResourceBundle;
5+
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class DefaultAwesomeActionService implements AwesomeActionService {
10+
11+
private ResourceBundle bundle = ResourceBundle.getBundle("i18n.helloworld");
12+
13+
@Override
14+
public String processName(final String name) {
15+
return MessageFormat.format(bundle.getString("greeting"), name);
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package example;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
5+
import de.felixroske.jfxsupport.FXMLController;
6+
import javafx.event.Event;
7+
import javafx.fxml.FXML;
8+
import javafx.scene.control.Label;
9+
import javafx.scene.control.TextField;
10+
11+
@FXMLController
12+
public class HelloworldController {
13+
14+
@FXML
15+
private Label helloLabel;
16+
17+
@FXML
18+
private TextField nameField;
19+
20+
// Be aware: This is a Spring bean. So we can do the following:
21+
@Autowired
22+
private AwesomeActionService actionService;
23+
24+
@FXML
25+
private void setHelloText(final Event event) {
26+
final String textToBeShown = actionService.processName(nameField.getText());
27+
helloLabel.setText(textToBeShown);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package example;
2+
3+
import de.felixroske.jfxsupport.AbstractFxmlView;
4+
import de.felixroske.jfxsupport.FXMLView;
5+
6+
@FXMLView(bundle="i18n.helloworld")
7+
public class HelloworldView extends AbstractFxmlView {
8+
9+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
5+
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
6+
7+
@SpringBootApplication
8+
public class Main extends AbstractJavaFxApplicationSupport{
9+
10+
public static void main(String[] args) {
11+
launchApp(Main.class, HelloworldView.class, args);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring:
2+
jmx:
3+
enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.root {
2+
-fx-background-color: #FFFFFF;
3+
}
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.button {
2+
-fx-background-color: #009688;
3+
-fx-background-radius: 0;
4+
-fx-text-fill: #FFFFFF;
5+
-fx-margin: 0;
6+
}
7+
8+
.text-field {
9+
-fx-background-color: #000000, white , white;
10+
-fx-background-insets: 0 0 -1 0, 0 0 0 0, 0 -1 3 -1;
11+
-fx-background-radius: 0;
12+
-fx-margin: 0;
13+
}
14+
15+
.text-field:focused {
16+
-fx-background-color: #009688 , white , white;
17+
-fx-background-insets: 0 0 -2 0, 0 0 0 0, 0 -1 3 -1;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Button?>
4+
<?import javafx.scene.control.Label?>
5+
<?import javafx.scene.control.TextField?>
6+
<?import javafx.scene.layout.Pane?>
7+
<?import javafx.scene.text.Font?>
8+
9+
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" stylesheets="@global.css" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="example.HelloworldController">
10+
<children>
11+
<Label fx:id="helloLabel" layoutX="99.0" layoutY="109.0" prefHeight="34.0" prefWidth="394.0" text="%hello">
12+
<font>
13+
<Font size="26.0" />
14+
</font>
15+
</Label>
16+
<TextField fx:id="nameField" layoutX="99.0" layoutY="162.0" prefHeight="26.0" prefWidth="234.0" />
17+
<Button fx:id="helloButton" layoutX="347.0" layoutY="162.0" mnemonicParsing="false" onAction="#setHelloText" text="%go" />
18+
</children>
19+
</Pane>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello=Hello
2+
greeting=Hello {0}!
3+
go=Go!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello=Hallo
2+
greeting=Hallo {0}!
3+
go=Los!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello=Salut
2+
greeting=Salut {0} !
3+
go=Vas-y !

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<module>part_1</module>
1515
<module>part_2</module>
1616
<module>part_3</module>
17+
<module>part_4</module>
1718
</modules>
1819
</project>

0 commit comments

Comments
 (0)