Skip to content

Commit a452a39

Browse files
author
Martin Plieske
committed
removed some license headers; refactored BrowserHelper & FileOpenHelper
1 parent e51e458 commit a452a39

File tree

7 files changed

+26
-140
lines changed

7 files changed

+26
-140
lines changed

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

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,16 @@
22

33
package de.doubleslash.keeptime.common;
44

5-
import java.net.MalformedURLException;
6-
import java.net.URL;
7-
85
import org.slf4j.Logger;
96
import org.slf4j.LoggerFactory;
107

118
public class BrowserHelper {
129

1310
public static final Logger LOG = LoggerFactory.getLogger(BrowserHelper.class);
1411

15-
private URL urlToOpen;
16-
17-
public BrowserHelper() {}
18-
19-
public BrowserHelper(final String url) {
20-
this.urlToOpen = getURLfromString(url);
21-
}
22-
23-
public BrowserHelper(final URL url) {
24-
this.urlToOpen = url;
25-
}
26-
27-
public void openURL(final URL url) {
28-
executeCommand(url);
29-
}
30-
31-
public void openURL(final String urlString) {
32-
final URL url = getURLfromString(urlString);
33-
34-
executeCommand(url);
35-
}
36-
37-
public void openURL() {
38-
executeCommand();
39-
}
40-
41-
public void setURL(final URL url) {
42-
this.urlToOpen = url;
43-
}
44-
45-
public void setURL(final String url) {
46-
this.urlToOpen = getURLfromString(url);
47-
}
48-
49-
private void executeCommand() {
50-
final Runtime rt = Runtime.getRuntime();
51-
52-
if (OS.isWindows()) {
53-
executeCommandWindows(rt);
54-
} else if (OS.isLinux()) {
55-
executeCommandLinux(rt);
56-
} else {
57-
LOG.warn("OS is not supported");
58-
}
59-
}
12+
private BrowserHelper() {}
6013

61-
private void executeCommand(final URL url) {
14+
public static void openURL(final String url) {
6215
final Runtime rt = Runtime.getRuntime();
6316

6417
if (OS.isWindows()) {
@@ -70,45 +23,25 @@ private void executeCommand(final URL url) {
7023
}
7124
}
7225

73-
private void executeCommandWindows(final Runtime rt) {
26+
private static void executeCommandWindows(final Runtime rt, final String url) {
7427
try {
75-
rt.exec("rundll32 url.dll,FileProtocolHandler " + urlToOpen);
76-
} catch (final Exception e) {
77-
LOG.error(e.getMessage());
78-
}
79-
}
28+
final String command = "rundll32 url.dll,FileProtocolHandler " + url;
29+
LOG.debug("execute command: {}", command);
8030

81-
private void executeCommandWindows(final Runtime rt, final URL url) {
82-
try {
83-
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
31+
rt.exec(command);
8432
} catch (final Exception e) {
8533
LOG.error(e.getMessage());
8634
}
8735
}
8836

89-
private void executeCommandLinux(final Runtime rt) {
37+
private static void executeCommandLinux(final Runtime rt, final String url) {
9038
try {
91-
rt.exec("xdg-open " + urlToOpen);
92-
} catch (final Exception e) {
93-
LOG.error(e.getMessage());
94-
}
95-
}
39+
final String command = "xdg-open " + url;
40+
LOG.debug("execute command: {}", command);
9641

97-
private void executeCommandLinux(final Runtime rt, final URL url) {
98-
try {
99-
rt.exec("xdg-open " + url);
42+
rt.exec(command);
10043
} catch (final Exception e) {
10144
LOG.warn(e.getMessage());
10245
}
10346
}
104-
105-
private URL getURLfromString(final String urlString) {
106-
try {
107-
return new URL(urlString);
108-
} catch (final MalformedURLException e) {
109-
LOG.error(e.getMessage());
110-
}
111-
112-
return null;
113-
}
11447
}

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

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,10 @@ public class FileOpenHelper {
1111

1212
private static final Logger LOG = LoggerFactory.getLogger(FileOpenHelper.class);
1313

14-
private final File fileToOpen;
15-
16-
public FileOpenHelper(final File file) {
17-
this.fileToOpen = file;
18-
}
19-
20-
public FileOpenHelper(final String file) {
21-
this.fileToOpen = new File(file);
22-
}
23-
24-
public void openFile() {
25-
executeCommand();
26-
}
27-
28-
public static void openFile(final File file) {
29-
executeCommand(file);
30-
}
14+
private FileOpenHelper() {}
3115

3216
public static void openFile(final String fileString) {
3317
final File file = new File(fileString);
34-
35-
executeCommand(file);
36-
}
37-
38-
private void executeCommand() {
39-
final Runtime rt = Runtime.getRuntime();
40-
41-
if (OS.isWindows()) {
42-
executeCommandWindows(rt);
43-
} else if (OS.isLinux()) {
44-
executeCommandLinux(rt);
45-
} else {
46-
LOG.warn("OS is not supported");
47-
}
48-
}
49-
50-
private static void executeCommand(final File file) {
5118
final Runtime rt = Runtime.getRuntime();
5219

5320
if (OS.isWindows()) {
@@ -59,33 +26,23 @@ private static void executeCommand(final File file) {
5926
}
6027
}
6128

62-
private void executeCommandWindows(final Runtime rt) {
63-
try {
64-
rt.exec("rundll32 url.dll,FileProtocolHandler " + fileToOpen);
65-
} catch (final Exception e) {
66-
LOG.error(e.getMessage());
67-
}
68-
}
69-
7029
private static void executeCommandWindows(final Runtime rt, final File file) {
7130
try {
72-
rt.exec("rundll32 url.dll,FileProtocolHandler " + file);
73-
} catch (final Exception e) {
74-
LOG.error(e.getMessage());
75-
}
76-
}
31+
final String command = "rundll32 url.dll,FileProtocolHandler " + file;
32+
LOG.debug("executing command: {}", command);
7733

78-
private void executeCommandLinux(final Runtime rt) {
79-
try {
80-
rt.exec("xdg-open " + fileToOpen);
34+
rt.exec(command);
8135
} catch (final Exception e) {
8236
LOG.error(e.getMessage());
8337
}
8438
}
8539

8640
private static void executeCommandLinux(final Runtime rt, final File file) {
8741
try {
88-
rt.exec("xdg-open " + file);
42+
final String command = "xdg-open " + file;
43+
LOG.debug("executing command: {}", command);
44+
45+
rt.exec(command);
8946
} catch (final Exception e) {
9047
LOG.error(e.getMessage());
9148
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public class AboutController {
2929
private static final String GITHUB_ISSUE_PAGE = GITHUB_PAGE + "/issues";
3030
private static final Color HYPERLINK_COLOR = Color.rgb(0, 115, 170);
3131

32-
private final FileOpenHelper fileOpen = new FileOpenHelper();
33-
private final BrowserHelper browserOpen = new BrowserHelper();
34-
3532
@FXML
3633
private Hyperlink gitHubHyperlink;
3734

@@ -80,7 +77,7 @@ protected void updateItem(final String item, final boolean empty) {
8077
final Licenses license = row.getLicense();
8178
LOG.debug("License file name: {}", license);
8279

83-
fileOpen.openFile(license.getPath());
80+
FileOpenHelper.openFile(license.getPath());
8481
// TODO show error if file does not exist
8582
}
8683
});
@@ -98,13 +95,13 @@ protected void updateItem(final String item, final boolean empty) {
9895
LOG.debug("hyperlink setonaction");
9996
gitHubHyperlink.setOnAction(ae -> {
10097
LOG.debug("hyperlink clicked");
101-
browserOpen.openURL(GITHUB_PAGE);
98+
BrowserHelper.openURL(GITHUB_PAGE);
10299
});
103100

104101
LOG.debug("roportbugbutton setonaction");
105102
reportBugButton.setOnAction(ae -> {
106103
LOG.info("Clicked reportBugButton");
107-
browserOpen.openURL(GITHUB_ISSUE_PAGE);
104+
BrowserHelper.openURL(GITHUB_ISSUE_PAGE);
108105
});
109106
}
110107

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private class Delta {
136136

137137
private Stage mainStage;
138138
private Controller controller;
139-
private static Model model;
139+
private Model model;
140140

141141
public void setController(final Controller controller, final Model model) {
142142
this.controller = controller;
@@ -198,7 +198,7 @@ private void initialize() {
198198
addNewProjectButton.textFillProperty().bind(fontColorProperty);
199199

200200
// Add a light to colorize buttons
201-
// TODO is there a nicer way for this?
201+
// TODO #12 is there a nicer way for this?
202202
final Lighting lighting = new Lighting();
203203
lighting.lightProperty().bind(Bindings.createObjectBinding(() -> {
204204
final Color color = fontColorProperty.get();

src/main/resources/application.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Copyright 2019 doubleSlash Net Business GmbH
2-
31
# H2
42
spring.h2.console.enabled=true
53
spring.h2.console.path=/h2

src/main/resources/layouts/about.fxml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<!-- Copyright 2019 doubleSlash Net Business GmbH -->
4+
35
<?import javafx.scene.control.Button?>
46
<?import javafx.scene.control.Hyperlink?>
57
<?import javafx.scene.control.Label?>
@@ -42,7 +44,7 @@
4244
<Font name="Open Sans Regular" size="14.0" />
4345
</font>
4446
</Label>
45-
<Button fx:id="reportBugButton" focusTraversable="false" layoutX="378.0" layoutY="288.0" mnemonicParsing="false" prefWidth="120.0" text="report a bug">
47+
<Button fx:id="reportBugButton" focusTraversable="false" layoutX="378.0" layoutY="288.0" mnemonicParsing="false" prefWidth="110.0" text="report a bug">
4648
<font>
4749
<Font name="Open Sans Regular" size="14.0" />
4850
</font>

src/main/resources/logback.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- Copyright 2019 doubleSlash Net Business GmbH -->
21
<configuration>
32
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
43
<encoder>

0 commit comments

Comments
 (0)