Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Readme + Docs + minor fixes
Browse files Browse the repository at this point in the history
Added proper readme
Added all missing docs
ToolPane was refactored to ToolBox lastminute and was still called
toolsPane
TODO:
Numbering implementation
Reordering of the list must be possible...
  • Loading branch information
Jelmerro committed Aug 25, 2016
1 parent a08d433 commit 73baa4e
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 11 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/f2utility/AboutAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.stage.Modality;

/**
* Alert for the about section of the program, includes link to github page
*
* @author Jelmerro
*/
Expand Down
4 changes: 3 additions & 1 deletion src/f2utility/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Expand Down Expand Up @@ -63,7 +65,7 @@ public String getNewName() {
}

/**
* Setter for newName
* Setter for newName, used when looping over the tools
*
* @param name String
*/
Expand Down
4 changes: 4 additions & 0 deletions src/f2utility/FileList.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.util.Callback;

/**
* Table for all the files and folders
*
* @author Jelmerro
*/
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/f2utility/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.input.KeyCombination;

/**
* MenuBar containing all the actions regarding the fileList
*
* @author Jelmerro
*/
Expand Down
31 changes: 22 additions & 9 deletions src/f2utility/ToolsBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> 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());
Expand All @@ -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<File, Boolean> results = getInstance().rename();
//And a list is made for all the items that failed
String failedItems = "";
for (Entry<File, Boolean> entry : results.entrySet()) {
if (!entry.getValue()) {
Expand All @@ -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");
Expand Down Expand Up @@ -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<File, Boolean>
*/
public HashMap<File, Boolean> rename() {
HashMap<File, Boolean> map = new HashMap<>();
for (File file : FileList.getInstance().getItems()) {
Expand All @@ -122,6 +132,9 @@ public HashMap<File, Boolean> 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();
Expand Down
12 changes: 12 additions & 0 deletions src/f2utility/tools/Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.layout.GridPane;

/**
* Tool for adding a string: before, into or after the current name
*
* @author Jelmerro
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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()) {
Expand Down
12 changes: 12 additions & 0 deletions src/f2utility/tools/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.layout.VBox;

/**
* Misc tools: modify the case or trim it
*
* @author Jelmerro
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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))) {
Expand All @@ -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;
Expand All @@ -91,6 +100,7 @@ public String processName(String name) {
} catch (Exception ex) {
}
}
//Trims if selected
if (trim.isSelected()) {
name = name.trim();
}
Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/f2utility/tools/Numbering.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static javafx.scene.layout.VBox.setMargin;

/**
* Tool for numbering the items with optional padding
*
* @author Jelmerro
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/f2utility/tools/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.layout.VBox;

/**
* Replace certain strings or use regex to do so
*
* @author Jelmerro
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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())) {
Expand Down
9 changes: 9 additions & 0 deletions src/f2utility/tools/RemoveRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.layout.VBox;

/**
* Remove a range of characters
*
* @author Jelmerro
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Loading

0 comments on commit 73baa4e

Please sign in to comment.