org.formaria.aria.helper
Class AriaUtilities

java.lang.Object
  extended by org.formaria.aria.helper.AriaUtilities

public class AriaUtilities
extends java.lang.Object

A collection of utilities for use with Aria

Copyright (c) Formaria Ltd., 2008

$Revision: 2.15 $

License: see License.txt


Field Summary
static java.awt.Image ERROR_BADGE
           
 
Constructor Summary
AriaUtilities()
           
 
Method Summary
static void applyStyle(Project currentProject, java.lang.Object comp, java.lang.String styleName)
          Apply a style to a component
static java.awt.Color brightenColor(java.awt.Color color, int percentage)
          Get a darker/brighter version of a color
static java.awt.image.BufferedImage brightenImage(java.awt.image.BufferedImage bi, float scaleFactor)
          Brighten an image
static void centerOnScreen(java.awt.Container dialog)
          Center a dialog on the screen.
static java.net.URL checkUrl(java.net.URL url)
          Check if a URL can be opened
static java.lang.String colorToHexString(java.awt.Color c)
          Convert a color to a hexadecimal string e.g.
static java.lang.Object convertValue(java.lang.Object obj, java.lang.Class type)
          Convert a value to a specified type
static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage bi)
          Copy and image
static int count(java.lang.String source, char match)
          Count the instances of a character in a string
static int count(java.lang.String source, char match, char openingToken, char endingToken)
          Count the instances of a character in a string, skipping nested expressions delimited by the specified tokens
static java.awt.image.BufferedImage createCompatibleImage(java.awt.Graphics2D g2d, java.awt.image.BufferedImage img)
          Create a compatible image for the specified image if it doe not match the display's color model.
static java.awt.image.BufferedImage createCompatibleImage(java.awt.Graphics2D g2d, int w, int h)
          Create a compatible image for the specified image if it doe not match the display's color model.
static java.lang.String exec(java.lang.String[] commandArray)
          Exec a process and output the error and output streams to the console
static void getArguments(java.lang.String argString, java.lang.Class[] argTypes, java.lang.Object[] argValues, char separator)
          Get the argument types and values from an argument string
static void getArguments(java.lang.String argString, java.lang.Class[] argTypes, java.lang.Object[] argValues, char separator, char openingToken, char endingToken)
          Get the argument types and values from an argument string, skipping nested expressions delimited by the specified tokens
static int getFileCount(java.io.File targetFolder)
          Count the number of files in a folder or the child folders
static java.awt.Point getMaxCoordinates(java.awt.Container cont)
          Get the maximum x and y coordinates of the children
static int getMinorVersion()
          Get the minor version of the runtime Java platform
static java.lang.String getRegistryEntry(java.lang.String key)
           
static java.io.File getUserDirectory(java.lang.String path)
          Get a directory under the user.home.
static boolean hasFiles(java.io.File targetFolder)
          Does the folder or its children contain files
static int indexOfMatchingEnding(java.lang.String s, char openingToken, char endingToken, int startPos)
          Find the index of the matching token, taking into account any nested pairs
static void invokeAndWait(java.lang.Runnable r)
          Invoke the SwingUtilities invokeAndWait method via reflection.
static void invokeLater(java.lang.Runnable r)
          Invoke the SwingUtilities invokeLater method via reflection.
static java.lang.String replace(java.lang.String srcValue, java.lang.String pattern, java.lang.String replacement)
          Replace all the occurances of one string with another
static java.lang.String slashify(java.lang.String path, boolean isDirectory)
          Taken from java.io.File in JDK 1.4
static java.lang.String translate(Project currentProject, java.lang.String key)
          Translate a key to the current language
static java.awt.Color unsaturateColor(java.awt.Color color, int percentage)
          Get an unsaturated version of a color
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_BADGE

public static java.awt.Image ERROR_BADGE
Constructor Detail

AriaUtilities

public AriaUtilities()
Method Detail

count

public static int count(java.lang.String source,
                        char match)
Count the instances of a character in a string

Parameters:
source - the source string
match - the character to match
Returns:
the numer of instances of the match character

count

public static int count(java.lang.String source,
                        char match,
                        char openingToken,
                        char endingToken)
Count the instances of a character in a string, skipping nested expressions delimited by the specified tokens

Parameters:
source - the source string
match - the character to match
endingToken - the ending token
openingToken - the opening token
Returns:
the numer of instances of the match character

centerOnScreen

public static void centerOnScreen(java.awt.Container dialog)
Center a dialog on the screen.

Parameters:
dialog - the dialog window you want to center

invokeLater

public static void invokeLater(java.lang.Runnable r)
Invoke the SwingUtilities invokeLater method via reflection.

Parameters:
r - the runnable to be passed to the SwingUtilities method

invokeAndWait

public static void invokeAndWait(java.lang.Runnable r)
Invoke the SwingUtilities invokeAndWait method via reflection.

Parameters:
r - the runnable to be passed to the SwingUtilities method

translate

public static java.lang.String translate(Project currentProject,
                                         java.lang.String key)
Translate a key to the current language

Parameters:
key - the language key
Returns:
the translated text

unsaturateColor

public static java.awt.Color unsaturateColor(java.awt.Color color,
                                             int percentage)
Get an unsaturated version of a color

Parameters:
color - the original color
percentage - the percentage of the original color saturation to return

brightenColor

public static java.awt.Color brightenColor(java.awt.Color color,
                                           int percentage)
Get a darker/brighter version of a color

Parameters:
color - the original color
percentage - the percentage of the original color brightness to return

getArguments

public static void getArguments(java.lang.String argString,
                                java.lang.Class[] argTypes,
                                java.lang.Object[] argValues,
                                char separator)
Get the argument types and values from an argument string

Parameters:
argString - the raw argument string e.g. foo,bar,12
argTypes - the argument class names - for the above example java.lang.String,java.lang.String,java.lang.int
argValues - the argument values - for the above example "foo", "bar", 12
separator - the argument seperator

getArguments

public static void getArguments(java.lang.String argString,
                                java.lang.Class[] argTypes,
                                java.lang.Object[] argValues,
                                char separator,
                                char openingToken,
                                char endingToken)
Get the argument types and values from an argument string, skipping nested expressions delimited by the specified tokens

Parameters:
argString - the raw argument string e.g. foo,bar,12
argTypes - the argument class names - for the above example java.lang.String,java.lang.String,java.lang.int
argValues - the argument values - for the above example "foo", "bar", 12
separator - the argument seperator
endingToken - the ending token
openingToken - the opening token

applyStyle

public static void applyStyle(Project currentProject,
                              java.lang.Object comp,
                              java.lang.String styleName)
Apply a style to a component

Parameters:
comp - the component
styleName - the style to lookup

getMinorVersion

public static int getMinorVersion()
Get the minor version of the runtime Java platform

Returns:
the minor version e.g. 3 for JDK 1.3.x

indexOfMatchingEnding

public static int indexOfMatchingEnding(java.lang.String s,
                                        char openingToken,
                                        char endingToken,
                                        int startPos)
Find the index of the matching token, taking into account any nested pairs

Parameters:
s - the string to search
endingToken - the ending token
openingToken - the opening token
Returns:
the index of the closing token

replace

public static java.lang.String replace(java.lang.String srcValue,
                                       java.lang.String pattern,
                                       java.lang.String replacement)
Replace all the occurances of one string with another

Parameters:
srcValue - the source string
pattern - the pattern to locate
replacement - the replacement text
Returns:
the new string

exec

public static java.lang.String exec(java.lang.String[] commandArray)
Exec a process and output the error and output streams to the console

Parameters:
commandArray - the command and arguments
Returns:
0 on success, non zero otherwise

getRegistryEntry

public static java.lang.String getRegistryEntry(java.lang.String key)

getMaxCoordinates

public static java.awt.Point getMaxCoordinates(java.awt.Container cont)
Get the maximum x and y coordinates of the children

Parameters:
cont - the container whose children will be examined
Returns:
the coordinate of the maximum x and y

colorToHexString

public static java.lang.String colorToHexString(java.awt.Color c)
Convert a color to a hexadecimal string e.g. Color( 255,0,0 ) becomes ff0000. The alpha channel is included if used

Parameters:
c - the color to convert
Returns:
the string representation

checkUrl

public static java.net.URL checkUrl(java.net.URL url)
Check if a URL can be opened

Parameters:
url - the url to check
Returns:
the url or null if it cannot be opened

getFileCount

public static int getFileCount(java.io.File targetFolder)
Count the number of files in a folder or the child folders

Parameters:
targetFolder - the folder to search
Returns:
the file count

hasFiles

public static boolean hasFiles(java.io.File targetFolder)
Does the folder or its children contain files

Parameters:
targetFolder - the folder to search
Returns:
true if the folders contain a file

createCompatibleImage

public static java.awt.image.BufferedImage createCompatibleImage(java.awt.Graphics2D g2d,
                                                                 java.awt.image.BufferedImage img)
Create a compatible image for the specified image if it doe not match the display's color model.

Parameters:
g2d - the display graphics object
img - the source image
Returns:
the compatible image
Since:
3.2

createCompatibleImage

public static java.awt.image.BufferedImage createCompatibleImage(java.awt.Graphics2D g2d,
                                                                 int w,
                                                                 int h)
Create a compatible image for the specified image if it doe not match the display's color model.

Parameters:
g2d - the graphics object/context
w - the width
h - the width
Returns:
the compatible image
Since:
3.2

brightenImage

public static java.awt.image.BufferedImage brightenImage(java.awt.image.BufferedImage bi,
                                                         float scaleFactor)
Brighten an image

Parameters:
bi - the source image
Returns:
the filtered image

copyImage

public static java.awt.image.BufferedImage copyImage(java.awt.image.BufferedImage bi)
Copy and image

Parameters:
bi - the source image
Returns:
the new image

convertValue

public static java.lang.Object convertValue(java.lang.Object obj,
                                            java.lang.Class type)
Convert a value to a specified type

Parameters:
obj -
type -
Returns:
teh value or null

getUserDirectory

public static java.io.File getUserDirectory(java.lang.String path)
Get a directory under the user.home. The directory will be created if it is not already available

Parameters:
path - the sub path or null for the home directory itself
Returns:
the file object for teh directory

slashify

public static java.lang.String slashify(java.lang.String path,
                                        boolean isDirectory)
Taken from java.io.File in JDK 1.4

Parameters:
path - The path to be corrected
isDirectory - Does the path lead to a directory?
Returns:
The corrected path String