示例#1
0
  /** Create a new config editor that isn't attached to any ViperData. */
  public ConfigEditor() {
    super(new JTree());
    popup = new ConfigEditPopup();
    getTree()
        .addMouseListener(
            new MouseAdapter() {
              public void mousePressed(MouseEvent e) {
                maybeShowPopup(e);
                TreePath p = getTree().getClosestPathForLocation(e.getX(), e.getY());
                Object end = p.getLastPathComponent();
                if (end instanceof Config) {
                  EventQueue.invokeLater(new CheckIfExpanded(p));
                }
              }

              public void mouseReleased(MouseEvent e) {
                maybeShowPopup(e);
              }

              private void maybeShowPopup(MouseEvent e) {
                if (e.isPopupTrigger()) {
                  popup.show(e.getComponent(), e.getX(), e.getY());
                }
              }
            });
    model = new ViperTreeModel(this);
    model.addTreeToSelect(getTree());
    // getTree().setRootVisible(false);
    expandedNodes = new HashSet();
    getTree().setModel(model);
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes.
    getTree().addTreeSelectionListener(new MySelectionChangeListener());
  }