net.curre.prefcount.util
Class Utilities

java.lang.Object
  extended by net.curre.prefcount.util.Utilities

public class Utilities
extends java.lang.Object

Object of this class represents a set of common utilities for prefcount.

Created date: Apr 7, 2007

Author:
Yevgeny Nyden

Nested Class Summary
static class Utilities.FieldType
          Enumeration tha represents a field type.
static class Utilities.PlatformType
          Enumeration tha represents a platform/os type.
 
Field Summary
static java.util.Calendar lastTime
          Helper object to be used in the printTime() method.
 
Constructor Summary
Utilities()
           
 
Method Summary
static java.awt.Color createDarkerColor(java.awt.Color color, int decrease)
          Creates a new color that is darker than the passed color according to the passed int parameter.
static javax.swing.ImageIcon createImage(java.lang.String fileName)
          Creates a gif image for the given file name (image file is expected to be in the images/ directory relative to the net.curre.prefcount.App class).
static java.awt.Dimension determineSizeOfString(java.awt.Graphics2D g2, java.lang.String str)
          Computes the size of the passed String.
static void displayMessageInFrame(java.lang.String messageKey)
          Opens a new frame and displayes a message in it (given its resource key).
static java.lang.String getFirstLetterFromField(javax.swing.JTextField field)
          Returns capitalized first letter from the passed text field or null if the text field is empty.
static Utilities.PlatformType getPlatformType()
          Determines the platform/os type we are running on.
static boolean isMacOs()
          Returns true if we are running on Mac OS; false otehrwise.
static int parseIntFromTextField(javax.swing.JTextField field)
          Gets and parses text from the given text field.
static void printAvailableFonts()
          Displays available fonts in a frame.
static void printLookAndFeels()
          Prints available looks and feels.
static void printTime(java.lang.String msg)
          This method is used for debugging purposes to print timestamps and the elapsed time since the last call to this method.
static java.lang.String underlineLetter(java.lang.String str, int ind)
          Underlines a letter in the given string at the given position; note, that the string is converted to html.
static boolean validateTextField(javax.swing.JTextField field, Utilities.FieldType type)
          Validates if the passed component value is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastTime

public static java.util.Calendar lastTime
Helper object to be used in the printTime() method.

Constructor Detail

Utilities

public Utilities()
Method Detail

validateTextField

public static boolean validateTextField(javax.swing.JTextField field,
                                        Utilities.FieldType type)
Validates if the passed component value is valid.

Parameters:
field - Input field, which value to validate.
type - Type of the value to check (i.e. Utilities.TYPE_INTEGER).
Returns:
true If the component value is valid; false otherwise.

getFirstLetterFromField

public static java.lang.String getFirstLetterFromField(javax.swing.JTextField field)
Returns capitalized first letter from the passed text field or null if the text field is empty.

Parameters:
field - Text field to read.
Returns:
Capitalized first letter from the passed text field or null if the text field is empty.

parseIntFromTextField

public static int parseIntFromTextField(javax.swing.JTextField field)
Gets and parses text from the given text field. If the text field is null or contains an empty string or white space only, 0 if returned.

Parameters:
field - Text field to parse.
Returns:
Parsed integer.
Throws:
java.lang.NumberFormatException - If text field contains an invalid integer.

determineSizeOfString

public static java.awt.Dimension determineSizeOfString(java.awt.Graphics2D g2,
                                                       java.lang.String str)
Computes the size of the passed String.

Parameters:
g2 - Graphics object to use.
str - String to be measured.
Returns:
The size of the passed string as a Dimension object.

createImage

public static javax.swing.ImageIcon createImage(java.lang.String fileName)
Creates a gif image for the given file name (image file is expected to be in the images/ directory relative to the net.curre.prefcount.App class).

Parameters:
fileName - File name without extention.
Returns:
The created ImageIcon object.

underlineLetter

public static java.lang.String underlineLetter(java.lang.String str,
                                               int ind)
Underlines a letter in the given string at the given position; note, that the string is converted to html.

Parameters:
str - String to underline.
ind - Letter index, which to underline.
Returns:
A string with underlined letter at the given position.

createDarkerColor

public static java.awt.Color createDarkerColor(java.awt.Color color,
                                               int decrease)
Creates a new color that is darker than the passed color according to the passed int parameter.

Parameters:
color - Model color.
decrease - Value to be subtracted from the RGB chanels of the model color.
Returns:
New darker color.

displayMessageInFrame

public static void displayMessageInFrame(java.lang.String messageKey)
Opens a new frame and displayes a message in it (given its resource key).

Parameters:
messageKey - Message key.

printTime

public static void printTime(java.lang.String msg)
This method is used for debugging purposes to print timestamps and the elapsed time since the last call to this method.

Parameters:
msg - Message to add to the print statement.

printLookAndFeels

public static void printLookAndFeels()
Prints available looks and feels.


printAvailableFonts

public static void printAvailableFonts()
Displays available fonts in a frame.


getPlatformType

public static Utilities.PlatformType getPlatformType()
Determines the platform/os type we are running on.

Returns:
A PlatformType enumeration that represents the platform/os.

isMacOs

public static boolean isMacOs()
Returns true if we are running on Mac OS; false otehrwise.

Returns:
True if we are on Mac OS; false otherwise.


Copyright © 2008. All Rights Reserved.