Package jaxx.runtime
Class SwingUtil
java.lang.Object
jaxx.runtime.JAXXUtil
jaxx.runtime.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 - chemit@codelutin.com
-
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 java.lang.StringCOLOR_PREFIXstatic java.lang.StringDEFAULT_ICON_PATHstatic java.lang.StringDEFAULT_ICON_PATH_PROPERTYstatic java.lang.StringICON_PREFIX -
Constructor Summary
Constructors Constructor Description SwingUtil() -
Method Summary
Modifier and Type Method Description static voidaddExpandOnClickListener(javax.swing.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(javax.swing.JTable table, int rowIndex)Add the given row indexrowIndex(from the model coordinate) in the selection of the given table.static <V extends javax.swing.JComponent>
org.jdesktop.jxlayer.JXLayer<V>boxComponentWithJxLayer(V component)Box a component in aJXLayer.static voidcenter(java.awt.Component parent, java.awt.Component component)Centrer un component graphique au center d'un autre component.static intcomputeTableColumnWidth(javax.swing.JTable table, java.awt.Font font, int columnIndex, java.lang.String suffix)static javax.swing.ImageIconcreateActionIcon(java.lang.String name)static javax.swing.ImageIconcreateI18nIcon(java.lang.String name)static javax.swing.ImageIconcreateIcon(java.lang.String path)static javax.swing.ImageIconcreateIcon(java.lang.String classifier, java.lang.String name)static javax.swing.ImageIconcreateImageIcon(java.lang.String path)static booleaneditCell(javax.swing.JTable table, int row, int colummn)Used to edit a cell of a given table.static voidensureColumnIndex(javax.swing.table.TableModel model, int index)static voidensureRowIndex(javax.swing.table.TableModel model, int rowIndex)static voidexpandTree(javax.swing.JTree tree)Expand all childs of a tree.static voidexpandTreeTable(org.jdesktop.swingx.JXTreeTable treeTable)Expand all childs of a tree table.static voidfillComboBox(javax.swing.JComboBox combo, java.util.Collection<?> data, java.lang.Object select)Fill a combo box model with some datas, and select after all the given objectstatic voidfillComboBox(JAXXComboBox combo, java.util.Collection<?> data, java.lang.Object select, boolean firstNull)Deprecated.since 1.7.XXX this code is moved to JAXXComboBoxstatic voidfillList(javax.swing.JList list, java.util.Collection<?> data, java.lang.Object select)Fill a list model with some datas, and select after all the given objectstatic java.awt.ComponentfindComponentAt(java.awt.Container cont, int width, int height, int x, int y)static voidfixTableColumnWidth(javax.swing.JTable table, int columnIndex, int width)static java.awt.ComponentgetDeepestObjectAt(java.awt.Component parent, int x, int y)Gets the higest visible component in a ancestor hierarchy at specific x,y coordinatesstatic java.awt.DesktopgetDesktopForBrowse()static chargetFirstCharAt(java.lang.String text, char defaultValue)Get the first char of a String, or return default value.static <V extends javax.swing.JComponent>
org.jdesktop.jxlayer.JXLayer<V>getLayer(V comp)static java.util.List<javax.swing.JComponent>getLayeredComponents(JAXXObject object)static <O> OgetParent(java.lang.Object top, java.lang.Class<O> clazz)Find a parent of the giventopobject using the container api to get up.static <O extends java.awt.Container>
OgetParentContainer(java.lang.Object top, java.lang.Class<O> clazz)Return parent's container corresponding to the Class clazzstatic intgetSelectedModelColumn(javax.swing.JTable table)Return the selected column of the table in the model coordinate or-1if selection is empty.static intgetSelectedModelRow(javax.swing.JTable table)Return the selected row of the table in the model coordinate or-1if selection is empty.static int[]getSelectedModelRows(javax.swing.JTable table)Return the selected rows of the table in the model coordinate or empty array if selection is empty.static javax.swing.IcongetUIManagerActionIcon(java.lang.String key)retreave for theUIManagerthe icon prefixed byaction.static javax.swing.IcongetUIManagerIcon(java.lang.String key)static voidinitNimbusLoookAndFeel()Try to load the Nimbus look and feel.static booleanisLayered(javax.swing.JComponent comp)static voidloadUIConfig(java.lang.String defaultUIConfig, java.lang.String extraUIConfig)Load the ui.properties file and set inUIManagercolors and icons found.static voidloadUIConfig(java.util.Properties incoming)Load the ui.properties file and set inUIManagercolors and icons found.static java.util.Map<java.lang.String,javax.swing.JComponent>lookingForEditor(java.lang.Class<?> clazz, java.awt.Container container)recherche les composants portant le meme nom que les champs de la classe clazz.static voidmakeTableTabFocusable(javax.swing.JTable table)AddKeyListenerto focus next editable cell on TAB keystatic BooleanCellEditornewBooleanTableCellEditor(javax.swing.table.TableCellRenderer renderer)static javax.swing.table.TableCellRenderernewBooleanTableCellEditorAndRenderer(javax.swing.table.TableCellRenderer renderer)static javax.swing.table.TableCellRenderernewBooleanTableCellRenderer(javax.swing.table.TableCellRenderer renderer)static javax.swing.table.TableCellRenderernewBooleanTableCellRenderer(javax.swing.table.TableCellRenderer renderer, com.google.common.base.Predicate<?> predicate)static javax.swing.DefaultComboBoxModelnewComboModel(java.lang.Object... items)static javax.swing.table.TableCellRenderernewDeleteCellRenderer(javax.swing.table.DefaultTableCellRenderer renderer)static EmptyNumberTableCellRenderernewEmptyNumberTableCellRenderer(javax.swing.table.TableCellRenderer renderer)static <E extends java.lang.Enum<E>>
EnumTableCellRenderer<E>newEnumTableCellRenderer(javax.swing.table.TableCellRenderer renderer, java.lang.Class<E> enumClass)static javax.swing.JLabelnewLabel(java.lang.String text, java.lang.Object iconKey, int aligment)static java.awt.DimensionnewMaxXDimension()static java.awt.DimensionnewMaxXYDimension()static java.awt.DimensionnewMaxYDimension()static java.awt.DimensionnewMinDimension()static javax.swing.table.TableCellRenderernewStringTableCellRenderer(javax.swing.table.DefaultTableCellRenderer renderer, int length, boolean tooltip)static SwingUtil.TabbedPaneIterator<java.awt.Component>newTabbedPaneIterator(javax.swing.JTabbedPane tabs)Iterate the components of aJTabbedPanein natural order.static voidopenLink(java.lang.String url)static voidopenLink(java.net.URI uri)static voidopenLink(javax.swing.event.HyperlinkEvent he)Open a link coming from aHyperlinkEvent.static voidscrollToTableSelection(javax.swing.JTable table)Add to a given table a selec tion model listener to always scroll to current cell selection.static voidsetComponentHeight(java.awt.Component component, int height)Set the height of a given component.static voidsetComponentWidth(java.awt.Component component, int width)Set the width of the given componentstatic voidsetI18nTableHeaderRenderer(javax.swing.JTable table, java.lang.String... libelles)static voidsetLayerUI(javax.swing.JComponent comp, org.jdesktop.jxlayer.plaf.LayerUI<javax.swing.JComponent> ui)static voidsetSelectionInterval(javax.swing.JTable table, int rowIndex)Select the given row indexrowIndex(from the model coordinate) in the selection of the given table.static voidsetTableColumnEditor(javax.swing.JTable table, int columnIndex, javax.swing.table.TableCellEditor editor)static voidsetTableColumnRenderer(javax.swing.JTable table, int columnIndex, javax.swing.table.TableCellRenderer editor)Methods inherited from class jaxx.runtime.JAXXUtil
applyDataBinding, applyDataBinding, assignment, assignment, assignment, assignment, assignment, assignment, assignment, assignment, assignment, 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, removeDataBindingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT_ICON_PATH
public static final java.lang.String DEFAULT_ICON_PATH- See Also:
- Constant Field Values
-
DEFAULT_ICON_PATH_PROPERTY
public static final java.lang.String DEFAULT_ICON_PATH_PROPERTY- See Also:
- Constant Field Values
-
ICON_PREFIX
public static final java.lang.String ICON_PREFIX- See Also:
- Constant Field Values
-
COLOR_PREFIX
public static final java.lang.String COLOR_PREFIX- See Also:
- Constant Field Values
-
-
Constructor Details
-
SwingUtil
public SwingUtil()
-
-
Method Details
-
newMinDimension
public static java.awt.Dimension newMinDimension() -
newMaxXDimension
public static java.awt.Dimension newMaxXDimension() -
newMaxYDimension
public static java.awt.Dimension newMaxYDimension() -
newMaxXYDimension
public static java.awt.Dimension newMaxXYDimension() -
fillComboBox
public static void fillComboBox(javax.swing.JComboBox combo, java.util.Collection<?> data, java.lang.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(javax.swing.JList list, java.util.Collection<?> data, java.lang.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, java.util.Collection<?> data, java.lang.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 java.awt.Container> O getParentContainer(java.lang.Object top, java.lang.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(java.lang.Object top, java.lang.Class<O> clazz)Find a parent of the giventopobject using the container api to get up. Stop on parent when it is of the givenclazztype.- 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(javax.swing.JTable table, java.awt.Font font, int columnIndex, java.lang.String suffix) -
fixTableColumnWidth
public static void fixTableColumnWidth(javax.swing.JTable table, int columnIndex, int width) -
setTableColumnEditor
public static void setTableColumnEditor(javax.swing.JTable table, int columnIndex, javax.swing.table.TableCellEditor editor) -
setTableColumnRenderer
public static void setTableColumnRenderer(javax.swing.JTable table, int columnIndex, javax.swing.table.TableCellRenderer editor) -
setI18nTableHeaderRenderer
public static void setI18nTableHeaderRenderer(javax.swing.JTable table, java.lang.String... libelles) -
newStringTableCellRenderer
public static javax.swing.table.TableCellRenderer newStringTableCellRenderer(javax.swing.table.DefaultTableCellRenderer renderer, int length, boolean tooltip) -
boxComponentWithJxLayer
public static <V extends javax.swing.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
-
getLayer
public static <V extends javax.swing.JComponent> org.jdesktop.jxlayer.JXLayer<V> getLayer(V comp) -
setLayerUI
public static void setLayerUI(javax.swing.JComponent comp, org.jdesktop.jxlayer.plaf.LayerUI<javax.swing.JComponent> ui) -
isLayered
public static boolean isLayered(javax.swing.JComponent comp) -
lookingForEditor
public static java.util.Map<java.lang.String,javax.swing.JComponent> lookingForEditor(java.lang.Class<?> clazz, java.awt.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(java.awt.Component parent, java.awt.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 javax.swing.UnsupportedLookAndFeelException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessExceptionTry to load the Nimbus look and feel.- Throws:
javax.swing.UnsupportedLookAndFeelException- if nimbus is not applicablejava.lang.ClassNotFoundExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
loadUIConfig
public static void loadUIConfig(java.lang.String defaultUIConfig, java.lang.String extraUIConfig) throws java.io.IOExceptionLoad 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:
java.io.IOException- if could not load the ui.properties file
-
loadUIConfig
public static void loadUIConfig(java.util.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<java.awt.Component> newTabbedPaneIterator(javax.swing.JTabbedPane tabs)Iterate the components of aJTabbedPanein natural order. Says using methodContainer.getComponent(int)- Parameters:
tabs- the- Returns:
- the iterator
- Since:
- 1.4
-
getSelectedModelRows
public static int[] getSelectedModelRows(javax.swing.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(javax.swing.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(javax.swing.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(javax.swing.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(javax.swing.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
-
newLabel
public static javax.swing.JLabel newLabel(java.lang.String text, java.lang.Object iconKey, int aligment) -
getDeepestObjectAt
public static java.awt.Component getDeepestObjectAt(java.awt.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 java.awt.Component findComponentAt(java.awt.Container cont, int width, int height, int x, int y) -
newDeleteCellRenderer
public static javax.swing.table.TableCellRenderer newDeleteCellRenderer(javax.swing.table.DefaultTableCellRenderer renderer) -
newBooleanTableCellRenderer
public static javax.swing.table.TableCellRenderer newBooleanTableCellRenderer(javax.swing.table.TableCellRenderer renderer) -
newBooleanTableCellRenderer
public static javax.swing.table.TableCellRenderer newBooleanTableCellRenderer(javax.swing.table.TableCellRenderer renderer, com.google.common.base.Predicate<?> predicate) -
newBooleanTableCellEditorAndRenderer
public static javax.swing.table.TableCellRenderer newBooleanTableCellEditorAndRenderer(javax.swing.table.TableCellRenderer renderer) -
newBooleanTableCellEditor
public static BooleanCellEditor newBooleanTableCellEditor(javax.swing.table.TableCellRenderer renderer) -
newEmptyNumberTableCellRenderer
public static EmptyNumberTableCellRenderer newEmptyNumberTableCellRenderer(javax.swing.table.TableCellRenderer renderer) -
newEnumTableCellRenderer
public static <E extends java.lang.Enum<E>> EnumTableCellRenderer<E> newEnumTableCellRenderer(javax.swing.table.TableCellRenderer renderer, java.lang.Class<E> enumClass) -
openLink
public static void openLink(javax.swing.event.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(java.lang.String url) -
expandTree
public static void expandTree(javax.swing.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(javax.swing.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(java.awt.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(java.awt.Component component, int height)Set the height of a given component.- Parameters:
component- the component to resizeheight- the new height to apply
-
createIcon
public static javax.swing.ImageIcon createIcon(java.lang.String path) -
createImageIcon
public static javax.swing.ImageIcon createImageIcon(java.lang.String path)- Parameters:
path- the location of icons in root directory icons- Returns:
- the icon at
getIconPath()+path
-
getUIManagerIcon
public static javax.swing.Icon getUIManagerIcon(java.lang.String key)- Parameters:
key- the key of the icon to retreave fromUIManager- Returns:
- the icon, or
nullif no icon found inUIManager
-
getUIManagerActionIcon
public static javax.swing.Icon getUIManagerActionIcon(java.lang.String key)retreave for theUIManagerthe icon prefixed byaction.- Parameters:
key- the key of the action icon to retreave fromUIManager- Returns:
- the icon, or
nullif no icon found inUIManager
-
createActionIcon
public static javax.swing.ImageIcon createActionIcon(java.lang.String name) -
createIcon
public static javax.swing.ImageIcon createIcon(java.lang.String classifier, java.lang.String name) -
createI18nIcon
public static javax.swing.ImageIcon createI18nIcon(java.lang.String name) -
makeTableTabFocusable
public static void makeTableTabFocusable(javax.swing.JTable table)AddKeyListenerto focus next editable cell on TAB key- Parameters:
table- to add TABKeyListener
-
editCell
public static boolean editCell(javax.swing.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(javax.swing.table.TableModel model, int rowIndex) throws java.lang.ArrayIndexOutOfBoundsException- Throws:
java.lang.ArrayIndexOutOfBoundsException
-
ensureColumnIndex
public static void ensureColumnIndex(javax.swing.table.TableModel model, int index) throws java.lang.ArrayIndexOutOfBoundsException- Throws:
java.lang.ArrayIndexOutOfBoundsException
-
scrollToTableSelection
public static void scrollToTableSelection(javax.swing.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(java.lang.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(java.net.URI uri) -
getDesktopForBrowse
public static java.awt.Desktop getDesktopForBrowse() -
newComboModel
public static javax.swing.DefaultComboBoxModel newComboModel(java.lang.Object... items)
-