/** 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); } } }
/** 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 } }
public void setModel(TreeModel model) { if(!(model instanceof UnitedNameTreeModel)) return; TreeModel currentModel = getModel(); if(currentModel != null && currentModel instanceof UnitedNameTreeModel) ((UnitedNameTreeModel)currentModel).removeUnitedNameTreeModelListener(this); super.setModel(model); TreeUI ui = getUI(); if((model instanceof NodeMapper) && (ui instanceof Aligner)) ((Aligner)ui).setMapper((NodeMapper)model); if(model != null && model instanceof UnitedNameTreeModel) ((UnitedNameTreeModel)model).addUnitedNameTreeModelListener(this); }
private Component getCurrentComponent() { debugString("AccessibleJTreeNode: getCurrentComponent"); // is the object visible? // if so, get row, selected, focus & leaf state, // and then get the renderer component and return it if (tree.isVisible(path)) { TreeCellRenderer r = tree.getCellRenderer(); if (r == null) { debugString(" returning null 1"); return null; } TreeUI ui = tree.getUI(); if (ui != null) { int row = ui.getRowForPath(tree, path); boolean selected = tree.isPathSelected(path); boolean expanded = tree.isExpanded(path); boolean hasFocus = false; // how to tell?? -PK Component retval = r.getTreeCellRendererComponent(tree, obj, selected, expanded, isLeaf, row, hasFocus); debugString(" returning = "+retval.getClass()); return retval; } } debugString(" returning null 2"); return null; }
/** * Get the pathes that are displayes between the two given rows. * * @param index0 the starting row, inclusive * @param index1 the ending row, inclusive * * @return the array of the tree pathes */ protected TreePath[] getPathBetweenRows(int index0, int index1) { TreeUI ui = getUI(); if (ui == null) return null; int minIndex = Math.min(index0, index1); int maxIndex = Math.max(index0, index1); TreePath[] paths = new TreePath[maxIndex - minIndex + 1]; for (int i = minIndex; i <= maxIndex; ++i) paths[i - minIndex] = ui.getPathForRow(this, i); return paths; }
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; }
public static void doNotFillBackground(@NotNull final JTree tree, @NotNull final DefaultTreeCellRenderer renderer) { TreeUI ui = tree.getUI(); if (ui instanceof WideSelectionTreeUI) { if (((WideSelectionTreeUI)ui).isWideSelection()) { renderer.setOpaque(false); try { final Field fillBackground = DefaultTreeCellRenderer.class.getDeclaredField("fillBackground"); fillBackground.setAccessible(true); fillBackground.set(renderer, false); } catch (Exception e) { // nothing } } } }
public void setUI(final TreeUI ui) { super.setUI(ui); // [vova] we cannot create this hash in constructor and just clear it here. The // problem is that setUI is invoked by constructor of superclass. myHighlightAttributes = new HashMap<HighlightSeverity, Map<SimpleTextAttributes, SimpleTextAttributes>>(); final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes attributes = globalScheme.getAttributes(JavaHighlightingColors.STRING); myBindingAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getTreeForeground()); myClassAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()); myPackageAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.GRAY); myTitleAttributes =new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, attributes.getForegroundColor()); myUnknownAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.RED); }
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; }
@Override public void setUI(final TreeUI ui) { super.setUI(ui); // [vova] we cannot create this hash in constructor and just clear it here. The // problem is that setUI is invoked by constructor of superclass. myHighlightAttributes = new HashMap<HighlightSeverity, Map<SimpleTextAttributes, SimpleTextAttributes>>(); final EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme(); final TextAttributes attributes = globalScheme.getAttributes(JavaHighlightingColors.STRING); myBindingAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getTreeForeground()); myClassAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getTreeForeground()); myPackageAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.GRAY); myTitleAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, attributes.getForegroundColor()); myUnknownAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.RED); }
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); } }
public static void doNotFillBackground(@Nonnull final JTree tree, @Nonnull final DefaultTreeCellRenderer renderer) { TreeUI ui = tree.getUI(); if (ui instanceof WideSelectionTreeUI) { if (((WideSelectionTreeUI)ui).isWideSelection()) { renderer.setOpaque(false); try { final Field fillBackground = DefaultTreeCellRenderer.class.getDeclaredField("fillBackground"); fillBackground.setAccessible(true); fillBackground.set(renderer, false); } catch (Exception e) { // nothing } } } }
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) {} } }
/** * Invokes the <code>getPathBounds</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Rectangle getPathBounds(JTree a, TreePath b) { Rectangle returnValue = ((TreeUI) (uis.elementAt(0))).getPathBounds(a,b); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getPathBounds(a,b); } return returnValue; }
/** * Invokes the <code>getPathForRow</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public TreePath getPathForRow(JTree a, int b) { TreePath returnValue = ((TreeUI) (uis.elementAt(0))).getPathForRow(a,b); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getPathForRow(a,b); } return returnValue; }
/** * Invokes the <code>getRowForPath</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public int getRowForPath(JTree a, TreePath b) { int returnValue = ((TreeUI) (uis.elementAt(0))).getRowForPath(a,b); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getRowForPath(a,b); } return returnValue; }
/** * Invokes the <code>getRowCount</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public int getRowCount(JTree a) { int returnValue = ((TreeUI) (uis.elementAt(0))).getRowCount(a); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getRowCount(a); } return returnValue; }
/** * Invokes the <code>getClosestPathForLocation</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public TreePath getClosestPathForLocation(JTree a, int b, int c) { TreePath returnValue = ((TreeUI) (uis.elementAt(0))).getClosestPathForLocation(a,b,c); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getClosestPathForLocation(a,b,c); } return returnValue; }
/** * Invokes the <code>isEditing</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public boolean isEditing(JTree a) { boolean returnValue = ((TreeUI) (uis.elementAt(0))).isEditing(a); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).isEditing(a); } return returnValue; }
/** * Invokes the <code>stopEditing</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public boolean stopEditing(JTree a) { boolean returnValue = ((TreeUI) (uis.elementAt(0))).stopEditing(a); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).stopEditing(a); } return returnValue; }
/** * Invokes the <code>getEditingPath</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public TreePath getEditingPath(JTree a) { TreePath returnValue = ((TreeUI) (uis.elementAt(0))).getEditingPath(a); for (int i = 1; i < uis.size(); i++) { ((TreeUI) (uis.elementAt(i))).getEditingPath(a); } return returnValue; }
private Component getCurrentComponent() { debugString("AccessibleJTreeNode: getCurrentComponent"); // is the object visible? // if so, get row, selected, focus & leaf state, // and then get the renderer component and return it if (tree != null && tree.isVisible(path)) { TreeCellRenderer r = tree.getCellRenderer(); if (r == null) { debugString(" returning null 1"); return null; } TreeUI ui = tree.getUI(); if (ui != null) { int row = ui.getRowForPath(tree, path); boolean selected = tree.isPathSelected(path); boolean expanded = tree.isExpanded(path); boolean hasFocus = false; // how to tell?? -PK Component retval = r.getTreeCellRendererComponent(tree, obj, selected, expanded, isLeaf, row, hasFocus); debugString(" returning = "+retval.getClass()); return retval; } } debugString(" returning null 2"); return null; }