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

📄 optiondesigner.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }      }      catch (NullPointerException nullerr) {}      catch (ArrayIndexOutOfBoundsException arrerr) {}    }    if (b.getActionCommand().equals("left")) {      DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1);      DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent();      DefaultMutableTreeNode superparent = null;      try {        superparent = (DefaultMutableTreeNode) parent.getParent();        int newNodeIndex = 0;        if (superparent == null) {          superparent = (DefaultMutableTreeNode) parent.getRoot();          newNodeIndex = superparent.getIndex(child);        }        else {          newNodeIndex = superparent.getIndex(parent);        }        tm.removeNodeFromParent(child);        tm.insertNodeInto(child, superparent, newNodeIndex);        OptionTree.setSelectionPath(new TreePath(child.getPath()));        updateSample();      }      catch (NullPointerException nullerr) {}    }    if (b.getActionCommand().equals("right")) {      try {        DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1);        DefaultMutableTreeNode parent = child.getNextSibling();        if (parent.getAllowsChildren()) {          try {            tm.removeNodeFromParent(child);            tm.insertNodeInto(child, parent, 0);            OptionTree.setSelectionPath(new TreePath(child.getPath()));            updateSample();          }          catch (ArrayIndexOutOfBoundsException err) {}        }      }      catch (NullPointerException nullerr) {}      catch (ArrayIndexOutOfBoundsException bounderr) {}    }  }  /**   * When a node is selected, updates the path.   */  private void OptionTree_valueChanged(TreeSelectionEvent e) {    path = e.getPath();  }  /**   * Updates the tree and if right clicked displays a context   * menu.   */  private void OptionTree_mouseClicked(MouseEvent e) {    updateSample();    if (e.getModifiers() == RIGHT_MOUSE_BUTTON) {      TreePopupMenu.show((JTree) e.getSource(), e.getX(), e.getY());    }  }  /**   * Updates the sample display if a tree node value is changed.   */  private void tm_treeNodesChanged(TreeModelEvent e) {    int cnt = path.getPathCount();    DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1);    if (child.getAllowsChildren()) {      optgroupNode n = (optgroupNode) child;     n.setTitle((String) child.getUserObject());    }    else {      optionNode n = (optionNode) child;      n.setData((String) child.getUserObject());    }    updateSample();  }  /**   * Displays the proper properties dialog box for the selected node.   */  private void NodePropertiesButton_actionPerformed(ActionEvent e) {    try {      int cnt = path.getPathCount();      DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1);      GraphicalControlsProperties gcp = new GraphicalControlsProperties();      if (child.getAllowsChildren()) {        optgroupNode n = (optgroupNode) child;        gcp.showOptionGroupPanel(n.getTitle(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setTitle((String) dialogData.get(0));        n.setExtra((String) dialogData.get(1));        updateSample();      }      else {        optionNode n = (optionNode) child;        gcp.showOptionPanel(n.getOnpick(), n.getTitle(), n.getValue(), n.getExtra());        gcp.show();        Vector dialogData = gcp.getData();        n.setOnpick((String) dialogData.get(0));        n.setTitle((String) dialogData.get(1));        n.setValue((String) dialogData.get(2));        n.setExtra((String) dialogData.get(3));        updateSample();      }    }    catch (NullPointerException nullerr) {}  }  /**   * Performs the actual construction of the sample that is displayed in   * preview pane.   */  private void updateSample() {    try {      int cnt = path.getPathCount();      DefaultMutableTreeNode child = (DefaultMutableTreeNode) path.getPathComponent(cnt -1);      DefaultMutableTreeNode parent = (DefaultMutableTreeNode) child.getParent();      PreviewPane.requestFocus();      PreviewPane.setEditable(true);      PreviewPane.setText("");      GridLayout grid = new GridLayout();      grid.setRows(parent.getChildCount());      grid.setColumns(1);      JPanel p = new JPanel();      p.setLayout(grid);      p.setSize(p.getWidth(), 13 * parent.getChildCount());      JLabel l = new JLabel();      int nodeIndex = parent.getIndex(child);      for (int i = 0; i < parent.getChildCount(); i++) {        DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getChildAt(i);        if (node.getAllowsChildren()) {          optgroupNode n = (optgroupNode) node;          BorderLayout border = new BorderLayout();          JPanel compoundPanel = new JPanel();          compoundPanel.setLayout(border);          // add the icon          l = new JLabel("");          l.setIcon(image9);          l.setForeground(fg);          l.setBackground(bkg);          l.setOpaque(true);          compoundPanel.add(l, BorderLayout.WEST);          // add the text          l = new JLabel(n.getTitle());          l.setFont(f);          if (i == nodeIndex) {            l.setForeground(bkg);            l.setBackground(fg);          }          else {            l.setForeground(fg);            l.setBackground(bkg);          }          l.setOpaque(true);          //l.setSize(p.getWidth(), l.getHeight());          compoundPanel.add(l, BorderLayout.CENTER);          p.add(compoundPanel);        }        else {          optionNode n = (optionNode) node;          BorderLayout border = new BorderLayout();          JPanel compoundPanel = new JPanel();          compoundPanel.setLayout(border);          String s  = n.getData();          if (s.equals(""))            s = n.getTitle();          if (i == nodeIndex) {            // add the icon            l = new JLabel("");            l.setIcon(image10);            l.setForeground(fg);            l.setBackground(bkg);            l.setOpaque(true);            compoundPanel.add(l, BorderLayout.WEST);            // add the text            l = new JLabel(s);            l.setFont(f);            l.setForeground(bkg);            l.setBackground(fg);            l.setOpaque(true);            compoundPanel.add(l, BorderLayout.CENTER);            p.add(compoundPanel);          }          else {            // add the icon            l = new JLabel("");            l.setIcon(image8);            l.setForeground(fg);            l.setBackground(bkg);            l.setOpaque(true);            compoundPanel.add(l, BorderLayout.WEST);            // add the text            l = new JLabel(s);            l.setFont(f);            l.setForeground(fg);            l.setBackground(bkg);            l.setOpaque(true);            compoundPanel.add(l, BorderLayout.CENTER);            p.add(compoundPanel);          }        }      }      PreviewPane.insertComponent(p);      PreviewPane.setEditable(false);    }    catch (NullPointerException nullerr) {}  }  /**   * Inner Class - encapsulates all the data that an optgroup tag can   * contain and provides methods for accessing that data.   */  private class optgroupNode extends DefaultMutableTreeNode {    private String Title = "";    private String Extra = "";    /**     * Constructs an optgroupNode.     * @param String s - the title of the optgroup, used as title for the node.     */    public optgroupNode(String s) {      super(s);      setUserObject(s);      setAllowsChildren(true);      Title = s;    }    /**    * Constructs an optgroupNode.    * @param String s - the title of the optgroup, used as title for the node.    * @param String extra - extra tag attributes such as id and class.     */    public optgroupNode(String s, String extra) {      super(s);      setUserObject(s);      setAllowsChildren(true);      Title = s;      Extra = extra;    }    /**     * Gets the title attribute of the node.     * @return String title.     */    public String getTitle() {      return Title;    }    /**     * Sets this node's title attribute.     * @param String title.     */    public void setTitle(String title) {      Title = title;      setUserObject(title);    }    /**     * Gets the extra attribute of the node.     * @return String title.     */    public String getExtra() {      return Extra;    }    /**     * Sets this node's extra attribute.     * @param String title.     */    public void setExtra(String extra) {      Extra = extra;    }  }  private class optionNode extends DefaultMutableTreeNode {    private String Onpick = "";    private String Title = "";    private String Value = "";    private String Extra = "";    /**     * extra text that can be placed between the &lt;option&gt;&lt;/option&gt; tags.     */    private String Data =  "";    /**     * Constructs a new optionNode.     * @param String data.     * @param String title.     * @param String value.     * @param String onpick.     */    public optionNode(String data, String title, String value, String onpick) {      setUserObject(data);      setAllowsChildren(false);      Data = data;      Title = title;      Value = value;      Onpick = onpick;    }    /**     * Constructs a new optionNode.     * @param String data.     * @param String title.     * @param String value.     * @param String onpick.     * @param String extra.     */    public optionNode(String data, String title, String value, String onpick, String extra) {      setUserObject(data);      setAllowsChildren(false);      Data = data;      Title = title;      Value = value;      Onpick = onpick;      Extra = extra;    }    /**     * Gets the node's data attribute.     * @return String data.     */    public String getData() {      return Data;    }    /**     * Gets the node's title attribute.     * @return String title.     */    public String getTitle() {      return Title;    }    /**     * Gets the node's value attribute.     * @return String value.     */    public String getValue() {      return Value;    }    /**     * Gets the node's onpick attribute.     * @return String onpick.     */    public String getOnpick() {      return Onpick;    }    /**     * Gets the node's extra attribute.     * @return String extra.     */    public String getExtra() {      return Extra;    }    /**     * Sets the node's title attribute.     * @param String title.     */    public void setTitle(String title) {      Title = title;    }

⌨️ 快捷键说明

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