Class GUIUtil
- java.lang.Object
-
- com.vividsolutions.jump.workbench.ui.GUIUtil
-
public class GUIUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGUIUtil.FileChooserWithOverwritePromptingstatic classGUIUtil.Location
-
Field Summary
Fields Modifier and Type Field Description static FileFilterALL_FILES_FILTERstatic Stringdbfstatic StringdbfDescstatic Stringfmestatic StringfmeDescstatic Stringgmlstatic StringgmlDescstatic Stringjmlstatic StringjmlDescstatic intPERPIXEL_TRANSLUCENCYstatic intSHAPED_WINDOWstatic Stringshpstatic StringshpDescstatic Stringshxstatic StringshxDescstatic intUNIFORM_TRANSLUCENCYstatic Stringwktstatic StringwktaDescstatic StringwktDescstatic Stringxmlstatic StringxmlDesc
-
Constructor Summary
Constructors Constructor Description GUIUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Point2Dadd(Point2D a, Point2D b)static voidaddInternalFrameListener(JDesktopPane pane, InternalFrameListener listener)Listens to all internal frames (current and future) in a JDesktopPane.static ColoralphaColor(Color color, int alpha)static voidcentre(Component componentToMove, Component componentToCentreOn)Centres the first component on the secondstatic voidcentreOnScreen(Component componentToMove)Centres the component on the screenstatic voidcentreOnWindow(Component componentToMove)Centres the component on its windowstatic voidcentreOnWindow(Window windowToMove)Center the window on its parent windowstatic voidchooseGoodColumnWidths(JTable table)Sets the column widths based on the first row.static CursorcreateCursor(Image cursorImage, Point hotSpot, String name)static CursorcreateCursorFromIcon(Image iconImage)static CursorcreateCursorOld(Image image, Point hotSpot)static FileFiltercreateFileFilter(String description, String[] extensions)static JFileChoosercreateJFileChooserWithExistenceChecking()static JFileChoosercreateJFileChooserWithOverwritePrompting()static JFileChoosercreateJFileChooserWithOverwritePrompting(String ext)static TimercreateRestartableSingleEventTimer(int delay, ActionListener listener)Returns a Timer that fires once, after the delay.static ValidatingTextFieldcreateSyncdTextField(JSlider s)static ValidatingTextFieldcreateSyncdTextField(JSlider s, int columns)static voiddispose(JInternalFrame internalFrame, JDesktopPane desktopPane)Ensures that the next frame is activated when #dispose is called explicitly, in JDK 1.4.static voiddoNotRoundDoubles(JTable table)static StringescapeHTML(String value)Convenience method by default escaping everything.static StringescapeHTML(String value, boolean escapeSpaces, boolean escapeNewlines)Returns a string suitable for embedding as HTML.static voidfixClicks(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 voidfixEditableComboBox(JComboBox cb)Workaround for Java Bug 4648654 "REGRESSION: Editable JComboBox focus misbehaves under Windows look and feel, proposed by Kleopatra (fastegal@addcom.de).static ImageIconfromColor(Color color, int width, int height)Create an ImageIcon from given color and dimensionsstatic TransferablegetContents(Clipboard clipboard)The JVM's clipboard implementation is buggy (see bugs 4644554 and 4522198 in Sun's Java bug database).static GraphicsDevicegetDefaultScreenDevice()static ComponentgetDescendantOfClass(Class c, Container container)static StringgetExtension(File f)static voidhandleThrowable(Throwable t, Component parent)static voidhighlightForDebugging(JComponent component, Color color)Highlights a given component with a given color.static voidinvokeOnEventThread(Runnable r)GUI operations should be performed only on the AWT event dispatching thread.static booleanisPerPixelTranslucencySupported()static booleanisShapedWindowSupported()static booleanisUniformTranslucencySupported()static Listitems(JComboBox comboBox)static JTextAreamakeTabMoveFocus(JTextArea textArea)Based on Green, Roedy.static Point2Dmultiply(Point2D v, double x)static StringnameWithoutExtension(File file)static ImageIconoverlay(ImageIcon icon, ImageIcon overlay, int x, int y)Overlay an icon over another iconstatic ImageIconoverlay(ImageIcon image, ImageIcon overlay, int x, int y, float alpha, Image mask)overlay an icon over another icon respecting mask (b/w image)static ImageIconpad(ImageIcon icon, int border)Enlarge icon by padding border pixels onto itstatic ImageIconpad(ImageIcon icon, int top, int left, int bottom, int right)Enlarge icon by padding it by given number of pixelsstatic voidremoveChoosableFileFilters(JFileChooser fc)static Imageresize(Image image, int extent_x, int extent_y)static ImageIconresize(ImageIcon icon, int extent_xy)resize to a square, even non square imagesstatic ImageIconresize(ImageIcon icon, int extent_x, int extent_y)resizes to the given dimensions.static File[]selectedFiles(JFileChooser chooser)Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns nothing when a file is selected" [Jon Aquino]static voidsetBounds(Component componentToMove, GUIUtil.Location location, int width, int height, Component other)static voidsetLocation(Component componentToMove, GUIUtil.Location location, Component other)static voidsetSelectedWithClick(JCheckBox checkBox, boolean selected)Calls #doClick so that events are fired.static booleanshowConfirmOverwriteDialog(Component parent, File file)utility method to show an overwrite confirmation yes/no dialogstatic voidshrinkFont(JComponent component)static Point2Dsubtract(Point2D a, Point2D b)static intswingThreadPriority()static voidsync(JCheckBox c1, JCheckBox c2)static voidsync(JSlider s, ValidatingTextField t)static voidsync(JSlider s1, JSlider s2)static voidsyncEnabledStates(JComponent c1, JComponent c2)static ImageIcontoDisabledIcon(ImageIcon icon)static DocumentListenertoDocumentListener(ActionListener listener)static ImageIcontoGrayScale(ImageIcon icon)Convert icon to grayscalestatic ImagetoImage(Icon icon)convert Icon to Imagestatic ImageIcontoImageIcon(Icon icon)static InternalFrameListenertoInternalFrameListener(ActionListener listener)static ListDataListenertoListDataListener(ActionListener listener)static ComponenttopCard(Container c)static ColortoSimulatedTransparency(Color color)static ImageIcontoSmallIcon(ImageIcon icon)Resizes icon to 16 x 16.static ImageIcontoSmallIcon(ImageIcon icon, int width)Resize icon to specified widthstatic doubletrueAscent(TextLayout layout)Returns the distance from the baseline to the top of the text's bounding box.static StringtruncateString(String s, int maxLength)
-
-
-
Field Detail
-
dbf
public static final String dbf
- See Also:
- Constant Field Values
-
dbfDesc
public static final String dbfDesc
- See Also:
- Constant Field Values
-
fme
public static final String fme
- See Also:
- Constant Field Values
-
fmeDesc
public static final String fmeDesc
- See Also:
- Constant Field Values
-
gml
public static final String gml
- See Also:
- Constant Field Values
-
gmlDesc
public static final String gmlDesc
- See Also:
- Constant Field Values
-
jml
public static final String jml
- See Also:
- Constant Field Values
-
jmlDesc
public static final String jmlDesc
- See Also:
- Constant Field Values
-
shp
public static final String shp
- See Also:
- Constant Field Values
-
shpDesc
public static final String shpDesc
- See Also:
- Constant Field Values
-
shx
public static final String shx
- See Also:
- Constant Field Values
-
shxDesc
public static final String shxDesc
- See Also:
- Constant Field Values
-
wkt
public static final String wkt
- See Also:
- Constant Field Values
-
wktDesc
public static final String wktDesc
- See Also:
- Constant Field Values
-
wktaDesc
public static final String wktaDesc
- See Also:
- Constant Field Values
-
xml
public static final String xml
- See Also:
- Constant Field Values
-
xmlDesc
public static final String xmlDesc
- See Also:
- Constant Field Values
-
ALL_FILES_FILTER
public static final FileFilter ALL_FILES_FILTER
-
UNIFORM_TRANSLUCENCY
public static final int UNIFORM_TRANSLUCENCY
- See Also:
- Constant Field Values
-
PERPIXEL_TRANSLUCENCY
public static final int PERPIXEL_TRANSLUCENCY
- See Also:
- Constant Field Values
-
SHAPED_WINDOW
public static final int SHAPED_WINDOW
- See Also:
- Constant Field Values
-
-
Method Detail
-
escapeHTML
public static String escapeHTML(String value)
Convenience method by default escaping everything.- Parameters:
value- string to escape- Returns:
- string or null
-
escapeHTML
public static String escapeHTML(String value, boolean escapeSpaces, boolean escapeNewlines)
Returns a string suitable for embedding 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
-
centre
public static void centre(Component componentToMove, Component componentToCentreOn)
Centres the first component on the second- Parameters:
componentToMove- Description of the ParametercomponentToCentreOn- Description of the Parameter
-
centreOnScreen
public static void centreOnScreen(Component componentToMove)
Centres the component on the screen- Parameters:
componentToMove- Description of the Parameter
-
centreOnWindow
public static void centreOnWindow(Component componentToMove)
Centres the component on its window- Parameters:
componentToMove- Description of the Parameter
-
centreOnWindow
public static void centreOnWindow(Window windowToMove)
Center the window on its parent window- Parameters:
windowToMove- window to be centered on its parent window
-
chooseGoodColumnWidths
public static void chooseGoodColumnWidths(JTable table)
Sets the column widths based on the first row.- Parameters:
table- Description of the Parameter
-
createJFileChooserWithExistenceChecking
public static JFileChooser createJFileChooserWithExistenceChecking()
-
createJFileChooserWithOverwritePrompting
public static JFileChooser createJFileChooserWithOverwritePrompting()
-
createJFileChooserWithOverwritePrompting
public static JFileChooser createJFileChooserWithOverwritePrompting(String ext)
-
showConfirmOverwriteDialog
public static boolean showConfirmOverwriteDialog(Component parent, File file)
utility method to show an overwrite confirmation yes/no dialog- Returns:
- boolean yes/no
-
doNotRoundDoubles
public static void doNotRoundDoubles(JTable table)
-
fixEditableComboBox
public static void fixEditableComboBox(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
-
invokeOnEventThread
public static void invokeOnEventThread(Runnable r) throws InterruptedException, InvocationTargetException
GUI operations should be performed only on the AWT event dispatching thread. Blocks until the Runnable is finished.
-
removeChoosableFileFilters
public static void removeChoosableFileFilters(JFileChooser fc)
-
createFileFilter
public static FileFilter createFileFilter(String description, String[] extensions)
- Parameters:
extensions- e.g. txt
-
toSimulatedTransparency
public static Color toSimulatedTransparency(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
-
getContents
public static Transferable getContents(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(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.
-
toImage
public static Image toImage(Icon icon)
convert Icon to Image- Parameters:
icon- Icon to transform to an Image- Returns:
- an Image containing this icon
-
fromColor
public static ImageIcon fromColor(Color color, int width, int height)
Create an ImageIcon from given color and dimensions- Parameters:
color- Color of the ImageIcon to createwidth- integer width of the ImageIcon to createheight- integer height of the ImageIcon to create- Returns:
- a new ImageIcon
-
resize
public static ImageIcon resize(ImageIcon icon, int extent_xy)
resize to a square, even non square images- Parameters:
icon- imageIcon to resizeextent_xy- new size of the icon- Returns:
- the resized ImageIcon
-
resize
public static ImageIcon resize(ImageIcon icon, int extent_x, int extent_y)
resizes to the given dimensions. take care to calculate them properly if you want to keep aspect ratio- Parameters:
icon- imageIcon to resizeextent_x- new width of the iconextent_y- new height of the icon- Returns:
- the resized ImageIcon
-
toSmallIcon
public static ImageIcon toSmallIcon(ImageIcon icon, int width)
Resize icon to specified width- Parameters:
icon- imageIcon to resizewidth- width of the new ImageIcon- Returns:
- the resized ImageIcon
-
pad
public static ImageIcon pad(ImageIcon icon, int border)
Enlarge icon by padding border pixels onto it- Parameters:
icon- the ImageIcon to enlargeborder- width of the border to add- Returns:
- the enlarged ImageIcon
-
pad
public static ImageIcon pad(ImageIcon icon, int top, int left, int bottom, int right)
Enlarge icon by padding it by given number of pixels- Parameters:
icon- Icon to be paddedtop- number of pixels to add to the topleft- number of pixels to add to the leftbottom- number of pixels to add to the bottomright- number of pixels to add to the right- Returns:
- the new Padded ImageIcon
-
toGrayScale
public static ImageIcon toGrayScale(ImageIcon icon)
Convert icon to grayscale- Parameters:
icon- ImageIcon to transform- Returns:
- the grayed ImageIcon
-
overlay
public static ImageIcon overlay(ImageIcon icon, ImageIcon overlay, int x, int y)
Overlay an icon over another icon- Parameters:
icon- ImageIcon to be overlayedoverlay- overlay ImageIconx- x position of the overlay in the sourcey- y position of the overlay in the source- Returns:
- an ImageIcon combining source image and overlaid image
-
overlay
public static ImageIcon overlay(ImageIcon image, ImageIcon overlay, int x, int y, float alpha, Image mask)
overlay an icon over another icon respecting mask (b/w image)- Parameters:
image- source ImageIcon to be overlaidoverlay- overlay ImageIconx- x position of the overlay in the sourcey- y position of the overlay in the sourcealpha- alpha coefficient used to combine ovelay to source imagemask- source image will only be overlaid within this mask- Returns:
- an ImageIcon combining source image and overlaid image within the mask
-
swingThreadPriority
public static int swingThreadPriority()
-
fixClicks
public static void fixClicks(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(JDesktopPane pane, InternalFrameListener listener)
Listens to all internal frames (current and future) in a JDesktopPane.
-
toDocumentListener
public static DocumentListener toDocumentListener(ActionListener listener)
-
toListDataListener
public static ListDataListener toListDataListener(ActionListener listener)
-
toInternalFrameListener
public static InternalFrameListener toInternalFrameListener(ActionListener listener)
-
createRestartableSingleEventTimer
public static Timer createRestartableSingleEventTimer(int delay, 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(JSlider s)
-
createSyncdTextField
public static ValidatingTextField createSyncdTextField(JSlider s, int columns)
-
sync
public static void sync(JSlider s, ValidatingTextField t)
-
syncEnabledStates
public static void syncEnabledStates(JComponent c1, JComponent c2)
-
setSelectedWithClick
public static void setSelectedWithClick(JCheckBox checkBox, boolean selected)
Calls #doClick so that events are fired.
-
setLocation
public static void setLocation(Component componentToMove, GUIUtil.Location location, Component other)
-
setBounds
public static void setBounds(Component componentToMove, GUIUtil.Location location, int width, int height, Component other)
-
highlightForDebugging
public static void highlightForDebugging(JComponent component, Color color)
Highlights a given component with a given color. Great for GridBagLayout debugging.
-
selectedFiles
public static File[] selectedFiles(JFileChooser chooser)
Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns nothing when a file is selected" [Jon Aquino]
-
dispose
public static void dispose(JInternalFrame internalFrame, 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.
-
makeTabMoveFocus
public static JTextArea makeTabMoveFocus(JTextArea textArea)
Based on Green, Roedy. "Java Glossary : focus". Available from http://mindprod.com/jgloss/focus.html. Internet; accessed 8 March 2004.
-
shrinkFont
public static void shrinkFont(JComponent component)
-
getDefaultScreenDevice
public static GraphicsDevice getDefaultScreenDevice()
-
isUniformTranslucencySupported
public static boolean isUniformTranslucencySupported()
-
isPerPixelTranslucencySupported
public static boolean isPerPixelTranslucencySupported()
-
isShapedWindowSupported
public static boolean isShapedWindowSupported()
-
-