|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectccs.utils.MsgHelper
public class MsgHelper
Helps your app provide I18N'ed messages and other strings. Your app should contain terse key strings with no embedded whitespace; we use a convention similar to the unix convention for error constants. The first letter or bigraph of the string indicates which type of message this is:
The remaining prefix letters are reserved for future expansion. The main identifier which follows the prefix should start with a capital; in this way there is no ambiguity between a two-letter prefix and a main identifier that happens to start with an "M" or a "G".
For applications which will (or might) run as InternalTasks inside CPCC or as plug-ins inside CPC, you have an extra responsibility: since many such apps may be running simultaneously inside the same message namespaces, you must disambiguate these strings by prepending at least your usual base package name to the names. You must further ensure that there are no name clashes within this disambiguated namespace which you control; you might care to do this by extending the prepended package names, but this is up to you.
For example, if your app's main class is org.myhouse.myapp.App
and it runs as an InternalTask, then one of its error message defns might be
org.myhouse.EBroken=Application has died horribly, please reboot
.
Within these disambiguated namespaces, all prefix letters are available for you to use as you like, although it's best to stick to the standard scheme unless you have a good reason not to.
As a special case, the fully-qualified name of any throwable, used as a key string (without any prefix letter/s), should be a human-readable description of that throwable.
Field Summary | |
---|---|
static int |
ARGH
Constant for msgBox: display the severe, no-entry icon. |
static int |
GUESS
Constant for msgBox: use your initiative to work out the right icon. |
static int |
LOSE
Constant for msgBox: display the ordinary, exclamation mark icon. |
Constructor Summary | |
---|---|
MsgHelper()
|
Method Summary | |
---|---|
static void |
addBundle(java.lang.String bundleName)
add a bundle to be used by translateMessage methods. |
static boolean |
hasTranslation(java.lang.String msg)
Whether an internationalised version of the message exists. |
static void |
msgBox(java.awt.Component frame,
java.lang.Throwable th)
Display a message box announcing the supplied throwable, and always guessing the correct icon. |
static void |
msgBox(java.awt.Component frame,
java.lang.Throwable th,
int iconCode)
Display a message box announcing the supplied throwable. |
static java.lang.String |
multixlat(java.lang.String msg)
Translate a message which contains multiple space-separated I18N keys - it tokenises the string and calls xlat for each. |
static java.lang.String |
translate(java.lang.String msg)
Alias for translateMessage(String) . |
static java.lang.String |
translateMessage(java.lang.String msg)
Returns an internationalised version of the supplied message. |
static java.lang.String |
translateMessage(java.lang.Throwable th)
returns an internationalised version of this throwable's message string. |
static java.lang.String |
translateName(java.lang.Throwable th)
returns a helpful, internationalised description of what this throwable is about. |
static java.lang.String |
xlat(java.lang.String msg)
Even briefer alias for translateMessage . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LOSE
public static final int GUESS
public static final int ARGH
Constructor Detail |
---|
public MsgHelper()
Method Detail |
---|
public static java.lang.String translateName(java.lang.Throwable th)
public static java.lang.String translateMessage(java.lang.Throwable th)
EBig
for file too big). Kernel codes begin with
EK
, not just E
. If the message is null, it changes it
to ENotTelling
and goes from there. If there is no such key in the message
bundle, it returns the original message, with a warning.
public static java.lang.String translateMessage(java.lang.String msg)
ENotTelling
and goes from
there. If there is no such key in the message bundle, it returns the
original message, optionally with a warning.
public static boolean hasTranslation(java.lang.String msg)
public static java.lang.String xlat(java.lang.String msg)
translateMessage
.
public static java.lang.String multixlat(java.lang.String msg)
xlat
for each. This
is heavier and slower than the alternatives. It won't work well if
the debugging property ccs.utils.showBrokenI18N
is
set.
public static java.lang.String translate(java.lang.String msg)
translateMessage(String)
. Use the alias for brevity
wherever this does not cause loss of clarity.
public static void addBundle(java.lang.String bundleName)
translateMessage
methods.
bundleName
- The bundle base name. The bundle for the default locale
(if present) will be selected. Bundle naming / resolution follows the same rules
as for classes: for details, see java.util.ResourceBundle
.public static void msgBox(java.awt.Component frame, java.lang.Throwable th)
frame
- The frame (if any) the message box should depend from.th
- The Throwable to present.public static void msgBox(java.awt.Component frame, java.lang.Throwable th, int iconCode)
frame
- The frame (if any) the message box should depend from.th
- The Throwable to present.iconCode
- which icon to display - a constant from this class.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |