List of usage examples for javax.swing.event TreeSelectionEvent getPath
public TreePath getPath()
From source file:de.codesourcery.eve.skills.ui.components.impl.ItemBrowserComponent.java
@Override protected JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); treeModelBuilder = new MarketGroupTreeModelBuilder(dataModel); treeModelBuilder.attach(itemTree);/*from ww w .j a v a 2 s .c o m*/ itemTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (e.getPath() != null) { treeSelectionChanged((ITreeNode) e.getPath().getLastPathComponent()); } else { treeSelectionChanged(null); } } }); itemTree.setCellRenderer(new DefaultTreeCellRenderer() { public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); final ITreeNode node = (ITreeNode) value; if (node.getValue() instanceof MarketGroup) { setText(((MarketGroup) node.getValue()).getName()); } else if (node.getValue() instanceof InventoryType) { setText(((InventoryType) node.getValue()).getName()); } return this; }; }); // text area itemDetails.setLineWrap(true); itemDetails.setWrapStyleWord(true); itemDetails.setEditable(false); // context menu final PopupMenuBuilder menuBuilder = new PopupMenuBuilder(); menuBuilder.addItem("Refine...", new AbstractAction() { @Override public boolean isEnabled() { return getSelectedType() != null && selectionProvider.getSelectedItem() != null; } private InventoryType getSelectedType() { final TreePath selection = itemTree.getSelectionPath(); if (selection != null && selection.getPathCount() > 0) { final ITreeNode node = (ITreeNode) selection.getLastPathComponent(); if (node.getValue() instanceof InventoryType) { return (InventoryType) node.getValue(); } } return null; } @Override public void actionPerformed(ActionEvent e) { final ICharacter currentCharacter = selectionProvider.getSelectedItem(); final InventoryType t = getSelectedType(); if (t != null && currentCharacter != null) { final RefiningComponent comp = new RefiningComponent(currentCharacter); comp.setModal(true); comp.setItemsToRefine(Collections.singletonList(new ItemWithQuantity(getSelectedType(), 1))); ComponentWrapper.wrapComponent(comp).setVisible(true); } } }); menuBuilder.attach(itemTree); result.add(new JScrollPane(itemTree), constraints(0, 0).resizeBoth().end()); result.add(new JScrollPane(itemDetails), constraints(1, 0).resizeBoth().end()); return result; }
From source file:de.codesourcery.eve.skills.ui.components.impl.BlueprintChooserComponent.java
@Override protected JPanel createPanel() { final JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); // add tree// w w w . j av a 2s. co m tree.setRootVisible(false); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { treeNodeSelected(e.getPath()); } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2) { return; } final int row = tree.getRowForLocation(e.getX(), e.getY()); if (row == -1) { return; } final TreePath selectionPath = tree.getSelectionPath(); final TreePath path = tree.getPathForRow(row); if (path == null) { return; } // tree expansion is also triggered by a double-click, // make sure the double-click wasn't just an expansion trigger if (ObjectUtils.equals(selectionPath, path)) { treeNodeDoubleClicked(path); } } }); tree.setCellRenderer(new BlueprintTreeRendererer()); byNameTextField.setColumns(10); panel.add(new JLabel("Filter:"), constraints().x(0).y(0).width(1).height(1).noResizing().anchorCenter().end()); panel.add(byNameTextField, constraints().x(1).y(0).width(1).height(1).resizeHorizontally().weightX(1).weightY(0).end()); panel.add(new JScrollPane(tree), constraints().x(0).y(1).width(2).height(1).resizeBoth().weightX(1).weightY(1).end()); return panel; }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
public FileObjectGroupSelector(FileObject root) throws FileSystemException { if (root.getType() != FileType.FOLDER) { throw new IllegalArgumentException("root file must be a directory"); }// ww w . j av a2 s . c o m rootFolder = root; explorer = new FileExplorer(rootFolder); explorer.getJTree().setRootVisible(false); explorer.getJTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setLayout(new BorderLayout()); Box topPanel = new Box(BoxLayout.X_AXIS); topPanel.setBorder(BorderFactory.createEmptyBorder(8, 12, 8, 8)); topPanel.add(regexLabel); topPanel.add(regexField); topPanel.add(Box.createHorizontalStrut(4)); topPanel.add(searchType); add(topPanel, BorderLayout.NORTH); //JPanel mainPanel = new JPanel(); //MigLayout layout = new MigLayout(""); // mainPanel.setLayout(layout); //add(regexLabel); //add(regexField, "gap left 0, growx"); //add(findButton, "align right, wrap"); //add(searchType, "wrap"); //add(createSplitPane(), "span 3, grow, wrap"); add(createSplitPane(), BorderLayout.CENTER); depthSpinner.setMaximumSize(new Dimension(50, 200)); depthSpinner.setModel(new SpinnerNumberModel(recursiveDepth, 0, 5, 1)); JPanel bottomPanel = new JPanel(); MigLayout layout = new MigLayout("", "[][grow]", "[][]"); bottomPanel.setLayout(layout); //bottomPanel.setBorder(BorderFactory.createEmptyBorder(4,12,8,8)); bottomPanel.add(new JLabel("Root Folder: ")); rootField.setEditable(false); rootField.setText(root.getName().getBaseName()); bottomPanel.add(rootField, "wrap, width 150:150:150"); bottomPanel.add(new JLabel("Search Depth: "), "gap top 8"); bottomPanel.add(depthSpinner, "width 35:45:55, wrap"); add(bottomPanel, BorderLayout.SOUTH); explorer.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); Object[] obj = path.getPath(); Object lastNode = obj[obj.length - 1]; if (lastNode instanceof FileExplorer.FileObjectNode) { FileExplorer.FileObjectNode fnode = (FileExplorer.FileObjectNode) lastNode; try { if (fnode.getFileObject().getType() == FileType.FOLDER) { rootField.setText(fnode.getFileObject().getName().getBaseName()); rootFolder = fnode.getFileObject(); updateFileList(); } } catch (FileSystemException ex) { throw new RuntimeException(ex); } } } }); depthSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { recursiveDepth = ((Number) depthSpinner.getValue()).intValue(); updateFileList(); } }); regexField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateFileList(); System.out.println(Arrays.toString(explorer.getSelectedNodes().toArray())); } }); }
From source file:com.enderville.enderinstaller.ui.Installer.java
@Override public void valueChanged(TreeSelectionEvent e) { if (!e.isAddedPath()) { return;//from w ww . jav a 2 s .c o m } TreePath path = e.getPath(); CheckBoxTree tree = getModTree(); if (e.getSource() == tree.getSelectionModel()) { DefaultMutableTreeNode last = (DefaultMutableTreeNode) path.getLastPathComponent(); loadModDescription(last.getUserObject().toString()); } else if (e.getSource() == tree.getCheckBoxTreeSelectionModel()) { getPresetDropdown().setSelectedItem(PRESET_CUSTOM); } }
From source file:com.mirth.connect.client.ui.LibraryResourcesPanel.java
@Override public void valueChanged(TreeSelectionEvent evt) { MutableTreeTableNode node = (MutableTreeTableNode) evt.getPath().getLastPathComponent(); ConnectorEntry entry = (ConnectorEntry) node.getUserObject(); if (node.equals(treeTable.getTreeTableModel().getRoot())) { resourceTable.setEnabled(true);//from w w w . ja va 2 s . c o m for (int row = 0; row < resourceTable.getRowCount(); row++) { LibraryProperties properties = (LibraryProperties) resourceTable.getModel().getValueAt(row, PROPERTIES_COLUMN); boolean allChildrenChecked = true; boolean allChildrenUnchecked = true; for (Enumeration<? extends MutableTreeTableNode> en = node.children(); en.hasMoreElements();) { if (selectedResourceIds.get(((ConnectorEntry) en.nextElement().getUserObject()).metaDataId) .containsKey(properties.getId())) { allChildrenUnchecked = false; } else { allChildrenChecked = false; } } Boolean value = null; if (allChildrenChecked) { value = true; } else if (allChildrenUnchecked) { value = false; } resourceTable.getModel().setValueAt(value, row, SELECTED_COLUMN); } } else { resourceTable.setEnabled(node.getParent().equals(treeTable.getTreeTableModel().getRoot())); for (int row = 0; row < resourceTable.getRowCount(); row++) { LibraryProperties properties = (LibraryProperties) resourceTable.getModel().getValueAt(row, PROPERTIES_COLUMN); resourceTable.getModel().setValueAt( selectedResourceIds.get(entry.metaDataId).containsKey(properties.getId()), row, SELECTED_COLUMN); } } }
From source file:com.ssn.listener.SSNHiveAlbumSelectionListner.java
@Override public void valueChanged(TreeSelectionEvent e) { iT = 0;// w w w. ja v a 2s .co m dT = 0; DefaultMutableTreeNode node = treeHelper.getTreeNode(e.getPath()); List hiveFiles = new ArrayList(); if (this.form.getHiveTree() != null) { this.form.getHiveTree().clearSelection(); } this.form.setCursor(new Cursor(Cursor.WAIT_CURSOR)); SSNFileNode fnode = null; try { if (((SSNIconData) node.getUserObject()).getObject() instanceof SSNFileNode) { fnode = (SSNFileNode) ((SSNIconData) node.getUserObject()).getObject(); } } catch (ClassCastException ee) { logger.error(ee); this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } getAlbumMedia(form.getHomeModel().getLoggedInUserAccessToken(), 1, fileTree.hiveAlbumMap.get(fnode.getFile().getName())); /** * ******* * */ if (fnode != null) { if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(fnode.getFile().getAbsolutePath()); } if (fnode.getFile().isDirectory()) { this.fileTree.setSelectedFolder(fnode.getFile().getName()); getSSNMediaFolderProperties(fnode.getFile().getPath()); File[] file = fnode.getFile().listFiles(); for (File f : file) { if (f.isFile()) { hiveFiles.add(f.getName()); } else { } } } if (hiveFiles != null && hiveFiles.size() > 0) { createCompontents(fnode.getFile().getAbsolutePath(), form, true); } else { createCompontents(fnode.getFile().getAbsolutePath(), form, false); } } else { SSNHelper.toggleDeleteAndShareImages(false, form); String path = SSNHelper.getSsnHiveDirPath(); path = SSNHelper.getSsnTempDirPath(); form.getFileNamesToBeDeleted().clear(); getSSNMediaFolderProperties(path); if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(path); } getForm().ssnFileExplorer.m_tree.setSelectionRow(1); long size = FileUtils.sizeOfDirectory(new File(path)); if (size > 0) { File file1 = new File(path); if (fileTree.m_display.getText() != null && !fileTree.m_display.getText().equals("viewAllAlbums") && !fileTree.m_display.getText().equals("instagramMedia") && !fileTree.m_display.getText().equals("tagUnTaggedMedia")) { fileTree.m_display.setText(file1.getAbsolutePath()); } //just copied from above if block if (file1.isDirectory()) { this.form.setCurrentSelectedFile(null); fileTree.setSelectedFolder(file1.getName()); File[] file = file1.listFiles(); for (File f : file) { if (f.isFile()) { hiveFiles.add(f.getName()); } else { } } } if (hiveFiles != null && hiveFiles.size() > 0) { createCompontents(file1.getAbsolutePath(), form, true); } else { createCompontents(file1.getAbsolutePath(), form, false); } } else { // show welcome screen addWelcomeIcons(); } this.form.getSsnHomeCenterMainPanel().revalidate(); this.form.getSsnHomeCenterMainPanel().repaint(); this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } this.form.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.CreateProductionTemplateComponent.java
@Override protected JPanel createPanel() { tree.setRootVisible(true);/* w ww.j a va 2 s . co m*/ tree.setCellRenderer(renderer); tree.setModel(this.treeBuilder.getTreeModel()); final PopupMenuBuilder menuBuilder = new PopupMenuBuilder().addItem("Produce", new CreateSubPlanAction()) .addItem("Buy on market", new DeleteSubPlanAction()) .addItem("Buy on market", new DeleteInventionJobAction()) .addItem("Invent from T1 blueprint", new CreateInventionJobAction()); menuBuilder.attach(tree); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { final TreePath selectedPath = e.getPath(); if (selectedPath == null || selectedPath.getPathCount() == 0) { selectedNodeChanged(null); } else { selectedNodeChanged((ITreeNode) selectedPath.getLastPathComponent()); } } }); final JScrollPane treePane = new JScrollPane(tree); // add editor panel editorPanel.setLayout(new GridBagLayout()); editorPanel.setBorder(BorderFactory.createLineBorder(Color.black)); // cost statement panel final JPanel costPanel = costStatement.getPanel(); final JPanel combinedPanel = new JPanel(); combinedPanel.setLayout(new GridBagLayout()); combinedPanel.add(costPanel, constraints(0, 0).resizeBoth().useRemainingWidth().end()); combinedPanel.add(editorPanel, constraints(0, 1).resizeBoth().useRemainingSpace().end()); final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, combinedPanel); result.add(splitPane, constraints().resizeBoth().end()); costStatement.refresh(); return result; }
From source file:com.mirth.connect.client.ui.LibraryResourcesDialog.java
@Override public void valueChanged(TreeSelectionEvent evt) { MutableTreeTableNode node = (MutableTreeTableNode) evt.getPath().getLastPathComponent(); ConnectorEntry entry = (ConnectorEntry) node.getUserObject(); if (node.equals(treeTable.getTreeTableModel().getRoot())) { resourceTable.setEnabled(true);//w ww .j a v a 2 s. co m for (int row = 0; row < resourceTable.getRowCount(); row++) { LibraryProperties properties = (LibraryProperties) resourceTable.getModel().getValueAt(row, PROPERTIES_COLUMN); boolean allChildrenChecked = true; boolean allChildrenUnchecked = true; for (Enumeration<? extends MutableTreeTableNode> en = node.children(); en.hasMoreElements();) { if (selectedResourceIds.get(((ConnectorEntry) en.nextElement().getUserObject()).metaDataId) .contains(properties.getId())) { allChildrenUnchecked = false; } else { allChildrenChecked = false; } } Boolean value = null; if (allChildrenChecked) { value = true; } else if (allChildrenUnchecked) { value = false; } resourceTable.getModel().setValueAt(value, row, SELECTED_COLUMN); } } else { resourceTable.setEnabled(node.getParent().equals(treeTable.getTreeTableModel().getRoot())); for (int row = 0; row < resourceTable.getRowCount(); row++) { LibraryProperties properties = (LibraryProperties) resourceTable.getModel().getValueAt(row, PROPERTIES_COLUMN); resourceTable.getModel().setValueAt( selectedResourceIds.get(entry.metaDataId).contains(properties.getId()), row, SELECTED_COLUMN); } } }
From source file:edu.ucla.stat.SOCR.chart.ChartTree.java
/** * Receives notification of tree selection events and updates the demo * display accordingly./*w w w. j av a 2 s . c o m*/ * * @param event the event. */ public void valueChanged(TreeSelectionEvent event) { TreePath path = event.getPath(); Object obj = path.getLastPathComponent(); if (obj != null) { DefaultMutableTreeNode n = (DefaultMutableTreeNode) obj; Object userObj = n.getUserObject(); if (userObj instanceof DemoDescription) { // DemoDescription dd = (DemoDescription) userObj; //SwingUtilities.invokeLater(new DisplayDemo(this, dd)); } else { /* this.chartContainer.removeAll(); this.chartContainer.add(createNoDemoSelectedPanel()); this.displayPanel.validate(); displayDescription("select.html");*/ } } System.out.println(obj); }
From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java
private void trInstancesValueChanged(javax.swing.event.TreeSelectionEvent evt) {// GEN-FIRST:event_trInstancesValueChanged Object nodeObj = evt.getPath().getLastPathComponent(); if (null != nodeObj) { if (nodeObj instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) nodeObj; Object userObject = treeNode.getUserObject(); if (userObject instanceof InstanceObjectWrapper) { InstanceObjectWrapper wrapper = (InstanceObjectWrapper) userObject; instanceTableModel.setObject(wrapper.instance); tblInstances.setModel(instanceTableModel); } else { tblInstances.setModel(instancesTableModel); }/* w w w .jav a 2 s .c om*/ } } }