Package org.nuiton.jaxx.runtime.swing
Class SwingUtil
- java.lang.Object
-
- org.nuiton.jaxx.runtime.JAXXUtil
-
- org.nuiton.jaxx.runtime.swing.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwingUtil.TabbedPaneIterator<O>A simple iterator on aJTabbedPane.
-
Field Summary
Fields Modifier and Type Field Description static StringCOLOR_PREFIXstatic StringDECIMAL1_PATTERNPattern to use for decimal numeric values with 1 decimal digits in editors.static StringDECIMAL2_PATTERNPattern to use for decimal numeric values with 2 decimal digits in editors.static StringDECIMAL3_PATTERNPattern to use for decimal numeric values with 3 decimal digits in editors.static StringDECIMAL4_PATTERNPattern to use for decimal numeric values with 4 decimal digits in editors.static StringDEFAULT_ICON_PATHstatic StringDEFAULT_ICON_PATH_PROPERTYstatic StringICON_PREFIXstatic StringINT_3_DIGITS_PATTERNPattern to use for short numeric values in editors with max 3 digits.static StringINT_6_DIGITS_PATTERNPattern to use for integer numeric values in editors with max 6 digits.static StringINT_7_DIGITS_PATTERNPattern to use for integer numeric values in editors with max 7 digits.static StringLONG_10_DIGITS_PATTERNPattern to use for long numeric values in editors with max 10 digits.static StringLONG_3_DIGITS_PATTERNPattern to use for long numeric values in editors with max 3 digits.
-
Constructor Summary
Constructors Constructor Description SwingUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddExpandOnClickListener(JTree tree)Add a listener of tree selection model to expand a new selected node when it is selected.static voidaddExpandOnClickListener(org.jdesktop.swingx.JXTreeTable treeTable)Add a listener of tree table selection model to expand a new selected node when it is selected.static voidaddRowSelectionInterval(JTable table, int rowIndex)Add the given row indexrowIndex(from the model coordinate) in the selection of the given table.static intaskUser(Component ui, String title, Object message, int typeMessage, Object[] options, int defaultOption)static intaskUser(Component ui, String title, String message, int typeMessage, Object[] options, int defaultOption)static intaskUser(Frame ui, JOptionPane pane, String title, Object[] options)static <V extends JComponent>
org.jdesktop.jxlayer.JXLayer<V>boxComponentWithJxLayer(V component)Box a component in aJXLayer.static voidcenter(Component parent, Component component)Centrer un component graphique au center d'un autre component.static intcomputeTableColumnWidth(JTable table, Font font, int columnIndex, String suffix)static ImageIconcreateActionIcon(String name)static ImageIconcreateI18nIcon(String name)static ImageIconcreateIcon(String path)static ImageIconcreateIcon(String classifier, String name)static ImageIconcreateImageIcon(String path)static voiddisplayInfo(Component ui, String title, String text)static voiddisplayWarning(Component ui, String title, String text)static booleaneditCell(JTable table, int row, int colummn)Used to edit a cell of a given table.static voidensureColumnIndex(TableModel model, int index)static voidensureRowIndex(TableModel model, int rowIndex)static voidexpandTree(JTree tree)Expand all childs of a tree.static voidexpandTreeTable(org.jdesktop.swingx.JXTreeTable treeTable)Expand all childs of a tree table.static voidfillComboBox(JComboBox combo, Collection<?> data, Object select)Fill a combo box model with some datas, and select after all the given objectstatic voidfillComboBox(JAXXComboBox combo, Collection<?> data, Object select, boolean firstNull)Deprecated.since 1.7.XXX this code is moved to JAXXComboBoxstatic voidfillList(JList list, Collection<?> data, Object select)Fill a list model with some datas, and select after all the given objectstatic ComponentfindComponentAt(Container cont, int width, int height, int x, int y)static KeyStrokefindKeyStroke(String name, String defaultValue)static voidfixTableColumnWidth(JTable table, int columnIndex, int width)static StringgetAccText(KeyStroke actionKey)static ComponentgetDeepestObjectAt(Component parent, int x, int y)Gets the higest visible component in a ancestor hierarchy at specific x,y coordinatesstatic DesktopgetDesktopForBrowse()static chargetFirstCharAt(String text, char defaultValue)Get the first char of a String, or return default value.static <V extends JComponent>
org.jdesktop.jxlayer.JXLayer<V>getLayer(V comp)static List<JComponent>getLayeredComponents(JAXXObject object)static <O> OgetParent(Object top, Class<O> clazz)Find a parent of the giventopobject using the container api to get up.static <O extends Container>
OgetParentContainer(Object top, Class<O> clazz)Return parent's container corresponding to the Class clazzstatic intgetSelectedModelColumn(JTable table)Return the selected column of the table in the model coordinate or-1if selection is empty.static intgetSelectedModelRow(JTable table)Return the selected row of the table in the model coordinate or-1if selection is empty.static int[]getSelectedModelRows(JTable table)Return the selected rows of the table in the model coordinate or empty array if selection is empty.static IcongetUIManagerActionIcon(String key)retreave for theUIManagerthe icon prefixed byaction.static IcongetUIManagerIcon(String key)static voidinitNimbusLoookAndFeel()Try to load the Nimbus look and feel.static booleanisLayered(JComponent comp)static StringkeyStrokeToStr(KeyStroke actionKey)static voidloadUIConfig(String defaultUIConfig, String extraUIConfig)Load the ui.properties file and set inUIManagercolors and icons found.static voidloadUIConfig(Properties incoming)Load the ui.properties file and set inUIManagercolors and icons found.static Map<String,JComponent>lookingForEditor(Class<?> clazz, Container container)recherche les composants portant le meme nom que les champs de la classe clazz.static voidmakeTableTabFocusable(JTable table)AddKeyListenerto focus next editable cell on TAB keystatic BooleanCellEditornewBooleanTableCellEditor(TableCellRenderer renderer)static TableCellRenderernewBooleanTableCellEditorAndRenderer(TableCellRenderer renderer)static TableCellRenderernewBooleanTableCellRenderer(TableCellRenderer renderer)static TableCellRenderernewBooleanTableCellRenderer(TableCellRenderer renderer, Predicate<?> predicate)static DefaultComboBoxModelnewComboModel(Object... items)static TableCellRenderernewDeleteCellRenderer(DefaultTableCellRenderer renderer)static EmptyNumberTableCellRenderernewEmptyNumberTableCellRenderer(TableCellRenderer renderer)static <E extends Enum<E>>
EnumTableCellRenderer<E>newEnumTableCellRenderer(TableCellRenderer renderer, Class<E> enumClass)static JLabelnewLabel(String text, Object iconKey, int aligment)static DimensionnewMaxXDimension()static DimensionnewMaxXYDimension()static DimensionnewMaxYDimension()static DimensionnewMinDimension()static TableCellRenderernewStringTableCellRenderer(DefaultTableCellRenderer renderer, int length, boolean tooltip)static SwingUtil.TabbedPaneIterator<Component>newTabbedPaneIterator(JTabbedPane tabs)Iterate the components of aJTabbedPanein natural order.static voidopenLink(String url)static voidopenLink(URI uri)static voidopenLink(HyperlinkEvent he)Open a link coming from aHyperlinkEvent.static voidscrollToTableSelection(JTable table)Add to a given table a selec tion model listener to always scroll to current cell selection.static voidsetComponentHeight(Component component, int height)Set the height of a given component.static voidsetComponentWidth(Component component, int width)Set the width of the given componentstatic voidsetI18nTableHeaderRenderer(JTable table, String... libelles)static voidsetLayerUI(JComponent comp, org.jdesktop.jxlayer.plaf.LayerUI<JComponent> ui)static voidsetSelectionInterval(JTable table, int rowIndex)Select the given row indexrowIndex(from the model coordinate) in the selection of the given table.static voidsetTableColumnEditor(JTable table, int columnIndex, TableCellEditor editor)static voidsetTableColumnRenderer(JTable table, int columnIndex, TableCellRenderer editor)static voidsetText(JTextComponent c, String text)-
Methods inherited from class org.nuiton.jaxx.runtime.JAXXUtil
applyDataBinding, applyDataBinding, castList, castMap, checkJAXXContextEntries, checkJAXXContextEntry, copyToClipBoard, decodeCompressedJAXXObjectDescriptor, decodeJAXXObjectDescriptor, destroy, destroy, findJaxxPropertyChangeListener, getDataBindingUpdateListener, getEventListener, getEventListener, getStringValue, initContext, invokeConstructor, newContextEntryDef, newContextEntryDef, newListContextEntryDef, newListContextEntryDef, newMapContextEntryDef, processDataBinding, reloadBinding, reloadBinding, removeAllDataBindings, removeDataBinding
-
-
-
-
Field Detail
-
DEFAULT_ICON_PATH
public static final String DEFAULT_ICON_PATH
- See Also:
- Constant Field Values
-
DEFAULT_ICON_PATH_PROPERTY
public static final String DEFAULT_ICON_PATH_PROPERTY
- See Also:
- Constant Field Values
-
ICON_PREFIX
public static final String ICON_PREFIX
- See Also:
- Constant Field Values
-
COLOR_PREFIX
public static final String COLOR_PREFIX
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
newMinDimension
public static Dimension newMinDimension()
-
newMaxXDimension
public static Dimension newMaxXDimension()
-
newMaxYDimension
public static Dimension newMaxYDimension()
-
newMaxXYDimension
public static Dimension newMaxXYDimension()
-
setText
public static void setText(JTextComponent c, String text)
-
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 filldata- data ot inject in comboselect- 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 filldata- data ot inject in comboselect- 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 JAXXComboBoxTODO move this to JAXXComboBox.Fill a combo box model with some datas, and select after all the given object
- Parameters:
combo- the combo to filldata- data ot inject in comboselect- the object to select in combo after reflling his modelfirstNull- 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 containerclazz- desired- Returns:
- parent's container
-
getParent
public static <O> O getParent(Object top, Class<O> clazz)
Find a parent of the giventopobject using the container api to get up.Stop on parent when it is of the given
clazztype.- Type Parameters:
O- type of container to obtain from context- Parameters:
top- the top containerclazz- 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)
-
newStringTableCellRenderer
public static TableCellRenderer newStringTableCellRenderer(DefaultTableCellRenderer renderer, int length, boolean tooltip)
-
boxComponentWithJxLayer
public static <V extends JComponent> org.jdesktop.jxlayer.JXLayer<V> boxComponentWithJxLayer(V component)
Box a component in aJXLayer.- Parameters:
component- the component to box- Returns:
- the
JXLayerboxing the component
-
getLayeredComponents
public static List<JComponent> getLayeredComponents(JAXXObject object)
-
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 champscontainer- 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 parentcomponent- le component à centrer
-
initNimbusLoookAndFeel
public static void initNimbusLoookAndFeel() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessExceptionTry to load the Nimbus look and feel.- Throws:
UnsupportedLookAndFeelException- if nimbus is not applicableClassNotFoundExceptionInstantiationExceptionIllegalAccessException
-
loadUIConfig
public static void loadUIConfig(String defaultUIConfig, String extraUIConfig) throws IOException
Load the ui.properties file and set inUIManagercolors 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 inUIManagercolors and icons found.- Parameters:
incoming- the ui resources to load.- Since:
- 2.1
-
newTabbedPaneIterator
public static SwingUtil.TabbedPaneIterator<Component> newTabbedPaneIterator(JTabbedPane tabs)
Iterate the components of aJTabbedPanein natural order.Says using method
Container.getComponent(int)- Parameters:
tabs- the- Returns:
- the iterator
- Since:
- 1.4
-
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-1if selection is empty.- Parameters:
table- the table to seek- Returns:
- the selected row of the table in the model coordinate or
-1if 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-1if selection is empty.- Parameters:
table- the table to seek- Returns:
- the selected column of the table in the model coordinate or
-1if selection is empty. - Since:
- 2.5.29
-
setSelectionInterval
public static void setSelectionInterval(JTable table, int rowIndex)
Select the given row indexrowIndex(from the model coordinate) in the selection of the given table.- Parameters:
table- the table where to set the selectionrowIndex- 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 indexrowIndex(from the model coordinate) in the selection of the given table.- Parameters:
table- the table where to set the selectionrowIndex- 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)
-
askUser
public static int askUser(Frame ui, JOptionPane pane, String title, Object[] options)
-
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)
-
newDeleteCellRenderer
public static TableCellRenderer newDeleteCellRenderer(DefaultTableCellRenderer renderer)
-
newBooleanTableCellRenderer
public static TableCellRenderer newBooleanTableCellRenderer(TableCellRenderer renderer)
-
newBooleanTableCellRenderer
public static TableCellRenderer newBooleanTableCellRenderer(TableCellRenderer renderer, Predicate<?> predicate)
-
newBooleanTableCellEditorAndRenderer
public static TableCellRenderer newBooleanTableCellEditorAndRenderer(TableCellRenderer renderer)
-
newBooleanTableCellEditor
public static BooleanCellEditor newBooleanTableCellEditor(TableCellRenderer renderer)
-
newEmptyNumberTableCellRenderer
public static EmptyNumberTableCellRenderer newEmptyNumberTableCellRenderer(TableCellRenderer renderer)
-
newEnumTableCellRenderer
public static <E extends Enum<E>> EnumTableCellRenderer<E> newEnumTableCellRenderer(TableCellRenderer renderer, Class<E> enumClass)
-
openLink
public static void openLink(HyperlinkEvent he)
Open a link coming from aHyperlinkEvent.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 resizewidth- 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 resizeheight- 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
-
getUIManagerActionIcon
public static Icon getUIManagerActionIcon(String key)
retreave for theUIManagerthe icon prefixed byaction.
-
makeTableTabFocusable
public static void makeTableTabFocusable(JTable table)
AddKeyListenerto focus next editable cell on TAB key- Parameters:
table- to add TABKeyListener
-
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 editrow- row index of cell to editingcolummn- column index of cell to editing- Returns:
falseif for any reason the cell cannot be edited, or if the indices are invalid
-
ensureRowIndex
public static void ensureRowIndex(TableModel model, int rowIndex) throws ArrayIndexOutOfBoundsException
- Throws:
ArrayIndexOutOfBoundsException
-
ensureColumnIndex
public static void ensureColumnIndex(TableModel model, int index) throws ArrayIndexOutOfBoundsException
- Throws:
ArrayIndexOutOfBoundsException
-
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 cutdefaultValue- 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()
-
newComboModel
public static DefaultComboBoxModel newComboModel(Object... items)
-
-