de.frame4j
Class AskAlert

java.lang.Object
  extended by de.frame4j.util.App
      extended by de.frame4j.AskAlert
All Implemented Interfaces:
AttrSettable, TextHelper.MessageComponents, UIInfo, ActionListener, EventListener, DynamicMBean

@MinDoc(copyright="Copyright 2004, 2009  A. Weinert",
        author="Albrecht Weinert",
        version="V.51",
        lastModified="21.05.2010",
        lastModifiedBy="A. Weinert",
        usage="start as Java application (-? for help)",
        purpose="report or question on Window with timeout")
public class AskAlert
extends App

Report and / or question with timeout.

This application shows alarm, error or status reports, to be acknowledged, on a window or asks a question. The timeout to acknowledge or respond as well as the default answer are settable.
The window shown is simply structured (from top to bottom):

Window layout and content, the number of buttons (0..3) and else can be freely customised via parameters and options. Hints by
    java AskAlert -help

Besides a variety of settings the level of verbosity determines, what is logged: By starting the application AskAlert the window is made visible and it is now waited for a limited time for a user reaction. This time until answering or pressing a button is settable in 1/10s units in the range 5 to 90000 seconds.

Timeout or user reaction ends this application. The event is signalled via the exit code:

Value Meaning
>5 problems The application had startup proplems; the window was not shown.
5 cancel Cancel button / middle button
4 closed window was explicitly closed (by X or icon menu).
3 time out No response, waiting time over *1).
1 no No button / right button
0 yes Yes button / left button

Remark *1): The return code for time-out is freely settable by options. Among other possibilities, this simplifies the interpretation of time-out as default yes in a batch script.

This application can be used for report and control tasks in batch scripts (.bat instead of @Echo and @Pause).
Example:
  java AskAlert "Onwards with WWW server update" -v "Stop and cancel" -wa -wp
  if ERRORLEVEL 1 goto :ende


Additional function:
Started without any parameter, this application provides some information about version and copyright of the Frame4J installation it is part of (see also here).
When possible (accessible) the main manifest entries are displayed from Frame4J's main .jar-file, namely "frame4j.jar", that should be an installed extension in directory ...jre\lib\ext. Therefore AskAlert is the start application of the .jar file frame4j.jar. By
  java -jar frame4j.jar or by double clicking the .jar file this application AskAlert is started in this info mode. Exit codes 0, 5 (buttons), 4 (close) as well as 3 (time-out) are returned also in this mode.


Hints:

Execution / command line parameters containing blanks, quotes or asterisks must be quoted ("" at least on Windows).

To this application AskAlert (source) belongs (as integral part) a .properties file named AskAlert.properties. It's part of the documentation.


© Copyright 2004, 2008   Albrecht Weinert

Version:
51 (21.05.2010
Author:
Albrecht Weinert
See Also:
de.frame4j, App, de.frame4j.graf, AskDialog

Field Summary
protected  Color bg
          Dialouege's background colour..
 String cancel
          Middle Cancel-button, text.
 String cancelKey
          Middle Cancel-button, key.
 String lower
          The question / text below the buttons.
 String no
          Right No button, text.
 String noKey
          Right No button, key.
 int timeOutCode
          Return code for timeout.
 String upper
          The report / text above buttons.
 boolean upperMonospaced
          Font of upper text non proportional.
protected  int waitMax
          Maximal wait time in tenth (1/10) of seconds.
 String yes
          Left Yes-button, text.
 String yesKey
          Left Yes-button, key.
 
Fields inherited from class de.frame4j.util.App
ano, appBase, appIO, appStartTime, args, bgColor, err, fullClassName, help, icon, INIT_ERROR, jmxRemoteNote, JOB_DONE_OK, log, LOG_OUT_ERROR, MAIN_THREAD_EXC, mainThread, myClass, myFrame, name, NO_PARS_ERROR, objectName, out, outMode, packName, prop, retCode, runFlag, shortClassName, title, verbose, verbosity
 
Fields inherited from interface de.frame4j.net.AttrSettable
ILLEGAL_TYPE, ILLEGAL_VALUE, NO_ATTRIBUTE, NO_KNOWN_ATTRIBUTE, NO_VALUE, OK
 
Constructor Summary
AskAlert()
           
 
Method Summary
 int doIt()
          AskAlert's working method.
static void main(String[] args)
          AskAlert's start method.
 void setBg(CharSequence bg)
          Set dialogoue's background colour.
 void setCancel(String cancel)
          Setter.
 void setCancelKey(String cancelKey)
          Setter.
 void setLower(String lower)
          Set the question / text below the buttons.
 void setNo(String no)
          Setter.
 void setNoKey(String noKey)
          Setter.
 void setUpper(String upper)
          Set the report / text above buttons.
 void setWaitMax(int waitMax)
          Set maximal wait time in tenth (1/10) of seconds.
 void setYes(String yes)
          Setter for yes.
 void setYesKey(String yesKey)
          Setter for yesKey.
 
Methods inherited from class de.frame4j.util.App
actionPerformed, allowNoPropertiesFile, clientOrder, condHelpLog, connect, errMeld, errMeld, errorExit, errorExit, errorExit, errorText, formMessage, formMessage, getAbout, getAboutText, getActTime, getAppLogger, getAppStartTime, getArgs, getAttribute, getAttributes, getAuthor, getCopyright, getDbLogger, getExecTimeMs, getExecTimeString, getHelp, getHelpText, getIcon, getLanguage, getLogHandler, getMBeanInfo, getMessageComponent, getMessageComponentsLength, getMyFrame, getName, getNameWithVersDate, getOutMode, getProp, getPurpose, getStartTime, getStateString, getTitle, getUsage, getVerbosity, getVerbosityString, getVersDate, getXMLinput, go, go, go, haveIcon, invoke, isDebug, isHelp, isHelpLog, isNormal, isRunFlag, isSilent, isTest, isVerbose, logVerbose, logVerbose, makeDbLogger, makeMenuBar, makeMenuBar, makeStatusTextEnd, makeStatusTextStart, messageFormat, normalExit, parsePartial, performeAction, postDeregister, postRegister, preRegister, queueAction, registerAsMBean, setAboutText, setAttribute, setAttribute, setAttribute, setAttributes, setAuthor, setBgColor, setCodePages, setCopyright, setHelp, setJmxRemoteNote, setLogOut2, setName, setOutMode, setOutMode, setPurpose, setTitle, setUsage, setVerbose, setVerbose, setVerbosity, setVerbosity, setVerbosityString, setVersDate, stop, threeLineEndMsg, toString, twoLineEndMsg, twoLineStartMsg, valueLang, valueLang, wakeMainThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

waitMax

protected int waitMax
Maximal wait time in tenth (1/10) of seconds.

Range: 50..900000 (5s .. ~1d)
Default: 120 (12s)


upper

public String upper
The report / text above buttons.

default: null (no report text)


upperMonospaced

public boolean upperMonospaced
Font of upper text non proportional.

Usually better to display file or directory names.

Default: false (hence proportional)


lower

public String lower
The question / text below the buttons.

default: null (no question text)


yes

public String yes
Left Yes-button, text.

Default: null
Null or empty means no left button, if also the language key (yesKey) is empty.


yesKey

public String yesKey
Left Yes-button, key.

If the text yes value is null or empty, this is the key to a (inter) nationalised, user language dependent value fetched by (@link App#valueLang(CharSequence) valueLang(yesKey)}.

Default: "yes"

See Also:
AppLangMap

cancel

public String cancel
Middle Cancel-button, text.

Same proceeding as with yes and yesKey.
Default: null


cancelKey

public String cancelKey
Middle Cancel-button, key.

Same proceeding as with yes and yesKey.
Default: "abort"


no

public String no
Right No button, text.

Same proceeding as with yes and yesKey.


noKey

public String noKey
Right No button, key.

Same proceeding as with yes and yesKey.


bg

protected Color bg
Dialouege's background colour..

See Also:
setBg(CharSequence)

timeOutCode

public int timeOutCode
Return code for timeout.

If ended by time-out due to no user response the standard return code is 3 (time-out).

This can be arbitrarily changed by this property. So any default response can be substituted for time-out, usually simplifying the return code evaluation in scripts significantly (especially when blessed with Window's rich "IF ERRORLEVEL" syntax.

Default: 3

Constructor Detail

AskAlert

public AskAlert()
Method Detail

setWaitMax

public void setWaitMax(int waitMax)
Set maximal wait time in tenth (1/10) of seconds.

Range: 50..900000 (5s .. ~1d)
Default: 120 (12s)


setUpper

public void setUpper(String upper)
Set the report / text above buttons.


setLower

public void setLower(String lower)
Set the question / text below the buttons.


setYes

public void setYes(String yes)
Setter for yes.

Sets yes according to the parameter and leaves yesKey unchanged.

See Also:
setYesKey(String)

setYesKey

public void setYesKey(String yesKey)
Setter for yesKey.

Sets yesKey according to parameter and leaves yes (text) unchanged.

Parameters:
yesKey - the key, will be stripped from surrounding white space; (then) empty acts like null
See Also:
setYes(String)

setCancel

public void setCancel(String cancel)
Setter.

Same proceeding as with yes and yesKey.


setCancelKey

public void setCancelKey(String cancelKey)
Setter.

Same proceeding as with yes and yesKey.


setNo

public void setNo(String no)
Setter.

Same proceeding as with yes and yesKey.


setNoKey

public void setNoKey(String noKey)
Setter.

Same proceeding as with yes and yesKey.


setBg

public void setBg(CharSequence bg)
Set dialogoue's background colour.

If set non empty the value is used as the dialogue windows background colour before making it visible.

It is tried to interpret bg as colour by GrafHelper.getColor(CharSequence). If this is not possible null is set or left.

Default: null (standard background colour of runtime)


main

public static void main(String[] args)
AskAlert's start method.

Execute: java AskAlert [options] [report [question [title]]] The application returns with exit codes signalling the user's response; see above.

Parameters:
args - command line parameters

doIt

public int doIt()
AskAlert's working method.

Specified by:
doIt in class App
Returns:
0..5: exit code; > 5: start or parameter error
See Also:
Prop, App.go(String[], boolean), App.go(String[], String, boolean, CharSequence), App.mainThread