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

📄 cardleveltagsdesigner.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /**     *Gets the data of the Node and returns it as a Vector.     * @return Vector v - the data in the following format:<br>     * value<br>     * name<br>     * extra     */    public Vector getData() {      Vector v = new Vector();      v.add(value);      v.add(name);      v.add(extra);      return v;    }    public String getValue() {      return value;    }    public String getName() {      return name;    }    public String getExtra() {      return extra;    }    /**     * Updates the Node's data and visual component.     */    public void updateNode() {      String s = "<setvar";      if (!value.equals(""))        s = s + " value=\"" + value + "\"";      if (!name.equals(""))        s = s + " name=\"" + name + "\"";      if (extra.length() > 0)        s = s + " " + extra.trim();      s = s + "/>";      setUserObject(s);    }    /**     * Updates a node data from a String.     * @param String s - the data to update the node with.     */    public void updateNode(String s) {      value = "";      name = "";      extra = "";      int start = s.indexOf("value");      if (start > -1) {        start = s.indexOf("=" , start + 1);        if (start > -1) {          start = s.indexOf("\"" , start + 1);          if (start > -1) {            int end = s.indexOf("\"" , start + 1);            if (end < 0)              end = s.length();            value = s.substring(start + 1, end);          }        }      }      start = s.indexOf("name");      if (start > -1) {        start = s.indexOf("=" , start + 1);        if (start > -1) {          start = s.indexOf("\"" , start + 1);          if (start > -1) {            int end = s.indexOf("\"" , start + 1);            if (end < 0)              end = s.length();            name = s.substring(start + 1, end);          }        }      }      start = s.indexOf("id=\"");      if (start > -1) {        start = start + 4;        int end = s.indexOf("\"", start);        extra = extra + " " + s.substring(start - 4, end + 1);      }      start = s.indexOf("class=\"");      if (start > -1) {        start = start + 7;        int end = s.indexOf("\"", start);        extra = extra + " " + s.substring(start - 7, end + 1);      }      start = s.indexOf("xml:lang=\"");      if (start > -1) {        start = start + 10;        int end = s.indexOf("\"", start);        extra = extra + " " + s.substring(start - 10, end + 1);      }      setUserObject(s);    }  }  // Actions  /**   * Calls up the proper properties dialog based on the selected node.   */  private void NodePropertiesButton_actionPerformed(ActionEvent e) {    try {      int cnt = path.getPathCount();      EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);      GraphicalControlsProperties gcp = new GraphicalControlsProperties();      if (child.getNodeType().equals("do")) {        doNode n = (doNode) child;        gcp.showDoPanel(n.getType(), n.getLabel(), n.getName(), n.getOpt(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("go")) {        goNode n = (goNode) child;        gcp.showGoPanel(n.getHref(), n.getCharset(), n.getMethod(), n.getSendref(),                        n.getCache(), n.getEnctype(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("onevent")) {        oneventNode n = (oneventNode) child;        gcp.showOneventPanel(n.getType(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("timer")) {        timerNode n = (timerNode) child;        gcp.showTimerPanel(n.getValue(), n.getName(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("setvar")) {        setvarNode n = (setvarNode) child;        gcp.showSetvarPanel(n.getValue(), n.getName(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("postfield")) {        postfieldNode n = (postfieldNode) child;        gcp.showPostfieldPanel(n.getValue(), n.getName(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("noop")) {        noopNode n = (noopNode) child;        JPanel p = new JPanel();        p.setName(n.getExtra());        new SpecialAttributesProperties(p, false);        Vector dialogData = new Vector();        dialogData.add(p.getName());        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("prev")) {        prevNode n = (prevNode) child;        JPanel p = new JPanel();        p.setName(n.getExtra());        new SpecialAttributesProperties(p, false);        Vector dialogData = new Vector();        dialogData.add(p.getName());        n.setData(dialogData);        updateTree();      }      else if (child.getNodeType().equals("refresh")) {        refreshNode n = (refreshNode) child;        JPanel p = new JPanel();        p.setName(n.getExtra());        new SpecialAttributesProperties(p, false);        Vector dialogData = new Vector();        dialogData.add(p.getName());        n.setData(dialogData);        updateTree();      }      tm.reload();      TagTree.setSelectionPath(new TreePath(child.getPath()));    }    catch (NullPointerException nullerr) {}  }  /**   * update the path to the selected node.   */  private void TagTree_valueChanged(TreeSelectionEvent e) {    path = e.getPath();  }  /**   * Mouse handler for the tree, detects clicks and if the   * tree receives a right click a context sensitive menu   * is popup up.   */  private void TagTree_mouseClicked(MouseEvent e) {    updateTree();    if (e.getModifiers() == RIGHT_MOUSE_BUTTON) {      TreePopupMenu.show((JTree) e.getSource(), e.getX(), e.getY());    }  }  private void Popup_actionPerformed(ActionEvent e) {    String s = e.getActionCommand();    if (s.equals("Cut")) {      try {        int cnt = path.getPathCount();        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();        TempNode = child;        tm.removeNodeFromParent(child);        try {          EnhancedTreeNode before = (EnhancedTreeNode) parent.getFirstChild();          TagTree.setSelectionPath(new TreePath(before.getPath()));        }        catch (NoSuchElementException elemerr) {}        updateTree();      }      catch (NullPointerException nullerr) {}    }    if (s.equals("Copy")) {      try {        int cnt = path.getPathCount();        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        TempNode = child;        updateTree();      }      catch (NullPointerException nullerr) {}    }    if (s.equals("Paste")) {    try {        int cnt = path.getPathCount();        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();        int index = parent.getIndex(child);        tm.insertNodeInto(TempNode, parent, index);        TagTree.setSelectionPath(path);        updateTree();      }      catch (ArrayIndexOutOfBoundsException arrerr) {}      catch (NullPointerException nullerr) {        try {          tm.insertNodeInto(TempNode, (EnhancedTreeNode) tm.getRoot(), 0);          TagTree.setSelectionPath(path);          updateTree();        }        catch (IllegalArgumentException iae) {}        catch (NullPointerException nullerr2) {}      }    }    if (s.equals("Delete")) {      try {        int cnt = path.getPathCount();        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();        tm.removeNodeFromParent(child);        try {          EnhancedTreeNode before = (EnhancedTreeNode) parent.getFirstChild();          TagTree.setSelectionPath(new TreePath(before.getPath()));        }        catch (NoSuchElementException elemerr) {}        updateTree();      }      catch (NullPointerException nullerr) {}    }    if (s.equals("Properties")) {      NodePropertiesButton.doClick();    }  }  /**   * Handler for the cursor buttons which allow the user to move node up and   * down, left and right.   */  private void moveItems_actionPerformed(ActionEvent e) {    JButton b = (JButton) e.getSource();    int cnt = path.getPathCount();    if (b.getActionCommand().equals("up")) {      try {        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();        int index = parent.getIndex(child);        index--;        if (index > -1) {          tm.removeNodeFromParent(child);          tm.insertNodeInto(child, parent, index);          TagTree.setSelectionPath(path);          updateTree();        }      }      catch (NullPointerException nullerr) {}      catch (ArrayIndexOutOfBoundsException arrerr) {}    }    if (b.getActionCommand().equals("down")) {      try {        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();        int index = parent.getIndex(child);        index++;        if (index < parent.getChildCount()) {          tm.removeNodeFromParent(child);          tm.insertNodeInto(child, parent, index);          TagTree.setSelectionPath(path);          updateTree();        }      }      catch (NullPointerException nullerr) {}      catch (ArrayIndexOutOfBoundsException arrerr) {}    }    if (b.getActionCommand().equals("left")) {      EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);      EnhancedTreeNode parent = (EnhancedTreeNode) child.getParent();      EnhancedTreeNode superparent = null;      try {        superparent = (EnhancedTreeNode) parent.getParent();        int newNodeIndex = 0;        if (superparent == null) {          superparent = (EnhancedTreeNode) parent.getRoot();          newNodeIndex = superparent.getIndex(child);        }        else {          newNodeIndex = superparent.getIndex(parent);        }        tm.removeNodeFromParent(child);        tm.insertNodeInto(child, superparent, newNodeIndex);        TagTree.setSelectionPath(new TreePath(child.getPath()));        updateTree();      }      catch (NullPointerException nullerr) {}    }    if (b.getActionCommand().equals("right")) {      try {        EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);        EnhancedTreeNode parent = (EnhancedTreeNode) child.getNextSibling();        if (parent.getAllowsChildren()) {          try {            tm.removeNodeFromParent(child);            tm.insertNodeInto(child, parent, 0);            TagTree.setSelectionPath(new TreePath(child.getPath()));            updateTree();          }          catch (ArrayIndexOutOfBoundsException err) {}        }      }      catch (NullPointerException nullerr) {}      catch (ArrayIndexOutOfBoundsException bounderr) {}    }  }  /**   * Used when a direct edit (3 clicks on a tree node) is performed.   * Not implemented yet.   */  private void tm_treeNodesChanged(TreeModelEvent e) {  }  // Helper functions  /**   * Updates the whole tree.  This occures when node properties change or   * nodes are moved, added, or deleted.   */  private void updateTree() {    try {      int cnt = path.getPathCount();      EnhancedTreeNode child = (EnhancedTreeNode) path.getPathComponent(cnt -1);      if (child.getNodeType().equals("do")) {        doNode node = (doNode) child;        node.updateNode();      }      if (child.getNodeType().equals("go")) {        goNode node = (goNode) child;        node.updateNode();      }      if (child.getNodeType().equals("onevent")) {        oneventNode node = (oneventNode) child;        node.updateNode();      }      if (child.getNodeType().equals("timer")) {        timerNode node = (timerNode) child;        node.updateNode();      }      if (child.getNodeType().equals("postfield")) {        postfieldNode node = (postfieldNode) child;        node.updateNode();      }      if (child.getNodeType().equals("setvar")) {        setvarNode node = (setvarNode) child;        node.updateNode();      }      if (child.getNodeType().equals("noop")) {        noopNode node = (noopNode) child;        node.updateNode();      }      if (child.getNodeType().equals("prev")) {        prevNode node = (prevNode) child;        node.updateNode();      }      if (child.getNodeType().equals("refresh")) {        refreshNode node = (refreshNode) child;        node.updateNode();      }    }    catch (NullPointerException nullerr) {}  }  /**   * Constructs the tree and adds the appropriate nodes based on the wml   * string passed in.   * @param String data - wml data with card level tags such as "do" and "ontimer."   * @return EnhancedTreeNode root - the root of the tree with child nodes added.   */  private EnhancedTreeNode Build_Tree(String data) {    data = cleanupData(data);    EnhancedTreeNode root = new EnhancedTreeNode("root");    EnhancedTreeNode parent = root;    StringTokenizer st = new StringTokenizer(data, "<");    while (st.hasMoreTokens()) {      String token = st.nextToken();      StringTokenizer temptokenizer = new StringTokenizer(token.trim());      String nodeType = temptokenizer.nextToken();      // Clean up nodeType, remove > or />      if (nodeType.indexOf("/>") > -1)        nodeType = nodeType.substring(0, nodeType.length() - 2);

⌨️ 快捷键说明

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