コード例 #1
0
  @Override
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());

    // Toolbar

    DefaultActionGroup group = new DefaultActionGroup();

    fillToolbarActions(group);

    group.addSeparator();

    ExpandAllAction expandAllAction = new ExpandAllAction();
    expandAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_EXPAND_ALL)),
        myTree);
    group.add(expandAllAction);

    CollapseAllAction collapseAllAction = new CollapseAllAction();
    collapseAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)),
        myTree);
    group.add(collapseAllAction);

    panel.add(
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent(),
        BorderLayout.NORTH);

    // Tree
    expandFirst();
    defaultExpandTree();
    installSpeedSearch();

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(new Dimension(350, 450));
    panel.add(scrollPane, BorderLayout.CENTER);

    return panel;
  }
コード例 #2
0
 public void actionPerformed(final AnActionEvent e) {
   @NonNls final String delim = " -> ";
   final StringBuffer buf = new StringBuffer();
   processDependencies(
       getSelectedScope(myLeftTree),
       getSelectedScope(myRightTree),
       new Processor<List<PsiFile>>() {
         public boolean process(final List<PsiFile> path) {
           if (buf.length() > 0) buf.append("<br>");
           buf.append(
               StringUtil.join(
                   path,
                   new Function<PsiFile, String>() {
                     public String fun(final PsiFile psiFile) {
                       return psiFile.getName();
                     }
                   },
                   delim));
           return true;
         }
       });
   final JEditorPane pane =
       new JEditorPane(UIUtil.HTML_MIME, "<html>" + buf.toString() + "</html>");
   pane.setForeground(Color.black);
   pane.setBackground(HintUtil.INFORMATION_COLOR);
   pane.setOpaque(true);
   final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
   final Dimension dimension = pane.getPreferredSize();
   scrollPane.setMinimumSize(new Dimension(dimension.width, dimension.height + 20));
   scrollPane.setPreferredSize(new Dimension(dimension.width, dimension.height + 20));
   JBPopupFactory.getInstance()
       .createComponentPopupBuilder(scrollPane, pane)
       .setTitle("Dependencies")
       .setMovable(true)
       .createPopup()
       .showInBestPositionFor(e.getDataContext());
 }
コード例 #3
0
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    myModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    createTreeModel();
    myTree = new Tree(myModel);

    UIUtil.setLineStyleAngled(myTree);
    myTree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            setIcon(expanded ? Icons.PACKAGE_OPEN_ICON : Icons.PACKAGE_ICON);

            if (value instanceof DefaultMutableTreeNode) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              Object object = node.getUserObject();
              if (object instanceof PsiPackage) {
                String name = ((PsiPackage) object).getName();
                if (name != null && name.length() > 0) {
                  setText(name);
                } else {
                  setText(IdeBundle.message("node.default"));
                }
              }
            }
            return this;
          }
        });

    myTree.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(new Dimension(500, 300));

    new TreeSpeedSearch(
        myTree,
        new Convertor<TreePath, String>() {
          public String convert(TreePath path) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            Object object = node.getUserObject();
            if (object instanceof PsiPackage) return ((PsiPackage) object).getName();
            else return "";
          }
        });

    myTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                PsiPackage selection = getTreeSelection();
                if (selection != null) {
                  String name = selection.getQualifiedName();
                  setTitle(
                      myTitle
                          + " - "
                          + ("".equals(name) ? IdeBundle.message("node.default.package") : name));
                } else {
                  setTitle(myTitle);
                }
              }
            });

    panel.add(scrollPane, BorderLayout.CENTER);
    DefaultActionGroup group = createActionGroup(myTree);

    ActionToolbar toolBar =
        ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    panel.add(toolBar.getComponent(), BorderLayout.NORTH);
    toolBar.getComponent().setAlignmentX(JComponent.LEFT_ALIGNMENT);

    return panel;
  }