Refactored create svg Buttons
This commit is contained in:
parent
141d294b79
commit
0d626bb6dc
@ -12,7 +12,6 @@ import javafx.util.converter.LocalTimeStringConverter;
|
|||||||
import res.DataController;
|
import res.DataController;
|
||||||
import res.Event;
|
import res.Event;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -1,23 +1,18 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import com.jfoenix.svg.SVGGlyph;
|
import customUI.Button;
|
||||||
import com.jfoenix.svg.SVGGlyphLoader;
|
import customUI.Label;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.geometry.Bounds;
|
import javafx.geometry.Bounds;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import customUI.Button;
|
|
||||||
import customUI.Label;
|
|
||||||
import javafx.scene.control.ContentDisplay;
|
import javafx.scene.control.ContentDisplay;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.shape.SVGPath;
|
import javafx.scene.shape.SVGPath;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
@ -149,20 +144,13 @@ public class MainController {
|
|||||||
HBox btnHBox = new HBox();
|
HBox btnHBox = new HBox();
|
||||||
btnHBox.setAlignment(Pos.BOTTOM_RIGHT);
|
btnHBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
|
||||||
Button deleteBtn = new Button();
|
|
||||||
Group svgDel = new Group(
|
Group svgDel = new Group(
|
||||||
createPath("M0 0h24v24H0z", "transparent", "transparent"),
|
SvgBtnCreator.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("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",
|
||||||
"white", "lightgray")
|
"white", "lightgray")
|
||||||
);
|
);
|
||||||
Bounds boundsDel = svgDel.getBoundsInParent();
|
Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel);
|
||||||
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);
|
|
||||||
deleteBtn.getStyleClass().add("deleteEventBtn");
|
deleteBtn.getStyleClass().add("deleteEventBtn");
|
||||||
deleteBtn.setOnAction(e -> {
|
deleteBtn.setOnAction(e -> {
|
||||||
DataController dataController = new DataController();
|
DataController dataController = new DataController();
|
||||||
@ -170,20 +158,12 @@ public class MainController {
|
|||||||
updateEvents();
|
updateEvents();
|
||||||
});
|
});
|
||||||
|
|
||||||
Button editBtn = new Button();
|
|
||||||
Group svgEdit = new Group(
|
Group svgEdit = new Group(
|
||||||
createPath("M0 0h24v24H0z", "transparent", "transparent"),
|
SvgBtnCreator.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("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")
|
"white", "lightgray")
|
||||||
);
|
);
|
||||||
Bounds boundsEdit = svgEdit.getBoundsInParent();
|
Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit);
|
||||||
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);
|
|
||||||
editBtn.getStyleClass().add("editEventBtn");
|
editBtn.getStyleClass().add("editEventBtn");
|
||||||
editBtn.setOnAction(event1 -> {
|
editBtn.setOnAction(event1 -> {
|
||||||
try {
|
try {
|
||||||
@ -271,4 +251,5 @@ public class MainController {
|
|||||||
path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';');
|
path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';');
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
34
client/app/src/main/java/main/SvgBtnCreator.java
Normal file
34
client/app/src/main/java/main/SvgBtnCreator.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user