Refactored create svg Buttons

This commit is contained in:
Marco Kühn 2022-01-20 13:49:07 +01:00
parent 141d294b79
commit 0d626bb6dc
3 changed files with 44 additions and 30 deletions

View File

@ -12,7 +12,6 @@ import javafx.util.converter.LocalTimeStringConverter;
import res.DataController;
import res.Event;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.FormatStyle;
import java.util.Locale;

View File

@ -1,23 +1,18 @@
package main;
import com.jfoenix.svg.SVGGlyph;
import com.jfoenix.svg.SVGGlyphLoader;
import customUI.Button;
import customUI.Label;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Bounds;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import customUI.Button;
import customUI.Label;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.SVGPath;
import javafx.stage.Modality;
import javafx.stage.Stage;
@ -149,20 +144,13 @@ public class MainController {
HBox btnHBox = new HBox();
btnHBox.setAlignment(Pos.BOTTOM_RIGHT);
Button deleteBtn = new Button();
Group svgDel = new Group(
createPath("M0 0h24v24H0z", "transparent", "transparent"),
createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",
SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"),
SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",
"white", "lightgray")
);
Bounds boundsDel = svgDel.getBoundsInParent();
double scaleDel = Math.min(20/boundsDel.getWidth(), 20 / boundsDel.getHeight());
svgDel.setScaleX(scaleDel);
svgDel.setScaleY(scaleDel);
deleteBtn.setGraphic(svgDel);
deleteBtn.setMaxSize(24, 24);
deleteBtn.setMinSize(24, 24);
deleteBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel);
deleteBtn.getStyleClass().add("deleteEventBtn");
deleteBtn.setOnAction(e -> {
DataController dataController = new DataController();
@ -170,20 +158,12 @@ public class MainController {
updateEvents();
});
Button editBtn = new Button();
Group svgEdit = new Group(
createPath("M0 0h24v24H0z", "transparent", "transparent"),
createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",
SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"),
SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",
"white", "lightgray")
);
Bounds boundsEdit = svgEdit.getBoundsInParent();
double scaleEdit = Math.min(20/boundsEdit.getWidth(), 20 / boundsEdit.getHeight());
svgEdit.setScaleX(scaleEdit);
svgEdit.setScaleY(scaleEdit);
editBtn.setGraphic(svgEdit);
editBtn.setMaxSize(24, 24);
editBtn.setMinSize(24, 24);
editBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit);
editBtn.getStyleClass().add("editEventBtn");
editBtn.setOnAction(event1 -> {
try {
@ -271,4 +251,5 @@ public class MainController {
path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';');
return path;
}
}

View File

@ -0,0 +1,34 @@
package main;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import customUI.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.shape.SVGPath;
public class SvgBtnCreator {
public static Button cretaeBtn(Group group) {
Button btn = new Button();
Bounds boundsDel = group.getBoundsInParent();
double scaleDel = Math.min(20 / boundsDel.getWidth(), 20 / boundsDel.getHeight());
group.setScaleX(scaleDel);
group.setScaleY(scaleDel);
btn.setGraphic(group);
btn.setMaxSize(24, 24);
btn.setMinSize(24, 24);
btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
return btn;
}
public static SVGPath createPath(String d, String fill, String hoverFill) {
SVGPath path = new SVGPath();
path.getStyleClass().add("svg");
path.setContent(d);
path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';');
return path;
}
}