com.lightdev.app
Class Application


java.lang.Object

  extended by com.lightdev.app.Application

Direct Known Subclasses:
MenuApplication

public abstract class Application
extends Object

Base class for applications

An application typically has some basic functionality such as logging and online help. This abstract base class implements such basic functionality so that application objects can extend from it.

In particular, it implements

See the various methods for comments about how the implementation works by default

To create a new application based on the Light Development Application package

  1. create a new java source code file "TestApp.java" with the following content, place it into a new directory in the file system and compile it:

     package com.lightdev.app.test;
    
     import com.lightdev.app.DefaultApplication;
     import javax.swing.UIManager;
    
     public class TestApp extends DefaultApplication {
       public TestApp() {
         super();
       }
       public static void main(String[] args) {
         try {
           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         }
         catch(Exception e) {
           e.printStackTrace();
         }
         new TestApp();
       }
     }
     

  2. make a copy of file "DefaultApplication.properties" from the Light Development application package, rename it to "TestApp.properties" and place it into the folder where the file "TestApp.class" resides in.

That's it, you are ready to build your new application from the newly created directory and files.

Please note: You need Application.jar and jhall.jar (the JavaHelp extension) in the classpath of your new application so that all classes are present.

Licensing this material as open source does not necessarily mean to give it away for nothing. I always like to hear about your comments and even without comments a short e-mail about you using this software makes my day and lets me continue to work on open source projects (I certainly promise to respect your privacy).

Thank you!

Version:
2, February 12, 2004
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the GNU General Public License, for details see file in the distribution package of this software as well as any licensing notes inside this documentation

Field Summary
static String actionSuffix
          name constant for action commands in the resource file
static String APP_HELP_NAME
           
static String imageSuffix
          name constant for indicating image resources in the resource file
static String JAVA_HELP_EXT
           
static String labelSuffix
          name constant for labels in the resource file
protected static Logger logger
          logger for this Application
static String RB_KEY_ABOUT_APP_DIALOG_TITLE
          resource bundle key to identify the string to use for the title of this application's about dialog
static String RB_KEY_LOG_APP_CAN_NOT_EXIT
          resource bundle key to identify the string to use to log that the application can not end
static String RB_KEY_LOG_APP_STARTED
          resource bundle key to identify the string to use to log that the application has started
static String RB_KEY_LOG_APP_TERMINATED
          resource bundle key to identify the string to use to log that the application has ended
static String RESOURCE_NOT_FOUND
          string to display when a resource could not be loaded
protected  ResourceBundle resources
          resource bundle
static String selectedIconSuffix
          name constant for selected icon names in the resource file
static String toolTipSuffix
          name constant for tool tip strings in the resource file
static String URL_SEPARATOR
           
 
Constructor Summary
Application()
          constructor with default parameters
Application(Level level, String logDir)
          constructor Looks for a resource bundle which is named similar to the class name inside the package of this class
Application(OutputStream logStream, Level level, String logDir)
          constructor Looks for a resource bundle which is named similar to the class name inside the package of this class
 
Method Summary
 void about()
          Called by default by class AboutAppAction.
 void addAction(Class uiClass, String cmd, Action action)
          add an action to this DynamicResource
protected  boolean canExit()
          called by default by method exitApplication.
 void exitApplication()
          Called by default by class ExitAction.
 Action getAction(String cmd)
          get an action from the commands table
protected  String getAppName()
          get the name of this application
 ResourceBundle getBundle()
          get the ResourceBundle of this application
static HelpBroker getHelpBroker()
          get the HelpBroker of this application
 Icon getIconForCommand(ResourceBundle resources, Class uiClass, String cmd)
          get an icon from the application's resource bundle For some reason I am not able to get a resource when the class from which getResource is called is in a different package, which is why this method requires any class that resides in the package having ui resoruces
 Icon getIconForName(Class uiClass, String name)
          get an icon from the application's resource bundle For some reason I am not able to get a resource when the class from which getResource is called is in a different package, which is why this method requires any class that resides in the package having ui resoruces
 URL getResource(Class c, String key)
          get the location of a resource.
 String getResourceString(String nm)
          get a string from the resources file
protected  void initActions()
          initialize the command table of the resource menu with this application's actions (here to override by subclasses)
static void log(String msg, Class source, Level level)
          log an information message
static void logStackTrace(Exception ex, Class source)
          log an exception by writing the stack trace to the log as a warning
protected  void setLogging(OutputStream stream, Level level, String dir)
          set logging
protected  void setLogLevel(Level level)
          set the log level
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resources


protected ResourceBundle resources
resource bundle


logger


protected static Logger logger
logger for this Application


RESOURCE_NOT_FOUND


public static final String RESOURCE_NOT_FOUND
string to display when a resource could not be loaded

See Also:
Constant Field Values

RB_KEY_LOG_APP_STARTED


public static final String RB_KEY_LOG_APP_STARTED
resource bundle key to identify the string to use to log that the application has started

See Also:
Constant Field Values

RB_KEY_LOG_APP_TERMINATED


public static final String RB_KEY_LOG_APP_TERMINATED
resource bundle key to identify the string to use to log that the application has ended

See Also:
Constant Field Values

RB_KEY_LOG_APP_CAN_NOT_EXIT


public static final String RB_KEY_LOG_APP_CAN_NOT_EXIT
resource bundle key to identify the string to use to log that the application can not end

See Also:
Constant Field Values

RB_KEY_ABOUT_APP_DIALOG_TITLE


public static final String RB_KEY_ABOUT_APP_DIALOG_TITLE
resource bundle key to identify the string to use for the title of this application's about dialog

See Also:
Constant Field Values

labelSuffix


public static final String labelSuffix
name constant for labels in the resource file

See Also:
Constant Field Values

actionSuffix


public static final String actionSuffix
name constant for action commands in the resource file

See Also:
Constant Field Values

imageSuffix


public static final String imageSuffix
name constant for indicating image resources in the resource file

See Also:
Constant Field Values

toolTipSuffix


public static final String toolTipSuffix
name constant for tool tip strings in the resource file

See Also:
Constant Field Values

selectedIconSuffix


public static final String selectedIconSuffix
name constant for selected icon names in the resource file

See Also:
Constant Field Values

APP_HELP_NAME


public static final String APP_HELP_NAME
See Also:
Constant Field Values

JAVA_HELP_EXT


public static final String JAVA_HELP_EXT
See Also:
Constant Field Values

URL_SEPARATOR


public static final String URL_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

Application


public Application(OutputStream logStream,

                   Level level,

                   String logDir)
constructor

Looks for a resource bundle which is named similar to the class name inside the package of this class

Parameters:
logStream - OutputStream the stream to log to
level - Level log level to recognize in logs
logDir - String a directory to log to (e.g. ".appName" + File.separator + "logs")

Application


public Application(Level level,

                   String logDir)
constructor

Looks for a resource bundle which is named similar to the class name inside the package of this class

Parameters:
level - Level log level to recognize in logs
logDir - String a directory to log to (e.g. ".appName" + File.separator + "logs")

Application


public Application()
constructor with default parameters

Method Detail

getAppName


protected String getAppName()
get the name of this application

Returns:
the name of this application

setLogging


protected void setLogging(OutputStream stream,

                          Level level,

                          String dir)
set logging

Parameters:
stream - OutputStream a stream to log to
level - Level the log level to use
dir - String the directory to log to

setLogLevel


protected void setLogLevel(Level level)
set the log level

Parameters:
level - Level the level to log

log


public static void log(String msg,

                       Class source,

                       Level level)
log an information message

Parameters:
msg - the message string
source - Class the class that logged this message
level - Level the log level the message has

logStackTrace


public static void logStackTrace(Exception ex,

                                 Class source)
log an exception by writing the stack trace to the log as a warning

Parameters:
ex - the exception to log the stack trace for
source - Class the class the error came from

initActions


protected void initActions()
initialize the command table of the resource menu with this application's actions (here to override by subclasses)


canExit


protected boolean canExit()
called by default by method exitApplication. Override this method to customize exit hnadling, i.e. if a certain condition causes the application to temporarily being unable to terminte, this method should return false

Returns:
boolean ture, if the application can terminate at the time this method is called

about


public void about()
Called by default by class AboutAppAction. Override this method to implement custom about handling.


getHelpBroker


public static HelpBroker getHelpBroker()
get the HelpBroker of this application

Returns:
the HelpBroker

exitApplication


public void exitApplication()
Called by default by class ExitAction. Override this method to implement custom exit handling.


getBundle


public ResourceBundle getBundle()
get the ResourceBundle of this application

Returns:
the ResourceBundle

getAction


public Action getAction(String cmd)
get an action from the commands table

Parameters:
cmd - the name of the action the get
Returns:
the action found for the given name

getResourceString


public String getResourceString(String nm)
get a string from the resources file

Parameters:
resources - the ResourceBundle to get the string from
nm - the key of the string
Returns:
the string for the given key or null if not found

addAction


public void addAction(Class uiClass,

                      String cmd,

                      Action action)
add an action to this DynamicResource

Parameters:
uiClass - a class residing in the package having access to ui resources
resources - the ResourceBundle to get resources such as icons and strings from
cmd - the internal identifier for the action
action - the action to associate with cmd

getIconForCommand


public Icon getIconForCommand(ResourceBundle resources,

                              Class uiClass,

                              String cmd)
get an icon from the application's resource bundle

For some reason I am not able to get a resource when the class from which getResource is called is in a different package, which is why this method requires any class that resides in the package having ui resoruces

Parameters:
uiClass - Class a class that resides in the package having ui resources
cmd - String the action command
Returns:
Icon the icon or null

getIconForName


public Icon getIconForName(Class uiClass,

                           String name)
get an icon from the application's resource bundle

For some reason I am not able to get a resource when the class from which getResource is called is in a different package, which is why this method requires any class that resides in the package having ui resoruces

Parameters:
uiClass - Class a class that resides in the package having ui resources
cmd - String the action command
Returns:
Icon the icon or null

getResource


public URL getResource(Class c,

                       String key)
get the location of a resource.

Parameters:
c - Class any ui class for finding the package
key - the key of the resource in the resource file
Returns:
the resource location as a URL

Copyright (c) 2004, 2005 Ulrich Hilger