ProgramixGenericLib v5.0.1

com.programix.gui
Class GuiTools

java.lang.Object
  extended by com.programix.gui.GuiTools

public class GuiTools
extends Object


Field Summary
static Font NUMBER_FONT
           
static GridLayout ONE_CELL_GRID
           
 
Method Summary
static void centerOnScreen(Window window)
          Centers the specified window on the screen.
static void centerOnTop(Window topWindow, Window bottomWindow)
          Centers topWindow over bottomWindow.
static void clearGlobalFocus()
          Removes focus from all components which allows keyboard navigation to still work.
static JLabel createCenteredOpaqueLabel(String text)
           
static Border createCompoundBorder(Border outerBorder, Border middleBorder, Border innerBorder)
          Combines 3 borders into 1 border.
static ImageIcon createIcon(String imageResourceLocation)
          Creates an ImageIcon from the data stored in the specified resource.
static Border createSandwichBorder(int outerThickness, int innerThickness, Border middleBorder)
          Creates an empty border for the outer border and an empty border for the inner border and then sandwiches the middle border in between.
static JLabel createScaledLabel(String text, double scale)
           
static TexturePaint createTexturePaint(String imageResourceLocation)
          Creates a TexturePaint from the data stored in the specified resource.
static Rectangle ensureOnScreen(Window window)
          If necessary, window is shrunk and/or moved so that no part of it hangs off the edges of the screen.
static Component[] getAllComponents(Container con)
          Gets all the components contained (recursively).
static FocusListener getSelectAllFocusListener()
          Returns a sharable FocusListener that can be any to any sublcass of JTextComponent.
static Rectangle getUsableScreenBounds(Window window)
          Returns the usable screen bounds for the screen where this window is currently residing.
static Dimension getUsableScreenSize(Window window)
          Returns the usable screen size for the screen where this window is currently residing.
static void packAndCenterOnScreen(Window window)
          Packs the specified window to get its preferred size, then centers it on the screen.
static void packAndCenterOnTop(Window topWindow, Window bottomWindow)
          Packs the topWindow and then centers it over bottomWindow.
static Component scaleFont(Component comp, double scale)
           
static Font scaleFont(Font font, double scale)
           
static void selectAllOnFocus(JTextComponent comp)
          Adds a FocusListener to the specified JTextComponent that selects all of the text when focus is gained.
static void setAutoScrollToFocus(JScrollPane sp)
           
static void setEmptyBorder(JComponent target, int thickness)
           
static void setPreferredColumnSizes(JTable table)
           
static void setPreferredColumnSizes(JTable table, int minPrefWidth, int maxPrefWidth, int padding, int maxRowsToExamine)
           
static void setPreferredSizeToLargest(JComponent[] comp)
           
static void setQualityHints(Graphics g)
           
static JScrollPane setScrollBackingStore(JScrollPane sp)
          Forces viewport of scrollpane to use a backing store instead of the default "blit" that causes crud to show up on some screens.
static void setSizeAndCenterOnScreen(Window window, int width, int height)
          Sets the specified window to the specified size, then centers it on the screen.
static void setSizeToMax(Window window)
          Resizes and/or moves the specified window so that it fills all of the usable screen.
static void useWindowDecorations()
          Sets the look and feel hint for JFrame and JDialog that the entire window should try to use custom decorations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMBER_FONT

public static final Font NUMBER_FONT

ONE_CELL_GRID

public static final GridLayout ONE_CELL_GRID
Method Detail

getUsableScreenBounds

public static Rectangle getUsableScreenBounds(Window window)
Returns the usable screen bounds for the screen where this window is currently residing. This is the rectangle available after subtracting insets for task bars, etc.


getUsableScreenSize

public static Dimension getUsableScreenSize(Window window)
Returns the usable screen size for the screen where this window is currently residing. This is the space available after subtracting insets for task bars, etc.


ensureOnScreen

public static Rectangle ensureOnScreen(Window window)
If necessary, window is shrunk and/or moved so that no part of it hangs off the edges of the screen. If the window is wider or taller than the screen (minus screen insets), the window is resized. If after any resizing a portion of the window would not be visible because of the location of the window, the window will be moved just enough to get all of the window onto the screen.

Parameters:
window - the window to be moved and/or reduced in size.
Returns:
the shape of the window after any moving or shrinking, the original window bounds if no resizing or moving was needed, or null if the window's getBounds() method returns null.

centerOnScreen

public static void centerOnScreen(Window window)
Centers the specified window on the screen. If the window is wider or taller than the screen dimensions, the window is shrunk only as much as is necessary to fit entirely within the visible screen space. Screen insets (for things like task bars) are taken into account.


packAndCenterOnScreen

public static void packAndCenterOnScreen(Window window)
Packs the specified window to get its preferred size, then centers it on the screen. If the preferred window size is wider or taller than the screen, then the window is shrunk to fit. Screen insets (for things like task bars) are taken into account.


setSizeAndCenterOnScreen

public static void setSizeAndCenterOnScreen(Window window,
                                            int width,
                                            int height)
Sets the specified window to the specified size, then centers it on the screen. If the specified window size is wider or taller than the screen, then the window is shrunk to fit. Screen insets (for things like task bars) are taken into account.


setSizeToMax

public static void setSizeToMax(Window window)
Resizes and/or moves the specified window so that it fills all of the usable screen. Screen insets (for things like task bars) are taken into account.


centerOnTop

public static void centerOnTop(Window topWindow,
                               Window bottomWindow)
Centers topWindow over bottomWindow. After centering, the top window is run through ensureOnScreen(Window) (as a result, the top window will always be entirely on the visible screen—even at the sacrifice of centering it over the bottom window).


packAndCenterOnTop

public static void packAndCenterOnTop(Window topWindow,
                                      Window bottomWindow)
Packs the topWindow and then centers it over bottomWindow. After centering, the top window is run through ensureOnScreen(Window) (as a result, the top window will always be entirely on the visible screen—even at the sacrifice of centering it over the bottom window).


useWindowDecorations

public static void useWindowDecorations()
Sets the look and feel hint for JFrame and JDialog that the entire window should try to use custom decorations. This hint may or may not be observed by the current look and feel.

See Also:
JFrame.setDefaultLookAndFeelDecorated(boolean), JDialog.setDefaultLookAndFeelDecorated(boolean)

clearGlobalFocus

public static void clearGlobalFocus()
Removes focus from all components which allows keyboard navigation to still work. This can be helpful when the focus is on a component that is no longer visible.


createScaledLabel

public static JLabel createScaledLabel(String text,
                                       double scale)

createCenteredOpaqueLabel

public static JLabel createCenteredOpaqueLabel(String text)

scaleFont

public static Font scaleFont(Font font,
                             double scale)

scaleFont

public static Component scaleFont(Component comp,
                                  double scale)

setQualityHints

public static void setQualityHints(Graphics g)

setScrollBackingStore

public static JScrollPane setScrollBackingStore(JScrollPane sp)
Forces viewport of scrollpane to use a backing store instead of the default "blit" that causes crud to show up on some screens.


selectAllOnFocus

public static void selectAllOnFocus(JTextComponent comp)
Adds a FocusListener to the specified JTextComponent that selects all of the text when focus is gained. When the focus is lost, none of the text remains selected.


getSelectAllFocusListener

public static FocusListener getSelectAllFocusListener()
Returns a sharable FocusListener that can be any to any sublcass of JTextComponent.


setPreferredSizeToLargest

public static void setPreferredSizeToLargest(JComponent[] comp)

setPreferredColumnSizes

public static void setPreferredColumnSizes(JTable table,
                                           int minPrefWidth,
                                           int maxPrefWidth,
                                           int padding,
                                           int maxRowsToExamine)

setPreferredColumnSizes

public static void setPreferredColumnSizes(JTable table)

setAutoScrollToFocus

public static void setAutoScrollToFocus(JScrollPane sp)

createSandwichBorder

public static Border createSandwichBorder(int outerThickness,
                                          int innerThickness,
                                          Border middleBorder)
Creates an empty border for the outer border and an empty border for the inner border and then sandwiches the middle border in between.


createCompoundBorder

public static Border createCompoundBorder(Border outerBorder,
                                          Border middleBorder,
                                          Border innerBorder)
Combines 3 borders into 1 border.


setEmptyBorder

public static void setEmptyBorder(JComponent target,
                                  int thickness)

getAllComponents

public static Component[] getAllComponents(Container con)
Gets all the components contained (recursively).


createIcon

public static ImageIcon createIcon(String imageResourceLocation)
                            throws ImageTools.ImageNotFoundException,
                                   ImageTools.ImageException
Creates an ImageIcon from the data stored in the specified resource. The specified resource is not a filename, but is a resource that can be loaded from JAR's, WAR's, etc.

Equivalent to:

 return new ImageIcon(
     ImageTools.createImageFromResource(imageResourceLocation));
 
The exceptions declared to be thrown from this method are subclasses of RuntimeException, so callers are not required to catch them.

Throws:
ImageTools.ImageNotFoundException
ImageTools.ImageException

createTexturePaint

public static TexturePaint createTexturePaint(String imageResourceLocation)
                                       throws ImageTools.ImageNotFoundException,
                                              ImageTools.ImageException
Creates a TexturePaint from the data stored in the specified resource. The specified resource is not a filename, but is a resource that can be loaded from JAR's, WAR's, etc.

Equivalent to:

 return new ImageIcon(
     ImageTools.createImageFromResource(imageResourceLocation));
 BufferedImage image =
     ImageTools.createImageFromResource(imageResourceLocation);

 return new TexturePaint(image, new Rectangle2D.Double(0, 0,
     image.getWidth(), image.getHeight()));
 
The exceptions declared to be thrown from this method are subclasses of RuntimeException, so callers are not required to catch them.

Throws:
ImageTools.ImageNotFoundException
ImageTools.ImageException

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.