diff --git a/README.md b/README.md index 365f473..eda3813 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,20 @@ +![f2utility](https://cloud.githubusercontent.com/assets/1696674/17949675/d8cb5cf6-6a56-11e6-8d6f-ef7f9de98220.png) # F2Utility An easy and effective batch file rename tool # Features -* TODO +* Replace text from your file names +* Use regex or regular strings to do so +* Remove a range of characters from the names +* Cut the first or last couple of characters +* Add a prefix or suffix +* Insert text at a certain position +* Number the files with optional padding (TODO) +* Change the case of the names in many ways +* Trim the file names +* Lists all the files which could not be renamed (if any) +* Easily determine which tools are active by looking at the border color +* Or simply drag and drop some files and folders to get started # License The MIT License (MIT) diff --git a/src/f2utility/AboutAlert.java b/src/f2utility/AboutAlert.java index 96e251d..fca60ad 100644 --- a/src/f2utility/AboutAlert.java +++ b/src/f2utility/AboutAlert.java @@ -9,6 +9,7 @@ import javafx.stage.Modality; /** + * Alert for the about section of the program, includes link to github page * * @author Jelmerro */ diff --git a/src/f2utility/File.java b/src/f2utility/File.java index 016ece7..c0543cd 100644 --- a/src/f2utility/File.java +++ b/src/f2utility/File.java @@ -18,6 +18,8 @@ public class File extends java.io.File { */ public File(String pathname) { super(pathname); + //The new name is initially equal to the current name + //setNewName is used to change this after any configs newName = getName(); } @@ -63,7 +65,7 @@ public String getNewName() { } /** - * Setter for newName + * Setter for newName, used when looping over the tools * * @param name String */ diff --git a/src/f2utility/FileList.java b/src/f2utility/FileList.java index 75c2443..ddb2ca0 100644 --- a/src/f2utility/FileList.java +++ b/src/f2utility/FileList.java @@ -22,6 +22,7 @@ import javafx.util.Callback; /** + * Table for all the files and folders * * @author Jelmerro */ @@ -110,6 +111,9 @@ public TableCell call(TableColumn column) { @Override protected void updateItem(Object t, boolean bln) { super.updateItem(t, bln); + //Try to change the color if the file named was changed + //Exceptions can happen when item is still loading + //These will simply be ignored and updated later try { int currentIndex = indexProperty().getValue() < 0 ? 0 : indexProperty().getValue(); File file = (File) column.getTableView().getItems().get(currentIndex); diff --git a/src/f2utility/MenuBar.java b/src/f2utility/MenuBar.java index a8a0626..e0efa1a 100644 --- a/src/f2utility/MenuBar.java +++ b/src/f2utility/MenuBar.java @@ -7,6 +7,7 @@ import javafx.scene.input.KeyCombination; /** + * MenuBar containing all the actions regarding the fileList * * @author Jelmerro */ diff --git a/src/f2utility/ToolsBox.java b/src/f2utility/ToolsBox.java index 5a48aa5..f9ef720 100644 --- a/src/f2utility/ToolsBox.java +++ b/src/f2utility/ToolsBox.java @@ -23,22 +23,23 @@ import javafx.scene.paint.Color; /** + * Horizontal Box containing all the tools for renaming * * @author Jelmerro */ public class ToolsBox extends HBox { - private static ToolsBox toolsPane; + private static ToolsBox toolsBox; private static ArrayList tools; public static ToolsBox getInstance() { - if (toolsPane == null) { + if (toolsBox == 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)); + toolsBox = new ToolsBox(5); + toolsBox.setMinHeight(100); + toolsBox.setMaxHeight(100); + toolsBox.setBackground(new Background(new BackgroundFill(Color.web("#EEE"), CornerRadii.EMPTY, Insets.EMPTY))); + toolsBox.setPadding(new Insets(5)); //Tools tools = new ArrayList<>(); tools.add(new Regex()); @@ -53,7 +54,9 @@ public static ToolsBox getInstance() { Button renameButton = new Button("Rename"); renameButton.setMinSize(90, 42); renameButton.setOnAction(e -> { + //Results of the rename process are checked here HashMap results = getInstance().rename(); + //And a list is made for all the items that failed String failedItems = ""; for (Entry entry : results.entrySet()) { if (!entry.getValue()) { @@ -66,6 +69,8 @@ public static ToolsBox getInstance() { } } } + //No failed items means the renaming was a success + //Otherwise a the list of failed items is shown if (failedItems.isEmpty()) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Rename success"); @@ -99,12 +104,17 @@ public static ToolsBox getInstance() { tools.add(buttonBox); //Add all the tools for (Node tool : tools) { - toolsPane.getChildren().add(tool); + toolsBox.getChildren().add(tool); } } - return toolsPane; + return toolsBox; } + /** + * Renames all the items and returns the list with results + * + * @return results HashMap + */ public HashMap rename() { HashMap map = new HashMap<>(); for (File file : FileList.getInstance().getItems()) { @@ -122,6 +132,9 @@ public HashMap rename() { return map; } + /** + * Loops over the tools and updates the list with the new name + */ public void updateNewNames() { for (File file : FileList.getInstance().getItems()) { String name = file.getName(); diff --git a/src/f2utility/tools/Add.java b/src/f2utility/tools/Add.java index a51af19..5fbadba 100644 --- a/src/f2utility/tools/Add.java +++ b/src/f2utility/tools/Add.java @@ -7,6 +7,7 @@ import javafx.scene.layout.GridPane; /** + * Tool for adding a string: before, into or after the current name * * @author Jelmerro */ @@ -18,6 +19,9 @@ public class Add extends GridPane implements Tool { private final TextField insert; private final TextField pos; + /** + * Constructor for the Add Tool + */ public Add() { super(); Deactivate(); @@ -73,12 +77,16 @@ public Add() { @Override public String processName(String name) { + //Adds the prefix if provided if (!prefix.getText().isEmpty()) { name = prefix.getText() + name; } + //Adds the suffix if provided if (!suffix.getText().isEmpty()) { name = name + suffix.getText(); } + //If a valid integer position is given, add the insert if provided + //Insert goes after the current name if the position is too high if (!insert.getText().isEmpty() && !pos.getText().isEmpty()) { try { int position = Integer.parseInt(pos.getText()); @@ -99,6 +107,10 @@ public String processName(String name) { @Override public void checkActive() { + //If a prefix is given, activate + //If a suffix is given, activate + //If a valid integer position is given and the insert text isn't empty, activate + //Else deactivate if (!prefix.getText().isEmpty()) { Activate(); } else if (!suffix.getText().isEmpty()) { diff --git a/src/f2utility/tools/Misc.java b/src/f2utility/tools/Misc.java index 6168235..c26ff76 100644 --- a/src/f2utility/tools/Misc.java +++ b/src/f2utility/tools/Misc.java @@ -11,6 +11,7 @@ import javafx.scene.layout.VBox; /** + * Misc tools: modify the case or trim it * * @author Jelmerro */ @@ -20,6 +21,9 @@ public class Misc extends VBox implements Tool { private final ComboBox mode; private final CheckBox trim; + /** + * Constructor for the Misc Tool + */ public Misc() { super(5); Deactivate(); @@ -58,11 +62,13 @@ public Misc() { @Override public String processName(String name) { + //Applies the selected case if any 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")) { + //Capitalize the first alphabetic character found and break try { for (int i = 0; i < name.length(); i++) { if (Character.isAlphabetic(name.charAt(i))) { @@ -73,6 +79,9 @@ public String processName(String name) { } catch (Exception ex) { } } else if (mode.getSelectionModel().getSelectedItem().equals("Title")) { + //Capitalize every alphabetic letter that follows a nonalphabetic letter + //Single quote ' being the exception to that + //Also capitalizes the very first character (if needed) try { String nameTemp = ""; boolean capital = true; @@ -91,6 +100,7 @@ public String processName(String name) { } catch (Exception ex) { } } + //Trims if selected if (trim.isSelected()) { name = name.trim(); } @@ -99,6 +109,8 @@ public String processName(String name) { @Override public void checkActive() { + //If a case mode is selected and/or the trim is checked, activate + //Else deactivate if (mode.getSelectionModel().getSelectedItem().equals("Same case")) { if (trim.isSelected()) { Activate(); diff --git a/src/f2utility/tools/Numbering.java b/src/f2utility/tools/Numbering.java index b51efae..ac715ec 100644 --- a/src/f2utility/tools/Numbering.java +++ b/src/f2utility/tools/Numbering.java @@ -12,6 +12,7 @@ import static javafx.scene.layout.VBox.setMargin; /** + * Tool for numbering the items with optional padding * * @author Jelmerro */ @@ -21,6 +22,9 @@ public class Numbering extends VBox implements Tool { private final ComboBox mode; private final TextField pad; + /** + * Constructor of the Numbering Tool + */ public Numbering() { super(5); Deactivate(); @@ -58,11 +62,15 @@ public Numbering() { @Override public String processName(String name) { + //#TODO return name; } @Override public void checkActive() { + //If any numbering mode is selected + //And the padding is either empty or a valid integer, activate + //Else deactivate if (mode.getSelectionModel().getSelectedItem().equals("None")) { Deactivate(); } else { diff --git a/src/f2utility/tools/Regex.java b/src/f2utility/tools/Regex.java index a06993e..812be6d 100644 --- a/src/f2utility/tools/Regex.java +++ b/src/f2utility/tools/Regex.java @@ -7,6 +7,7 @@ import javafx.scene.layout.VBox; /** + * Replace certain strings or use regex to do so * * @author Jelmerro */ @@ -16,6 +17,9 @@ public class Regex extends VBox implements Tool { private final TextField match; private final TextField replace; + /** + * Constructor for the Regex Tool + */ public Regex() { super(5); Deactivate(); @@ -49,6 +53,9 @@ public Regex() { @Override public String processName(String name) { + //Replace the input string with the output string + //Uses regex for the match if provided + //Exception catching is done to prevent any regex problems try { return name.replaceAll(match.getText(), replace.getText()); } catch (Exception ex) { @@ -58,6 +65,10 @@ public String processName(String name) { @Override public void checkActive() { + //Tries the replace the match with the replacement + //On errors, deactivate + //On succes with effect, activate + //On succes without any effect, deactivate try { "".replaceAll(match.getText(), replace.getText()); if (match.getText().equals(replace.getText())) { diff --git a/src/f2utility/tools/RemoveRange.java b/src/f2utility/tools/RemoveRange.java index da2d8aa..4691eda 100644 --- a/src/f2utility/tools/RemoveRange.java +++ b/src/f2utility/tools/RemoveRange.java @@ -7,6 +7,7 @@ import javafx.scene.layout.VBox; /** + * Remove a range of characters * * @author Jelmerro */ @@ -16,6 +17,9 @@ public class RemoveRange extends VBox implements Tool { private final TextField start; private final TextField end; + /** + * Constructor for the RemoveRange Tool + */ public RemoveRange() { super(5); Deactivate(); @@ -49,6 +53,8 @@ public RemoveRange() { @Override public String processName(String name) { + //Removes the provided range if valid + //Also checks for too high end integer and works around it try { int startNum = Integer.parseInt(start.getText()); int endNum = Integer.parseInt(end.getText()); @@ -68,6 +74,9 @@ public String processName(String name) { @Override public void checkActive() { + //If a valid start and end integer are provided + //And the end integer is higher than or equal to the start integer, activate + //Else deactivate try { int startNum = Integer.parseInt(start.getText()); int endNum = Integer.parseInt(end.getText()); diff --git a/src/f2utility/tools/RemoveStartEnd.java b/src/f2utility/tools/RemoveStartEnd.java index f6fa146..fc1f666 100644 --- a/src/f2utility/tools/RemoveStartEnd.java +++ b/src/f2utility/tools/RemoveStartEnd.java @@ -7,6 +7,7 @@ import javafx.scene.layout.VBox; /** + * Cut the first and/or last bunch of characters * * @author Jelmerro */ @@ -16,6 +17,9 @@ public class RemoveStartEnd extends VBox implements Tool { private final TextField start; private final TextField end; + /** + * Constructor for the RemoveStartEnd Tool + */ public RemoveStartEnd() { super(5); Deactivate(); @@ -49,6 +53,7 @@ public RemoveStartEnd() { @Override public String processName(String name) { + //Removes the first number of characters if start is a valid integer try { int startNum = Integer.parseInt(start.getText()); if (startNum > 0) { @@ -56,6 +61,7 @@ public String processName(String name) { } } catch (Exception ex) { } + //Removes the last number of characters if end is a valid integer try { int startNum = Integer.parseInt(end.getText()); if (startNum > 0) { @@ -68,6 +74,8 @@ public String processName(String name) { @Override public void checkActive() { + //If either of them is a valid integer above 0, activate + //Else deactivate try { int startNum = Integer.parseInt(start.getText()); if (startNum > 0) { diff --git a/src/f2utility/tools/Tool.java b/src/f2utility/tools/Tool.java index 93b772c..c162f58 100644 --- a/src/f2utility/tools/Tool.java +++ b/src/f2utility/tools/Tool.java @@ -1,6 +1,7 @@ package f2utility.tools; /** + * Interface Tool stores the style for the border and defines all the needed methods * * @author Jelmerro */ @@ -9,13 +10,31 @@ 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;"; + /** + * Rename the provided string using the tools capabilities + * + * @param name String + * @return newName String + */ public String processName(String name); + /** + * Similar to the process of renaming, but changes the border accordingly + */ public void checkActive(); + /** + * Activates the border/Colors the border green-ish + */ public void Activate(); + /** + * Deactivates the border/Colors the border gray-ish + */ public void Deactivate(); + /** + * Resets all the fields for the Tool and calls checkActive to style the border appropriately + */ public void Reset(); }