java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Canvas
|
+--HexIntTextField
A light-weight component representing a text field which only accepts digits of its currently active number system, or six additional letters, in case of hexadecimal mode.
| Field Summary | |
static int |
BIN
|
private int |
caretPosition
|
private static int |
CHARWIDTH
|
static int |
DEC
|
private static int |
DIST
|
private Font |
font
|
private String[] |
fontnames
|
private static int |
FONTSIZE
|
static int |
HEX
|
private Vector |
listeners
|
private int |
mode
|
static int |
OCT
|
private StringBuffer |
shown
|
| Fields inherited from class java.awt.Canvas |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
HexIntTextField()
|
|
| Method Summary | |
private boolean |
accept(char c)
Tells whether a given character is allowed as input in the current mode of our HexIntTextField. |
void |
addActionListener(ActionListener l)
|
void |
fireActionEvent(String command)
Tells anyone interested in ActionEvents occuring on
this HexIntTextField, when an event took place. |
int |
getMode()
Provides the current mode of this HexIntTextField. |
private char |
getModifiedChar(char c)
Provide ability to re-interprete characters before inserting them into our HexIntTextField. |
String |
getText()
|
long |
getValue()
|
private void |
init()
|
void |
insertChar(char c)
Tries to insert a given character at the current caret position. |
void |
keyPressed(KeyEvent e)
Location of our main work. |
void |
keyReleased(KeyEvent e)
Without effect. |
void |
keyTyped(KeyEvent e)
Without effect. |
void |
moveEnd()
|
void |
moveHome()
|
void |
paint(Graphics g)
Paints this Canvas to appear as a text field! |
void |
removeActionListener(ActionListener l)
|
void |
removeChar(boolean forward)
Removes the character left or right beside the current caret position. |
void |
setMode(int m)
Sets the new mode for this HexIntTextField, ie
the base of the number system to be modelled by this text field. |
void |
setText(String text)
Sets the text for this HexIntTextField. |
void |
setValue(long value)
|
void |
stepCaret(boolean forward)
Moves the caret one step left of right. |
| Methods inherited from class java.awt.Canvas |
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private static final int FONTSIZE
private static final int CHARWIDTH
private static final int DIST
public static final int BIN
public static final int OCT
public static final int DEC
public static final int HEX
private StringBuffer shown
private int caretPosition
private Font font
private String[] fontnames
private Vector listeners
private int mode
| Constructor Detail |
public HexIntTextField()
| Method Detail |
private void init()
public String getText()
public void setText(String text)
throws IllegalArgumentException
HexIntTextField.
text - the new text for this HexIntTextField
IllegalArgumentException - if an invalid String
is given, where currently we do only accept
Strings encoding integers in binary,
octal, decimal, or hexadecimal representation,
see getMode(), with an optional
minus sign at the beginninggetMode()public long getValue()
public void setValue(long value)
public int getMode()
HexIntTextField.
HexIntTextField,
ie the base of the number system, but symbolic constants
are usedBIN,
OCT,
DEC,
HEX
public void setMode(int m)
throws IllegalArgumentException
HexIntTextField, ie
the base of the number system to be modelled by this text field.
m - the new mode for this HexIntTextField,
where symbolic constants should be used
IllegalArgumentException - if an unknown mode is given,
where known modes currently are
BIN, OCT, DEC, and HEXBIN,
OCT,
DEC,
HEXpublic void addActionListener(ActionListener l)
public void removeActionListener(ActionListener l)
public void fireActionEvent(String command)
ActionEvents occuring on
this HexIntTextField, when an event took place.
More specifically, calls actionPerformed for
the registered listeners.
command - describes the event that took placeActionListener.actionPerformed(ActionEvent)private char getModifiedChar(char c)
HexIntTextField.
c - the character to be re-interpreted occasionally
c in most cases,
currently only changes minore letters into capitalsprivate boolean accept(char c)
HexIntTextField.
true for them.
c - the character to be inserted into our field
c=='-', c in {'A',...,'F'}
and we are in HEX mode, or
c in {'0',...,MIN(mode, 10)-1}
public void insertChar(char c)
throws IllegalArgumentException
c - the character to be inserted at the caret position
IllegalArgumentException - if
getModifiedChar(char),
accept(char)public void stepCaret(boolean forward)
forward - moves the caret right, iff truepublic void removeChar(boolean forward)
forward==false the caret steps one backward.
forward - removes the character right of the caret, iff truepublic void moveHome()
public void moveEnd()
public void keyPressed(KeyEvent e)
keyPressed in interface KeyListenermoveEnd(),
moveHome(),
stepCaret(boolean),
removeChar(boolean),
fireActionEvent(String),
insertChar(char)public void keyTyped(KeyEvent e)
keyTyped in interface KeyListenerpublic void keyReleased(KeyEvent e)
keyReleased in interface KeyListenerpublic void paint(Graphics g)
Canvas to appear as a text field!
paint in class Canvas