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

📄 taghandler.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
          newset.addAttributes(set);          newset.addAttribute("u", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "u");        }      }      if (command.equals("<br> Tag")) {// text format        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        AttributeSet oldset = thepane.getCharacterAttributes();        SimpleAttributeSet newset = new SimpleAttributeSet();        newset.addAttributes(oldset);        newset.addAttribute("br", "");        thepane.setCharacterAttributes(newset, false);        button.setAction(new DefaultEditorKit.InsertBreakAction());        button.doClick();        thepane.setCharacterAttributes(oldset, true);      }      if (command.equals("<img> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        AttributeSet oldset = thepane.getCharacterAttributes();        SimpleAttributeSet newset = new SimpleAttributeSet();        newset.addAttributes(oldset);        GlobalControlCounter++;        newset.addAttribute("img", new Integer(GlobalControlCounter).toString());        img i = new img(thepane, GlobalControlCounter);        cardControls.add(i);        int pos = thepane.getCaretPosition();        thepane.setSelectionStart(thepane.getCaretPosition() - 1);        thepane.setSelectionEnd(thepane.getCaretPosition());        thepane.setCharacterAttributes(newset, false);        thepane.setSelectionStart(pos);        thepane.setSelectionEnd(pos);      }      if (command.equals("<p> Tag")) {        button.setAction(new DefaultEditorKit.InsertBreakAction());        button.doClick();        MutableAttributeSet set = new SimpleAttributeSet();        StyleConstants.setAlignment(set, StyleConstants.ALIGN_LEFT);        StyleConstants.setFontFamily(set, "Default");        gp.setParagraphAttributes(set, true);      }      if (command.equals("<pre> Tag")) {        button.setAction(new DefaultEditorKit.InsertBreakAction());        button.doClick();        MutableAttributeSet set = new SimpleAttributeSet();        StyleConstants.setAlignment(set, StyleConstants.ALIGN_LEFT);        StyleConstants.setFontFamily(set, "Serif");        set.addAttribute("pre", "");        gp.setParagraphAttributes(set, true);      }      if (command.equals("<input> Tag")) {// user input        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        AttributeSet oldset = thepane.getCharacterAttributes();        SimpleAttributeSet newset = new SimpleAttributeSet();        newset.addAttributes(oldset);        GlobalControlCounter++;        newset.addAttribute("input", new Integer(GlobalControlCounter).toString());        input i = new input(graphicsPane, GlobalControlCounter, border);        cardControls.add(i);        int pos = thepane.getCaretPosition();        thepane.setSelectionStart(thepane.getCaretPosition() - 1);        thepane.setSelectionEnd(thepane.getCaretPosition());        thepane.setCharacterAttributes(newset, false);        thepane.setSelectionStart(pos);        thepane.setSelectionEnd(pos);      }      if (command.equals("<optgroup> Tag"))        currentOptionDesigner.addOptGroup();        currentOptionDesigner.requestFocus();      if (command.equals("<option> Tag"))        currentOptionDesigner.addOption();        currentOptionDesigner.requestFocus();      if (command.equals("<select> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        AttributeSet oldset = thepane.getCharacterAttributes();        SimpleAttributeSet newset = new SimpleAttributeSet();        newset.addAttributes(oldset);        GlobalControlCounter++;        newset.addAttribute("select", new Integer(GlobalControlCounter).toString());        select s = new select(graphicsPane, GlobalControlCounter, border);        cardControls.add(s);        int pos = thepane.getCaretPosition();        thepane.setSelectionStart(thepane.getCaretPosition() - 1);        thepane.setSelectionEnd(thepane.getCaretPosition());        thepane.setCharacterAttributes(newset, false);        thepane.setSelectionStart(pos);        thepane.setSelectionEnd(pos);      }      if (command.equals("<fieldset> Tag")){        GlobalControlCounter++;        SimpleAttributeSet attr = new SimpleAttributeSet();        attr.addAttribute("counter", new Integer(GlobalControlCounter).toString());        SimpleAttributeSet tag = new SimpleAttributeSet();        tag.addAttribute("fieldset", attr);        if (graphicsPane.hasFocus())          gp.setCharacterAttributes(tag, false);        else          focusControl.setCharacterAttributes(tag, false);        disableControls("fieldset");      }      if (command.equals("<setvar> Tag")) { // variables        if (CardTagsCreated && currentTagsDesigner.isVisible()) {          if (currentTagsDesigner.isVisible())            currentTagsDesigner.addSetvarTag();        }        else if (currentDoDesigner.isVisible())          currentDoDesigner.addSetvarTag();        else {          JTextPane thepane;          if (focusControl == null) {            thepane = gp;          }          else            thepane = focusControl;          AttributeSet oldset = thepane.getCharacterAttributes();          SimpleAttributeSet newset = new SimpleAttributeSet();          newset.addAttributes(oldset);          GlobalControlCounter++;          newset.addAttribute("variable", new Integer(GlobalControlCounter).toString());          variable v = new variable(graphicsPane, GlobalControlCounter);          cardControls.add(v);          int pos = thepane.getCaretPosition();          thepane.setSelectionStart(thepane.getCaretPosition() - 1);          thepane.setSelectionEnd(thepane.getCaretPosition());          thepane.setCharacterAttributes(newset, false);          thepane.setSelectionStart(pos);          thepane.setSelectionEnd(pos);        }      }      if (command.equals("<table> Tag")) {// tables        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        AttributeSet oldset = thepane.getCharacterAttributes();        SimpleAttributeSet newset = new SimpleAttributeSet();        newset.addAttributes(oldset);        GlobalControlCounter++;        newset.addAttribute("table", new Integer(GlobalControlCounter).toString());        table t = new table(graphicsPane, GlobalControlCounter);        int pos = thepane.getCaretPosition();        thepane.setSelectionStart(thepane.getCaretPosition() - 1);        thepane.setSelectionEnd(thepane.getCaretPosition());        thepane.setCharacterAttributes(newset, false);        thepane.setSelectionStart(pos);        thepane.setSelectionEnd(pos);        t.addDefaultContent();        cardControls.add(t);      }      if (command.equals("<td> Tag")) {        try {          table t = (table) controlContainer;          t.addColumn();        }        catch (NullPointerException nuullerr) {}      }      if (command.equals("<tr> Tag")) {        try {          table t = (table) controlContainer;          t.addRow();        }        catch (NullPointerException nullerr) {}      }    }  }  /////////////////////////////////////////////////////////////////////////  /////// Helper functions for IDEFrame  /////////////////////////////////////////////////////////////////////////  /**   * Sets the keyword finder to be used in this TagHandler.   * @param KeywordFinder keywordfinder.   */  public void setKeywordFinder(KeywordFinder kf) {    keywordFinder = kf;  }  /**   * Performs the actual switching of data when a different tab is clicked.   */  public void switchCards() {    if (CardPane.getTabCount() > 0) {      int index = CardPane.getSelectedIndex();        // save the data        if ((previndex > -1) && (previndex != index)) {          Vector data = new Vector();          data.add(new Integer(GlobalControlCounter));          data.add(gp.getStyledDocument());          data.add(new Boolean(CardTagsCreated));          data.add(cardControls);          data.add(CardLevelTags);          openData.setElementAt(data, previndex);        }        // get the data        if (previndex != index) {          Vector data = (Vector) openData.get(index);          GlobalControlCounter = ((Integer) data.get(0)).intValue();          gp.setStyledDocument((DefaultStyledDocument) data.get(1));          CardTagsCreated = ((Boolean) data.get(2)).booleanValue();          cardControls = (Vector) data.get(3);          CardLevelTags = (CardTags) data.get(4);          gp.setVisible(false);          gp.setVisible(true);          previndex = index;        }    }  }  /**   * Creates the cards of a deck from the text supplied.  Does not do   * any syntax checking or parsing yet.   * @param String text - the contents of a deck in text.   */  public void createCards(String text) {    // first be sure to remove any tabs previously set    CardPane.removeAll();    openData = new Vector();    CardCounter = -1;    // look for wml and delete everything before it, including wml tag    // look for /wml and delete everything after it, including /wml tag    // if either tag does not exist report an error and stop conversion    Vector cardData = new Vector();    int pos = -1;    int wmlstart = -1;    int wmlend =  -1;    StringTokenizer st = new StringTokenizer(text, "<", true);    while (st.hasMoreTokens()) {      String s = st.nextToken();      if (s.trim().indexOf("wml") == 0) {        wmlstart = text.indexOf("wml", pos);        int test = text.indexOf("<", wmlstart + 1); // perform a test        int end = text.indexOf(">", wmlstart + 1);  // to see if <wml> tag        if (end > test) // ends with the proper closing character.          wmlstart = test;  // if it does not, do not overwrite anything,        else          wmlstart = end + 1; // if it does, then don't include closing character.      }      if (s.trim().indexOf("/wml") == 0) {        wmlend = pos;      }      pos = pos + s.length();    }    boolean error = true;    try {      if (wmlstart > -1) {        if (wmlend > -1) {          text = text.substring(wmlstart, wmlend);          error = false;        }        else {          Statusbar.setText("Error: no </wml> tag found.");        }      }      else {        Statusbar.setText("Error: no <wml> tag found.");      }    }    catch (StringIndexOutOfBoundsException sioberr) {      Statusbar.setText("Error: cannot process text for Graphical Editor");    }    if (!error) {      int cardcount = 0;      boolean carderror = false;      pos = -1;      int cardstart = -1;      int cardend = -1;      st = new StringTokenizer(text, "<", true);      while (st.hasMoreTokens()) {        String s = st.nextToken();        if ((s.trim().indexOf("card") == 0) && (cardstart > -1)) {          Statusbar.setText("Error: stopped processing at card #" + new Integer(cardcount).toString());          carderror = true;        }        if ((s.trim().indexOf("card") == 0) && (cardstart == -1)) {          cardstart = pos - 1;        }        if (s.trim().indexOf("card") == 0) {          cardcount++;        }        if ((s.trim().indexOf("/card") == 0) && (cardstart == -1)) {          Statusbar.setText("Error: stopped processing after card #" + new Integer(cardcount).toString());          carderror = true;        }        if ((s.trim().indexOf("/card") == 0) && (cardstart > -1) &&            (cardend == -1)) {          cardend = pos;        }        pos = pos + s.length();        if ((cardstart > - 1) && (cardend > -1)) {          try {            if (!carderror) {              cardData.add(text.substring(cardstart, cardend) + "</card>");              cardstart = cardend = -1;            }          }          catch (StringIndexOutOfBoundsException siobe2) {            Statusbar.setText("Error: stopped processing at card #" + cardcount);          }        }      }      for (int c = 0; c < cardData.size(); c++) {        Converter conv = new Converter(gp);        conv.toGraphics((String) cardData.get(c));      }    }  }  /**   * Merges the card data with the rest of the WML deck data.   * @param String cardData - the data converted.   * @param String deckData - the rest of the WML deck.   * @return String text - the merged deck and cards.   *   */  public String mergeCards(String cardData, String deckData) {    Hashtable mergepoints = getMergePositions(deckData);    String header = "";    String footer = "";    String template = "";    try {      int pos = ((Integer) mergepoints.get("wml")).intValue();      int end = deckData.indexOf(">", pos);      header = deckData.substring(0, end + 1) + "\n";    }

⌨️ 快捷键说明

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