本文整理汇总了Java中javax.swing.JTree.getPathForRow方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.getPathForRow方法的具体用法?Java JTree.getPathForRow怎么用?Java JTree.getPathForRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.getPathForRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTree tree = (JTree) e.getSource();
Point p = e.getPoint();
int row = tree.getRowForLocation(e.getX(), e.getY());
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if (path != null) {
FileNode node = (FileNode) path.getLastPathComponent();
Rectangle chRect = DeletedListRenderer.getCheckBoxRectangle();
Rectangle rowRect = tree.getPathBounds(path);
chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
if (e.getClickCount() == 1 && chRect.contains(p)) {
boolean isSelected = !(node.isSelected());
node.setSelected(isSelected);
((DefaultTreeModel) tree.getModel()).nodeChanged(node);
if (row == 0) {
tree.revalidate();
}
tree.repaint();
}
}
}
示例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: restoreLastExpandedPaths
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expand all the path from the given expandedPaths and the given tree
*
* @param expandedPaths
* - the paths to expand
* @param tree
* - the tree on which the paths has to be expanded
*/
public static void restoreLastExpandedPaths(Enumeration<TreePath> expandedPaths, JTree tree) {
if (expandedPaths != null) {
List<TreePath> paths = Collections.list(expandedPaths);
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath currentPath = tree.getPathForRow(i);
String currentStringPath = TreeFormatter.getStringPath(currentPath);
for (TreePath treePath : paths) {
String stringTreePahr = TreeFormatter.getStringPath(treePath);
if (currentStringPath.equals(stringTreePahr)) {
tree.expandRow(i);
}
}
}
}
}
示例4: mousePressed
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent event) {
JTree tree = (JTree) event.getSource();
int x = event.getX();
int y = event.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if (path == null) {
return;
}
CheckNode node = (CheckNode) path.getLastPathComponent();
if ( !SwingUtilities.isRightMouseButton(event)) {
return;
}
Object o = node.getUserObject();
}
示例5: storeScrollPosition
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Store first visible node and its offset. Called when the view is scrolled
* by the user.
*/
private void storeScrollPosition() {
JTree tree = getJTree();
if (tree != null) {
int scrollTop = mainScrollPane.getViewport().getViewPosition().y;
int row = tree.getClosestRowForLocation(tree.getRowBounds(0).x + 1,
scrollTop);
if (row >= 0) {
TreePath path = tree.getPathForRow(row);
if (path != null) {
int offset = tree.getRowBounds(row).y - scrollTop;
visibleTreePosition = new VisibleTreePosition(
path, offset);
return;
}
} else {
return;
}
}
visibleTreePosition = null;
}
示例6: saveExpansionState
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Saves the currently selected paths and saves all expanded repositories and nodes.
*
* @param tree
* The related tree, containing the path(s)
*/
public void saveExpansionState(JTree tree) {
saveSelectionPaths(tree.getSelectionPaths());
expandedNodes = new HashSet<>();
expandedRepositories = new HashSet<>();
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath path = tree.getPathForRow(i);
if (tree.isExpanded(path)) {
Entry entry = (Entry) path.getLastPathComponent();
String absoluteLocation = entry.getLocation().getAbsoluteLocation();
if (entry instanceof Repository) {
expandedRepositories.add(absoluteLocation);
} else {
expandedNodes.add(absoluteLocation);
}
}
}
}
示例7: restoreExpansionState
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expands all repositories and nodes, which have been saved before. Restores selected paths,
* which have been saved proviously.
*
* @param tree
* The related tree, containing the path(s)
*/
public void restoreExpansionState(JTree tree) {
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath path = tree.getPathForRow(i);
Object entryObject = path.getLastPathComponent();
if (entryObject instanceof Entry) {
Entry entry = (Entry) entryObject;
String absoluteLocation = entry.getLocation().getAbsoluteLocation();
if (expandedRepositories.contains(absoluteLocation) || expandedNodes.contains(absoluteLocation)) {
tree.expandPath(path);
}
}
}
restoreSelectionPaths(tree);
}
示例8: getTreeCellRendererComponent
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
((DefaultTreeCellRenderer) renderer).setIcon(null);
((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
((DefaultTreeCellRenderer) renderer).setClosedIcon(null);
TreePath path = tree.getPathForRow(row);
if (path != null) {
if (selectionModel.isPathSelected(path, true)) {
checkBox.setState(Boolean.TRUE);
} else {
checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
}
}
removeAll();
add(checkBox, BorderLayout.WEST);
add(renderer, BorderLayout.CENTER);
return this;
}
示例9: getTextForNode
import javax.swing.JTree; //导入方法依赖的package包/类
private String getTextForNode(JTree tree, int row) {
TreePath treePath = tree.getPathForRow(row);
if (treePath == null) {
return row + "";
}
StringBuilder sb = new StringBuilder();
int start = tree.isRootVisible() ? 0 : 1;
Object[] objs = treePath.getPath();
for (int i = start; i < objs.length; i++) {
String pathString;
if (objs[i].toString() == null) {
pathString = "";
} else {
pathString = escapeSpecialCharacters(getTextForNodeObject(tree, objs[i]));
}
sb.append("/" + pathString);
}
return sb.toString();
}
示例10: 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;
}
示例11: 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);
}
}
示例12: mouseClicked
import javax.swing.JTree; //导入方法依赖的package包/类
public void mouseClicked(MouseEvent e) {
// todo (#pf): we need to solve problem between click and double
// click - click should be possible only on the check box area
// and double click should be bordered by title text.
// we need a test how to detect where the mouse pointer is
JTree tree = (JTree) e.getSource();
Point p = e.getPoint();
int x = e.getX();
int y = e.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
// if path exists and mouse is clicked exactly once
if( null == path )
return;
Node node = Visualizer.findNode( path.getLastPathComponent() );
if( null == node )
return;
Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
Rectangle rowRect = tree.getPathBounds(path);
chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
if (e.getClickCount() == 1 && chRect.contains(p)) {
boolean isSelected = settings.isNodeVisible( node );
settings.setNodeVisible( node, !isSelected );
tree.repaint();
}
}
示例13: 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);
}
示例14: format
import javax.swing.JTree; //导入方法依赖的package包/类
@Override
protected void format(CellContext arg0) {
// 从CellContext获取tree中的文字和图标
JTree tree = (JTree) arg0.getComponent();
DefaultMutableTreeTableNode node = (DefaultMutableTreeTableNode) arg0.getValue();
Object obj = node.getUserObject();
if(obj instanceof FieldEntity){
_label.setText(((FieldEntity) obj).getKey());
_checkBox.setSelector((FieldEntity) obj);
}else if(obj instanceof ClassEntity){
_label.setText(((ClassEntity) obj).getClassName());
_checkBox.setSelector((ClassEntity) obj);
}
// _label.setIcon(arg0.getIcon());
// 根据selectionModel中的状态来绘制TristateCheckBox的外观
TreePath path = tree.getPathForRow(arg0.getRow());
if (path != null) {
if (selectionModel.isPathSelected(path, true)) {
_checkBox.setState(Boolean.TRUE);
} else if (selectionModel.isPartiallySelected(path)) {
_checkBox.setState(null); // 注意“部分选中”状态的API
} else {
_checkBox.setState(Boolean.FALSE);
}
}
// 使用BorderLayout布局,依次放置TristateCheckBox和JLabel
rendererComponent.setLayout(new BorderLayout());
rendererComponent.add(_checkBox);
rendererComponent.add(_label, BorderLayout.LINE_END);
}
示例15: getText
import javax.swing.JTree; //导入方法依赖的package包/类
@Override public String getText() {
JTree tree = (JTree) component;
if (row == -1) {
return null;
}
TreePath rowPath = tree.getPathForRow(row);
if (rowPath == null) {
return null;
}
Object lastPathComponent = rowPath.getLastPathComponent();
if (lastPathComponent != null) {
return getTextForNodeObject(tree, lastPathComponent);
}
return null;
}