summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:40:33 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:40:33 -0400
commit889fac2bdf993dc86f64a8893c0260fdcf848acb (patch)
tree99ed08552efa86fdc5fdf4ddb8720d10e599fafe /BJC-Utils2/src/main/java/bjc/utils/gui
parent1656b02144446aeedebb3d1179e07ed99c01861c (diff)
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java84
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java78
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java58
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java50
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java22
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java41
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java32
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java4
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java57
20 files changed, 263 insertions, 258 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
index 8662f4e..7c487eb 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java
@@ -1,13 +1,13 @@
package bjc.utils.gui;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
import java.io.File;
import java.util.List;
import javax.swing.filechooser.FileFilter;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+
/**
* A file filter based on extensions.
*
@@ -20,7 +20,7 @@ public class ExtensionFileFilter extends FileFilter {
/**
* The list holding all filtered extensions
*/
- private IList<String> extensions;
+ private final IList<String> extensions;
/**
* Create a new filter only showing files with the specified extensions.
@@ -28,7 +28,7 @@ public class ExtensionFileFilter extends FileFilter {
* @param exts
* The extensions to show in this filter.
*/
- public ExtensionFileFilter(List<String> exts) {
+ public ExtensionFileFilter(final List<String> exts) {
extensions = new FunctionalList<>(exts);
}
@@ -38,13 +38,13 @@ public class ExtensionFileFilter extends FileFilter {
* @param exts
* The extensions to show in this filter.
*/
- public ExtensionFileFilter(String... exts) {
+ public ExtensionFileFilter(final String... exts) {
extensions = new FunctionalList<>(exts);
}
@Override
- public boolean accept(File pathname) {
- if(pathname == null) throw new NullPointerException("Pathname must not be null");
+ public boolean accept(final File pathname) {
+ if (pathname == null) throw new NullPointerException("Pathname must not be null");
return extensions.anyMatch(pathname.getName()::endsWith);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
index bb14327..59eb1c3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
@@ -1,7 +1,5 @@
package bjc.utils.gui;
-import bjc.utils.gui.layout.VLayout;
-
import java.awt.Component;
import java.awt.Frame;
import java.util.function.Function;
@@ -14,6 +12,8 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import bjc.utils.gui.layout.VLayout;
+
/**
* Utility class for getting simple input from the user.
*
@@ -36,13 +36,14 @@ public class SimpleDialogs {
* The upper integer bound to accept.
* @return A int within the specified bounds.
*/
- public static int getBoundedInt(Component parent, String title, String prompt, int lowerBound, int upperBound) {
+ public static int getBoundedInt(final Component parent, final String title, final String prompt,
+ final int lowerBound, final int upperBound) {
return getValue(parent, title, prompt, (strang) -> {
try {
- int value = Integer.parseInt(strang);
+ final int value = Integer.parseInt(strang);
return value < upperBound && value > lowerBound;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about the specifics of the
// exception, just
// that this value isn't good
@@ -68,28 +69,29 @@ public class SimpleDialogs {
* @return The choice the user picked, or null if they didn't pick one
*/
@SuppressWarnings("unchecked")
- public static <E> E getChoice(Frame parent, String title, String question, E... choices) {
- if(parent == null)
+ public static <E> E getChoice(final Frame parent, final String title, final String question,
+ final E... choices) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(question == null) throw new NullPointerException("Question must not be null");
+ else if (question == null) throw new NullPointerException("Question must not be null");
- JDialog chooser = new JDialog(parent, title, true);
+ final JDialog chooser = new JDialog(parent, title, true);
chooser.setLayout(new VLayout(2));
- JPanel questionPane = new JPanel();
+ final JPanel questionPane = new JPanel();
- JLabel questionText = new JLabel(question);
- JComboBox<E> questionChoices = new JComboBox<>(choices);
+ final JLabel questionText = new JLabel(question);
+ final JComboBox<E> questionChoices = new JComboBox<>(choices);
questionPane.add(questionText);
questionPane.add(questionChoices);
- JPanel buttonPane = new JPanel();
+ final JPanel buttonPane = new JPanel();
- JButton okButton = new JButton("Ok");
- JButton cancelButton = new JButton("Cancel");
+ final JButton okButton = new JButton("Ok");
+ final JButton cancelButton = new JButton("Cancel");
okButton.addActionListener((event) -> chooser.dispose());
cancelButton.addActionListener((event) -> chooser.dispose());
@@ -117,12 +119,12 @@ public class SimpleDialogs {
* The prompt to tell the user what to enter.
* @return A int.
*/
- public static int getInt(Component parent, String title, String prompt) {
+ public static int getInt(final Component parent, final String title, final String prompt) {
return getValue(parent, title, prompt, strang -> {
try {
Integer.parseInt(strang);
return true;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about this exception, just mark
// the value
// as not good
@@ -142,12 +144,12 @@ public class SimpleDialogs {
* The prompt to tell the user what to enter.
* @return A string.
*/
- public static String getString(Component parent, String title, String prompt) {
- if(parent == null)
+ public static String getString(final Component parent, final String title, final String prompt) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(prompt == null) throw new NullPointerException("Prompt must not be null");
+ else if (prompt == null) throw new NullPointerException("Prompt must not be null");
return JOptionPane.showInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE);
}
@@ -170,15 +172,15 @@ public class SimpleDialogs {
* The function to transform the string into a value.
* @return The value parsed from a string.
*/
- public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator,
- Function<String, E> transformer) {
- if(validator == null)
+ public static <E> E getValue(final Component parent, final String title, final String prompt,
+ final Predicate<String> validator, final Function<String, E> transformer) {
+ if (validator == null)
throw new NullPointerException("Validator must not be null");
- else if(transformer == null) throw new NullPointerException("Transformer must not be null");
+ else if (transformer == null) throw new NullPointerException("Transformer must not be null");
String input = getString(parent, title, prompt);
- while(!validator.test(input)) {
+ while (!validator.test(input)) {
showError(parent, "I/O Error", "Please enter a valid value");
input = getString(parent, title, prompt);
@@ -198,7 +200,7 @@ public class SimpleDialogs {
* The prompt to tell the user what to enter.
* @return A whole number.
*/
- public static int getWhole(Component parent, String title, String prompt) {
+ public static int getWhole(final Component parent, final String title, final String prompt) {
return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE);
}
@@ -213,14 +215,14 @@ public class SimpleDialogs {
* The question to ask the user.
* @return True if the user said yes, false otherwise.
*/
- public static boolean getYesNo(Component parent, String title, String question) {
- if(parent == null)
+ public static boolean getYesNo(final Component parent, final String title, final String question) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(question == null) throw new NullPointerException("Question must not be null");
+ else if (question == null) throw new NullPointerException("Question must not be null");
- int result = JOptionPane.showConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION);
+ final int result = JOptionPane.showConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION);
return result == JOptionPane.YES_OPTION ? true : false;
}
@@ -235,12 +237,12 @@ public class SimpleDialogs {
* @param message
* The error to show the user.
*/
- public static void showError(Component parent, String title, String message) {
- if(parent == null)
+ public static void showError(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Error message must not be null");
+ else if (message == null) throw new NullPointerException("Error message must not be null");
JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
}
@@ -255,12 +257,12 @@ public class SimpleDialogs {
* @param message
* Show the message for this dialog
*/
- public static void showMessage(Component parent, String title, String message) {
- if(parent == null)
+ public static void showMessage(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Message must not be null");
+ else if (message == null) throw new NullPointerException("Message must not be null");
JOptionPane.showMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
index cd7c180..7da0bd8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
@@ -1,12 +1,12 @@
package bjc.utils.gui;
-import bjc.utils.exceptions.FileNotChosenException;
-
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
+import bjc.utils.exceptions.FileNotChosenException;
+
/**
* Utility class for easily prompting user for files.
*
@@ -16,19 +16,19 @@ import javax.swing.JFileChooser;
*
*/
public class SimpleFileChooser {
- private static File doOpenFile(Component parent, String title, JFileChooser files) {
- if(title == null) throw new NullPointerException("Title must not be null");
+ private static File doOpenFile(final Component parent, final String title, final JFileChooser files) {
+ if (title == null) throw new NullPointerException("Title must not be null");
files.setDialogTitle(title);
boolean success = false;
- while(!success) {
+ while (!success) {
try {
maybeDoOpenFile(parent, files);
success = true;
- } catch(FileNotChosenException fncx) {
+ } catch (final FileNotChosenException fncx) {
// We don't care about specifics
SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to open");
}
@@ -37,25 +37,23 @@ public class SimpleFileChooser {
return files.getSelectedFile();
}
- private static File doSaveFile(Component parent, String title, JFileChooser files) {
- if(title == null) throw new NullPointerException("Title must not be null");
+ private static File doSaveFile(final Component parent, final String title, final JFileChooser files) {
+ if (title == null) throw new NullPointerException("Title must not be null");
files.setDialogTitle(title);
- boolean success = false;
+ final boolean success = false;
- while(!success) {
+ while (!success) {
try {
maybeDoSaveFile(parent, files);
return files.getSelectedFile();
- } catch(FileNotChosenException fncex) {
+ } catch (final FileNotChosenException fncex) {
// We don't care about specifics
SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to save to");
}
}
-
- return files.getSelectedFile();
}
/**
@@ -68,8 +66,8 @@ public class SimpleFileChooser {
* The title of the dialog to prompt with.
* @return The file the user has chosen.
*/
- public static File getOpenFile(Component parent, String title) {
- JFileChooser files = new JFileChooser();
+ public static File getOpenFile(final Component parent, final String title) {
+ final JFileChooser files = new JFileChooser();
return doOpenFile(parent, title, files);
}
@@ -86,8 +84,8 @@ public class SimpleFileChooser {
* The list of file extensions the file should have.
* @return The file the user has chosen.
*/
- public static File getOpenFile(Component parent, String title, String... extensions) {
- JFileChooser files = new JFileChooser();
+ public static File getOpenFile(final Component parent, final String title, final String... extensions) {
+ final JFileChooser files = new JFileChooser();
files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
@@ -103,8 +101,8 @@ public class SimpleFileChooser {
* The title of the dialog to prompt with.
* @return The file the user chose.
*/
- public static File getSaveFile(Component parent, String title) {
- JFileChooser files = new JFileChooser();
+ public static File getSaveFile(final Component parent, final String title) {
+ final JFileChooser files = new JFileChooser();
return doSaveFile(parent, title, files);
}
@@ -120,32 +118,34 @@ public class SimpleFileChooser {
* The extensions of the files the user can choose.
* @return The file the user chose.
*/
- public static File getSaveFile(Component parent, String title, String... extensions) {
- JFileChooser files = new JFileChooser();
+ public static File getSaveFile(final Component parent, final String title, final String... extensions) {
+ final JFileChooser files = new JFileChooser();
files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
return doSaveFile(parent, title, files);
}
- private static void maybeDoOpenFile(Component parent, JFileChooser files) throws FileNotChosenException {
- if(parent == null)
+ private static void maybeDoOpenFile(final Component parent, final JFileChooser files)
+ throws FileNotChosenException {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(files == null) throw new NullPointerException("File chooser must not be null");
+ else if (files == null) throw new NullPointerException("File chooser must not be null");
- int result = files.showSaveDialog(parent);
+ final int result = files.showSaveDialog(parent);
- if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
+ if (result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
}
- private static void maybeDoSaveFile(Component parent, JFileChooser files) throws FileNotChosenException {
- if(parent == null)
+ private static void maybeDoSaveFile(final Component parent, final JFileChooser files)
+ throws FileNotChosenException {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(files == null) throw new NullPointerException("File chooser must not be null");
+ else if (files == null) throw new NullPointerException("File chooser must not be null");
- int result = files.showSaveDialog(parent);
+ final int result = files.showSaveDialog(parent);
- if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
+ if (result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
}
/**
@@ -157,15 +157,15 @@ public class SimpleFileChooser {
* The title of the dialog to prompt with.
* @return The file if the user chose one or null if they didn't.
*/
- public static File maybeOpenFile(Component parent, String title) {
- if(title == null) throw new NullPointerException("Title must not be null");
+ public static File maybeOpenFile(final Component parent, final String title) {
+ if (title == null) throw new NullPointerException("Title must not be null");
- JFileChooser files = new JFileChooser();
+ final JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
try {
maybeDoOpenFile(parent, files);
- } catch(FileNotChosenException fncex) {
+ } catch (final FileNotChosenException fncex) {
// We don't care about specifics
}
@@ -181,15 +181,15 @@ public class SimpleFileChooser {
* The title of the dialog to prompt with.
* @return The file if the user chose one or null if they didn't.
*/
- public static File maybeSaveFile(Component parent, String title) {
- if(title == null) throw new NullPointerException("Title must not be null");
+ public static File maybeSaveFile(final Component parent, final String title) {
+ if (title == null) throw new NullPointerException("Title must not be null");
- JFileChooser files = new JFileChooser();
+ final JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
try {
maybeDoSaveFile(parent, files);
- } catch(FileNotChosenException fncex) {
+ } catch (final FileNotChosenException fncex) {
// We don't care about specifics
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
index d7bb700..5237557 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
@@ -30,13 +30,14 @@ public class SimpleInternalDialogs {
* The upper integer bound to accept.
* @return A int within the specified bounds.
*/
- public static int getBoundedInt(Component parent, String title, String prompt, int lowerBound, int upperBound) {
+ public static int getBoundedInt(final Component parent, final String title, final String prompt,
+ final int lowerBound, final int upperBound) {
return getValue(parent, title, prompt, (strang) -> {
try {
- int value = Integer.parseInt(strang);
+ final int value = Integer.parseInt(strang);
return value < upperBound && value > lowerBound;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about the specifics of the
// exception, just
// that this value isn't good
@@ -56,12 +57,12 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A int.
*/
- public static int getInt(Component parent, String title, String prompt) {
+ public static int getInt(final Component parent, final String title, final String prompt) {
return getValue(parent, title, prompt, strang -> {
try {
Integer.parseInt(strang);
return true;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about this exception, just mark
// the value
// as not good
@@ -81,12 +82,12 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A string.
*/
- public static String getString(Component parent, String title, String prompt) {
- if(parent == null)
+ public static String getString(final Component parent, final String title, final String prompt) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(prompt == null) throw new NullPointerException("Prompt must not be null");
+ else if (prompt == null) throw new NullPointerException("Prompt must not be null");
return JOptionPane.showInternalInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE);
}
@@ -109,15 +110,15 @@ public class SimpleInternalDialogs {
* The function to transform the string into a value.
* @return The value parsed from a string.
*/
- public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator,
- Function<String, E> transformer) {
- if(validator == null)
+ public static <E> E getValue(final Component parent, final String title, final String prompt,
+ final Predicate<String> validator, final Function<String, E> transformer) {
+ if (validator == null)
throw new NullPointerException("Validator must not be null");
- else if(transformer == null) throw new NullPointerException("Transformer must not be null");
+ else if (transformer == null) throw new NullPointerException("Transformer must not be null");
String strang = getString(parent, title, prompt);
- while(!validator.test(strang)) {
+ while (!validator.test(strang)) {
showError(parent, "I/O Error", "Please enter a valid value");
strang = getString(parent, title, prompt);
@@ -137,7 +138,7 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A whole number.
*/
- public static int getWhole(Component parent, String title, String prompt) {
+ public static int getWhole(final Component parent, final String title, final String prompt) {
return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE);
}
@@ -152,14 +153,15 @@ public class SimpleInternalDialogs {
* The question to ask the user.
* @return True if the user said yes, false otherwise.
*/
- public static boolean getYesNo(Component parent, String title, String question) {
- if(parent == null)
+ public static boolean getYesNo(final Component parent, final String title, final String question) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(question == null) throw new NullPointerException("Question must not be null");
+ else if (question == null) throw new NullPointerException("Question must not be null");
- int result = JOptionPane.showInternalConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION);
+ final int result = JOptionPane.showInternalConfirmDialog(parent, question, title,
+ JOptionPane.YES_NO_OPTION);
return result == JOptionPane.YES_OPTION ? true : false;
}
@@ -174,12 +176,12 @@ public class SimpleInternalDialogs {
* @param message
* The error to show the user.
*/
- public static void showError(Component parent, String title, String message) {
- if(parent == null)
+ public static void showError(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Error message must not be null");
+ else if (message == null) throw new NullPointerException("Error message must not be null");
JOptionPane.showInternalMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
}
@@ -194,12 +196,12 @@ public class SimpleInternalDialogs {
* @param message
* Show the message for this dialog
*/
- public static void showMessage(Component parent, String title, String message) {
- if(parent == null)
+ public static void showMessage(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Message must not be null");
+ else if (message == null) throw new NullPointerException("Message must not be null");
JOptionPane.showInternalMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
index 9fdf18f..afb498e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
@@ -24,7 +24,7 @@ public class SimpleInternalFrame extends JInternalFrame {
* @param title
* The title of the internal frame
*/
- public SimpleInternalFrame(String title) {
+ public SimpleInternalFrame(final String title) {
super(title);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java
index e469f2f..411d0db 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java
@@ -21,8 +21,8 @@ public class SimpleJList {
* The list to populate the JList with.
* @return A JList populated with the elements from ls.
*/
- public static <E> JList<E> buildFromList(Iterable<E> source) {
- if(source == null) throw new NullPointerException("Source must not be null");
+ public static <E> JList<E> buildFromList(final Iterable<E> source) {
+ if (source == null) throw new NullPointerException("Source must not be null");
return new JList<>(buildModel(source));
}
@@ -37,10 +37,10 @@ public class SimpleJList {
* The list to fill the list model from.
* @return A list model populated with the elements from ls.
*/
- public static <E> ListModel<E> buildModel(Iterable<E> source) {
- if(source == null) throw new NullPointerException("Source must not be null");
+ public static <E> ListModel<E> buildModel(final Iterable<E> source) {
+ if (source == null) throw new NullPointerException("Source must not be null");
- DefaultListModel<E> defaultModel = new DefaultListModel<>();
+ final DefaultListModel<E> defaultModel = new DefaultListModel<>();
source.forEach(defaultModel::addElement);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java
index 723fad0..9b01507 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java
@@ -19,7 +19,7 @@ public class SimpleTitledBorder extends TitledBorder {
* @param title
* The title for the border.
*/
- public SimpleTitledBorder(String title) {
+ public SimpleTitledBorder(final String title) {
super(new EtchedBorder(), title);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
index c63abfd..fbc58ed 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
@@ -12,7 +12,7 @@ import javax.swing.JTextArea;
* @author Levente S\u00e1ntha (lsantha@users.sourceforge.net)
*/
public class TextAreaOutputStream extends OutputStream {
- private JTextArea textArea;
+ private final JTextArea textArea;
/**
* Create a new output stream attached to a textarea
@@ -20,15 +20,15 @@ public class TextAreaOutputStream extends OutputStream {
* @param console
* The textarea to write to
*/
- public TextAreaOutputStream(JTextArea console) {
+ public TextAreaOutputStream(final JTextArea console) {
this.textArea = console;
}
@Override
- public void write(int b) throws IOException {
+ public void write(final int b) throws IOException {
textArea.append("" + (char) b);
- if(b == '\n') {
+ if (b == '\n') {
textArea.repaint();
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
index 68978e7..eb60ae2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
@@ -1,12 +1,12 @@
package bjc.utils.gui.awt;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
import java.io.File;
import java.io.FilenameFilter;
import java.util.List;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+
/**
* Filter a set of filenames by extension.
*
@@ -19,7 +19,7 @@ public class ExtensionFileFilter implements FilenameFilter {
/**
* The list of extensions to filter
*/
- private IList<String> extensions;
+ private final IList<String> extensions;
/**
* Create a new filter only showing files with the specified extensions.
@@ -27,8 +27,8 @@ public class ExtensionFileFilter implements FilenameFilter {
* @param exts
* The extensions to show in this filter.
*/
- public ExtensionFileFilter(List<String> exts) {
- if(exts == null) throw new NullPointerException("Extensions must not be null");
+ public ExtensionFileFilter(final List<String> exts) {
+ if (exts == null) throw new NullPointerException("Extensions must not be null");
extensions = new FunctionalList<>(exts);
}
@@ -39,12 +39,12 @@ public class ExtensionFileFilter implements FilenameFilter {
* @param exts
* The extensions to show in this filter.
*/
- public ExtensionFileFilter(String... exts) {
+ public ExtensionFileFilter(final String... exts) {
extensions = new FunctionalList<>(exts);
}
@Override
- public boolean accept(File directory, String name) {
+ public boolean accept(final File directory, final String name) {
return extensions.anyMatch(name::endsWith);
}
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
index 47f76b8..77a4a59 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
@@ -1,12 +1,12 @@
package bjc.utils.gui.awt;
-import bjc.utils.gui.SimpleDialogs;
-
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.File;
import java.io.FilenameFilter;
+import bjc.utils.gui.SimpleDialogs;
+
/**
* A simple way to get the user to pick a file
*
@@ -25,7 +25,7 @@ public class SimpleFileDialog {
* The title of the file picker
* @return The file the user picked
*/
- public static File getOpenFile(Frame parent, String title) {
+ public static File getOpenFile(final Frame parent, final String title) {
return getOpenFile(parent, title, (String[]) null);
}
@@ -40,21 +40,21 @@ public class SimpleFileDialog {
* The extensions to accept as valid
* @return The file the user picked
*/
- public static File getOpenFile(Frame parent, String title, String... extensions) {
- if(parent == null)
+ public static File getOpenFile(final Frame parent, final String title, final String... extensions) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null) throw new NullPointerException("Title must not be null");
+ else if (title == null) throw new NullPointerException("Title must not be null");
- FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
+ final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
- if(extensions != null) {
- FilenameFilter filter = new ExtensionFileFilter(extensions);
+ if (extensions != null) {
+ final FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
chooser.setVisible(true);
- while(chooser.getFile() == null) {
+ while (chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open.");
chooser.setVisible(true);
}
@@ -73,22 +73,22 @@ public class SimpleFileDialog {
* The extensions to accept as valid
* @return The file the user picked
*/
- public static File[] getOpenFiles(Frame parent, String title, String... extensions) {
- if(parent == null)
+ public static File[] getOpenFiles(final Frame parent, final String title, final String... extensions) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null) throw new NullPointerException("Title must not be null");
+ else if (title == null) throw new NullPointerException("Title must not be null");
- FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
+ final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
- if(extensions != null) {
- FilenameFilter filter = new ExtensionFileFilter(extensions);
+ if (extensions != null) {
+ final FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
chooser.setMultipleMode(true);
chooser.setVisible(true);
- while(chooser.getFile() == null) {
+ while (chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open.");
chooser.setVisible(true);
}
@@ -105,7 +105,7 @@ public class SimpleFileDialog {
* The title of the file picker
* @return The file the user picked
*/
- public static File getSaveFile(Frame parent, String title) {
+ public static File getSaveFile(final Frame parent, final String title) {
return getSaveFile(parent, title, (String[]) null);
}
@@ -120,21 +120,21 @@ public class SimpleFileDialog {
* The extensions to accept as valid
* @return The file the user picked
*/
- public static File getSaveFile(Frame parent, String title, String... extensions) {
- if(parent == null)
+ public static File getSaveFile(final Frame parent, final String title, final String... extensions) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null) throw new NullPointerException("Title must not be null");
+ else if (title == null) throw new NullPointerException("Title must not be null");
- FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE);
+ final FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE);
- if(extensions != null) {
- FilenameFilter filter = new ExtensionFileFilter(extensions);
+ if (extensions != null) {
+ final FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
chooser.setVisible(true);
- while(chooser.getFile() == null) {
+ while (chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to save to.");
chooser.setVisible(true);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java
index be2116a..4ed1661 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java
@@ -19,7 +19,7 @@ public class HLayout extends GridLayout {
* @param columns
* The number of columns in this layout.
*/
- public HLayout(int columns) {
+ public HLayout(final int columns) {
super(1, columns);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java
index 9c5a563..6993365 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java
@@ -19,7 +19,7 @@ public class VLayout extends GridLayout {
* @param rows
* The number of rows.
*/
- public VLayout(int rows) {
+ public VLayout(final int rows) {
super(rows, 1);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
index 6e6be02..4f71d38 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
@@ -1,9 +1,5 @@
package bjc.utils.gui.panels;
-import bjc.utils.funcdata.IList;
-import bjc.utils.gui.layout.AutosizeLayout;
-import bjc.utils.gui.layout.HLayout;
-
import java.awt.BorderLayout;
import javax.swing.DefaultListModel;
@@ -13,6 +9,10 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
+import bjc.utils.funcdata.IList;
+import bjc.utils.gui.layout.AutosizeLayout;
+import bjc.utils.gui.layout.HLayout;
+
/**
* A panel that allows you to select choices from a dropdown list
*
@@ -34,27 +34,27 @@ public class DropdownListPanel extends JPanel {
* @param choices
* The items to choose from
*/
- public <T> DropdownListPanel(String type, DefaultListModel<T> model, IList<T> choices) {
+ public <T> DropdownListPanel(final String type, final DefaultListModel<T> model, final IList<T> choices) {
setLayout(new AutosizeLayout());
- JPanel itemInputPanel = new JPanel();
+ final JPanel itemInputPanel = new JPanel();
itemInputPanel.setLayout(new BorderLayout());
- JPanel addItemPanel = new JPanel();
+ final JPanel addItemPanel = new JPanel();
addItemPanel.setLayout(new HLayout(2));
- JComboBox<T> addItemBox = new JComboBox<>();
+ final JComboBox<T> addItemBox = new JComboBox<>();
choices.forEach(addItemBox::addItem);
- JButton addItemButton = new JButton("Add " + type);
+ final JButton addItemButton = new JButton("Add " + type);
addItemPanel.add(addItemBox);
addItemPanel.add(addItemButton);
- JList<T> itemList = new JList<>(model);
+ final JList<T> itemList = new JList<>(model);
itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- JButton removeItemButton = new JButton("Remove " + type);
+ final JButton removeItemButton = new JButton("Remove " + type);
addItemButton.addActionListener((ev) -> {
model.addElement(addItemBox.getItemAt(addItemBox.getSelectedIndex()));
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java
index 877f308..2cecf0c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java
@@ -1,7 +1,5 @@
package bjc.utils.gui.panels;
-import bjc.utils.gui.layout.HLayout;
-
import java.util.function.Consumer;
import javax.swing.JFormattedTextField;
@@ -9,6 +7,8 @@ import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import bjc.utils.gui.layout.HLayout;
+
/**
* A simple panel allowing for input of a single formatted value
*
@@ -20,7 +20,7 @@ import javax.swing.JPanel;
public class FormattedInputPanel<InputVal> extends JPanel {
private static final long serialVersionUID = 5232016563558588031L;
- private JFormattedTextField field;
+ private final JFormattedTextField field;
/**
* Create a new formatted input panel
@@ -35,10 +35,11 @@ public class FormattedInputPanel<InputVal> extends JPanel {
* The action to call whenever the value changes
*/
@SuppressWarnings("unchecked")
- public FormattedInputPanel(String label, int length, AbstractFormatter formatter, Consumer<InputVal> reciever) {
+ public FormattedInputPanel(final String label, final int length, final AbstractFormatter formatter,
+ final Consumer<InputVal> reciever) {
setLayout(new HLayout(2));
- JLabel lab = new JLabel(label);
+ final JLabel lab = new JLabel(label);
field = new JFormattedTextField(formatter);
field.setColumns(length);
@@ -59,7 +60,7 @@ public class FormattedInputPanel<InputVal> extends JPanel {
* @param value
* The value to set the panel to
*/
- public void resetValues(InputVal value) {
+ public void resetValues(final InputVal value) {
field.setValue(value);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
index 054eb38..653dace 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java
@@ -1,12 +1,12 @@
package bjc.utils.gui.panels;
-import bjc.utils.data.IHolder;
-import bjc.utils.gui.layout.HLayout;
-
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
+import bjc.utils.data.IHolder;
+import bjc.utils.gui.layout.HLayout;
+
/**
* A panel that outputs a value bound to a {@link IHolder}
*
@@ -16,10 +16,10 @@ import javax.swing.Timer;
public class HolderOutputPanel extends JPanel {
private static final long serialVersionUID = 166573313903782080L;
- private Timer updater;
- private JLabel value;
- private int nDelay;
- private IHolder<String> val;
+ private Timer updater;
+ private final JLabel value;
+ private final int nDelay;
+ private final IHolder<String> val;
/**
* Create a new display panel, backed by a holder
@@ -31,13 +31,13 @@ public class HolderOutputPanel extends JPanel {
* @param nDelay
* The delay in ms between value updates
*/
- public HolderOutputPanel(String lab, IHolder<String> valueHolder, int nDelay) {
+ public HolderOutputPanel(final String lab, final IHolder<String> valueHolder, final int nDelay) {
this.val = valueHolder;
this.nDelay = nDelay;
setLayout(new HLayout(2));
- JLabel label = new JLabel(lab);
+ final JLabel label = new JLabel(lab);
value = new JLabel("(stopped)");
updater = new Timer(nDelay, (event) -> {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java
index 8f68571..cca73d5 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java
@@ -1,10 +1,5 @@
package bjc.utils.gui.panels;
-import bjc.utils.funcdata.IList;
-import bjc.utils.gui.SimpleJList;
-import bjc.utils.gui.layout.HLayout;
-import bjc.utils.gui.layout.VLayout;
-
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -14,6 +9,11 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
+import bjc.utils.funcdata.IList;
+import bjc.utils.gui.SimpleJList;
+import bjc.utils.gui.layout.HLayout;
+import bjc.utils.gui.layout.VLayout;
+
/**
* A panel that has a list of objects and ways of manipulating that list
*
@@ -36,7 +36,7 @@ public class ListParameterPanel<E> extends JPanel {
* @param remove
* The action that removes items
*/
- public ListParameterPanel(Supplier<E> add, Consumer<E> edit, Consumer<E> remove) {
+ public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, final Consumer<E> remove) {
this(add, edit, remove, null);
}
@@ -52,12 +52,13 @@ public class ListParameterPanel<E> extends JPanel {
* @param defaults
* The default values to put in the list
*/
- public ListParameterPanel(Supplier<E> add, Consumer<E> edit, Consumer<E> remove, IList<E> defaults) {
+ public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, final Consumer<E> remove,
+ final IList<E> defaults) {
setLayout(new VLayout(2));
JList<E> list;
- if(defaults != null) {
+ if (defaults != null) {
list = SimpleJList.buildFromList(defaults.toIterable());
} else {
list = new JList<>(new DefaultListModel<>());
@@ -65,19 +66,19 @@ public class ListParameterPanel<E> extends JPanel {
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- JPanel buttonPanel = new JPanel();
+ final JPanel buttonPanel = new JPanel();
int numButtons = 0;
- if(add != null) {
+ if (add != null) {
numButtons++;
}
- if(edit != null) {
+ if (edit != null) {
numButtons++;
}
- if(remove != null) {
+ if (remove != null) {
numButtons++;
}
@@ -85,10 +86,10 @@ public class ListParameterPanel<E> extends JPanel {
JButton addParam = null;
- if(add != null) {
+ if (add != null) {
addParam = new JButton("Add...");
addParam.addActionListener((event) -> {
- DefaultListModel<E> model = (DefaultListModel<E>) list.getModel();
+ final DefaultListModel<E> model = (DefaultListModel<E>) list.getModel();
model.addElement(add.get());
});
@@ -96,7 +97,7 @@ public class ListParameterPanel<E> extends JPanel {
JButton editParam = null;
- if(edit != null) {
+ if (edit != null) {
editParam = new JButton("Edit...");
editParam.addActionListener((event) -> {
edit.accept(list.getSelectedValue());
@@ -105,24 +106,24 @@ public class ListParameterPanel<E> extends JPanel {
JButton removeParam = null;
- if(remove != null) {
+ if (remove != null) {
removeParam = new JButton("Remove...");
removeParam.addActionListener((event) -> {
- DefaultListModel<E> model = (DefaultListModel<E>) list.getModel();
+ final DefaultListModel<E> model = (DefaultListModel<E>) list.getModel();
remove.accept(model.remove(list.getSelectedIndex()));
});
}
- if(add != null) {
+ if (add != null) {
buttonPanel.add(addParam);
}
- if(edit != null) {
+ if (edit != null) {
buttonPanel.add(editParam);
}
- if(remove != null) {
+ if (remove != null) {
buttonPanel.add(removeParam);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
index d0881c5..65c533d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
@@ -28,12 +28,12 @@ public class SimpleInputPanel extends JPanel {
* @param columns
* The number of columns of text input to take
*/
- public SimpleInputPanel(String label, int columns) {
+ public SimpleInputPanel(final String label, final int columns) {
setLayout(new BorderLayout());
- JLabel inputLabel = new JLabel(label);
+ final JLabel inputLabel = new JLabel(label);
- if(columns < 1) {
+ if (columns < 1) {
inputValue = new JTextField();
} else {
inputValue = new JTextField(columns);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
index b4fcfe1..edc1797 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
@@ -1,8 +1,5 @@
package bjc.utils.gui.panels;
-import bjc.utils.gui.layout.AutosizeLayout;
-import bjc.utils.gui.layout.HLayout;
-
import java.awt.BorderLayout;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -15,6 +12,9 @@ import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
+import bjc.utils.gui.layout.AutosizeLayout;
+import bjc.utils.gui.layout.HLayout;
+
/**
* A simple list of strings
*
@@ -24,11 +24,11 @@ import javax.swing.ListSelectionModel;
public class SimpleListPanel extends JPanel {
private static final long serialVersionUID = 2719963952350133541L;
- private static void addItem(DefaultListModel<String> model, Predicate<String> verifier,
- Consumer<String> onFailure, JTextField addItemField) {
- String potentialItem = addItemField.getText();
+ private static void addItem(final DefaultListModel<String> model, final Predicate<String> verifier,
+ final Consumer<String> onFailure, final JTextField addItemField) {
+ final String potentialItem = addItemField.getText();
- if(verifier == null || verifier.test(potentialItem)) {
+ if (verifier == null || verifier.test(potentialItem)) {
model.addElement(potentialItem);
} else {
onFailure.accept(potentialItem);
@@ -49,28 +49,28 @@ public class SimpleListPanel extends JPanel {
* @param onFailure
* The function to call when an item doesn't verify
*/
- public SimpleListPanel(String type, DefaultListModel<String> model, Predicate<String> verifier,
- Consumer<String> onFailure) {
+ public SimpleListPanel(final String type, final DefaultListModel<String> model,
+ final Predicate<String> verifier, final Consumer<String> onFailure) {
setLayout(new AutosizeLayout());
- JPanel itemInputPanel = new JPanel();
+ final JPanel itemInputPanel = new JPanel();
itemInputPanel.setLayout(new BorderLayout());
- JPanel addItemPanel = new JPanel();
+ final JPanel addItemPanel = new JPanel();
addItemPanel.setLayout(new HLayout(2));
- JTextField addItemField = new JTextField(255);
- JButton addItemButton = new JButton("Add " + type);
+ final JTextField addItemField = new JTextField(255);
+ final JButton addItemButton = new JButton("Add " + type);
addItemPanel.add(addItemField);
addItemPanel.add(addItemButton);
- JList<String> itemList = new JList<>(model);
+ final JList<String> itemList = new JList<>(model);
itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- JScrollPane listScroller = new JScrollPane(itemList);
+ final JScrollPane listScroller = new JScrollPane(itemList);
- JButton removeItemButton = new JButton("Remove " + type);
+ final JButton removeItemButton = new JButton("Remove " + type);
addItemButton.addActionListener((ev) -> {
addItem(model, verifier, onFailure, addItemField);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
index 2b48adf..6106182 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
@@ -29,10 +29,10 @@ public class SimpleSpinnerPanel extends JPanel {
* @param model
* The model to attach to the spinner
*/
- public SimpleSpinnerPanel(String label, SpinnerModel model) {
+ public SimpleSpinnerPanel(final String label, final SpinnerModel model) {
setLayout(new BorderLayout());
- JLabel inputLabel = new JLabel(label);
+ final JLabel inputLabel = new JLabel(label);
inputValue = new JSpinner(model);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java
index 71eaf33..e6a6da4 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java
@@ -1,7 +1,5 @@
package bjc.utils.gui.panels;
-import bjc.utils.gui.layout.HLayout;
-
import java.text.ParseException;
import java.util.function.Consumer;
@@ -10,6 +8,8 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
+import bjc.utils.gui.layout.HLayout;
+
/**
* A simple input panel for a slider-controlled value and a manual-input field
* for setting the slider
@@ -21,12 +21,12 @@ public class SliderInputPanel extends JPanel {
private final class NumberFormatter extends JFormattedTextField.AbstractFormatter {
private static final long serialVersionUID = -4448291795913908270L;
- private int minValue;
- private int maxValue;
+ private final int minValue;
+ private final int maxValue;
- private int initValue;
+ private final int initValue;
- public NumberFormatter(SliderSettings settings) {
+ public NumberFormatter(final SliderSettings settings) {
minValue = settings.minValue;
maxValue = settings.maxValue;
@@ -34,18 +34,17 @@ public class SliderInputPanel extends JPanel {
}
@Override
- public Object stringToValue(String text) throws ParseException {
+ public Object stringToValue(final String text) throws ParseException {
try {
- int val = Integer.parseInt(text);
+ final int val = Integer.parseInt(text);
- if(val < minValue)
+ if (val < minValue)
throw new ParseException("Value must be greater than " + minValue, 0);
- else if(val > maxValue)
+ else if (val > maxValue)
throw new ParseException("Value must be smaller than " + maxValue, 0);
- else
- return val;
- } catch(NumberFormatException nfex) {
- ParseException pex = new ParseException("Value must be a valid integer", 0);
+ else return val;
+ } catch (final NumberFormatException nfex) {
+ final ParseException pex = new ParseException("Value must be a valid integer", 0);
pex.initCause(nfex);
@@ -54,8 +53,8 @@ public class SliderInputPanel extends JPanel {
}
@Override
- public String valueToString(Object value) throws ParseException {
- if(value == null) return Integer.toString(initValue);
+ public String valueToString(final Object value) throws ParseException {
+ if (value == null) return Integer.toString(initValue);
return Integer.toString((Integer) value);
}
@@ -91,7 +90,7 @@ public class SliderInputPanel extends JPanel {
* @param max
* The maximum value of the slider
*/
- public SliderSettings(int min, int max) {
+ public SliderSettings(final int min, final int max) {
this(min, max, (min + max) / 2);
}
@@ -105,7 +104,7 @@ public class SliderInputPanel extends JPanel {
* @param init
* Th initial slider value
*/
- public SliderSettings(int min, int max, int init) {
+ public SliderSettings(final int min, final int max, final int init) {
minValue = min;
maxValue = max;
@@ -113,9 +112,9 @@ public class SliderInputPanel extends JPanel {
}
}
- private static final long serialVersionUID = 2956394160569961404L;
- private JSlider slider;
- private JFormattedTextField field;
+ private static final long serialVersionUID = 2956394160569961404L;
+ private final JSlider slider;
+ private final JFormattedTextField field;
/**
* Create a new slider input panel
@@ -131,11 +130,11 @@ public class SliderInputPanel extends JPanel {
* @param action
* The action to execute for a given value
*/
- public SliderInputPanel(String lab, SliderSettings settings, int majorTick, int minorTick,
- Consumer<Integer> action) {
+ public SliderInputPanel(final String lab, final SliderSettings settings, final int majorTick,
+ final int minorTick, final Consumer<Integer> action) {
setLayout(new HLayout(3));
- JLabel label = new JLabel(lab);
+ final JLabel label = new JLabel(lab);
slider = new JSlider(settings.minValue, settings.maxValue, settings.initValue);
field = new JFormattedTextField(new NumberFormatter(settings));
@@ -146,10 +145,10 @@ public class SliderInputPanel extends JPanel {
slider.setPaintLabels(true);
slider.addChangeListener((event) -> {
- if(slider.getValueIsAdjusting()) {
+ if (slider.getValueIsAdjusting()) {
// Do nothing
} else {
- int val = slider.getValue();
+ final int val = slider.getValue();
field.setValue(val);
@@ -160,9 +159,9 @@ public class SliderInputPanel extends JPanel {
field.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
field.setColumns(15);
field.addPropertyChangeListener("value", (event) -> {
- Object value = field.getValue();
+ final Object value = field.getValue();
- if(value == null) {
+ if (value == null) {
// Do nothing
} else {
slider.setValue((Integer) value);
@@ -180,7 +179,7 @@ public class SliderInputPanel extends JPanel {
* @param value
* The value to reset the fields to
*/
- public void resetValues(int value) {
+ public void resetValues(final int value) {
slider.setValue(value);
field.setValue(value);