📄 texteditor.java
字号:
/* * @(#)TextEditor.java 1.17 01/08/09 * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */package javax.microedition.lcdui;import com.sun.midp.lcdui.Resource;/** * The TextEditor class is an common shared editor for all * instances of TextField and * is used by to enter and edit text. * */class TextEditor extends TextBox implements CommandListener { /** Flag indicating a key was typed */ private boolean wasTyped; // = false /** The first char being edited */ private int firstChar; // = 0 /** The number of characters saved prior to editing */ private int savedNumChars; /** The buffer holding the content prior to editing */ private char[] savedBuffer; /** The Form holding the TextField prior to editing */ private Screen returnScreen; /** The TextField this TextEditor is editing */ private TextField textField; /** The command to go "back" from the editor */ private final static Command BACK = new Command(Resource.getString("Back"), Command.CANCEL, 1); /** The command to accept the changes made in the editor */ private final static Command SAVE = new Command(Resource.getString("Save"), Command.OK, 1); /** * Construct a new TextEditor */ TextEditor() { super(null, null, -1, -1); super.addCommandImpl(BACK); super.addCommandImpl(SAVE); super.setCommandListener(this); } /** * Initialize the text handler * * @param constraints The constraints to set on the text handler * @param maxSize The maximum size of the text handler * @param text The initial text to set in the text handler */ void initializeTextBasic(int constraints, int maxSize, String text) { // We override our super class and make this a no-op // because we simply grab the TextBasic from the TextField // we are editing } /** * This method is used to determine if that screen instance * is used as an edit screen for the screen passed in. * * @param d The Displayable to check * @return boolean True if the Displayable is the source of this editor */ boolean isEditScreen(Displayable d) { return d == returnScreen; } /** * Run this text editor * * @param returnScreen The Screen to return to when editing is completed * @param textField The TextField this editor is editing * @param keycode The first keycode entered which caused the edit to occur * @param wasTyped A flag indicating the key was typed */ void invoke(Screen returnScreen, TextField textField, int keycode, boolean wasTyped) { firstChar = keycode; this.wasTyped = wasTyped; this.returnScreen = returnScreen; this.textField = textField; this.sD = textField.sD; setChild(sD.policy.height); setTitle(textField.getLabel()); savedNumChars = sD.numChars; if (savedBuffer == null || savedBuffer.length < savedNumChars) { savedBuffer = new char[savedNumChars]; } System.arraycopy(sD.buffer, 0, savedBuffer, 0, savedNumChars); returnScreen.currentDisplay.setCurrent(this); } /** * Handle a command action (such as 'save' or 'back) * * @param x The Command to handle * @param s The Displayable generating the Command action * (the current one on the Display) */ public void commandAction(Command x, Displayable s) { Form form = null; TextField field = null; ItemStateListener isl = null; synchronized (Display.LCDUILock) { if (x == SAVE) { // it is possible that during the editing // textField for which the edits were done // was removed from the form and possible // added to a different form field = textField; field.saveHeight(sD.policy.height); form = (Form)field.getOwner(); isl = form.getItemStateListener(); } else if (x == BACK) { sD.setChars(savedBuffer, 0, savedNumChars); } (s.currentDisplay).setCurrent(returnScreen); } // SYNC NOTE: We make sure we notify the ItemStateChangedListener // outside of our lock if (form != null) { form.itemStateChanged(field, isl); } } /** * Get the client object of this editor * * @return Object Returns the TextField associated with this editor */ Object getClientObject() { return textField; } /** * Notify this TextEditor it is being shown on the display * * @param d The Display showing this TextEditor */ void showNotifyImpl(Display d) { super.showNotifyImpl(d); if (firstChar != 0) { if (wasTyped) { keyTypedImpl((char)firstChar); } else { keyPressedImpl(firstChar); } firstChar = 0; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -