Class GUIUtil


  • public class GUIUtil
    extends Object
    • Constructor Detail

      • GUIUtil

        public GUIUtil()
    • 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

      • getExtension

        public static String getExtension​(File f)
      • alphaColor

        public static Color alphaColor​(Color color,
                                       int alpha)
      • centre

        public static void centre​(Component componentToMove,
                                  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​(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
      • handleThrowable

        public static void handleThrowable​(Throwable t,
                                           Component parent)
      • nameWithoutExtension

        public static String nameWithoutExtension​(File file)
      • 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
      • truncateString

        public static String truncateString​(String s,
                                            int maxLength)
      • 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.
      • toSmallIcon

        public static ImageIcon toSmallIcon​(ImageIcon icon)
        Resizes icon to 16 x 16.
      • 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.
      • 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.
      • setSelectedWithClick

        public static void setSelectedWithClick​(JCheckBox checkBox,
                                                boolean selected)
        Calls #doClick so that events are fired.
      • 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.
      • createCursorFromIcon

        public static Cursor createCursorFromIcon​(Image iconImage)
      • createCursor

        public static Cursor createCursor​(Image image,
                                          Point hotSpot)
      • 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.