/** 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); } } }
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); }
/** 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); } } }
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 { super.setUI(ui); // #269500 - performance workaround for BasicTreeUI if (!DISABLE_TREEUI_FIX && ui instanceof BasicTreeUI) workaroundVerticalLines = UIManager.getBoolean("Tree.paintLines"); // NOI18N } }
/** * Constructs a tree, with cell renderer and editor set by * {@link #createRenderer()} and {@link #createEditor()}. */ public CheckboxTree() { setCellRenderer(createRenderer()); setCellEditor(createEditor()); setEditable(true); setRootVisible(false); setShowsRootHandles(true); // make sure the checkbox never selects the label // note that the BasicTreeUI may not be what is used in the current LAF, // but I don't know any other way to modify the selection behaviour BasicTreeUI ui = new BasicTreeUI() { @Override protected void selectPathForEvent(TreePath path, MouseEvent event) { if (!isOverCheckBox(path, event.getPoint().x)) { super.selectPathForEvent(path, event); } } }; setUI(ui); // initialise the tree model this.topNode = new DefaultMutableTreeNode(); this.treeModel = new DefaultTreeModel(this.topNode); setModel(this.treeModel); // set selection mode getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); }
public void createRecordTree(){ model = new RecordTreeModel(); this.setModel(model); renderer = new RecordTreeCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); this.setCellRenderer(renderer); renderer.setIcon(null); renderer.setOpenIcon(null); renderer.setClosedIcon(null); editor = new RecordTreeCellEditor(this,renderer); this.setCellEditor(editor); this.setEditable(true); this.setRootVisible(false); this.putClientProperty("JTree.lineStyle", "None"); ((BasicTreeUI)this.getUI()).setCollapsedIcon(null); ((BasicTreeUI)this.getUI()).setExpandedIcon(null); this.setScrollsOnExpand(true); this.setExpandsSelectedPaths(true); }
private void handleKeys(Component comp,KeyEvent e){ if(e.getKeyCode()==KeyEvent.VK_L && e.getModifiers()== InputEvent.CTRL_MASK) listiciButton.doClick(); if(e.getKeyCode()==KeyEvent.VK_V && e.getModifiers()== InputEvent.CTRL_MASK) validateRecord.doClick(); /*if(e.getKeyCode()==KeyEvent.VK_NUMPAD7) addUField.doClick(); */ if(e.getKeyCode()==KeyEvent.VK_ESCAPE){ if(comp.equals(zapisPanel.getRecordTree())){ if(!((BasicTreeUI)zapisPanel.getRecordTree().getUI()).isEditing(zapisPanel.getRecordTree())) handleCloseEditor(); }else handleCloseEditor(); } if(e.getKeyCode()== KeyEvent.VK_S){ saveRecord.doClick(); } if(e.getKeyCode()==KeyEvent.VK_F6 && e.getModifiers()== InputEvent.CTRL_MASK){ BisisApp.getMainFrame().selectNextInternalFrame(); } }
private void clearRendererCache() { // 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(); for (int i = rowForLocation + visibleRowCount + 1; i >= rowForLocation; i--) { final TreePath eachPath = myTree.getPathForRow(i); if (eachPath == null) continue; treeState.invalidatePathBounds(eachPath); } myTree.repaint(visibleRect); } else { myTree.setCellRenderer(myUsageViewTreeCellRenderer); } }
private boolean isLocationInExpandControl(final TreePath path, final int x, final int y) { final TreeUI ui = getUI(); if (!(ui instanceof BasicTreeUI)) return false; try { Class aClass = ui.getClass(); while (BasicTreeUI.class.isAssignableFrom(aClass) && !BasicTreeUI.class.equals(aClass)) { aClass = aClass.getSuperclass(); } final Method method = ReflectionUtil.getDeclaredMethod(aClass, "isLocationInExpandControl", TreePath.class, int.class, int.class); if (method != null) { return (Boolean)method.invoke(ui, path, x, y); } } catch (Throwable ignore) { } return false; }
protected boolean isLocationInExpandControl(@Nullable TreePath path, int mouseX) { if (path == null) return false; TreeUI ui = getUI(); if (!(ui instanceof BasicTreeUI)) return false; BasicTreeUI treeUI = (BasicTreeUI)ui; if (!treeModel.isLeaf(path.getLastPathComponent())) { Insets insets = this.getInsets(); int boxWidth = treeUI.getExpandedIcon() != null ? treeUI.getExpandedIcon().getIconWidth() : 8; int boxLeftX = treeUI.getLeftChildIndent() + treeUI.getRightChildIndent() * (path.getPathCount() - 1); if (getComponentOrientation().isLeftToRight()) { boxLeftX = boxLeftX + insets.left - treeUI.getRightChildIndent() + 1; } else { boxLeftX = getWidth() - boxLeftX - insets.right + treeUI.getRightChildIndent() - 1; } boxLeftX -= getComponentOrientation().isLeftToRight() ? (int)Math.ceil(boxWidth / 2.0) : (int)Math.floor(boxWidth / 2.0); return mouseX >= boxLeftX && mouseX < boxLeftX + boxWidth; } return false; }
private boolean isLocationInExpandControl(final TreePath path, final int x, final int y) { final TreeUI ui = getUI(); if (!(ui instanceof BasicTreeUI)) return false; try { Class aClass = ui.getClass(); while (BasicTreeUI.class.isAssignableFrom(aClass) && !BasicTreeUI.class.equals(aClass)) { aClass = aClass.getSuperclass(); } final Method method = ReflectionUtil.getDeclaredMethod(aClass, "isLocationInExpandControl", TreePath.class, int.class, int.class); if (method != null) { method.setAccessible(true); return (Boolean)method.invoke(ui, path, x, y); } } catch (Throwable ignore) { } return false; }
protected boolean isLocationInExpandControl(@Nullable TreePath path, int mouseX) { if (path == null) return false; TreeUI ui = getUI(); if (!(ui instanceof BasicTreeUI)) return false; BasicTreeUI treeUI = (BasicTreeUI)ui; if (!treeModel.isLeaf(path.getLastPathComponent())) { Insets insets = Tree.this.getInsets(); int boxWidth = treeUI.getExpandedIcon() != null ? treeUI.getExpandedIcon().getIconWidth() : 8; int boxLeftX = treeUI.getLeftChildIndent() + treeUI.getRightChildIndent() * (path.getPathCount() - 1); if (getComponentOrientation().isLeftToRight()) { boxLeftX = boxLeftX + insets.left - treeUI.getRightChildIndent() + 1; } else { boxLeftX = getWidth() - boxLeftX - insets.right + treeUI.getRightChildIndent() - 1; } boxLeftX -= (getComponentOrientation().isLeftToRight() ? (int)Math.ceil(boxWidth / 2.0) : (int)Math.floor(boxWidth / 2.0)); return (mouseX >= boxLeftX && mouseX < (boxLeftX + boxWidth)); } return false; }
private void clearRendererCache() { ApplicationManager.getApplication().assertIsDispatchThread(); if (expandingAll) 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(); for (int i = rowForLocation + visibleRowCount + 1; i >= rowForLocation; i--) { final TreePath eachPath = myTree.getPathForRow(i); if (eachPath == null) continue; treeState.invalidatePathBounds(eachPath); } myTree.repaint(visibleRect); } else { myTree.setCellRenderer(myUsageViewTreeCellRenderer); } }
private void setTreeUIVariables() { if (tree.getUI() instanceof BasicTreeUI) { BasicTreeUI treeUI = (BasicTreeUI) tree.getUI(); treeSignExtent = treeUI.getExpandedIcon().getIconWidth() / 2; treeSignRightMargin = treeUI.getRightChildIndent(); } }
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) {} } }
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()); }
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, "")); }
private void createPubTypeTree(){ treeModel = new PubTypeTreeModel(1); pubTypeTree = new JTree(treeModel); pubTypeTree.putClientProperty("JTree.lineStyle", "None"); //$NON-NLS-1$ //$NON-NLS-2$ pubTypeTree.setRootVisible(false); ((BasicTreeUI)pubTypeTree.getUI()).setCollapsedIcon(null); ((BasicTreeUI)pubTypeTree.getUI()).setExpandedIcon(null); treeCellRenderer = new PubTypeTreeCellRenderer(); pubTypeTree.setCellRenderer(treeCellRenderer); treeScrollPane = new JScrollPane(pubTypeTree); }
private void createTree(){ model = new FormatTreeModel(); setModel(model); //setRootVisible(false); renderer = new FormatTreeCellRenderer(); putClientProperty("JTree.lineStyle", "None"); ((BasicTreeUI)this.getUI()).setCollapsedIcon(null); ((BasicTreeUI)this.getUI()).setExpandedIcon(null); setCellRenderer(renderer); }
public AlignableFixedHeightLayoutCache(BasicTreeUI ui, LayoutCacheAligner aligner) { super(); setUI(ui); setAligner(aligner); }
public AlignableVariableHeightLayoutCache(BasicTreeUI ui, LayoutCacheAligner aligner) { super(); setUI(ui); setAligner(aligner); setAlignable(true); }
public synchronized void setUI(BasicTreeUI ui) { this.ui = ui; if(ui instanceof AlignableTreeUI) alignable = (AlignableTreeUI)ui; else alignable = null; }
public void setCollapsedIcon(Icon icon) { if(tree instanceof NameTree) ((NameTree)tree).setCollapsedIcon(icon); else ((BasicTreeUI)tree.getUI()).setCollapsedIcon(icon); }
public void setExpandedIcon(Icon icon) { if(tree instanceof NameTree) ((NameTree)tree).setExpandedIcon(icon); else ((BasicTreeUI)tree.getUI()).setExpandedIcon(icon); }
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; }
@Nullable public static Range<Integer> getExpandControlRange(@NotNull 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(); if (expandedIcon != null) { boxWidth = expandedIcon.getIconWidth(); } else { boxWidth = 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<Integer>(boxLeftX, boxRightX); } return box; }
public void customizeCellRenderer(@NotNull final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { myHaveLink = false; myLink.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); XDebuggerTreeNode node = (XDebuggerTreeNode)value; node.appendToComponent(this); setIcon(node.getIcon()); Rectangle treeVisibleRect = tree.getVisibleRect(); TreePath path = tree.getPathForRow(row); int rowX = path != null ? getRowX((BasicTreeUI)tree.getUI(), row, path.getPathCount() - 1) : 0; if (myHaveLink) { setupLinkDimensions(treeVisibleRect, rowX); } else { if (rowX + super.getPreferredSize().width > treeVisibleRect.x + treeVisibleRect.width) { // text does not fit visible area - show link if (node instanceof XValueNodeImpl) { final String rawValue = DebuggerUIUtil.getNodeRawValue((XValueNodeImpl)node); if (!StringUtil.isEmpty(rawValue)) { myLongTextLink.setupComponent(rawValue, ((XDebuggerTree)tree).getProject()); append(myLongTextLink.getLinkText(), myLongTextLink.getTextAttributes(), myLongTextLink); setupLinkDimensions(treeVisibleRect, rowX); myLinkWidth = 0; } } } } putClientProperty(AbstractExpandableItemsHandler.DISABLE_EXPANDABLE_HANDLER, myHaveLink ? true : null); }
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; }
/** * If a negative number is returned, then all events that occur in the * leading margin will be forwarded to the tree and consumed. * * @return the width of the tree handle if it can be determined, else -1 */ protected int getTreeHandleWidth() { if (renderer.getUI() instanceof BasicTreeUI) { BasicTreeUI ui = (BasicTreeUI) renderer.getUI(); return ui.getLeftChildIndent() + ui.getRightChildIndent(); } else { return -1; } }
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); }
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); } }); }
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); } }); }