public class GUIUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.awt.Color |
COLOR_LF_BLUE
Represents the Leisenfels blue.
|
static java.awt.Color |
COLOR_LF_GREEN
Represents the Leisenfels green.
|
static java.net.URL |
COMBO_BOX_ICON_EMPTY
Default combo box icon if not available.
|
static java.awt.datatransfer.DataFlavor |
javaURLListFlavor
Used for URL adresses deposited on the system's clipboard.
|
Constructor and Description |
---|
GUIUtils()
Constructor method for i18n purposes only.
|
Modifier and Type | Method and Description |
---|---|
static void |
addClipboardPopupMenu(java.awt.Component comp,
ContentGetter getter)
Creates a popup menu for component to copy text contents to clipboard.
|
static void |
addGlobalAccelerators(javax.swing.JDialog dialog,
javax.swing.JMenuItem[] items)
Installs keyboard actions based on a main window menu items.
|
static void |
addGlobalAccelerators(javax.swing.JFrame frame,
javax.swing.JMenuItem[] items)
Installs keyboard actions based on a main window menu items.
|
static void |
addPopupMenu(java.awt.Component target,
javax.swing.JPopupMenu menu)
Creates a popup menu for a target component to show up automatically.
|
static javax.swing.JCheckBoxMenuItem |
addViewMenuItem(javax.swing.JMenu menu,
java.awt.Component comp,
java.lang.String name)
Creates a "View" menu item to make main window components visible/invisible.
|
static int |
addXMLNode(javax.swing.tree.DefaultMutableTreeNode parent,
org.jdom.Element element,
int nodecount,
boolean setelement,
java.lang.String includeregex)
Recursive method to add new
DefaultMutableTreeNode for the given XML element. |
static void |
adjustColumnWidths(javax.swing.JTable table,
int margin)
Aligns the given table columns (set preferred widths to the maximum).
|
static void |
alignHorizontally(AlignmentDef[] defs)
Auto-aligns multiple panels with
TableLayout vertically. |
static void |
alignHorizontally(java.awt.Component... comps)
Aligns the given components (set preferred widths to the maximum).
|
static boolean |
checkEmptyTextField(javax.swing.JTextField field)
Checks if the given text field is empty and sets the background color appropriately.
|
static void |
clearClipboard(java.awt.datatransfer.Clipboard clipboard)
Removes all data from the given clipboard.
|
static void |
clearMenuSeparators(javax.swing.JMenu menu)
Removes redundant menu separators.
|
static void |
collectAllChildren(java.util.Vector<javax.swing.tree.DefaultMutableTreeNode> container,
javax.swing.tree.DefaultMutableTreeNode node)
Collects all children of the specified node.
|
static void |
collectAllExpandedChildren(java.util.Vector<javax.swing.tree.DefaultMutableTreeNode> container,
javax.swing.tree.DefaultMutableTreeNode node,
javax.swing.JTree tree)
Collects all children of the specified node being currently expanded.
|
static boolean |
containsItem(javax.swing.JComboBox box,
java.lang.Object item)
Determines whether the combo box already holds the specified item.
|
static void |
copyToClipboard(java.io.File[] files)
Copies the files to the system clipboard for other applications to use.
|
static void |
copyToClipboard(org.apache.commons.vfs2.FileObject[] urls)
Copies the URLs to the system clipboard for other applications to use.
|
static void |
copyToClipboard(java.lang.String text)
Copies the text to the system clipboard for other applications to use.
|
static java.awt.image.BufferedImage |
createColorImage(int width,
int height,
java.awt.Color color)
Creates a new image with specific background color and size.
|
static java.util.Vector<SuffixFilter> |
createImageWriterSuffixFilters()
Creates the supported image file suffices for writing.
|
static void |
debugAWTEventType(java.awt.AWTEvent event)
Prints info about the type of the given event.
|
static void |
debugInputMap(javax.swing.JComponent comp)
Prints info about the input map installed for the given component.
|
static void |
editFile(java.io.File target,
java.awt.Component comp,
StatusBar statusbar)
Let the system edit a file.
|
static void |
editTemporaryFile(java.io.File tempdir,
java.io.InputStream istream,
java.awt.Component comp,
boolean deleteonexit,
java.lang.String suffix)
Let the system open a file which is created temporarily from the given data stream.
|
static void |
editURL(org.apache.commons.vfs2.FileObject target,
java.awt.Component comp,
StatusBar statusbar)
Let the system edit a URL.
|
static void |
enableToolBarLabels(javax.swing.JToolBar toolbar,
boolean enable)
Enables or disables the labels shown by the
LabeledPanel instances of the toolbar. |
static void |
executeByEDT(java.lang.Runnable runner)
Makes sure that the given code is executed by the EDT.
|
static java.lang.Thread |
executeByThread(java.lang.Runnable runner)
Makes sure that the given code is executed by a separate thread (not the EDT).
|
static void |
expandAllNodes(javax.swing.JTree tree,
javax.swing.tree.DefaultMutableTreeNode node)
Causes the given node and it's childs to expand.
|
static java.lang.Thread |
findEventDispatchThread()
Searches for the current event dispatch thread.
|
static void |
getAllComponents(java.awt.Component comp,
java.util.Vector<java.awt.Component> collector,
java.lang.String type)
Determines the children of the given GUI component and collects them recursively.
|
static java.awt.image.BufferedImage |
getBufferedImage(javax.swing.ImageIcon icon)
Convenience to convert an
ImageIcon into a BufferedImage . |
static int |
getColumnWidth(info.clearthought.layout.TableLayout layout,
int column)
Provides the width of the column in pixels for a
TableLayout . |
static java.util.Hashtable<java.lang.Integer,java.lang.Integer> |
getColumnWidths(javax.swing.JTable table)
Remembers the current column widths to be restored.
|
static java.lang.String |
getComboBoxIconText(java.lang.String text,
javax.swing.ImageIcon icon)
Converts the given combo box text so that the given icon is also displayed (HTML code).
|
static int |
getComponentIndex(java.awt.Container container,
java.awt.Component comp)
Determines the component's index within the container.
|
static javax.swing.ImageIcon |
getGrayscaleIcon(javax.swing.ImageIcon icon)
Provides the image as grayscale variant.
|
static java.lang.String |
getHTMLColor(java.awt.Color color)
Converts the Java color to a HTML compatible string representation.
|
static byte[] |
getIconData(javax.swing.ImageIcon icon,
java.lang.String format)
Gets the binary data of an icon image in the desired format.
|
static long |
getIconFileSize(javax.swing.ImageIcon icon)
Provides the length of the icon file in bytes.
|
static javax.swing.ImageIcon |
getIconVariant(javax.swing.ImageIcon icon,
int newsize)
Provides the image in a different size.
|
static byte[] |
getImageData(java.awt.image.BufferedImage image,
java.lang.String format)
Gets the binary data of an image in the desired format.
|
static javax.swing.JPopupMenu |
getPopupMenu(javax.swing.JMenuItem item)
Recurses the parent containers as long as the popup component is found.
|
static java.awt.Image |
getScaledInstance(java.awt.Image image,
java.awt.Component observer,
int shrink)
Returns a scaled instance of the desired image.
|
static java.awt.Image |
getScaledInstance(java.awt.Image image,
java.awt.Component observer,
int maxwidth,
int maxheight)
Returns a scaled instance of the desired image.
|
static java.awt.Component[] |
getTabComponents(javax.swing.JTabbedPane tabbedPane)
Returns the tab components if available.
|
static javax.swing.AbstractButton |
getToolBarButton(javax.swing.JToolBar toolbar,
java.lang.String actioncommand)
Determines the tool bar button if one is associated with the menu items via action command.
|
static LabeledPanel |
getToolBarButtonPanel(javax.swing.JToolBar toolbar,
java.lang.String actioncommand)
Determines the tool bar button panel if one is associated with the menu items via action command.
|
static boolean |
hasTabComponent(javax.swing.JTabbedPane tabbedPane,
java.awt.Component comp)
Returns the tab components if available.
|
static int |
indexOf(javax.swing.JMenu menu,
javax.swing.JMenuItem item,
int fallback)
Determines the index of the given menu item within the given menu.
|
static void |
installActionListeners(javax.swing.JCheckBox comp,
java.awt.event.ActionListener[] listeners)
Installs the
ActionListener s. |
static void |
installChangeListeners(javax.swing.JCheckBox comp,
javax.swing.event.ChangeListener[] listeners)
Installs the
ChangeListener s. |
static void |
installEnterListener(javax.swing.text.JTextComponent field,
javax.swing.AbstractButton button)
Installs a
KeyListener listening for ENTER/RETURN hits to click a button. |
static void |
installEnterListener(javax.swing.text.JTextComponent field,
java.lang.Runnable runner)
Installs a
KeyListener listening for ENTER/RETURN hits to execute some code. |
static java.awt.event.FocusListener |
installFocusClearListener(javax.swing.text.JTextComponent field)
Installs a
FocusListener to clear the text field if the user starts working. |
static java.awt.event.FocusListener |
installFocusSelectionListener(javax.swing.text.JTextComponent field)
Installs a
FocusListener detecting when the focus is gained and selects the text. |
static void |
installGroupPopup(java.util.Vector boxes)
Creates popup menues for check boxes that auto-selects all or none of the boxes.
|
static java.awt.event.FocusListener |
installHintListener(javax.swing.text.JTextComponent field,
java.lang.String text)
Shows a certain text and stops displaying it when the text field gets the focus.
|
static void |
installResolutionMenuItems(javax.swing.JMenu menu,
javax.swing.JFrame window)
Creates the default menu items for main window resolutions.
|
static Configuration |
installTextAreaPopup(javax.swing.JTextArea textarea,
boolean autoscroll,
boolean autoscrollenabled,
boolean clearenabled,
boolean copyenabled)
Creates a popup menu for a text area with default items.
|
static void |
installToolBarMenu(javax.swing.JMenu menu,
javax.swing.JToolBar toolbar,
boolean separators)
Creates a menu for a toolbar with buttons including the enabled state.
|
static void |
installToolBarPopup(javax.swing.JPopupMenu popupmenu,
javax.swing.JToolBar toolbar,
boolean separators)
Creates a popup menu for a toolbar with buttons including the enabled state.
|
static javax.swing.JPopupMenu |
installToolBarPopup(javax.swing.JToolBar toolbar,
javax.swing.JMenuItem toolbaritem,
javax.swing.JMenuItem labelsitem,
boolean labeled)
Installs the default toolbar popup to show/hide the component, the labels etc.
|
static java.awt.event.HierarchyBoundsListener |
installWindowResizeListener(StatusBar statusbar,
javax.swing.JDialog dialog)
Installs listener to display the current window/dialog size when resized.
|
static java.awt.event.HierarchyBoundsListener |
installWindowResizeListener(StatusBar statusbar,
javax.swing.JFrame frame)
Installs listener to display the current window/dialog size when resized.
|
static boolean |
isChildOf(java.awt.Component comp,
java.awt.Container container)
Determines whether the given component is a child of the parent.
|
static boolean |
isClipboardLoaded(java.awt.datatransfer.Clipboard clipboard)
Determines whether the given clipboard is currently loaded.
|
static boolean |
isEventDispatchThread(java.lang.Thread thread)
Determines whether the given thread is the event dispatch thread or not.
|
static boolean |
isScrollable(java.awt.Component comp)
Checks the given component if any sub-component (if any) is a
JScrollPane . |
static javax.swing.ImageIcon |
loadImage(byte[] data)
Tries to load an
Image object from a raw data array. |
static javax.swing.ImageIcon |
loadImage(java.io.InputStream istream)
Tries to load an
Image object from a raw data stream. |
static javax.swing.ImageIcon |
loadImage(java.lang.String url)
Tries to load an
Image object from a specified URL. |
static javax.swing.ImageIcon |
loadImage(java.net.URL url)
Tries to load an
Image object from a specified URL. |
static javax.swing.ImageIcon |
loadImageVFS(org.apache.commons.vfs2.FileObject target)
Tries to load an
Image object from a specified VFS URL. |
static void |
makeComponentVisible(java.awt.Component comp)
Scroll automatically the viewport for the given component.
|
static void |
makeRowVisible(javax.swing.JTable table,
int row)
Scroll automatically the viewport to the desired row.
|
static java.lang.String |
mapFilterIDToImageMIME(java.lang.String filterid)
Maps the image format identifiers from
ModelDelegate to MIME types. |
static java.lang.String |
mapFilterIDToImageSuffix(java.lang.String filterid)
Maps the image format identifiers from
ModelDelegate to writer formats. |
static java.lang.String |
mapFromImageType(int type)
Maps the given numerical image type to the corresponding text representation.
|
static java.lang.String |
mapFromSwingConstant(int constant)
Maps the given numerical constant to the corresponding text representation.
|
static java.lang.String |
mapFromTransparency(int type)
Maps the given numerical image type to the corresponding text representation.
|
static void |
openFile(java.io.File target,
java.awt.Component comp,
StatusBar statusbar)
Let the system open a file.
|
static void |
openTemporaryFile(java.io.File tempdir,
java.io.InputStream istream,
java.awt.Component comp,
boolean deleteonexit,
java.lang.String suffix)
Let the system open a file which is created temporarily from the given data stream.
|
static void |
openURL(org.apache.commons.vfs2.FileObject target,
java.awt.Component comp,
StatusBar statusbar)
Let the system open a URL.
|
static int |
populateTreeFromXML(javax.swing.tree.DefaultMutableTreeNode root,
boolean setelement,
java.lang.String includeregex,
org.jdom.Element... elements)
Assembles a
JTree from the given XML data. |
static int |
removeAllChildrenRecursively(javax.swing.tree.DefaultMutableTreeNode node)
Removes all child nodes from the given node by removing each single node from its parent.
|
static boolean |
replaceItem(javax.swing.JComboBox box,
java.lang.Object olditem,
java.lang.Object newitem)
Determines whether the combo box already holds the specified item.
|
static java.awt.image.BufferedImage |
rotate270(java.awt.image.BufferedImage image)
Rotates the given image 270 degrees counter wise.
|
static java.awt.image.BufferedImage |
rotate90(java.awt.image.BufferedImage image)
Rotates the given image 90 degrees counter wise.
|
static void |
setButtonGroup(javax.swing.JCheckBox... boxes)
Implements mutual exclusion for the given
JCheckBox es. |
static void |
setEnabledAllComponents(java.awt.Container parent,
boolean enable)
Enables/disables the components of this given container.
|
static void |
setEnabledAllComponents(java.awt.Container parent,
boolean enable,
java.lang.Class[] excludes)
Enables/disables the components of this given container.
|
static void |
setHeadlessMode(boolean value,
boolean force)
Sets/overwrite the headless parameter of this JVM.
|
static void |
setNumericOnly(javax.swing.JTextField field,
boolean beep)
Configures a text field so that only numbers can be typed.
|
static void |
setSelectedValues(javax.swing.JList list,
java.util.Vector data,
java.lang.Object[] selection)
Compensates the lack of the
JList.setSelectedValues() method. |
static void |
setShowErrorColors(javax.swing.JEditorPane editor,
boolean error)
Sets the default error colors for a text editor.
|
static void |
setShowErrorColors(javax.swing.JTextArea textarea,
boolean error)
Sets the default error colors for a text editor.
|
static void |
setShowErrorColors(javax.swing.JTextField field,
boolean error)
Sets the default error colors for a text field.
|
static java.awt.event.ItemListener |
syncComponentsEnable(javax.swing.JCheckBox master,
java.awt.Component... slaves)
Enables/disables components depending on a check box state.
|
static java.awt.event.ItemListener |
syncComponentsEnable(javax.swing.JRadioButton master,
java.awt.Component... slaves)
Enables/disables components depending on a radio button state.
|
static java.beans.PropertyChangeListener |
syncCompsEnable(java.awt.Component master,
java.awt.Component slave)
Synchronizes the enabled state of two components.
|
static void |
syncTableGroup(javax.swing.JTable[] tables)
Synchronizes a group of table instances (column widths).
|
static void |
syncToggleButtonGroup(javax.swing.JToggleButton[] buttons)
Synchronizes a group of toggle buttons.
|
static java.awt.event.ActionListener[] |
uninstallActionListeners(javax.swing.JCheckBox comp)
Uninstalls the
ActionListener s and provides them for re-install. |
static javax.swing.event.ChangeListener[] |
uninstallChangeListeners(javax.swing.JCheckBox comp)
Uninstalls the
ChangeListener s and provides them for re-install. |
static void |
uninstallWindowResizeListener(javax.swing.JDialog dialog,
java.awt.event.HierarchyBoundsListener listener)
Uninstalls listener to display the current window/dialog size when resized.
|
static java.lang.String |
wrapButtonText(java.lang.String rawtext,
int lines)
Wraps the given text to be displayed at the bottom of a
JButton . |
public static final java.awt.Color COLOR_LF_GREEN
public static final java.awt.Color COLOR_LF_BLUE
public static final java.net.URL COMBO_BOX_ICON_EMPTY
public static final java.awt.datatransfer.DataFlavor javaURLListFlavor
public GUIUtils() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic static void getAllComponents(java.awt.Component comp, java.util.Vector<java.awt.Component> collector, java.lang.String type)
type
is null
, all components are collected.
comp
- The AWT component to searchcollector
- The container to fill with resultstype
- Filtering class name, others are rejectedjava.lang.NullPointerException
- If a parameter is null
public static java.awt.Component[] getTabComponents(javax.swing.JTabbedPane tabbedPane)
tabbedPane
- The tabbed panepublic static boolean hasTabComponent(javax.swing.JTabbedPane tabbedPane, java.awt.Component comp)
tabbedPane
- The tabbed panecomp
- The desired componentpublic static java.awt.Image getScaledInstance(java.awt.Image image, java.awt.Component observer, int maxwidth, int maxheight)
null
return value. The result image does NOT exceed
the maximum width or height. The method always scales it down with the correct ratio
so that the width and height relation of the original image is kept. The default scaling
method is SMOOTH
.
image
- The image to be scaledobserver
- The component for the contextmaxwidth
- Desired width of the scaled instancemaxheight
- Desired height of the scaled instancepublic static java.awt.Image getScaledInstance(java.awt.Image image, java.awt.Component observer, int shrink)
null
return value. The method always scales it down
with the correct ratio so that the width and height relation of the original image is kept.
The default scaling method is SMOOTH
.
image
- The image to be scaledobserver
- The component for the contextshrink
- Desired shrink factor between 1 and 100%java.lang.IllegalArgumentException
- If parameters are invalidpublic static javax.swing.ImageIcon loadImage(java.lang.String url)
Image
object from a specified URL.
url
- The location to load as an imagenull
if an error occursloadImage(URL)
,
loadImageVFS(FileObject)
public static javax.swing.ImageIcon loadImage(java.net.URL url)
Image
object from a specified URL.
This method directly loads the data without any caching. Perhaps you like to use the new
ImageFactory
functionality in order to increase performance.
url
- The location to load as an imagenull
if an error occursloadImage(String)
,
loadImageVFS(FileObject)
,
ImageFactory
public static javax.swing.ImageIcon loadImageVFS(org.apache.commons.vfs2.FileObject target)
Image
object from a specified VFS URL.
This method directly loads the data without any caching. Perhaps you like to use the new
ImageFactory
functionality in order to increase performance.
target
- The VFS file to load as an imagenull
if an error occursloadImage(String)
,
loadImage(URL)
public static javax.swing.ImageIcon loadImage(byte[] data)
Image
object from a raw data array.
This method directly loads the data without any caching. Perhaps you like to use the new
ImageFactory
functionality in order to increase performance.
data
- The raw data to load as an imagenull
if an error occursloadImage(String)
,
loadImage(URL)
public static javax.swing.ImageIcon loadImage(java.io.InputStream istream)
Image
object from a raw data stream.
This method directly loads the data without any caching. Perhaps you like to use the new
ImageFactory
functionality in order to increase performance.
istream
- The stream to load as an imagenull
if an error occursloadImage(String)
,
loadImage(URL)
public static java.util.Vector<SuffixFilter> createImageWriterSuffixFilters()
public static java.lang.String mapFilterIDToImageSuffix(java.lang.String filterid)
ModelDelegate
to writer formats.
filterid
- The identifiernull
otherwisepublic static java.lang.String mapFilterIDToImageMIME(java.lang.String filterid)
ModelDelegate
to MIME types.
filterid
- The identifiernull
otherwisepublic static java.awt.image.BufferedImage rotate90(java.awt.image.BufferedImage image)
image
- The image to be rotatedpublic static java.awt.image.BufferedImage rotate270(java.awt.image.BufferedImage image)
image
- The image to be rotatedpublic static javax.swing.JPopupMenu getPopupMenu(javax.swing.JMenuItem item)
item
- The item where the recursion startsnull
public static int getComponentIndex(java.awt.Container container, java.awt.Component comp)
container
- The container with componentscomp
- The desired componentpublic static javax.swing.JCheckBoxMenuItem addViewMenuItem(javax.swing.JMenu menu, java.awt.Component comp, java.lang.String name)
menu
- The target menu to add the itemcomp
- The desired componentname
- The menu item namejava.lang.NullPointerException
- Error casepublic static void expandAllNodes(javax.swing.JTree tree, javax.swing.tree.DefaultMutableTreeNode node)
tree
- The tree the node belongs tonode
- The starting point for expansionpublic static void collectAllChildren(java.util.Vector<javax.swing.tree.DefaultMutableTreeNode> container, javax.swing.tree.DefaultMutableTreeNode node)
container
- Cache for the nodesnode
- The starting point for te searchpublic static boolean containsItem(javax.swing.JComboBox box, java.lang.Object item)
box
- The combo box to be searcheditem
- The item objectpublic static boolean replaceItem(javax.swing.JComboBox box, java.lang.Object olditem, java.lang.Object newitem)
box
- The combo box to be searchedolditem
- The existing item objectnewitem
- The replacementpublic static void collectAllExpandedChildren(java.util.Vector<javax.swing.tree.DefaultMutableTreeNode> container, javax.swing.tree.DefaultMutableTreeNode node, javax.swing.JTree tree)
container
- Cache for the expanded nodesnode
- The starting point for the searchtree
- The analyzed treepublic static int removeAllChildrenRecursively(javax.swing.tree.DefaultMutableTreeNode node)
node
- The starting point for the removalpublic static boolean isChildOf(java.awt.Component comp, java.awt.Container container)
comp
- The assumed child componentcontainer
- The parental containerjava.lang.NullPointerException
- Error casepublic static javax.swing.AbstractButton getToolBarButton(javax.swing.JToolBar toolbar, java.lang.String actioncommand)
toolbar
- The container to search for buttonsactioncommand
- The action command, or null
if not availablepublic static LabeledPanel getToolBarButtonPanel(javax.swing.JToolBar toolbar, java.lang.String actioncommand)
toolbar
- The container to search for buttonsactioncommand
- The action command, or null
if not availablepublic static void enableToolBarLabels(javax.swing.JToolBar toolbar, boolean enable)
LabeledPanel
instances of the toolbar.
toolbar
- The container to search for buttonsenable
- The new statepublic static void setNumericOnly(javax.swing.JTextField field, boolean beep)
field
- The text fieldbeep
- Give acoustic feedback if non-digit is typedpublic static void addPopupMenu(java.awt.Component target, javax.swing.JPopupMenu menu)
target
- The componentmenu
- The menu to showpublic static void openFile(java.io.File target, java.awt.Component comp, StatusBar statusbar)
target
- The target file to be openedcomp
- The component to set the cursorstatusbar
- The status bar for message (optional)public static void openURL(org.apache.commons.vfs2.FileObject target, java.awt.Component comp, StatusBar statusbar)
target
- The target entry to be openedcomp
- The component to set the cursorstatusbar
- The status bar for message (optional)public static void openTemporaryFile(java.io.File tempdir, java.io.InputStream istream, java.awt.Component comp, boolean deleteonexit, java.lang.String suffix)
tempdir
- The temporary directoryistream
- The data streamcomp
- The component to set the cursordeleteonexit
- Delete if application terminates?suffix
- The optional file extension e.g. ".png"public static void editTemporaryFile(java.io.File tempdir, java.io.InputStream istream, java.awt.Component comp, boolean deleteonexit, java.lang.String suffix)
tempdir
- The temporary directoryistream
- The data streamcomp
- The component to set the cursordeleteonexit
- Delete if application terminates?suffix
- The optional file extension e.g. ".png"public static void editFile(java.io.File target, java.awt.Component comp, StatusBar statusbar)
target
- The target file to be openedcomp
- The component to set the cursorstatusbar
- The status bar for message (optional)public static void editURL(org.apache.commons.vfs2.FileObject target, java.awt.Component comp, StatusBar statusbar)
target
- The target entry to be openedcomp
- The component to set the cursorstatusbar
- The status bar for message (optional)public static boolean isEventDispatchThread(java.lang.Thread thread)
thread
- The thread to be checkedpublic static java.lang.Thread findEventDispatchThread()
null
public static java.awt.image.BufferedImage createColorImage(int width, int height, java.awt.Color color)
width
- Desired image widthheight
- Desired image heightcolor
- Background color of the imagenull
if an error occurredpublic static void makeRowVisible(javax.swing.JTable table, int row)
table
- Target tablerow
- Desired row indexpublic static void installGroupPopup(java.util.Vector boxes)
boxes
- The check boxespublic static void alignHorizontally(java.awt.Component... comps)
comps
- The components to alignjava.lang.NullPointerException
- Error casepublic static java.lang.String getHTMLColor(java.awt.Color color)
color
- The Java colorjava.lang.NullPointerException
- Error casepublic static void adjustColumnWidths(javax.swing.JTable table, int margin)
table
- The table component to get renderers etc.margin
- Optional margin width in pixelsjava.lang.NullPointerException
- If the parameters are null
java.lang.IllegalArgumentException
- If parameters are invalidpublic static void installToolBarPopup(javax.swing.JPopupMenu popupmenu, javax.swing.JToolBar toolbar, boolean separators)
getName()
method. The separators are created
if desired. The action command is set for the menu items to identify mouse clicks.
popupmenu
- The popup menu to be filledtoolbar
- The button containerseparators
- Synchronize separators?java.lang.NullPointerException
- If the parameters are null
public static void installToolBarMenu(javax.swing.JMenu menu, javax.swing.JToolBar toolbar, boolean separators)
getName()
method. The separators are created
if desired. The action command is set for the menu items to identify mouse clicks.
menu
- The menu to be filledtoolbar
- The button containerseparators
- Synchronize separators?java.lang.NullPointerException
- If the parameters are null
public static java.util.Hashtable<java.lang.Integer,java.lang.Integer> getColumnWidths(javax.swing.JTable table)
table
- The table component to get renderers etc.java.lang.NullPointerException
- If the parameters are null
public static void setEnabledAllComponents(java.awt.Container parent, boolean enable)
parent
- The parental containerenable
- New component statepublic static void setEnabledAllComponents(java.awt.Container parent, boolean enable, java.lang.Class[] excludes)
parent
- The parental containerenable
- New component stateexcludes
- List of classes to be excluded e.g. labels (optional)public static int getColumnWidth(info.clearthought.layout.TableLayout layout, int column)
TableLayout
.
layout
- The layout managercolumn
- Index of desired columnjava.lang.NullPointerException
- If the parameters are null
java.lang.IllegalArgumentException
- If parameters are invalidpublic static void alignHorizontally(AlignmentDef[] defs)
TableLayout
vertically.
This method allows for proper alignment of separate panels which are grouped together within
a container in multiple rows. Simply specify the layout, the column to be aligned and
the column to be resized (normally a column holding a label or with no content at all).
defs
- The alignment definitionspublic static java.beans.PropertyChangeListener syncCompsEnable(java.awt.Component master, java.awt.Component slave)
master
- The component to get the enabled state fromslave
- The component to set the enabled statepublic static void installEnterListener(javax.swing.text.JTextComponent field, javax.swing.AbstractButton button)
KeyListener
listening for ENTER/RETURN hits to click a button.
field
- The input field to listen for ENTER/RETURNbutton
- The button to clickjava.lang.NullPointerException
- If the parameters are null
public static void installEnterListener(javax.swing.text.JTextComponent field, java.lang.Runnable runner)
KeyListener
listening for ENTER/RETURN hits to execute some code.
field
- The input field to listen for ENTER/RETURNrunner
- The code to be executedjava.lang.NullPointerException
- If the parameters are null
public static java.awt.event.FocusListener installFocusSelectionListener(javax.swing.text.JTextComponent field)
FocusListener
detecting when the focus is gained and selects the text.
field
- The input field to be observedjava.lang.NullPointerException
- If the parameters are null
public static java.awt.event.FocusListener installHintListener(javax.swing.text.JTextComponent field, java.lang.String text)
field
- The input field to be observedtext
- The hint textjava.lang.NullPointerException
- If the parameters are null
public static javax.swing.ImageIcon getIconVariant(javax.swing.ImageIcon icon, int newsize)
description
attribute of the icons and can be used
to search the desired icon variants. The method return null if the desired image cannot
be loaded from the same directory as the original image.
icon
- The original iconnewsize
- The desired image sizenull
if it does not existjava.lang.NullPointerException
- If the parameters are null
public static java.lang.String getComboBoxIconText(java.lang.String text, javax.swing.ImageIcon icon)
null
then an empty placeholder is displayed instead.
text
- The original text for the comboicon
- The icon for the combojava.lang.NullPointerException
- If the parameters are null
public static void debugInputMap(javax.swing.JComponent comp)
comp
- The component to be analyzedjava.lang.NullPointerException
- If the parameters are null
public static void setSelectedValues(javax.swing.JList list, java.util.Vector data, java.lang.Object[] selection)
JList.setSelectedValues()
method.
list
- The componentdata
- The container (list model)selection
- The desired selectionjava.lang.NullPointerException
- If the parameters are null
public static boolean checkEmptyTextField(javax.swing.JTextField field)
field
- The componentjava.lang.NullPointerException
- If the parameters are null
public static void setShowErrorColors(javax.swing.JTextField field, boolean error)
field
- The componenterror
- Indicate error?java.lang.NullPointerException
- If the parameters are null
public static void setShowErrorColors(javax.swing.JEditorPane editor, boolean error)
editor
- The componenterror
- Indicate error?java.lang.NullPointerException
- If the parameters are null
public static void setShowErrorColors(javax.swing.JTextArea textarea, boolean error)
textarea
- The componenterror
- Indicate error?java.lang.NullPointerException
- If the parameters are null
public static void debugAWTEventType(java.awt.AWTEvent event)
event
- The event to be analyzedjava.lang.NullPointerException
- If the parameters are null
public static java.awt.event.ItemListener syncComponentsEnable(javax.swing.JCheckBox master, java.awt.Component... slaves)
master
- The check box to get the enabled state fromslaves
- The follower componentspublic static java.awt.event.ItemListener syncComponentsEnable(javax.swing.JRadioButton master, java.awt.Component... slaves)
master
- The radio box to get the enabled state fromslaves
- The follower componentspublic static java.awt.image.BufferedImage getBufferedImage(javax.swing.ImageIcon icon)
ImageIcon
into a BufferedImage
.
icon
- The image iconnull
public static java.awt.event.FocusListener installFocusClearListener(javax.swing.text.JTextComponent field)
FocusListener
to clear the text field if the user starts working.
The listener is automatically removed if the text component gains the focus for the first
time.
field
- The input field to be observedjava.lang.NullPointerException
- If the parameters are null
public static long getIconFileSize(javax.swing.ImageIcon icon)
icon
- The image iconpublic static byte[] getIconData(javax.swing.ImageIcon icon, java.lang.String format)
icon
- The image iconformat
- png|gif|...null
indicates errorpublic static byte[] getImageData(java.awt.image.BufferedImage image, java.lang.String format)
image
- The imageformat
- png|gif|...null
indicates errorpublic static java.lang.String mapFromImageType(int type)
type
- The value BufferedImage.TYPE_INT_RGB
|...null
if not a valid typepublic static java.lang.String mapFromTransparency(int type)
type
- The value BufferedImage.TYPE_INT_RGB
|...null
if not a valid typepublic static java.lang.String mapFromSwingConstant(int constant)
constant
- The internal valuenull
if not a valid modepublic static java.awt.event.HierarchyBoundsListener installWindowResizeListener(StatusBar statusbar, javax.swing.JDialog dialog)
statusbar
- The output componentdialog
- The monitored componentjava.lang.NullPointerException
- If the parameters are null
public static void uninstallWindowResizeListener(javax.swing.JDialog dialog, java.awt.event.HierarchyBoundsListener listener)
dialog
- The monitored componentlistener
- The listenerjava.lang.NullPointerException
- If the parameters are null
public static java.awt.event.HierarchyBoundsListener installWindowResizeListener(StatusBar statusbar, javax.swing.JFrame frame)
statusbar
- The output componentframe
- The monitored componentjava.lang.NullPointerException
- If the parameters are null
public static void installResolutionMenuItems(javax.swing.JMenu menu, javax.swing.JFrame window)
menu
- The parental menuwindow
- The target windowpublic static javax.swing.ImageIcon getGrayscaleIcon(javax.swing.ImageIcon icon)
icon
- The original iconnull
if not availablejava.lang.NullPointerException
- If the parameters are null
public static boolean isScrollable(java.awt.Component comp)
JScrollPane
.
comp
- The AWT component to searchJScrollPane
?java.lang.NullPointerException
- If a parameter is null
public static void makeComponentVisible(java.awt.Component comp)
comp
- Component to be made visiblepublic static void addGlobalAccelerators(javax.swing.JDialog dialog, javax.swing.JMenuItem[] items)
dialog
- The dialogitems
- The menu items holding the accelerators and listenersjava.lang.NullPointerException
- If a parameter is null
public static void addGlobalAccelerators(javax.swing.JFrame frame, javax.swing.JMenuItem[] items)
frame
- The windowitems
- The menu items holding the accelerators and listenersjava.lang.NullPointerException
- If a parameter is null
public static void syncToggleButtonGroup(javax.swing.JToggleButton[] buttons)
buttons
- The toggle buttonsjava.lang.NullPointerException
- If the parameters are null
public static void syncTableGroup(javax.swing.JTable[] tables)
tables
- The tablesjava.lang.NullPointerException
- If the parameters are null
public static Configuration installTextAreaPopup(javax.swing.JTextArea textarea, boolean autoscroll, boolean autoscrollenabled, boolean clearenabled, boolean copyenabled)
textarea
- The text areaautoscroll
- Item "Auto-scroll" is selected (toggle)?autoscrollenabled
- Item "Auto-scroll" is enabled?clearenabled
- Item "Clear" is enabled?copyenabled
- Item "Copy" is enabled?java.lang.NullPointerException
- If the parameters are null
public static int populateTreeFromXML(javax.swing.tree.DefaultMutableTreeNode root, boolean setelement, java.lang.String includeregex, org.jdom.Element... elements)
JTree
from the given XML data.
For each XML element a new node is added in the hierarchy defined by the XML document.
root
- The starting point to add nodessetelement
- Set the Element
's as user object in nodes?includeregex
- Regular expression to include elements (optional)elements
- The XML data on the top-levelpublic static int addXMLNode(javax.swing.tree.DefaultMutableTreeNode parent, org.jdom.Element element, int nodecount, boolean setelement, java.lang.String includeregex)
DefaultMutableTreeNode
for the given XML element.
parent
- The starting point to add nodeselement
- The XML data to addnodecount
- The number of nodes added so farsetelement
- Set the Element
's as user object in nodes?includeregex
- Regular expression to include elements (optional)public static javax.swing.event.ChangeListener[] uninstallChangeListeners(javax.swing.JCheckBox comp)
ChangeListener
s and provides them for re-install.
comp
- The componentjava.lang.NullPointerException
- If the parameters are null
public static void installChangeListeners(javax.swing.JCheckBox comp, javax.swing.event.ChangeListener[] listeners)
ChangeListener
s.
comp
- The componentlisteners
- The new listenersjava.lang.NullPointerException
- If the parameters are null
public static java.awt.event.ActionListener[] uninstallActionListeners(javax.swing.JCheckBox comp)
ActionListener
s and provides them for re-install.
comp
- The componentjava.lang.NullPointerException
- If the parameters are null
public static void installActionListeners(javax.swing.JCheckBox comp, java.awt.event.ActionListener[] listeners)
ActionListener
s.
comp
- The componentlisteners
- The new listenersjava.lang.NullPointerException
- If the parameters are null
public static java.lang.String wrapButtonText(java.lang.String rawtext, int lines)
JButton
.
rawtext
- The unformatted textlines
- The number of lines, -1 = dynamicpublic static javax.swing.JPopupMenu installToolBarPopup(javax.swing.JToolBar toolbar, javax.swing.JMenuItem toolbaritem, javax.swing.JMenuItem labelsitem, boolean labeled)
toolbar
- The toolbartoolbaritem
- The associated menu item (optional)labelsitem
- The associated menu item (optional)labeled
- Show the component labels?public static void executeByEDT(java.lang.Runnable runner)
runner
- The code to be executedpublic static java.lang.Thread executeByThread(java.lang.Runnable runner)
runner
- The code to be executednull
otherwisepublic static void copyToClipboard(java.lang.String text)
text
- The text to be copiedpublic static void copyToClipboard(java.io.File[] files)
files
- The files to be copiedpublic static void copyToClipboard(org.apache.commons.vfs2.FileObject[] urls)
urls
- The network files to be copiedpublic static void clearClipboard(java.awt.datatransfer.Clipboard clipboard)
clipboard
- The clipboard to be clearedjava.lang.IllegalStateException
- If the clipboard is currently unavailablepublic static boolean isClipboardLoaded(java.awt.datatransfer.Clipboard clipboard)
clipboard
- The clipboard to be checkedjava.lang.IllegalStateException
- If the clipboard is currently unavailablepublic static int indexOf(javax.swing.JMenu menu, javax.swing.JMenuItem item, int fallback)
menu
- The parental menuitem
- The item to search forfallback
- The failsafe indexpublic static void clearMenuSeparators(javax.swing.JMenu menu)
menu
- The parental menujava.lang.NullPointerException
- If a parameter is null
public static void setButtonGroup(javax.swing.JCheckBox... boxes)
JCheckBox
es.
boxes
- The check boxesjava.lang.NullPointerException
- If the parameters are null
public static void addClipboardPopupMenu(java.awt.Component comp, ContentGetter getter)
comp
- The componentgetter
- Instance getting the text to be copiedjava.lang.NullPointerException
- If the parameters are null
public static void setHeadlessMode(boolean value, boolean force)
value
- The new valueforce
- Overwrite via refelection?java.lang.NullPointerException
- If the parameters are null
Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.