Package org.hortonmachine.gui.utils
Class GuiUtilities
- java.lang.Object
-
- org.hortonmachine.gui.utils.GuiUtilities
-
public class GuiUtilities extends Object
Utilities class.- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGuiUtilities.IOnCloseListenerstatic classGuiUtilities.ShpFileFilter
-
Constructor Summary
Constructors Constructor Description GuiUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddClosingListener(JFrame frame, GuiUtilities.IOnCloseListener onCloseListener)static voidaddFileDropTarget(Component component, Consumer<File[]> filesConsumer)static voidapplyComponentOrientation(Component component, ComponentOrientation co)static voidcenterOnScreen(Component component)Set the location of a component to center it on the screen.static voidcolorButton(JButton button, Color color, Integer size)Create an image to make a color picker button.static voidcopyToClipboard(String text)static StringgetFromClipboard()static voidhandleError(Component parentComponent, Exception e)static booleanopenConfirmDialogWithPanel(Component parentComponent, JPanel panel, String title)static JDialogopenDialogWithPanel(JPanel panel, String title, Dimension dimension, boolean modal)static voidopenDialogWithTable(String title, String[][] dataMatrix, String[] columnNames, Dimension dimension, boolean modal)static voidopenFile(File file)static voidsetDefaultFrameIcon(JFrame frame)Set the default frame icon, also considering the macos case.static voidsetDefaultFrameIcon(JFrame frame, Image forceIcon)Set the frame icon, also considering the macos case.static voidsetDefaultLookAndFeel()static voidsetFileBrowsingOnWidgets(JTextField pathTextField, JButton browseButton, String[] allowedExtensions, Runnable postRunnable)Adds to a textfield and button the necessary to browse for a file.static voidsetFolderBrowsingOnWidgets(JTextField pathTextField, JButton browseButton, Runnable postRunnable)Adds to a textfield and button the necessary to browse for a folder.static voidsetUIFont(FontUIResource f)static StringshowComboDialog(Component parentComponent, String title, String message, String[] values, String selectedValue)static voidshowErrorMessage(Component parentComponent, String message)static voidshowErrorMessage(Component parentComponent, String title, String message)static voidshowImage(Component parentComponent, String title, BufferedImage image)static voidshowInfoMessage(Component parentComponent, String message)static voidshowInfoMessage(Component parentComponent, String title, String message)static StringshowInputAreaDialog(Component parentComponent, String message, String defaultInput)static StringshowInputDialog(Component parentComponent, String message, String defaultInput)static String[]showMultiInputDialog(Component parentComponent, String title, String[] labels, String[] defaultValues, HashMap<String,String[]> fields2ValuesMap)Create a simple multi input pane, that returns what the use inserts.static File[]showOpenFilesDialog(Component parent, String title, boolean multiselection, File initialPath, FileFilter filter)static File[]showOpenFolderDialog(Component parent, String title, boolean multiselection, File initialPath)static FileshowSaveFileDialog(Component parent, String title, File initialPath)static voidshowWarningMessage(Component parentComponent, String message)static voidshowWarningMessage(Component parentComponent, String title, String message)static booleanshowYesNoDialog(Component parentComponent, String message)
-
-
-
Method Detail
-
centerOnScreen
public static void centerOnScreen(Component component)
Set the location of a component to center it on the screen.- Parameters:
component- the component to center.
-
applyComponentOrientation
public static void applyComponentOrientation(Component component, ComponentOrientation co)
-
copyToClipboard
public static void copyToClipboard(String text)
-
openFile
public static void openFile(File file) throws IOException
- Throws:
IOException
-
openDialogWithPanel
public static JDialog openDialogWithPanel(JPanel panel, String title, Dimension dimension, boolean modal)
-
openDialogWithTable
public static void openDialogWithTable(String title, String[][] dataMatrix, String[] columnNames, Dimension dimension, boolean modal)
-
openConfirmDialogWithPanel
public static boolean openConfirmDialogWithPanel(Component parentComponent, JPanel panel, String title)
-
showInputDialog
public static String showInputDialog(Component parentComponent, String message, String defaultInput)
-
showInputAreaDialog
public static String showInputAreaDialog(Component parentComponent, String message, String defaultInput)
-
showMultiInputDialog
public static String[] showMultiInputDialog(Component parentComponent, String title, String[] labels, String[] defaultValues, HashMap<String,String[]> fields2ValuesMap)
Create a simple multi input pane, that returns what the use inserts.- Parameters:
parentComponent-title- the dialog title.labels- the labels to set.defaultValues- a set of default values.fields2ValuesMap- a map that allows to set combos for the various options.- Returns:
- the result inserted by the user.
-
showComboDialog
public static String showComboDialog(Component parentComponent, String title, String message, String[] values, String selectedValue)
-
setDefaultLookAndFeel
public static void setDefaultLookAndFeel()
-
setUIFont
public static void setUIFont(FontUIResource f)
-
setDefaultFrameIcon
public static void setDefaultFrameIcon(JFrame frame)
Set the default frame icon, also considering the macos case.- Parameters:
frame- the frame to set the icon for.
-
setDefaultFrameIcon
public static void setDefaultFrameIcon(JFrame frame, Image forceIcon)
Set the frame icon, also considering the macos case.- Parameters:
frame- the frame to set the icon for.forceIcon- an icon to set. If null, the default icon is used.
-
addClosingListener
public static void addClosingListener(JFrame frame, GuiUtilities.IOnCloseListener onCloseListener)
-
showInfoMessage
public static void showInfoMessage(Component parentComponent, String title, String message)
-
showWarningMessage
public static void showWarningMessage(Component parentComponent, String message)
-
showWarningMessage
public static void showWarningMessage(Component parentComponent, String title, String message)
-
showErrorMessage
public static void showErrorMessage(Component parentComponent, String title, String message)
-
showImage
public static void showImage(Component parentComponent, String title, BufferedImage image)
-
colorButton
public static void colorButton(JButton button, Color color, Integer size)
Create an image to make a color picker button.- Parameters:
button- the button.color- the color to set.size- the optional size of the image.
-
setFileBrowsingOnWidgets
public static void setFileBrowsingOnWidgets(JTextField pathTextField, JButton browseButton, String[] allowedExtensions, Runnable postRunnable)
Adds to a textfield and button the necessary to browse for a file.- Parameters:
pathTextField-browseButton-allowedExtensions-
-
setFolderBrowsingOnWidgets
public static void setFolderBrowsingOnWidgets(JTextField pathTextField, JButton browseButton, Runnable postRunnable)
Adds to a textfield and button the necessary to browse for a folder.- Parameters:
pathTextField-browseButton-
-
showOpenFilesDialog
public static File[] showOpenFilesDialog(Component parent, String title, boolean multiselection, File initialPath, FileFilter filter)
-
showSaveFileDialog
public static File showSaveFileDialog(Component parent, String title, File initialPath)
-
showOpenFolderDialog
public static File[] showOpenFolderDialog(Component parent, String title, boolean multiselection, File initialPath)
-
-