|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.peace_tools.generic.Utilities
public class Utilities
This class acts as a helper class and contains STATIC methods (only) that acts as helpers to handle some of the common, often performed tasks in the presentation manager
Field Summary | |
---|---|
static int |
CHECK_BOX_ITEM
Constant that can be supplied to the createMenuItem method |
static int |
MENU_ITEM
Constant that can be supplied to the createMenuItem method |
static java.lang.String |
PATH_PREFIX
The default prefix that is added to the path of the files to be loaded by the various methods in this class. |
static int |
RADIO_BUTTON_ITEM
Constant that can be supplied to the createMenuItem method |
Constructor Summary | |
---|---|
Utilities()
|
Method Summary | |
---|---|
static void |
adjustDimension(java.awt.Component c,
int xDelta,
int yDelta)
Helper method to set the preferred and maximum size of a component. |
static void |
adjustFont(java.awt.Component c,
int sizeChange,
int minSize,
int bold)
Utility method to change the font size set for a given component. |
static void |
centerPanel(java.awt.Window parent,
java.awt.Window child)
Helper method to center a given child on a parent. |
static javax.swing.JPanel |
collapsedMessage(java.lang.String message,
java.lang.String details)
Helper method to create a collapsed pane with message. |
static javax.swing.JButton |
createButton(java.lang.String iconFileName,
java.lang.String title,
java.lang.String command,
java.awt.event.ActionListener al,
java.lang.String toolTip,
boolean enable)
This method is a utility method to create generic buttons. |
static javax.swing.JPanel |
createLabeledComponents(java.lang.String label,
java.lang.String subLabel,
int textBoxHeightDelta,
boolean addEndSpacer,
java.awt.Component... components)
This method is a helper method to lay out components vertically. |
static javax.swing.JMenuItem |
createMenuItem(int itemKind,
java.lang.String itemTitle,
java.lang.String command,
java.awt.event.ActionListener al,
java.lang.String iconFileName,
javax.swing.KeyStroke shortCut,
boolean enable,
boolean auxFlag)
This method is a convenience method that provides a simple mechanism for creating a JMenuItem, given the parameters. |
static javax.swing.JMenuItem |
createMenuItem(int itemKind,
java.lang.String itemTitle,
java.lang.String subTitle,
java.lang.String command,
java.awt.event.ActionListener al,
java.lang.String iconFileName,
javax.swing.KeyStroke shortCut,
boolean enable,
boolean auxFlag)
This method is a convenience method that provides a simple mechanism for creating a JMenuItem, given the parameters. |
static javax.swing.JPanel |
createSubPanel(int alignment,
java.lang.String label,
javax.swing.JComponent... components)
This method is a helper method that takes the alignment for a FlowLayout , a label to identify the components, and the
actual JComponents themselves and places them in a JPanel with a
FlowLayout. |
static javax.swing.JButton |
createToolButton(java.lang.String iconFileName,
java.lang.String title,
java.lang.String command,
java.awt.event.ActionListener al,
java.lang.String toolTip,
boolean enable)
This method is a utility method to create tool bar buttons. |
static void |
download(javax.swing.ProgressMonitor pm,
java.lang.String address,
java.lang.String localFileName)
Helper method for download a file from a given URL. |
static java.lang.String |
enableHTMLText(java.lang.String text,
boolean enabled)
Utility method to modify HTML text to look enabled or disabled. |
static java.lang.String |
getDefaultDirectory()
Helper method to determine the default working directory for PEACE. |
static java.lang.String |
getExtension(java.io.File f)
A helper method to determine the extension of a file. |
static javax.swing.ImageIcon |
getIcon(java.lang.String path)
This method is a quick little helper method to pull image (icons) using getResource(String). |
static java.io.InputStream |
getStream(java.lang.String resourceName)
This is a helper method that can be used to obtain an input stream for a resource. |
static byte[] |
integerToByteArray(int integer)
Returns a byte array containing the two's-complement representation of the integer. The byte array will be in big-endian byte-order with a fixes length of 4 (the least significant byte is in the 4th element). Example: intToByteArray(258) will return { 0, 0, 1, 2 },BigInteger.valueOf(258).toByteArray() returns { 1, 2 }. |
static void |
makeToolBarButton(javax.swing.AbstractButton button,
boolean fillContentArea)
Method to add mouse adapter to make button like a tool bar button. |
static java.lang.String |
readFullStream(java.io.InputStream is)
This is a helper method to read small text data from a stream into a String. |
static java.lang.String |
readSmallTextFile(java.lang.String fileName)
This is a helper method to read small text files (like license information) into a string. |
static void |
setEnabled(java.awt.Container parent,
boolean status)
Helper method to recursively enable/disable a component and its children. |
static void |
setEnabled(javax.swing.JMenuItem menuItem,
boolean enabled)
Utility method to update menu item text that uses HTML. |
static int |
toInteger(byte msb,
byte lsb)
This is a utility method to convert a pair of bytes into a single integer. |
static java.lang.String |
toString(java.lang.Throwable e)
Helper method to convert the stack trace in an exception to a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String PATH_PREFIX
public static final int MENU_ITEM
public static final int CHECK_BOX_ITEM
public static final int RADIO_BUTTON_ITEM
Constructor Detail |
---|
public Utilities()
Method Detail |
---|
public static javax.swing.JMenuItem createMenuItem(int itemKind, java.lang.String itemTitle, java.lang.String command, java.awt.event.ActionListener al, java.lang.String iconFileName, javax.swing.KeyStroke shortCut, boolean enable, boolean auxFlag)
itemKind
- This is a enumeration value which can be MENU_ITEM,
CHECK_BOX_ITEM, or RADIO_BUTTON_ITEMitemTitle
- String representing the menu option. Note: The string may
contain a "_" (underscore) character preceeding the letter
that is suppoed to be used as an accelerator for this item.
However, if an explicit key stroke is specified (parameter 3
to this method call) then this underscore will be ignored. In
either case the "_" will be stripped out of the option! The
string cannot be "null"command
- The string representing the action command that will be
generated when this menu option is slected!al
- The ActionListener to register with the Menu Item.iconFileName
- String representing the file name of the icon (*.jpg or *.gif)
to be assiocated with this menu option. If the name is "null"
then no icon is associates with this menu.shortCut
- Keystroke representing the shortcut for this menu itemenable
- Boolean value that indicates if this menu item should be
enabled by default. "true" implies menu item is enabled and
"false" implies the menu item is disabled.auxFlag
- A boolean value that is used to select or unselect a
CHECK_BOX_ITEM. Refer to the documentation of CheckBoxMenuItem
in Java SDK API for further information
public static javax.swing.JMenuItem createMenuItem(int itemKind, java.lang.String itemTitle, java.lang.String subTitle, java.lang.String command, java.awt.event.ActionListener al, java.lang.String iconFileName, javax.swing.KeyStroke shortCut, boolean enable, boolean auxFlag)
itemKind
- This is a enumeration value which can be MENU_ITEM,
CHECK_BOX_ITEM, or RADIO_BUTTON_ITEMitemTitle
- String representing the menu option. Note: The string may
contain a "_" (underscore) character preceding the letter
that is supposed to be used as an accelerator for this item.
However, if an explicit key stroke is specified (parameter 3
to this method call) then this underscore will be ignored. In
either case the "_" will be stripped out of the option! The
string cannot be "null"subTitle
- A sub title string to be used for this menu item. If this
string is null then this method calls the overloaded method that does not
take a subTitle as parameter.command
- The string representing the action command that will be
generated when this menu option is slected!al
- The ActionListener to register with the Menu Item.iconFileName
- String representing the file name of the icon (*.jpg or *.gif)
to be associated with this menu option. If the name is "null"
then no icon is associates with this menu.shortCut
- Keystroke representing the shortcut for this menu itemenable
- Boolean value that indicates if this menu item should be
enabled by default. "true" implies menu item is enabled and
"false" implies the menu item is disabled.auxFlag
- A boolean value that is used to select or unselect a
CHECK_BOX_ITEM. Refer to the documentation of CheckBoxMenuItem
in Java SDK API for further information
public static void setEnabled(javax.swing.JMenuItem menuItem, boolean enabled)
Note:Calling this method with menu items whose text is not HTML causes no side effects. So it is safe to call this method with any menu item.
menuItem
- The menu item that must be enabled or disabled.enabled
- If this parameter is true, then the menu item is
enabled. Otherwise it is disabled.public static java.lang.String enableHTMLText(java.lang.String text, boolean enabled)
Note:Calling this method with text that is not HTML causes no side effects. So it is safe to call this method with any text.
text
- The message whose text is to be modified to make
it appear enabled to disabled.enabled
- If this parameter is true, then the text is
updated to appear enabled. Otherwise it is set to appear disabled.
public static javax.swing.JButton createButton(java.lang.String iconFileName, java.lang.String title, java.lang.String command, java.awt.event.ActionListener al, java.lang.String toolTip, boolean enable)
iconFileName
- A string representing the icon file (gif/jpeg) that is to be
associated with this buttontitle
- A string representing the title for this buttoncommand
- The command string to be generated when this button is clickedal
- The action listener for this button. When the button is
clicked the action listener gets triggered by the java system
where the processing for the button click is performedtoolTip
- The string to be associated with the tool tip associated with
this buttonenable
- A boolean that indicates if the button must be enabled by
default ("true" => button enabled. "false" => button disabled)
public static javax.swing.JButton createToolButton(java.lang.String iconFileName, java.lang.String title, java.lang.String command, java.awt.event.ActionListener al, java.lang.String toolTip, boolean enable)
iconFileName
- A string representing the icon file (gif/jpeg) that is to be
associated with this buttontitle
- A string representing the title for this buttoncommand
- The command string to be generated when this button is clickedal
- The action listener for this button. When the button is
clicked the action listener gets triggered by the java system
where the processing for the button click is performedtoolTip
- The string to be associated with the tool tip associated with
this buttonenable
- A boolean that indicates if the button must be enabled by
default ("true" => button enabled. "false" => button disabled)
public static void makeToolBarButton(javax.swing.AbstractButton button, boolean fillContentArea)
button
- The button whose properties have to be modified.fillContentArea
- If this parameter is true, then filling
of the content area is enabled when the mouse rolls over a
button.public static javax.swing.JPanel createSubPanel(int alignment, java.lang.String label, javax.swing.JComponent... components)
FlowLayout
, a label to identify the components, and the
actual JComponents themselves and places them in a JPanel with a
FlowLayout. The panel is useful for situations that require multiple
panels to create a vertical layout of many components. (Note: FlowLayout
performs only a horizontal layout)
alignment
- The Alignment, one of FlowLayout.LEFT
,
FlowLayout.RIGHT
,
FlowLayout.CENTER
,
FlowLayout.LEADING
or
FlowLayout.TRAILING
label
- The label to put before the components (gets converted into a
JLabel, set to null for none)components
- One or more comma seperated components to place in the JPanel.
public static javax.swing.JPanel createLabeledComponents(java.lang.String label, java.lang.String subLabel, int textBoxHeightDelta, boolean addEndSpacer, java.awt.Component... components)
label
- The label to put before the components (gets converted into a
JLabel, set to null for none)subLabel
- A sub-label to be placed below the main label. This
label is displayed with a smaller font if it is not null.textBoxHeightDelta
- If this parameter is non-zero then it adds this
value to the preferred height of any JTextField components in the
component list. This feature is useful to ensure that text fields are
not too small (they happen to be in GTK)addEndSpacer
- If this flag is true, then this method adds a
trailing empty component that will stretch to take up any available
vertical space.components
- One or more comma separated components to place in the JPanel.
public static javax.swing.ImageIcon getIcon(java.lang.String path)
path
- The path of the image (relative)
public static java.lang.String getExtension(java.io.File f)
f
- The file whose extension needs to be determined
public static int toInteger(byte msb, byte lsb)
msb
- The most significant byte of the number.lsb
- The least significant byte of the number.
public static byte[] integerToByteArray(int integer)
intToByteArray(258)
will return { 0, 0, 1, 2 },BigInteger.valueOf(258).toByteArray()
returns { 1, 2 }.
integer
- The integer to be converted.
public static void adjustFont(java.awt.Component c, int sizeChange, int minSize, int bold)
c
- The component whose current font size is to be changed.sizeChange
- The change in font size. This value gets added
to the component's current font size to determine the new font
size. Therefore, positive values will increase the font size while
negative values will decrease the font size.minSize
- The minimum font size below which the font value must
never drop.bold
- If this value is 1, then the font is made bold. If this
value is -1, the font is made normal. If this value is 0 then the
weight of the font is unchanged.public static void download(javax.swing.ProgressMonitor pm, java.lang.String address, java.lang.String localFileName) throws java.lang.Exception
pm
- The progress monitor to be updated as data is downloaded.address
- The URL from where the data is to be downloaded/copied.localFileName
- The name of the local file (with optional path) where
the data is to be saved.
java.lang.Exception
- This method throws various exception on errors.public static java.io.InputStream getStream(java.lang.String resourceName) throws java.lang.Exception
resourceName
- The relative path/name of the resource to which an input stream
is desired.
java.lang.Exception
- This method throws an exception if a valid input stream could not
be created to the specified resource.public static java.lang.String readSmallTextFile(java.lang.String fileName) throws java.lang.Exception
fileName
- The name of the file to be loaded. Prefer to use
relative path names so that the file can be loaded immaterial of
whether it is from a jar or from the local file system.
java.lang.Exception
- This method throws an exception if errors occur
during reading the file.public static java.lang.String readFullStream(java.io.InputStream is) throws java.lang.Exception
is
- The input stream from where the data is to be read.
java.lang.Exception
- This method throws an exception if errors occur
during reading the stream.public static void adjustDimension(java.awt.Component c, int xDelta, int yDelta)
c
- The component whose sizes are to be adjusted.xDelta
- The change in width with respect to current width.yDelta
- The change in height with respect to current height.public static void setEnabled(java.awt.Container parent, boolean status)
parent
- The parent component whose status is to be changed.status
- If true, the components are enabled otherwise the component is
disabled.public static java.lang.String toString(java.lang.Throwable e)
e
- The exception to whose stack trace and information
is desired.
public static javax.swing.JPanel collapsedMessage(java.lang.String message, java.lang.String details)
message
- The message that is to be constantly displayed
to the user via a JLabel.details
- The extra information that will be placed within
a JTextArea that is hidden (or shown) depending on the user's
choice (indicated by clicking on the details button)
public static java.lang.String getDefaultDirectory()
public static void centerPanel(java.awt.Window parent, java.awt.Window child)
parent
- The parent component on which the child component
is to be centered.child
- The child component to be centered.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |