Skip to content

Commit e6892ad

Browse files
ddamkeddamke
authored andcommitted
remove getSvgPathWithXML and getNode and extract in own Class
1 parent 975befb commit e6892ad

File tree

1 file changed

+7
-44
lines changed

1 file changed

+7
-44
lines changed

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

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.time.LocalDateTime;
2424
import java.util.Optional;
2525

26+
import de.doubleslash.keeptime.common.*;
2627
import javafx.geometry.Bounds;
2728
import javafx.scene.Node;
2829
import javafx.scene.control.*;
@@ -32,12 +33,7 @@
3233
import org.springframework.beans.factory.annotation.Autowired;
3334
import org.springframework.stereotype.Component;
3435

35-
import de.doubleslash.keeptime.common.ColorHelper;
36-
import de.doubleslash.keeptime.common.DateFormatter;
37-
import de.doubleslash.keeptime.common.Resources;
3836
import de.doubleslash.keeptime.common.Resources.RESOURCE;
39-
import de.doubleslash.keeptime.common.ScreenPosHelper;
40-
import de.doubleslash.keeptime.common.StyleUtils;
4137
import de.doubleslash.keeptime.common.time.Interval;
4238
import de.doubleslash.keeptime.controller.Controller;
4339
import de.doubleslash.keeptime.exceptions.FXMLLoaderException;
@@ -85,6 +81,7 @@
8581
import javax.xml.parsers.DocumentBuilderFactory;
8682
import javax.xml.parsers.ParserConfigurationException;
8783

84+
8885
@Component
8986
public class ViewController {
9087
private static final Logger LOG = LoggerFactory.getLogger(ViewController.class);
@@ -133,18 +130,6 @@ public class ViewController {
133130
@FXML
134131
private Canvas canvas;
135132

136-
@FXML
137-
private Button calendarIcon;
138-
139-
@FXML
140-
private Button settingsIcon;
141-
142-
@FXML
143-
private Button minimizeIcon;
144-
145-
@FXML
146-
private Button closeIcon;
147-
148133
private ColorTimeLine mainColorTimeLine;
149134

150135
private class Delta {
@@ -214,25 +199,25 @@ private void initialize() throws ParserConfigurationException, IOException, SAXE
214199
calendarButton.setMaxSize(30, 30);
215200
calendarButton.setMinSize(30, 30);
216201
calendarButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
217-
calendarButton.setGraphic(getNode(getSvgPathWithXMl(RESOURCE.SVG_CALENDAR_DAYS_ICON)));
202+
calendarButton.setGraphic(SvgNodeProvider.getSvgNode(RESOURCE.SVG_CALENDAR_DAYS_ICON));
218203

219204
closeButton.textFillProperty().bind(fontColorProperty);
220205
closeButton.setMaxSize(30, 30);
221206
closeButton.setMinSize(30, 30);
222207
closeButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
223-
closeButton.setGraphic(getNode(getSvgPathWithXMl(RESOURCE.SVG_CLOSE_ICON)));
208+
closeButton.setGraphic(SvgNodeProvider.getSvgNode(RESOURCE.SVG_CLOSE_ICON));
224209

225210
settingsButton.textFillProperty().bind(fontColorProperty);
226211
settingsButton.setMaxSize(30, 30);
227212
settingsButton.setMinSize(30, 30);
228213
settingsButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
229-
settingsButton.setGraphic(getNode(getSvgPathWithXMl(RESOURCE.SVG_SETTINGS_ICON)));
214+
settingsButton.setGraphic(SvgNodeProvider.getSvgNode(RESOURCE.SVG_SETTINGS_ICON));
230215

231216
minimizeButton.textFillProperty().bind(fontColorProperty);
232217
minimizeButton.setMaxSize(30, 30);
233218
minimizeButton.setMinSize(30, 30);
234219
minimizeButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
235-
minimizeButton.setGraphic(getNode(getSvgPathWithXMl(RESOURCE.SVG_MINUS_ICON)));
220+
minimizeButton.setGraphic(SvgNodeProvider.getSvgNode(RESOURCE.SVG_MINUS_ICON));
236221

237222
final Runnable updateMainBackgroundColor = this::runUpdateMainBackgroundColor;
238223

@@ -340,29 +325,7 @@ private void initialize() throws ParserConfigurationException, IOException, SAXE
340325

341326
}
342327

343-
public String getSvgPathWithXMl(RESOURCE resource) throws ParserConfigurationException, IOException, SAXException {
344-
String svgPath;
345-
Document document;
346-
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
347-
DocumentBuilder db = dbf.newDocumentBuilder();
348-
349-
try (InputStream inputStream = Resources.getResource(resource).openStream()) {
350-
document = db.parse(inputStream);
351-
NodeList nodeList = document.getElementsByTagName("path");
352-
svgPath = nodeList.item(0).getAttributes().getNamedItem("d").getNodeValue();
353-
}
354-
return svgPath;
355-
}
356328

357-
private Node getNode(String s) {
358-
SVGPath IconSvg = new SVGPath();
359-
IconSvg.setContent(s);
360-
Bounds bounds = IconSvg.getBoundsInParent();
361-
double scale = Math.min(20 / bounds.getWidth(), 20 / bounds.getHeight());
362-
IconSvg.setScaleX(scale);
363-
IconSvg.setScaleY(scale);
364-
return IconSvg;
365-
}
366329

367330
private Dialog<Project> dialogResultConverter(final Dialog<Project> dialog,
368331
final ManageProjectController manageProjectController) {
@@ -382,7 +345,7 @@ private void settingsClicked() {
382345
settingsStage.show();
383346
}
384347

385-
private void calendarClicked() {
348+
private void calendarClicked(){
386349
LOG.info("Calendar clicked");
387350
this.mainStage.setAlwaysOnTop(false);
388351
reportStage.setAlwaysOnTop(true);

0 commit comments

Comments
 (0)