Quaqua 8.0 2011-10-02

ch.randelshofer.quaqua
Class QuaquaUtilities

java.lang.Object
  extended by javax.swing.plaf.basic.BasicGraphicsUtils
      extended by ch.randelshofer.quaqua.QuaquaUtilities
All Implemented Interfaces:
javax.swing.SwingConstants

public class QuaquaUtilities
extends javax.swing.plaf.basic.BasicGraphicsUtils
implements javax.swing.SwingConstants

Utility class for the Quaqua LAF.

Version:
$Id: QuaquaUtilities.java 432 2011-08-07 08:39:32Z wrandelshofer $
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland

Nested Class Summary
static class QuaquaUtilities.SizeVariant
           
 
Field Summary
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Method Summary
static void adjustFocus(javax.swing.JComponent tree)
           
static void applySizeVariant(javax.swing.JComponent c)
           
static java.lang.Object beginGraphics(java.awt.Graphics2D graphics2d)
          Turns on common rendering hints for UI delegates.
static java.awt.Component compositeRequestFocus(java.awt.Component component)
          Copied from BasicLookAndFeel.
static int convertModifiersToDropAction(int modifiers, int supportedActions)
           
static java.awt.image.BufferedImage createBufferedImage(java.net.URL location)
           
static java.awt.TexturePaint createTexturePaint(java.net.URL location)
           
static void drawStringUnderlineCharAt(java.awt.Graphics g, java.lang.String text, int underlinedIndex, int x, int y)
          Draw a string with the graphics g at location (x, y) just like g.drawString would.
static void endGraphics(java.awt.Graphics2D graphics2d, java.lang.Object oldHints)
          Restores rendering hints for UI delegates.
static java.awt.Component findFocusOwner(java.awt.Component c)
          Return the child Component of the specified Component that is the focus owner, if any.
static int getDragThreshold()
           
static java.lang.String getKeyModifiersText(int modifiers, boolean leftToRight)
          Returns a Mac OS X specific String describing the modifier key(s), such as "Shift", or "Ctrl+Shift".
static int getLeftSideBearing(java.awt.Font f, java.lang.String string)
           
static QuaquaUtilities.SizeVariant getSizeVariant(java.awt.Component c)
          Gets the size variant of a component.
static java.awt.Font getSizeVariantFont(javax.swing.JComponent c)
           
static java.lang.Object getUIOfType(javax.swing.plaf.ComponentUI ui, java.lang.Class klass)
          Returns the ui that is of type klass, or null if one can not be found.
static java.awt.Rectangle getVisualBounds(java.awt.Component c, int type)
          Returns the visual bounds of the component given in the local coordinate system of the component.
static void installProperty(javax.swing.JComponent c, java.lang.String propertyName, java.lang.Object value)
          Convenience method for installing a property with the specified name and value on a component if that property has not already been set by the client program.
static boolean isFocused(java.awt.Component component)
          Returns true, if the specified component is focus owner or permanent focus owner and if the component is on an the active window.
static boolean isLeftToRight(java.awt.Component c)
           
static boolean isOnActiveWindow(java.awt.Component c)
          Returns true if the component is on a Dialog or a Frame, which is active, or if it is on a Window, which is focused.
static boolean isOnActiveWindow(java.awt.Component c, boolean isActiveWhenSheetIsActive)
          Returns true if the component is on a Dialog or a Frame, which is active, or if it is on a Window, which is focused.
static boolean isOnTexturedWindow(java.awt.Component c)
           
static java.lang.String layoutCompoundLabel(java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
          Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string.
static java.lang.String layoutCompoundLabel(javax.swing.JComponent c, java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
          Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string.
static int mapDragOperationFromModifiers(java.awt.event.MouseEvent me, javax.swing.TransferHandler th)
           
static void repaintBorder(javax.swing.JComponent component)
           
 
Methods inherited from class javax.swing.plaf.basic.BasicGraphicsUtils
drawBezel, drawDashedRect, drawEtchedRect, drawGroove, drawLoweredBezel, drawString, getEtchedInsets, getGrooveInsets, getPreferredButtonSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isLeftToRight

public static boolean isLeftToRight(java.awt.Component c)

drawStringUnderlineCharAt

public static void drawStringUnderlineCharAt(java.awt.Graphics g,
                                             java.lang.String text,
                                             int underlinedIndex,
                                             int x,
                                             int y)
Draw a string with the graphics g at location (x, y) just like g.drawString would. The character at index underlinedIndex in text will be underlined. If index is beyond the bounds of text (including < 0), nothing will be underlined.

Parameters:
g - Graphics to draw with
text - String to draw
underlinedIndex - Index of character in text to underline
x - x coordinate to draw at
y - y coordinate to draw at
Since:
1.4

isOnActiveWindow

public static boolean isOnActiveWindow(java.awt.Component c)
Returns true if the component is on a Dialog or a Frame, which is active, or if it is on a Window, which is focused. Always returns true, if the component has no parent window.


isOnActiveWindow

public static boolean isOnActiveWindow(java.awt.Component c,
                                       boolean isActiveWhenSheetIsActive)
Returns true if the component is on a Dialog or a Frame, which is active, or if it is on a Window, which is focused. Always returns true, if the component has no parent window.

Parameters:
c - The component.
isActiveWhenSheetIsActive - Set this to true, when the window should be considered as active when its sheet dialog is active.

getKeyModifiersText

public static java.lang.String getKeyModifiersText(int modifiers,
                                                   boolean leftToRight)
Returns a Mac OS X specific String describing the modifier key(s), such as "Shift", or "Ctrl+Shift".

Returns:
string a text description of the combination of modifier keys that were held down during the event

repaintBorder

public static void repaintBorder(javax.swing.JComponent component)

beginGraphics

public static java.lang.Object beginGraphics(java.awt.Graphics2D graphics2d)
Turns on common rendering hints for UI delegates.


endGraphics

public static void endGraphics(java.awt.Graphics2D graphics2d,
                               java.lang.Object oldHints)
Restores rendering hints for UI delegates.


isFocused

public static boolean isFocused(java.awt.Component component)
Returns true, if the specified component is focus owner or permanent focus owner and if the component is on an the active window.


getLeftSideBearing

public static int getLeftSideBearing(java.awt.Font f,
                                     java.lang.String string)

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(java.net.URL location)

createTexturePaint

public static java.awt.TexturePaint createTexturePaint(java.net.URL location)

layoutCompoundLabel

public static java.lang.String layoutCompoundLabel(javax.swing.JComponent c,
                                                   java.awt.FontMetrics fm,
                                                   java.lang.String text,
                                                   javax.swing.Icon icon,
                                                   int verticalAlignment,
                                                   int horizontalAlignment,
                                                   int verticalTextPosition,
                                                   int horizontalTextPosition,
                                                   java.awt.Rectangle viewR,
                                                   java.awt.Rectangle iconR,
                                                   java.awt.Rectangle textR,
                                                   int textIconGap)
Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. The JComponents orientation (LEADING/TRAILING) will also be taken into account and translated into LEFT/RIGHT values accordingly.


layoutCompoundLabel

public static java.lang.String layoutCompoundLabel(java.awt.FontMetrics fm,
                                                   java.lang.String text,
                                                   javax.swing.Icon icon,
                                                   int verticalAlignment,
                                                   int horizontalAlignment,
                                                   int verticalTextPosition,
                                                   int horizontalTextPosition,
                                                   java.awt.Rectangle viewR,
                                                   java.awt.Rectangle iconR,
                                                   java.awt.Rectangle textR,
                                                   int textIconGap)
Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. This layoutCompoundLabel() does not know how to handle LEADING/TRAILING values in horizontalTextPosition (they will default to RIGHT) and in horizontalAlignment (they will default to CENTER). Use the other version of layoutCompoundLabel() instead.


compositeRequestFocus

public static java.awt.Component compositeRequestFocus(java.awt.Component component)
Copied from BasicLookAndFeel.


installProperty

public static void installProperty(javax.swing.JComponent c,
                                   java.lang.String propertyName,
                                   java.lang.Object value)
Convenience method for installing a property with the specified name and value on a component if that property has not already been set by the client program. This method is intended to be used by UI delegate instances that need to specify a default value for a property of primitive type (boolean, int, ..), but do not wish to override a value set by the client. Since primitive property values cannot be wrapped with the UIResource marker, this method uses private state to determine whether the property has been set by the client.

Parameters:
c - the target component for installing the property
propertyName - String containing the name of the property to be set
Throws:
java.lang.IllegalArgumentException - if the specified property is not one which can be set using this method
java.lang.ClassCastException - may be thrown if the property value specified does not match the property's type
java.lang.NullPointerException - may be thrown if c or propertyValue is null

getUIOfType

public static java.lang.Object getUIOfType(javax.swing.plaf.ComponentUI ui,
                                           java.lang.Class klass)
Returns the ui that is of type klass, or null if one can not be found.


adjustFocus

public static void adjustFocus(javax.swing.JComponent tree)

getSizeVariant

public static QuaquaUtilities.SizeVariant getSizeVariant(java.awt.Component c)
Gets the size variant of a component.

The size variant can be explicitly set using the client property "JComponent.sizeVariant="regular"|"small"|"mini".

The default size variant is "regular". If a component is a cell renderer, the default size variant is "small".

Parameters:
c -
Returns:
size variant.

getSizeVariantFont

public static java.awt.Font getSizeVariantFont(javax.swing.JComponent c)

applySizeVariant

public static void applySizeVariant(javax.swing.JComponent c)

getDragThreshold

public static int getDragThreshold()

mapDragOperationFromModifiers

public static int mapDragOperationFromModifiers(java.awt.event.MouseEvent me,
                                                javax.swing.TransferHandler th)

convertModifiersToDropAction

public static int convertModifiersToDropAction(int modifiers,
                                               int supportedActions)

findFocusOwner

public static java.awt.Component findFocusOwner(java.awt.Component c)
Return the child Component of the specified Component that is the focus owner, if any.

Parameters:
c - the root of the Component hierarchy to search for the focus owner
Returns:
the focus owner, or null if there is no focus owner, or if the focus owner is not comp, or a descendant of comp
See Also:
KeyboardFocusManager.getFocusOwner()

isOnTexturedWindow

public static boolean isOnTexturedWindow(java.awt.Component c)

getVisualBounds

public static java.awt.Rectangle getVisualBounds(java.awt.Component c,
                                                 int type)
Returns the visual bounds of the component given in the local coordinate system of the component.

Parameters:
c - The component.
type - A type from VisuallyLayoutable.
Returns:
The visual bounds. Returns null if the given type is not applicable.

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.