From 6dbf88bea9e18cf4927a625cce6c9820158eb998 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Mon, 9 Jan 2023 01:01:05 -0600 Subject: [PATCH] Replace Find/Replace slider with two CheckBoxes --- .../org/worlio/WorldsOrganizer/WorldsTab.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/worlio/WorldsOrganizer/WorldsTab.java b/src/main/java/org/worlio/WorldsOrganizer/WorldsTab.java index b27c633..154f0f6 100644 --- a/src/main/java/org/worlio/WorldsOrganizer/WorldsTab.java +++ b/src/main/java/org/worlio/WorldsOrganizer/WorldsTab.java @@ -792,7 +792,7 @@ public class WorldsTab { } private VBox getFindPane() { - Console.print("Initializing FindPane", 1, ConsoleType.INFO); + Console.print("Showing FindPane", 1, ConsoleType.INFO); Text findText = new Text("Find Text"); findText.setFont(Font.font("Verdana", FontWeight.NORMAL, FontPosture.REGULAR, 12)); TextField findInput = new TextField(); @@ -801,16 +801,13 @@ public class WorldsTab { replText.setFont(Font.font("Verdana", FontWeight.NORMAL, FontPosture.REGULAR, 12)); TextField replInput = new TextField(); - Slider selSlider = new Slider(-1,1,0); - selSlider.setMajorTickUnit(1); - selSlider.setMinorTickCount(0); - selSlider.setSnapToTicks(true); - Text labelTxt = new Text("Label"); - Text valueTxt = new Text("Value"); + CheckBox nameCheck = new CheckBox("Name"); + nameCheck.setSelected(true); + CheckBox valueCheck = new CheckBox("Value"); + valueCheck.setSelected(false); - HBox.setHgrow(selSlider, Priority.ALWAYS); - HBox.setHgrow(labelTxt, Priority.ALWAYS); - HBox.setHgrow(valueTxt, Priority.ALWAYS); + HBox.setHgrow(nameCheck, Priority.ALWAYS); + HBox.setHgrow(valueCheck, Priority.ALWAYS); GridPane findBar = new GridPane(); @@ -834,7 +831,8 @@ public class WorldsTab { WorldList replaced; final int index = ((TableView)content).getSelectionModel().getSelectedIndex(); - final double slider = selSlider.getValue(); + final boolean isName = nameCheck.isSelected(); + final boolean isValue = valueCheck.isSelected(); @Override public void execute() { @@ -842,9 +840,9 @@ public class WorldsTab { WorldList item = ((TableView)content).getSelectionModel().getSelectedItem(); if (item.getName().contains(findInput.getCharacters()) || item.getValue().contains(findInput.getCharacters())) { WorldTableItem tableItem = new WorldTableItem(((TableView) content).getItems().indexOf(item), item.getName(), item.getValue()); - if (selSlider.getValue() >= 0) + if (isValue) item.setValue(item.getValue().replace(findInput.getCharacters(), replInput.getCharacters())); - if (selSlider.getValue() <= 0) + if (isName) item.setName(item.getName().replace(findInput.getCharacters(), replInput.getCharacters())); Main.setStatusText("Replaced item"); replaced = tableItem; @@ -856,8 +854,8 @@ public class WorldsTab { @Override public void undo() { WorldList item = (WorldList)((TableView) content).getItems().get(index); - if (slider >= 0) item.setValue(replaced.getValue()); - if (slider <= 0) item.setName(replaced.getName()); + if (isValue) item.setValue(replaced.getValue()); + if (isName) item.setName(replaced.getName()); ((TableView) content).refresh(); setSaved(false); } @@ -869,7 +867,8 @@ public class WorldsTab { commandStack.doCommand(new Command() { final List replaced = new ArrayList<>(); - final double slider = selSlider.getValue(); + final boolean isName = nameCheck.isSelected(); + final boolean isValue = valueCheck.isSelected(); @Override public void execute() { @@ -879,8 +878,8 @@ public class WorldsTab { if (item.getName().contains(findInput.getCharacters()) || item.getValue().contains(findInput.getCharacters())) { count++; WorldTableItem tableItem = new WorldTableItem(((TableView)content).getItems().indexOf(item), item.getName(), item.getValue()); - if (selSlider.getValue() >= 0) item.setValue(item.getValue().replace(findInput.getCharacters(), replInput.getCharacters())); - if (selSlider.getValue() <= 0) item.setName(item.getName().replace(findInput.getCharacters(), replInput.getCharacters())); + if (isValue) item.setValue(item.getValue().replace(findInput.getCharacters(), replInput.getCharacters())); + if (isName) item.setName(item.getName().replace(findInput.getCharacters(), replInput.getCharacters())); replaced.add(tableItem); } } @@ -893,8 +892,8 @@ public class WorldsTab { public void undo() { for (WorldTableItem tableItem : replaced) { WorldList item = (WorldList)((TableView)content).getItems().get(tableItem.getIndex()); - if (slider >= 0) item.setValue(tableItem.getValue()); - if (slider <= 0) item.setName(tableItem.getName()); + if (valueCheck.isSelected()) item.setValue(tableItem.getValue()); + if (nameCheck.isSelected()) item.setName(tableItem.getName()); } ((TableView) content).refresh(); setSaved(false); @@ -912,7 +911,7 @@ public class WorldsTab { findBar.add(replText, 0, 1); findBar.add(replInput, 1, 1); - findBar.add(new HBox(labelTxt, selSlider, valueTxt), 0, 2); + findBar.add(new HBox(nameCheck, valueCheck), 0, 2); findBar.add(btns, 1, 2); GridPane.setHgrow(findInput, Priority.ALWAYS);