|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.lightdev.app.Application
public abstract class Application
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
a Logger for log messages and global error handling along with some common logging methods
a help broker for a JavaHelp help set
a ResourceMenu for dynamic component creation from a description resource and for caching of action objects
a ResourceBundle for internationalized UI components
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
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();
}
}
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!
| 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 |
|---|
protected ResourceBundle resources
protected static Logger logger
public static final String RESOURCE_NOT_FOUND
public static final String RB_KEY_LOG_APP_STARTED
public static final String RB_KEY_LOG_APP_TERMINATED
public static final String RB_KEY_LOG_APP_CAN_NOT_EXIT
public static final String RB_KEY_ABOUT_APP_DIALOG_TITLE
public static final String labelSuffix
public static final String actionSuffix
public static final String imageSuffix
public static final String toolTipSuffix
public static final String selectedIconSuffix
public static final String APP_HELP_NAME
public static final String JAVA_HELP_EXT
public static final String URL_SEPARATOR
| Constructor Detail |
|---|
public Application(OutputStream logStream,
Level level,
String logDir)
Looks for a resource bundle which is named similar to the class name inside the package of this class
logStream - OutputStream the stream to log tolevel - Level log level to recognize in logslogDir - String a directory to log to (e.g. ".appName" + File.separator + "logs")
public Application(Level level,
String logDir)
Looks for a resource bundle which is named similar to the class name inside the package of this class
level - Level log level to recognize in logslogDir - String a directory to log to (e.g. ".appName" + File.separator + "logs")public Application()
| Method Detail |
|---|
protected String getAppName()
protected void setLogging(OutputStream stream,
Level level,
String dir)
stream - OutputStream a stream to log tolevel - Level the log level to usedir - String the directory to log toprotected void setLogLevel(Level level)
level - Level the level to log
public static void log(String msg,
Class source,
Level level)
msg - the message stringsource - Class the class that logged this messagelevel - Level the log level the message has
public static void logStackTrace(Exception ex,
Class source)
ex - the exception to log the stack trace forsource - Class the class the error came fromprotected void initActions()
protected boolean canExit()
public void about()
public static HelpBroker getHelpBroker()
public void exitApplication()
public ResourceBundle getBundle()
public Action getAction(String cmd)
cmd - the name of the action the get
public String getResourceString(String nm)
resources - the ResourceBundle to get the string fromnm - the key of the string
public void addAction(Class uiClass,
String cmd,
Action action)
DynamicResource
uiClass - a class residing in the package having access to ui resourcesresources - the ResourceBundle to get resources such as icons and strings fromcmd - the internal identifier for the actionaction - the action to associate with cmd
public Icon getIconForCommand(ResourceBundle resources,
Class uiClass,
String cmd)
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
uiClass - Class a class that resides in the package having ui resourcescmd - String the action command
public Icon getIconForName(Class uiClass,
String name)
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
uiClass - Class a class that resides in the package having ui resourcescmd - String the action command
public URL getResource(Class c,
String key)
c - Class any ui class for finding the packagekey - the key of the resource in the resource file
|
Copyright (c) 2004, 2005 Ulrich Hilger | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||