diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05027b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +//Netbeans +build/ +build.xml +dist/ +nbproject/ +manifest.mf +//Windows +Thumbs.db \ No newline at end of file diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..a0c6916 --- /dev/null +++ b/License.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Jelmerro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..365f473 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# F2Utility +An easy and effective batch file rename tool + +# Features +* TODO + +# License +The MIT License (MIT) + +Copyright (c) 2016 [Jelmerro](http://github.com/Jelmerro) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/f2utility/AboutAlert.java b/src/f2utility/AboutAlert.java new file mode 100644 index 0000000..96e251d --- /dev/null +++ b/src/f2utility/AboutAlert.java @@ -0,0 +1,46 @@ +package f2utility; + +import java.awt.Desktop; +import java.net.URI; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.image.ImageView; +import javafx.stage.Modality; + +/** + * + * @author Jelmerro + */ +class AboutAlert extends Alert { + + public AboutAlert() { + super(AlertType.INFORMATION); + initModality(Modality.APPLICATION_MODAL); + //Icon + ImageView icon = new ImageView(F2Utility.stage.getIcons().get(0)); + icon.maxHeight(80); + icon.setFitHeight(80); + icon.setPreserveRatio(true); + icon.setCache(true); + getDialogPane().setGraphic(icon); + //Content + setTitle("About"); + setHeaderText("F2Utility 0.1.0"); + setContentText("An easy and effective batch file rename tool\nCreated by Jelmerro\nMIT License"); + //Github button + Button githubButton = (Button) getDialogPane().lookupButton(ButtonType.OK); + githubButton.setText("Github"); + githubButton.setOnAction(e -> { + try { + Desktop.getDesktop().browse(new URI("https://github.com/Jelmerro/F2Utility")); + } catch (Exception ex) { + new Alert(Alert.AlertType.NONE, "URL: https://github.com/Jelmerro/F2Utility", ButtonType.CLOSE).showAndWait(); + } + e.consume(); + }); + setOnCloseRequest(e -> { + e.consume(); + }); + } +} diff --git a/src/f2utility/F2Utility.java b/src/f2utility/F2Utility.java new file mode 100644 index 0000000..72a7594 --- /dev/null +++ b/src/f2utility/F2Utility.java @@ -0,0 +1,79 @@ +package f2utility; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Base64; +import javafx.application.Application; +import javafx.embed.swing.SwingFXUtils; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.layout.BorderPane; +import javafx.stage.Stage; +import javax.imageio.ImageIO; + +/** + * Main class of the application creates all panes + * + * @author Jelmerro + */ +public class F2Utility extends Application { + + public static Stage stage; + + /** + * Application starts and decorates stage + * + * @param s Stage + */ + @Override + public void start(Stage s) { + stage = s; + BorderPane pane = new BorderPane(); + Scene scene = new Scene(pane); + //MenuBar top + MenuBar menubar = MenuBar.getInstance(); + pane.setTop(menubar); + //Files center + FileList fileList = FileList.getInstance(); + pane.setCenter(fileList); + //Tools bottom + ToolsBox toolPane = ToolsBox.getInstance(); + pane.setBottom(toolPane); + //Stage + stage.setTitle("F2Utility"); + stage.setScene(scene); + //Sets the size to a decent portion of the screen + stage.setMinWidth(935); + stage.setMinHeight(500); + stage.setWidth(935); + stage.setHeight(600); + //Adds icon from base64 and show the frame + String imageString = "iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAYAAACI7Fo9AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTCtCgrAAAAa0UlEQVR4Xu3dT5AU53kGcB84cNCBgw4cdOCgAwcOOuigg6pMUiQmMYlJhGOlTGxSpSRUgsvERTmKSylTpUqolJJQCXGITWKlgmNkIwlJWMIylpGFHSwhC0mIIAvBAgssy8KCtPxfQed9xp6tnm+e6ZnZ+d7+M/1M1W9r54Pvne6efr7Zme6v52NJkhRi/fr1C81as90cNNdMQoyaw2aPwf/dYnBD31VmibnPLDB3sMcSqTva6AVB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GtontM7NFG6Wc7MnH3AMMDveYrMOYBwwGB53FWE14DuewfWC2aKMMD9th5pqsw5jbDHYsneNQDvgLbj57LgdBG6XebEdrnuPQ6TCmznHwgcPDA50Y0wltFOmX7aCdDmNimjMGB53jkA1HdKL+uZ5GG0XyYDs2O4z5iGHnOAzrYUz8RfQg2z4x0UaRsrJQhIcxMTjglj7HoQqHMbFsGNTmsvWMjTaKDBMLU/ow5oOGneOQ12FMfK6Bzzuif+CWhTaK1JmFMDyMGZ7j0M9hTHwegYEEn1Xcxx7PX/Kx/weg8qI5ZY04OAAAAABJRU5ErkJggg=="; + stage.getIcons().add(Base64ToImage(imageString)); + stage.show(); + } + + /** + * Converts a base64 String to an Image + * + * @param base64 String + * @return image Image + */ + public Image Base64ToImage(String base64) { + try { + byte[] imageBytes = Base64.getDecoder().decode(base64); + Image image = SwingFXUtils.toFXImage(ImageIO.read(new ByteArrayInputStream(imageBytes)), null); + return image; + } catch (IOException ex) { + return null; + } + } + + /** + * + * @param args String[] + */ + public static void main(String[] args) { + Application.launch(args); + } +} diff --git a/src/f2utility/File.java b/src/f2utility/File.java new file mode 100644 index 0000000..016ece7 --- /dev/null +++ b/src/f2utility/File.java @@ -0,0 +1,114 @@ +package f2utility; + +import java.text.SimpleDateFormat; + +/** + * Extension on the File class + * + * @author Jelmerro + */ +public class File extends java.io.File { + + private String newName; + + /** + * Constructor for a new file + * + * @param pathname + */ + public File(String pathname) { + super(pathname); + newName = getName(); + + } + + /** + * Returns the current name, without the extension + * + * @return name String + */ + @Override + public String getName() { + try { + return super.getName().substring(0, super.getName().lastIndexOf(".")); + } catch (Exception ex) { + return super.getName(); + } + } + + /** + * Returns the extension + * + * @return ext String + */ + public String getExt() { + try { + String ext = super.getName().substring(super.getName().lastIndexOf(".") + 1); + if (ext.equals(super.getName())) { + return "-"; + } + return ext; + } catch (Exception ex) { + return "-"; + } + } + + /** + * Getter for newName + * + * @return newName String + */ + public String getNewName() { + return newName; + } + + /** + * Setter for newName + * + * @param name String + */ + public void setNewName(String name) { + newName = name; + } + + /** + * Rename method calls the renameTo with the path and extension if needed + * + * @return success Boolean + */ + public boolean rename() { + String ext = getExt(); + if (ext.equals("-")) { + return renameTo(new File(getParent() + separator + newName)); + } else { + return renameTo(new File(getParent() + separator + newName + "." + ext)); + } + } + + /** + * Gets a formatted version of the last modified date + * + * @return lastModified String + */ + public String getLastModified() { + return "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(lastModified()); + } + + /** + * Gets a formatted version of the length of the file + * + * @return size String + */ + public String getSize() { + if (isDirectory()) { + return "Folder"; + } + long length = length(); + if (length < 1000) { + return length + " B"; + } + int exp = (int) (Math.log(length) / Math.log(1000)); + String pre = ("kMGTPE").charAt(exp - 1) + "B"; + return String.format("%.1f %s", length / Math.pow(1000, exp), pre); + } +} diff --git a/src/f2utility/FileList.java b/src/f2utility/FileList.java new file mode 100644 index 0000000..75c2443 --- /dev/null +++ b/src/f2utility/FileList.java @@ -0,0 +1,230 @@ +package f2utility; + +import java.util.Arrays; +import java.util.List; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.SelectionMode; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.input.Dragboard; +import javafx.scene.input.TransferMode; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.shape.StrokeType; +import javafx.scene.text.Text; +import javafx.scene.text.TextAlignment; +import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; +import javafx.util.Callback; + +/** + * + * @author Jelmerro + */ +public class FileList extends TableView { + + private static FileList fileList; + + public static FileList getInstance() { + if (fileList == null) { + //FileList + fileList = new FileList(); + fileList.setEditable(true); + fileList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + fileList.setTableMenuButtonVisible(true); + //Startup dialog using placeholder + VBox placeholder = new VBox(50); + placeholder.setAlignment(Pos.CENTER); + Text welcomeLabel = new Text("Drag and drop your files or folder here to start\nOr browse to them to get going"); + welcomeLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 32;"); + welcomeLabel.setStrokeType(StrokeType.INSIDE); + welcomeLabel.setTextAlignment(TextAlignment.CENTER); + welcomeLabel.setFill(Color.web("#bbb")); + placeholder.getChildren().add(welcomeLabel); + //Buttons for file and folder choosers inside the placeholder + HBox buttonBox = new HBox(10); + buttonBox.setAlignment(Pos.CENTER); + //Files button + Button fileChooserButton = new Button("Files"); + fileChooserButton.setStyle("-fx-font-weight: bold; -fx-font-size: 20;"); + fileChooserButton.setTextFill(Color.web("#444")); + fileChooserButton.setOnAction(e -> { + fileList.showFileChooser(); + }); + buttonBox.getChildren().add(fileChooserButton); + //Folder button + Button dirChooserButton = new Button("Folder"); + dirChooserButton.setStyle("-fx-font-weight: bold; -fx-font-size: 20;"); + dirChooserButton.setTextFill(Color.web("#444")); + dirChooserButton.setOnAction(e -> { + fileList.showDirChooser(); + }); + buttonBox.getChildren().add(dirChooserButton); + //Add placeholder to list + placeholder.getChildren().add(buttonBox); + fileList.setPlaceholder(placeholder); + fileList.setStyle("-fx-background-color: white"); + //Columns + //Current name + TableColumn currentName = new TableColumn("Current name"); + currentName.setMinWidth(50); + currentName.setPrefWidth(200); + currentName.setCellValueFactory(new PropertyValueFactory<>("name")); + //New name + TableColumn newName = new TableColumn("New name"); + newName.setMinWidth(50); + newName.setPrefWidth(200); + newName.setCellValueFactory(new PropertyValueFactory<>("newName")); + //Path + TableColumn parent = new TableColumn("Path"); + parent.setMinWidth(50); + parent.setPrefWidth(300); + parent.setCellValueFactory(new PropertyValueFactory<>("parent")); + //Extension + TableColumn ext = new TableColumn("Extension"); + ext.setMinWidth(50); + ext.setPrefWidth(100); + ext.setCellValueFactory(new PropertyValueFactory<>("ext")); + //Size + TableColumn size = new TableColumn("Size"); + size.setMinWidth(50); + size.setPrefWidth(100); + size.setCellValueFactory(new PropertyValueFactory<>("size")); + //Last modified + TableColumn lastModified = new TableColumn("Modified"); + lastModified.setMinWidth(50); + lastModified.setPrefWidth(300); + lastModified.setVisible(false); + lastModified.setCellValueFactory(new PropertyValueFactory<>("lastModified")); + //Custom color for changed names + newName.setCellFactory(new Callback, TableCell>() { + + @Override + public TableCell call(TableColumn column) { + return new TableCell() { + + @Override + protected void updateItem(Object t, boolean bln) { + super.updateItem(t, bln); + try { + int currentIndex = indexProperty().getValue() < 0 ? 0 : indexProperty().getValue(); + File file = (File) column.getTableView().getItems().get(currentIndex); + if (!file.getName().equals(file.getNewName())) { + setTextFill(Color.GREEN); + setStyle("-fx-font-weight: bold;"); + } else { + setTextFill(Color.BLACK); + setStyle(""); + } + setText(t.toString()); + } catch (Exception e) { + setText(""); + } + } + + }; + } + }); + //Add all columns + fileList.getColumns().addAll(currentName, newName, parent, ext, size, lastModified); + //Drag and drop + //Detection of drag over the frame + fileList.setOnDragOver(e -> { + //Start accepting copy transfers + e.acceptTransferModes(TransferMode.COPY); + e.consume(); + }); + //Move inside of the frame with drag + fileList.setOnDragEntered(e -> { + //If the list is empty, color the background light blue + if (fileList.getItems().isEmpty()) { + fileList.setStyle("-fx-background-color: #ddfbff"); + } + e.consume(); + }); + //Cancel drag or move out of the frame + fileList.setOnDragExited(e -> { + //Reset the background color to white + fileList.setStyle("-fx-background-color: white"); + e.consume(); + }); + //Items drag and dropped + fileList.setOnDragDropped(e -> { + //List the files from the dragboard + Dragboard db = e.getDragboard(); + List files = db.getFiles(); + if (files.size() == 1 && files.get(0).isDirectory()) { + files = Arrays.asList(files.get(0).listFiles()); + } + fileList.addFiles(files); + e.consume(); + }); + } + return fileList; + } + + /** + * Configures and shows the folder chooser and adds the folder contents to the list afterwards + */ + public void showDirChooser() { + DirectoryChooser dirChooser = new DirectoryChooser(); + dirChooser.setTitle("Select folder"); + //Try to list the files from the folder and add them + try { + fileList.addFiles(Arrays.asList(dirChooser.showDialog(F2Utility.stage).listFiles())); + } catch (NullPointerException ex) { + + } + } + + /** + * Configures and shows the file chooser and adds the files to the list afterwards + */ + public void showFileChooser() { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Select files"); + //Try to add all selected files + try { + fileList.addFiles(fileChooser.showOpenMultipleDialog(F2Utility.stage)); + } catch (NullPointerException ex) { + + } + } + + /** + * Adds the provided files to the fileList, includes duplicate and null checks + * + * @param files List + */ + public void addFiles(List files) { + if (files != null) { + for (java.io.File file : files) { + boolean exists = false; + for (File listedFile : fileList.getItems()) { + if (file.getAbsolutePath().equals(listedFile.getAbsolutePath())) { + exists = true; + } + } + if (!exists) { + fileList.getItems().add(new File(file.getAbsolutePath())); + } + } + } + } + + /** + * Removes all the currently selected files from the list and clear the selection + */ + public void removeSelectedFiles() { + fileList.getItems().removeAll(fileList.getSelectionModel().getSelectedItems()); + fileList.getSelectionModel().clearSelection(); + } + + private FileList() { + super(); + } +} diff --git a/src/f2utility/MenuBar.java b/src/f2utility/MenuBar.java new file mode 100644 index 0000000..a8a0626 --- /dev/null +++ b/src/f2utility/MenuBar.java @@ -0,0 +1,69 @@ +package f2utility; + +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; + +/** + * + * @author Jelmerro + */ +public class MenuBar extends javafx.scene.control.MenuBar { + + private static MenuBar menuBar; + + public static MenuBar getInstance() { + if (menuBar == null) { + //Create the menuBar + menuBar = new MenuBar(); + //File menu + Menu menu = new Menu("Menu"); + menuBar.getMenus().addAll(menu); + //Open files item + MenuItem fileItem = new MenuItem("Open files"); + fileItem.setOnAction(e -> { + FileList.getInstance().showFileChooser(); + }); + fileItem.setAccelerator(KeyCombination.valueOf("O")); + //Open folder item + MenuItem folderItem = new MenuItem("Open folder"); + folderItem.setOnAction(e -> { + FileList.getInstance().showDirChooser(); + }); + folderItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN)); + //Delete item + MenuItem deleteItem = new MenuItem("Remove selected"); + deleteItem.setOnAction(e -> { + FileList.getInstance().removeSelectedFiles(); + }); + deleteItem.setAccelerator(KeyCombination.valueOf("DELETE")); + //clear item + MenuItem clearItem = new MenuItem("Clear list"); + clearItem.setOnAction(e -> { + FileList.getInstance().getItems().clear(); + }); + clearItem.setAccelerator(new KeyCodeCombination(KeyCode.DELETE, KeyCombination.SHIFT_DOWN)); + //About item + MenuItem aboutItem = new MenuItem("About"); + aboutItem.setOnAction(e -> { + new AboutAlert().showAndWait(); + }); + aboutItem.setAccelerator(KeyCombination.valueOf("A")); + //Exit item + MenuItem exitItem = new MenuItem("Exit"); + exitItem.setOnAction(e -> { + System.exit(0); + }); + exitItem.setAccelerator(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN)); + //Add all items + menu.getItems().addAll(folderItem, fileItem, deleteItem, clearItem, aboutItem, exitItem); + } + return menuBar; + } + + private MenuBar() { + super(); + } +} diff --git a/src/f2utility/ToolsBox.java b/src/f2utility/ToolsBox.java new file mode 100644 index 0000000..5a48aa5 --- /dev/null +++ b/src/f2utility/ToolsBox.java @@ -0,0 +1,145 @@ +package f2utility; + +import f2utility.tools.Add; +import f2utility.tools.Misc; +import f2utility.tools.Numbering; +import f2utility.tools.Regex; +import f2utility.tools.RemoveRange; +import f2utility.tools.RemoveStartEnd; +import f2utility.tools.Tool; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import javafx.geometry.Insets; +import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; + +/** + * + * @author Jelmerro + */ +public class ToolsBox extends HBox { + + private static ToolsBox toolsPane; + private static ArrayList tools; + + public static ToolsBox getInstance() { + if (toolsPane == null) { + //ToolsPane + toolsPane = new ToolsBox(5); + toolsPane.setMinHeight(100); + toolsPane.setMaxHeight(100); + toolsPane.setBackground(new Background(new BackgroundFill(Color.web("#EEE"), CornerRadii.EMPTY, Insets.EMPTY))); + toolsPane.setPadding(new Insets(5)); + //Tools + tools = new ArrayList<>(); + tools.add(new Regex()); + tools.add(new RemoveRange()); + tools.add(new RemoveStartEnd()); + tools.add(new Add()); + tools.add(new Numbering()); + tools.add(new Misc()); + //ButtonBox + VBox buttonBox = new VBox(6); + //Rename button + Button renameButton = new Button("Rename"); + renameButton.setMinSize(90, 42); + renameButton.setOnAction(e -> { + HashMap results = getInstance().rename(); + String failedItems = ""; + for (Entry entry : results.entrySet()) { + if (!entry.getValue()) { + File file = entry.getKey(); + String ext = file.getExt(); + if (ext.equals("-")) { + failedItems += file.getParent() + File.separator + file.getNewName() + "\n"; + } else { + failedItems += file.getParent() + File.separator + file.getNewName() + "." + ext + "\n"; + } + } + } + if (failedItems.isEmpty()) { + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Rename success"); + alert.setHeaderText("Succesfully renamed all files"); + alert.setContentText(results.size() + " files and folders were renamed with succes"); + alert.showAndWait(); + } else { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Rename error"); + alert.setHeaderText("Some files were not renamed correctly"); + TextArea list = new TextArea(failedItems); + alert.getDialogPane().setContent(list); + alert.showAndWait(); + } + }); + buttonBox.getChildren().add(renameButton); + //Reset button + Button resetButton = new Button("Reset"); + resetButton.setMinSize(90, 42); + resetButton.setOnAction(e -> { + for (Node n : tools) { + try { + Tool tool = (Tool) n; + tool.Reset(); + } catch (ClassCastException ex) { + + } + } + }); + buttonBox.getChildren().add(resetButton); + tools.add(buttonBox); + //Add all the tools + for (Node tool : tools) { + toolsPane.getChildren().add(tool); + } + } + return toolsPane; + } + + public HashMap rename() { + HashMap map = new HashMap<>(); + for (File file : FileList.getInstance().getItems()) { + boolean success = file.rename(); + if (success) { + String ext = file.getExt(); + if (ext.equals("-")) { + FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName())); + } else { + FileList.getInstance().getItems().set(FileList.getInstance().getItems().indexOf(file), new File(file.getParent() + File.separator + file.getNewName() + "." + ext)); + } + } + map.put(file, success); + } + return map; + } + + public void updateNewNames() { + for (File file : FileList.getInstance().getItems()) { + String name = file.getName(); + for (Node n : tools) { + try { + Tool tool = (Tool) n; + name = tool.processName(name); + } catch (ClassCastException ex) { + + } + } + file.setNewName(name); + } + FileList.getInstance().getColumns().get(0).setVisible(false); + FileList.getInstance().getColumns().get(0).setVisible(true); + } + + private ToolsBox(double d) { + super(d); + } +} diff --git a/src/f2utility/tools/Add.java b/src/f2utility/tools/Add.java new file mode 100644 index 0000000..a51af19 --- /dev/null +++ b/src/f2utility/tools/Add.java @@ -0,0 +1,140 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; + +/** + * + * @author Jelmerro + */ +public class Add extends GridPane implements Tool { + + private final Label label; + private final TextField prefix; + private final TextField suffix; + private final TextField insert; + private final TextField pos; + + public Add() { + super(); + Deactivate(); + //Label + label = new Label("Add"); + setMargin(label, new Insets(5, 5, 0, 5)); + add(label, 0, 0); + //Prefix field + prefix = new TextField(); + setMargin(prefix, new Insets(5, 5, 5, 5)); + prefix.setPromptText("Prefix"); + prefix.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + prefix.setMinWidth(100); + prefix.setMaxWidth(100); + add(prefix, 0, 1); + //Suffix field + suffix = new TextField(); + setMargin(suffix, new Insets(0, 5, 5, 5)); + suffix.setPromptText("Suffix"); + suffix.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + suffix.setMinWidth(100); + suffix.setMaxWidth(100); + add(suffix, 0, 2); + //Insert field + insert = new TextField(); + setMargin(insert, new Insets(5, 5, 5, 0)); + insert.setPromptText("Insert"); + insert.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + insert.setMinWidth(100); + insert.setMaxWidth(100); + add(insert, 1, 1); + //Suffix field + pos = new TextField(); + setMargin(pos, new Insets(0, 5, 5, 0)); + pos.setPromptText("Position"); + pos.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + pos.setMinWidth(100); + pos.setMaxWidth(100); + add(pos, 1, 2); + } + + @Override + public String processName(String name) { + if (!prefix.getText().isEmpty()) { + name = prefix.getText() + name; + } + if (!suffix.getText().isEmpty()) { + name = name + suffix.getText(); + } + if (!insert.getText().isEmpty() && !pos.getText().isEmpty()) { + try { + int position = Integer.parseInt(pos.getText()); + if (position > name.length()) { + return name + insert.getText(); + } else if (position > 0) { + return name.substring(0, position - 1) + insert.getText() + name.substring(position - 1); + } else { + return name; + } + } catch (Exception ex) { + return name; + } + } else { + return name; + } + } + + @Override + public void checkActive() { + if (!prefix.getText().isEmpty()) { + Activate(); + } else if (!suffix.getText().isEmpty()) { + Activate(); + } else if (!insert.getText().isEmpty() && !pos.getText().isEmpty()) { + try { + int position = Integer.parseInt(pos.getText()); + if (position > 0) { + Activate(); + } else { + Deactivate(); + } + } catch (Exception ex) { + Deactivate(); + } + } else { + Deactivate(); + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + prefix.setText(""); + suffix.setText(""); + insert.setText(""); + pos.setText(""); + checkActive(); + } +} diff --git a/src/f2utility/tools/Misc.java b/src/f2utility/tools/Misc.java new file mode 100644 index 0000000..6168235 --- /dev/null +++ b/src/f2utility/tools/Misc.java @@ -0,0 +1,129 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import java.util.ArrayList; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.geometry.Insets; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; + +/** + * + * @author Jelmerro + */ +public class Misc extends VBox implements Tool { + + private final Label label; + private final ComboBox mode; + private final CheckBox trim; + + public Misc() { + super(5); + Deactivate(); + //Label + label = new Label("Misc"); + setMargin(label, new Insets(5, 5, 0, 5)); + getChildren().add(label); + //Mode field + ArrayList list = new ArrayList<>(); + list.add("Same case"); + list.add("Lowercase"); + list.add("Uppercase"); + list.add("Sentence"); + list.add("Title"); + mode = new ComboBox(FXCollections.observableArrayList(list)); + mode.getSelectionModel().select(0); + setMargin(mode, new Insets(0, 5, 0, 5)); + mode.valueProperty().addListener((ObservableValue ov, Object t, Object t1) -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + mode.setMinWidth(100); + mode.setMaxWidth(100); + getChildren().add(mode); + //Trim field + trim = new CheckBox("Trim"); + setMargin(trim, new Insets(0, 5, 5, 5)); + trim.setOnAction(e -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + trim.setMinWidth(100); + trim.setMaxWidth(100); + getChildren().add(trim); + } + + @Override + public String processName(String name) { + if (mode.getSelectionModel().getSelectedItem().equals("Lowercase")) { + name = name.toLowerCase(); + } else if (mode.getSelectionModel().getSelectedItem().equals("Uppercase")) { + name = name.toUpperCase(); + } else if (mode.getSelectionModel().getSelectedItem().equals("Sentence")) { + try { + for (int i = 0; i < name.length(); i++) { + if (Character.isAlphabetic(name.charAt(i))) { + name = name.substring(0, i) + Character.toUpperCase(name.charAt(i)) + name.substring(i + 1).toLowerCase(); + break; + } + } + } catch (Exception ex) { + } + } else if (mode.getSelectionModel().getSelectedItem().equals("Title")) { + try { + String nameTemp = ""; + boolean capital = true; + for (int i = 0; i < name.length(); i++) { + if (capital) { + nameTemp += Character.toUpperCase(name.charAt(i)); + } else { + nameTemp += Character.toLowerCase(name.charAt(i)); + } + capital = false; + if (!Character.isAlphabetic(name.charAt(i)) && name.charAt(i) != '\'') { + capital = true; + } + } + name = nameTemp; + } catch (Exception ex) { + } + } + if (trim.isSelected()) { + name = name.trim(); + } + return name; + } + + @Override + public void checkActive() { + if (mode.getSelectionModel().getSelectedItem().equals("Same case")) { + if (trim.isSelected()) { + Activate(); + } else { + Deactivate(); + } + } else { + Activate(); + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + mode.getSelectionModel().select(0); + trim.setSelected(false); + checkActive(); + } +} diff --git a/src/f2utility/tools/Numbering.java b/src/f2utility/tools/Numbering.java new file mode 100644 index 0000000..b51efae --- /dev/null +++ b/src/f2utility/tools/Numbering.java @@ -0,0 +1,101 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import java.util.ArrayList; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.geometry.Insets; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; +import static javafx.scene.layout.VBox.setMargin; + +/** + * + * @author Jelmerro + */ +public class Numbering extends VBox implements Tool { + + private final Label label; + private final ComboBox mode; + private final TextField pad; + + public Numbering() { + super(5); + Deactivate(); + //Label + label = new Label("Numbering"); + setMargin(label, new Insets(5, 5, 0, 5)); + getChildren().add(label); + //Mode field + ArrayList list = new ArrayList<>(); + list.add("None"); + list.add("Prefix"); + list.add("Suffix"); + mode = new ComboBox(FXCollections.observableArrayList(list)); + mode.getSelectionModel().select(0); + setMargin(mode, new Insets(0, 5, 0, 5)); + mode.valueProperty().addListener((ObservableValue ov, Object t, Object t1) -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + mode.setMinWidth(100); + mode.setMaxWidth(100); + getChildren().add(mode); + //Padding field + pad = new TextField(); + setMargin(pad, new Insets(0, 5, 5, 5)); + pad.setPromptText("Padding"); + pad.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + pad.setMinWidth(100); + pad.setMaxWidth(100); + getChildren().add(pad); + } + + @Override + public String processName(String name) { + return name; + } + + @Override + public void checkActive() { + if (mode.getSelectionModel().getSelectedItem().equals("None")) { + Deactivate(); + } else { + try { + if (Integer.parseInt(pad.getText()) >= 0) { + Activate(); + } else { + Deactivate(); + } + } catch (Exception ex) { + if (pad.getText().isEmpty()) { + Activate(); + } else { + Deactivate(); + } + } + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + mode.getSelectionModel().select(0); + pad.setText(""); + checkActive(); + } +} diff --git a/src/f2utility/tools/Regex.java b/src/f2utility/tools/Regex.java new file mode 100644 index 0000000..a06993e --- /dev/null +++ b/src/f2utility/tools/Regex.java @@ -0,0 +1,89 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; + +/** + * + * @author Jelmerro + */ +public class Regex extends VBox implements Tool { + + private final Label label; + private final TextField match; + private final TextField replace; + + public Regex() { + super(5); + Deactivate(); + //Label + label = new Label("Regex or Replace"); + setMargin(label, new Insets(5, 5, 0, 5)); + getChildren().add(label); + //Match field + match = new TextField(); + setMargin(match, new Insets(0, 5, 0, 5)); + match.setPromptText("Match"); + match.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + match.setMinWidth(100); + match.setMaxWidth(100); + getChildren().add(match); + //Replacement field + replace = new TextField(); + setMargin(replace, new Insets(0, 5, 5, 5)); + replace.setPromptText("Replacement"); + replace.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + replace.setMinWidth(100); + replace.setMaxWidth(100); + getChildren().add(replace); + } + + @Override + public String processName(String name) { + try { + return name.replaceAll(match.getText(), replace.getText()); + } catch (Exception ex) { + return name; + } + } + + @Override + public void checkActive() { + try { + "".replaceAll(match.getText(), replace.getText()); + if (match.getText().equals(replace.getText())) { + Deactivate(); + } else { + Activate(); + } + } catch (Exception ex) { + Deactivate(); + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + match.setText(""); + replace.setText(""); + checkActive(); + } +} diff --git a/src/f2utility/tools/RemoveRange.java b/src/f2utility/tools/RemoveRange.java new file mode 100644 index 0000000..da2d8aa --- /dev/null +++ b/src/f2utility/tools/RemoveRange.java @@ -0,0 +1,100 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; + +/** + * + * @author Jelmerro + */ +public class RemoveRange extends VBox implements Tool { + + private final Label label; + private final TextField start; + private final TextField end; + + public RemoveRange() { + super(5); + Deactivate(); + //Label + label = new Label("Remove range"); + setMargin(label, new Insets(5, 5, 0, 5)); + getChildren().add(label); + //Start field + start = new TextField(); + setMargin(start, new Insets(0, 5, 0, 5)); + start.setPromptText("From"); + start.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + start.setMinWidth(100); + start.setMaxWidth(100); + getChildren().add(start); + //End field + end = new TextField(); + setMargin(end, new Insets(0, 5, 5, 5)); + end.setPromptText("To"); + end.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + end.setMinWidth(100); + end.setMaxWidth(100); + getChildren().add(end); + } + + @Override + public String processName(String name) { + try { + int startNum = Integer.parseInt(start.getText()); + int endNum = Integer.parseInt(end.getText()); + if (startNum <= endNum && startNum > 0 && endNum > 0) { + if (endNum > name.length()) { + return name.substring(0, startNum - 1); + } else { + return name.substring(0, startNum - 1) + name.substring(endNum); + } + } else { + return name; + } + } catch (Exception ex) { + return name; + } + } + + @Override + public void checkActive() { + try { + int startNum = Integer.parseInt(start.getText()); + int endNum = Integer.parseInt(end.getText()); + if (startNum <= endNum && startNum > 0 && endNum > 0) { + Activate(); + } else { + Deactivate(); + } + } catch (Exception ex) { + Deactivate(); + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + start.setText(""); + end.setText(""); + checkActive(); + } +} diff --git a/src/f2utility/tools/RemoveStartEnd.java b/src/f2utility/tools/RemoveStartEnd.java new file mode 100644 index 0000000..f6fa146 --- /dev/null +++ b/src/f2utility/tools/RemoveStartEnd.java @@ -0,0 +1,108 @@ +package f2utility.tools; + +import f2utility.ToolsBox; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; + +/** + * + * @author Jelmerro + */ +public class RemoveStartEnd extends VBox implements Tool { + + private final Label label; + private final TextField start; + private final TextField end; + + public RemoveStartEnd() { + super(5); + Deactivate(); + //Label + label = new Label("Remove start/end"); + setMargin(label, new Insets(5, 5, 0, 5)); + getChildren().add(label); + //Start field + start = new TextField(); + setMargin(start, new Insets(0, 5, 0, 5)); + start.setPromptText("Start"); + start.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + start.setMinWidth(100); + start.setMaxWidth(100); + getChildren().add(start); + //End field + end = new TextField(); + setMargin(end, new Insets(0, 5, 5, 5)); + end.setPromptText("End"); + end.setOnKeyReleased(t -> { + ToolsBox.getInstance().updateNewNames(); + checkActive(); + }); + end.setMinWidth(100); + end.setMaxWidth(100); + getChildren().add(end); + } + + @Override + public String processName(String name) { + try { + int startNum = Integer.parseInt(start.getText()); + if (startNum > 0) { + name = name.substring(Integer.parseInt(start.getText())); + } + } catch (Exception ex) { + } + try { + int startNum = Integer.parseInt(end.getText()); + if (startNum > 0) { + name = name.substring(0, name.length() - Integer.parseInt(end.getText())); + } + } catch (Exception ex2) { + } + return name; + } + + @Override + public void checkActive() { + try { + int startNum = Integer.parseInt(start.getText()); + if (startNum > 0) { + Activate(); + } else { + Deactivate(); + } + } catch (Exception ex) { + try { + int endNum = Integer.parseInt(end.getText()); + if (endNum > 0) { + Activate(); + } else { + Deactivate(); + } + } catch (Exception ex2) { + Deactivate(); + } + } + } + + @Override + public void Activate() { + setStyle(activated); + } + + @Override + public void Deactivate() { + setStyle(deactivated); + } + + @Override + public void Reset() { + start.setText(""); + end.setText(""); + checkActive(); + } +} diff --git a/src/f2utility/tools/Tool.java b/src/f2utility/tools/Tool.java new file mode 100644 index 0000000..93b772c --- /dev/null +++ b/src/f2utility/tools/Tool.java @@ -0,0 +1,21 @@ +package f2utility.tools; + +/** + * + * @author Jelmerro + */ +public interface Tool { + + public String activated = "-fx-border-color: #ADA;-fx-border-width: 2px;-fx-border-radius: 3px;"; + public String deactivated = "-fx-border-color: #bbb;-fx-border-width: 2px;-fx-border-radius: 3px;"; + + public String processName(String name); + + public void checkActive(); + + public void Activate(); + + public void Deactivate(); + + public void Reset(); +}