com.intellij.ui.treeStructure.Tree Java Examples

The following examples show how to use com.intellij.ui.treeStructure.Tree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseExecuteBeforeRunDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void expacndChecked(Tree tree) {
  TreeNode root = (TreeNode)tree.getModel().getRoot();
  Enumeration factories = root.children();
  ArrayList<TreeNode[]> toExpand = new ArrayList<TreeNode[]>();
  while (factories.hasMoreElements()) {
    DefaultMutableTreeNode factoryNode = (DefaultMutableTreeNode)factories.nextElement();
    Enumeration configurations = factoryNode.children();
    while (configurations.hasMoreElements()) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode)configurations.nextElement();
      ConfigurationDescriptor config = (ConfigurationDescriptor)node.getUserObject();
      if (config.isChecked()) {
        toExpand.add(factoryNode.getPath());
        break;
      }
    }
  }
  for (TreeNode[] treeNodes : toExpand) {
    tree.expandPath(new TreePath(treeNodes));
  }
}
 
Example #2
Source File: TestTreeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void paintRowData(Tree tree, String duration, Rectangle bounds, Graphics2D g, boolean isSelected, boolean hasFocus) {
  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
  g.setFont(tree.getFont().deriveFont(Font.PLAIN, UIUtil.getFontSize(UIUtil.FontSize.SMALL)));
  final FontMetrics metrics = tree.getFontMetrics(g.getFont());
  int totalWidth = metrics.stringWidth(duration) + 2;
  int x = bounds.x + bounds.width - totalWidth;
  g.setColor(isSelected ? UIUtil.getTreeSelectionBackground(hasFocus) : UIUtil.getTreeBackground());
  final int leftOffset = 5;
  g.fillRect(x - leftOffset, bounds.y, totalWidth + leftOffset, bounds.height);
  g.translate(0, bounds.y - 1);
  if (isSelected) {
    if (!hasFocus && UIUtil.isUnderAquaBasedLookAndFeel()) {
      g.setColor(UIUtil.getTreeForeground());
    }
    else {
      g.setColor(UIUtil.getTreeSelectionForeground());
    }
  }
  else {
    g.setColor(new JBColor(0x808080, 0x808080));
  }
  g.drawString(duration, x, SimpleColoredComponent.getTextBaseLine(tree.getFontMetrics(tree.getFont()), bounds.height) + 1);
  g.translate(0, -bounds.y + 1);
  config.restore();
}
 
Example #3
Source File: FileTemplateTabAsTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected FileTemplateTabAsTree(String title) {
  super(title);
  myRoot = initModel();
  myTreeModel = new MyTreeModel(myRoot);
  myTree = new Tree(myTreeModel);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(myTree);

  myTree.expandPath(TreeUtil.getPathFromRoot(myRoot));
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  myTree.expandRow(0);

  myTree.addTreeSelectionListener(e -> onTemplateSelected());
  new TreeSpeedSearch(myTree);
}
 
Example #4
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void autofixIsNotShownWhenNull() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();
  JPanel rightPane = (JPanel) splitter.getSecondComponent();

  TreePath streamingPath =
      getTreePathWithString(suggestionTree, streamingSuggestionData.toString());
  suggestionTree.addSelectionPath(streamingPath);

  for (Component component : rightPane.getComponents()) {
    if (component instanceof JButton) {
      assertThat(component.isVisible()).isFalse();
    }
  }
}
 
Example #5
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleSuggestionsCreateIssueTypeNode() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  TreePath webPIssuePath =
      getTreePathWithString(
          suggestionTree, SuggestionDataFactory.issueTypeNodeNames.get(IssueType.WEBP));
  DefaultMutableTreeNode webPIssueNode =
      (DefaultMutableTreeNode) webPIssuePath.getLastPathComponent();
  assertThat(webPIssueNode.getChildCount()).isEqualTo(2);
}
 
Example #6
Source File: TreeUtilTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRemoveSelected() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
  DefaultTreeModel model = new DefaultTreeModel(root);
  DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("1");
  model.insertNodeInto(child1, root, 0);
  DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("2");
  model.insertNodeInto(child2, root, 1);
  DefaultMutableTreeNode child11 = new DefaultMutableTreeNode("11");
  model.insertNodeInto(child11, child1, 0);
  JTree tree = new Tree(model);
  TreeExpandCollapse.expandAll(tree);
  tree.clearSelection();
  TreeUtil.removeSelected(tree);
  assertEquals(2, model.getChildCount(root));
  assertEquals(1, model.getChildCount(child1));
  tree.setSelectionPath(TreeUtil.getPathFromRoot(child11));
  TreeUtil.removeSelected(tree);
  assertSame(child1, tree.getSelectionPath().getLastPathComponent());
  TreeUtil.removeSelected(tree);
  assertSame(child2, tree.getSelectionPath().getLastPathComponent());
  tree.setSelectionPath(new TreePath(root));
  assertEquals(1, model.getChildCount(root));
  TreeUtil.removeSelected(tree);
  assertSame(root, model.getRoot());
  assertEquals(1, model.getChildCount(root));
}
 
Example #7
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void categoryNodesHaveCorrectExtraInformation() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString());
  TreeCellRenderer treeCellRenderer = suggestionTree.getCellRenderer();
  Component renderedNode =
      treeCellRenderer.getTreeCellRendererComponent(
          suggestionTree,
          webPPath.getLastPathComponent(),
          false,
          false,
          false,
          suggestionTree.getRowForPath(webPPath),
          false);
  assertThat(renderedNode.toString()).contains("2 recommendations");
  assertThat(renderedNode.toString()).contains("29.30 KB");
}
 
Example #8
Source File: TreeUtilTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testMultiLevelRemove() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
  DefaultTreeModel model = new DefaultTreeModel(root) {
      @Override
      public void removeNodeFromParent(MutableTreeNode mutableTreeNode) {
        super.removeNodeFromParent((MutableTreeNode) mutableTreeNode.getParent());
      }
    };
  DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
  model.insertNodeInto(node1, root, 0);
  DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
  model.insertNodeInto(node2, node1, 0);
  JTree tree = new Tree(model);
  TreeExpandCollapse.expandAll(tree);
  tree.setSelectionPath(TreeUtil.getPathFromRoot(node2));
  TreeUtil.removeSelected(tree);
  assertEquals(0, root.getChildCount());
  assertEquals(root, tree.getSelectionPath().getLastPathComponent());
}
 
Example #9
Source File: BuckTreeViewPanelImpl.java    From buck with Apache License 2.0 6 votes vote down vote up
public BuckTreeViewPanelImpl() {
  mRoot = new BuckTextNode("", BuckTextNode.TextType.INFO);
  DefaultTreeModel treeModel = new DefaultTreeModel(mRoot);
  mModifiableModel =
      new ModifiableModelImpl(
          treeModel,
          new Tree(treeModel) {
            @Override
            public int getScrollableUnitIncrement(
                Rectangle visibleRect, int orientation, int direction) {
              return 5;
            }
          });
  mScrollPane = new JBScrollPane(mModifiableModel.getTree());
  mScrollPane.setAutoscrolls(true);
}
 
Example #10
Source File: InspectorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initTree(final Tree tree) {
  tree.setCellRenderer(new DiagnosticsTreeCellRenderer(this));
  tree.setShowsRootHandles(true);
  TreeUtil.installActions(tree);

  PopupHandler.installUnknownPopupHandler(tree, createTreePopupActions(), ActionManager.getInstance());

  new TreeSpeedSearch(tree) {
    @Override
    protected String getElementText(Object element) {
      final TreePath path = (TreePath)element;
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object object = node.getUserObject();
      if (object instanceof DiagnosticsNode) {
        // TODO(pq): consider a specialized String for matching.
        return object.toString();
      }
      return null;
    }
  };
}
 
Example #11
Source File: ModulesDependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void initTree(Tree tree, boolean isRightTree) {
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setCellRenderer(new MyTreeCellRenderer());
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(tree);

  TreeUtil.installActions(tree);
  new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {
    @Override
    public String convert(TreePath o) {
      return o.getLastPathComponent().toString();
    }
  }, true);
  PopupHandler.installUnknownPopupHandler(tree, createTreePopupActions(isRightTree, tree), ActionManager.getInstance());
}
 
Example #12
Source File: DirectoryChooserModuleTreeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public DirectoryChooserModuleTreeView(@Nonnull Project project) {
  myRootNode = new DefaultMutableTreeNode();
  myTree = new Tree(myRootNode);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  myProject = project;
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath o) {
      final Object userObject = ((DefaultMutableTreeNode)o.getLastPathComponent()).getUserObject();
      if (userObject instanceof Module) {
        return ((Module)userObject).getName();
      }
      else {
        if (userObject == null) return "";
        return userObject.toString();
      }
    }
  }, true);
}
 
Example #13
Source File: ExternalProjectPathField.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Tree buildRegisteredProjectsTree(@Nonnull Project project, @Nonnull ProjectSystemId externalSystemId) {
  ExternalSystemTasksTreeModel model = new ExternalSystemTasksTreeModel(externalSystemId);
  ExternalSystemTasksTree result = new ExternalSystemTasksTree(model, ContainerUtilRt.<String, Boolean>newHashMap(), project, externalSystemId);
  
  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
  assert manager != null;
  AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
  Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = settings.getAvailableProjects();
  List<ExternalProjectPojo> rootProjects = ContainerUtilRt.newArrayList(projects.keySet());
  ContainerUtil.sort(rootProjects);
  for (ExternalProjectPojo rootProject : rootProjects) {
    model.ensureSubProjectsStructure(rootProject, projects.get(rootProject));
  }
  return result;
}
 
Example #14
Source File: SlingServerTreeManager.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
    final SlingServerTreeBuilder builder = myBuilder;
    if(builder != null) {
        Disposer.dispose(builder);
        myBuilder = null;
    }

    final Tree aTree = tree;
    if(aTree != null) {
        ToolTipManager.sharedInstance().unregisterComponent(aTree);
        for(KeyStroke keyStroke : aTree.getRegisteredKeyStrokes()) {
            aTree.unregisterKeyboardAction(keyStroke);
        }
        tree = null;
    }

    final KeyMapListener listener = myKeyMapListener;
    if(listener != null) {
        myKeyMapListener = null;
        listener.stopListen();
    }
}
 
Example #15
Source File: TfsTreeForm.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 *
 * @noinspection ALL
 */
private void $$$setupUI$$$() {
    contentPane = new JPanel();
    contentPane.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
    final JBScrollPane jBScrollPane1 = new JBScrollPane();
    contentPane.add(jBScrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    tree = new Tree();
    jBScrollPane1.setViewportView(tree);
    pathField = new JTextField();
    pathField.setEditable(false);
    contentPane.add(pathField, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    messagePanel = new JPanel();
    messagePanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
    contentPane.add(messagePanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
    final Spacer spacer1 = new Spacer();
    messagePanel.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(11, 10), null, 0, false));
    messageLabel = new JLabel();
    messageLabel.setText("Label");
    messagePanel.add(messageLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
 
Example #16
Source File: SerialisationHelper.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("SameReturnValue")
private static boolean exportCell(TableModel model, StringBuilder csv, boolean firstCell, int i, int j) {
    if (!firstCell) {
        csv.append(EXPORT_CELL_DELIMITER);
    }
    Object t = model.getValueAt(i, j);
    if (Tree.class.isAssignableFrom(t.getClass())) {
        Tree tt = (Tree) t;
        TreeModel tm = tt.getModel();
        try {
            csv.append(convertToCsv(((DefaultMutableTreeNode) tm.getRoot()).getUserObject()));
        } catch (Exception e) {
            // skipping non-convertible nodes
        }
    } else {
        csv.append(t.toString());
    }
    return false;
}
 
Example #17
Source File: TodoPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param currentFileMode if {@code true} then view doesn't have "Group By Packages" and "Flatten Packages"
 *                        actions.
 */
TodoPanel(Project project, TodoPanelSettings settings, boolean currentFileMode, Content content) {
  super(false, true);

  myProject = project;
  mySettings = settings;
  myCurrentFileMode = currentFileMode;
  myContent = content;

  DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
  myTree = new Tree(model);
  myTreeExpander = new MyTreeExpander();
  myOccurenceNavigator = new MyOccurenceNavigator();
  initUI();
  myTodoTreeBuilder = setupTreeStructure();
  updateTodoFilter();
  myTodoTreeBuilder.setShowPackages(mySettings.arePackagesShown);
  myTodoTreeBuilder.setShowModules(mySettings.areModulesShown);
  myTodoTreeBuilder.setFlattenPackages(mySettings.areFlattenPackages);

  myVisibilityWatcher = new MyVisibilityWatcher();
  myVisibilityWatcher.install(this);
}
 
Example #18
Source File: LiteralChooser.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Tree createTree(java.util.List<String> literals) {
	final CheckedTreeNode rootNode = new CheckedTreeNode("all literals not defined");
	for (String literal : literals) {
		CheckedTreeNode child = new CheckedTreeNode(new LiteralChooserObject(literal, Icons.LEXER_RULE));
		child.setChecked(true);
		rootNode.add(child);
	}
	DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);

	selectedElements.addAll(literals); // all are "on" by default

	Tree tree = new Tree(treeModel);
	tree.setRootVisible(false);
	tree.setCellRenderer(new LiteralChooserRenderer());
	tree.addTreeSelectionListener(new MyTreeSelectionListener());

	return tree;
}
 
Example #19
Source File: CertificateTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void selectFirstCertificate() {
  if (!isEmpty()) {
    Tree tree = (Tree)getTree();
    TreePath path = TreeUtil.getFirstLeafNodePath(tree);
    tree.addSelectionPath(path);
  }
}
 
Example #20
Source File: CallerChooserBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CallerChooserBase(M method, Project project, String title, Tree previousTree, String fileName, Consumer<Set<M>> callback) {
  super(true);
  myMethod = method;
  myProject = project;
  myTree = previousTree;
  myFileName = fileName;
  myCallback = callback;
  setTitle(title);
  init();
  myInitDone = true;
}
 
Example #21
Source File: TreeUtilTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRemoveLast() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
  DefaultTreeModel model = new DefaultTreeModel(root);
  model.insertNodeInto(new DefaultMutableTreeNode("1"), root, 0);
  DefaultMutableTreeNode middle = new DefaultMutableTreeNode("2");
  model.insertNodeInto(middle, root, 1);
  DefaultMutableTreeNode last = new DefaultMutableTreeNode("3");
  model.insertNodeInto(last, root, 2);
  JTree tree = new Tree(model);
  tree.setSelectionPath(TreeUtil.getPathFromRoot(last));
  TreeUtil.removeSelected(tree);
  assertSame(middle, tree.getSelectionPath().getLastPathComponent());
}
 
Example #22
Source File: CompositeTableCellRenderer.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    if (e.isControlDown()) {
        if (e.getKeyCode() == KeyEvent.VK_C) { // Copy
            List<TreePath> v = Arrays.asList(((Tree) e.getComponent()).getSelectionModel().getSelectionPaths());
            String str = SerialisationHelper.convertToCsv(v);
            StringSelection selection = new StringSelection(str);
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(selection, selection);
        }
    }
}
 
Example #23
Source File: DependenciesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Set<PsiFile> getSelectedScope(final Tree tree) {
  TreePath[] paths = tree.getSelectionPaths();
  if (paths == null ) return EMPTY_FILE_SET;
  Set<PsiFile> result = new HashSet<PsiFile>();
  for (TreePath path : paths) {
    PackageDependenciesNode node = (PackageDependenciesNode)path.getLastPathComponent();
    node.fillFiles(result, !mySettings.UI_FLATTEN_PACKAGES);
  }
  return result;
}
 
Example #24
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FilteringTreeBuilder(Tree tree, ElementFilter filter, AbstractTreeStructure structure, @Nullable Comparator<? super NodeDescriptor> comparator) {
  super(tree, (DefaultTreeModel)tree.getModel(), structure instanceof FilteringTreeStructure ? structure : new FilteringTreeStructure(filter, structure), comparator);

  myTree = tree;
  initRootNode();

  if (filter instanceof ElementFilter.Active) {
    ((ElementFilter.Active)filter).addListener(new ElementFilter.Listener() {
      @Nonnull
      @Override
      public Promise<?> update(final Object preferredSelection, final boolean adjustSelection, final boolean now) {
        return refilter(preferredSelection, adjustSelection, now);
      }
    }, this);
  }

  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath newPath = e.getNewLeadSelectionPath();
      if (newPath != null) {
        Object element = getElementFor(newPath.getLastPathComponent());
        if (element != null) {
          myLastSuccessfulSelect = element;
        }
      }
    }
  });
}
 
Example #25
Source File: NoSqlExplorerPanel.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
private Tree createTree() {

        Tree tree = new Tree() {

            private final JLabel myLabel = new JLabel(
                    String.format("<html><center>NoSql server list is empty<br><br>You may use <img src=\"%s\"> to add configuration</center></html>", pluginSettingsUrl)
            );

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (!getServerConfigurations().isEmpty()) return;

                myLabel.setFont(getFont());
                myLabel.setBackground(getBackground());
                myLabel.setForeground(getForeground());
                Rectangle bounds = getBounds();
                Dimension size = myLabel.getPreferredSize();
                myLabel.setBounds(0, 0, size.width, size.height);

                int x = (bounds.width - size.width) / 2;
                Graphics g2 = g.create(bounds.x + x, bounds.y + 20, bounds.width, bounds.height);
                try {
                    myLabel.paint(g2);
                } finally {
                    g2.dispose();
                }
            }
        };

        tree.getEmptyText().clear();
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

        return tree;
    }
 
Example #26
Source File: PantsConsoleViewPanel.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
protected Tree createTree(@NotNull final DefaultTreeModel treeModel) {
  return new Tree(treeModel) {
    @Override
    public void setRowHeight(int i) {
      super.setRowHeight(0);
      // this is needed in order to make UI calculate the height for each particular row
    }
  };
}
 
Example #27
Source File: ArmaAddonsSettingsForm.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
private void createUIComponents() {
	bundle = ResourceBundle.getBundle("com.kaylerrenslow.armaplugin.ProjectSettingsBundle");

	tfWithBrowseReferenceDirectory = new TextFieldWithBrowseButton(new JTextField(40));

	treeAddonsRoots_rootNode = new RootTreeNode();
	treeAddonsRoots = new Tree(treeAddonsRoots_rootNode);
	treeAddonsRoots.setCellRenderer(new MyColoredTreeCellRenderer());
	treeAddonsRoots.setHoldSize(true);
	treeAddonsRoots.addTreeSelectionListener(e -> {
		System.out.println("ArmaAddonsSettingsForm.createUIComponents e=" + e);
	});
}
 
Example #28
Source File: VisibleTreeState.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void saveVisibleState(Tree tree) {
  myExpandedNodes.clear();
  final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)tree.getModel().getRoot();
  Enumeration<TreePath> expanded = tree.getExpandedDescendants(new TreePath(rootNode.getPath()));
  if (expanded != null) {
    while (expanded.hasMoreElements()) {
      final TreePath treePath = expanded.nextElement();
      final InspectionConfigTreeNode node = (InspectionConfigTreeNode)treePath.getLastPathComponent();
      myExpandedNodes.add(getState(node));
    }
  }

  setSelectionPaths(tree.getSelectionPaths());
}
 
Example #29
Source File: DetailsComponentTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  final JFrame frame = new JFrame();
  frame.getContentPane().setLayout(new BorderLayout());
  final JPanel content = new JPanel(new BorderLayout());

  final DetailsComponent d = new DetailsComponent();
  content.add(d.getComponent(), BorderLayout.CENTER);

  d.setText("This is a Tree");
  final JTree c = new Tree();
  c.setBorder(new LineBorder(Color.red));
  d.setContent(c);

  frame.getContentPane().add(content, BorderLayout.CENTER);
  final JCheckBox details = new JCheckBox("Details");
  details.setSelected(true);
  frame.getContentPane().add(details, BorderLayout.SOUTH);
  details.addActionListener(new ActionListener() {
    public void actionPerformed(final ActionEvent e) {
      d.setDetailsModeEnabled(details.isSelected());
    }
  });


  frame.setBounds(300, 300, 300, 300);
  frame.show();
}
 
Example #30
Source File: DebuggerTreeWithHistoryPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateInitialBounds(final Tree tree) {
  final Window popupWindow = SwingUtilities.windowForComponent(myPopup.getContent());
  final Dimension size = tree.getPreferredSize();
  final Point location = popupWindow.getLocation();
  final Rectangle windowBounds = popupWindow.getBounds();
  final Rectangle targetBounds = new Rectangle(location.x,
                                               location.y,
                                               Math.max(size.width + 250, windowBounds.width),
                                               Math.max(size.height, windowBounds.height));
  ScreenUtil.cropRectangleToFitTheScreen(targetBounds);
  popupWindow.setBounds(targetBounds);
  popupWindow.validate();
  popupWindow.repaint();
}