|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdip.misc.Utils
Various static utilities used by GUI and non-GUI classes.
NOTE: to go from a String resource to a URL, use Utils.getURL() e.g., for a resource, called common/test.txt to use with Utils.getText(): String RESOURCE = "resource/common/test.txt"; String myText = Utils.getText(RESOURCE); to get the URL: URL url = Utils.getURL(RESOURCE); JeditorPane editorPane.setPage(url);
Field Summary | |
static javax.swing.border.Border |
EMPTY_BORDER_10
|
static javax.swing.border.Border |
EMPTY_BORDER_5
|
static java.lang.String |
FRAME_ICON
|
static java.lang.String |
UTILS_RES_ERR_DLG_TEXT
|
static java.lang.String |
UTILS_RES_ERR_DLG_TITLE
|
static java.lang.String |
UTILS_RES_NOT_FOUND
|
Method Summary | |
static java.io.File |
appendExtension(java.io.File file,
java.lang.String ext)
Appends the extension to the file, unless it was already appended. |
static void |
centerIn(java.awt.Component inner,
java.awt.Component outer)
Centers the inner component within the outer component. |
static void |
centerInScreen(java.awt.Component c)
Centers the component in the screen. |
static java.lang.String |
colorToHex(java.awt.Color color)
Given a Color, convert it to a hex String. |
static java.lang.String |
colorToHex(java.awt.Color color,
boolean withPound)
Converts a Color to its Hexadecimal equivalent, and prepends a '#' sign if withPound is true. |
static java.lang.String |
colorToHTMLHex(java.awt.Color color)
Converts a color to HTML hex color in the following format: #RRGGBB . |
static javax.swing.JTextField |
createEmailTextField(int cols)
Constructs a formatted text field that only allows valid email characters. |
static javax.swing.JEditorPane |
createTextLabel(boolean blend)
Creates a JEditorPane that has flowing, rich (HTML) text, but is not selectable or editable. |
static javax.swing.JEditorPane |
createTextLabel(java.lang.String text,
boolean blend)
Creates a JEditorPane that has flowing, rich (HTML) text, but is not selectable or editable. |
static javax.swing.JEditorPane |
createTextLabel(java.lang.String text,
boolean blend,
boolean isFocusable)
Creates a JEditorPane that has flowing, rich (HTML) text, but is not selectable or editable. |
static javax.swing.JTextField |
createURITextField(int cols)
Constructs a formatted text field that only allows valid URI characters. |
static java.lang.String |
format(java.lang.String format,
java.lang.Object[] args)
A less flexible and faster but easier-to-use message formatting. |
static java.lang.ClassLoader |
getClassLoader()
Gets the classloader used for this class |
static java.lang.String |
getCommonString(java.lang.String key)
Gets a common-bundle (non-localized) String. |
static java.lang.String[] |
getCommonStringArray(java.lang.String key)
Gets a common-bundle (non-localized) String array. |
static javax.swing.Icon |
getIcon(java.lang.String name)
Gets a resource as an Icon. |
static java.awt.Image |
getImage(java.lang.String name)
Gets a resource as an Image. |
static java.awt.Image |
getImage(java.net.URL url)
Returns an Image from the given URL. |
static javax.swing.ImageIcon |
getImageIcon(java.lang.String name)
Get an ImageIcon. |
static java.io.InputStream |
getInputStream(java.lang.String name)
Gets an InputStream to the named resource; throws an exception if the resource could not be found. |
static java.io.InputStreamReader |
getInputStreamReader(java.lang.String name)
Gets an InputStreamReader to the named resource. |
static java.util.Locale |
getLocale()
Get which Locale has been loaded or selected. |
static int[] |
getLocalIntArray(java.lang.String key)
Gets an array of resource-bundle ints, for internationalization. |
static java.lang.String |
getLocalString(java.lang.String key)
Gets a resource-bundle String; this is for internationalization. |
static java.lang.String |
getLocalString(java.lang.String key,
java.lang.Object arg1)
Gets a resource-bundle String; this is for internationalization. |
static java.lang.String |
getLocalString(java.lang.String key,
java.lang.Object[] args)
Gets a resource-bundle String; this is for internationalization. |
static java.lang.String |
getLocalString(java.lang.String key,
java.lang.Object arg1,
java.lang.Object arg2)
Gets a resource-bundle String; this is for internationalization. |
static java.lang.String |
getLocalString(java.lang.String key,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
Gets a resource-bundle String; this is for internationalization. |
static java.lang.String[] |
getLocalStringArray(java.lang.String key)
Gets an array of resource-bundle Strings, for internationalization. |
static java.lang.String |
getLocalStringNoEx(java.lang.String key)
Gets a resource-bundle String; this is for internationalization. |
static java.net.URL |
getResourceBase()
Gets the Resource Base (resource directory). |
static java.lang.String |
getResourceBasePrefix()
Get the resource base prefix. |
static java.awt.Image |
getScaledImage(java.awt.Image src,
float factor)
Return a scaled image that is proportionally scaled via the given factor (e.g., 0.5f = 1/2 size). |
static java.awt.Image |
getScaledImage(java.awt.Image src,
int w,
int h)
Scale an Image to the given width and height (in pixels) |
static java.awt.Dimension |
getScreenSize()
Return the screen size. |
static java.awt.Dimension |
getScreenSize(float fraction)
Returns the screen size multiplied by the given fraction, preserving the aspect ratio, and returns the result. |
static java.awt.Dimension |
getScreenSize(float fraction,
float smallScreenFraction)
Returns the screen size multiplied by the given fraction, preserving the aspect ratio, and returns the result. |
static java.lang.String |
getText(java.lang.String name)
Gets a resource as a String. |
static java.lang.String |
getText(java.lang.String name,
java.lang.Object arg1)
Gets a resource as a String. |
static java.lang.String |
getText(java.lang.String name,
java.lang.Object[] args)
Gets a resource as a String. |
static java.net.URL |
getURL(java.lang.String name)
Given a resource name, extract a URL for the given resource. |
static boolean |
isOSX()
Detect if we are running on Mac OS X |
static boolean |
isWindows()
Detect if we are running on Windows |
static void |
loadLocale(java.util.Locale loc)
Force a load of a locale |
static java.awt.Color |
parseColor(java.lang.String value,
java.awt.Color defaultValue)
Given a color string, converts it to a color value. |
static java.lang.String[] |
parseCSV(java.lang.String input)
Parses a line of CSV text into a String array. |
static java.lang.String[] |
parseCSVXE(java.lang.String input)
Similar to parseCSV(), but if the input string (after trimming) is null or empty, returns an array of length 0. |
static void |
popupError(javax.swing.JFrame parent,
java.lang.String title,
java.lang.String text)
Popup an Error message dialog |
static void |
popupInfo(javax.swing.JFrame parent,
java.lang.String title,
java.lang.String text)
Popup an Info message dialog |
static java.lang.String |
replaceAll(java.lang.String input,
java.lang.String[] toFind,
java.lang.String[] toReplace)
Replaces all instances of "tofind" with "toReplace" in the given input String, and returns the String after replacement has occured. |
static java.lang.String |
replaceAll(java.lang.String input,
java.lang.String toFind,
java.lang.String toReplace)
Replaces all instances of "tofind" with "toReplace" in the given input String, and returns the String after replacement has occured. |
static javax.swing.ImageIcon |
rescaleImageIcon(javax.swing.ImageIcon src,
int w,
int h)
Scale an ImageIcon to the given width and height (in pixels) |
static javax.swing.ImageIcon |
scaleDown(javax.swing.ImageIcon src,
int maxW,
int maxH)
Scale an ImageIcon *down* to the given width and height (in pixels), keeping aspect ratio intact. |
static void |
setFontColor(java.lang.StringBuffer sb,
java.awt.Color color)
Create a <font> tag with the given color. |
static void |
setFontColor(java.lang.StringBuffer sb,
int r,
int g,
int b)
Create a <font> tag with the given color. |
static java.awt.Image |
syncCreateImage(java.awt.Image img)
Ensure that the entire image has been created. |
static java.awt.Image |
syncCreateImage(java.awt.image.ImageProducer ip)
Ensure that the entire image has been created. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final javax.swing.border.Border EMPTY_BORDER_5
public static final javax.swing.border.Border EMPTY_BORDER_10
public static final java.lang.String UTILS_RES_NOT_FOUND
public static final java.lang.String UTILS_RES_ERR_DLG_TITLE
public static final java.lang.String UTILS_RES_ERR_DLG_TEXT
public static final java.lang.String FRAME_ICON
Method Detail |
public static void loadLocale(java.util.Locale loc)
public static java.util.Locale getLocale()
public static java.lang.ClassLoader getClassLoader()
public static java.awt.Dimension getScreenSize()
public static java.awt.Dimension getScreenSize(float fraction)
For example, getScreenSize(0.5f) would return a Dimension that was 400 x 300 if the screen size was 800 x 600 pixels.
public static java.awt.Dimension getScreenSize(float fraction, float smallScreenFraction)
This is a hackish version, with two fractions. The second fraction is used for 'smaller' screens (defined as 800x600 or less).
public static void centerInScreen(java.awt.Component c)
public static void centerIn(java.awt.Component inner, java.awt.Component outer)
public static java.io.File appendExtension(java.io.File file, java.lang.String ext)
public static void setFontColor(java.lang.StringBuffer sb, java.awt.Color color)
public static void setFontColor(java.lang.StringBuffer sb, int r, int g, int b)
public static void popupError(javax.swing.JFrame parent, java.lang.String title, java.lang.String text)
public static void popupInfo(javax.swing.JFrame parent, java.lang.String title, java.lang.String text)
public static java.net.URL getResourceBase()
public static java.lang.String getResourceBasePrefix()
public static java.net.URL getURL(java.lang.String name)
public static javax.swing.ImageIcon getImageIcon(java.lang.String name)
public static java.io.InputStream getInputStream(java.lang.String name) throws java.io.IOException
java.io.IOException
public static java.io.InputStreamReader getInputStreamReader(java.lang.String name) throws java.io.IOException
java.io.IOException
public static java.lang.String getText(java.lang.String name)
Suitable for small text files / HTML files. May not be appropriate for larger text files.
A null string is returned if an error occurs.
public static java.lang.String getText(java.lang.String name, java.lang.Object arg1)
Uses MessageFormat to replace the given argument with the argument provided.
public static java.lang.String getText(java.lang.String name, java.lang.Object[] args)
Uses MessageFormat to replace the given argument with the arguments provided.
public static java.awt.Image getImage(java.lang.String name)
Synchronous; may not suitable for large images.
null if error
public static java.awt.Image getImage(java.net.URL url)
Synchronous; may not suitable for large images.
null if error
public static javax.swing.Icon getIcon(java.lang.String name)
Synchronous; may not suitable for large images.
null if error
public static java.awt.Image syncCreateImage(java.awt.image.ImageProducer ip)
This method ensures that the Image desired has been
fully realized (i.e., loaded or created) before
returning a reference to it. If an error occurs, the
returned Image will be null
.
ip
- ImageProducer image source.
public static java.awt.Image syncCreateImage(java.awt.Image img)
This method ensures that the Image desired has been
fully realized (i.e., loaded or created) before
returning a reference to it. If an error occurs, the
returned Image will be null
.
img
- the image source.
public static java.lang.String getLocalString(java.lang.String key)
If resource is missing, a popup-error message is displayed.
.
public static java.lang.String[] getLocalStringArray(java.lang.String key)
The Strings must be comma-separated. Spaces before/after are trimmed. Quotes have no special meaning.
.
public static int[] getLocalIntArray(java.lang.String key)
The Integers must be comma-separated. Spaces before/after are trimmed. Quotes have no special meaning.
.
public static java.lang.String getLocalString(java.lang.String key, java.lang.Object arg1)
If resource is missing, a popup-error message is displayed.
.
public static java.lang.String getLocalString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
If resource is missing, a popup-error message is displayed.
.
public static java.lang.String getLocalString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
If resource is missing, a popup-error message is displayed.
.
public static java.lang.String getLocalString(java.lang.String key, java.lang.Object[] args)
If resource is missing, a popup-error message is displayed.
.
public static java.lang.String getLocalStringNoEx(java.lang.String key)
. If there is NO resource present, returns 'null'.
public static java.awt.Color parseColor(java.lang.String value, java.awt.Color defaultValue)
Acceptable forms are:
#RGB
(3 hex values; values will be doubled (e.g.,
#FAF becomes #FFAAFF)#RRGGBB
(6 hex digits)#RRGGBBAA
(8 hex digits; A is alpha value)rgb(r, g, b)
(where r, g, b are specified as
integers (0-255) or percents (0-100%, 100% = 255).If parsing fails, defaultValue is returned.
public static java.lang.String colorToHex(java.awt.Color color)
The format of the output string is: "RRGGBBAA". No '#' is prepended. The String length is always 8 characters, zero-padded as necessary.
public static java.lang.String colorToHex(java.awt.Color color, boolean withPound)
public static java.lang.String colorToHTMLHex(java.awt.Color color)
#RRGGBB
. Alpha values are not used.
public static javax.swing.JEditorPane createTextLabel(boolean blend)
This is non-focusable by default.
blend
- match background of component if true.public static javax.swing.JEditorPane createTextLabel(java.lang.String text, boolean blend)
This is non-focusable by default.
text
- the initial text.blend
- match background of component if true.public static javax.swing.JEditorPane createTextLabel(java.lang.String text, boolean blend, boolean isFocusable)
text
- the initial text.blend
- match background of component if true.isFocusable
- true if this component can receive focus eventspublic static java.awt.Image getScaledImage(java.awt.Image src, int w, int h)
public static javax.swing.ImageIcon rescaleImageIcon(javax.swing.ImageIcon src, int w, int h)
public static javax.swing.ImageIcon scaleDown(javax.swing.ImageIcon src, int maxW, int maxH)
public static java.awt.Image getScaledImage(java.awt.Image src, float factor)
public static java.lang.String format(java.lang.String format, java.lang.Object[] args)
public static javax.swing.JTextField createEmailTextField(int cols)
public static javax.swing.JTextField createURITextField(int cols)
public static java.lang.String[] parseCSV(java.lang.String input)
This quoted text, unquoted text, and escaped quotes. Excel-style quote support could be added, but has not been tested adequately. Unescaped quotes are also acceptable in this parser. Commas with only whitespace between them return empty ("") Strings. Whitespace is removed around unquoted items.
For example:
"hello", goodbye , """test",, "a line, a \"quote\""
Will parse into:
hello|goodbye|""test||a line, a "quote"|
Should never return null. NOTE that a entry of "" will return "" (array length 1). An array length of 0 is never returned.
public static java.lang.String[] parseCSVXE(java.lang.String input)
public static java.lang.String getCommonString(java.lang.String key)
public static java.lang.String[] getCommonStringArray(java.lang.String key)
public static java.lang.String replaceAll(java.lang.String input, java.lang.String toFind, java.lang.String toReplace)
public static java.lang.String replaceAll(java.lang.String input, java.lang.String[] toFind, java.lang.String[] toReplace)
toFind and toReplace must have the same lengths.
The order of replacement is the order of the toFind array.
public static boolean isOSX()
public static boolean isWindows()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |