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.chameleon.layers;
028:
029: import javax.microedition.lcdui.*;
030: import com.sun.midp.chameleon.skins.InputModeSkin;
031:
032: /**
033: * The InputModeLayer is a very simple overlay that displays to
034: * the user the notion of the "current" input mode. The layer is
035: * not interactive and is only visible when a text component is
036: * currently selected.
037: */
038: public class InputModeLayer extends PopupLayer {
039:
040: /** A variable holding the current display mode label */
041: protected String mode;
042:
043: /** The width in pixels (using the default font) of the mode name */
044: protected int stringWidth;
045:
046: protected int stringHeight;
047:
048: protected int[] anchor;
049:
050: public InputModeLayer() {
051: super ();
052: setBackground(InputModeSkin.IMAGE_BG, InputModeSkin.COLOR_BG);
053: this .supportsInput = false;
054: anchor = new int[2];
055: stringHeight = InputModeSkin.FONT.getHeight();
056: }
057:
058: /**
059: * Set the text to be displayed which represents the display name of
060: * the currently selected input mode
061: *
062: * @param mode the display name of the currently selected input mode
063: */
064: public void setDisplayMode(String mode) {
065: if (this .mode != mode) {
066: this .mode = mode;
067: stringWidth = InputModeSkin.FONT.stringWidth(mode);
068: updateLocation();
069: }
070: }
071:
072: /**
073: * Get the text to be displayed which represents the display name of
074: * the currently selected input mode
075: *
076: * @return mode the display name of the currently selected input mode
077: */
078: public String getDisplayMode() {
079: return mode;
080: }
081:
082: public void setAnchor(int anchorX, int anchorY, int itemH,
083: int spaceBelow) {
084: anchor[X] = anchorX;
085: anchor[Y] = anchorY;
086: if (spaceBelow < stringHeight) {
087: anchor[Y] -= stringHeight;
088: } else {
089: anchor[Y] += itemH;
090: }
091: updateLocation();
092: }
093:
094: public void paintBody(Graphics g) {
095: if (mode != null) {
096: g.setFont(InputModeSkin.FONT);
097: g.setColor(InputModeSkin.COLOR_FG);
098: g.drawString(mode, InputModeSkin.MARGIN, 0, Graphics.LEFT
099: | Graphics.TOP);
100: }
101: g.setColor(InputModeSkin.COLOR_BDR);
102: g.drawRect(0, 0, bounds[W] - 1, bounds[H] - 1);
103: g.setColor(InputModeSkin.COLOR_FG);
104: }
105:
106: protected void updateLocation() {
107: if (owner != null) {
108: owner.relocateLayer(this , anchor[X] - stringWidth
109: - InputModeSkin.MARGIN * 2, anchor[Y], stringWidth
110: + InputModeSkin.MARGIN * 2, stringHeight);
111: }
112: }
113: }
|