net.sf.doolin.gui.swing
Class SwingUtils

java.lang.Object
  extended by net.sf.doolin.gui.swing.SwingUtils

public class SwingUtils
extends Object

Several utility methods for dealing with Swing.

Author:
Damien Coraboeuf

Nested Class Summary
static class SwingUtils.ClassComponentPredicate
          Checks the class of a component
 
Field Summary
static int XOR_STROKE_WIDTH
          Width of the stroke when drawing a shape
 
Method Summary
static void copyToolbar(JToolBar targetBar, JToolBar sourceBar)
          Copies items of a tool bar to another tool bar
static
<T> T
createWindow(Class<T> windowClass, Component parent)
          Creates an instance of a frame or a dialog
static void drawGrayShape(JComponent component, Rectangle shape)
          Draws a shape for a component
static void drawXORShape(JComponent component, Rectangle shape)
          Draws an XOR shape in a component
static Component findComponentInTree(Container parent, com.google.common.base.Predicate<Component> predicate)
          Recursively descends the parent container, applies the predicate to each component and returns the first one the predicate has returned true for.
static void setTableColumnWidth(JTable table, int column, ValueUnit width, boolean resizable)
          Set the width of a column
static Image toImage(Icon icon)
          Creates an image from an icon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XOR_STROKE_WIDTH

public static final int XOR_STROKE_WIDTH
Width of the stroke when drawing a shape

See Also:
drawXORShape(JComponent, Rectangle), Constant Field Values
Method Detail

copyToolbar

public static void copyToolbar(JToolBar targetBar,
                               JToolBar sourceBar)
Copies items of a tool bar to another tool bar

Parameters:
targetBar - Target tool bar
sourceBar - Source tool bar

createWindow

public static <T> T createWindow(Class<T> windowClass,
                                 Component parent)
Creates an instance of a frame or a dialog

Type Parameters:
T - Type of window
Parameters:
windowClass - Class of Window to create
parent - Parent component (can be null)
Returns:
Window

drawGrayShape

public static void drawGrayShape(JComponent component,
                                 Rectangle shape)
Draws a shape for a component

Parameters:
component - Component to draw the shape into
shape - Shape to draw
See Also:
drawXORShape(JComponent, Rectangle)

drawXORShape

public static void drawXORShape(JComponent component,
                                Rectangle shape)
Draws an XOR shape in a component

Parameters:
component - Component to draw the shape into
shape - Shape to draw

findComponentInTree

public static Component findComponentInTree(Container parent,
                                            com.google.common.base.Predicate<Component> predicate)
Recursively descends the parent container, applies the predicate to each component and returns the first one the predicate has returned true for.

Parameters:
parent - Parent container
predicate - Test predicate
Returns:
Found component or null

setTableColumnWidth

public static void setTableColumnWidth(JTable table,
                                       int column,
                                       ValueUnit width,
                                       boolean resizable)
Set the width of a column

Parameters:
table - Table
column - Column to set
width - Width to set
resizable - true if the column can be resized

toImage

public static Image toImage(Icon icon)
Creates an image from an icon. So far, only instances of ImageIcon are accepted.

Parameters:
icon - Icon
Returns:
Image or null if not appliable.


Copyright © 2011. All Rights Reserved.