package
gve.calc.formula;
The AWT-minded CursorLabel class is adapted more to our purposes here: we implement a few interfaces and when the cursor enters or leaves, we invalidate ourself.
public
class
CursorPosLabel
extends
CursorLabel
implements
HasCursorPos
,
HasBaseline
{
public
CursorPosLabel
(String str) {
super
(str); }
public
CursorPosLabel
(String str,
int
pos) {
super
(str,pos); }
public
void
activate() {}
public
void
deactivate() {
super
.setCursorPos(-1); invalidate(); }
public
int
getBaseline() {
//if (getFont() == null) return 5;
return
getFontMetrics(getFont()).getAscent(); }
public
void
setCursorPos(
int
pos) {
if
(pos >= 0) {
if
(
super
.getCursorPos() < 0) invalidate();
super
.setCursorPos(pos);
return
; } invalidate();
switch
(pos) {
default
:
case
Somewhere_LEFT:
super
.setCursorPos(0);
return
;
case
Somewhere_RIGHT:
super
.setCursorPos(getText().length());
return
;
case
Somewhere_NOWHERE:
super
.setCursorPos(-1);
return
; } } }