EditLine.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
* Copyright 1996 Active Software Inc.
*
* @version @(#)EditLine.java 1.13 97/06/18
*/
/**
* An EditLine allows for the editing of text within some other component.
*/
{
public static final int REPAINT = 87000;
public static final int APPLY = 87001;
public static final int CANCEL = 87002;
public static final int BACKSPACE_KEY = 8;
public static final int TAB_KEY = 9;
public static final int RETURN_KEY = 10;
public static final int ESCAPE_KEY = 27;
public static final int DELETE_KEY = 127;
private FontMetrics metrics;
private int x, y, w, h;
private int initWidth;
private boolean justStartedEditing;
private boolean cancelApply;
private boolean applying;
private int scrollPos;
private int cursorPos;
private int selectPos;
private boolean dragging;
private boolean cursorState;
private boolean paintCursor;
private Thread cursorThread;
private long cursorTime;
private static final long CURSOR_DELAY = 500;
private static final int XOFF = 2;
private static final int MINWIDTH = 12;
static final int XPAD = 15;
static final int YPAD = 4;
selectPos = 0;
scrollPos = 0;
justStartedEditing = true;
cacheDims();
this.initWidth = w;
comp.requestFocus();
cursorThread.setDaemon(true);
cursorState = true;
}
scrollPos = 0;
cacheText();
}
return text;
}
repaint();
}
public String getSelection() {
}
cacheDims();
}
else
return font;
}
}
public Color getForeground() {
return comp.getForeground();
else
return fg;
}
}
public Color getBackground() {
return comp.getBackground();
else
return bg;
}
public boolean applyChanges() {
applying = true;
cancelApply = false;
applying = false;
return !cancelApply;
} else {
return true;
}
}
public void cancelApply() {
cancelApply = true;
}
private void cacheText() {
scrollPos = 0;
}
private void cacheDims() {
}
private Rectangle cacheHorizontal() {
int prevLeft = x;
int prevRight = x+w;
if (w > (d.width-x)) {
x = d.width - w;
if (x < 0) {
x = 0;
w = d.width;
}
}
int left = x;
int right = x+w;
else
return null;
}
private void cacheVertical() {
if (h > (d.height-y)) {
y = d.height - h;
if (y < 0) {
y = 0;
h = d.height;
}
}
}
justStartedEditing = false;
return false;
} else {
justStartedEditing = false;
}
}
boolean retval = false;
case Event.MOUSE_DOWN:
retval = true;
}
break;
case Event.MOUSE_DRAG:
if (dragging) {
retval = true;
}
break;
if (dragging) {
retval = true;
}
break;
case Event.LOST_FOCUS:
// Don't allow the focus to get away!
comp.requestFocus();
// Intentional lack of break
retval = true;
break;
case Event.MOUSE_MOVE:
retval = true;
break;
case Event.KEY_ACTION:
// intentional lack of break
case Event.KEY_RELEASE:
case Event.KEY_ACTION_RELEASE:
retval = true;
break;
}
return retval;
}
comp.requestFocus();
switch (clickCount) {
case 2:
break;
case 3:
selectLine();
break;
default:
dragging = true;
break;
}
}
}
dragging = false;
resetTimer();
}
if (f == null)
return;
} else {
}
}
boolean cacheText = false;
boolean repaint = false;
if (key == RETURN_KEY) {
applyChanges();
return;
} else if (key == ESCAPE_KEY) {
return;
}
switch (key) {
if (cursorPos != 0) {
setCursorPos(0);
repaint = true;
}
break;
repaint = true;
}
break;
if (cursorPos != 0) {
repaint = true;
}
break;
repaint = true;
}
break;
case BACKSPACE_KEY:
if (deleteSelection()) {
cacheText = true;
} else if (cursorPos != 0) {
cursorPos--;
selectPos--;
cacheText = true;
}
break;
case DELETE_KEY:
if (deleteSelection()) {
cacheText = true;
cacheText = true;
}
break;
default:
cursorPos++;
selectPos++;
cacheText = true;
}
break;
}
if (cacheText)
cacheText();
else if (repaint)
repaint();
}
private boolean deleteSelection() {
int start = selectStart();
return true;
} else {
return false;
}
}
private void selectWord(int evtX) {
repaint();
}
private int getWordStart(int pos) {
int i;
boolean hitChar = false;
break;
hitChar = true;
}
return i+1;
}
private int getWordEnd(int pos) {
int i;
boolean hitSpace = false;
break;
hitSpace = true;
}
return i;
}
private void selectLine() {
selectPos = 0;
repaint();
}
c = c.getParent();
}
return frame;
}
return new Point(x, y);
}
return new Dimension(w, h);
}
private void setCursorX(int evtX) {
repaint();
}
private void setCursorPos(int pos) {
resetTimer();
}
private void adjustSelection(int evtX) {
repaint();
}
}
private boolean makeVisible(int pos) {
return true;
if (width >= (w-3)) {
return true;
}
}
return false;
}
private synchronized void resetTimer() {
cursorState = true;
notify();
}
private int getCursorPos(int evtX) {
}
return lower;
return lower;
else
return upper;
}
else
}
if (offset <= 0)
return scrollPos;
}
return lower;
return lower;
else
return upper;
}
else
}
}
private int selectStart() {
}
private int selectEnd() {
}
public void repaint() {
}
// If "rect" is non-null, then the component is expected to repaint
// the area define by the rectangle. The coordinates
// in the rectangle
// are relative to the component's coordinate space.
}
g = g.create();
g.translate(x, y);
if (paintCursor) {
if (cursorState)
g.setColor(getForeground());
else
g.setColor(getBackground());
int xoff =
paintCursor = false;
return;
}
g.setColor(getBackground());
} else {
}
g.setColor(getForeground());
yoff -= 1;
int start = selectStart();
if (cursorState) {
cursorPos));
}
} else {
// Draw first unselected segment
}
// Draw selected segment
if (cursorState)
g.setColor(getForeground());
// Draw the cursor
if (!cursorState)
g.setColor(getForeground());
// Draw last unselected segment
}
}
}
public synchronized void run() {
long waitTime = CURSOR_DELAY;
try {
}
catch (InterruptedException ex) {
}
comp.requestFocus();
if (dragging) {
waitTime = 0;
} else {
if (diff >= CURSOR_DELAY) {
paintCursor = true;
repaint();
} else {
}
}
}
}
public synchronized void destroy() {
cursorThread = null;
notify();
}
protected void finalize() {
destroy();
}
}