Пример #1
0
  public Browser(CavityNestingDB cndb) throws SQLException {
    super(new BorderLayout());
    setPreferredSize(new Dimension(300, 500));
    db = cndb;
    displayer = new NodeDisplay();

    top = new DefaultMutableTreeNode("CavityNestingDB");
    tree = new JTree(top);
    DefaultTreeSelectionModel selModel = new DefaultTreeSelectionModel();
    selModel.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionModel(selModel);

    tree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            if (e.isAddedPath()) {
              TreePath path = e.getPath();
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
              Object value = node.getUserObject();

              // System.out.println(String.valueOf(value));
              if (value instanceof CavityDBObject) {
                displayer.display((CavityDBObject) value);
              } else {
                // System.out.println(value.getClass().getSimpleName());
              }
            }
          }
        });

    JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    add(splitter, BorderLayout.CENTER);
    splitter.add(new JScrollPane(tree));
    splitter.add(displayer);

    populate();
  }
Пример #2
0
    /**
     * This is overridden to set <code>updatingListSelectionModel</code> and message super. This is
     * the only place DefaultTreeSelectionModel alters the ListSelectionModel.
     */
    public void resetRowSelection() {
      if (!updatingListSelectionModel) {
        updatingListSelectionModel = true;

        try {
          super.resetRowSelection();
        } finally {
          updatingListSelectionModel = false;
        }
      }

      // Notice how we don't message super if
      // updatingListSelectionModel is true. If
      // updatingListSelectionModel is true, it implies the
      // ListSelectionModel has already been updated and the
      // paths are the only thing that needs to be updated.
    }