提交 bd49191e 编写于 作者: A asaha

Merge

/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -872,9 +872,10 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -872,9 +872,10 @@ public class JTree extends JComponent implements Scrollable, Accessible
if(treeModelListener != null) if(treeModelListener != null)
treeModel.addTreeModelListener(treeModelListener); treeModel.addTreeModelListener(treeModelListener);
// Mark the root as expanded, if it isn't a leaf. // Mark the root as expanded, if it isn't a leaf.
if(treeModel.getRoot() != null && Object treeRoot = treeModel.getRoot();
!treeModel.isLeaf(treeModel.getRoot())) { if(treeRoot != null &&
expandedState.put(new TreePath(treeModel.getRoot()), !treeModel.isLeaf(treeRoot)) {
expandedState.put(new TreePath(treeRoot),
Boolean.TRUE); Boolean.TRUE);
} }
} }
...@@ -3223,6 +3224,9 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -3223,6 +3224,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
int count = indexs.length; int count = indexs.length;
Object parent = model.getRoot(); Object parent = model.getRoot();
if (parent == null)
return null;
TreePath parentPath = new TreePath(parent); TreePath parentPath = new TreePath(parent);
for(int counter = 0; counter < count; counter++) { for(int counter = 0; counter < count; counter++) {
...@@ -3798,8 +3802,9 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -3798,8 +3802,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (parent.getPathCount() == 1) { if (parent.getPathCount() == 1) {
// New root, remove everything! // New root, remove everything!
clearToggledPaths(); clearToggledPaths();
if(treeModel.getRoot() != null && Object treeRoot = treeModel.getRoot();
!treeModel.isLeaf(treeModel.getRoot())) { if(treeRoot != null &&
!treeModel.isLeaf(treeRoot)) {
// Mark the root as expanded, if it isn't a leaf. // Mark the root as expanded, if it isn't a leaf.
expandedState.put(parent, Boolean.TRUE); expandedState.put(parent, Boolean.TRUE);
} }
...@@ -4283,7 +4288,11 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4283,7 +4288,11 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (model == null) { if (model == null) {
return null; return null;
} }
TreePath path = new TreePath(model.getRoot()); Object treeRoot = model.getRoot();
if (treeRoot == null)
return null;
TreePath path = new TreePath(treeRoot);
if (JTree.this.isVisible(path)) { if (JTree.this.isVisible(path)) {
TreeCellRenderer r = JTree.this.getCellRenderer(); TreeCellRenderer r = JTree.this.getCellRenderer();
TreeUI ui = JTree.this.getUI(); TreeUI ui = JTree.this.getUI();
...@@ -4296,8 +4305,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4296,8 +4305,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
boolean expanded = JTree.this.isExpanded(path); boolean expanded = JTree.this.isExpanded(path);
return r.getTreeCellRendererComponent(JTree.this, return r.getTreeCellRendererComponent(JTree.this,
model.getRoot(), selected, expanded, treeRoot, selected, expanded,
model.isLeaf(model.getRoot()), row, hasFocus); model.isLeaf(treeRoot), row, hasFocus);
} }
} }
return null; return null;
...@@ -4350,8 +4359,11 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4350,8 +4359,11 @@ public class JTree extends JComponent implements Scrollable, Accessible
return 1; // the root node return 1; // the root node
} }
Object treeRoot = model.getRoot();
if (treeRoot == null)
return 0;
// return the root's first set of children count // return the root's first set of children count
return model.getChildCount(model.getRoot()); return model.getChildCount(treeRoot);
} }
/** /**
...@@ -4365,9 +4377,17 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4365,9 +4377,17 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (model == null) { if (model == null) {
return null; return null;
} }
Object treeRoot = model.getRoot();
if (treeRoot == null) {
return null;
}
if (isRootVisible()) { if (isRootVisible()) {
if (i == 0) { // return the root node Accessible if (i == 0) { // return the root node Accessible
Object[] objPath = { model.getRoot() }; Object[] objPath = { treeRoot };
if (objPath[0] == null)
return null;
TreePath path = new TreePath(objPath); TreePath path = new TreePath(objPath);
return new AccessibleJTreeNode(JTree.this, path, JTree.this); return new AccessibleJTreeNode(JTree.this, path, JTree.this);
} else { } else {
...@@ -4376,12 +4396,14 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4376,12 +4396,14 @@ public class JTree extends JComponent implements Scrollable, Accessible
} }
// return Accessible for one of root's child nodes // return Accessible for one of root's child nodes
int count = model.getChildCount(model.getRoot()); int count = model.getChildCount(treeRoot);
if (i < 0 || i >= count) { if (i < 0 || i >= count) {
return null; return null;
} }
Object obj = model.getChild(model.getRoot(), i); Object obj = model.getChild(treeRoot, i);
Object[] objPath = { model.getRoot(), obj }; if (obj == null)
return null;
Object[] objPath = { treeRoot, obj };
TreePath path = new TreePath(objPath); TreePath path = new TreePath(objPath);
return new AccessibleJTreeNode(JTree.this, path, JTree.this); return new AccessibleJTreeNode(JTree.this, path, JTree.this);
} }
...@@ -4420,6 +4442,9 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4420,6 +4442,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
public int getAccessibleSelectionCount() { public int getAccessibleSelectionCount() {
Object[] rootPath = new Object[1]; Object[] rootPath = new Object[1];
rootPath[0] = treeModel.getRoot(); rootPath[0] = treeModel.getRoot();
if (rootPath[0] == null)
return 0;
TreePath childPath = new TreePath(rootPath); TreePath childPath = new TreePath(rootPath);
if (JTree.this.isPathSelected(childPath)) { if (JTree.this.isPathSelected(childPath)) {
return 1; return 1;
...@@ -4442,6 +4467,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4442,6 +4467,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (i == 0) { if (i == 0) {
Object[] rootPath = new Object[1]; Object[] rootPath = new Object[1];
rootPath[0] = treeModel.getRoot(); rootPath[0] = treeModel.getRoot();
if (rootPath[0] == null)
return null;
TreePath childPath = new TreePath(rootPath); TreePath childPath = new TreePath(rootPath);
if (JTree.this.isPathSelected(childPath)) { if (JTree.this.isPathSelected(childPath)) {
return new AccessibleJTreeNode(JTree.this, childPath, JTree.this); return new AccessibleJTreeNode(JTree.this, childPath, JTree.this);
...@@ -4461,6 +4488,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4461,6 +4488,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (i == 0) { if (i == 0) {
Object[] rootPath = new Object[1]; Object[] rootPath = new Object[1];
rootPath[0] = treeModel.getRoot(); rootPath[0] = treeModel.getRoot();
if (rootPath[0] == null)
return false;
TreePath childPath = new TreePath(rootPath); TreePath childPath = new TreePath(rootPath);
return JTree.this.isPathSelected(childPath); return JTree.this.isPathSelected(childPath);
} else { } else {
...@@ -4482,6 +4511,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4482,6 +4511,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (model != null) { if (model != null) {
if (i == 0) { if (i == 0) {
Object[] objPath = {model.getRoot()}; Object[] objPath = {model.getRoot()};
if (objPath[0] == null)
return;
TreePath path = new TreePath(objPath); TreePath path = new TreePath(objPath);
JTree.this.addSelectionPath(path); JTree.this.addSelectionPath(path);
} }
...@@ -4500,6 +4531,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4500,6 +4531,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
if (model != null) { if (model != null) {
if (i == 0) { if (i == 0) {
Object[] objPath = {model.getRoot()}; Object[] objPath = {model.getRoot()};
if (objPath[0] == null)
return;
TreePath path = new TreePath(objPath); TreePath path = new TreePath(objPath);
JTree.this.removeSelectionPath(path); JTree.this.removeSelectionPath(path);
} }
...@@ -4525,6 +4558,8 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -4525,6 +4558,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
TreeModel model = JTree.this.getModel(); TreeModel model = JTree.this.getModel();
if (model != null) { if (model != null) {
Object[] objPath = {model.getRoot()}; Object[] objPath = {model.getRoot()};
if (objPath[0] == null)
return;
TreePath path = new TreePath(objPath); TreePath path = new TreePath(objPath);
JTree.this.addSelectionPath(path); JTree.this.addSelectionPath(path);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册