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

📄 displayengine.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      }
    }
  }
  catch (Exception e)
  {
    System.out.println("drawDO threw a " + e.getClass() + " with message: " + e.getMessage());
  }
  return i;
}
  /**
  Takes care of the card element, when a card element is found it will change
  the title of the frame to whatever the title of the card is
  @param g graphics object
  @param i current index of the vector
  @return  The index of where the final card related
                tag was found
  */

  private int handleCard(Graphics g,int i)
  {
    String value;
    i++; //type
    while (isAttribute(clsScreen.elementAt(i).toString()))
    {
      if (clsScreen.elementAt(i).toString().indexOf("title") >= 0 )
      {
        value = GetValue(clsScreen.elementAt(i).toString());
        frame.setTitle("j2wap v1.1 - " + value);
      }
      i++;
    }
    return i;
  }
  /**
  Draws an input box of some sort
  @param g grpahics object
  @param i current index of the vector
  @return The index of where the final input related
                tag was found
  */
  private int drawInput(Graphics g,int i)
  {
    TextField txt;
    String name;
    String value;
    boolean bolValueFound = false;
    i++; //next element
    while (isAttribute(clsScreen.elementAt(i).toString()) && !clsScreen.elementAt(i).toString().equals(END_TAG_INPUT))
    {
      if (clsScreen.elementAt(i).toString().indexOf("name") >= 0 )
      {
        name = GetValue(clsScreen.elementAt(i).toString());
        value = c_clsBrowserCore.getVariable(name);
        bolValueFound = true;
        txt = new TextField(value);
        txt.setBounds(x,y-ROW_HEIGHT+5,50,15);
        if (value != null)
          txt.setText(value);
        txt.addTextListener(new VariableListener(name,c_clsBrowserCore,txt));
        add(txt);
      }
      if (clsScreen.elementAt(i).toString().indexOf("value") >= 0 && !bolValueFound)
      {
        value = GetValue(clsScreen.elementAt(i).toString());
        txt = new TextField(value);
        txt.setBounds(x,y-ROW_HEIGHT+5,50,15);
        add(txt);
      }
      i++;
    }
    return ++i;
  }

  /**
  Draws text onto the screen that is not associated with any other
  tags
  @param g graphics object
  @param clsWords a vector of words, this is used so I can wrap text
  @param intIndent the current indent in pixels
  @return The index of where the final input related
                tag was found
  */
  private void drawNormalText(Graphics g,Vector clsWords,int intIndent)
  {
    int intLength;
    currentFontMetrics = getFontMetrics(getFont());
    //System.out.println("drawNormalText");
    try
    {
      for (int ii=0;ii<clsWords.size();ii++)
      {
        intLength = currentFontMetrics.stringWidth(clsWords.elementAt(ii).toString());
        if ((x+intLength)>(160-intIndent))
        {
          y+=ROW_HEIGHT;
          x=5+intIndent;
        }
        g.drawString(clsWords.elementAt(ii).toString(),x,y);
        x+=5; //wordspacing
        x+=intLength;
      }
      clsWords.removeAllElements();
      clsWords.trimToSize();
      clsWords = null;
      //age collection explicitly, need all memory
  //  repaint();
    }
    catch(Exception e)
    {
      System.out.println("Error");
    }
  }

  /**
  Draws the A tag to the screen, the anchor is drawn with black
  background and white foreground. This is done so the link will be easy
  vieable especially on the palm
  @param g graphics object
  @param i current index of the vector
  @return The index of where the final input related
                tag was found
  */
  private int drawA(Graphics g,int i)
  {
    Label clsLink = new Label();
    int intLinkLength;
    String strLinkTitle = new String("");
    String strLink = new String("");
    String strAttribToCheck;
    String strEvent = new String("");
    Vector clsWords = new Vector(1,1);

    i++;  //ready for next element in the vector
    while (isAttribute(clsScreen.elementAt(i).toString()))
    {
      strAttribToCheck = clsScreen.elementAt(i).toString();
      if (strAttribToCheck.indexOf("title") >= 0)
        strLinkTitle = GetValue(strAttribToCheck);
      else if (strAttribToCheck.indexOf("href") >= 0)
        strEvent = GetValue(strAttribToCheck);
      i++;
    }
    //an anchor can contain images and text
    while (!clsScreen.elementAt(i).toString().equals(END_TAG_A))
    {
      if (clsScreen.elementAt(i).toString().equals(START_TAG_IMG))
      {
        //if anchor contains image, make the alt text clickable
        i = drawImage(g,i,true,strEvent);//anchor can contain image
        i++; //done since drawimage returns the position of the end tag and we
                  //want the next position
        i++;
      }
      else
      {
      //  clsWords = split(" ",clsScreen.elementAt(i).toString());
        if (clsScreen.elementAt(i).toString().length()>1){
          clsLink.setText(clsScreen.elementAt(i).toString());
          //here I change the coordinates of the label to the current positon
          System.out.println("link title: " + clsScreen.elementAt(i).toString());
          intLinkLength = currentFontMetrics.stringWidth(clsScreen.elementAt(i).toString());
          clsLink.setBounds(x,y-(ROW_HEIGHT-3),intLinkLength+5,15);
          x+= intLinkLength+4; //increments x with length of link + word space
          clsLink.setBackground(Color.black);
          clsLink.setForeground(Color.white);
          System.out.println("adding: " + clsLink);
          clsLink.addMouseListener(new LinkListener(strEvent,this));
          if (bolRepaintNeeded)
            add(clsLink);
        }
        i++;
      }
    }
    return i;
  }

   /**
  Draws the Anchor tag to the screen, the anchor is drawn with black
  background and white foreground. This is done so the link will be easy
  to vieva especially on the palm
  @param g graphics object
  @param i current index of the vector
  @return The index of where the final input related
                tag was found
  */
  private int drawAnchor(Graphics g,int i)
  {
    Label clsLink = new Label();
    int intLinkLength;
    String strLinkTitle = new String("");
    String strLink = new String("");
    String strAttribToCheck;
    String strEvent = new String("");
    Vector clsWords = new Vector(1,1);

    i++;  //ready for next element in the vector
    strLinkTitle = clsScreen.elementAt(i).toString();
    while (isAttribute(clsScreen.elementAt(i).toString()))
    {
      strAttribToCheck = clsScreen.elementAt(i).toString();
      if (strAttribToCheck.indexOf("title") >= 0)
        strLinkTitle = GetValue(strAttribToCheck);
      i++;
    }
    //an anchor can contain images and text
    while (!clsScreen.elementAt(i).toString().equals(END_TAG_ANCHOR))
    {
      if (clsScreen.elementAt(i).toString().equals(START_TAG_GO))
      {
        i++;
        strEvent = clsScreen.elementAt(i).toString();
        while (isAttribute(clsScreen.elementAt(i).toString()))
        {
          i++;
        }
      }
      else if (clsScreen.elementAt(i).toString().equals(START_TAG_PREV))
      {
        while (!clsScreen.elementAt(i).toString().equals(END_TAG_PREV))
        {
          i++;
        }
      }
      else if (clsScreen.elementAt(i).toString().equals(START_TAG_REFRESH))
      {
        while (!clsScreen.elementAt(i).toString().equals(END_TAG_REFRESH))
        {
          i++;
        }
      }
      else
      {
      clsWords = split(" ",clsScreen.elementAt(i).toString());
    //  drawNormalText(g,clsWords,intIndent); //this should be removed when this
                          //add label works!!!
  //    i++;
      clsLink.setText(strLinkTitle);
      //here I change the coordinates of the label to the current positon
      intLinkLength = currentFontMetrics.stringWidth(clsScreen.elementAt(i).toString());
      clsLink.setBounds(x,y-(ROW_HEIGHT-3),intLinkLength+10,15);
      x+= intLinkLength+4; //increments x with length of link + word space
      clsLink.setBackground(Color.black);
      clsLink.setForeground(Color.white);
      clsLink.addMouseListener(new LinkListener(strEvent,this));
      if (bolRepaintNeeded)
        add(clsLink);
      i++;
      }
    }
    return i;
  }

  /**
  Draws the image onto the screen, at the moment only the alt text is rendered
  to the screen
  @param g graphics object
  @param i current index of the vector<p>
  @param bolClickable - an image might be part of an anchor and if it is
      it needs to be clickable
     strEvent is the event that will be triggered if the image is clicked
  @return The index of where the final input related
                tag was found
  */
  private int drawImage(Graphics g,int i,boolean bolClickable,String strEvent)
  {
    String strAltText   = new String("");
    String strImgHref   = new String("");
    String strHeight  = new String("");
    String strWidth   = new String("");
    String strClass   = new String("");
    String strID    = new String("");
    String strAttribToCheck;
    Label clsLink = new Label();
    int intLinkLength;

    i++;  //ready for next element in the vector
    while (isAttribute(clsScreen.elementAt(i).toString()) && !clsScreen.elementAt(i).toString().equals(END_TAG_IMG))
    {
      strAttribToCheck = clsScreen.elementAt(i).toString();
      if (strAttribToCheck.indexOf("alt") >= 0)
        strAltText = GetValue(strAttribToCheck);
      else if (strAttribToCheck.indexOf("src") >= 0)
        strImgHref = GetValue(strAttribToCheck);
      else if (strAttribToCheck.indexOf("height") >= 0)
        strHeight = GetValue(strAttribToCheck);
      else if (strAttribToCheck.indexOf("width") >= 0)
        strWidth = GetValue(strAttribToCheck);
      else if(strAttribToCheck.indexOf("id") >=0)
        strID = GetValue(strAttribToCheck);
      else if(strAttribToCheck.indexOf("class") >=0)
        strClass = GetValue(strAttribToCheck);
      i++;
    }

    if (!bolClickable)
    {
      g.setColor(Color.darkGray);
      g.drawString(strAltText,x,y);
    }
    else
    {
      clsLink.setText(strAltText);
      System.out.println("link title: " + strAltText);
      intLinkLength = currentFontMetrics.stringWidth(strAltText);
      clsLink.setBounds(x,y-(ROW_HEIGHT-3),intLinkLength,12);
      x+= intLinkLength+4; //increments x with length of link + word space
      clsLink.setBackground(Color.black);
      clsLink.setForeground(Color.white);
      clsLink.addMouseListener(new LinkListener(strEvent,this));
      add(clsLink);
      g.setColor(Color.black);
    }
    return i;
  }
  /**
  handles the timeer tag found in the card, it will set some class variables to
  indicate that a timer was found in the card
  @param i current index of the vector
  @return The index of where the final input related
                tag was found
  */

  private int handleTimer(int i)
  {
    String strTimerLength = new String("");
    i++;  //ready for next element in the vector
    while (!clsScreen.elementAt(i).toString().equals(END_TAG_TIMER))
    {
      bolTimer = true; //timer found, now when starttimer is called
                        //from the end of card tag the timer will be started
                        //with the actual timeout value
      while (isAttribute(clsScreen.elementAt(i).toString()) && !clsScreen.elementAt(i).toString().equals(END_TAG_TIMER))
      {
        if (clsScreen.elementAt(i).toString().indexOf("value") >= 0)
        {
          strTimerLength = GetValue(clsScreen.elementAt(i).toString());
          c_timerDelay = Integer.valueOf(strTimerLength).intValue();
          SetEventID(c_timerEventID); //sets the eventid to the
                                      //event id specified in the ontimer event
        }
        i++;
      }
    i++;
    }
    return i;
  }

  /**
  Main function for all the widgets seen on the screen. Everytime the screen
  needs to be repainted this is the function that is first called. Then
  draweverything will start to process tag by tag until it has processed the
  whole loop. It wont repaint widgets that doesnt explicitly need to be repainted
  eg. labels and non graphics objects. All text is always re-rendered whenever a
  call to this function is done.
  @param g graphics object
  */

  public void drawEverything(Graphics g)
  {
    int i,ii;
    int intMode,intAlign;
    Integer clsMode,clsAlign;
    boolean bolAttributes;
    boolean notDone = true;
    Vector clsWords = new Vector(1,1);
    String strLink;
    intIndent = 0;
    y = ROW_HEIGHT;
    x = 5;
    try
    {

      for (i=0;i<clsScreen.size();i++)
      {
        //if tag is a br
        if (clsScreen.elementAt(i).toString().equals(START_TAG_BR))
        {
          y+=ROW_HEIGHT;
          x=5+intIndent;
          i++; //skips the following end br tag, not needed
        }
        //if tag is a paragraph tag, should handle two attributes too
        //extension stuff
        else if (clsScreen.elementAt(i).toString().equals(START_TAG_P))
        {
          bolAttributes = false;
          i++; //next element in the vector
          while (isAttribute(clsScreen.elementAt(i).toString()))
          {
            //handles attributes for the p tag, no attribute is implement
            //at this stage
            i++;
            bolAttributes = true;
          }
          if (!bolAttributes)
            i--; //no attributes founds, hence I have to decrement the counter
          intIndent=10;
          x+=intIndent;
        }
        else if (clsScreen.elementAt(i).toString().equals(END_TAG_P))
        {
          intIndent=0;
          x=5+intIndent;
          y+=ROW_HEIGHT;
        }
        else if (clsScreen.elementAt(i).toString().equals(START_TAG_IMG))
        {

⌨️ 快捷键说明

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