javax.swing.plaf.basic.BasicTreeUI Java Examples

The following examples show how to use javax.swing.plaf.basic.BasicTreeUI. 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: InspectorTree.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public InspectorTree(final DefaultMutableTreeNode treemodel,
                     String treeName,
                     boolean detailsSubtree,
                     String parentTreeName,
                     boolean rootVisible,
                     boolean legacyMode,
                     Disposable parentDisposable) {
  super(treemodel);
  setUI(new InspectorTreeUI());
  final BasicTreeUI ui = (BasicTreeUI)getUI();
  this.detailsSubtree = detailsSubtree;

  setRootVisible(rootVisible);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  registerShortcuts(parentDisposable);
  if (detailsSubtree) {
    // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes.
    getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName);
  }
  else {
    getEmptyText().setText(treeName + " tree for the running app");
  }
}
 
Example #2
Source File: InspectorTree.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public InspectorTree(final DefaultMutableTreeNode treemodel,
                     String treeName,
                     boolean detailsSubtree,
                     String parentTreeName,
                     boolean rootVisible,
                     boolean legacyMode,
                     Disposable parentDisposable) {
  super(treemodel);
  setUI(new InspectorTreeUI());
  final BasicTreeUI ui = (BasicTreeUI)getUI();
  this.detailsSubtree = detailsSubtree;

  setRootVisible(rootVisible);
  getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  registerShortcuts(parentDisposable);
  if (detailsSubtree) {
    // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes.
    getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName);
  }
  else {
    getEmptyText().setText(treeName + " tree for the running app");
  }
}
 
Example #3
Source File: BeanTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Make a path visible.
* @param path the path
*/
private void showPathWithoutExpansion(TreePath path) {
    Rectangle rect = tree.getPathBounds(path);
    if (rect != null) { //PENDING
        TreeUI tmp = tree.getUI();
        int correction = 0;
        if (tmp instanceof BasicTreeUI) {
            correction = ((BasicTreeUI) tmp).getLeftChildIndent();
            correction += ((BasicTreeUI) tmp).getRightChildIndent();
        }
        rect.x = Math.max(0, rect.x - correction);
        if (rect.y >= 0) { //#197514 - do not scroll to negative y values
            tree.scrollRectToVisible(rect);
        }
    }
}
 
Example #4
Source File: TreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean isLocationInExpandControl( TreePath path, Point location ) {
   if( tree.getModel().isLeaf( path.getLastPathComponent() ) )
       return false;
   
   Rectangle r = tree.getPathBounds(path);
   int boxWidth = 8;
   Insets i = tree.getInsets();
   int indent = 0;
   
   if( tree.getUI() instanceof BasicTreeUI ) {
       BasicTreeUI ui = (BasicTreeUI)tree.getUI();
       if( null != ui.getExpandedIcon() )
           boxWidth = ui.getExpandedIcon().getIconWidth();
       
       indent = ui.getLeftChildIndent();
   }
   int boxX;
   if( tree.getComponentOrientation().isLeftToRight() ) {
       boxX = r.x - positionX - indent - boxWidth;
   } else {
       boxX = r.x - positionX + indent + r.width;
   }
   return location.getX() >= boxX && location.getX() <= (boxX + boxWidth);
}
 
Example #5
Source File: TemplatesPanelGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Make a path visible.
* @param path the path
*/
private void showPathWithoutExpansion(TreePath path) {
    Rectangle rect = tree.getPathBounds(path);
    if (rect != null) { //PENDING
        TreeUI tmp = tree.getUI();
        int correction = 0;
        if (tmp instanceof BasicTreeUI) {
            correction = ((BasicTreeUI) tmp).getLeftChildIndent();
            correction += ((BasicTreeUI) tmp).getRightChildIndent();
        }
        rect.x = Math.max(0, rect.x - correction);
        rect.y += rect.height;
        if (rect.y >= 0) { //#197514 - do not scroll to negative y values
            tree.scrollRectToVisible(rect);
        }
    }
}
 
Example #6
Source File: MyTreeTableCellRenderer.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public MyTreeTableCellRenderer(MyTreeTable treeTable, TreeModel model) {
    super(model);
    setUI(new BasicTreeUI());

    this.treeTable = treeTable;

    // Setzen der Zeilenhoehe fuer die JTable
    // Muss explizit aufgerufen werden, weil treeTable noch
    // null ist, wenn super(model) setRowHeight aufruft!
    setRowHeight(getRowHeight());
}
 
Example #7
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setUI(TreeUI ui) {
            if (ui instanceof SynthTreeUI) {
//                if (synthLikeUI == null) {
                    super.setUI(ui);
                    SynthTreeUI synthUI = (SynthTreeUI)ui;
                    int left = synthUI.getLeftChildIndent();
                    int right = synthUI.getRightChildIndent();

                    synthLikeUI = new SynthLikeTreeUI();
                    super.setUI(synthLikeUI);

                    boolean nimbus = UIUtils.isNimbusLookAndFeel();
                    synthLikeUI.setLeftChildIndent(left + (nimbus ? 4 : 6));
                    synthLikeUI.setRightChildIndent(right);
//                } else {
//                    super.setUI(synthLikeUI);
//                }
            } else {
                synthLikeUI = null;
                
                super.setUI(ui);
                
                // #269500 - performance workaround for BasicTreeUI
                if (!DISABLE_TREEUI_FIX && ui instanceof BasicTreeUI)
                    workaroundVerticalLines = UIManager.getBoolean("Tree.paintLines"); // NOI18N
            }
        }
 
Example #8
Source File: JTreeTable.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void setTreeUIVariables() {
    if (tree.getUI() instanceof BasicTreeUI) {
        BasicTreeUI treeUI = (BasicTreeUI) tree.getUI();
        treeSignExtent = treeUI.getExpandedIcon().getIconWidth() / 2;
        treeSignRightMargin = treeUI.getRightChildIndent();
    }
}
 
Example #9
Source File: bug8003830.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #10
Source File: bug8003830.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #11
Source File: bug8003830.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #12
Source File: bug8003830.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #13
Source File: GenericTagTreePanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public MyTree() {
    setBackground(Color.white);
    setUI(new BasicTreeUI() {
        @Override
        public void paint(Graphics g, JComponent c) {
            setHashColor(Color.gray);
            super.paint(g, c);
        }
    });
    setCellRenderer(new MyTreeCellRenderer());
    setCellEditor(new MyTreeCellEditor(this));
    setInvokesStopCellEditing(true);

}
 
Example #14
Source File: TagTree.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public TagTree(TagTreeModel treeModel, MainPanel mainPanel) {
    super(treeModel);
    this.mainPanel = mainPanel;
    setCellRenderer(new TagTreeCellRenderer());
    setRootVisible(false);
    setBackground(Color.white);
    setRowHeight(Math.max(getFont().getSize() + 5, 16));
    setLargeModel(true);
    setUI(new BasicTreeUI() {
        {
            setHashColor(Color.gray);
        }
    });
}
 
Example #15
Source File: DumpTree.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public DumpTree(DumpTreeModel treeModel, MainPanel mainPanel) {
    super(treeModel);
    this.mainPanel = mainPanel;
    setCellRenderer(new DumpTreeCellRenderer());
    setRootVisible(false);
    setBackground(Color.white);
    setUI(new BasicTreeUI() {
        {
            setHashColor(Color.gray);
        }
    });
}
 
Example #16
Source File: ProgressMonitor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public ProgressMonitor() {
  super(ProgressWatcher.getTreeModel());
  setRootVisible(false);
  setShowsRootHandles(false);
  setSelectionModel(null);
  root = (TreeNode)treeModel.getRoot();
  setCellRenderer(new CellRenderer(getCellRenderer()));
  putClientProperty("JTree.lineStyle", "Angled");
  ComponentUI treeUI = getUI();
  EMPTY_IMAGE.setRGB(0, 0, getBackground().getRGB());
  if(treeUI instanceof BasicTreeUI) { 
    ((BasicTreeUI)treeUI).setExpandedIcon(new ImageIcon(EMPTY_IMAGE)); 
    ((BasicTreeUI)treeUI).setCollapsedIcon(new ImageIcon(EMPTY_IMAGE)); 
  } 
}
 
Example #17
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void clearRendererCache() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (myExpandingCollapsing) return; // to avoid quadratic row enumeration
  // clear renderer cache of node preferred size
  TreeUI ui = myTree.getUI();
  if (ui instanceof BasicTreeUI) {
    AbstractLayoutCache treeState = ReflectionUtil.getField(BasicTreeUI.class, ui, AbstractLayoutCache.class, "treeState");
    Rectangle visibleRect = myTree.getVisibleRect();
    int rowForLocation = myTree.getClosestRowForLocation(0, visibleRect.y);
    int visibleRowCount = getVisibleRowCount();
    List<Node> toUpdate = new ArrayList<>();
    for (int i = rowForLocation + visibleRowCount + 1; i >= rowForLocation; i--) {
      final TreePath eachPath = myTree.getPathForRow(i);
      if (eachPath == null) continue;

      treeState.invalidatePathBounds(eachPath);
      Object node = eachPath.getLastPathComponent();
      if (node instanceof UsageNode) {
        toUpdate.add((Node)node);
      }
    }
    queueUpdateBulk(toUpdate, () -> {
      if (!isDisposed()) {
        myTree.repaint(visibleRect);
      }
    });
  }
  else {
    myTree.setCellRenderer(myUsageViewTreeCellRenderer);
  }
}
 
Example #18
Source File: SimpleTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int getBoxWidth(JTree tree) {
  BasicTreeUI basicTreeUI = (BasicTreeUI)tree.getUI();
  int boxWidth;
  if (basicTreeUI.getExpandedIcon() != null) {
    boxWidth = basicTreeUI.getExpandedIcon().getIconWidth();
  }
  else {
    boxWidth = 8;
  }
  return boxWidth;
}
 
Example #19
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Range<Integer> getExpandControlRange(@Nonnull final JTree aTree, @Nullable final TreePath path) {
  TreeModel treeModel = aTree.getModel();

  final BasicTreeUI basicTreeUI = (BasicTreeUI)aTree.getUI();
  Icon expandedIcon = basicTreeUI.getExpandedIcon();


  Range<Integer> box = null;
  if (path != null && !treeModel.isLeaf(path.getLastPathComponent())) {
    int boxWidth;
    Insets i = aTree.getInsets();

    boxWidth = expandedIcon != null ? expandedIcon.getIconWidth() : 8;

    int boxLeftX = i != null ? i.left : 0;

    boolean leftToRight = aTree.getComponentOrientation().isLeftToRight();
    int depthOffset = getDepthOffset(aTree);
    int totalChildIndent = basicTreeUI.getLeftChildIndent() + basicTreeUI.getRightChildIndent();

    if (leftToRight) {
      boxLeftX += (path.getPathCount() + depthOffset - 2) * totalChildIndent + basicTreeUI.getLeftChildIndent() - boxWidth / 2;
    }
    int boxRightX = boxLeftX + boxWidth;

    box = new Range<>(boxLeftX, boxRightX);
  }
  return box;
}
 
Example #20
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public static void invalidateCacheAndRepaint(@Nullable TreeUI ui) {
  if (ui instanceof BasicTreeUI) {
    BasicTreeUI basic = (BasicTreeUI)ui;
    basic.setLeftChildIndent(basic.getLeftChildIndent());
  }
}
 
Example #21
Source File: CommittedChangeListRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static int getRowX(JTree tree, int depth) {
  if (tree == null) return 0;
  final TreeUI ui = tree.getUI();
  if (ui instanceof BasicTreeUI) {
    final BasicTreeUI treeUI = ((BasicTreeUI)ui);
    return (treeUI.getLeftChildIndent() + treeUI.getRightChildIndent()) * depth;
  }

  final int leftIndent = UIUtil.getTreeLeftChildIndent();
  final int rightIndent = UIUtil.getTreeRightChildIndent();

  return (leftIndent + rightIndent) * depth;
}
 
Example #22
Source File: DefaultUIDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void decorateTree0(JTree tree, Color color) {
  TreeUI treeUI = tree.getUI();
  if (treeUI instanceof BasicTreeUI) {
    ((BasicTreeUI)treeUI).setLeftChildIndent(JBUI.scale(10));
  }

  tree.setFont(JBUI.Fonts.biggerFont());
  tree.setBackground(color);
}
 
Example #23
Source File: BasicTreeUIHacking.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static int getRowX(TreeUI treeUI, int row, int depth) {
  if (!(treeUI instanceof BasicTreeUI) || ourGetRowX == null) {
    return -1;
  }
  try {
    return (int)ourGetRowX.invoke(treeUI, row, depth);
  }
  catch (IllegalAccessException | InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 
Example #24
Source File: BasicTreeUIHacking.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isLocationInExpandControl(TreeUI treeUI, TreePath path, int mouseX, int mouseY) {
  if (!(treeUI instanceof BasicTreeUI) || ourIsLocationInExpandControl == null) {
    return false;
  }

  try {
    return (boolean)ourIsLocationInExpandControl.invoke(treeUI, path, mouseX, mouseY);
  }
  catch (IllegalAccessException | InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 
Example #25
Source File: FlatTreeUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyChangeListener createPropertyChangeListener() {
	if( !wideSelection )
		return super.createPropertyChangeListener();

	return new BasicTreeUI.PropertyChangeHandler() {
		@Override
		public void propertyChange( PropertyChangeEvent e ) {
			super.propertyChange( e );

			if( e.getSource() == tree && e.getPropertyName() == "dropLocation" ) {
				JTree.DropLocation oldValue = (JTree.DropLocation) e.getOldValue();
				repaintWideDropLocation( oldValue );
				repaintWideDropLocation( tree.getDropLocation() );
			}
		}

		private void repaintWideDropLocation(JTree.DropLocation loc) {
			if( loc == null || isDropLine( loc ) )
				return;

			Rectangle r = tree.getPathBounds( loc.getPath() );
			if( r != null )
				tree.repaint( 0, r.y, tree.getWidth(), r.height );
		}
	};
}
 
Example #26
Source File: DebugTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void clearDrawingCache(JTree tree) {
   TreeUI tui = tree.getUI();
   if (tui instanceof BasicTreeUI) {
       try {
           Field drawingCacheField = BasicTreeUI.class.getDeclaredField("drawingCache");
           drawingCacheField.setAccessible(true);
           Map table = (Map) drawingCacheField.get(tui);
           table.clear();
       } catch (Exception ex) {}
   }
}
 
Example #27
Source File: bug8003830.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #28
Source File: bug8003830.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #29
Source File: bug8003830.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}
 
Example #30
Source File: bug8003830.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void testNPEAtActionsPage() {
    JTree tree = new JTree();
    BasicTreeUI ui = new NullReturningTreeUI();
    tree.setUI(ui);
    BasicTreeUI.TreePageAction tpa = ui.new TreePageAction(0, "down");
    tpa.actionPerformed(new ActionEvent(tree, 0, ""));
}