221 lines
7.7 KiB
Java
221 lines
7.7 KiB
Java
package mod_quicklaunch;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Map;
|
|
|
|
import javafx.event.ActionEvent;
|
|
import javafx.event.EventHandler;
|
|
import javafx.geometry.Insets;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.ScrollPane;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.Pane;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.scene.shape.Rectangle;
|
|
import javafx.stage.Stage;
|
|
import manager.ResourceManager;
|
|
|
|
public class ShortcutWindow extends AnchorPane {
|
|
|
|
|
|
Rectangle buttonBar;
|
|
Button addButton;
|
|
Button backButton;
|
|
Button editButton;
|
|
boolean editable = false;
|
|
Button saveButton;
|
|
Button trashButton;
|
|
|
|
Pane shortcutRootPane;
|
|
ScrollPane scrollPane;
|
|
private ArrayList<ShortcutEntryPane> shortcutEntries;
|
|
|
|
public ShortcutWindow(Map<String, String> currentShortcuts) {
|
|
|
|
this.setPrefWidth(600);
|
|
this.setMaxWidth(600);
|
|
this.setPrefHeight(400);
|
|
this.setMaxHeight(400);
|
|
|
|
buttonBar = new Rectangle(600,40);
|
|
buttonBar.setLayoutX(0);
|
|
buttonBar.setLayoutY(0);
|
|
buttonBar.setFill(Color.WHITE);
|
|
//buttonBar.setFill(Color.rgb(244, 244, 244));
|
|
|
|
addButton = new Button();
|
|
addButton.setPrefWidth(32);
|
|
addButton.setPrefHeight(32);
|
|
addButton.setLayoutX(120);
|
|
addButton.setLayoutY(5);
|
|
addButton.setPadding(Insets.EMPTY);
|
|
addButton.setStyle("-fx-background-color: transparent");
|
|
addButton.setGraphic(ResourceManager.getAddImage());//Background(new Background(new BackgroundImage(ResourceManager.getAddImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
addButton.setVisible(editable);
|
|
|
|
addButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
|
|
public void handle(ActionEvent event) {
|
|
shortcutEntries.add(new ShortcutEntryPane(shortcutEntries.size()*35));
|
|
shortcutEntries.get(shortcutEntries.size()-1).setEditable(true);
|
|
shortcutRootPane.setPrefHeight(shortcutRootPane.getPrefHeight()+35);
|
|
shortcutRootPane.getChildren().add(shortcutEntries.get(shortcutEntries.size()-1));
|
|
scrollPane.getContent().setVisible(false);
|
|
scrollPane.getContent().setVisible(true);
|
|
//Scrolling Thread :c
|
|
Thread t = new Thread(new Runnable() {
|
|
public void run() {
|
|
try {
|
|
Thread.sleep(200);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
scrollPane.setVvalue(1.0);
|
|
}
|
|
});
|
|
t.start();
|
|
shortcutEntries.get(shortcutEntries.size()-1).focus();
|
|
|
|
|
|
}
|
|
});
|
|
|
|
backButton = new Button();
|
|
backButton.setPrefWidth(32);
|
|
backButton.setPrefHeight(32);
|
|
backButton.setLayoutX(0);
|
|
backButton.setLayoutY(5);
|
|
backButton.setPadding(Insets.EMPTY);
|
|
backButton.setStyle("-fx-background-color: transparent");
|
|
backButton.setGraphic(ResourceManager.getBackImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getBackImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
backButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
|
|
public void handle(ActionEvent event) {
|
|
Stage thisStage = (Stage) ShortcutWindow.this.getScene().getWindow();
|
|
thisStage.close();
|
|
}
|
|
});
|
|
|
|
editButton = new Button();
|
|
editButton.setPrefWidth(32);
|
|
editButton.setPrefHeight(32);
|
|
editButton.setLayoutX(80);
|
|
editButton.setLayoutY(5);
|
|
editButton.setPadding(Insets.EMPTY);
|
|
editButton.setStyle("-fx-background-color: transparent");
|
|
editButton.setGraphic(ResourceManager.getEditImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getEditImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
editButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
|
|
public void handle(ActionEvent event) {
|
|
if(!editable) {
|
|
editButton.setGraphic(ResourceManager.getLockImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getLockImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
editable = true;
|
|
addButton.setVisible(editable);
|
|
trashButton.setVisible(editable);
|
|
saveButton.setGraphic(ResourceManager.getSaveImageUnsaved());
|
|
|
|
|
|
for(ShortcutEntryPane sep: shortcutEntries) {
|
|
sep.setEditable(editable);
|
|
}
|
|
}
|
|
else {
|
|
editButton.setGraphic(ResourceManager.getEditImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getEditImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
editable = false;
|
|
addButton.setVisible(editable);
|
|
trashButton.setVisible(editable);
|
|
saveButton.setGraphic(ResourceManager.getSaveImage());
|
|
for(ShortcutEntryPane sep: shortcutEntries) {
|
|
sep.setEditable(editable);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
saveButton = new Button();
|
|
saveButton.setPrefWidth(32);
|
|
saveButton.setPrefHeight(32);
|
|
saveButton.setLayoutX(40);
|
|
saveButton.setLayoutY(5);
|
|
saveButton.setPadding(Insets.EMPTY);
|
|
saveButton.setStyle("-fx-background-color: transparent");
|
|
saveButton.setGraphic(ResourceManager.getSaveImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getSaveImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
saveButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
|
|
public void handle(ActionEvent event) {
|
|
saveButton.setGraphic(ResourceManager.getSaveImage());
|
|
editButton.fire();
|
|
currentShortcuts.clear();
|
|
for (ShortcutEntryPane shortcutEntry : shortcutEntries) {
|
|
currentShortcuts.put(shortcutEntry.getShortcut(), shortcutEntry.getPath());
|
|
}
|
|
}
|
|
});
|
|
|
|
trashButton = new Button();
|
|
trashButton.setPrefWidth(32);
|
|
trashButton.setPrefHeight(32);
|
|
trashButton.setLayoutX(556);
|
|
trashButton.setLayoutY(5);
|
|
trashButton.setVisible(false);
|
|
trashButton.setPadding(Insets.EMPTY);
|
|
trashButton.setStyle("-fx-background-color: transparent");
|
|
trashButton.setGraphic(ResourceManager.getTrashImage());//setBackground(new Background(new BackgroundImage(ResourceManager.getTrashImage(),BackgroundRepeat.NO_REPEAT,BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,BackgroundSize.DEFAULT)));
|
|
trashButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
|
|
public void handle(ActionEvent event) {
|
|
boolean allRemoved = false;
|
|
while(!allRemoved) {
|
|
allRemoved = true;
|
|
for(int i = 0; i < shortcutEntries.size();i++) {
|
|
System.out.println(i);
|
|
if(shortcutEntries.get(i).isChecked()) {
|
|
allRemoved = false;
|
|
shortcutEntries.remove(i);
|
|
shortcutRootPane.getChildren().remove(i);
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
shortcutRootPane.setPrefHeight(shortcutEntries.size()*35);
|
|
int y = 0;
|
|
for(int i = 0;i < shortcutEntries.size();i++) {
|
|
shortcutEntries.get(i).setLayoutY(y);
|
|
y+=35;
|
|
}
|
|
}
|
|
});
|
|
|
|
shortcutRootPane = new Pane();
|
|
shortcutRootPane.setPrefSize(582 , currentShortcuts.size()*35);
|
|
shortcutRootPane.setLayoutX(0);
|
|
shortcutRootPane.setLayoutY(0);
|
|
|
|
scrollPane = new ScrollPane(shortcutRootPane);
|
|
scrollPane.setPrefSize(600, 360);
|
|
scrollPane.setLayoutX(0);
|
|
scrollPane.setLayoutY(40);
|
|
|
|
shortcutEntries = new ArrayList<>();
|
|
int y = 0;
|
|
for(String key : currentShortcuts.keySet()){
|
|
ShortcutEntryPane sep = new ShortcutEntryPane(y).setFieldContent(key, currentShortcuts.get(key));
|
|
shortcutEntries.add(sep);
|
|
shortcutRootPane.getChildren().add(sep);
|
|
y+=35;
|
|
}
|
|
|
|
this.getChildren().add(scrollPane);
|
|
this.getChildren().add(buttonBar);
|
|
this.getChildren().add(addButton);
|
|
this.getChildren().add(backButton);
|
|
this.getChildren().add(editButton);
|
|
this.getChildren().add(saveButton);
|
|
this.getChildren().add(trashButton);
|
|
|
|
}
|
|
|
|
}
|