001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.lcdui;
028:
029: import javax.microedition.lcdui.Graphics;
030:
031: import com.sun.midp.chameleon.skins.TextFieldSkin;
032:
033: /**
034: * Class that represents the character index, and (x,y) position
035: * of a text cursor in a TextField
036: */
037: public class TextCursor {
038:
039: /** x, y coordinates */
040: public int x, y;
041:
042: /** width, height */
043: public int width, height;
044:
045: /** array index */
046: public int index;
047:
048: /** drawing options: can be one of the PAINT_* variables in Text.java */
049: public int option;
050:
051: /** whether or not this cursor is visible */
052: public boolean visible;
053:
054: /** preferred x location when traversing vertically */
055: public int preferredX;
056:
057: /** yOffset to modify paint by for calculating h value */
058: public int yOffset;
059:
060: /**
061: * Construct a new text cursor with the given array index
062: *
063: * @param index index into the array that this cursor will be drawn
064: */
065: public TextCursor(int index) {
066: this .index = index;
067: option = Text.PAINT_USE_CURSOR_INDEX;
068: visible = true;
069: }
070:
071: /**
072: * Copy a TextCursor object
073: *
074: * @param tc TextCursor object to copy
075: */
076: public TextCursor(TextCursor tc) {
077: this (0);
078:
079: if (tc != null) {
080: this .x = tc.x;
081: this .y = tc.y;
082: this .option = tc.option;
083: this .index = tc.index;
084: this .visible = tc.visible;
085: this .preferredX = tc.preferredX;
086: this .yOffset = tc.yOffset;
087: }
088: }
089:
090: /**
091: * Paint this cursor in the given graphics context
092: *
093: * @param g the graphics context to paint in
094: */
095: public void paint(Graphics g) {
096: // Stroke should already be SOLID
097: g.setColor(TextFieldSkin.COLOR_FG);
098: g.fillRect(x, y - yOffset - height + 2,
099: TextFieldSkin.WIDTH_CARET, height - 3);
100: g.setColor(0); // back to default black
101: }
102: }
|