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

📄 displayengine.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      catch(Exception e)
      {
        System.out.println("here");
      }

    currentFontMetrics = getFontMetrics(getFont());
    intCellWidth  = TABLE_WIDTH/intCols; //returns an int
    i++;
    intCurrentColumn = 0;
    y -= (ROW_HEIGHT); //correction,
    intTableStartY = y;
    for (;i<clsScreen.capacity();i++)
    {
      if (clsScreen.elementAt(i).toString().equals(START_TAG_TR))
      {
        intCurrentColumn = 0; //after a new row, put current column to 0
        intOffset = 0;
        y+=(ROW_HEIGHT);
        x=5;
        g.drawLine(5,y,TABLE_WIDTH,y); //draws a horizontal line
      }
      else if (clsScreen.elementAt(i).toString().equals(END_TAG_TR))
      {
        x=5;
        if (intRowsInCell > 0)
        {
          for (int intLoop=0;intLoop<intCols;intLoop++)
            g.drawLine(x+(intLoop*intCellWidth),y-((intRowsInCell)*(ROW_HEIGHT-2)),x+(intLoop*intCellWidth),y+ROW_HEIGHT-2);
        }
        g.drawLine(5,y/*+ROW_HEIGHT*/,TABLE_WIDTH,y/*+ROW_HEIGHT*/); //draws a horizontal line
      }
      else if (clsScreen.elementAt(i).toString().equals(START_TAG_TD))
      {
        intRowsInCell = 0;
        g.drawLine(intCellWidth*intCurrentColumn+x,y,intCellWidth*intCurrentColumn+x,y+ROW_HEIGHT);
        intCurrentColumn++; //increment columns counter
      }
      else if (clsScreen.elementAt(i).toString().equals(END_TAG_TD))
      {
        if (intCurrentColumn==intCols)  //The last column needs to be treathed specially
          if ((TABLE_WIDTH%intCols)!=0) //if the reminder is not 0 then decrease the
            intOffset = 1;     //cellwith by one
        if (intCols == 1)
           intOffset = 4;
        g.drawLine((intCellWidth-intOffset)*intCurrentColumn+x,y-(ROW_HEIGHT*intRowsInCell),(intCellWidth-intOffset)*intCurrentColumn+x,y+ROW_HEIGHT);
      }
      else if (clsScreen.elementAt(i).toString().equals(END_TAG_TABLE))
      {
        x=5;
        g.drawLine(5,y+ROW_HEIGHT,TABLE_WIDTH,y+ROW_HEIGHT); //draws a horizontal line
        y+=(2*ROW_HEIGHT);
        return i;
      }
      else if (clsScreen.elementAt(i).toString().equals(START_TAG_A))
      {
        y+=ROW_HEIGHT;
        i = drawAnchor(g,i);
      }
      else if (clsScreen.elementAt(i).toString().equals(START_TAG_IMG))
      {
        i = drawImage(g,i,false,"0");
      }
      else if (clsScreen.elementAt(i).toString().equals(END_TAG_IMG))
      {
        //dont do anything when end of images is found
        //simply take the next element in the vector
      }
      else
      {
        ii=0;
        clsWords = split(" ",clsScreen.elementAt(i).toString());
      //  drawNormalText(g,clsWords,0);

        intCellStartX = intCellWidth*(intCurrentColumn-1)+CELL_PADDING+2;
        x=intCellStartX;
        for (ii=0;ii<clsWords.size();ii++)
        {
          intWordLength = currentFontMetrics.stringWidth(clsWords.elementAt(ii).toString());
          if ((x+intWordLength)>(intCellStartX+intCellWidth))
          {
            y+=ROW_HEIGHT-CELL_PADDING;
            x=intCellStartX;
            intRowsInCell++;
          }
          g.drawString(clsWords.elementAt(ii).toString(),x+CELL_PADDING,(y-CELL_PADDING+ROW_HEIGHT));
          x+=intWordLength;
          x+=4; //wordspacing
        }
        clsWords.removeAllElements();
        clsWords.trimToSize();
        clsWords = null;
      }
      x=5;
    }
    return i;
  }

  /**
  * splits a string on delimeter and returns a vector with the sub strings
  @param delim string delimeter
  @param str main string
  @return A vector filled with elements for each substring found in str
  */
  public static Vector split(String delim, String str)
  {
    Vector v = new Vector();
    boolean ok = true;

    int indx1 = 0;
    int indx2 = 0;
    str = str.trim();
    try
    {
      indx2 = str.indexOf(delim,indx1);
      while(indx2!=-1)
      {
        v.addElement(str.substring(indx1,indx2));
        indx1 = indx2 + 1;
        indx2 = str.indexOf(delim,indx1);
      }
      v.addElement(str.substring(indx1, str.length()));
    }
    catch (Exception e)
    {
      System.out.println("threw in split " + e.getClass() + " with message: " + e.getMessage());
    }
    return v;
  }

  /**Gets the preferred size of the ui. These values are used in displaying the scrollpane in particular*/
  public Dimension getPreferredSize()
  {
    return new Dimension(160,1500);
  }
  /**
  GetValue Gets the value of a string of the form name=value
  @param nameValue contains a string of the format "name=value"
  @return The value part
  */
  private String GetValue(String nameValue)
  {
    String out_value;
    out_value = nameValue.substring(nameValue.indexOf("=")+1);
    return out_value.replace('"',' ').trim();
  }

  /**
  isAttribute will Return true if the string is of the form name=value
  @param s is the string to be tested
  @return True if string is of the form name=value otherwise false
  */
  private boolean isAttribute(String s)
  {
    if (s.indexOf("=") > 1)
      return true;
    else
      return  false;
  }

  /**
  drawSelect will draw the tag select, option onto the screen
  @param g graphics object
  @param i the index of where in the vector we are
  @return The index of where the final select related
                tag was found
  */

  private int drawSelect(Graphics g,int i)
  {
    Integer temp1,temp2,temp4;
    Boolean temp3;
    int intOptionWidth;
    String in_strTitle,in_strName,in_strValue;
    int in_intName,in_intValue;
    boolean in_bolMultiple;
    int in_intTabIndex;
    intOptionWidth = 0;
    try
    {
      i++;
      in_strTitle     = clsScreen.elementAt(i++).toString();
      in_strName      = clsScreen.elementAt(i++).toString();
      in_strValue     = clsScreen.elementAt(i++).toString();
      temp1           = (Integer)clsScreen.elementAt(i++);
      in_intName      = temp1.intValue();
      temp2           = (Integer)clsScreen.elementAt(i++);
      in_intValue     = temp2.intValue();
      temp3           = (Boolean)clsScreen.elementAt(i++);
      in_bolMultiple  = temp3.booleanValue();
      temp4           = (Integer)clsScreen.elementAt(i++);
      in_intTabIndex  = temp4.intValue();

      Choice clsPullDown = new Choice();
      currentFontMetrics = getFontMetrics(getFont());
      while (!clsScreen.elementAt(i).toString().equals(END_TAG_SELECT))
      {
        if (clsScreen.elementAt(i++).toString().equals(START_TAG_OPTION))
        {
          i++; //jumps to the title
          if (intOptionWidth < currentFontMetrics.stringWidth(clsScreen.elementAt(i).toString()))
            intOptionWidth = currentFontMetrics.stringWidth(clsScreen.elementAt(i).toString());
          clsPullDown.addItem(clsScreen.elementAt(i).toString());
          i++; //jumps over the onpick event at this stage
        }
      }
      clsPullDown.setBounds(x,y-ROW_HEIGHT,intOptionWidth+20,15);
      x+=4;
      add(clsPullDown);
    }
    catch (Exception e)
    {
      System.out.println("drawselect threw a " + e.getClass() + " with message: " + e.getMessage());
    }
    return i;
  }

/**
  Handles the go tags, it associates an actionlistener with the appropriate
  button
  @param g graphics object
  @param i current index of the vector
  @param button need this reference here to be able to add a linkListener
    to the button. All of this is done at runtime
  @return  The index of where the final go related
                tag was found*/
  private int handleGo(Graphics g,int i,Button b)
  {
    String strGoEventID;
    i++;
    strGoEventID = clsScreen.elementAt(i).toString();
    //set c_intGoEventID
    if (c_intDoFound == 1)
    {
      cls_DoButton1Listener = new LinkListener(strGoEventID,this);
      b.addActionListener(cls_DoButton1Listener);
    }
    else
    {
      cls_DoButton2Listener = new LinkListener(strGoEventID,this);
      b.addActionListener(cls_DoButton2Listener);
    }
    System.out.println("do go event: " + strGoEventID + " " +b);

    while (!clsScreen.elementAt(i).toString().equals(END_TAG_GO))
    {
      i++;
    }
    return i;
  }
/**
  Handles the prev tags, it associates an actionlistener with the appropriate
  menuitem
  @param g graphics object
  @param i current index of the vector
  menuItem need this reference here to be able to add a linkListener
    to the menuItem. All of this is done at runtime
  @return  The index of where the final prev related
                tag was found*/
  private int handlePrev(Graphics g,int i,Button b)
  {
    String strGoEventID;
    i++;
    strGoEventID = clsScreen.elementAt(i).toString();
    //set c_intGoEventID

    if (c_intDoFound == 1)
    {
      cls_DoButton1Listener = new LinkListener(strGoEventID,this);
      b.addActionListener(cls_DoButton1Listener);
    }
    else
    {
      cls_DoButton2Listener = new LinkListener(strGoEventID,this);
      b.addActionListener(cls_DoButton2Listener);
    }

    System.out.println("do prev event: " + strGoEventID + " " + b);
    while (!clsScreen.elementAt(i).toString().equals(END_TAG_PREV))
    {
      i++;
    }
    return ++i;
 }

/**
  Handles the refresh tags
  @param g graphics object
  @param i current index of the vector
  @return The index of where the final refresh related
                tag was found*/

  private int handleRefresh(Graphics g,int i)
  {
    return i;
  }

  /**
  Takes care of the do element, if a do element is found, it will create
  a menuitem for it
  @param g graphics object
  @param i current index of the vector
  @return The index of where the final refresh related
                tag was found
  */
  private int drawDo(Graphics g,int i)
  {
    String doItem = new String(""); //initialise the string to empty string
    Button btnGeneral = null;       //in case of no label in the wml
    String type = new String("");
    boolean bolRenderDo = false;
    try
    {
      if (!bolRunOnce)
      {
        while (!clsScreen.elementAt(i).toString().equals(END_TAG_DO))
        {
          i++; //type
          while (isAttribute(clsScreen.elementAt(i).toString()))
          {
          //checks if the string contains the keyword label,
          //if it does, the actual label is extracted and shown in the menu
            if (clsScreen.elementAt(i).toString().indexOf("type") >= 0)
            {
              //this is done for future use where the usersagent want to
              //show different widgets for different types
              bolRenderDo = true;
              btnGeneral = null; //clears the button... a new do exists
            } //end if

            if (clsScreen.elementAt(i).toString().indexOf("label") >= 0)
            {
              doItem = GetValue(clsScreen.elementAt(i).toString());
              c_intDoFound++;
              btnGeneral = null; //clears the button... a new do exists
              if ((c_intDoFound == 1) && (bolRenderDo))
              {
                if (b1 == null)
                {
                  Button b1 = new Button(doItem);
                }
                else
                  b1.setLabel(doItem);
                btnGeneral = b1;
              }//end if

              if ((c_intDoFound == 2) && (bolRenderDo))
              {
                if (b2 == null)
                {
                  Button b2 = new Button(doItem);
                }
                else
                  b2.setLabel(doItem);
                btnGeneral = b2;
              }//end if
            }//end if
            i++;
          }//end while
         // i++;
        //handle tags in here

        if ((c_intDoFound==1) && (cls_DoButton1Listener != null))
          btnGeneral.removeActionListener(cls_DoButton1Listener);
        if ((c_intDoFound==2) && (cls_DoButton2Listener != null))
          btnGeneral.removeActionListener(cls_DoButton2Listener);

        if (clsScreen.elementAt(i).toString().equals(START_TAG_GO))
        {
          System.out.println("go tag found");
          i = handleGo(g,i,btnGeneral);
        }
        else if(clsScreen.elementAt(i).toString().equals(START_TAG_PREV))
        {
          if (btnGeneral == null) //this happens when no label was specified in the wml
          {
            doItem = new String("Prev"); //prev as standard label
            if (bolRenderDo)
            {
              if (b2 == null)
              {
                Button b2 = new Button(doItem);
              }
              else
                b2.setLabel(doItem);
              btnGeneral = b2;
            }//end if
          }
        i = handlePrev(g,i,btnGeneral);
        }
        else if(clsScreen.elementAt(i).toString().equals(START_TAG_REFRESH))
        {
          i = handleRefresh(g,i);
        }
      }
   //     frame.setMenuBar (menuBar);
   btnGeneral.repaint(); //forces a repaint to show the new text on the button
   btnGeneral.validate();
    }
    else
    {
      while ((clsScreen.elementAt(i) == null) || (!clsScreen.elementAt(i).toString().equals(END_TAG_DO)))
      {
        i++; //type
        while ((clsScreen.elementAt(i) == null) || (isAttribute(clsScreen.elementAt(i).toString())))
        {
          i++;
        }

⌨️ 快捷键说明

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