本文整理汇总了Java中javax.swing.JTree.getSelectionRows方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.getSelectionRows方法的具体用法?Java JTree.getSelectionRows怎么用?Java JTree.getSelectionRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.getSelectionRows方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: focusLost
import javax.swing.JTree; //导入方法依赖的package包/类
@Override public void focusLost(RComponent next) {
JTree tree = (JTree) component;
String currentText = getText();
if (currentText != null && !currentText.equals(text)) {
recorder.recordSelect2(this, currentText, true);
}
if ((next == null || next.getComponent() != component) && tree.getSelectionCount() > 1) {
int[] selectionRows = tree.getSelectionRows();
if (selectionRows == null) {
selectionRows = new int[0];
}
List<Properties> pa = new ArrayList<Properties>();
for (int selectionRow : selectionRows) {
Properties p = new Properties();
p.put("Path", getTextForNode(tree, selectionRow));
pa.add(p);
}
recorder.recordSelect(this, PropertyHelper.toString(pa.toArray(new Properties[pa.size()]), new String[] { "Path" }));
}
}
示例2: haveCompleteNode
import javax.swing.JTree; //导入方法依赖的package包/类
private boolean haveCompleteNode(JTree tree) {
int[] selRows = tree.getSelectionRows();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode first =
(DefaultMutableTreeNode)path.getLastPathComponent();
int childCount = first.getChildCount();
// first has children and no children are selected.
if(childCount > 0 && selRows.length == 1)
return false;
// first may have children.
for(int i = 1; i < selRows.length; i++) {
path = tree.getPathForRow(selRows[i]);
DefaultMutableTreeNode next =
(DefaultMutableTreeNode)path.getLastPathComponent();
if(first.isNodeChild(next)) {
// Found a child of first.
if(childCount > selRows.length-1) {
// Not all children of first are selected.
return false;
}
}
}
return true;
}
示例3: haveCompleteNode
import javax.swing.JTree; //导入方法依赖的package包/类
private boolean haveCompleteNode(JTree tree) {
int[] selRows = tree.getSelectionRows();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode first = (DefaultMutableTreeNode)
path.getLastPathComponent();
int childCount = first.getChildCount();
// first has children and no children are selected.
if (childCount > 0 && selRows.length == 1) {
return false;
}
// first may have children.
for (int i = 1; i < selRows.length; i++) {
path = tree.getPathForRow(selRows[i]);
DefaultMutableTreeNode next = (DefaultMutableTreeNode)
path.getLastPathComponent();
if (first.isNodeChild(next)) {
// Found a child of first.
if (childCount > selRows.length - 1) {
// Not all children of first are selected.
return false;
}
}
}
return true;
}
示例4: keyReleased
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) {
JTree tree = (JTree) e.getSource();
int row = tree.getSelectionRows()[0];
TreePath path = tree.getSelectionPath();
if (path != null) {
CheckNode node = (CheckNode) path.getLastPathComponent();
Object o = node.getUserObject();
if (o instanceof TreeElement) {
o = ((TreeElement) o).getUserObject();
if (o instanceof RefactoringElement) {
openDiff(node);
}
// else if (o instanceof FileObject) {
// tree.expandPath(path);
// TreePath pathForRow = tree.getPathForRow(row + 1);
// CheckNode lastPathComponent = (CheckNode) pathForRow.getLastPathComponent();
// Object userObject = lastPathComponent.getUserObject();
// if (userObject instanceof TreeElement) {
// Object refElement = ((TreeElement) userObject).getUserObject();
// if (refElement instanceof RefactoringElement) {
// openDiff(lastPathComponent);
// }
// }
// }
}
}
}
}
示例5: selectNextPrev
import javax.swing.JTree; //导入方法依赖的package包/类
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) {
int[] rows = tree.getSelectionRows();
int newRow = rows == null || rows.length == 0 ? 0 : rows[0];
int maxcount = tree.getRowCount();
CheckNode node;
do {
if (next) {
newRow++;
if (newRow >= maxcount) {
newRow = 0;
}
} else {
newRow--;
if (newRow < 0) {
newRow = maxcount - 1;
}
}
TreePath path = tree.getPathForRow(newRow);
node = (CheckNode) path.getLastPathComponent();
if (!node.isLeaf()) {
tree.expandRow(newRow);
maxcount = tree.getRowCount();
}
} while (!node.isLeaf());
tree.setSelectionRow(newRow);
tree.scrollRowToVisible(newRow);
if (isQuery) {
CheckNodeListener.findInSource(node);
} else {
CheckNodeListener.openDiff(node);
}
}
示例6: selectNextPrev
import javax.swing.JTree; //导入方法依赖的package包/类
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) {
int[] rows = tree.getSelectionRows();
int newRow = rows == null || rows.length == 0 ? 0 : rows[0];
int maxcount = tree.getRowCount();
CheckNode node;
do {
if (next) {
newRow++;
if (newRow >= maxcount) {
newRow = 0;
}
} else {
newRow--;
if (newRow < 0) {
newRow = maxcount - 1;
}
}
TreePath path = tree.getPathForRow(newRow);
node = (CheckNode) path.getLastPathComponent();
if (!node.isLeaf()) {
tree.expandRow(newRow);
maxcount = tree.getRowCount();
}
} while (!node.isLeaf());
tree.setSelectionRow(newRow);
tree.scrollRowToVisible(newRow);
}
示例7: canImport
import javax.swing.JTree; //导入方法依赖的package包/类
public boolean canImport(TransferHandler.TransferSupport support) {
if(!support.isDrop()) {
return false;
}
support.setShowDropLocation(true);
if(!support.isDataFlavorSupported(nodesFlavor)) {
return false;
}
// Do not allow a drop on the drag source selections.
JTree.DropLocation dl =
(JTree.DropLocation)support.getDropLocation();
JTree tree = (JTree)support.getComponent();
int dropRow = tree.getRowForPath(dl.getPath());
int[] selRows = tree.getSelectionRows();
for(int i = 0; i < selRows.length; i++) {
if(selRows[i] == dropRow) {
return false;
}
}
// Do not allow MOVE-action drops if a non-leaf node is
// selected unless all of its children are also selected.
int action = support.getDropAction();
if(action == MOVE) {
return haveCompleteNode(tree);
}
// Do not allow a non-leaf node to be copied to a level
// which is less than its source level.
TreePath dest = dl.getPath();
DefaultMutableTreeNode target =
(DefaultMutableTreeNode)dest.getLastPathComponent();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode firstNode =
(DefaultMutableTreeNode)path.getLastPathComponent();
if(firstNode.getChildCount() > 0 &&
target.getLevel() < firstNode.getLevel()) {
return false;
}
return true;
}
示例8: canImport
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDrop()) {
return false;
}
support.setShowDropLocation(true);
if (!support.isDataFlavorSupported(nodesFlavor)) {
return false;
}
// Do not allow a drop on the drag source selections.
JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
JTree tree = (JTree) support.getComponent();
int dropRow = tree.getRowForPath(dl.getPath());
int[] selRows = tree.getSelectionRows();
for (int i = 0; i < selRows.length; i++) {
if (selRows[i] == dropRow) {
return false;
}
}
// Do not allow MOVE-action drops if a non-leaf node is
// selected unless all of its children are also selected.
int action = support.getDropAction();
if (action == MOVE) {
return haveCompleteNode(tree);
}
// Do not allow a non-leaf node to be copied to a level
// which is less than its source level.
TreePath dest = dl.getPath();
DefaultMutableTreeNode target = (DefaultMutableTreeNode)
dest.getLastPathComponent();
TreePath path = tree.getPathForRow(selRows[0]);
DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode)
path.getLastPathComponent();
if (firstNode.getChildCount() > 0
&& target.getLevel() < firstNode.getLevel()) {
return false;
}
return true;
}