adavid.util
Class Bundle

java.lang.Object
  |
  +--adavid.util.Bundle
Direct Known Subclasses:
ResourceLoader

public class Bundle
extends java.lang.Object


Field Summary
static java.lang.String COLOR_DEF
           
static java.lang.String FALSE
           
static java.lang.String ICON_DEF
          resource extensions to define how to initialise variables
static java.lang.String ICON_EXT
           
static java.lang.String MNEMO_DEF
           
static java.lang.String NAME_DEF
           
static java.lang.String PATH_NAME
           
static java.lang.String STATE_DEF
           
static java.lang.String TEAR_DEF
           
static java.awt.MediaTracker tracker
           
static java.lang.String TRUE
           
 
Constructor Summary
Bundle(java.lang.Class target)
          constructor with a class
Bundle(java.util.ResourceBundle bundle)
          constructor: takes the resource bundle in argument
Bundle(java.lang.String bundleName, java.lang.Class target)
          constructor: takes the name of the resource bundle, and tries to locate the resource bundle
 
Method Summary
 boolean getBoolResource(java.lang.String def, java.lang.String defValue)
          returns the bool resource definition
 java.awt.Button getButton(java.lang.String name)
          returns the Button corresponding the given name, use resource definitions to initialize the button
 java.awt.Checkbox getCheckbox(java.lang.String name)
          same as getButton, for a check box
 java.awt.CheckboxMenuItem getCheckboxMenuItem(java.lang.String name)
          same as getMenuItem, but for a check box menu item
static java.awt.Color getColor(java.lang.String name, java.awt.Color defaultColor)
          returns a color by its name or by its rgb definition in hexadecimal or null in case of failure
 java.awt.Color getColorResource(java.lang.String def, java.awt.Color defaultValue)
          returns the color resource definition
 java.awt.Image getImage(java.lang.String def)
          return the image with the name definition def
 java.awt.Label getLabel(java.lang.String name)
          returns a label with its name declared in the resource file
 java.awt.Menu getMenu(java.lang.String name)
          same as getMenuItem, but for a menu
 java.awt.MenuItem getMenuItem(java.lang.String name)
          returns a configured menu item with the corresponding name definition
 java.lang.String getNameResource(java.lang.String def, java.lang.String defaultValue)
          convenient function: load a name definition
 java.awt.PopupMenu getPopupMenu(java.lang.String name)
          return the corresponding popup menu
 java.lang.String getResource(java.lang.String def)
          returns a resource definition or null is not found characters '_' are converted to '.'
 java.lang.String getResource(java.lang.String def, java.lang.String defaultResource)
          returns a resource definition or default name is not found characters '_' are converted to '.'
 java.lang.String getString(java.lang.String name, java.lang.String value)
          returns the corresponding string resource with the name definition for the string (the resource name) and its current value
static java.lang.String iconName(java.lang.String def)
          returns the corresponding default name of a resource for an icon
 void init(java.lang.Class dataClass)
          initialization for pure static classes, no instance required
 void init(java.lang.Object data, java.lang.Object actionHandler)
          the initialization function called if data is not null => the class can be used only to load resources in an easy way, with no initialization
 java.awt.Image loadImage(java.lang.String name)
           
static java.awt.Image loadImageFrom(java.lang.String completeName)
          easy solution: return new Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(iconPath+name)); but java crashes sometimes: Uncaught error fetching image: java.lang.NullPointerException at java.net.URLConnection.guessContentTypeFromStream(URLConnection.java) at sun.net.www.URLConnection.getContentType(URLConnection.java:126) at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:98) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:259) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:151) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:127) so we do the job in another way: load the data and create an image from the data
static java.lang.String pathName(java.lang.Class c)
          give the package-superclass name as path
static java.lang.String pathName(java.lang.String longName)
          give the package-superclass name as path
static java.lang.String pathName(java.lang.String longName, char separator, boolean replace)
          give the path of longName, with separator as separator, replace '.' by '/' instead of File.separatorChar if the flag is set, and the path is then of the form "" or "name/name/"
 void setActionHandler(java.lang.Object actionHandler)
          change the action handler
 void setIconPath(java.lang.String path)
          change the icon path
static void setLocation(java.awt.Frame parent, java.awt.Window win)
          position a window relative to its parent frame
static void setLocation(java.awt.Window win)
          sets the location of a window so that it appears in the middle of the screen
 void setMenuItem(java.awt.MenuItem item, java.lang.String name, java.lang.String def)
          configure a menu item with the resource definitions
static java.lang.String shortName(java.lang.Class c)
          give the short name of a class
static java.lang.String shortName(java.lang.String longName)
          give the short name of a class name
static java.lang.String shortName(java.lang.String longName, char separator)
          give the short name with separator as separator
static void show(java.awt.Frame parent, java.awt.Window win)
          show a window relative to its parent frame
static void show(java.awt.Window win)
          set location and make a window visible
static boolean waitImage(java.awt.Image img)
          wait until an image is ready to use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_DEF

public static final java.lang.String ICON_DEF
resource extensions to define how to initialise variables

NAME_DEF

public static final java.lang.String NAME_DEF

TEAR_DEF

public static final java.lang.String TEAR_DEF

ICON_EXT

public static java.lang.String ICON_EXT

TRUE

public static final java.lang.String TRUE

FALSE

public static final java.lang.String FALSE

MNEMO_DEF

public static final java.lang.String MNEMO_DEF

STATE_DEF

public static final java.lang.String STATE_DEF

COLOR_DEF

public static final java.lang.String COLOR_DEF

PATH_NAME

public static final java.lang.String PATH_NAME

tracker

public static final java.awt.MediaTracker tracker
Constructor Detail

Bundle

public Bundle(java.lang.Class target)
constructor with a class

Bundle

public Bundle(java.lang.String bundleName,
              java.lang.Class target)
constructor: takes the name of the resource bundle, and tries to locate the resource bundle

Bundle

public Bundle(java.util.ResourceBundle bundle)
constructor: takes the resource bundle in argument
Method Detail

setActionHandler

public void setActionHandler(java.lang.Object actionHandler)
change the action handler

getResource

public java.lang.String getResource(java.lang.String def)
returns a resource definition or null is not found characters '_' are converted to '.'

getResource

public java.lang.String getResource(java.lang.String def,
                                    java.lang.String defaultResource)
returns a resource definition or default name is not found characters '_' are converted to '.'

getNameResource

public java.lang.String getNameResource(java.lang.String def,
                                        java.lang.String defaultValue)
convenient function: load a name definition

getColorResource

public java.awt.Color getColorResource(java.lang.String def,
                                       java.awt.Color defaultValue)
returns the color resource definition

getBoolResource

public boolean getBoolResource(java.lang.String def,
                               java.lang.String defValue)
returns the bool resource definition

shortName

public static java.lang.String shortName(java.lang.Class c)
give the short name of a class

shortName

public static java.lang.String shortName(java.lang.String longName)
give the short name of a class name

shortName

public static java.lang.String shortName(java.lang.String longName,
                                         char separator)
give the short name with separator as separator

pathName

public static java.lang.String pathName(java.lang.Class c)
give the package-superclass name as path

pathName

public static java.lang.String pathName(java.lang.String longName)
give the package-superclass name as path

pathName

public static java.lang.String pathName(java.lang.String longName,
                                        char separator,
                                        boolean replace)
give the path of longName, with separator as separator, replace '.' by '/' instead of File.separatorChar if the flag is set, and the path is then of the form "" or "name/name/"

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String value)
returns the corresponding string resource with the name definition for the string (the resource name) and its current value

getColor

public static java.awt.Color getColor(java.lang.String name,
                                      java.awt.Color defaultColor)
returns a color by its name or by its rgb definition in hexadecimal or null in case of failure

setLocation

public static void setLocation(java.awt.Window win)
sets the location of a window so that it appears in the middle of the screen

show

public static void show(java.awt.Window win)
set location and make a window visible

setLocation

public static void setLocation(java.awt.Frame parent,
                               java.awt.Window win)
position a window relative to its parent frame

show

public static void show(java.awt.Frame parent,
                        java.awt.Window win)
show a window relative to its parent frame

getImage

public java.awt.Image getImage(java.lang.String def)
return the image with the name definition def

setIconPath

public void setIconPath(java.lang.String path)
change the icon path

iconName

public static java.lang.String iconName(java.lang.String def)
returns the corresponding default name of a resource for an icon

loadImageFrom

public static java.awt.Image loadImageFrom(java.lang.String completeName)
                                    throws java.io.IOException
easy solution: return new Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(iconPath+name)); but java crashes sometimes: Uncaught error fetching image: java.lang.NullPointerException at java.net.URLConnection.guessContentTypeFromStream(URLConnection.java) at sun.net.www.URLConnection.getContentType(URLConnection.java:126) at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:98) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:259) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:151) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:127) so we do the job in another way: load the data and create an image from the data

loadImage

public java.awt.Image loadImage(java.lang.String name)

waitImage

public static boolean waitImage(java.awt.Image img)
wait until an image is ready to use

getButton

public java.awt.Button getButton(java.lang.String name)
returns the Button corresponding the given name, use resource definitions to initialize the button

getCheckbox

public java.awt.Checkbox getCheckbox(java.lang.String name)
same as getButton, for a check box

setMenuItem

public void setMenuItem(java.awt.MenuItem item,
                        java.lang.String name,
                        java.lang.String def)
configure a menu item with the resource definitions

getMenuItem

public java.awt.MenuItem getMenuItem(java.lang.String name)
returns a configured menu item with the corresponding name definition

getCheckboxMenuItem

public java.awt.CheckboxMenuItem getCheckboxMenuItem(java.lang.String name)
same as getMenuItem, but for a check box menu item

getMenu

public java.awt.Menu getMenu(java.lang.String name)
same as getMenuItem, but for a menu

getLabel

public java.awt.Label getLabel(java.lang.String name)
returns a label with its name declared in the resource file

getPopupMenu

public java.awt.PopupMenu getPopupMenu(java.lang.String name)
return the corresponding popup menu

init

public void init(java.lang.Object data,
                 java.lang.Object actionHandler)
the initialization function called if data is not null => the class can be used only to load resources in an easy way, with no initialization

init

public void init(java.lang.Class dataClass)
initialization for pure static classes, no instance required