public GAGenerationTreePanel(GAObjectMonitor monitor, String parentNodeTitle) {
    super();

    selectedChildrenPaths = new Vector();
    generationNumber = 1;
    saveNumber = 0;
    generations = new DefaultMutableTreeNode(parentNodeTitle);
    gaMonitor = monitor;

    setLayout(new BorderLayout());

    tree = new JTree(generations);

    tree.setShowsRootHandles(true);
    tree.setRootVisible(true);
    tree.putClientProperty("JTree.lineStyle", "Angled");

    // Add Action Listeners
    MyTreeSelectionListener listener = new MyTreeSelectionListener(monitor.getSelectionInfoPanel());
    MyTreeClickListener mlistener = new MyTreeClickListener();

    tree.addTreeSelectionListener(listener);
    tree.addMouseListener(mlistener);

    // Add Scroll Plane
    scrollPane = new JScrollPane(tree);
    add(scrollPane, BorderLayout.CENTER);

    // Add Menu Bar Functionality
    createMenuBar();
    add(menuBar, BorderLayout.NORTH);
  }
Пример #2
0
  /** Constructor. */
  public DatasetTreeView() {
    // the catalog tree
    tree =
        new JTree() {
          public JToolTip createToolTip() {
            return new MultilineTooltip();
          }
        };
    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
    tree.setCellRenderer(new MyTreeCellRenderer());

    tree.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            int selRow = tree.getRowForLocation(e.getX(), e.getY());
            if (selRow != -1) {
              TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
              if (node instanceof VariableNode) {
                VariableIF v = ((VariableNode) node).var;
                firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
              }
            }

            if ((selRow != -1) && (e.getClickCount() == 2)) {
              // acceptSelected();
            }
          }
        });

    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setToggleClickCount(1);
    ToolTipManager.sharedInstance().registerComponent(tree);

    // layout
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);
  }
Пример #3
0
  public ActionsTree() {
    myRoot = new DefaultMutableTreeNode(ROOT);

    myTree =
        new Tree(new MyModel(myRoot)) {
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            Rectangle visibleRect = getVisibleRect();
            Rectangle clip = g.getClipBounds();
            for (int row = 0; row < getRowCount(); row++) {
              Rectangle rowBounds = getRowBounds(row);
              rowBounds.x = 0;
              rowBounds.width = Integer.MAX_VALUE;

              if (rowBounds.intersects(clip)) {
                Object node = getPathForRow(row).getLastPathComponent();

                if (node instanceof DefaultMutableTreeNode) {
                  Object data = ((DefaultMutableTreeNode) node).getUserObject();
                  Rectangle fullRowRect =
                      new Rectangle(
                          visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
                  paintRowData(this, data, fullRowRect, (Graphics2D) g);
                }
              }
            }
          }
        };
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);

    myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
    myTree.setCellRenderer(new KeymapsRenderer());
    myTree.addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseMoved(MouseEvent e) {
            String description = getDescription(e);
            if (description != null) {
              ActionMenu.showDescriptionInStatusBar(true, myTree, description);
            } else {
              ActionMenu.showDescriptionInStatusBar(false, myTree, null);
            }
          }

          @Nullable
          private String getDescription(@NotNull MouseEvent e) {
            TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
            if (path == null) return null;

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            if (node == null) return null;

            Object userObject = node.getUserObject();
            if (!(userObject instanceof String)) return null;

            String actionId = (String) userObject;
            AnAction action = ActionManager.getInstance().getActionOrStub(actionId);
            if (action == null) return null;

            return action.getTemplatePresentation().getDescription();
          }
        });

    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    myComponent =
        ScrollPaneFactory.createScrollPane(
            myTree,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  }