Skip to content
This repository was archived by the owner on Jun 15, 2024. It is now read-only.

Commit a4e428a

Browse files
committed
added button-style css, added photographer list fxml, changed Configuration Class to Singleton, added Bindings
1 parent d872b84 commit a4e428a

23 files changed

+691
-87
lines changed

.idea/cssdialects.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/PIC-DB.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/PIC-DB.main.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/PIC-DB.test.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app.properties

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
db.url=jdbc:mysql://localhost:3306/picdb?useUnicode=true&characterEncoding=UTF-8
2-
db.user=root
1+
# Database Properties
2+
3+
# Logger Properties
4+
5+
# Other Properties
6+

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ sourceSets.main {
3333
java {
3434
srcDir 'src/main/java'
3535
}
36-
3736
resources {
3837
srcDirs = ['src/main/java', 'src/main/resources']
3938
exclude "**/*.java"

default.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Database Properties
2+
db.url=jdbc:mysql://localhost:3306/picdb?useUnicode=true&characterEncoding=UTF-8
3+
db.user=root
4+
db.passwd=
5+
6+
# Logger Properties
7+
8+
# Other Properties

src/main/java/at/technikum/ApplicationFX.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ApplicationFX extends Application {
1919

2020
public static void main(String[] args) throws Exception {
2121

22-
logger.debug("Hello from Log4j 2");
22+
logger.info("Hello from Log4j 2");
2323

2424
BusinessLayer businessLayer = new BusinessLayerImpl();
2525
PictureModel pictureModel = businessLayer.getPicture(2);
@@ -38,6 +38,7 @@ public void start(Stage primaryStage) {
3838
} catch (RuntimeException | IOException e) {
3939
e.printStackTrace();
4040
}
41+
assert root != null;
4142
Scene scene = new Scene(root, 800, 800);
4243
scene.getStylesheets().add(String.valueOf(getClass().getResource("stylesheet.css")));
4344
primaryStage.setTitle("PIC DB");

src/main/java/at/technikum/Controller/MainController.java

-33
This file was deleted.

src/main/java/at/technikum/DataAccessLayer/Database.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import at.technikum.Utils.Configurations;
44

5+
import java.net.URISyntaxException;
56
import java.sql.Connection;
67
import java.sql.DriverManager;
78
import java.sql.SQLException;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package at.technikum.Utils;
2+
3+
import javafx.beans.property.Property;
4+
import javafx.beans.value.ObservableValue;
5+
import javafx.scene.Node;
6+
import javafx.scene.layout.Pane;
7+
8+
import java.util.ArrayList;
9+
import java.util.Dictionary;
10+
import java.util.Hashtable;
11+
import java.util.List;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
14+
15+
/**
16+
* Created by arthur on 17.03.2016.
17+
*/
18+
public class Binding {
19+
public enum Mode {
20+
ONEWAY,
21+
TWOWAY,
22+
ONEWAYTOSOURCE
23+
}
24+
25+
private static Dictionary<Node, List<Binding>> bindings = new Hashtable<>();
26+
27+
private Node node;
28+
private String binding;
29+
private Mode mode;
30+
31+
public Binding() {
32+
}
33+
34+
public Binding(Node node, String binding, Mode mode) {
35+
this.node = node;
36+
this.binding = binding;
37+
this.mode = mode;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "Binding{" +
43+
"node=" + node +
44+
", binding='" + binding + '\'' +
45+
", mode=" + mode +
46+
'}';
47+
}
48+
49+
public static void addBinding(Node n, Binding b) {
50+
List<Binding> lst = bindings.get(n);
51+
if (lst == null) {
52+
lst = new ArrayList<Binding>();
53+
bindings.put(n, lst);
54+
}
55+
lst.add(b);
56+
}
57+
58+
public static void setTwoWay(Node n, String binding) {
59+
Binding b = new Binding(n, binding, Mode.TWOWAY);
60+
addBinding(n, b);
61+
System.out.println(String.format("Setting two way binding for %s", b));
62+
}
63+
64+
public static void setOneWay(Node n, String binding) {
65+
Binding b = new Binding(n, binding, Mode.ONEWAY);
66+
addBinding(n, b);
67+
System.out.println(String.format("Setting one way binding for %s", b));
68+
}
69+
70+
public static void applyBinding(Node n, Object bean) {
71+
Pattern p = Pattern.compile("\\{(\\w+)=(\\w+)\\}");
72+
73+
List<Binding> lst = bindings.get(n);
74+
if (lst != null) {
75+
for (Binding b : lst) {
76+
Matcher m = p.matcher(b.binding);
77+
if (m.matches()) {
78+
String destName = m.group(1); // 0 = everything
79+
String sourceName = m.group(2);
80+
Property<Object> dest = ReflectionHelper.getProperty(n, destName);
81+
ObservableValue<Object> destRO = ReflectionHelper.getReadonlyProperty(n, destName);
82+
Property<Object> source = ReflectionHelper.getProperty(bean, sourceName);
83+
ObservableValue<Object> sourceRO = ReflectionHelper.getReadonlyProperty(bean, sourceName);
84+
if ((dest != null || destRO != null) && (source != null || sourceRO != null)) {
85+
switch (b.mode) {
86+
case ONEWAY:
87+
if(dest != null) {
88+
dest.bind(sourceRO);
89+
} else {
90+
System.out.print(String.format("Invalid binding %s, destination is not a Property<?>", b));
91+
}
92+
break;
93+
case TWOWAY:
94+
if ((dest != null || destRO != null) && (source != null || sourceRO != null)) {
95+
dest.bindBidirectional(source);
96+
} else {
97+
System.out.print(String.format("Invalid binding %s", b));
98+
if (source == null) {
99+
System.out.println(String.format(", source is not a Property<?>"));
100+
}
101+
if (dest == null) {
102+
System.out.println(String.format(", destination is not a Property<?>"));
103+
}
104+
}
105+
break;
106+
case ONEWAYTOSOURCE:
107+
if(source != null) {
108+
source.bind(destRO);
109+
} else {
110+
System.out.print(String.format("Invalid binding %s, source is not a Property<?>", b));
111+
}
112+
break;
113+
}
114+
} else {
115+
System.out.print(String.format("Invalid binding %s", b));
116+
if (source == null && sourceRO == null) {
117+
System.out.println(String.format(", source property %s not found", sourceName));
118+
}
119+
if (dest == null && destRO == null) {
120+
System.out.println(String.format(", destination property %s not found", destName));
121+
}
122+
System.out.println();
123+
}
124+
}
125+
}
126+
}
127+
128+
if (n instanceof Pane) {
129+
Pane pane = (Pane) n;
130+
// go down
131+
for (Node child : pane.getChildren()) {
132+
applyBinding(child, bean);
133+
}
134+
}
135+
}
136+
137+
/**
138+
* TODO: Is this called by JavaFX?
139+
*
140+
* @param n
141+
*/
142+
public static void clearConstraints(Node n) {
143+
System.out.println(String.format("clear all constrains for %s", n.getId()));
144+
}
145+
}

src/main/java/at/technikum/Utils/Configurations.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package at.technikum.Utils;
22

3+
import at.technikum.ApplicationFX;
34
import at.technikum.DataAccessLayer.Database;
5+
import org.apache.logging.log4j.LogManager;
46

57
import java.io.BufferedReader;
68
import java.io.IOException;
@@ -13,11 +15,19 @@
1315
import java.util.logging.Logger;
1416

1517
public class Configurations {
18+
private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(ApplicationFX.class);
19+
20+
static Properties applicationProps = null;
21+
1622
public static Properties readProperties() {
23+
24+
if (applicationProps != null) return applicationProps;
25+
26+
logger.debug("Inside Configurations.java");
27+
1728
// create and load default properties Properties
1829
java.util.Properties defaultProps = new java.util.Properties();
19-
Path defaultPropsPath = Paths.get(System.getProperty("user.dir") +
20-
"\\src\\main\\resources\\default.properties");
30+
Path defaultPropsPath = Paths.get("default.properties");
2131

2232
try {
2333
BufferedReader bf = Files.newBufferedReader(defaultPropsPath, StandardCharsets.UTF_8);
@@ -27,7 +37,7 @@ public static Properties readProperties() {
2737
}
2838

2939
// create application properties with default
30-
java.util.Properties applicationProps = new java.util.Properties(defaultProps);
40+
Properties applicationProps = new java.util.Properties(defaultProps);
3141
Path applicationPropsPath = Paths.get("app.properties");
3242

3343
try {

0 commit comments

Comments
 (0)