下面列出了怎么用javax.swing.plaf.basic.BasicTreeUI的API类实例代码及写法,或者点击链接到github查看源代码。
/** 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 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");
}
}
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");
}
}
@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 );
}
};
}
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, ""));
}
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, ""));
}
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, ""));
}
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, ""));
}
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
}
}
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 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, ""));
}
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, ""));
}
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, ""));
}
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, ""));
}
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, ""));
}
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
}
}
private void setTreeUIVariables() {
if (tree.getUI() instanceof BasicTreeUI) {
BasicTreeUI treeUI = (BasicTreeUI) tree.getUI();
treeSignExtent = treeUI.getExpandedIcon().getIconWidth() / 2;
treeSignRightMargin = treeUI.getRightChildIndent();
}
}
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, ""));
}
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, ""));
}
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, ""));
}
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, ""));
}
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);
}
});
}
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());
}
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);
}
}
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;
}