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

📄 displayengine.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * j2wap is distributed under the terms of the GNU Public License
 *
 *  j2wap was written by:
 *
 *	        Scott Campbell
 *			Michael Nordling
 *			Karl Maftoum
 * 			Julian Bright
 *
 *			This was a final project for Comp.Engineering at the University of Canberra, Australia
 *
 *			Now released as Open Source software. 28 November 2000
 *
 *			Email: k_maftoum@hotmail.com for more info
 *
 *			Use entirely at your own risk.
 */



 /**
 * Title:        Display Engine
 * Description:  The main user interface class
 * Copyright:    Copyright (c) 2000 j2wap.com
 * Company:      j2wap.com
 * @author       Michael Nordling
 * @version      1.1
 */

package ui;
import de.kawt.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.MenuBar;
import wae.*;

/**
Closer closes the windows
*/
class Closer extends WindowAdapter
{
  public void windowClosing (WindowEvent e)
  {
    System.exit (0);
  }
}

/**
  CloseDialog simply closes a dialog
*/
class CloseDialog extends WindowAdapter
{
  private Dialog clsDialog;
  public CloseDialog(Dialog dialog)
  {
    clsDialog = dialog;
  }
  public void windowClosing(WindowEvent e)
  {
    clsDialog.dispose();
  }
}
/**
* DisplayEngine is the main class
*/

public class DisplayEngine extends Frame
{
  /**class wide scroll pane*/
  ScrollPane sp;
  /**Panel of do buttons, show in the lower parts of the browser*/
  Panel buttonPanel;
  DisplayEngineCore clsDengCore;

  /**
   * Constructor for the displayengine
   * @param in_bc is a reference to the browsercore class
   */
  public DisplayEngine(BrowserCore in_bc)
  {
    this.setTitle("j2wap v1.1");
    sp = new ScrollPane();
    buttonPanel = new Panel();
    add ("Center",sp);
    add ("South",buttonPanel);
    clsDengCore = new DisplayEngineCore(this,in_bc,buttonPanel);
    sp.add(clsDengCore);
    addWindowListener (new Closer ());
  //setLayout(null);
    pack ();
  }

  /**
   * Draws the card,contained in the vector, and returns an event
   * id when it has finished exceuting<p>
   * @param  v holds the representation of the wml card that is going to be rendered on the screen
     @param  em contais a reference to the event management<p>
     @param  in_intTimerEventID this is the event that will be triggered when a timer event is found<p>
   * @return The EventID
   */
  public int drawCard(Vector v,wae.EventManagement em,int in_intTimerEventID)
  {
    int eventID;
    eventID = clsDengCore.drawCard(v,em,in_intTimerEventID);
    return eventID;
  }
}

  /**
   * Class DisplayEngineCore is the main class where all the processing
   * is done, it is always called from inside the displayengine class
   * id when it has finished exceuting<p>
   */
class DisplayEngineCore extends Panel implements WMLStringTags,ActionListener
{
  /**Contains the os name*/
  private String c_strOs;
  /**Contains the os version*/
  private int c_intMajor;
  /**Contains the elements that will be rendered*/
  public Vector clsScreen;// = new Vector(1,1);
  /**Contains the Font metrics used currently*/
  private FontMetrics currentFontMetrics;
   /**Sets the rowehight */
  private int ROW_HEIGHT=15;
  /**Sets the table width in pixels */
  private int TABLE_WIDTH = 145;
  /**Contains the number of rows in each cell */
  private int intRowsInCell = 0;
  /**Current coordinates*/
  private int y,x; //current coordinates
  /**Indicates if an event has occured*/
  public boolean bolEvents = false;
  /**Menus is only needed to be rendered once*/
  public boolean bolRunOnce;
  /**Contains a reference to the display engine */
  private Frame frame;
  /**The event id*/
  private int eventID=0;
  private java.awt.MenuBar menuBar = new MenuBar();
  /**Event managment*/
  private EventManagement em;
  /**Holds the current indent in pixels*/
  private int intIndent = 0;
  /**Indicates if a timer is found in the card*/
  boolean bolTimer = false;
  protected BrowserCore c_clsBrowserCore;
  /**Indicates if a repaint is needed*/
  private boolean bolRepaintNeeded = true;
  /**A reference to the menuitem naviagate*/
  private java.awt.Menu navigate;
  private boolean bolFirstDo = true;
  /**Holds the eventid for the timer*/
  private int c_timerEventID=0;
  /**Contains the delay for the timer*/
  private int c_timerDelay=0;
  /**Holds the number of do found in the card, max two is displayed by the UI */
  private int c_intDoFound=0; //should be max 2
  private Panel cls_Buttons;
  /**Is the first button used by the first do found*/
  private Button b1;
  /**Is the second button used by the second do found*/
  private Button b2;
  /***/
  private LinkListener cls_DoButton1Listener;
  /***/
  private LinkListener cls_DoButton2Listener;


  /**
   * Constructor for the displayenginecore class
   * Creates the menus and the panel for the "do" buttons
   * @param  frame  reference to the display engine<p>
     @param  in_bc  reference to the browsercore<p>
     @param  buttons  reference to the panel of buttons<p>

   */
  public DisplayEngineCore (Frame frame,BrowserCore in_bc,Panel buttons)
  {
    this.frame = frame;
    this.cls_Buttons = buttons;
    c_clsBrowserCore = in_bc;


  //file menu
    java.awt.Menu file = new java.awt.Menu("File");
    java.awt.MenuItem miGo = new java.awt.MenuItem("Go");
    miGo.addActionListener(this);
    file.add(miGo);
    java.awt.MenuItem miGateway = new java.awt.MenuItem("Set gateway");
    miGateway.addActionListener(this);
    file.add(miGateway);
    menuBar.add(file);
    java.awt.MenuItem miRefresh =  new java.awt.MenuItem ("Refresh");
    miRefresh.addActionListener(this);
    file.add (miRefresh);

    java.awt.MenuItem miExit = new java.awt.MenuItem("Exit");
    miExit.addActionListener(this);
    file.add(miExit);

      //navigate menu
    navigate = new java.awt.Menu ("Navigate");
    menuBar.add (navigate); //adds the menu Navigate to the menubar
    java.awt.MenuItem miBack = new java.awt.MenuItem ("Back");
    miBack.addActionListener (this);
    navigate.add (miBack);
    //Help menu
    java.awt.Menu help = new java.awt.Menu ("Help");
    menuBar.add (help);
    java.awt.MenuItem miTopic =  new java.awt.MenuItem ("Topic");
    miTopic.addActionListener(this);
    help.add (miTopic);
    java.awt.MenuItem miAbout = new java.awt.MenuItem ("About");
    miAbout.addActionListener (this);
    help.add (miAbout);
    frame.setMenuBar (menuBar); //sets the menubar to the frame
    setLayout(null); //gives me control over the layout of components
    b1 = new Button("           ");
    b1.setSize(80,15);
    b1.setVisible(true);
    cls_Buttons.add(b1);
    b2 = new Button("           ");
    b2.setSize(80,15);
    b2.setVisible(true);
    cls_Buttons.add(b2);
  }

  /**Sets the wap gateway used in the network layer
  @param in_strGateway a wapgateway in either ip format or domain.com format
  */
  public void setGateway(String in_strGateway)
  {
    c_clsBrowserCore.setGateway(in_strGateway);
  }

  /**
  * Paint is called when needed, paint is calling the main
  * draw function called draweverything which controls eveything
  * seen on the screen
  */
  public void paint(Graphics g)
  {
    if (bolRepaintNeeded)
      super.paint(g);
    drawEverything(g);
  }

  //inner class, this is used so the processing can stay inside the UI
  class uiThread extends Thread
  {
    public void run()
    {
      try
      {
        while (!bolEvents) //this is read from the outer class
        {
          sleep(100);
        }
      }
      catch(InterruptedException e)
      {
        System.out.println("Exception");
      }
    }
  }

  /**
  * drawCard is called from the drawcard function in the displayengine,
  * this method will return an eventID when it has finished processing.
  * It is implemented as a blocking call where it waits for an event to
  * occur before it exists
  @param v contains the representation of the wml card to be rendered
  @param in_clsEm eventmanagment
  @param timerEventID holds the eventid to be triggered in case of a timer event

  @return The current position in the vector
  */
  public int drawCard(Vector v,EventManagement in_clsEm,int timerEventID)
  {
    c_timerEventID = timerEventID;

    em = in_clsEm;
    clsScreen = v;
    bolRunOnce = false;
    bolFirstDo = true;
    this.removeAll();

    bolRepaintNeeded = true;
    repaint();
    System.out.println(v);
    uiThread t = new uiThread();
    t.run();
    bolEvents = false;
    bolTimer = false; //default value, assume no timer in card
    System.out.println("End of DrawCard");
    return eventID;                   //can remain in memory
  }

  /**
  SetEventID sets the id for the event that was raised.
  @param in_intEventID eventid, when clicking on a link an event is called. The eventID is passed into
  this function
  */
  public void SetEventID(int in_intEventID)
  {
    System.out.println("SetEventID");
    eventID = in_intEventID;
  }

  /**
  ActionPerformed recieves all the actionevents that was triggered
  in the displayenginecore
  @param e the event that triggered this method
  */

  public void actionPerformed (ActionEvent e)
  {
    System.out.println("command:" + e.getActionCommand().toLowerCase());
    if (e.getActionCommand().toLowerCase().equals("exit"))
    {
          eventID = 0;
          bolEvents = true;
      //System.exit(0);
    }
    else if (e.getActionCommand().toLowerCase().equals("go"))
    {
      UrlDialog clsUrlDialog = new UrlDialog(frame,this,"Go to url",em);
      clsUrlDialog.setBounds(frame.getX(),frame.getY()+20,120,60);
    }
    else if (e.getActionCommand().toLowerCase().equals("about"))
    {
    //OptionDialog.showMessageDialog(this.frame, "Visit www.j2wap.com");
    }
    else if (e.getActionCommand().toLowerCase().equals("refresh"))
    {
      eventID = em.registerRefresh();
      System.out.println(eventID);
      bolEvents = true;
    }
    else if (e.getActionCommand().toLowerCase().equals("set gateway"))
    {
      GateWayDialog clsGatewaydialog = new GateWayDialog(frame,this,"Set gateway",em);
      clsGatewaydialog.setBounds(frame.getX(),frame.getY()+20,120,60);
    }
    else if (e.getActionCommand().toLowerCase().equals("topic"))
    {
    }
    else if (e.getActionCommand().toLowerCase().equals("back"))
    {
      eventID = em.registerPrev();
      System.out.println("PREVID: " + eventID);
      bolEvents = true;
    }
  }

  /**
  drawTable function is used when the processing is done inside of the table
  all table related functionality is encapsulated here
  @param g graphics object
  @param i the index of where in the vector we are
  @return the index of where the final table related
                tag was found

  */
   private int drawTable(Graphics g,int i)
  {
    int intCols=0;          //holds the number of columns in the able
    int intCurrentColumn=0; //holds which column is currently being drawn
    int intCellWidth=0;     //the width of the cell in pixels
    int intOffset = 0;
    int ii;   //loop variable
    int intWordLength; //the length, in pixels, of a word
    int intCellStartX;
    int CELL_PADDING=2;
    int intTableStartY;
    Integer clsAttrib;
    Vector clsWords = new Vector(1,1); //contains all the words inside a cell in a vector
    String attrib   = new String();

    currentFontMetrics = getFontMetrics(getFont());

    i++;
    //attrib = clsScreen.elementAt(i).toString();
    try{
          while(isAttribute(clsScreen.elementAt(i).toString()))
          {
        //if attribute is equal to columns
        if (clsScreen.elementAt(i).toString().indexOf("columns") >= 0 )
        {
          attrib        = clsScreen.elementAt(i).toString();
          attrib        = GetValue(attrib);
          String s    = attrib;
          int v=0;
          for (int ix=0; ix<s.length(); ix++){
            if (s.charAt(ix)!='"')
              v = 10*v + s.charAt(ix) - '0';
            }
          intCols = v;
          }//end if
      i++;
      } //end while loop

          intCellWidth  = TABLE_WIDTH/intCols; //returns an int
    }//end try

⌨️ 快捷键说明

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