Пример #1
0
  private void installAutoScroll() {
    myAutoScrollHandler =
        new AutoScrollToSourceHandler() {
          protected boolean isAutoScrollMode() {
            return isAutoScrollEnabled();
          }

          protected void setAutoScrollMode(boolean state) {
            // do nothing
          }

          protected void scrollToSource(Component tree) {
            updateSelectionFromTree();
          }

          protected boolean needToCheckFocus() {
            return false;
          }
        };
    myAutoScrollHandler.install(myTree);
  }
  @NotNull
  private JTree createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final Tree tree = new Tree(new DefaultTreeModel(root)) /* {
      @Override
      protected void paintComponent(Graphics g) {
        DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this);
        super.paintComponent(g);
      }
    }*/;
    tree.setOpaque(false);

    tree.setToggleClickCount(-1);
    SliceUsageCellRenderer renderer = new SliceUsageCellRenderer();
    renderer.setOpaque(false);
    tree.setCellRenderer(renderer);
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);

    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionPath(new TreePath(root.getPath()));
    // ActionGroup group =
    // (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
    // PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP,
    // ActionManager.getInstance());
    EditSourceOnDoubleClickHandler.install(tree);

    new TreeSpeedSearch(tree);
    TreeUtil.installActions(tree);
    ToolTipManager.sharedInstance().registerComponent(tree);

    myAutoScrollToSourceHandler.install(tree);

    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(final TreeSelectionEvent e) {
                treeSelectionChanged();
              }
            });

    tree.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
              List<Navigatable> navigatables = getNavigatables();
              if (navigatables.isEmpty()) return;
              for (Navigatable navigatable : navigatables) {
                if (navigatable instanceof AbstractTreeNode
                    && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
                  navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
                }
                if (navigatable.canNavigateToSource()) {
                  navigatable.navigate(false);
                  if (navigatable instanceof Usage) {
                    ((Usage) navigatable).highlightInEditor();
                  }
                }
              }
              e.consume();
            }
          }
        });

    tree.addTreeWillExpandListener(
        new TreeWillExpandListener() {
          @Override
          public void treeWillCollapse(TreeExpansionEvent event) {}

          @Override
          public void treeWillExpand(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            SliceNode node = fromPath(path);
            node.calculateDupNode();
          }
        });

    return tree;
  }
Пример #3
0
  private JPanel createPanel() {
    createModel();
    myTree = new MyTree();
    myTree.setLineStyleAngled();
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.updateUI();
    myTree.setLargeModel(true);

    myTree.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              OpenSourceUtil.openSourcesFrom(
                  DataManager.getInstance().getDataContext(myTree), false);
            }
          }
        });

    myTree.addMouseListener(
        new PopupHandler() {
          public void invokePopup(Component comp, int x, int y) {
            popupInvoked(comp, x, y);
          }
        });

    EditSourceOnDoubleClickHandler.install(myTree);

    myAutoScrollToSourceHandler.install(myTree);

    myOccurenceNavigatorSupport =
        new OccurenceNavigatorSupport(myTree) {
          protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
            if (!(node instanceof MessageNode)) {
              return null;
            }
            MessageNode messageNode = (MessageNode) node;
            AntBuildMessageView.MessageType type = messageNode.getType();

            if (type != AntBuildMessageView.MessageType.MESSAGE
                && type != AntBuildMessageView.MessageType.ERROR) {
              return null;
            }

            if (!isValid(messageNode.getFile())) {
              return null;
            }

            return new OpenFileDescriptor(
                myProject, messageNode.getFile(), messageNode.getOffset());
          }

          @Nullable
          public String getNextOccurenceActionName() {
            return AntBundle.message("ant.execution.next.error.warning.action.name");
          }

          @Nullable
          public String getPreviousOccurenceActionName() {
            return AntBundle.message("ant.execution.previous.error.warning.action.name");
          }
        };

    JPanel panel = new JPanel(new BorderLayout());

    JScrollPane scrollPane = MessageTreeRenderer.install(myTree);
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
  }