|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.util.Util
public abstract class Util
Utility functions.
Field Summary | |
---|---|
static java.lang.String |
RB_KEY
|
static java.lang.String |
VERTICAL_LINE_WIDTH_STRING
|
Fields inherited from interface com.sas.swing.Constants |
---|
CENTER_BOTTOM, CENTER_LEADING, CENTER_LEFT, CENTER_RIGHT, CENTER_TOP, CENTER_TRAILING |
Constructor Summary | |
---|---|
Util()
|
Method Summary | |
---|---|
static void |
addCommand(javax.swing.JMenu menu,
com.sas.util.Command command)
Alias for addCommand(menu, commands, null); |
static void |
addCommand(javax.swing.JMenu menu,
com.sas.util.Command command,
java.lang.Object object)
|
static void |
addCommand(javax.swing.JPopupMenu menu,
com.sas.util.Command command)
Alias for addCommand(menu, commands, null); |
static void |
addCommand(javax.swing.JPopupMenu menu,
com.sas.util.Command command,
java.lang.Object object)
|
static void |
addCommands(javax.swing.JMenu menu,
com.sas.util.Command[] commands)
Alias for addCommands(menu, commands, null); |
static void |
addCommands(javax.swing.JMenu menu,
com.sas.util.Command[] commands,
java.lang.Object object)
|
static void |
addCommands(javax.swing.JPopupMenu menu,
com.sas.util.Command[] commands)
Alias for addCommands(menu, commands, null); |
static void |
addCommands(javax.swing.JPopupMenu menu,
com.sas.util.Command[] commands,
java.lang.Object object)
|
static void |
apply(java.awt.Component rootComponent,
com.sas.util.ApplyInterface operation)
Applies a given operation to each of a set of components. |
static java.lang.String[] |
breakupLines(java.lang.String text)
StringTokenizer(text,"\n") really does a "\n+" which is not what we want. |
static void |
center(java.awt.Window window)
Center the dialog on the screen. |
static void |
centerOver(java.awt.Window window,
java.awt.Component component)
Center the dialog over a component on the screen. |
static void |
centerOverWindow(java.awt.Window window,
java.awt.Component component)
Center the dialog over a Window on the screen. |
static java.awt.Point |
computePopupMenuLocation(int x,
int y,
int width,
int height,
java.awt.Component comp)
Determines the location on the screen the popup menu should be displayed at. |
static java.awt.Dimension |
computePopupMenuSize(javax.swing.JPopupMenu popMenu,
java.awt.Component comp)
Calculates the size a popup menu will be so that a user will be able to know where to locate the popup menu on the screen. |
static void |
configureGroupBoxBorder(javax.swing.border.Border border,
java.lang.String borderTitle)
Sets the values on a Border object for it to look like an MS group box. |
static void |
configureMnemonicForButton(javax.swing.AbstractButton button,
java.lang.String text)
Configures the mnemonic for the button given the text. |
static void |
configureMnemonicForLabel(javax.swing.JLabel label,
java.lang.String text)
Configures the mnemonic for the label given the text. |
static java.awt.Image |
convertIconToImage(java.awt.Component component,
javax.swing.Icon icon)
Converts the specified icon to an image. |
static javax.swing.JLabel |
createLabelForComponent(java.awt.Component component,
java.lang.String text)
Creates an instance of JLabel and configures the mnemonic for the label given the text. |
static void |
drawFocusRect(java.awt.Graphics g,
int x,
int y,
int width,
int height)
WARNING: Changes current color setting. |
static void |
drawFocusRect(java.awt.Graphics g,
int x,
int y,
int width,
int height,
boolean useXOR)
WARNING: Changes current color setting. |
static boolean |
drawString(java.awt.Graphics g,
java.lang.String text,
int underlinedChar,
int x,
int y)
Copied and modified from BasicGraphicsUtils Draw a string with the graphics g at location (x,y) just like g.drawString() would. |
static java.lang.String |
getClippedText(java.lang.String text,
java.awt.FontMetrics fm,
int availTextWidth)
Retruns a clipped version of the text passed in if necessary. |
static java.lang.Object |
getDefaultModel(java.lang.Object comp)
Get an instance of the default model for the given component. |
static java.awt.Font |
getDialogFont()
|
static int |
getDisplayedMnemonic(java.lang.String label)
Returns the first mnemonic in the given string. |
static int |
getDisplayedMnemonicIndex(java.lang.String label)
Returns the index of the first mnemonic in the given string. |
static javax.swing.border.Border |
getGroupBoxBorder(java.lang.String title)
|
static javax.swing.border.Border |
getGroupBoxBorder(java.lang.String title,
int top,
int left,
int bottom,
int right)
|
static int |
getKeyMapping(java.lang.String key)
Get the java.awt.event.KeyEvent key code corresponding to the given string. |
static java.lang.String |
getLabelWithoutMnemonic(java.lang.String label)
Returns a string with all mnemonics in the given string removed. |
static java.awt.Container |
getParent(java.awt.Component comp,
java.lang.Class containerClass)
Returns the first Container ancestor of the given component that is of type containerClass . |
static java.awt.Frame |
getParentAWTFrame(java.awt.Component comp)
Get the parent frame of the given component. |
static javax.swing.JFrame |
getParentFrame(java.awt.Component comp)
Get the parent frame of the given component. |
static java.lang.String |
getStringMapping(int key)
Get the string corresponding to the given java.awt.event.KeyEvent key code. |
protected static java.lang.String[] |
getWrappedText(int availableSize,
java.lang.String[] lines,
java.awt.FontMetrics fm,
boolean wordWrap,
int orientation)
Returns an array of lines of text, which is a wrapped version of the lines passed in passed on the various properties passed in. |
static void |
invertRect(java.awt.Graphics g,
int x,
int y,
int width,
int height)
Draws an inverted rectangle. |
static void |
invertRect(java.awt.Graphics g,
java.awt.Rectangle rect)
Draws an inverted rectangle. |
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,
int orientation,
boolean lineWrap,
boolean wrapStyleWord,
int gapBetweenLines,
boolean clipIt,
int tabSize,
int leadingContentOffset,
int topContentOffset)
Copied and modified from SwingUtilities, defines what the orientation is, line wrap policy is, and the gap between lines so that multiline text can be handled. |
static void |
setEnabledOnContainer(java.awt.Container container,
boolean enabled)
This method sets the enabled state on all of it's descendents to either true or false depending on the value of the enabled parameter. |
static void |
setLabelAndMnemonicOnAction(javax.swing.Action action,
java.lang.String text)
Sets the mnemonic and label for the given action given the text. |
Field Detail |
---|
public static final java.lang.String RB_KEY
public static final java.lang.String VERTICAL_LINE_WIDTH_STRING
Constructor Detail |
---|
public Util()
Method Detail |
---|
public static void setEnabledOnContainer(java.awt.Container container, boolean enabled)
public static void center(java.awt.Window window)
public static void centerOver(java.awt.Window window, java.awt.Component component)
public static void centerOverWindow(java.awt.Window window, java.awt.Component component)
window
- The window to center.component
- The component who's Window should be used to center over.public static java.awt.Font getDialogFont()
public static void configureGroupBoxBorder(javax.swing.border.Border border, java.lang.String borderTitle)
border
- the border to modify for a group boxborderTitle
- the title for the border, or null for no titlepublic static javax.swing.border.Border getGroupBoxBorder(java.lang.String title, int top, int left, int bottom, int right)
public static javax.swing.border.Border getGroupBoxBorder(java.lang.String title)
public static javax.swing.JFrame getParentFrame(java.awt.Component comp)
comp
- the component to find the parent frame for
public static java.awt.Frame getParentAWTFrame(java.awt.Component comp)
comp
- the component to find the parent frame for
public static java.awt.Container getParent(java.awt.Component comp, java.lang.Class containerClass)
containerClass
.
comp
- the component to find the parent frame for
containerClass
public static java.lang.Object getDefaultModel(java.lang.Object comp)
comp
- the component to get the default model for
public static void addCommand(javax.swing.JMenu menu, com.sas.util.Command command, java.lang.Object object)
public static void addCommand(javax.swing.JMenu menu, com.sas.util.Command command)
public static void addCommands(javax.swing.JMenu menu, com.sas.util.Command[] commands)
public static void addCommands(javax.swing.JMenu menu, com.sas.util.Command[] commands, java.lang.Object object)
public static void addCommand(javax.swing.JPopupMenu menu, com.sas.util.Command command, java.lang.Object object)
public static void addCommand(javax.swing.JPopupMenu menu, com.sas.util.Command command)
public static void addCommands(javax.swing.JPopupMenu menu, com.sas.util.Command[] commands)
public static void addCommands(javax.swing.JPopupMenu menu, com.sas.util.Command[] commands, java.lang.Object object)
public static java.lang.String[] breakupLines(java.lang.String text)
public static java.lang.String getClippedText(java.lang.String text, java.awt.FontMetrics fm, int availTextWidth)
text
- the text to clip if necessaryfm
- the font metrics for the graphicsavailTextWidth
- the number of pixels the text has to paint itself in
public static boolean drawString(java.awt.Graphics g, java.lang.String text, int underlinedChar, int x, int y)
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, int orientation, boolean lineWrap, boolean wrapStyleWord, int gapBetweenLines, boolean clipIt, int tabSize, int leadingContentOffset, int topContentOffset)
protected static java.lang.String[] getWrappedText(int availableSize, java.lang.String[] lines, java.awt.FontMetrics fm, boolean wordWrap, int orientation)
availableSize
- the available size the text has to paint itselflines
- the lines of text which will be wrapped as neededfm
- the font metrics for the graphics that is being usedwordWrap
- whether to wrap the lines of text on word boundaries or notorientation
- whether the text is being painted vertically or horizontally
public static java.awt.Dimension computePopupMenuSize(javax.swing.JPopupMenu popMenu, java.awt.Component comp)
popMenu
- the popup menu whoose size the user wants to knowcomp
- the component the popup menu will be displayed upon, used so if the popup menu
does not have a font set, it will use the font form the component if possible
public static java.awt.Point computePopupMenuLocation(int x, int y, int width, int height, java.awt.Component comp)
x
- the initial popup menu x location, used to calculate if the popup menu will fit on the screen as isy
- the initial popup menu y location, used to calculate if the popup menu will fit on the screen as iswidth
- the width of the popup menuheight
- the hieight of the popup menucomp
- the component the popup menu is displaying on
public static java.lang.String getStringMapping(int key)
key
- the KeyEvent key code
public static int getKeyMapping(java.lang.String key)
key
- the string of the KeyEvent key code name
public static int getDisplayedMnemonic(java.lang.String label)
String item = bundle.getString("name.txt"); // returns "&Name:" String text = Util.getLabelWithoutMnemonic(item); int index = Util.getDisplayedMnemonicIndex(item); JLabel label = new JLabel(text); JTextField field = new JTextField(); label.setLabelFor(field); if (index > -1) { int mnemonic = Util.getDisplayedMnemonic(item); label.setDisplayedMnemonic(mnemonic); label.setDisplayedMnemonicIndex(index); } This will set the mnemonic index to 0, mnemonic to 'N', and label to "Name". Also, since the label is set as the label for the JTextField, when the user executes the mnemonic, the textfield will gain focus.
the
- string that will be parsed to return the frist mnemonic contain within it
public static int getDisplayedMnemonicIndex(java.lang.String label)
String item = bundle.getString("saveAs.txt"); // returns "Save &As" String label = Util.getLabelWithoutMnemonic(item); int index = Util.getDisplayedMnemonicIndex(item); JButton button = new JButton(label); if (index > -1) { int mnemonic = Util.getDisplayedMnemonic(item); button.setMnemonic(mnemonic); button.setDisplayedMnemonicIndex(index); } This will set the mnemonic index to 5, mnemonic to 'A', and label to "Save As". If just setMnemoic was called, then the 'a' in "Save" would be the mnemonic character, instead of the 'A' in "As".
the
- string that will be parsed to return the frist mnemonic contain within it
public static java.lang.String getLabelWithoutMnemonic(java.lang.String label)
String item = bundle.getString("saveAs.txt"); // returns "Save &As" String label = Util.getLabelWithoutMnemonic(item); int index = Util.getDisplayedMnemonicIndex(item); JButton button = new JButton(label); if (index > -1) { int mnemonic = Util.getDisplayedMnemonic(item); button.setMnemonic(mnemonic); button.setDisplayedMnemonicIndex(index); } This will set the label to "Save As", as the & will be removed from the string.
the
- string that will be parsed to have its mnemonics removed
public static void configureMnemonicForLabel(javax.swing.JLabel label, java.lang.String text)
getLabelWithoutMnemonic
, getDisplayedMnemonicIndex
, and
getDisplayedMnemonic
to set the mnemonic.
label
- The label the mnemoinc is to be set ontext
- the text for the label, should contain an & before the
character that the mnemonic is suppose to begetLabelWithoutMnemonic(String)
,
getDisplayedMnemonicIndex(String)
,
getDisplayedMnemonic(String)
public static void configureMnemonicForButton(javax.swing.AbstractButton button, java.lang.String text)
getLabelWithoutMnemonic
, getDisplayedMnemonicIndex
, and
getDisplayedMnemonic
to set the mnemonic.
button
- The button the mnemoinc is to be set ontext
- the text for the button, should contain an & before the
character that the mnemonic is suppose to begetLabelWithoutMnemonic(String)
,
getDisplayedMnemonicIndex(String)
,
getDisplayedMnemonic(String)
public static void setLabelAndMnemonicOnAction(javax.swing.Action action, java.lang.String text)
action
- the action that is going to have the Action.NAME, Action.MNEMONIC_KEY and
com.sas.swing.util.Action.MNEMONIC_INDEX properties set.text
- the string that contains the mnemonicgetLabelWithoutMnemonic(String)
,
getDisplayedMnemonicIndex(String)
,
getDisplayedMnemonic(String)
public static javax.swing.JLabel createLabelForComponent(java.awt.Component component, java.lang.String text)
configureMnemonicForLabel
for setting up the mnemonic.
The label is also sets as teh component for the given component.
component
- The componet the label is created fortext
- the text for the label, should contain an & before the
character that the mnemonic is suppose to be
configureMnemonicForLabel(JLabel, String)
public static java.awt.Image convertIconToImage(java.awt.Component component, javax.swing.Icon icon)
(int,int) Component.createImage()
).
If the icon is an instance of ImageIcon
, then
ImageIcon.getImage()
is returned.
component
- the component to create an image object fromicon
- the icon to convert to an image
null
ImageIcon
public static void apply(java.awt.Component rootComponent, com.sas.util.ApplyInterface operation)
rootComponent
- the root of a hierarchy of components; operation will
be applied to it and each of its childrenoperation
- an object that implements com.sas.util.ApplyInterface
;
rootComponent and each of its children will be passed in
turn as the argument to the apply(Object)
methodChangeCursorCommand
public static void invertRect(java.awt.Graphics g, int x, int y, int width, int height)
g
- the Graphics object to draw intox
- the x coordinate of the rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglepublic static void invertRect(java.awt.Graphics g, java.awt.Rectangle rect)
g
- the Graphics object to draw intorect
- the bounding rectangle to invertpublic static final void drawFocusRect(java.awt.Graphics g, int x, int y, int width, int height)
g
- the graphics object to draw intox
- the logical x coordinate of the rectangley
- the logical y coordinate of the rectanglewidth
- the logical width of the rectangleheight
- the logical height of the rectanglepublic static final void drawFocusRect(java.awt.Graphics g, int x, int y, int width, int height, boolean useXOR)
g
- the graphics object to draw intox
- the logical x coordinate of the rectangley
- the logical y coordinate of the rectanglewidth
- the logical width of the rectangleheight
- the logical height of the rectangleuseXOR
- use XOR to draw the focus rectangle
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |