Search in sources :

Example 11 with DefaultListSelectionModel

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;
}
Also used : SkillPointTableModel(pcgen.gui2.tabs.skill.SkillPointTableModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) SkillTreeViewModel(pcgen.gui2.tabs.skill.SkillTreeViewModel)

Example 12 with DefaultListSelectionModel

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;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) UserCancelException(org.vcell.util.UserCancelException) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) UserCancelException(org.vcell.util.UserCancelException) ListSelectionListener(javax.swing.event.ListSelectionListener) Vector(java.util.Vector)

Aggregations

DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)12 ListSelectionModel (javax.swing.ListSelectionModel)4 ArrayList (java.util.ArrayList)2 ListSelectionListener (javax.swing.event.ListSelectionListener)2 TableColumnModel (javax.swing.table.TableColumnModel)2 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)2 DateRenderer (alma.acs.logging.table.renderer.DateRenderer)1 EntryTypeRenderer (alma.acs.logging.table.renderer.EntryTypeRenderer)1 InfoRenderer (alma.acs.logging.table.renderer.InfoRenderer)1 AlarmTableColumn (alma.acsplugins.alarmsystem.gui.table.AlarmTableModel.AlarmTableColumn)1 UndocAlarmTableModel (alma.acsplugins.alarmsystem.gui.undocumented.table.UndocAlarmTableModel)1 ROI (cbit.vcell.VirtualMicroscopy.ROI)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1 ExportSpecs (cbit.vcell.export.server.ExportSpecs)1 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)1 Constant (cbit.vcell.math.Constant)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 FontMetrics (java.awt.FontMetrics)1