📄 simulator.java
字号:
idemenu.getItem(x).setEnabled(false); for (int x = 8; x < 9; x++) idemenu.getItem(x).setEnabled(false); for (int x = 21; x < 25; x++) idetoolbar.getComponentAtIndex(x).setEnabled(false); } setVisible(false); } } /** Needed to implement mouse listener, not used */ public void mouseExited(MouseEvent e) { } /** Needed to implement mouse listener, not used */ public void mouseEntered(MouseEvent e) { } /** * Needed to implement mouse listener, not used. * Will be used eventually to determine what character * is being selected when a button has multiple * action commands associated with it. */ public void mouseReleased(MouseEvent e) { } /** * Needed to implement mouse listener, not used. * Will be used eventually to determine what character * is being selected when a button has multiple * action commands associated with it. */ public void mousePressed(MouseEvent e) { } /** * Handles mouse events, label-specific behavior. Overrides * the default mouse clicked event */ public void mouseClicked(MouseEvent e) { int count = e.getClickCount(); JLabel l = new JLabel(); try { l = (JLabel) e.getSource(); } catch (ClassCastException cce) { return; } String commandstring = l.getName(); int pos = commandstring.indexOf("["); if (pos > -1) { commandstring = commandstring.substring(pos + 1); commandstring = commandstring.substring(0, commandstring.length() - 1); pos = commandstring.indexOf(",,"); Vector command = new Vector(); if (pos > - 1) { command.add(","); } StringTokenizer st = new StringTokenizer(commandstring, ","); while (st.hasMoreTokens()) command.add(st.nextToken()); int max = command.size(); int c = count%max; if (c == 0) count = max - 1; else count = c - 1; commandstring = (String) command.get(count); } if (commandstring.toLowerCase().equals("ok")) { if(_donext && !_donextstring.equals("")){ if( _donextstring.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = _donextstring.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(_donextstring); drawScreen(_currentcard); _vertical = 0; } } else if(linkOnScreen(_highlightlink)){ Tag tag = (Tag)(_links.get( new Integer( _highlightlink))); String link = tag.getParm("href"); // debug // showStatus("follow link to: " + link); if( link.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = link.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(link); drawScreen(_currentcard); _vertical = 0; } } } else if (commandstring.toLowerCase().equals("clear")) { if(_doprev && !_dostring.equals("")){ if( _dostring.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = _dostring.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(_dostring); drawScreen(_currentcard); _vertical = 0; } } } else if(commandstring.toLowerCase().equals("up")){ if(0 < _highlightlink && linkOnScreen( _highlightlink - 1)){ _highlightlink--; drawScreen(_currentcard); } else{ _vertical += 10; if( _vertical > 0) _vertical = 0; if(0 < _highlightlink && linkOnScreen( _highlightlink - 1)){ _highlightlink--; drawScreen(_currentcard); } } } else if(commandstring.toLowerCase().equals("down")){ if(linkOnScreen( _highlightlink + 1)){ _highlightlink++; drawScreen(_currentcard); } else{ _vertical -= 10; int tmp = Math.max(0, _cursor.y - ScreenHeight); if(_vertical < ( 0 - tmp)) _vertical = ( 0 - tmp); if(linkOnScreen( _highlightlink + 1)){ _highlightlink++; drawScreen(_currentcard); } } } else if(commandstring.toLowerCase().equals("#")){ _highlightlink = 0; loadContent(_page); drawScreen(_currentcard); _vertical = 0; } this.repaint(); } /** handle button events, button-specific behavior */ public void actionPerformed(ActionEvent e){ // check the current link index. if there's // another link on the screen, move to that one. if(e.getActionCommand().equals("left")){ if(_donext && !_donextstring.equals("")){ if( _donextstring.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = _donextstring.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(_donextstring); drawScreen(_currentcard); _vertical = 0; } } else if(linkOnScreen(_highlightlink)){ Tag tag = (Tag)(_links.get( new Integer( _highlightlink))); String link = tag.getParm("href"); // debug // showStatus("follow link to: " + link); if( link.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = link.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(link); drawScreen(_currentcard); _vertical = 0; } } } else if(e.getActionCommand().equals("right")){ if(_doprev && !_dostring.equals("")){ if( _dostring.startsWith("#")){ _highlightlink = 0; drawScreen(_currentcard = _dostring.substring(1)); _vertical = 0; } else{ _highlightlink = 0; loadContent(_dostring); drawScreen(_currentcard); _vertical = 0; } } } else if(e.getActionCommand().equals("up")){ if(0 < _highlightlink && linkOnScreen( _highlightlink - 1)){ _highlightlink--; drawScreen(_currentcard); } else{ _vertical += 10; if( _vertical > 0) _vertical = 0; if(0 < _highlightlink && linkOnScreen( _highlightlink - 1)){ _highlightlink--; drawScreen(_currentcard); } } } else if(e.getActionCommand().equals("down")){ if(linkOnScreen( _highlightlink + 1)){ _highlightlink++; drawScreen(_currentcard); } else{ _vertical -= 10; int tmp = Math.max(0, _cursor.y - ScreenHeight); if(_vertical < ( 0 - tmp)) _vertical = ( 0 - tmp); if(linkOnScreen( _highlightlink + 1)){ _highlightlink++; drawScreen(_currentcard); } } } else if(e.getActionCommand().equals("home")){ _highlightlink = 0; loadContent(_page); drawScreen(_currentcard); _vertical = 0; } this.repaint(); } /** * overrides the default update method. repaints * the two display panels. */ public void update(Graphics g) { try{ _p.repaint(); _p2.repaint(); } catch (NullPointerException nullerr) { super.update(g); } } /** * this renders the screen. ideally, this will only be * rendered once, and then painted on the panel at * varying offssets. * * note that that's not true anymore: changing links now * forces rendering, because of issues with the xor paint * mode. this certainly should be changed. */ private void drawScreen(String cardid) { // System.out.println("drawScreen()"); // set the offscreen image graphics object, if null if(null == _offg) _offg = _offscreen.getGraphics(); // reset the _cursor _cursor.x = 1; _cursor.y = 16; // draw the background -- numbers should be static _offg.setColor( Screen_Green); _offg.fillRect( 0, 0, _offscreen.getWidth(null), _offscreen.getHeight(null)); // render the card render(cardid); } /** * this method has been moved out of the screen * paint routine, so it can be adapted for better xml * parsing routines (or any other drawing routines). * also, I want to switch to a dynamic class loader, * because I'm a little worried about loading times. * there's some card control here, it's a little bloated... */ private void render(String cardid) { // System.out.println("render() called"); Object obj = null; Tag tag = null; int flag = 0; _links = new Hashtable(); for(Enumeration e = _contents.elements(); e.hasMoreElements(); ){ obj = e.nextElement(); if(obj instanceof Tag){ tag = (Tag)obj; if(1 == flag){ // reading, so process the tag. if it's a close // card tag, ++ the flag. if(tag.getName().equals("card") && tag.getState() == tag.TAG_CLOSE){ flag = 2; } else processTag(tag); } else if(0 == flag){ // not reading yet: check if this is an open // card tag, and then if it's the right card. if (!(cardid.equals(""))) { if(tag.getName().equals("card") && tag.getState() == tag.TAG_OPEN && tag.getParm("id").equals(cardid)){ flag = 1; } } else if((tag.getName().equals("card")) && (tag.getState() == tag.TAG_OPEN)) { flag = 1; } } } // otherwise it's a string, so if we're reading, // drop the leading ' (') and write it. else if( 1 == flag){ String tmp = ((String)obj).trim(); //System.out.println("calling write(): " + tmp); //write( tmp.substring(1)); bufferText( tmp.substring(1)); } } _doprev = false; _dostring = ""; _donext = false; _donextstring = ""; flag = 0; // check again, for do... Enumeration e = _contents.elements(); while( e.hasMoreElements() && flag < 5){ obj = e.nextElement(); if( obj instanceof Tag){ tag = (Tag)obj; if(flag > 0 && tag.getName().equals("card")) flag = 5; if(flag == 2){ if(tag.getName().equals("go")){ _doprev = true; _dostring = tag.getParm("href"); } flag = 5; } if(flag == 3){ if(tag.getName().equals("go")){ _donext = true; _donextstring = tag.getParm("href"); } flag = 5; } if(flag == 1 && tag.getName().equals("do") && tag.getState() == tag.TAG_OPEN && tag.getParm("type").equals("prev")) { flag = 2; _dotext = tag.getParm("label"); try { if (_dotext.equals("")) _dotext = "Back"; } catch (NullPointerException nullerr) { _dotext = "Back"; } } if(flag == 1 && tag.getName().equals("do") && tag.getState() == tag.TAG_OPEN && tag.getParm("type").equals("accept")) { flag = 3; _donexttext = tag.getParm("label"); try { if (_donexttext.equals("")) _donexttext = "Next"; } catch (NullPointerException nullerr) { _donexttext = "Next"; } } if(flag == 1 && tag.getName().equals("do") && tag.getState() == tag.TAG_OPEN && tag.getParm("type").equals("unknown")) { flag = 3; _donexttext = tag.getParm("label"); try { if (_donexttext.equals("")) _donexttext = "Unknown"; } catch (NullPointerException nullerr) { _donexttext = "Unknown"; } } try { if(flag == 0 && tag.getName().equals("card") && tag.getState() == tag.TAG_OPEN && tag.getParm("id").equals(cardid)) flag = 1; } catch (NullPointerException nullerr) { if(flag == 0 && tag.getName().equals("card") && tag.getState() == tag.TAG_OPEN) flag = 1; } checkPrev(); } } } /** handle one tag. should put together a case method for this. */ private void processTag(Tag tag){ String name = tag.getName(); String parm = null; int state = tag.getState(); if(name.equals("p") && state == tag.TAG_OPEN){ _justify = LEFT_JUSTIFY; parm = tag.getParm("align"); if(null != parm){ if( parm.equals("center")) _justify = CENTER_JUSTIFY; else if( parm.equals("right")) _justify = RIGHT_JUSTIFY; } } else if(name.equals("a")){ // anchor... for open tag, // store the tag, by index number; // set the current link index number... if(state == tag.TAG_OPEN){ _currentlinkindex = _links.size(); _links.put( new Integer( _currentlinkindex), tag); } else{ // System.out.println("added link no. " + _currentlinkindex); _currentlinkindex = -1; } } else if(name.equals("p") && state == tag.TAG_CLOSE){ flushBuffer(); } else if(name.equals("b")){ _currentfont = (state == tag.TAG_OPEN) ? FONT_BOLD : FONT_PLAIN; } else if(name.equals("small")){ _currentfont = (state == tag.TAG_OPEN) ? FONT_SMALL : FONT_PLAIN; } else if(name.equals("i")){ _currentfont = (state == tag.TAG_OPEN) ? FONT_ITALIC : FONT_PLAIN;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -