Class SwingUtil


  • public class SwingUtil
    extends JAXXUtil
    The runtime swing util class with some nice stuff.

    Note : Replace previous class jaxx.runtime.swing.Utils in previous versions.

    Since:
    1.2
    Author:
    Tony Chemit - dev@tchemit.fr
    • Field Detail

      • INT_3_DIGITS_PATTERN

        public static final String INT_3_DIGITS_PATTERN
        Pattern to use for short numeric values in editors with max 3 digits.
        Since:
        4.0
        See Also:
        Constant Field Values
      • INT_6_DIGITS_PATTERN

        public static final String INT_6_DIGITS_PATTERN
        Pattern to use for integer numeric values in editors with max 6 digits.
        Since:
        4.0
        See Also:
        Constant Field Values
      • INT_7_DIGITS_PATTERN

        public static final String INT_7_DIGITS_PATTERN
        Pattern to use for integer numeric values in editors with max 7 digits.
        Since:
        4.0
        See Also:
        Constant Field Values
      • LONG_10_DIGITS_PATTERN

        public static final String LONG_10_DIGITS_PATTERN
        Pattern to use for long numeric values in editors with max 10 digits.
        Since:
        4.0
        See Also:
        Constant Field Values
      • DECIMAL1_PATTERN

        public static final String DECIMAL1_PATTERN
        Pattern to use for decimal numeric values with 1 decimal digits in editors.
        Since:
        4.0
        See Also:
        Constant Field Values
      • DECIMAL2_PATTERN

        public static final String DECIMAL2_PATTERN
        Pattern to use for decimal numeric values with 2 decimal digits in editors.
        Since:
        4.0
        See Also:
        Constant Field Values
      • DECIMAL3_PATTERN

        public static final String DECIMAL3_PATTERN
        Pattern to use for decimal numeric values with 3 decimal digits in editors.
        Since:
        4.0
        See Also:
        Constant Field Values
      • DECIMAL4_PATTERN

        public static final String DECIMAL4_PATTERN
        Pattern to use for decimal numeric values with 4 decimal digits in editors.
        Since:
        4.0
        See Also:
        Constant Field Values
      • LONG_3_DIGITS_PATTERN

        public static final String LONG_3_DIGITS_PATTERN
        Pattern to use for long numeric values in editors with max 3 digits.
        Since:
        4.0
        See Also:
        Constant Field Values
    • Constructor Detail

      • SwingUtil

        public SwingUtil()
    • Method Detail

      • newMinDimension

        public static Dimension newMinDimension()
      • newMaxXDimension

        public static Dimension newMaxXDimension()
      • newMaxYDimension

        public static Dimension newMaxYDimension()
      • newMaxXYDimension

        public static Dimension newMaxXYDimension()
      • fillComboBox

        public static void fillComboBox​(JComboBox combo,
                                        Collection<?> data,
                                        Object select)
        Fill a combo box model with some datas, and select after all the given object
        Parameters:
        combo - the combo to fill
        data - data ot inject in combo
        select - the object to select in combo after reflling his model
      • fillList

        public static void fillList​(JList list,
                                    Collection<?> data,
                                    Object select)
        Fill a list model with some datas, and select after all the given object
        Parameters:
        list - the list to fill
        data - data ot inject in combo
        select - the object to select in combo after reflling his model
      • fillComboBox

        @Deprecated
        public static void fillComboBox​(JAXXComboBox combo,
                                        Collection<?> data,
                                        Object select,
                                        boolean firstNull)
        Deprecated.
        since 1.7.XXX this code is moved to JAXXComboBox
        TODO move this to JAXXComboBox.

        Fill a combo box model with some datas, and select after all the given object

        Parameters:
        combo - the combo to fill
        data - data ot inject in combo
        select - the object to select in combo after reflling his model
        firstNull - add a first null element
      • getParentContainer

        public static <O extends Container> O getParentContainer​(Object top,
                                                                 Class<O> clazz)
        Return parent's container corresponding to the Class clazz
        Type Parameters:
        O - type of container to obtain from context
        Parameters:
        top - the top container
        clazz - desired
        Returns:
        parent's container
      • getParent

        public static <O> O getParent​(Object top,
                                      Class<O> clazz)
        Find a parent of the given top object using the container api to get up.

        Stop on parent when it is of the givenclazz type.

        Type Parameters:
        O - type of container to obtain from context
        Parameters:
        top - the top container
        clazz - desired
        Returns:
        parent's container
        Since:
        2.5.14
      • computeTableColumnWidth

        public static int computeTableColumnWidth​(JTable table,
                                                  Font font,
                                                  int columnIndex,
                                                  String suffix)
      • fixTableColumnWidth

        public static void fixTableColumnWidth​(JTable table,
                                               int columnIndex,
                                               int width)
      • setTableColumnEditor

        public static void setTableColumnEditor​(JTable table,
                                                int columnIndex,
                                                TableCellEditor editor)
      • setTableColumnRenderer

        public static void setTableColumnRenderer​(JTable table,
                                                  int columnIndex,
                                                  TableCellRenderer editor)
      • setI18nTableHeaderRenderer

        public static void setI18nTableHeaderRenderer​(JTable table,
                                                      String... libelles)
      • boxComponentWithJxLayer

        public static <V extends JComponent> org.jdesktop.jxlayer.JXLayer<V> boxComponentWithJxLayer​(V component)
        Box a component in a JXLayer.
        Parameters:
        component - the component to box
        Returns:
        the JXLayer boxing the component
      • getLayer

        public static <V extends JComponent> org.jdesktop.jxlayer.JXLayer<V> getLayer​(V comp)
      • setLayerUI

        public static void setLayerUI​(JComponent comp,
                                      org.jdesktop.jxlayer.plaf.LayerUI<JComponent> ui)
      • isLayered

        public static boolean isLayered​(JComponent comp)
      • lookingForEditor

        public static Map<String,JComponent> lookingForEditor​(Class<?> clazz,
                                                              Container container)
        recherche les composants portant le meme nom que les champs de la classe clazz. Cette methode est statique pour pouvoir eventuellement l'utiliser dans un autre context (je pense par exemple a la generation jaxx).

        Si la recherche echoue pour quelque raison que se soit, aucune exception n'est leve, et la map retournee est tout simplement vide ou incomplete

        Parameters:
        clazz - la classe ou recherche les champs
        container - le container ou rechercher les composants d'edition
        Returns:
        le dictionnaire des composants recherches.
      • center

        public static void center​(Component parent,
                                  Component component)
        Centrer un component graphique au center d'un autre component.

        Note: si le parent est null, alors on ne fait rien.

        Parameters:
        parent - le component parent
        component - le component à centrer
      • loadUIConfig

        public static void loadUIConfig​(String defaultUIConfig,
                                        String extraUIConfig)
                                 throws IOException
        Load the ui.properties file and set in UIManager colors and icons found.
        Parameters:
        defaultUIConfig - le path vers le fichier de la config d'ui par défaut (doit etre dansle class-path)
        extraUIConfig - le path vers une surcharge de la config d'ui (doit etre dans le class-path)
        Throws:
        IOException - if could not load the ui.properties file
      • loadUIConfig

        public static void loadUIConfig​(Properties incoming)
        Load the ui.properties file and set in UIManager colors and icons found.
        Parameters:
        incoming - the ui resources to load.
        Since:
        2.1
      • getSelectedModelRows

        public static int[] getSelectedModelRows​(JTable table)
        Return the selected rows of the table in the model coordinate or empty array if selection is empty.
        Parameters:
        table - the table to seek
        Returns:
        the selected rows of the table in the model coordinate or empty array if selection is empty.
        Since:
        2.5.29
      • getSelectedModelRow

        public static int getSelectedModelRow​(JTable table)
        Return the selected row of the table in the model coordinate or -1 if selection is empty.
        Parameters:
        table - the table to seek
        Returns:
        the selected row of the table in the model coordinate or -1 if selection is empty.
        Since:
        2.5.29
      • getSelectedModelColumn

        public static int getSelectedModelColumn​(JTable table)
        Return the selected column of the table in the model coordinate or -1 if selection is empty.
        Parameters:
        table - the table to seek
        Returns:
        the selected column of the table in the model coordinate or -1 if selection is empty.
        Since:
        2.5.29
      • setSelectionInterval

        public static void setSelectionInterval​(JTable table,
                                                int rowIndex)
        Select the given row index rowIndex (from the model coordinate) in the selection of the given table.
        Parameters:
        table - the table where to set the selection
        rowIndex - the row index in the model coordinate to set as selection
        Since:
        2.5.29
      • addRowSelectionInterval

        public static void addRowSelectionInterval​(JTable table,
                                                   int rowIndex)
        Add the given row index rowIndex (from the model coordinate) in the selection of the given table.
        Parameters:
        table - the table where to set the selection
        rowIndex - the row index in the model coordinate to add to selection
        Since:
        2.5.29
      • askUser

        public static int askUser​(Component ui,
                                  String title,
                                  String message,
                                  int typeMessage,
                                  Object[] options,
                                  int defaultOption)
      • askUser

        public static int askUser​(Component ui,
                                  String title,
                                  Object message,
                                  int typeMessage,
                                  Object[] options,
                                  int defaultOption)
      • keyStrokeToStr

        public static String keyStrokeToStr​(KeyStroke actionKey)
      • newLabel

        public static JLabel newLabel​(String text,
                                      Object iconKey,
                                      int aligment)
      • getDeepestObjectAt

        public static Component getDeepestObjectAt​(Component parent,
                                                   int x,
                                                   int y)
        Gets the higest visible component in a ancestor hierarchy at specific x,y coordinates
        Parameters:
        parent -
        x -
        y -
        Returns:
        the deppest component
      • findComponentAt

        public static Component findComponentAt​(Container cont,
                                                int width,
                                                int height,
                                                int x,
                                                int y)
      • openLink

        public static void openLink​(HyperlinkEvent he)
        Open a link coming from a HyperlinkEvent.

        And try to open the link if an url in a browser.

        Parameters:
        he - the event to treate
        Since:
        1.6.0
      • openLink

        public static void openLink​(String url)
      • expandTree

        public static void expandTree​(JTree tree)
        Expand all childs of a tree.
        Parameters:
        tree - the tree to expand
      • expandTreeTable

        public static void expandTreeTable​(org.jdesktop.swingx.JXTreeTable treeTable)
        Expand all childs of a tree table.

        FIXME : Voir pour enlever le copier coller

        Parameters:
        treeTable - the tree to expand
      • addExpandOnClickListener

        public static void addExpandOnClickListener​(JTree tree)
        Add a listener of tree selection model to expand a new selected node when it is selected.
        Parameters:
        tree - the tree to treate
      • addExpandOnClickListener

        public static void addExpandOnClickListener​(org.jdesktop.swingx.JXTreeTable treeTable)
        Add a listener of tree table selection model to expand a new selected node when it is selected.

        FIXME : Voir pour enlever le copier coller

        Parameters:
        treeTable - the tree to treate
      • setComponentWidth

        public static void setComponentWidth​(Component component,
                                             int width)
        Set the width of the given component
        Parameters:
        component - the component to resize
        width - the new width to apply
      • setComponentHeight

        public static void setComponentHeight​(Component component,
                                              int height)
        Set the height of a given component.
        Parameters:
        component - the component to resize
        height - the new height to apply
      • createImageIcon

        public static ImageIcon createImageIcon​(String path)
        Parameters:
        path - the location of icons in root directory icons
        Returns:
        the icon at getIconPath()+path
      • getUIManagerIcon

        public static Icon getUIManagerIcon​(String key)
        Parameters:
        key - the key of the icon to retreave from UIManager
        Returns:
        the icon, or null if no icon found in UIManager
      • getUIManagerActionIcon

        public static Icon getUIManagerActionIcon​(String key)
        retreave for the UIManager the icon prefixed by action.
        Parameters:
        key - the key of the action icon to retreave from UIManager
        Returns:
        the icon, or null if no icon found in UIManager
      • createActionIcon

        public static ImageIcon createActionIcon​(String name)
      • makeTableTabFocusable

        public static void makeTableTabFocusable​(JTable table)
        Add KeyListener to focus next editable cell on TAB key
        Parameters:
        table - to add TAB KeyListener
      • editCell

        public static boolean editCell​(JTable table,
                                       int row,
                                       int colummn)
        Used to edit a cell of a given table.
        Parameters:
        table - the table to edit
        row - row index of cell to editing
        colummn - column index of cell to editing
        Returns:
        false if for any reason the cell cannot be edited, or if the indices are invalid
      • scrollToTableSelection

        public static void scrollToTableSelection​(JTable table)
        Add to a given table a selec tion model listener to always scroll to current cell selection.
        Parameters:
        table - the table
        Since:
        2.5.3
      • getFirstCharAt

        public static char getFirstCharAt​(String text,
                                          char defaultValue)
        Get the first char of a String, or return default value.

        Used for example by generated code (i18nMnemonic).

        Parameters:
        text - the text to cut
        defaultValue - default char value if text is null, or empty
        Returns:
        the first char of the given text or the default value if text is null or empty.
        Since:
        2.6.14
      • openLink

        public static void openLink​(URI uri)
      • getDesktopForBrowse

        public static Desktop getDesktopForBrowse()