List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
/** * This method removes the passed tree node from the tree * and selects appropiate node/*from w w w.j a v a 2 s. c o m*/ * * @param selNode node to be removed */ public void removeNode(DBBrowserNode selNode) { if (selNode != null) { //get the parent of the selected node DBBrowserNode parent = (DBBrowserNode) (selNode.getParent()); // if the parent is not null if (parent != null) { //get the sibling node to be selected after removing the //selected node DBBrowserNode toBeSelNode = getSibling(selNode); //if there are no siblings select the parent node after removing the node if (toBeSelNode == null) { toBeSelNode = parent; } //make the node visible by scroll to it TreeNode[] nodes = model.getPathToRoot(toBeSelNode); TreePath path = new TreePath(nodes); scrollPathToVisible(path); setSelectionPath(path); //remove the node from the parent model.removeNodeFromParent(selNode); } } }
From source file:ru.apertum.qsystem.client.forms.FReception.java
private void textFieldSerchServiceKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldSerchServiceKeyReleased TreeNode node = null;/*from w ww . j a v a 2 s .c o m*/ boolean flag = evt.getKeyCode() != 114; final QService ser = (QService) treeServices.getLastSelectedPathComponent(); for (Object object : ((ATreeModel) treeServices.getModel()).getNodes()) { final QService service = (QService) object; if (flag) { if (service.toString().toLowerCase() .contains(textFieldSerchService.getText().trim().toLowerCase())) { node = (TreeNode) object; break; } } else { if (!flag && (ser == null || service.getId().equals(ser.getId()))) { flag = true; } } } if (node != null) { TreeNode[] nodes = ((DefaultTreeModel) treeServices.getModel()).getPathToRoot(node); TreePath path = new TreePath(nodes); treeServices.setSelectionPath(path); treeServices.setExpandsSelectedPaths(true); treeServices.scrollPathToVisible(path); } else { Toolkit.getDefaultToolkit().beep(); } }
From source file:ru.apertum.qsystem.client.forms.FReception.java
private void listServicesForUserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listServicesForUserMouseClicked if (evt.getClickCount() > 1 && listServicesForUser.getSelectedIndex() != -1) { tabsPane.setSelectedComponent(panelServices); TreeNode[] nodes = ((DefaultTreeModel) treeServices.getModel()) .getPathToRoot(((ATreeModel) treeServices.getModel()) .getById(((QPlanService) listServicesForUser.getSelectedValue()).getService().getId())); TreePath path = new TreePath(nodes); treeServices.setSelectionPath(path); treeServices.setExpandsSelectedPaths(true); treeServices.scrollPathToVisible(path); }/*from w ww. j av a2 s . c om*/ }
From source file:ru.apertum.qsystem.client.forms.FReception.java
private void tableServicesMonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableServicesMonMouseClicked if (evt.getClickCount() > 1 && tableServicesMon.getSelectedRow() != -1) { tabsPane.setSelectedComponent(panelServices); TreeNode[] nodes = ((DefaultTreeModel) treeServices.getModel()) .getPathToRoot(((ATreeModel) treeServices.getModel()).getById(((ServiceInfo) tableServicesMon .getModel().getValueAt(tableServicesMon.getSelectedRow(), 2)).getId())); TreePath path = new TreePath(nodes); treeServices.setSelectionPath(path); treeServices.setExpandsSelectedPaths(true); treeServices.scrollPathToVisible(path); }/*w ww . jav a 2s.c om*/ }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
private void showFile(final File file, final boolean addIt) { locationTextField.setText(file.getAbsolutePath()); refreshReplacements();/*from w ww . j a v a 2s. c o m*/ try { StringBuilder sb = new StringBuilder(10 * 1024); sb.append("<html><head><title>" + file.getName() + "</title><style>body {font-size: 1em;}pre {margin: 0;}</style></head><body>"); String parent = file.getParent(); LineIterator lines = FileUtils.lineIterator(file, "UTF-8"); while (lines.hasNext()) { String line = StringEscapeUtils.escapeHtml4(lines.next()); sb.append("<pre>"); if (line.startsWith(LINK_LINE_START)) { String href = getFileLocation(parent, line); sb.append("<a href=\"").append(href).append("\">").append(line).append("</a>"); } else { sb.append(line); } sb.append("</pre>"); } sb.append("</body></html>"); lines.close(); sourceEditorPane.setText(sb.toString()); sourceEditorPane.setCaretPosition(0); if (addIt) { int listSize = pageList.size(); if (listSize > 0) { int pageIndex = pageList.indexOf(currentFile); if (pageIndex < listSize - 1) { for (int i = listSize - 1; i > pageIndex; i--) { pageList.remove(i); } } } pageList.add(file); } currentFile = file; updateButtons(); if (paths.containsKey(file)) { currentSelectionPath = new TreePath(paths.get(file)); documentTree.setSelectionPath(currentSelectionPath); } } catch (IOException e) { showError("Error in file handling: " + e); } }
From source file:studio.ui.Studio.java
private void createConnectionsTree() { if (treeConnections == null) { treeConnections = new KdbServicesTree(tabEditors); tools.setConnectionsView((KdbServicesTree) treeConnections); tabEditors.addFireDataListener((DataListener) treeConnections); }/*from w w w. ja v a 2 s . c om*/ DefaultMutableTreeNode top = null; if (!(treeConnections.getModel() instanceof DefaultMutableTreeNode)) { top = new DefaultMutableTreeNode("KDB+ servers"); treeConnections.setModel(new KdbServicesTreeModel(top)); treeConnections.setCellRenderer(new KdbServicesTreeCellRender()); Collection<String> hostnames = studioConfig.getHosts(); if (hostnames != null && !hostnames.isEmpty()) { for (String hostname : hostnames) { try { InetAddress.getAllByName(hostname); top.add(new HostTreeNode(hostname, studioConfig.getConnections(hostname))); } catch (UnknownHostException ignored) { } } } } treeConnections.expandPath(new TreePath(top)); treeConnections.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); }
From source file:studio.ui.Studio.java
private void createProjectsTree() { if (treeProjects == null) { treeProjects = new ProjectTree(tabEditors, tabConsoles); tools.setProjectView((ProjectTree) treeProjects); }/*from w ww . j a v a 2 s . co m*/ DefaultMutableTreeNode top = null; if (!(treeProjects.getModel() instanceof DefaultMutableTreeNode)) { top = new DefaultMutableTreeNode("q Projects"); ProjectConfig projects = null; try { projects = ProjectConfig.getConfig(); } catch (StudioException ignored) { } treeProjects.setModel(new FileTreeModel(projects)); if (treeProjects.getModel() instanceof TreeModelSupport) { treeProjects.getModel().addTreeModelListener(new ProjectTreeModelListener()); } treeProjects.setCellRenderer(new ProjectTreeCellRender()); } if (top != null) { treeProjects.expandPath(new TreePath(top)); } }
From source file:tvbrowser.extras.favoritesplugin.dlgs.FavoriteTreeModel.java
public void reload(FavoriteTree tree, TreeNode node) { super.reload(node); @SuppressWarnings("unchecked") Enumeration<FavoriteNode> e = node.children(); while (e.hasMoreElements()) { FavoriteNode child = e.nextElement(); if (child.isDirectoryNode()) { reload(tree, child);/*from w ww .j ava 2 s. co m*/ } } FavoriteNode parent = (FavoriteNode) node; if (parent.wasExpanded()) { tree.expandPath(new TreePath((tree.getModel()).getPathToRoot(node))); } else { tree.collapsePath(new TreePath((tree.getModel()).getPathToRoot(node))); } }
From source file:tvbrowser.ui.filter.dlgs.FilterTreeModel.java
public void reload(FilterTree tree, TreeNode node) { super.reload(node); @SuppressWarnings("unchecked") Enumeration<FilterNode> e = node.children(); while (e.hasMoreElements()) { FilterNode child = e.nextElement(); if (child.isDirectoryNode()) { reload(tree, child);//ww w.ja v a 2 s . co m } } FilterNode parent = (FilterNode) node; if (parent.wasExpanded()) { tree.expandPath(new TreePath((tree.getModel()).getPathToRoot(node))); } else { tree.collapsePath(new TreePath((tree.getModel()).getPathToRoot(node))); } }
From source file:uk.chromis.pos.admin.RolesViewTree.java
public void loadUserPermissionsIntoTree() throws BasicException { // Populate the tree with the selected users permissions uTree.clearChecking();// w w w.j a v a 2 s.co m if (!"".equals(m_jName.getText())) { getPermissions(); for (String userPermission : m_apermissions) { if (nodePaths.containsKey(userPermission)) { uTree.addCheckingPath(new TreePath(nodePaths.get(userPermission).getPath())); } } jRightsLevel.setValue(m_dlAdmin.getRightsLevel(m_jName.getText())); // jRightsLevel.setText(m_dlAdmin.getRightsLevel(m_jName.getText()).toString()); } }