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

📄 simulator.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package sim;import java.util.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;/** * A simple WAP Simulator based on the WAP simulator WAPLET.  WAPLEt was designed * as an applet so it overrides certain mehtods to do its painting and updating * of the screen.  It also calls the function init() when first loaded to * handle initializations.  These routines have been maintained and upgraded so that * they can work under a normal Java Application format.  Many of the * routines have been changed to reflect this. For example, in the init() routine * references to the "this" pointer have been replaced with this.getContentPane, since * the JFrame class does not support access to itself directly.  All Graphical controls * must be added to the contentpane.  Routines where added to provide more functions to the * class, shuch as routines for calling up a popup menu, or even routines accessible * by the WAPIDE class to make changes in that class as well as allow the WAPIOE * class access to certain simulator functions. * * Some routines of WAPLET that where maintained where also changed so as to provide * more functionality to the browser.  For example, do links of types "accept" and "unknown" * are now supported and take preference over the anchor tag.  In the future * I hope to add even more functionality to the browser, making it fully compliant with * the specifications laid fown by the WAPForum. * * Skinning support has been added, and skins created by the PhoneDesigner class in the * Designer package can be loaded into the Simulator interactively.  Eventually, menu support * will follow so that the Simulator will be able to mimick any phone on the market. * Copyright: Copyright (c) 2003 * @author Mark Busman * @version 1.0 * Contact Info: cougar@skyinet.net * * 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 *//******************* * Modifications made to the original WAPLET class * * Feb 3, 2003 * - Renamed WAPLET class to Simulator class, added dummy MouseListner implementations * - Added a popup menu and hooked it up to the this_mouseClicked listener. * - Changed init() routine to make it comply with the JFrame implementation * - Changed the size of the offscreen buffer and moved its implementation to the constructor. * - Added two constants LEFT_MOUSE_BUTTON and RIGHT_MOUSE_BUTTON * * Feb 4, 2003 * - Added a mainPanel JPanel to the class to act as a container for the background image * - Made changes to the paint and update routines to improve rendering, had problems with *   default rendering behaviour, tests with background image did not render properly -- FIXED * - Made changes to the render() routine, added support for do types "accept" and "unknown" * - Made changes to init() routine, added support for do types "accept" and "unknown" in *   paint() method of _p2 control. * - Added _donext, _donextstring, _doprevstring variables for use with the init(), render() routines *   when rendering do tags.  the -donextstring and _doprevstring store label info. * - Changed the loadContent() routine, removed portions refrencing this.getContentBase() since *   this routine is not supported by the JFrame class * - Changed tje loadContent() routine to allow it to load files from a hard disk *   by name instead pf by URL, url support removed since it is not needed at this point in time * - Added loadDocument() routine to load a disk file and remove white space before passed *   the file contents are passed back to loadContent() along with the 1st card's id if any. * - Added constructor Simulator(String filename) * * Feb 5, 2003 * - Added skinning support through the use of a popup menu -- BUTTONS NOT FUNCTIONAL * - Added loadskin() routine and implemented the popup menu listeners * - Implemented file loading through the use of the popup menu Load File command * - Modified default content * - Changed background loading routine to simplify loading of default background *   image by using getResource() routine and created a simple background image *   and added it to the project. * * Feb 6, 2003 * - Made skin buttons functional through mouse listener routine -- OK, CANCEL, UP, DOWN, # *    supported * - Crude method of getting data for buttons with more than 1 item, i.e [1,2,3] shuch as *   cell phone buttons, implemented -- NEEDS MORE WORK * - Preliminary integration with WAPIDE class using current constructors * - Changed SCREENWIDTH, SCREENHEIGHT, and SCREEN_GREEN from constants to variables, *   renamed ScreenWidth, ScreenHeight, and Screen_Green. * - Added a BUTTONSCREENHEIGHT constant to the class to keep the height of the 2nd panel *   constant, modified effected routines. * * Feb 7, 2003 * - Added _idemenu, idetoolbar variables * - Added a new cosntructor to the class allowing for a filename, skinfile, JMenu, and *   toolbar to be passed in to the class. * - Added several routines to integrate Simulator class with WAPIDE class, namely: *   Back(), Home(), loadFile(), loadLoc(), Refresh(), Reload(), setSkin(), Stop() * - Modified constructors, this_mouseClicked(), init(), loadSkin(), render() for *   interoperability with the WAPIDE.  If constructor (filename, skin, menu, toolbar) is *   used then right clciking on the simulator does not popup the popup menu, instead *   the options of the peopup menu must be selected in the WAPIDE class * * Feb 8, 2003 * - added main() function * - performed tests * * Feb 9, 2003 * - Final integration test -- SUCCESSFUL *******************/public class Simulator extends JFrame implements ActionListener, MouseListener{  private JPopupMenu navPopupMenu = new JPopupMenu();  private JMenuItem navBack = new JMenuItem();  private JMenuItem navHome = new JMenuItem();  private JMenuItem navRefresh = new JMenuItem();  private JMenuItem navReload = new JMenuItem();  private JMenuItem navStop = new JMenuItem();  private JMenuItem navLocation = new JMenuItem();  private JMenuItem navFile = new JMenuItem();  private JMenuItem navSkin = new JMenuItem();  private GridBagLayout gridBagLayout1 = new GridBagLayout();  private JPanel mainPanel = new JPanel();  private JLabel BKGround = new JLabel();  private JMenuItem navSkinDefault = new JMenuItem();  // User Variables  /////////////////////////////////////////////////////////////////////////////  // Original Copyright notice of WAPLET  /////////////////////////////////////////////////////////////////////////////  ///* attention decompilers */  //static String copyright =  //      "this code and all related object, binary and bytecode " +  //	"compilations are copyright (c) 2000 pagea company. ";  /////////////////////////////////////////////////////////////////////////////  /** the page parser class used in rendering pages */  private Parser _parser;  /** a local vector holds the page contents */  private Vector _contents;  /** this vector is used in rendering lines of text to the screen */  private Vector _buffer;  /**   * a hash of links is maintained to support navigation,   * keyed by position index in the document.   */  private Hashtable _links;  /**   * the cookie jar is used to pass cookies back and forth in the   * waplet. this isn't required behavior (I think), but it keeps   * the waplet from generating millions of sessions.   */  private Hashtable _cookiejar = new Hashtable();  /**   * this image is used for page rendering-- content is drawn for   * the whole card, then the display shows a window on this image.   */  private Image _offscreen;  /** panels used to lay out components */  private Panel _p, _p2;  /** this is a local variable for the vertical image offset */  private int _vertical;  /** this flag represents current justification when rendering a page. */  private int _justify;  /** this flag represents underline state when rendering pages. */  private boolean _underline;  /** this flag represents inverted-text state when rendering pages. */  private boolean _invert;  /** If true means a previous event exists */  private boolean _doprev;  /** the link for a do botton other than prev button */  private boolean _donext = false;  /** this field maintains the current text-cursor position */  private Point _cursor;  /** field indicates the current font, used in page rendering */  private int _currentfont;  /** the current link index. links are keyed by position in the document */  private int _currentlinkindex;  /** the current highlighted/selected link. */  private int _highlightlink;  /** the graphics object for the offscreen rendering image. */  private Graphics _offg;  /** the name of the current card, within the current deck. */  private String _currentcard;  /** the current page, as string. */  private String _page;  /** the ling for a back button */  private String _dostring;  /** the cardid that the go event of the do event points to */  private String _donextstring = "";  /** the label text, if any for do's with a type of prev */  private String _dotext = "Back";  /** the label text, if any for do's with a type other than prev */  private String _donexttext = "Next";  /** the background image (skin?) */  private Image _bgimage = null;  /** screen width */  private int ScreenWidth = 124;  /** screen height -- be realistic */  private int ScreenHeight = 83; // was 115  /** the green color used as a screen background. */  private Color Screen_Green = new Color( 0, 234, 0);  /** The Menu used by the WAPIDE */  private JMenu idemenu = null;  /** The Toolbar used by the WAPIDE */  private JToolBar idetoolbar = null;  /** screen-height for one row of text */  private static final int ROWHEIGHT = 16;  /** button screen height */  private static final int BUTTONSCREENHEIGHT = 25;  /** field represents left justification */  private static final int LEFT_JUSTIFY = 0;  /** field represents center justification */  private static final int CENTER_JUSTIFY = 1;  /** field represents right justification */  private static final int RIGHT_JUSTIFY = 2;  /** field represents an undefined font state */  private static final int UNDEFINED = -1;  /** field represents plain text font */  private static final int FONT_PLAIN = 0;  /** field represents bold text font */  private static final int FONT_BOLD = 1;  /** field represents small font */  private static final int FONT_SMALL = 2;  /** field represents italic font */  private static final int FONT_ITALIC = 3;  /**   * this array holds references to font class instances for the   * several fonts used.   */  private static final Font[] FONTS = {    new Font( "Helvetica", Font.PLAIN, 12),    new Font( "Helvetica", Font.BOLD, 12),    new Font( "Helvetica", Font.PLAIN, 10),    new Font( "Helvetica", Font.ITALIC, 12)  };  /** default content, used when a page fails compilation. */  private static String defaultContent =        "<wml>" +        "  <card id=\"init\" newcontext=\"true\">" +        "    <do type=\"accept\" label=\"about\">" +        "      <go href=\"#about\"/></do>" +        "    <p align=\"center\">" +        "    <b>Phone Simulator</b>" +        "    <br/>based on <i>WAPLET</i><br/>Modified by<br/>Mark Busman</p></card>" +        "  <card id=\"about\">" +        "    <do type=\"prev\">" +        "      <go href=\"#init\"/>" +        "    </do>" +        "    <p>WAPLET is released by pagea company." +        " This WAP Phone simulator is based on WAPLET" +        " and was modified for use with " +      " the WAPIDE package." +        "    </p>" +        "  </card>" +        "</wml>"  ;  /** the background image/skin. */  private static String BACKGROUND_IMAGE =      "phonedefault.gif";  /** Left mouse button value */  private static int LEFT_MOUSE_BUTTON = 16;  /** Right mouse button value */  private static int RIGHT_MOUSE_BUTTON = 4;  /** Constructs an empty Simulator object. */  public Simulator() {  }  /**   *  Constructs a Simulator object, displays the simulator, and loads a file for display.   *  @param String filename - the name of the file and its path.   */  public Simulator(String file) {    try {      jbInit();      pack();      show();      // max screen size      _offscreen = getContentPane().createImage(1600, 1600);      _page = file;      init();    }    catch(Exception e) {      e.printStackTrace();    }  }  public Simulator(String file, String skin, JMenu menu, JToolBar tb) {    try {      idemenu = menu;      idetoolbar = tb;      for (int x = 0; x < 2; x++)        idemenu.getItem(x).setEnabled(true);      for (int x = 3; x < 5; x++)        idemenu.getItem(x).setEnabled(true);      for (int x = 8; x < 9; x++)        idemenu.getItem(x).setEnabled(true);      for (int x = 21; x < 25; x++)        idetoolbar.getComponentAtIndex(x).setEnabled(true);      jbInit();      pack();      show();      // max screen size      _offscreen = getContentPane().createImage(1600, 1600);      _page = file;      String str = null;      FileInputStream fis = null;      try {        fis = new FileInputStream (skin);        int size = fis.available();        byte[] bytes = new byte [size];        fis.read (bytes);        str = new String (bytes);        fis.close ();      }      catch (IOException err) {      }      if (str != null) {        loadSkin(str);      }      else        init();    }    catch(Exception e) {      e.printStackTrace();    }  }  public static void main(String[] args) {    String message = "Simulator version 1.0, Copyright (C) 2003 Mark Busman\n";    message = message + "Simulator comes with ABSOLUTELY NO WARRANTY;\nfor details see Copying.txt\n";    message = message + "This is free software, and you are welcome to redistribute it under certain conditions; see Copying.txt for the details.";    System.out.println(message);    Simulator simulator1 = new Simulator("");  }  private void jbInit() throws Exception {    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);    setIconImage(Toolkit.getDefaultToolkit().createImage(Simulator.class.getResource("icon.gif")));    this.setTitle("WAP Simulator");    this.getContentPane().setLayout(gridBagLayout1);    this.addMouseListener(new java.awt.event.MouseAdapter() {      public void mouseClicked(MouseEvent e) {        this_mouseClicked(e);      }    });    navBack.setEnabled(false);    navBack.setText("Back");    navBack.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navBack_actionPerformed(e);      }    });    navHome.setText("Home");    navHome.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navHome_actionPerformed(e);      }    });    navRefresh.setText("Refresh Card");    navRefresh.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navRefresh_actionPerformed(e);      }    });    navReload.setText("Reload Deck");    navReload.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navReload_actionPerformed(e);      }    });    navStop.setEnabled(false);    navStop.setText("Stop Loading Deck");    navLocation.setEnabled(false);    navLocation.setText("Load Location");    navFile.setText("Load File");    navFile.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navFile_actionPerformed(e);      }    });    navSkin.setText("Load Phone Skin");    navSkin.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navSkin_actionPerformed(e);      }    });    navSkinDefault.setText("Default Skin");    navSkinDefault.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        navSkinDefault_actionPerformed(e);      }    });    navPopupMenu.add(navBack);    navPopupMenu.add(navHome);    navPopupMenu.addSeparator();    navPopupMenu.add(navRefresh);    navPopupMenu.add(navReload);    navPopupMenu.add(navStop);    navPopupMenu.addSeparator();    navPopupMenu.add(navLocation);    navPopupMenu.add(navFile);    navPopupMenu.addSeparator();    navPopupMenu.add(navSkin);    navPopupMenu.add(navSkinDefault);    this.getContentPane().add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));    mainPanel.add(BKGround, null);  }  /**Overridden so we can exit when window is closed*/  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      if (idemenu != null) { // disable IDE controls        for (int x = 0; x < 2; x++)          idemenu.getItem(x).setEnabled(false);        for (int x = 3; x < 5; x++)

⌨️ 快捷键说明

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