Skip to content

Commit 65083f9

Browse files
committed
did some smaller changes
Sonar didn't want commented out lines of code to stay in code and many other things
1 parent dd1bb96 commit 65083f9

File tree

12 files changed

+159
-158
lines changed

12 files changed

+159
-158
lines changed

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
import de.doubleslash.keeptime.viewPopup.GlobalScreenListener;
2424
import de.doubleslash.keeptime.viewPopup.ViewControllerPopup;
2525
import javafx.application.Application;
26-
import javafx.event.EventHandler;
2726
import javafx.fxml.FXMLLoader;
2827
import javafx.scene.Parent;
2928
import javafx.scene.Scene;
3029
import javafx.scene.layout.Pane;
3130
import javafx.scene.paint.Color;
3231
import javafx.stage.Stage;
3332
import javafx.stage.StageStyle;
34-
import javafx.stage.WindowEvent;
3533

3634
@SpringBootApplication
3735
public class Main extends Application {
@@ -116,29 +114,20 @@ public void start(final Stage primaryStage) throws Exception {
116114
}
117115

118116
primaryStage.setOnHiding((we) -> {
119-
// shutdown();
120117
popupViewStage.close();
121118
globalScreenListener.register(false); // deregister, as this will keep app running
122119
});
123120

124-
Runtime.getRuntime().addShutdownHook(new Thread() {
125-
@Override
126-
public void run() {
127-
// TODO this does not work - spring uses own hooks and may already be shutdown
128-
// shutdown();
129-
}
130-
});
131-
132121
try {
133122
initialiseUI(primaryStage);
134123
} catch (final Exception e) {
135-
e.printStackTrace();
124+
LOG.error(e.getMessage());
136125
}
137126

138127
try {
139128
initialisePopupUI(primaryStage);
140129
} catch (final Exception e) {
141-
e.printStackTrace();
130+
LOG.error(e.getMessage());
142131
}
143132
}
144133

@@ -175,13 +164,6 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
175164

176165
}
177166

178-
private void shutdown() {
179-
LOG.info("Shutting down");
180-
// viewController.changeProject(model.idleProject, 0); // TODO not so nice (view has the comments for the current
181-
// // job)
182-
controller.shutdown();
183-
}
184-
185167
ViewController viewController;
186168

187169
private void initialiseUI(final Stage primaryStage) {
@@ -197,35 +179,25 @@ private void initialiseUI(final Stage primaryStage) {
197179
// Show the scene containing the root layout.
198180
final Scene mainScene = new Scene(mainPane, Color.TRANSPARENT);
199181

200-
// Image(Resources.getResource(RESOURCE.ICON_MAIN).toString()));
201-
202182
primaryStage.setTitle("KeepTime");
203183
primaryStage.setScene(mainScene);
204184
primaryStage.setAlwaysOnTop(true);
205185
primaryStage.setResizable(false);
206186

207-
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
208-
@Override
209-
public void handle(final WindowEvent event) {
210-
LOG.info("On close request");
211-
// shutdown();
212-
// Platform.exit();
213-
}
214-
});
187+
primaryStage.setOnCloseRequest(actionEvent -> LOG.info("On close request"));
215188

216189
viewController = loader.getController();
217190
// Give the controller access to the main app.
218191
viewController.setStage(primaryStage);
219192

220-
// controller = springContext.getBean(Controller.class, model, new RealDateProvider());
221-
222193
viewController.setController(controller, model);
223194

224195
primaryStage.show();
225196

226-
} catch (final Exception e) {
197+
} catch (
198+
199+
final Exception e) {
227200
LOG.error("Error: " + e.toString(), e);
228-
e.printStackTrace();
229201
}
230202
}
231203

src/main/java/de/doubleslash/keeptime/common/ColorHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
public class ColorHelper {
66

7+
private ColorHelper() {
8+
throw new IllegalStateException("Utility class: ColorHelper");
9+
}
10+
711
public static Color randomColor() {
812
return Color.BLACK;
913
}

src/main/java/de/doubleslash/keeptime/common/DateFormatter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ public class DateFormatter {
99
private static DateTimeFormatter dayDateFormatter = DateTimeFormatter.ofPattern("eeee dd.MM.yyyy");
1010
private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
1111

12+
private DateFormatter() {
13+
throw new IllegalStateException("Utility class: DateFormatter");
14+
}
15+
1216
public static String secondsToHHMMSS(final long currentWorkSeconds) {
1317
final int hours = (int) (currentWorkSeconds / 3600);
1418
final int minutes = (int) ((currentWorkSeconds % 3600) / 60);
1519

16-
final int sec = (int) (((currentWorkSeconds % 3600) % 60));
20+
final int sec = (int) (currentWorkSeconds % 3600 % 60);
1721

1822
final String a = (hours > 9 ? hours : "0" + hours) + ":" + (minutes > 9 ? minutes : "0" + minutes) + ":"
1923
+ (sec > 9 ? sec : "0" + sec);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void changeProject(final Project newProject, final long minusSeconds) {
5151
final LocalDateTime now = dateProvider.dateTimeNow().minusSeconds(minusSeconds);
5252
if (currentWork != null) {
5353
currentWork.setEndTime(now);
54-
// currentWork.setNotes(notes);
5554
if (currentWork.getNotes().isEmpty()) {
5655
currentWork.setNotes("- No notes -");
5756
}
@@ -197,7 +196,6 @@ List<Project> resortProjectIndexes(final List<Project> originalList, final Proje
197196
}
198197

199198
final int newCurrentIndex = currentIndex + adjustOffset;
200-
// System.out.println("Moving index '" + currentIndex + "' to '" + newCurrentIndex + "'.");
201199
project.setIndex(newCurrentIndex);
202200
changedProjects.add(project);
203201
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package de.doubleslash.keeptime.exceptions;
2+
3+
public class FXMLLoaderException extends RuntimeException {
4+
5+
public FXMLLoaderException() {
6+
// XXX Auto-generated constructor stub
7+
}
8+
9+
public FXMLLoaderException(String message) {
10+
super(message);
11+
// XXX Auto-generated constructor stub
12+
}
13+
14+
public FXMLLoaderException(Throwable cause) {
15+
super(cause);
16+
// XXX Auto-generated constructor stub
17+
}
18+
19+
public FXMLLoaderException(String message, Throwable cause) {
20+
super(message, cause);
21+
// XXX Auto-generated constructor stub
22+
}
23+
24+
public FXMLLoaderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
25+
super(message, cause, enableSuppression, writableStackTrace);
26+
// XXX Auto-generated constructor stub
27+
}
28+
29+
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ private void updateReport(final LocalDate newvalue) {
7878

7979
gridPane.getChildren().clear();
8080
gridPane.getRowConstraints().clear();
81-
// gridPane.getColumnConstraints().clear();
8281

8382
int rowIndex = 0;
8483
long currentWorkSeconds = 0;
@@ -141,20 +140,17 @@ public void setModelAndController(final Model model, final Controller controller
141140
// HACK to show calendar from datepicker
142141
// https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
143142
final DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
144-
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
145-
@Override
146-
public DateCell call(final DatePicker datePicker) {
147-
return new DateCell() {
148-
@Override
149-
public void updateItem(final LocalDate item, final boolean empty) {
150-
super.updateItem(item, empty);
151-
if (model.workRepository.findByCreationDate(item).isEmpty()) {
152-
setDisable(true);
153-
setStyle(FX_BACKGROUND_COLOR_NOT_WORKED);
154-
}
143+
final Callback<DatePicker, DateCell> dayCellFactory = callback -> {
144+
return new DateCell() {
145+
@Override
146+
public void updateItem(final LocalDate item, final boolean empty) {
147+
super.updateItem(item, empty);
148+
if (model.workRepository.findByCreationDate(item).isEmpty()) {
149+
setDisable(true);
150+
setStyle(FX_BACKGROUND_COLOR_NOT_WORKED);
155151
}
156-
};
157-
}
152+
}
153+
};
158154
};
159155
datePicker.setDayCellFactory(dayCellFactory);
160156
final Node popupContent = datePickerSkin.getPopupContent();

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import de.doubleslash.keeptime.common.ConfigParser;
1010
import de.doubleslash.keeptime.controller.Controller;
1111
import de.doubleslash.keeptime.model.Model;
12-
import javafx.event.ActionEvent;
13-
import javafx.event.EventHandler;
1412
import javafx.fxml.FXML;
1513
import javafx.scene.control.Alert;
1614
import javafx.scene.control.Alert.AlertType;
@@ -141,13 +139,10 @@ private void initialize() {
141139
taskBarColor.setValue(Model.originalTaskBarFontColor);
142140
});
143141

144-
parseConfigButton.setOnAction(new EventHandler<ActionEvent>() {
145-
@Override
146-
public void handle(final ActionEvent actionEvent) {
147-
if (ConfigParser.hasConfigFile(INPUT_FILE)) {
148-
final ConfigParser parser = new ConfigParser(controller);
149-
parser.parseConfig(new File(INPUT_FILE));
150-
}
142+
parseConfigButton.setOnAction(actionEvent -> {
143+
if (ConfigParser.hasConfigFile(INPUT_FILE)) {
144+
final ConfigParser parser = new ConfigParser(controller);
145+
parser.parseConfig(new File(INPUT_FILE));
151146
}
152147
});
153148

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

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import de.doubleslash.keeptime.common.Resources;
2020
import de.doubleslash.keeptime.common.Resources.RESOURCE;
2121
import de.doubleslash.keeptime.controller.Controller;
22+
import de.doubleslash.keeptime.exceptions.FXMLLoaderException;
2223
import de.doubleslash.keeptime.model.Model;
2324
import de.doubleslash.keeptime.model.Project;
2425
import de.doubleslash.keeptime.model.Work;
@@ -35,6 +36,7 @@
3536
import javafx.collections.ListChangeListener.Change;
3637
import javafx.collections.ObservableList;
3738
import javafx.embed.swing.SwingFXUtils;
39+
import javafx.event.ActionEvent;
3840
import javafx.fxml.FXML;
3941
import javafx.fxml.FXMLLoader;
4042
import javafx.geometry.Insets;
@@ -192,26 +194,6 @@ private void initialize() throws IOException {
192194
closeButton.textFillProperty().bind(fontColorProperty);
193195

194196
addNewProjectButton.textFillProperty().bind(fontColorProperty);
195-
addNewProjectButton.setOnAction((ae) -> {
196-
LOG.info("Add new project clicked");
197-
// TODO somewhat duplicate dialog of create and edit
198-
Dialog<Project> dialog = setUpDialogProject("Create new project", "Create a new project");
199-
200-
final GridPane grid = setUpAddNewProjectGridPane("", Color.WHITE, true);
201-
202-
// TODO disable OK button if no name is set
203-
dialog.getDialogPane().setContent(grid);
204-
205-
dialog = dialogResultConverter(dialog, grid);
206-
mainStage.setAlwaysOnTop(false);
207-
final Optional<Project> result = dialog.showAndWait();
208-
mainStage.setAlwaysOnTop(true);
209-
210-
result.ifPresent(project -> {
211-
controller.addNewProject(project.getName(), project.isWork(), project.getColor(), project.getIndex());
212-
realignProjectList();
213-
});
214-
});
215197

216198
// Add a light to colorize buttons
217199
// TODO does this go nicer?
@@ -422,17 +404,16 @@ private long doIntervalRegisterCallBack() {
422404

423405
// update all ui labels
424406
// TODO do it with bindings (maybe create a viewmodel for this)
425-
// bigTimeLabel.setText(DateFormatter.secondsToHHMMSS(currentWorkSeconds));
407+
426408
allTimeLabel.setText(DateFormatter.secondsToHHMMSS(todayWorkingSeconds));
427409
todayAllSeconds.setText(DateFormatter.secondsToHHMMSS(todaySeconds));
428410

429-
for (final Project p : elapsedProjectTimeLabelMap.keySet()) {
430-
final Label label = elapsedProjectTimeLabelMap.get(p);
411+
for (final Map.Entry<Project, Label> entry : elapsedProjectTimeLabelMap.entrySet()) {
412+
final Label label = entry.getValue();
431413

432-
final long seconds = model.pastWorkItems.stream().filter((work) -> work.getProject().getId() == p.getId())
433-
.mapToLong(work -> {
434-
return Duration.between(work.getStartTime(), work.getEndTime()).getSeconds();
435-
}).sum();
414+
final long seconds = model.pastWorkItems.stream()
415+
.filter((work) -> work.getProject().getId() == entry.getKey().getId())
416+
.mapToLong(work -> Duration.between(work.getStartTime(), work.getEndTime()).getSeconds()).sum();
436417
label.setText(DateFormatter.secondsToHHMMSS(seconds));
437418
label.setFont(new Font(ARIAL, 12));
438419
}
@@ -501,7 +482,7 @@ private void loadSubStages() {
501482
this.mainStage.setAlwaysOnTop(true);
502483
});
503484
} catch (final IOException e) {
504-
throw new RuntimeException(e);
485+
throw new FXMLLoaderException(e);
505486
}
506487
}
507488

@@ -521,7 +502,7 @@ private Node addProjectToProjectList(final Project p) {
521502
projectElement = (Pane) loader.load();
522503
} catch (final IOException e1) {
523504
LOG.error("Could not load '{}'.", loader.getLocation(), e1);
524-
throw new RuntimeException(e1);
505+
throw new FXMLLoaderException(e1);
525506
}
526507

527508
final Label projectNameLabel = (Label) projectElement.getChildren().get(0);
@@ -546,7 +527,7 @@ private Node addProjectToProjectList(final Project p) {
546527
if (wasDragged) {
547528
return;
548529
}
549-
// a.consume();
530+
550531
final MouseButton button = a.getButton();
551532
if (button == MouseButton.PRIMARY) {
552533
changeProject(p, 0);
@@ -558,13 +539,13 @@ private Node addProjectToProjectList(final Project p) {
558539
final Bloom bloom = new Bloom();
559540
bloom.setThreshold(0.3);
560541
projectNameLabel.setEffect(bloom);
561-
// projectNameLabel.setUnderline(true);
542+
562543
});
563544
projectNameLabel.setOnMouseExited(ae -> {
564545
projectNameLabel.setTextFill(new Color(p.getColor().getRed() * dimFactor, p.getColor().getGreen() * dimFactor,
565546
p.getColor().getBlue() * dimFactor, 1));
566547
projectNameLabel.setEffect(null);
567-
// projectNameLabel.setUnderline(false);
548+
568549
});
569550

570551
availableProjectVbox.getChildren().add(projectElement);
@@ -852,7 +833,7 @@ private void updateTaskbarIcon(final long currentWorkSeconds) {
852833
gcIcon.setTextAlign(TextAlignment.CENTER);
853834
gcIcon.setFont(new Font(ARIAL, 12));
854835
gcIcon.strokeText(DateFormatter.secondsToHHMMSS(currentWorkSeconds).replaceFirst(":", ":\n"),
855-
Math.round(taskbarCanvas.getWidth() / 2), Math.round(taskbarCanvas.getHeight() / 2) - 5);
836+
Math.round(taskbarCanvas.getWidth() / 2), Math.round(taskbarCanvas.getHeight() / 2) - 5.0);
856837

857838
final SnapshotParameters snapshotParameters = new SnapshotParameters();
858839
snapshotParameters.setFill(Color.TRANSPARENT);
@@ -896,4 +877,26 @@ public void setStage(final Stage primaryStage) {
896877
this.mainStage = primaryStage;
897878
}
898879

880+
@FXML
881+
public void addNewProject(final ActionEvent ae) {
882+
LOG.info("Add new project clicked");
883+
// TODO somewhat duplicate dialog of create and edit
884+
final Dialog<Project> dialog = setUpDialogProject("Create new project", "Create a new project");
885+
886+
final GridPane grid = setUpAddNewProjectGridPane("", Color.WHITE, true);
887+
888+
// TODO disable OK button if no name is set
889+
dialog.getDialogPane().setContent(grid);
890+
891+
dialogResultConverter(dialog, grid);
892+
mainStage.setAlwaysOnTop(false);
893+
final Optional<Project> result = dialog.showAndWait();
894+
mainStage.setAlwaysOnTop(true);
895+
896+
result.ifPresent(project -> {
897+
controller.addNewProject(project.getName(), project.isWork(), project.getColor(), project.getIndex());
898+
realignProjectList();
899+
});
900+
}
901+
899902
}

0 commit comments

Comments
 (0)