@Override public void adoptElement(SceneElement elem) { if (!(elem instanceof NenyaImageSceneElement || elem instanceof NenyaTileSceneElement || elem instanceof NenyaComponentSceneElement)) { enableEditor(false); return; } DefaultComboBoxModel dcm = (DefaultComboBoxModel) itemList.getModel(); // Important: Work on a copy, not on the original. Otherwise we mess up the undomanager sceneElement = elem.copy(); if ((sceneElement instanceof NenyaImageSceneElement) && !locked) { dcm.removeAllElements(); String[] tmp = ((NenyaImageSceneElement) sceneElement).getPath(); dcm.addElement(tmp[tmp.length - 1]); } if ((sceneElement instanceof NenyaTileSceneElement) && !locked) { dcm.removeAllElements(); dcm.addElement(((NenyaTileSceneElement) sceneElement).getTileName()); } if ((sceneElement instanceof NenyaComponentSceneElement) && !locked) { dcm.removeAllElements(); NenyaComponentItem[] ni = ((NenyaComponentSceneElement) sceneElement).getComponents(); for (NenyaComponentItem element : ni) { dcm.addElement(element); } } try { ClassedItem[] cols = null; if (elem instanceof NenyaTileSceneElement) cols = ((NenyaTileSceneElement) elem).getColorList(); if (elem instanceof NenyaImageSceneElement) cols = ((NenyaImageSceneElement) elem).getColorList(); if (elem instanceof NenyaComponentSceneElement) { NenyaComponentItem nci = (NenyaComponentItem) dcm.getSelectedItem(); cols = nci.getColorList(); } Vector<TreePath> collect = new Vector<TreePath>(); TreeNode root = (TreeNode) colors.getModel().getRoot(); for (ClassedItem col : cols) { String[] tmp = {root.toString(), col.getClassName(), col.getItemName()}; collect.add(TreeUtil.findPath(root, tmp)); } TreePath[] path = collect.toArray(new TreePath[0]); colors.getSelectionModel().setSelectionPaths(path); } catch (Exception e) { // Either the tree is filtered away or the selected item is not colorized. } enableEditor(true); itemList.setEnabled(elem instanceof NenyaComponentSceneElement); }
/** * Find the class for the projection * * @param proj projection * @return corresponding ProjectionClass (or null if not found) */ private ProjectionClass findProjectionClass(Projection proj) { Class want = proj.getClass(); ComboBoxModel projClassList = projClassCB.getModel(); for (int i = 0; i < projClassList.getSize(); i++) { ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i); if (want.equals(pc.projClass)) { return pc; } } return null; }