Class GuiUtilities


  • public class GuiUtilities
    extends Object
    Utilities class.
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Constructor Detail

      • GuiUtilities

        public GuiUtilities()
    • 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.
      • copyToClipboard

        public static void copyToClipboard​(String text)
      • 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)
      • showYesNoDialog

        public static boolean showYesNoDialog​(Component parentComponent,
                                              String message)
      • 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.
      • setDefaultLookAndFeel

        public static void setDefaultLookAndFeel()
      • 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.
      • showInfoMessage

        public static void showInfoMessage​(Component parentComponent,
                                           String message)
      • 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 message)
      • handleError

        public static void handleError​(Component parentComponent,
                                       Exception e)
      • showErrorMessage

        public static void showErrorMessage​(Component parentComponent,
                                            String title,
                                            String message)
      • 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)
      • addFileDropTarget

        public static void addFileDropTarget​(Component component,
                                             Consumer<File[]> filesConsumer)
        Parameters:
        component -
        filesConsumer -