Class GUIUtil
- java.lang.Object
-
- org.locationtech.jts.jump.workbench.ui.GUIUtil
-
public class GUIUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GUIUtil.FileChooserWithOverwritePrompting
static class
GUIUtil.Location
-
Field Summary
Fields Modifier and Type Field Description static FileFilter
ALL_FILES_FILTER
static String
dbf
static String
dbfDesc
static String
fme
static String
fmeDesc
static String
gml
static String
gmlDesc
static String
jml
static String
jmlDesc
static String
shp
static String
shpDesc
static String
shx
static String
shxDesc
static String
wkt
static String
wktaDesc
static String
wktDesc
static String
xml
static String
xmlDesc
-
Constructor Summary
Constructors Constructor Description GUIUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Point2D
add(Point2D a, Point2D b)
static void
addInternalFrameListener(JDesktopPane pane, InternalFrameListener listener)
Listens to all internal frames (current and future) in a JDesktopPane.static Color
alphaColor(Color color, int alpha)
static void
centre(Component componentToMove, Component componentToCentreOn)
Centres the first component on the secondstatic void
centreOnScreen(Component componentToMove)
Centres the component on the screenstatic void
centreOnWindow(Component componentToMove)
Centres the component on its windowstatic void
chooseGoodColumnWidths(JTable table)
Sets the column widths based on the first row.static Cursor
createCursor(Image image, Point hotSpot)
static Cursor
createCursorFromIcon(Image iconImage)
static FileFilter
createFileFilter(String description, String[] extensions)
static JFileChooser
createJFileChooserWithExistenceChecking()
static JFileChooser
createJFileChooserWithOverwritePrompting()
static Timer
createRestartableSingleEventTimer(int delay, ActionListener listener)
Returns a Timer that fires once, after the delay.static ValidatingTextField
createSyncdTextField(JSlider s)
static ValidatingTextField
createSyncdTextField(JSlider s, int columns)
static void
dispose(JInternalFrame internalFrame, JDesktopPane desktopPane)
Ensures that the next frame is activated when #dispose is called explicitly, in JDK 1.4.static void
doNotRoundDoubles(JTable table)
static String
escapeHTML(String value, boolean escapeSpaces, boolean escapeNewlines)
Returns a string suitable for embeddind as HTML.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.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).static Transferable
getContents(Clipboard clipboard)
The JVM's clipboard implementation is buggy (see bugs 4644554 and 4522198 in Sun's Java bug database).static Component
getDescendantOfClass(Class c, Container container)
static String
getExtension(File f)
static void
handleThrowable(Throwable t, Component parent)
static void
highlightForDebugging(JComponent component, Color color)
Highlights a given component with a given color.static void
invokeOnEventThread(Runnable r)
GUI operations should be performed only on the AWT event dispatching thread.static List
items(JComboBox comboBox)
static JTextArea
makeTabMoveFocus(JTextArea textArea)
Based on Green, Roedy.static Point2D
multiply(Point2D v, double x)
static String
nameWithoutExtension(File file)
static void
removeChoosableFileFilters(JFileChooser fc)
static ImageIcon
resize(ImageIcon icon, int extent)
static File[]
selectedFiles(JFileChooser chooser)
Work around Java Bug 4437688 "JFileChooser.getSelectedFile() returns nothing when a file is selected" [Jon Aquino]static void
setLocation(Component componentToMove, GUIUtil.Location location, Component other)
static void
setSelectedWithClick(JCheckBox checkBox, boolean selected)
Calls #doClick so that events are fired.static Point2D
subtract(Point2D a, Point2D b)
static int
swingThreadPriority()
static void
sync(JCheckBox c1, JCheckBox c2)
static void
sync(JSlider s1, JSlider s2)
static void
sync(JSlider s, ValidatingTextField t)
static void
syncEnabledStates(JComponent c1, JComponent c2)
static ImageIcon
toDisabledIcon(ImageIcon icon)
static DocumentListener
toDocumentListener(ActionListener listener)
static InternalFrameListener
toInternalFrameListener(ActionListener listener)
static ListDataListener
toListDataListener(ActionListener listener)
static Component
topCard(Container c)
static Color
toSimulatedTransparency(Color color)
static ImageIcon
toSmallIcon(ImageIcon icon)
Resizes icon to 16 x 16.static double
trueAscent(TextLayout layout)
Returns the distance from the baseline to the top of the text's bounding box.static String
truncateString(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
-
-
Method Detail
-
escapeHTML
public static final String escapeHTML(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
-
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
-
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()
-
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.
-
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)
-
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.
-
-