Class GuiUtilities

java.lang.Object
org.hortonmachine.gui.utils.GuiUtilities

public class GuiUtilities
extends java.lang.Object
Utilities class.
Author:
Andrea Antonello (www.hydrologis.com)
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  GuiUtilities.IOnCloseListener  
    static class  GuiUtilities.ShpFileFilter  
  • Constructor Summary

    Constructors 
    Constructor Description
    GuiUtilities()  
  • Method Summary

    Modifier and Type Method Description
    static void addClosingListener​(javax.swing.JFrame frame, GuiUtilities.IOnCloseListener onCloseListener)  
    static void applyComponentOrientation​(java.awt.Component component, java.awt.ComponentOrientation co)  
    static void centerOnScreen​(java.awt.Component component)
    Set the location of a component to center it on the screen.
    static void colorButton​(javax.swing.JButton button, java.awt.Color color, java.lang.Integer size)
    Create an image to make a color picker button.
    static void copyToClipboard​(java.lang.String text)  
    static java.lang.String getFromClipboard()  
    static void handleError​(java.awt.Component parentComponent, java.lang.Exception e)  
    static boolean openConfirmDialogWithPanel​(java.awt.Component parentComponent, javax.swing.JPanel panel, java.lang.String title)  
    static javax.swing.JDialog openDialogWithPanel​(javax.swing.JPanel panel, java.lang.String title, java.awt.Dimension dimension, boolean modal)  
    static void openDialogWithTable​(java.lang.String title, java.lang.String[][] dataMatrix, java.lang.String[] columnNames, java.awt.Dimension dimension, boolean modal)  
    static void openFile​(java.io.File file)  
    static void setDefaultFrameIcon​(javax.swing.JFrame frame)
    Set the default frame icon, also considering the macos case.
    static void setDefaultFrameIcon​(javax.swing.JFrame frame, java.awt.Image forceIcon)
    Set the frame icon, also considering the macos case.
    static void setDefaultLookAndFeel()  
    static void setFileBrowsingOnWidgets​(javax.swing.JTextField pathTextField, javax.swing.JButton browseButton, java.lang.String[] allowedExtensions, java.lang.Runnable postRunnable)
    Adds to a textfield and button the necessary to browse for a file.
    static void setFolderBrowsingOnWidgets​(javax.swing.JTextField pathTextField, javax.swing.JButton browseButton, java.lang.Runnable postRunnable)
    Adds to a textfield and button the necessary to browse for a folder.
    static java.lang.String showComboDialog​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message, java.lang.String[] values, java.lang.String selectedValue)  
    static void showErrorMessage​(java.awt.Component parentComponent, java.lang.String message)  
    static void showErrorMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)  
    static void showImage​(java.awt.Component parentComponent, java.lang.String title, java.awt.image.BufferedImage image)  
    static void showInfoMessage​(java.awt.Component parentComponent, java.lang.String message)  
    static void showInfoMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)  
    static java.lang.String showInputDialog​(java.awt.Component parentComponent, java.lang.String message, java.lang.String defaultInput)  
    static java.lang.String[] showMultiInputDialog​(java.awt.Component parentComponent, java.lang.String title, java.lang.String[] labels, java.lang.String[] defaultValues, java.util.HashMap<java.lang.String,​java.lang.String[]> fields2ValuesMap)
    Create a simple multi input pane, that returns what the use inserts.
    static java.io.File[] showOpenFilesDialog​(java.awt.Component parent, java.lang.String title, boolean multiselection, java.io.File initialPath, javax.swing.filechooser.FileFilter filter)  
    static java.io.File[] showOpenFolderDialog​(java.awt.Component parent, java.lang.String title, boolean multiselection, java.io.File initialPath)  
    static java.io.File showSaveFileDialog​(java.awt.Component parent, java.lang.String title, java.io.File initialPath)  
    static void showWarningMessage​(java.awt.Component parentComponent, java.lang.String message)  
    static void showWarningMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)  
    static boolean showYesNoDialog​(java.awt.Component parentComponent, java.lang.String message)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • centerOnScreen

      public static void centerOnScreen​(java.awt.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​(java.awt.Component component, java.awt.ComponentOrientation co)
    • copyToClipboard

      public static void copyToClipboard​(java.lang.String text)
    • getFromClipboard

      public static java.lang.String getFromClipboard() throws java.lang.Exception
      Throws:
      java.lang.Exception
    • openFile

      public static void openFile​(java.io.File file) throws java.io.IOException
      Throws:
      java.io.IOException
    • openDialogWithPanel

      public static javax.swing.JDialog openDialogWithPanel​(javax.swing.JPanel panel, java.lang.String title, java.awt.Dimension dimension, boolean modal)
    • openDialogWithTable

      public static void openDialogWithTable​(java.lang.String title, java.lang.String[][] dataMatrix, java.lang.String[] columnNames, java.awt.Dimension dimension, boolean modal)
    • openConfirmDialogWithPanel

      public static boolean openConfirmDialogWithPanel​(java.awt.Component parentComponent, javax.swing.JPanel panel, java.lang.String title)
    • showInputDialog

      public static java.lang.String showInputDialog​(java.awt.Component parentComponent, java.lang.String message, java.lang.String defaultInput)
    • showYesNoDialog

      public static boolean showYesNoDialog​(java.awt.Component parentComponent, java.lang.String message)
    • showMultiInputDialog

      public static java.lang.String[] showMultiInputDialog​(java.awt.Component parentComponent, java.lang.String title, java.lang.String[] labels, java.lang.String[] defaultValues, java.util.HashMap<java.lang.String,​java.lang.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 java.lang.String showComboDialog​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message, java.lang.String[] values, java.lang.String selectedValue)
    • setDefaultLookAndFeel

      public static void setDefaultLookAndFeel()
    • setDefaultFrameIcon

      public static void setDefaultFrameIcon​(javax.swing.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​(javax.swing.JFrame frame, java.awt.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​(javax.swing.JFrame frame, GuiUtilities.IOnCloseListener onCloseListener)
    • showInfoMessage

      public static void showInfoMessage​(java.awt.Component parentComponent, java.lang.String message)
    • showInfoMessage

      public static void showInfoMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)
    • showWarningMessage

      public static void showWarningMessage​(java.awt.Component parentComponent, java.lang.String message)
    • showWarningMessage

      public static void showWarningMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)
    • showErrorMessage

      public static void showErrorMessage​(java.awt.Component parentComponent, java.lang.String message)
    • handleError

      public static void handleError​(java.awt.Component parentComponent, java.lang.Exception e)
    • showErrorMessage

      public static void showErrorMessage​(java.awt.Component parentComponent, java.lang.String title, java.lang.String message)
    • showImage

      public static void showImage​(java.awt.Component parentComponent, java.lang.String title, java.awt.image.BufferedImage image)
    • colorButton

      public static void colorButton​(javax.swing.JButton button, java.awt.Color color, java.lang.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​(javax.swing.JTextField pathTextField, javax.swing.JButton browseButton, java.lang.String[] allowedExtensions, java.lang.Runnable postRunnable)
      Adds to a textfield and button the necessary to browse for a file.
      Parameters:
      pathTextField -
      browseButton -
      allowedExtensions -
    • setFolderBrowsingOnWidgets

      public static void setFolderBrowsingOnWidgets​(javax.swing.JTextField pathTextField, javax.swing.JButton browseButton, java.lang.Runnable postRunnable)
      Adds to a textfield and button the necessary to browse for a folder.
      Parameters:
      pathTextField -
      browseButton -
    • showOpenFilesDialog

      public static java.io.File[] showOpenFilesDialog​(java.awt.Component parent, java.lang.String title, boolean multiselection, java.io.File initialPath, javax.swing.filechooser.FileFilter filter)
    • showSaveFileDialog

      public static java.io.File showSaveFileDialog​(java.awt.Component parent, java.lang.String title, java.io.File initialPath)
    • showOpenFolderDialog

      public static java.io.File[] showOpenFolderDialog​(java.awt.Component parent, java.lang.String title, boolean multiselection, java.io.File initialPath)