|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdatabionics.Application
public class Application
Base class for applications. Initializes Log4J, loads *.conf and messages, parses the command line, and offers much more...
Subclasses have to adhere to the following conventions:
app
of their own class typeprotected static MyApp app;
getInstance()
returning this
variablepublic static MyApp getInstance() { return app; }
this.name = "myapp"; this.banner = "MyApp 1.0 (written by me)"; this.msgfile = "databionics.myapp/Messages"; // _en_US.properties
src/databionics/myapp/Messages_en_US.properties
must exist,
though it can be emptyMyApp.getInstance().getMessage("KEY")
options.add("a", "augment", false, false, "augment data patterns with 1");
init()
to set the variable app
and to call super.init()
to pass the command line optionspublic void init(String[] args) { super.init(args); app = this; }
run()
method and will be executed in a Thread
public static void main(String[] args) { MyApp app = new MyApp(); app.init(args); app.start(); }
System.exit()
should never be called because it would also exit
the frontend, since programs are started in the same JVMthis.exit(1)
for errors and this.exit(0)
as the last command
in run()
instead} catch (IOException e) { log.error("error loading: " + e.getMessage()); this.exit(1); return; }
if (this.exitOnInterruption()) { return; }
87%
with log.info(...)
extends Application
this.sleep()
instead of Thread.currentThread().sleep()
if neccessaryextends GraphicalApplication
BaseMainFrame
and store it in the variable frame
in GraphicalApplication
this.frame = new MainFrame(); // MainFrame extends BaseMainFrame
windowClosing(WindowEvent e)
in the frame class
to close the corresponding application.public void windowClosing(WindowEvent e) { MyApp.getInstance().exit(0); }
sleepAndExit()
after showing the framethis.frame.show(); this.sleepAndExit();
Field Summary | |
---|---|
protected java.lang.String |
banner
long program name with version |
protected PropertyCommandLine |
cmd
interface to command line |
protected java.lang.String |
conf
name of config file |
protected boolean |
done
flag whether app is done, is set when calling the exit
method |
protected java.lang.String |
env
name of envorinment variable |
protected int |
exitCode
exit code of application, < 0 for not set, 0 for no error |
protected static java.lang.String |
home
value of environment variable |
protected static org.apache.log4j.Logger |
log
interface to log4j system |
protected java.util.ResourceBundle |
messages
localized messages |
protected java.lang.String |
msgfile
name of properties file with messages |
protected java.lang.String |
name
short program name |
protected java.text.NumberFormat |
nf
number format |
protected PropertyOptions |
options
interface option definition |
protected Project |
project
project holding files |
protected boolean |
standalone
flag whether app is run in stand alone mode from own main
method |
protected java.lang.Thread |
thread
corresponding thread |
protected java.lang.String |
workdir
current working directory |
Constructor Summary | |
---|---|
Application()
Standard constructor. |
|
Application(boolean standalone)
Constructor with flag for standalone mode. |
Method Summary | |
---|---|
void |
exit(int exitCode)
Really exit if run in standalone mode, otherwise only set done flag for frontend. |
boolean |
exitOnInterruption()
Exit application if current thread is interrupted |
java.lang.String |
getBanner()
Get long program name with version. |
static java.lang.String |
getColorGradient(java.lang.String name)
Get path to color gradient. |
static java.lang.String |
getColorPath()
Get path to color tables |
static java.lang.String |
getConfigPath()
Get path to configuration files |
int |
getExitCode()
Get exit code after app is done. |
static java.lang.String |
getHelpFile()
Get help file. |
static java.lang.String |
getHome()
Get value of environment variable |
static java.lang.String |
getLibPath()
Get path to *.jar files |
java.lang.String |
getMessage(java.lang.String key)
Get localized message from file defined in consructor. |
java.lang.String |
getName()
Get short program name. |
Project |
getProject()
Returns the current project holding filename of different types and optionally the data from the files. |
java.lang.Thread |
getThread()
|
java.lang.String |
getWorkDir()
Returns the current working directory. |
void |
init()
Init without command line parameters. |
void |
init(java.lang.String[] args)
Init Log4J logging system and parse command line. |
void |
interrupt()
Stop app thread |
boolean |
interrupted()
Check for interruption of current thread an reset interrupted flag |
boolean |
isDone()
Get flag whether app is done. |
static void |
main(java.lang.String[] args)
Main method, only for testing in this class |
protected void |
printHelp()
Print command line help and exit. |
protected void |
printVersion()
Print version information and exit |
void |
run()
Run method for Interface Runnable. |
void |
setProject(Project project)
Sets the current poject holding filename of different types and optionally the data from the files. |
void |
setStandAlone(boolean standalone)
Set flag whether app is run from main |
void |
setWorkDir(java.lang.String path)
Sets the curent working directory. |
void |
sleep(long ms)
Call sleep on current thread and handle interruptions |
java.lang.Thread |
start()
Start app thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static org.apache.log4j.Logger log
protected java.lang.Thread thread
protected static java.lang.String home
protected java.util.ResourceBundle messages
protected PropertyOptions options
protected PropertyCommandLine cmd
protected java.lang.String name
protected java.lang.String banner
protected java.lang.String msgfile
protected java.lang.String conf
protected java.lang.String env
protected boolean standalone
main
method
protected boolean done
exit
method
protected int exitCode
protected java.text.NumberFormat nf
protected Project project
protected java.lang.String workdir
Constructor Detail |
---|
public Application()
public Application(boolean standalone)
standalone
- flag whether app is run in stand alone mode from own main
methodMethod Detail |
---|
public java.lang.Thread getThread()
public static java.lang.String getHome()
public static java.lang.String getConfigPath()
public static java.lang.String getColorPath()
public static java.lang.String getColorGradient(java.lang.String name)
public static java.lang.String getLibPath()
public static java.lang.String getHelpFile()
public java.lang.String getMessage(java.lang.String key)
getInstance()
that
returns the instantiated class. Messages can then retrieved via
MyApp.getInstance().getMessage("MY_MSG_KEY")
.
...Messages_en_US.properties
public java.lang.String getName()
bin
.
public java.lang.String getBanner()
-v
is given of the help is displayed.
protected void printHelp()
protected void printVersion()
public void setStandAlone(boolean standalone)
standalone
- flag whether app is run in stand alone mode from own main
methodpublic boolean isDone()
exit
method.
public int getExitCode()
public Project getProject()
public void setProject(Project project)
project
- project to be setpublic java.lang.String getWorkDir()
public void setWorkDir(java.lang.String path)
path
- the working directorypublic void init(java.lang.String[] args)
public void init()
public void run()
run
in interface java.lang.Runnable
public boolean interrupted()
public boolean exitOnInterruption()
public void sleep(long ms)
public java.lang.Thread start()
public void interrupt()
public void exit(int exitCode)
exitCode
- exit code for System.exit()
in standalone mode.public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |