public class AccentAction
extends javax.swing.AbstractAction
Enable accents in JTextComponent textWithAccents by calling
AccentAction.allowAccents(textWithAccents);
To use the value in textWithAccents the client should first call
AccentActions.cleanup(textWithAccents)to remove excess ZWSP markers.
The user enters accents in textWithAccents by typing control-prefix and then
a letter to be entered with an accent. For instance, o-accent-acute is
entered by typing control-apostrophe and the letter o (not control-o).
The possible prefixes and the accent-able characters for each are in file
distsrc/assets/AccentsAvailable.html
. The prefixes are also listed
in enum Prefix, below.
A client may display AccentsAvailable.html as part of an application window. First construct a viewable pane with
String instructionsLocator
= "asset:com.physpics.tools/AccentsAvailable.html";
HelpPane instructions = new HelpPane(instructionsLocator);
instructions.setBackground(Color.yellow);
JScrollPane scrollInstructions = new JScrollPane(instructions);
and then add scrollInstructions
to the window.
The instructions are online as
physpics.com/Java/tools/assets/com.physpics.tools/AccentsAvailable.html
.
When the prefix is typed, the actual insertion in the text is the code for a standalone instance of the character (accent, caron, ring-above, whatever) followed by a ZWSP (Zero-Width-Space, code ) as a flag character. Then when the suffix character is typed the prefix and ZWSP are replaced. If a non-suffix is typed the ZWSP is retained and the suffix character is inserted as itself.
Objects of this class are the actions placed in the Action maps for the prefix and suffix keys. Other operations are performed with static functions.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NL |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e) |
static void |
allowAccents(javax.swing.text.JTextComponent text)
Adapt the text component so accented characters can be typed.
|
static void |
cleanup(javax.swing.text.JTextComponent text)
Remove spurious zero-width spaces (ZWSP) that may remain from
unusual user actions.
|
public static final java.lang.String NL
public static void allowAccents(javax.swing.text.JTextComponent text)
text
- The JTextComponent to be adapted.public static void cleanup(javax.swing.text.JTextComponent text)
text
- The JTextComponent to be cleaned.public void actionPerformed(java.awt.event.ActionEvent e)