com.iver.cit.gvsig.gui
Class GUIUtil

java.lang.Object
  extended bycom.iver.cit.gvsig.gui.GUIUtil

public class GUIUtil
extends java.lang.Object


Nested Class Summary
static class GUIUtil.Location
           
 
Field Summary
static javax.swing.filechooser.FileFilter ALL_FILES_FILTER
           
static java.lang.String dbf
           
static java.lang.String dbfDesc
           
static java.lang.String fme
           
static java.lang.String fmeDesc
           
static java.lang.String gml
           
static java.lang.String gmlDesc
           
static java.lang.String jml
           
static java.lang.String jmlDesc
           
static java.lang.String shp
           
static java.lang.String shpDesc
           
static java.lang.String shx
           
static java.lang.String shxDesc
           
static java.lang.String wkt
           
static java.lang.String wktaDesc
           
static java.lang.String wktDesc
           
static java.lang.String xml
           
static java.lang.String xmlDesc
           
 
Constructor Summary
GUIUtil()
           
 
Method Summary
static java.awt.geom.Point2D add(java.awt.geom.Point2D a, java.awt.geom.Point2D b)
           
static void addInternalFrameListener(javax.swing.JDesktopPane pane, javax.swing.event.InternalFrameListener listener)
          Listens to all internal frames (current and future) in a JDesktopPane.
static java.awt.Color alphaColor(java.awt.Color color, int alpha)
           
static void centre(java.awt.Component componentToMove, java.awt.Component componentToCentreOn)
          Centres the first component on the second
static void centreOnScreen(java.awt.Component componentToMove)
          Centres the component on the screen
static void centreOnWindow(java.awt.Component componentToMove)
          Centres the component on its window
static void chooseGoodColumnWidths(javax.swing.JTable table)
          Sets the column widths based on the first row.
static javax.swing.filechooser.FileFilter createFileFilter(java.lang.String description, java.lang.String[] extensions)
           
static javax.swing.JFileChooser createJFileChooserWithExistenceChecking()
           
static javax.swing.JFileChooser createJFileChooserWithOverwritePrompting()
           
static javax.swing.Timer createRestartableSingleEventTimer(int delay, java.awt.event.ActionListener listener)
          Returns a Timer that fires once, after the delay.
static ValidatingTextField createSyncdTextField(javax.swing.JSlider s)
           
static ValidatingTextField createSyncdTextField(javax.swing.JSlider s, int columns)
           
static void dispose(javax.swing.JInternalFrame internalFrame, javax.swing.JDesktopPane desktopPane)
          Ensures that the next frame is activated when #dispose is called explicitly, in JDK 1.4.
static void doNotRoundDoubles(javax.swing.JTable table)
           
static java.lang.String escapeHTML(java.lang.String value, boolean escapeSpaces, boolean escapeNewlines)
          Returns a string suitable for embeddind as HTML.
static void fixClicks(java.awt.Component c)
          Fix for Sun Java Bug 4398733: if you click in an inactive JInternalFrame, the mousePressed and mouseReleased events will be fired, but not the mouseClicked event.
static void fixEditableComboBox(javax.swing.JComboBox cb)
          Workaround for Java Bug 4648654 "REGRESSION: Editable JComboBox focus misbehaves under Windows look and feel, proposed by Kleopatra (fastegal@addcom.de).
static java.awt.datatransfer.Transferable getContents(java.awt.datatransfer.Clipboard clipboard)
          The JVM's clipboard implementation is buggy (see bugs 4644554 and 4522198 in Sun's Java bug database).
static java.awt.Component getDescendantOfClass(java.lang.Class c, java.awt.Container container)
           
static java.lang.String getExtension(java.io.File f)
           
static void handleThrowable(java.lang.Throwable t, java.awt.Component parent)
           
static void highlightForDebugging(javax.swing.JComponent component, java.awt.Color color)
          Highlights a given component with a given color.
static void invokeOnEventThread(java.lang.Runnable r)
          GUI operations should be performed only on the AWT event dispatching thread.
static java.util.List items(javax.swing.JComboBox comboBox)
           
static java.awt.geom.Point2D multiply(java.awt.geom.Point2D v, double x)
           
static java.lang.String nameWithoutExtension(java.io.File file)
           
static void removeChoosableFileFilters(javax.swing.JFileChooser fc)
           
static javax.swing.ImageIcon resize(javax.swing.ImageIcon icon, int extent)
           
static java.io.File[] selectedFiles(javax.swing.JFileChooser chooser)
          Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns nothing when a file is selected" [Jon Aquino]
static void setLocation(java.awt.Component componentToMove, GUIUtil.Location location, java.awt.Component other)
           
static void setSelectedWithClick(javax.swing.JCheckBox checkBox, boolean selected)
          Calls #doClick so that events are fired.
static java.awt.geom.Point2D subtract(java.awt.geom.Point2D a, java.awt.geom.Point2D b)
           
static int swingThreadPriority()
           
static void sync(javax.swing.JCheckBox c1, javax.swing.JCheckBox c2)
           
static void sync(javax.swing.JSlider s1, javax.swing.JSlider s2)
           
static void sync(javax.swing.JSlider s, ValidatingTextField t)
           
static void syncEnabledStates(javax.swing.JComponent c1, javax.swing.JComponent c2)
           
static javax.swing.ImageIcon toDisabledIcon(javax.swing.ImageIcon icon)
           
static javax.swing.event.DocumentListener toDocumentListener(java.awt.event.ActionListener listener)
           
static javax.swing.event.InternalFrameListener toInternalFrameListener(java.awt.event.ActionListener listener)
           
static javax.swing.event.ListDataListener toListDataListener(java.awt.event.ActionListener listener)
           
static java.awt.Component topCard(java.awt.Container c)
           
static java.awt.Color toSimulatedTransparency(java.awt.Color color)
           
static javax.swing.ImageIcon toSmallIcon(javax.swing.ImageIcon icon)
          Resizes icon to 16 x 16.
static double trueAscent(java.awt.font.TextLayout layout)
          Returns the distance from the baseline to the top of the text's bounding box.
static java.lang.String truncateString(java.lang.String s, int maxLength)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbf

public static final java.lang.String dbf
See Also:
Constant Field Values

dbfDesc

public static final java.lang.String dbfDesc
See Also:
Constant Field Values

fme

public static final java.lang.String fme
See Also:
Constant Field Values

fmeDesc

public static final java.lang.String fmeDesc
See Also:
Constant Field Values

gml

public static final java.lang.String gml
See Also:
Constant Field Values

gmlDesc

public static final java.lang.String gmlDesc
See Also:
Constant Field Values

jml

public static final java.lang.String jml
See Also:
Constant Field Values

jmlDesc

public static final java.lang.String jmlDesc
See Also:
Constant Field Values

shp

public static final java.lang.String shp
See Also:
Constant Field Values

shpDesc

public static final java.lang.String shpDesc
See Also:
Constant Field Values

shx

public static final java.lang.String shx
See Also:
Constant Field Values

shxDesc

public static final java.lang.String shxDesc
See Also:
Constant Field Values

wkt

public static final java.lang.String wkt
See Also:
Constant Field Values

wktDesc

public static final java.lang.String wktDesc
See Also:
Constant Field Values

wktaDesc

public static final java.lang.String wktaDesc
See Also:
Constant Field Values

xml

public static final java.lang.String xml
See Also:
Constant Field Values

xmlDesc

public static final java.lang.String xmlDesc
See Also:
Constant Field Values

ALL_FILES_FILTER

public static final javax.swing.filechooser.FileFilter ALL_FILES_FILTER
Constructor Detail

GUIUtil

public GUIUtil()
Method Detail

escapeHTML

public static final java.lang.String escapeHTML(java.lang.String value,
                                                boolean escapeSpaces,
                                                boolean escapeNewlines)
Returns a string suitable for embeddind as HTML. That is, all characters which have a special meaning in HTML are escaped as character codes.

Based on code from Jason Sherman. See http://www.w3schools.com/html/html_asciiref.asp


getExtension

public static java.lang.String getExtension(java.io.File f)

alphaColor

public static java.awt.Color alphaColor(java.awt.Color color,
                                        int alpha)

centre

public static void centre(java.awt.Component componentToMove,
                          java.awt.Component componentToCentreOn)
Centres the first component on the second

Parameters:
componentToMove - Description of the Parameter
componentToCentreOn - Description of the Parameter

centreOnScreen

public static void centreOnScreen(java.awt.Component componentToMove)
Centres the component on the screen

Parameters:
componentToMove - Description of the Parameter

centreOnWindow

public static void centreOnWindow(java.awt.Component componentToMove)
Centres the component on its window

Parameters:
componentToMove - Description of the Parameter

chooseGoodColumnWidths

public static void chooseGoodColumnWidths(javax.swing.JTable table)
Sets the column widths based on the first row.

Parameters:
table - Description of the Parameter

createJFileChooserWithExistenceChecking

public static javax.swing.JFileChooser createJFileChooserWithExistenceChecking()

createJFileChooserWithOverwritePrompting

public static javax.swing.JFileChooser createJFileChooserWithOverwritePrompting()

doNotRoundDoubles

public static void doNotRoundDoubles(javax.swing.JTable table)

fixEditableComboBox

public static void fixEditableComboBox(javax.swing.JComboBox cb)
Workaround for Java Bug 4648654 "REGRESSION: Editable JComboBox focus misbehaves under Windows look and feel, proposed by Kleopatra (fastegal@addcom.de). Also see Java Bug 4673880 "REGRESSION: Modified editable JComboBox in Windows LAF does not release focus." This bug started occurring in Java 1.4.0.

Parameters:
cb - Description of the Parameter

handleThrowable

public static void handleThrowable(java.lang.Throwable t,
                                   java.awt.Component parent)

invokeOnEventThread

public static void invokeOnEventThread(java.lang.Runnable r)
                                throws java.lang.InterruptedException,
                                       java.lang.reflect.InvocationTargetException
GUI operations should be performed only on the AWT event dispatching thread. Blocks until the Runnable is finished.

Throws:
java.lang.InterruptedException
java.lang.reflect.InvocationTargetException

nameWithoutExtension

public static java.lang.String nameWithoutExtension(java.io.File file)

removeChoosableFileFilters

public static void removeChoosableFileFilters(javax.swing.JFileChooser fc)

createFileFilter

public static javax.swing.filechooser.FileFilter createFileFilter(java.lang.String description,
                                                                  java.lang.String[] extensions)
Parameters:
extensions - e.g. txt

toSimulatedTransparency

public static java.awt.Color toSimulatedTransparency(java.awt.Color color)
Parameters:
color - a Color with possibly an alpha less than 255
Returns:
a Color with alpha equal to 255, but equivalent to the original translucent colour on a white background

truncateString

public static java.lang.String truncateString(java.lang.String s,
                                              int maxLength)

subtract

public static java.awt.geom.Point2D subtract(java.awt.geom.Point2D a,
                                             java.awt.geom.Point2D b)

add

public static java.awt.geom.Point2D add(java.awt.geom.Point2D a,
                                        java.awt.geom.Point2D b)

multiply

public static java.awt.geom.Point2D multiply(java.awt.geom.Point2D v,
                                             double x)

getContents

public static java.awt.datatransfer.Transferable getContents(java.awt.datatransfer.Clipboard clipboard)
The JVM's clipboard implementation is buggy (see bugs 4644554 and 4522198 in Sun's Java bug database). This method is a workaround that returns null if an exception is thrown, as suggested in the bug reports.


trueAscent

public static double trueAscent(java.awt.font.TextLayout layout)
Returns the distance from the baseline to the top of the text's bounding box. Unlike the usual ascent, which is independent of the actual text. Note that "True ascent" is not a standard term.


resize

public static javax.swing.ImageIcon resize(javax.swing.ImageIcon icon,
                                           int extent)

toSmallIcon

public static javax.swing.ImageIcon toSmallIcon(javax.swing.ImageIcon icon)
Resizes icon to 16 x 16.


swingThreadPriority

public static int swingThreadPriority()

fixClicks

public static void fixClicks(java.awt.Component c)
Fix for Sun Java Bug 4398733: if you click in an inactive JInternalFrame, the mousePressed and mouseReleased events will be fired, but not the mouseClicked event.


addInternalFrameListener

public static void addInternalFrameListener(javax.swing.JDesktopPane pane,
                                            javax.swing.event.InternalFrameListener listener)
Listens to all internal frames (current and future) in a JDesktopPane.


toDocumentListener

public static javax.swing.event.DocumentListener toDocumentListener(java.awt.event.ActionListener listener)

toListDataListener

public static javax.swing.event.ListDataListener toListDataListener(java.awt.event.ActionListener listener)

toInternalFrameListener

public static javax.swing.event.InternalFrameListener toInternalFrameListener(java.awt.event.ActionListener listener)

createRestartableSingleEventTimer

public static javax.swing.Timer createRestartableSingleEventTimer(int delay,
                                                                  java.awt.event.ActionListener listener)
Returns a Timer that fires once, after the delay. The delay can be restarted by restarting the Timer.


createSyncdTextField

public static ValidatingTextField createSyncdTextField(javax.swing.JSlider s)

createSyncdTextField

public static ValidatingTextField createSyncdTextField(javax.swing.JSlider s,
                                                       int columns)

sync

public static void sync(javax.swing.JSlider s,
                        ValidatingTextField t)
See Also:
createSyncdTextField(JSlider s, int columns)

syncEnabledStates

public static void syncEnabledStates(javax.swing.JComponent c1,
                                     javax.swing.JComponent c2)

sync

public static void sync(javax.swing.JSlider s1,
                        javax.swing.JSlider s2)

sync

public static void sync(javax.swing.JCheckBox c1,
                        javax.swing.JCheckBox c2)

items

public static java.util.List items(javax.swing.JComboBox comboBox)

setSelectedWithClick

public static void setSelectedWithClick(javax.swing.JCheckBox checkBox,
                                        boolean selected)
Calls #doClick so that events are fired.


setLocation

public static void setLocation(java.awt.Component componentToMove,
                               GUIUtil.Location location,
                               java.awt.Component other)

highlightForDebugging

public static void highlightForDebugging(javax.swing.JComponent component,
                                         java.awt.Color color)
Highlights a given component with a given color. Great for GridBagLayout debugging.


topCard

public static java.awt.Component topCard(java.awt.Container c)

selectedFiles

public static java.io.File[] selectedFiles(javax.swing.JFileChooser chooser)
Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns nothing when a file is selected" [Jon Aquino]


toDisabledIcon

public static javax.swing.ImageIcon toDisabledIcon(javax.swing.ImageIcon icon)

getDescendantOfClass

public static java.awt.Component getDescendantOfClass(java.lang.Class c,
                                                      java.awt.Container container)

dispose

public static void dispose(javax.swing.JInternalFrame internalFrame,
                           javax.swing.JDesktopPane desktopPane)
Ensures that the next frame is activated when #dispose is called explicitly, in JDK 1.4. JDK 1.3 didn't have this problem.