/** * selects object geo in the list of GeoElements * * @param addToSelection false => clear old selection */ public void setSelected(ArrayList<GeoElement> geos, boolean addToSelection) { TreePath tp = null; TreeSelectionModel lsm = getSelectionModel(); if (geos == null || geos.size() == 0) { lsm.clearSelection(); selectFirstElement(); } else { // make sure geos are in list, this is needed when MAX_OBJECTS_IN_TREE was // exceeded in setViewActive(true) // for (int i=0; i < geos.size(); i++) { // GeoElement geo = (GeoElement) geos.get(i); // add(geo); // } if (!addToSelection) lsm.clearSelection(); // get paths for all geos ArrayList<TreePath> paths = new ArrayList<TreePath>(); for (int i = 0; i < geos.size(); i++) { TreePath result = getGeoPath((GeoElement) geos.get(i)); if (result != null) { tp = result; expandPath(result); paths.add(result); } } // select geo paths TreePath[] selPaths = new TreePath[paths.size()]; for (int i = 0; i < selPaths.length; i++) { selPaths[i] = paths.get(i); } lsm.addSelectionPaths(selPaths); if (tp != null && geos.size() == 1) { scrollPathToVisible(tp); } } }
/** * Selects the collection of figures. * * @param l The collection of objects to select. * @param clear Pass <code>true</code> to clear the selection <code>false</code> otherwise. */ void setSelectedFigures(List<ROIShape> l, boolean clear) { Iterator<ROIShape> i = l.iterator(); TreeSelectionModel tsm = objectsTable.getTreeSelectionModel(); ROIFigure figure = null; ROIShape shape; if (clear) tsm.clearSelection(); objectsTable.removeTreeSelectionListener(treeSelectionListener); try { while (i.hasNext()) { shape = i.next(); figure = shape.getFigure(); objectsTable.selectROIShape(figure.getROIShape()); } objectsTable.repaint(); if (figure != null) objectsTable.scrollToROIShape(figure.getROIShape()); } catch (Exception e) { MeasurementAgent.getRegistry().getLogger().info(this, "Figure selection " + e); } objectsTable.addTreeSelectionListener(treeSelectionListener); }