use of javax.swing.DefaultListSelectionModel in project pcgen by PCGen.
the class SkillInfoTab method createModels.
@Override
public ModelMap createModels(final CharacterFacade character) {
ModelMap models = new ModelMap();
ListSelectionModel listModel = new DefaultListSelectionModel();
listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
models.put(ListSelectionModel.class, listModel);
models.put(SkillPointTableModel.class, new SkillPointTableModel(character));
models.put(SkillTreeViewModel.class, new SkillTreeViewModel(character, listModel));
models.put(FilterHandler.class, new FilterHandler(character, listModel));
models.put(InfoHandler.class, new InfoHandler(character));
models.put(LevelSelectionHandler.class, new LevelSelectionHandler(character, listModel));
models.put(SkillRankSpinnerEditor.class, new SkillRankSpinnerEditor(character, listModel));
SkillSheetHandler skillSheetHandler = new SkillSheetHandler(character);
models.put(SkillSheetHandler.class, skillSheetHandler);
models.put(SkillFilterHandler.class, new SkillFilterHandler(character, skillSheetHandler));
return models;
}
use of javax.swing.DefaultListSelectionModel in project vcell by virtualcell.
the class ROIAssistPanel method pickKeepRegionInfoFromCurrentROI.
private RegionInfo[] pickKeepRegionInfoFromCurrentROI() throws Exception {
RegionInfo[] thresholdRegionInfos = calculateRegionInfos(dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ());
Vector<RegionInfo> roiRegionInfoV = new Vector<RegionInfo>();
for (int i = 0; i < thresholdRegionInfos.length; i++) {
if (thresholdRegionInfos[i].getPixelValue() == 1) {
roiRegionInfoV.add(thresholdRegionInfos[i]);
}
}
if (roiRegionInfoV.size() == 0) {
DialogUtils.showInfoDialog(this, "There are no Regions Of Interest to resolve.");
return null;
}
// Present list to pick from
final RegionInfo[] regionInfoArr = roiRegionInfoV.toArray(new RegionInfo[0]);
Arrays.sort(regionInfoArr, new Comparator<RegionInfo>() {
public int compare(RegionInfo o1, RegionInfo o2) {
return o2.getNumPixels() - o1.getNumPixels();
}
});
final Object[][] rowData = new Object[regionInfoArr.length][1];
for (int i = 0; i < regionInfoArr.length; i++) {
rowData[i][0] = regionInfoArr[i].getNumPixels() + " pixels";
}
final ROI beforeROI = new ROI(dataToThreshold.getCurrentlyDisplayedROI());
int[] resultArr = null;
ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
try {
DefaultListSelectionModel defaultListSelectionModel = (DefaultListSelectionModel) e.getSource();
Vector<Integer> pickedIndexes = new Vector<Integer>();
if (!defaultListSelectionModel.isSelectionEmpty()) {
for (int i = defaultListSelectionModel.getMinSelectionIndex(); i <= defaultListSelectionModel.getMaxSelectionIndex(); i++) {
if (defaultListSelectionModel.isSelectedIndex(i)) {
pickedIndexes.add(i);
}
}
}
// beforeROI.getPixelsXYZ();
short[] pickedPixels = new short[beforeROI.getISize().getXYZ()];
for (int i = 0; i < pickedPixels.length; i++) {
for (int j = 0; j < pickedIndexes.size(); j++) {
if (regionInfoArr[pickedIndexes.elementAt(j)].isIndexInRegion(i)) {
pickedPixels[i] = 1;
}
}
}
ROI newCellROI = null;
if (pickedIndexes.size() == 0) {
newCellROI = beforeROI;
} else {
UShortImage ushortImage = new UShortImage(pickedPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
newCellROI = new ROI(ushortImage, originalROI.getROIName());
}
dataToThreshold.addReplaceRoi(newCellROI);
} catch (Exception e2) {
e2.printStackTrace();
throw new RuntimeException("Error selecting resolved ROI", e2);
}
}
}
};
try {
resultArr = DialogUtils.showComponentOptionsTableList(this, "Select 1 or more pixel regions to keep in ROI", new String[] { "ROI Size (pixel count)" }, rowData, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, listSelectionListener, null, null, null).selectedTableRows;
} catch (UserCancelException e) {
resultArr = null;
}
if (resultArr != null && resultArr.length > 0) {
RegionInfo[] pickedRegions = new RegionInfo[resultArr.length];
for (int i = 0; i < resultArr.length; i++) {
pickedRegions[i] = regionInfoArr[resultArr[i]];
}
// (resultArr == null?null:regionInfoArr[resultArr]);
return pickedRegions;
} else {
dataToThreshold.addReplaceRoi(beforeROI);
}
return null;
}
Aggregations