//----------------------------------------------------------------------------
// COMPONENT NAME: LPEX Editor
//
// All Rights Reserved.
//
// DESCRIPTION:
// ComposeAction - sample user-defined action (compose)
//----------------------------------------------------------------------------
package com.ibm.lpex.samples;
import com.ibm.lpex.core.LpexAction;
import com.ibm.lpex.core.LpexCommand;
import com.ibm.lpex.core.LpexView;
/**
* Sample action <b>compose</b> - enter special characters.
* Use this action to enter into the document special characters that are
* not found on your default keyboard. For example, enter a acute (á)
* by typing a compose sequence consisting of a and apostrophe ('), or the
* plus/minus sign (±) by typing + and -.
*
* <p>Here is the ComposeAction
* <a href="doc-files/ComposeAction.java.html">source code</a>.</p>
*
* <p>To run this sample:
* <ul>
* <li>Define the action via an editor preference page, where available, or
* from the editor command line:
* <pre>set actionClass.compose com.ibm.lpex.samples.ComposeAction</pre></li>
* <li>Run it from the editor command line:
* <pre>action compose</pre>
* or associate it with a key:
* <pre>set keyAction.a-f1 compose</pre></li>
* </ul></p>
* See the <a href="doc-files/ComposeAction.java.html">source code</a> for the
* supported compose sequences. To see these characters in the document, you
* may need a Unicode font installed on your system.
*
* @see com.ibm.lpex.samples.TestUserProfile
* @see com.ibm.lpex.samples All the samples
*/
public class ComposeAction implements LpexAction
{
// The special characters supported and their compose sequences.
private static String[] _compose =
{
// character compose sequence
// ========= ================
"\u00c1", "A'", // Á A acute A + APOSTROPHE (')
"\u00e1", "a'", // á a acute a + APOSTROPHE (')
"\u00c5", "A*", // Å A angstrom A + ASTERISK (*)
"\u00e5", "a*", // å a angstrom a + ASTERISK (*)
"\u00c2", "A^", // Â A circumflex A + CARET (^)
"\u00e2", "a^", // â a circumflex a + CARET (^)
"\u00c0", "A`", // À A grave A + ACCENT GRAVE (`)
"\u00e0", "a`", // à a grave a + ACCENT GRAVE (`)
"\u00c3", "A~", // Ã A tilde A + TILDE (~)
"\u00e3", "a~", // ã a tilde a + TILDE (~)
"\u00c4", "A\"", // Ä A umlaut A + QUOTATION MARK (")
"\u00e4", "a\"", // ä a umlaut a + QUOTATION MARK (")
"\u0102", "A&", // A breve A + AMPERSAND (&)
"\u0103", "a&", // a breve a + AMPERSAND (&)
"\u00c6", "AE", // Æ AE diphthong A + E
"\u00e6", "ae", // æ ae diphthong a + e
"\u00a6", "/ ", // ¦ broken bar SLASH (/) + SPACE
"\u00c7", "C,", // Ç C cedilla C + COMMA (,)
"\u00e7", "c,", // ç c cedilla c + COMMA (,)
"\u00b8", ",,", // ¸ cedilla COMMA (,) + COMMA (,)
"\u00b7", "^.", // · center dot CARET (^) + PERIOD (.)
"\u00a9", "CO", // © Copyright sign C + O, or
"\u00a9", "co", // c + o, or
"\u00a9", "C0", // C + 0, or
"\u00a9", "c0", // c + 0
"\u00b0", "^0", // ° degree CARET (^) + 0
"\u00f7", ":-", // ÷ division COLON (:) + MINUS (-)
"\u00c9", "E'", // É E acute E + APOSTROPHE (')
"\u00e9", "e'", // é e acute e + APOSTROPHE (')
"\u00ca", "E^", // Ê E circumflex E + CARET(^)
"\u00ea", "e^", // ê e circumflex e + CARET (^)
"\u00c8", "E`", // È E grave E + ACCENT GRAVE (`)
"\u00e8", "e`", // è e grave e + ACCENT GRAVE (`)
"\u00cb", "E\"", // Ë E umlaut E + QUOTATION MARK (")
"\u00eb", "e\"", // ë e umlaut e + QUOTATION MARK (")
"\u2014", "--", // em dash MINUS (-) + MINUS (-)
"\u00f0", "d-", // ð edh Latin small d + MINUS (-)
"\u00d0", "D-", // Ð edh Latin capital D + MINUS (-)
"\u00aa", "a_", // ª feminine ordinal a + UNDERSCORE (_), or
"\u00aa", "A_", // A + UNDERSCORE (_)
"\u00ad", "-=", // hyphen MINUS (-) + EQUAL SIGN (=)
"\u00cd", "I'", // Í I acute I + APOSTROPHE (')
"\u00ed", "i'", // í i acute i + APOSTROPHE (')
"\u00ce", "I^", // Î I circumflex I + CARET (^)
"\u00ee", "i^", // î i circumflex i + CARET (^)
"\u00cc", "I`", // Ì I grave I + ACCENT GRAVE (`)
"\u00ec", "i`", // ì i grave i + ACCENT GRAVE (`)
"\u00cf", "I\"", // Ï I umlaut I + QUOTATION MARK (")
"\u00ef", "i\"", // ï i umlaut i + QUOTATION MARK (")
"\u00a1", "!!", // ¡ inverted exclamation EXCLAMATION POINT (!) + EXCLAMATION POINT (!)
"\u00bf", "??", // ¿ inverted question mark QUESTION MARK (?) + QUESTION MARK (?)
"\u00ab", "<<", // « left angle quotes LESS THAN SIGN (<) + LESS THAN SIGN (<)
"\u00ba", "O_", // º masculine ordinal O + UNDERSCORE (_), or
"\u00ba", "o_", // o + UNDERSCORE (_)
"\u00b5", "/u", // µ micro sign SLASH (/) + u
"\u00d7", "xx", // × multiply sign x + x, or
"\u00d7", "XX", // X + X
"\u00d1", "N~", // Ñ N tilde N + TILDE (~)
"\u00f1", "n~", // ñ n tilde n + TILDE (~)
"\u00ac", "-]", // ¬ not sign MINUS (-) + CLOSING BRACKET (])
"\u2260", "/=", // not equal SLASH (/) + EQUAL SIGN (=)
"\u00d3", "O'", // Ó O acute O + APOSTROPHE (')
"\u00f3", "o'", // ó o acute o + APOSTROPHE (')
"\u00d4", "O^", // Ô O circumflex O + CARET (^)
"\u00f4", "o^", // ô o circumflex o + CARET (^)
"\u00d2", "O`", // Ò O grave O + ACCENT GRAVE (`)
"\u00f2", "o`", // ò o grave o + ACCENT GRAVE (`)
"\u00d8", "O/", // Ø O slash O + SLASH (/)
"\u00f8", "o/", // ø o slash o + SLASH (/)
"\u00d5", "O~", // Õ O tilde O + TILDE (~)
"\u00f5", "o~", // õ o tilde o + TILDE (~)
"\u00d6", "O\"", // Ö O umlaut O + QUOTATION MARK (")
"\u00f6", "o\"", // ö o umlaut o + QUOTATION MARK (")
"\u00af", "^-", // ¯ overline CARET (^) + MINUS (-)
"\u00b6", "!p", // ¶ paragraph symbol EXCLAMATION POINT (!) + p
"\u00b1", "+-", // ± plus-minus sign PLUS (+) + MINUS (-), or
"\u00b1", "-+", // MINUS (-) + PLUS (+)
"\u00ae", "RO", // ® Registered sign R + O, or
"\u00ae", "ro", // r + o, or
"\u00ae", "R0", // R + 0, or
"\u00ae", "r0", // r + 0
"\u00bb", ">>", // » right angle quotes GREATER THAN SIGN (>) + GREATER THAN SIGN (>)
"\u015e", "S,", // S cedilla S + COMMA (,)
"\u015f", "s,", // s cedilla s + COMMA (,)
"\u00a7", "so", // § section sign s + o
"\u00df", "ss", // ß sharp s German small s + s
"\u0162", "T,", // T cedilla T + COMMA (,)
"\u0163", "t,", // t cedilla t + COMMA (,)
"\u00fe", "p-", // þ thorn Latin small p + MINUS (-)
"\u00de", "P-", // Þ thorn Latin capital P + MINUS (-)
"\u00da", "U'", // Ú U acute U + APOSTROPHE (')
"\u00fa", "u'", // ú u acute u + APOSTROPHE (')
"\u00db", "U^", // Û U circumflex U + CARET (^)
"\u00fb", "u^", // û u circumflex u + CARET (^)
"\u00d9", "U`", // Ù U grave U + ACCENT GRAVE (`)
"\u00f9", "u`", // ù u grave u + ACCENT GRAVE (`)
"\u00dc", "U\"", // Ü U umlaut U + QUOTATION MARK (")
"\u00fc", "u\"", // ü u Umlaut u + QUOTATION MARK (")
"\u00dd", "Y'", // Ý Y acute Y + APOSTROPHE (')
"\u00fd", "y'", // ý y acute y + APOSTROPHE (')
"\u00ff", "y\"", // ÿ y umlaut y + QUOTATION MARK (")
"\u00a4", "XO", // ¤ currency sign X + O, or
"\u00a4", "xo", // x + o, or
"\u00a4", "X0", // X + 0, or
"\u00a4", "x0", // x + 0
"\u00a2", "c|", // ¢ cent c + VERTICAL LINE (|), or
"\u00a2", "c/", // c + SLASH (/), or
"\u00a2", "C|", // C + VERTICAL LINE (|), or
"\u00a2", "C/", // C + SLASH (/)
"\u20ac", "C=", // Euro sign C + EQUAL SIGN (=), or
"\u20ac", "c=", // c + EQUAL SIGN (=), or
"\u20ac", "C-", // C + MINUS (-), or
"\u20ac", "c-", // c + MINUS (-)
"\u00a3", "L=", // £ Pound sign L + EQUAL SIGN (=), or
"\u00a3", "l=", // l + EQUAL SIGN (=), or
"\u00a3", "L-", // L + MINUS (-), or
"\u00a3", "l-", // l + MINUS (-)
"\u00a5", "Y=", // ¥ Yen sign Y + EQUAL SIGN (=), or
"\u00a5", "y=", // y + EQUAL SIGN (=), or
"\u00a5", "Y-", // Y + MINUS (-), or
"\u00a5", "y-", // y + MINUS (-)
"\u00b9", "^1", // ¹ 1 superscript CARET (^) + 1
"\u00b2", "^2", // ² 2 superscript CARET (^) + 2
"\u00b3", "^3", // ³ 3 superscript CARET (^) + 3
"\u00bd", "12", // ½ one half fraction 1 + 2
"\u00bc", "14", // ¼ one quarter fraction 1 + 4
"\u00be", "34" // ¾ 3 quarters fraction 3 + 4
};
/**
* Command to compose a special character from regular ones.
* Also used by {@link TestUserProfile}.
*/
public static LpexCommand composeCommand = new LpexCommand() {
public boolean doCommand(LpexView lpexView, String parameters) {
for (int i = 1; i < _compose.length; i += 2)
{
if (_compose[i].equals(parameters))
{
// clear any previous error message we might have issued
if ("Cannot compose character.".equals(lpexView.query("messageText")))
{
lpexView.doDefaultCommand("set messageText");
}
return lpexView.doCommand((lpexView.queryOn("insertMode")? "insertText " : "replaceText ")
+ _compose[i-1]);
}
}
lpexView.doDefaultCommand("set messageText Cannot compose character.");
return false;
}
};
/**
* Compose action that can be used when the <b>compose</b> command has been
* already defined in that view. Used by {@link TestUserProfile}.
*/
public static LpexAction composeAction = new LpexAction() {
public void doAction(LpexView lpexView) {
lpexView.doDefaultCommand("input \"Compose:\" \"compose \"");
}
public boolean available(LpexView lpexView) {
return lpexView.currentElement() != 0 && !lpexView.queryOn("readonly");
}
};
/**
* Runs the action.
* Prompts the user for the compose sequence, then enters the special character
* into the document. Uses the <b>input</b> default editor command, and the
* <b>compose</b> command defined in here.
*/
public void doAction(LpexView lpexView)
{
// ensure command to handle composition is defined in the view this action runs
lpexView.defineCommand("compose", composeCommand);
// prompt user for the composition characters, insert result
lpexView.doDefaultCommand("input \"Compose:\" \"compose \"");
}
/**
* Returns the availability of this action.
* The action can be run in any visible, writable document view.
*/
public boolean available(LpexView lpexView)
{
return lpexView.currentElement() != 0 && !lpexView.queryOn("readonly");
}
}