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

📄 taghandler.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        str = "<postfield name=\"name\" value=\"value\"/>";      if (command.equals("<select> Tag"))        str = "<select name=\"name\" title=\"title\"></select>";      if (command.equals("<fieldset> Tag"))        str = "<fieldset title=\"title\"></fieldset>";      if (command.equals("<setvar> Tag")) // variables        str = "<setvar name=\"name\" value=\"value\"/>";      if (command.equals("<table> Tag")) // tables        str = "<table columns=\"num\"></table>";      if (command.equals("<td> Tag"))        str = "<td></td>";      if (command.equals("<tr> Tag"))        str = "<tr></tr>";      if (command.equals("<access> Tag")) // security        str = "<access/>";      if (command.equals("comboBoxChanged")) {        JComboBox box = (JComboBox) e.getSource();        String s = (String) box.getSelectedItem();        str = "<onevent type=\"" + s + "\"></onevent>";      }    }    return str;  }  /**   * Called by the Graphical Editor, adds controls or sets attributes in   * the GraphicalTextpane to match the desired tag selected by the button pressed.   * @param ActionEvent e - the button pressed.   * @param JTextPane graphicsPane - the JTextPane to which the attributes or controls should be added.   * @param Border border - a custom border to be used when controls are selected.   */  public void doAction(ActionEvent e, JTextPane graphicsPane, Border border) {    String str = "";    String command = "";    theBorder = border;    JButton button = new JButton(); // button which gets assigned an action    gp = graphicsPane;    try {      JMenuItem mi = (JMenuItem) e.getSource();      command = mi.getActionCommand();    }    catch (ClassCastException cce) {      try {        JButton mi = (JButton) e.getSource();        command = mi.getActionCommand();      }      catch (ClassCastException cce2) {        JComboBox mi = (JComboBox) e.getSource();        command = mi.getActionCommand();      }    }    if (!command.equals("")) {      if (command.equals("<card> Tag")) {        createNewCard();      }      if (command.equals("<a> Tag")) { // links        GlobalControlCounter++;        SimpleAttributeSet attr = new SimpleAttributeSet();        attr.addAttribute("counter", new Integer(GlobalControlCounter).toString());        SimpleAttributeSet tag = new SimpleAttributeSet();        StyleConstants.setBackground(tag, gp.getForeground());        StyleConstants.setForeground(tag, gp.getBackground());        tag.addAttribute("a", attr);        if (graphicsPane.hasFocus())          gp.setCharacterAttributes(tag, false);        else          focusControl.setCharacterAttributes(tag, false);        disableControls("a");      }      if (command.equals("<anchor> Tag")) {        GlobalControlCounter++;        SimpleAttributeSet attr = new SimpleAttributeSet();        attr.addAttribute("counter", new Integer(GlobalControlCounter).toString());        SimpleAttributeSet tag = new SimpleAttributeSet();        StyleConstants.setBackground(tag, gp.getForeground());        StyleConstants.setForeground(tag, gp.getBackground());        tag.addAttribute("anchor", attr);        if (graphicsPane.hasFocus())          gp.setCharacterAttributes(tag, false);        else          focusControl.setCharacterAttributes(tag, false);        disableControls("anchor");      }      if (command.equals("<do> Tag")) { // actions        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addDoTag();        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("do", new Integer(GlobalControlCounter).toString());          doTag d = new doTag(graphicsPane, GlobalControlCounter);          cardControls.add(d);          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("<go> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addGoTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addGoTag();      }      if (command.equals("<noop> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addNoopTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addNoopTag();      }      if (command.equals("<prev> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addPrevTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addPrevTag();      }      if (command.equals("<refresh> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addRefreshTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addRefreshTag();      }      if (command.equals("<timer> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addTimerTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addTimerTag();      }      if (command.equals("comboBoxChanged")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        JComboBox mi = (JComboBox) e.getSource();        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addOneventTag((String) mi.getSelectedItem());        if (currentDoDesigner.isVisible())          currentDoDesigner.addOneventTag((String) mi.getSelectedItem());      }      if (command.equals("<postfield> Tag")) {        if (!CardTagsCreated) {          CardLevelTags = new CardTags(graphicsPane);          CardLevelTags.doDoubleClick();        }        if (currentTagsDesigner.isVisible())          currentTagsDesigner.addPostfieldTag();        if (currentDoDesigner.isVisible())          currentDoDesigner.addPostfieldTag();      }      if (command.equals("<big> Tag")) {// font styles        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("big") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setFontSize(newset, 16);          newset.addAttributes(set);          newset.addAttribute("big", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "big");        }      }      if (command.equals("<b> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("b") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setBold(set, true);          newset.addAttributes(set);          newset.addAttribute("b", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "b");        }      }      if (command.equals("<em> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("em") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setItalic(set, true);          StyleConstants.setFontSize(set, 14);          newset.addAttributes(set);          newset.addAttribute("em", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "em");        }      }      if (command.equals("<i> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("i") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setItalic(set, true);          newset.addAttributes(set);          newset.addAttribute("i", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "i");        }      }      if (command.equals("<small> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("small") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setFontSize(set, 8);          newset.addAttributes(set);          newset.addAttribute("small", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "small");        }      }      if (command.equals("<strong> Tag")) {        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("strong") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setBold(set, true);          StyleConstants.setFontSize(set, 14);          newset.addAttributes(set);          newset.addAttribute("strong", "");          thepane.setCharacterAttributes(newset, false);        }        else { // remove the attribute          removeAttributes(thepane, start, end, "strong");        }      }      if (command.equals("<u> Tag")) {        // add a u tag to this section        JTextPane thepane;        if (focusControl == null) {          thepane = gp;        }        else          thepane = focusControl;        int start = thepane.getSelectionStart();        int end = thepane.getSelectionEnd();        thepane.setCaretPosition(start);        AttributeSet oldset = thepane.getCharacterAttributes();        thepane.setSelectionStart(start);        thepane.setSelectionEnd(end);        if (oldset.getAttribute("u") == null) { // apply the attribute          SimpleAttributeSet newset = new SimpleAttributeSet();          MutableAttributeSet set = new SimpleAttributeSet();          StyleConstants.setUnderline(set, true);

⌨️ 快捷键说明

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