Class GUIUtil

java.lang.Object
com.vividsolutions.jump.workbench.ui.GUIUtil

public class GUIUtil extends Object
  • Field Details

  • Constructor Details

    • GUIUtil

      public GUIUtil()
  • Method Details

    • 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

    • 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
    • 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
    • handleThrowable

      public static void handleThrowable(Throwable t, Component parent)
    • 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.
      Throws:
      InterruptedException
      InvocationTargetException
    • 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)
    • subtract

      public static Point2D subtract(Point2D a, Point2D b)
    • add

      public static Point2D add(Point2D a, Point2D b)
    • multiply

      public static Point2D multiply(Point2D v, double x)
    • 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
    • toImageIcon

      public static ImageIcon toImageIcon(Icon 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 create
      width - integer width of the ImageIcon to create
      height - 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 resize
      extent_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 resize
      extent_x - new width of the icon
      extent_y - new height of the icon
      Returns:
      the resized ImageIcon
    • resize

      public static Image resize(Image image, int extent_x, int extent_y)
    • toSmallIcon

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

      public static ImageIcon toSmallIcon(ImageIcon icon, int width)
      Resize icon to specified width
      Parameters:
      icon - imageIcon to resize
      width - 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 enlarge
      border - 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 padded
      top - number of pixels to add to the top
      left - number of pixels to add to the left
      bottom - number of pixels to add to the bottom
      right - 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 overlayed
      overlay - overlay ImageIcon
      x - x position of the overlay in the source
      y - 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 overlaid
      overlay - overlay ImageIcon
      x - x position of the overlay in the source
      y - y position of the overlay in the source
      alpha - alpha coefficient used to combine ovelay to source image
      mask - 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)
      See Also:
    • syncEnabledStates

      public static void syncEnabledStates(JComponent c1, JComponent c2)
    • sync

      public static void sync(JSlider s1, JSlider s2)
    • sync

      public static void sync(JCheckBox c1, JCheckBox c2)
    • items

      public static List items(JComboBox comboBox)
    • 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.
    • topCard

      public static Component topCard(Container c)
    • selectedFiles

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

      public static ImageIcon toDisabledIcon(ImageIcon icon)
    • getDescendantOfClass

      public static Component getDescendantOfClass(Class c, Container container)
    • 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)
    • createCursorOld

      public static Cursor createCursorOld(Image image, Point hotSpot)
    • createCursor

      public static Cursor createCursor(Image cursorImage, Point hotSpot, String name)
    • 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()