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

📄 heclcanvas.java

📁 Hecl编程语言是一个高层次的脚本语言的Java实现。其用意是要小
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void pointerDragged(int x,int y) {	callEventHandler(CanvasEvent.E_PDRAG,x,y,drawwidth,drawheight,0);    }        protected boolean isCommandKey(int keycode) {	if(isfullscreen && cmds.size() > 0) {	    switch(getGameAction(keycode)) {	      case GAME_LEFT_SK:	      case GAME_RIGHT_SK:		return true;	      case FIRE:		return cmds.size() == 3;	      default:		break;	    }	}	return false;    }        public void keyPressed(int keycode) {	if(isfullscreen && cmds.size() > 0) {	    Command c = findCommand(keycode);	    if(c != null) {		if(c == CMD_MENU) {		    menulist.setCommandListener(this);		    menulist.addCommand(CMD_BACK);		    MidletCmd.getDisplay().setCurrent(menulist);		    return;		}		handleCommand(c);		return;	    }	}	callEventHandler(CanvasEvent.E_KPRESS,0,0,drawwidth,drawheight,keycode);    }        public void keyReleased(int keycode) {	if(isfullscreen && cmds.size() > 0) {	    // ignore when command is selected	    if(findCommand(keycode) != null)		return;	}	callEventHandler(CanvasEvent.E_KRELEASE,0,0,drawwidth,drawheight,keycode);    }        public void keyRepeated(int keycode) {	if(isfullscreen && cmds.size() > 0) {	    // ignore when command is selected	    if(findCommand(keycode) != null)		return;	}	callEventHandler(CanvasEvent.E_KREPEAT,0,0,drawwidth,drawheight,keycode);    }        public void removeCommand(Command cmd) {	super.removeCommand(cmd);	cmds.removeElement(cmd);	cmds.trimToSize();	// update display	updateCommands();    }    public void showNotify() {	callEventHandler(CanvasEvent.E_SHOW,0,0,drawwidth,drawheight,0);    }//#ifdef polish.blackberry//#ifdef polish.usePolishGui    //de.enough.polish.ui.AccessibleCanvas sizeChanged is public    public//#else    protected//#endif//#else    protected//#endif	void sizeChanged(int w,int h) {//#ifdef DEBUG	System.err.println("size changed, w="+w+", h="+h);	System.err.println("size changed, w="+super.getWidth()+", h="+super.getHeight());//#endif	// go calculate. remind: some nokia devices have a bug that cause	// wrong values to be passed as arguments to this function.	calcScreenWidth();	if(this.drawable != null) {	    this.drawable.resize(drawwidth,drawheight);	}	try {	    callEventHandler(CanvasEvent.E_RESIZE,0,0,drawwidth,drawheight,0);	}	catch(Exception e) {	    e.printStackTrace();	}	showCommands(mygraphics);    }    protected void callEventHandler(int reason,int x,int y,				    int width,int height,int keycode) {	if(evh != null) {	    try {		//System.err.println("*** calling evh, reason="+reason);		CanvasEvent ce = new CanvasEvent(this,reason,x,y,width,height,keycode);		//System.err.println(ce.toString());		evh.handleEvent(ce);		//System.err.println("*** evh done");	    }	    catch(Exception e) {		//System.err.println("**** CANVASEVENT PROBLEM");		e.printStackTrace();	    }	}    }    public Drawable getDrawable() {return this.drawable;}        protected boolean isSoftKey(int keycode) {	return (keycode == KEYCODE_LEFT_SK || keycode == KEYCODE_RIGHT_SK);    }    private Command findCommand(int keyCode) {	for(int i=0; i < buttons.length; ++i) {	    Command c = buttons[i].getCommand();	    if(c == null)		continue;	    try {		if(buttons[i].gamecode == getGameAction(keyCode)) {		    return c;		}	    }	    catch(IllegalArgumentException illgl) {	    }	}	return null;    }            private void updateCommands() {	if(!SettingsCmd.cvdocmds)	    return;		for(int i=0; i<buttons.length; ++i)	    buttons[i].setCommand(null);		Vector commandsTable = new Vector();	for (int i = 0; i < cmds.size(); i++) {	    commandsTable.addElement(null);	}		// Sort commands using priority	Enumeration en = cmds.elements();	while (en.hasMoreElements()) {	    Command commandToSort = (Command)en.nextElement();	    	    for (int i = 0; i < commandsTable.size(); i++) {		if (commandsTable.elementAt(i) == null) {		    commandsTable.setElementAt(commandToSort, i);		    break;		}		if (commandToSort.getPriority() < ((Command)commandsTable.elementAt(i)).getPriority()) {		    for (int j = commandsTable.size() - 1; j > i; j--) {			if (commandsTable.elementAt(j - 1) != null) {			    commandsTable.setElementAt(commandsTable.elementAt(j - 1), j);			}		    }		}	    }				}	if(commandsTable.size() > buttons.length) {	    // Menu is needed	    commandsTable.insertElementAt(CMD_MENU, 0);	}	assignCommands(commandsTable);				showCommands(mygraphics);    }        private void assignCommands(Vector commandsTable) {	if(commandsTable.size() <= buttons.length) {	    // we have one button for each command	    for (int i = 0; i < commandsTable.size(); i++) {		for(int j=0; j<buttons.length; ++j) {		    Command c = (Command)commandsTable.elementAt(i);		    if (buttons[j].getCommand() == null && buttons[j].isPreferred(c)) {			buttons[j].setCommand(c);			commandsTable.removeElementAt(i);			i--;			break;		    }		}	    }	    for (int i = 0; i < commandsTable.size(); i++) {		for(int j=0; j<buttons.length; ++j) {		    if (buttons[j].getCommand() == null) {			buttons[j].setCommand((Command)commandsTable.elementAt(i));			commandsTable.removeElementAt(i);			i--;			break;		    }		}	    }	} else {	    // more cmds than buttons	    if(buttons.length > 0) {		buttons[0].setCommand((Command)commandsTable.firstElement());		commandsTable.removeElementAt(0);	    }	    if(buttons.length > 1) {		for(int i=0; i<commandsTable.size(); ++i) {		    Command c = (Command)commandsTable.elementAt(i);		    if(null == buttons[1].getCommand() && buttons[1].isPreferred(c)) {			buttons[1].setCommand(c);			commandsTable.removeElementAt(i);		    }		}	    }	    for(int i=2; i<buttons.length; ++i)		buttons[i].setCommand(null);	    	    menulist.deleteAll();	    menucommands = new Vector();	    for (int i = 0; i < commandsTable.size(); i++) {		Command c = (Command)commandsTable.elementAt(i);		menucommands.addElement(c);		menulist.append(WidgetInfo.commandLabel(c,false), null);	    }	}    }        private void calcScreenWidth() {	this.fullwidth = super.getWidth();	this.fullheight = super.getHeight();	this.drawwidth = fullwidth;	this.drawheight = getFullScreenMode() && !SettingsCmd.cvkeepcmdsinfullscreen ?	    this.fullheight-CMDBARHEIGHT : this.fullheight;    }    public boolean getAutoFlushMode() {	return this.autoflush;    }        public void setAutoFlushMode(boolean b) {	this.autoflush = b;    }        protected boolean nokeyevents;    protected EventHandler evh = null;    protected Vector cmds = new Vector();    protected CommandListener cmdlistener = null;    protected CommandListener savecmdlistener = null;    private Graphics mygraphics = null;    private boolean isfullscreen = false;    private Drawable drawable;    private SoftButton buttons[] = SoftButton.makeSoftButtons();    private Vector menucommands = null;    private List menulist = new List("Menu", List.IMPLICIT);    private int fullwidth = 1;    private int fullheight = 1;    private int drawwidth = 1;    private int drawheight = 1;    private Color cmdbgcolor = SettingsCmd.cvcmdbgcolor;    private Color cmdfgcolor = SettingsCmd.cvcmdfgcolor;    private boolean autoflush = true;    static class SoftButton {	private static SoftButton[] makeSoftButtons() {	    SoftButton[] v = new SoftButton[3];	    	    v[0] = new SoftButton(KEYCODE_LEFT_SK,GAME_LEFT_SK,				  new int[]{Command.OK,Command.ITEM,Command.SCREEN});	    v[1] = new SoftButton(KEYCODE_RIGHT_SK,GAME_RIGHT_SK,				  new int[]{Command.CANCEL,Command.EXIT,						Command.BACK,Command.STOP});	    v[2] = new SoftButton(0,Canvas.FIRE,new int[]{Command.SCREEN});	    return v;	}	    	public SoftButton(int keyCode,int gameCode,int [] ptypes) {	    keycode = keyCode;	    gamecode = gameCode;	    preferredtype = ptypes;	}	public Command getCommand() {	    return cmd;	}		public void setCommand(Command c) {	    cmd = c;	}		public boolean isPreferred(Command c) {	    int cmdtype = c.getCommandType();	    if(preferredtype != null) {		for(int i=0; i<preferredtype.length; ++i) {		    if(cmdtype == preferredtype[i])			return true;		}	    }	    return false;	}		public int keycode = 0;	public int gamecode = 0;	protected Command cmd = null;	public int[] preferredtype = null;    }    private static final Command CMD_MENU = new Command("Optionen", Command.SCREEN, 0);    private static final Command CMD_BACK = new Command("Zurück", Command.BACK, 0);    private static final Command CMD_SELECT = new Command("Auswahl", Command.OK, 0);    private static Font CMDFONT = Font.getFont(Font.FONT_STATIC_TEXT);    //private static int CMDFONTHEIGHT = CMDFONT.getHeight();    private static int CMDBARHEIGHT = CMDFONT.getHeight()+2;        static {	//Globals.set("isblackberry", new Boolean(false));	try {	    // Siemens (S65)	    Class.forName("com.siemens.mp.lcdui.Image");	    KEYCODE_LEFT_SK = -1;	    KEYCODE_RIGHT_SK = -4;	} catch (ClassNotFoundException e1) {	}		try {	    // Blackberry	    Class.forName("net.rim.device.api.system.Application");	    KEYCODE_LEFT_SK = 524288;	    KEYCODE_RIGHT_SK = 1769472;	    //Globals.set("isblackberry", new Boolean(true));	} catch (ClassNotFoundException e2) {	}    }}// Variables:// mode:java// coding:utf-8// End:

⌨️ 快捷键说明

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