@Override public void valueChanged(TreeSelectionEvent e) { if (e.getSource() == colors && !locked) { TreeSelectionModel tsm = colors.getSelectionModel(); TreePath tp[] = tsm.getSelectionPaths(); if (tp == null) return; Vector<ClassedItem> tmp = new Vector<ClassedItem>(); for (TreePath element : tp) { try { Object[] path = element.getPath(); ClassedItem ci = new ClassedItem(path[1].toString(), path[2].toString()); tmp.add(ci); } catch (Exception exp) { // User did not select a leafnode } } if (sceneElement instanceof NenyaImageSceneElement) { ((NenyaImageSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaTileSceneElement) { ((NenyaTileSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaComponentSceneElement) { ((NenyaComponentSceneElement) sceneElement) .getComponents()[itemList.getSelectedIndex()].setColorList( tmp.toArray(new ClassedItem[0])); } submitElement(sceneElement, null); } else { super.valueChanged(e); } }
/** * Returns the image information of the specified path, if it represents an image information. * Otherwise returns null. * * @param path the tree path. * @return the image information. */ protected XmlInformation getInformation(TreePath path) { String path_str = ""; Object[] paths = path.getPath(); for (int i = 1; i < paths.length; i++) { String name = (String) ((DefaultMutableTreeNode) paths[i]).getUserObject(); path_str += "/" + name; } XmlInformation info = (XmlInformation) hash_info.get(path_str); return info; }
public static void collapseAll(final JTree tree, final int keepSelectionLevel) { final TreePath leadSelectionPath = tree.getLeadSelectionPath(); // Collapse all int row = tree.getRowCount() - 1; while (row >= 0) { tree.collapseRow(row); row--; } final DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot(); tree.expandPath(new TreePath(root)); if (leadSelectionPath != null) { final Object[] path = leadSelectionPath.getPath(); final Object[] pathToSelect = new Object [path.length > keepSelectionLevel && keepSelectionLevel >= 0 ? keepSelectionLevel : path.length]; System.arraycopy(path, 0, pathToSelect, 0, pathToSelect.length); if (pathToSelect.length == 0) return; selectPath(tree, new TreePath(pathToSelect)); } }