⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screenlite.java

📁 类似于Windows上的Excel
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MC2 -- j2me spreadsheet * * Copyright (c) 2004-2006 Michael Zemljanukha (mixaz@mail.ru) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package com.wapindustrial.calc;//#ifndef NOGUIimport javax.microedition.lcdui.*;//#endifimport java.util.Vector;import java.util.Hashtable;/** * * @author  mzemlyan * @version * CommandListener interface to run functors with user input (forms) */public class ScreenLite extends FunctionModule//#ifndef NOGUIimplements CommandListener//#endif{    // it is a singleton pattern    public static final ScreenLite SCREENLITE = new ScreenLite();        public static final LispObject INPUT_FORM_CANCELLED = new LispObject();    //#ifndef NOGUI        private static final Vector menuBindings = new Vector(20);   // list of assigments, of MenuBinding class    private static final Vector keyBindings = new Vector(10);   // list of assigments, of Assigment class    private static final Vector commandBindings = new Vector(5);   // list of assigments, of Assigment class    private static final Vector goldBindings = new Vector(10);  // of Assigment class        private static String startPath;                        // current path in menu, root for ""        private static InputForm currentInputForm;    private static boolean isCancelled;             // if true after ExecuteAssigment() then user input was cancelled        private static List currentMenu;                // menu list    private static String currentMenuPath = "";     // root    private static Vector currentMenuList;    		// to return back to previous menu from submenu    private static int npreserved;        private static final Command cmdOK = new Command( "OK", Command.OK, 1 );    private static final Command cmdCancel = new Command( "Cancel", Command.BACK, 2 ); //#endif        private static final String _namesArray =     		            "\13bind-to-key" +            "\17bind-to-command" +            "\14bind-to-menu" +            "\06prompt" +            "\17prompt-preserve" +            "\10app-exit" +            "\11app-debug" +            "\12menu-start" +            "\14bind-to-gold" +            "\04bind" +            "\12input-form" +            "\17menu-input-form"//#ifdef POINTER            			+            "\17pointer-pressed" +            "\17coord-translate"//#endif                ;    private static final int NAME_BIND_TO_KEY = 0;    private static final int NAME_BIND_TO_COMMAND = NAME_BIND_TO_KEY + 11 + 1;    private static final int NAME_BIND_TO_MENU = NAME_BIND_TO_COMMAND + 15 + 1;    private static final int NAME_PROMPT = NAME_BIND_TO_MENU + 12 + 1;    private static final int NAME_PROMPT_PRESERVE = NAME_PROMPT + 6 + 1;    private static final int NAME_APP_EXIT = NAME_PROMPT_PRESERVE + 15 + 1;    private static final int NAME_APP_DEBUG = NAME_APP_EXIT + 8 + 1;    private static final int NAME_MENU_START = NAME_APP_DEBUG + 9 + 1;    private static final int NAME_BIND_TO_GOLD = NAME_MENU_START + 10 + 1;    private static final int NAME_BIND = NAME_BIND_TO_GOLD + 12 + 1;    private static final int NAME_INPUT_FORM = NAME_BIND + 4 + 1;    private static final int NAME_MENU_INPUT_FORM = NAME_INPUT_FORM + 10 + 1;        private static final int NAME_MENU_INPUT_FORM_NEXT = NAME_MENU_INPUT_FORM+16;//#ifdef POINTER        private static final int NAME_POINTER_PRESSED = NAME_MENU_INPUT_FORM_NEXT;    private static final int NAME_COORD_TRANSLATE = NAME_POINTER_PRESSED+16;    private static final int NAME_POINTER_NEXT = NAME_COORD_TRANSLATE+16;//#else//#    private static final int NAME_POINTER_NEXT = NAME_MENU_INPUT_FORM_NEXT;//#endif            public static final int INDEX_BIND_TO_KEY = 0;    public static final int INDEX_BIND_TO_COMMAND = 1;    public static final int INDEX_BIND_TO_MENU = 2;    public static final int INDEX_PROMPT = 3;    public static final int INDEX_PROMPT_PRESERVE = 4;    public static final int INDEX_APP_EXIT = 5;    public static final int INDEX_APP_DEBUG = 6;    public static final int INDEX_MENU_START = 7;    public static final int INDEX_BIND_TO_GOLD = 8;    public static final int INDEX_BIND = 9;    public static final int INDEX_INPUT_FORM = 10;    public static final int INDEX_MENU_INPUT_FORM = 11;        public static final int INDEX_MENU_INPUT_FORM_NEXT = 12;//#ifdef POINTER        public static final int INDEX_POINTER_PRESSED = INDEX_MENU_INPUT_FORM_NEXT;    public static final int INDEX_COORD_TRANSLATE = INDEX_POINTER_PRESSED+1;    public static final int INDEX_POINTER_NEXT = INDEX_COORD_TRANSLATE+1;//#else//#    public static final int INDEX_POINTER_NEXT = INDEX_MENU_INPUT_FORM_NEXT;//#endif            public void initializeNames() {                namesArray = _namesArray.getBytes();        namesArrayCount = namesArray.length;                table = new ModuleName[] {                new ModuleName(NAME_BIND_TO_KEY),                new ModuleName(NAME_BIND_TO_COMMAND),                new ModuleName(NAME_BIND_TO_MENU),                new ModuleName(NAME_PROMPT),                new ModuleName(NAME_PROMPT_PRESERVE),                new ModuleName(NAME_APP_EXIT),                new ModuleName(NAME_APP_DEBUG),                new ModuleName(NAME_MENU_START),                new ModuleName(NAME_BIND_TO_GOLD),                new ModuleName(NAME_BIND),                new ModuleName(NAME_INPUT_FORM),                new ModuleName(NAME_MENU_INPUT_FORM),//#ifdef POINTER                    new ModuleNameData(NAME_POINTER_PRESSED,this),                new ModuleName(NAME_COORD_TRANSLATE)//#endif                        };                namesCount = table.length;            }//#ifndef NOGUI        static Assigment findKeyBinding( int mode, int gameaction, int keycode ) {        for( int i=keyBindings.size()-1; i>=0; i-- ) {            Assigment ass = (Assigment) keyBindings.elementAt(i);            if( (gameaction!=0 && ass.gameaction==gameaction) ||                 (keycode!=0 && ass.keycode==keycode) ) {                // bit mask of valid modes                if( (ass.screenmode&mode)!=0 )                      return ass;            }        }        return null;    }     static Assigment findCommandBinding( Command cmd ) {        for( int i=0; i<commandBindings.size(); i++ ) {            Assigment ass = (Assigment) commandBindings.elementAt(i);            if( ass.command == cmd )                 return ass;        }        return null;    }        static Assigment findCommandBinding( String label ) {        for( int i=0; i<commandBindings.size(); i++ ) {            Assigment ass = (Assigment) commandBindings.elementAt(i);            if( ass.command.getLabel().compareTo(label) == 0 )                 return ass;        }        return null;    }        static Assigment findMenuBinding( String menupath ) {        for( int i=0; i<menuBindings.size(); i++ ) {            Assigment ass = (Assigment) commandBindings.elementAt(i);            if( ass.menupath.compareTo(menupath) == 0 )                 return ass;        }        return null;    }        /** finds Assigment bended to the given gold keys sequence     * @param goldkeys pressed gold sequence     * @param nkeys number of keys to check in goldkeys     * @return Assigment or null if not found     */        static Assigment findGoldBinding( short goldkeys[], int nkeys ) {        for( int i=goldBindings.size()-1; i>=0; i-- ) {            Assigment ass = (Assigment) goldBindings.elementAt(i);            LispObject bb[] = ass.goldkeys.value;            if( nkeys == bb.length ) {                int j;                for( j=0; j<nkeys; j++ ) {                    if( ((ShortAtom)bb[j]).value != goldkeys[j] )                        break;                }                if( j == nkeys )                    return ass;            }        }        return null;    }        void bindGold( QuotedList ql ) {        goldBindings.addElement( ql );    }        public void commandAction( Command cmd, Displayable dsp ) {        if( dsp == currentMenu ) {            if( cmd == cmdCancel ) {                // root node?                if( currentMenuPath.compareTo( startPath ) == 0 ) {                    CanvasHandler1.setCanvas();                    return;                }                // up to tree                int nn = currentMenuPath.lastIndexOf( '/', currentMenuPath.length()-2 );    // without trailing '/'//                if( nn < 0 ) {//                    System.out.println("menu path must start with '/'");//                    return;//                }                setMenu( currentMenuPath.substring( 0, nn+1 ) );              // reduce path string, leave trailing '/'                return;            }            if( cmd == cmdOK || cmd == List.SELECT_COMMAND ) {                int nn = currentMenu.getSelectedIndex();                Object el = currentMenuList.elementAt(nn);                // submenu                if( el instanceof String ) {                    // find next right '/'                    String ss = (String) el;                    int nn1 = ss.indexOf( '/', currentMenuPath.length() );                    // cannot be < 0                    setMenu( ss.substring( 0, nn1+1 ) );                    return;                }                // Ass                Assigment ass = (Assigment) el;                FunctorList menuInputForm = new FunctorList1( table[INDEX_MENU_INPUT_FORM], ass.code );                LispTask.LispMachine.putCommand(menuInputForm);                return;            }        }        else if( dsp == currentInputForm.screen ) {            if( cmd == cmdOK ) {            	synchronized(currentInputForm) {            		currentInputForm.notify();            	}//                CanvasHandler1.setCanvas();                return;            }            if( cmd == cmdCancel ) {            	isCancelled = true;				// cancel notification            	synchronized(currentInputForm) {            		currentInputForm.notify();            	}            	// after cancel/error will stay in menu //                CanvasHandler1.setCanvas();                return;            }            // SELECT_COMMAND            return;        }    }        // executed on LispMachine thread, blocks it    // notified from CommandListener of ScreenLite thread    // returns true if user input was canceled, and no code has been executed    public synchronized LispObject executeAssigment( InputForm ass ) throws EvaluateException {    	InputForm saved = currentInputForm;        Displayable savedScreen = CanvasHandler1.canvasHandler.display.getCurrent();    	try {    			            // postponed initialization	            if(ass.fields==null) {	                ass.initialize();	            }	            	            // this may throw EvaluateException if form can't be created (i.e. wrong title, prompts, etc), 	            // will be cascaded	            Displayable screen = ass.createForm();	            	            screen.addCommand( cmdOK );	            screen.addCommand( cmdCancel );	            screen.setCommandListener( SCREENLITE );	            	            currentInputForm = ass;	            CanvasHandler1.setDisplay( screen );	            	            do {	                isCancelled = false;	                synchronized(currentInputForm) {//	                	debug("waiting for input");			            try {							// wait for end of user input							currentInputForm.wait();						} catch (InterruptedException e) {							debug("InterruptedException in executeAssigment");						}	                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -