?? optiondesigner.java
字號(hào):
/** * Sets the node's data attribute. * @param String data. */ public void setData(String data) { Data = data; } /** * Sets the node's title attribute. * @param String value. */ public void setValue(String value) { Value = value; } /** * Sets the node's onpick attribute. * @param String onpick. */ public void setOnpick(String onpick) { Onpick = onpick; } /** * Sets the node's extra attribute. * @param String extra. */ public void setExtra(String extra) { Extra = extra; } } /** * Collates all the dialog data into a string of WML text. * @return String text. */ public String getData() { DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot(); Enumeration enum = root.preorderEnumeration(); String s = ""; int tabCount = 0; Vector stack = new Vector(); while (enum.hasMoreElements()) { DefaultMutableTreeNode tn = (DefaultMutableTreeNode) enum.nextElement(); if (tn.getAllowsChildren()) { try { optgroupNode optgrpNode = (optgroupNode) tn; TreeNode[] t = optgrpNode.getPath(); int tabCounter = t.length - 2; if (tabCount > tabCounter) { s = s + (String) stack.get(stack.size() - 1); stack.remove(stack.size() - 1); } if (tabCount < tabCounter) { tabCount = tabCounter; } String title = optgrpNode.getTitle(); String extra = optgrpNode.getExtra(); s = s + "<optgroup"; if (!title.equals("")) s = s + " title=\"" + title + "\""; if (!extra.equals("")) s = s + " " + extra; s = s.trim() + ">"; stack.add(new String("</optgroup>")); } catch (ClassCastException classerr) {} } else { optionNode optNode = (optionNode) tn; TreeNode[] t = optNode.getPath(); int tabCounter = t.length - 2; if (tabCount > tabCounter) { try { s = s + (String) stack.get(stack.size() - 1); stack.remove(stack.size() - 1); } catch (ArrayIndexOutOfBoundsException arrerr) {} } if (tabCount < tabCounter) { tabCount = tabCounter; } String data = optNode.getData(); String title = optNode.getTitle(); String value = optNode.getValue(); String onpick = optNode.getOnpick(); String extra = optNode.getExtra(); if (data.equals("")) { s = s + "<option"; if (!title.equals("")) s = s + " title=\"" + title + "\""; if (!value.equals("")) s = s + " value=\"" + value + "\""; if (!onpick.equals("")) s = s + " onpick=\"" + onpick + "\""; if (!extra.equals("")) s = s + " " + extra; s = s.trim() + "/>"; } else { s = s + "<option"; if (!title.equals("")) s = s + " title=\"" + title + "\""; if (!value.equals("")) s = s + " value=\"" + value + "\""; if (!onpick.equals("")) s = s + " onpick=\"" + onpick + "\""; if (!extra.equals("")) s = s + " " + extra.trim(); s = s.trim() + ">" + data + "</option>"; } } } while (stack.size() > 0) { s = s + (String) stack.get(stack.size() - 1); stack.remove(stack.size() - 1); } return s; } /** * Adds an optgroup node to the tree. */ public void addOptGroup() { try{ int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); optgroupNode n = new optgroupNode("New Group"); tm.insertNodeInto(n, parent, parent.getChildCount()); OptionTree.setSelectionPath(new TreePath(n.getPath())); updateSample(); } catch (NullPointerException nullerr) { try{ DefaultMutableTreeNode parent = (DefaultMutableTreeNode) tm.getRoot(); optgroupNode n = new optgroupNode("New Group"); tm.insertNodeInto(n, parent, parent.getChildCount()); OptionTree.setSelectionPath(new TreePath(n.getPath())); updateSample(); } catch (NullPointerException mainnullerr) {} } } /** * Adds an option node to the tree. */ public void addOption() { try { int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); optionNode n = new optionNode("New Option", "", "New Option", ""); tm.insertNodeInto(n, parent, parent.getChildCount()); OptionTree.setSelectionPath(new TreePath(n.getPath())); updateSample(); } catch (NullPointerException nullerr) { try { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) tm.getRoot(); optionNode n = new optionNode("New Option", "", "New Option", ""); tm.insertNodeInto(n, parent, 0); OptionTree.setSelectionPath(new TreePath(n.getPath())); updateSample(); } catch (NullPointerException mainnullerr) {} } } /** * Creates the root node and adds the child nodes to the root * node based on the WML data passed in. * @param String data - the WML text with the "optgroup" and "option" tags. */ private DefaultMutableTreeNode Build_Tree(String data) { Vector stack = new Vector(); StringTokenizer st = new StringTokenizer(data, "<"); DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); while (st.hasMoreTokens()) { String token = st.nextToken(); StringTokenizer tokens = new StringTokenizer(token); if (token.indexOf("/optgroup") > -1) { // its a close tag token = ""; // remove the last node in the stack // if stack is empty after removal add to the root optgroupNode child = (optgroupNode) stack.get(stack.size() - 1); stack.remove(stack.size() - 1); if (stack.size() > 0) { optgroupNode parent = (optgroupNode) stack.get(stack.size() - 1); parent.add(child); } else root.add(child); } if (token.indexOf("optgroup") > -1) { //its an optgroup, look for attributes String title = ""; String extra = ""; if (token.indexOf("title") > - 1) { int i = token.indexOf("title"); i = token.indexOf("\"", i + 1); int e = token.indexOf("\"", i + 1); title = token.substring(i + 1, e); } int start = token.indexOf("id=\""); if (start > -1) { start = start + 4; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 4, end + 1); } start = token.indexOf("class=\""); if (start > -1) { start = start + 7; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 7, end + 1); } start = token.indexOf("xml:lang=\""); if (start > -1) { start = start + 10; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 10, end + 1); } optgroupNode node = new optgroupNode(title, extra); stack.add(node); } if (token.indexOf("/option") > - 1) { token = ""; } if (token.indexOf("option") > - 1) { // its an option, look for attributes String nodeData = ""; String newToken = ""; if (token.indexOf("/>") > - 1) { newToken = token.substring(0, token.length() - 2); } else { StringTokenizer tmp = new StringTokenizer(token, ">"); newToken = tmp.nextToken(); nodeData = tmp.nextToken(); } String title = ""; String onpick = ""; String value = ""; String extra = ""; if (newToken.indexOf("title") > - 1) { int i = newToken.indexOf("title"); i = newToken.indexOf("\"", i + 1); int e = newToken.indexOf("\"", i + 1); title = newToken.substring(i + 1, e); } if (newToken.indexOf("value") > - 1) { int i = newToken.indexOf("value"); i = newToken.indexOf("\"", i + 1); int e = newToken.indexOf("\"", i + 1); value = newToken.substring(i + 1, e); } if (newToken.indexOf("onpick") > - 1) { int i = newToken.indexOf("onpick"); i = newToken.indexOf("\"", i + 1); int e = newToken.indexOf("\"", i + 1); onpick = newToken.substring(i + 1, e); } int start = token.indexOf("id=\""); if (start > -1) { start = start + 4; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 4, end + 1); } start = token.indexOf("class=\""); if (start > -1) { start = start + 7; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 7, end + 1); } start = token.indexOf("xml:lang=\""); if (start > -1) { start = start + 10; int end = token.indexOf("\"", start); extra = extra + " " + token.substring(start - 10, end + 1); } // create a new node and add it to the last node in the stack // if stack is empty add to the root optionNode child = new optionNode(nodeData, title, value, onpick, extra); if (stack.size() > 0) { optgroupNode parent = (optgroupNode) stack.get(stack.size() - 1); parent.add(child); } else root.add(child); } } return root; } /** * Event handler for the popup menu, perform the appropriate action * for the menu item selected. */ private void Popup_actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equals("Cut")) { try { int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); TempNode = child; tm.removeNodeFromParent(child); try { DefaultMutableTreeNode before = (DefaultMutableTreeNode) parent.getFirstChild(); OptionTree.setSelectionPath(new TreePath(before.getPath())); } catch (NoSuchElementException elemerr) {} updateSample(); } catch (NullPointerException nullerr) {} } if (s.equals("Copy")) { try { int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); TempNode = child; updateSample(); } catch (NullPointerException nullerr) {} } if (s.equals("Paste")) { try { int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); int index = parent.getIndex(child); tm.insertNodeInto(TempNode, parent, index); OptionTree.setSelectionPath(path); updateSample(); } catch (ArrayIndexOutOfBoundsException arrerr) {} catch (NullPointerException nullerr) { try { tm.insertNodeInto(TempNode, (DefaultMutableTreeNode) tm.getRoot(), 0); OptionTree.setSelectionPath(path); updateSample(); } catch (IllegalArgumentException iae) {} catch (NullPointerException nullerr2) {} } } if (s.equals("Delete")) { try { int cnt = path.getPathCount(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent(); tm.removeNodeFromParent(child); try { DefaultMutableTreeNode before = (DefaultMutableTreeNode) parent.getFirstChild(); OptionTree.setSelectionPath(new TreePath(before.getPath())); } catch (NoSuchElementException elemerr) {} updateSample(); } catch (NullPointerException nullerr) {} } if (s.equals("Properties")) { NodePropertiesButton.doClick(); } }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -