Skip to content

Commit bf2e4f3

Browse files
committed
Merge branch 'master' into feature/dayChange
# Conflicts: # src/main/java/de/doubleslash/keeptime/model/Model.java # src/main/java/de/doubleslash/keeptime/view/SettingsController.java
2 parents bee4601 + 635743e commit bf2e4f3

File tree

9 files changed

+362
-8
lines changed

9 files changed

+362
-8
lines changed

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@
4545
<artifactId>jnativehook</artifactId>
4646
<version>2.1.0</version>
4747
</dependency>
48+
<dependency>
49+
<groupId>org.w3c</groupId>
50+
<artifactId>dom</artifactId>
51+
<version>2.3.0-jaxb-1.0.6</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.mockito</groupId>
55+
<artifactId>mockito-core</artifactId>
56+
<version>2.21.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.commons</groupId>
60+
<artifactId>commons-lang3</artifactId>
61+
<version>3.8</version>
62+
</dependency>
63+
4864
</dependencies>
4965

5066
<build>

src/main/java/de/doubleslash/keeptime/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void init() throws Exception {
5656

5757
@Override
5858
public void start(final Stage primaryStage) throws Exception {
59+
5960
stage = primaryStage;
6061

6162
LOG.debug("Reading configuration");
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package de.doubleslash.keeptime.common;
2+
3+
import java.io.File;
4+
5+
import javax.xml.parsers.DocumentBuilder;
6+
import javax.xml.parsers.DocumentBuilderFactory;
7+
8+
import org.w3c.dom.Document;
9+
import org.w3c.dom.Element;
10+
import org.w3c.dom.Node;
11+
import org.w3c.dom.NodeList;
12+
13+
import de.doubleslash.keeptime.controller.Controller;
14+
import de.doubleslash.keeptime.model.Model;
15+
import de.doubleslash.keeptime.model.Project;
16+
import javafx.scene.paint.Color;
17+
18+
public class ConfigParser {
19+
20+
Controller controller;
21+
Model model;
22+
23+
public ConfigParser(final Model model, final Controller controller) {
24+
this.model = model;
25+
this.controller = controller;
26+
}
27+
28+
public static boolean hasConfigFile(final String fileName) {
29+
final File f = new File(fileName);
30+
return f.exists();
31+
}
32+
33+
public void parserConfig(final File inputFile) {
34+
try {
35+
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
36+
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
37+
final Document doc = dBuilder.parse(inputFile);
38+
doc.getDocumentElement().normalize();
39+
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
40+
final NodeList nList = doc.getElementsByTagName("project");
41+
System.out.println("----------------------------");
42+
43+
// index makes sure to add new projects at the end
44+
int index = controller.getAvailableProjects().size();
45+
for (int temp = 0; temp < nList.getLength(); temp++) {
46+
final Node nNode = nList.item(temp);
47+
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
48+
final Element eElement = (Element) nNode;
49+
// get element
50+
final String name = eElement.getElementsByTagName("name").item(0).getTextContent();
51+
final String isWork = eElement.getElementsByTagName("isWork").item(0).getTextContent();
52+
final String color = eElement.getElementsByTagName("color").item(0).getTextContent();
53+
54+
System.out.println("checking for: " + name);
55+
boolean exists = false;
56+
57+
for (final Project p : controller.getAvailableProjects()) {
58+
if (name.equals(p.getName())) {
59+
System.out.println(name + " " + Boolean.toString(exists));
60+
exists = true;
61+
}
62+
}
63+
if (!exists) {
64+
final Color colorTemp = Color.valueOf(color);
65+
controller.addNewProject(name, Boolean.parseBoolean(isWork), colorTemp, index);
66+
index++;
67+
}
68+
69+
}
70+
}
71+
72+
} catch (final Exception e) {
73+
e.printStackTrace();
74+
}
75+
}
76+
}

src/main/java/de/doubleslash/keeptime/controller/Controller.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import de.doubleslash.keeptime.model.Project;
2121
import de.doubleslash.keeptime.model.Settings;
2222
import de.doubleslash.keeptime.model.Work;
23+
import javafx.collections.ObservableList;
2324
import javafx.scene.paint.Color;
2425

2526
@Service
@@ -160,13 +161,13 @@ public void editProject(final Project p, final String newName, final Color newCo
160161
* Changes the indexes of the originalList parameter to have a consistent order.
161162
*
162163
* @param originalList
163-
* list of all projects to adapt the indexes for
164+
* list of all projects to adapt the indexes for
164165
* @param changedProject
165-
* the project which has changed which already has the new index
166+
* the project which has changed which already has the new index
166167
* @param oldIndex
167-
* the old index of the changed project
168+
* the old index of the changed project
168169
* @param newIndex
169-
* the new index of the changed project (which the projects also already has)
170+
* the new index of the changed project (which the projects also already has)
170171
* @return all projects whose index has been adapted
171172
*/
172173
List<Project> resortProjectIndexes(final List<Project> originalList, final Project changedProject,
@@ -208,9 +209,9 @@ List<Project> resortProjectIndexes(final List<Project> originalList, final Proje
208209
* Decreases all indexes by one, after the removed index
209210
*
210211
* @param originalList
211-
* list of all projects to adapt the indexes for
212+
* list of all projects to adapt the indexes for
212213
* @param removedIndex
213-
* the index which has been removed
214+
* the index which has been removed
214215
* @return all projects whose index has been adapted
215216
*/
216217
List<Project> adaptProjectIndexesAfterRemoving(final List<Project> originalList, final int removedIndex) {
@@ -265,4 +266,7 @@ public long calcTodaysSeconds() {
265266
}).sum();
266267
}
267268

269+
public ObservableList<Project> getAvailableProjects() {
270+
return this.model.availableProjects;
271+
}
268272
}

src/main/java/de/doubleslash/keeptime/model/Model.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public Model(final ProjectRepository projectRepository, final WorkRepository wor
3030
this.settingsRepository = settingsRepository;
3131
}
3232

33-
public static final Color originalHoverBackgroundColor = new Color(54 / 255., 143 / 255., 179 / 255., .1);
33+
public static final Color originalHoverBackgroundColor = new Color(54 / 255., 143 / 255., 179 / 255., .7);
34+
3435
public static final Color originalHoverFontColor = Color.BLACK;
35-
public static final Color originalDefaultBackgroundColor = new Color(54 / 255., 143 / 255., 179 / 255., 0.01);
36+
public static final Color originalDefaultBackgroundColor = new Color(54 / 255., 143 / 255., 179 / 255., .7);
3637
public static final Color originalDefaultFontColor = Color.BLACK;
3738

3839
public static final Color originalTaskBarFontColor = Color.BLACK;

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package de.doubleslash.keeptime.view;
22

3+
import java.io.File;
4+
35
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
57

8+
import de.doubleslash.keeptime.common.ConfigParser;
69
import de.doubleslash.keeptime.controller.Controller;
710
import de.doubleslash.keeptime.model.Model;
11+
import javafx.event.ActionEvent;
12+
import javafx.event.EventHandler;
813
import javafx.fxml.FXML;
914
import javafx.scene.control.Button;
1015
import javafx.scene.control.CheckBox;
@@ -49,9 +54,13 @@ public class SettingsController {
4954

5055
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
5156

57+
@FXML
58+
private Button parseConfigButton;
59+
5260
private Model model;
5361
private Controller controller;
5462
private Stage thisStage;
63+
private static final String INPUT_FILE = "config.xml";
5564

5665
@FXML
5766
private void initialize() {
@@ -85,6 +94,16 @@ private void initialize() {
8594
taskBarColor.setValue(Model.originalTaskBarFontColor);
8695
});
8796

97+
parseConfigButton.setOnAction(new EventHandler<ActionEvent>() {
98+
@Override
99+
public void handle(final ActionEvent actionEvent) {
100+
if (ConfigParser.hasConfigFile(INPUT_FILE)) {
101+
final ConfigParser parser = new ConfigParser(model, controller);
102+
parser.parserConfig(new File(INPUT_FILE));
103+
}
104+
}
105+
});
106+
88107
}
89108

90109
public void setModelAndController(final Model model, final Controller controller) {

src/main/resources/settings.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<children>
119119
<Button fx:id="saveButton" mnemonicParsing="false" text="Save" />
120120
<Button fx:id="cancelButton" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" text="Cancel" />
121+
<Button fx:id="parseConfigButton" mnemonicParsing="false" text="pars config.xml" />
121122
</children>
122123
</HBox>
123124
</children>

0 commit comments

Comments
 (0)