use of javax.swing.event.ListSelectionEvent in project vcell by virtualcell.
the class PDEDataViewer method roiAction.
private void roiAction() {
BeanUtils.setCursorThroughout(this, Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
final String[] ROI_COLUMN_NAMES = new String[] { "ROI source", "ROI source name", "ROI Description" };
final Vector<Object> auxInfoV = new Vector<Object>();
final DataIdentifier dataIdentifier = getPdeDataContext().getDataIdentifier();
VariableType variableType = dataIdentifier.getVariableType();
final boolean isVolume = variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION);
DefaultTableModel tableModel = new DefaultTableModel() {
public boolean isCellEditable(int row, int column) {
return false;
}
};
for (int i = 0; i < ROI_COLUMN_NAMES.length; i++) {
tableModel.addColumn(ROI_COLUMN_NAMES[i]);
}
// Add Snapshot ROI
if ((isVolume ? volumeSnapshotROI : membraneSnapshotROI) != null) {
tableModel.addRow(new Object[] { (isVolume ? "Volume" : "Membrane") + " Variables and Functions", "Snapshot", (isVolume ? volumeSnapshotROIDescription : membraneSnapshotROIDescription) + ", (values = 1.0)" });
auxInfoV.add((isVolume ? volumeSnapshotROI : membraneSnapshotROI));
}
// Add user ROIs
SpatialSelection[] userROIArr = getPDEDataContextPanel1().fetchSpatialSelections(true, false);
for (int i = 0; userROIArr != null && i < userROIArr.length; i += 1) {
String descr = null;
boolean bPoint = false;
if (isVolume) {
if (userROIArr[i] instanceof SpatialSelectionVolume) {
Curve curve = ((SpatialSelectionVolume) userROIArr[i]).getCurveSelectionInfo().getCurve();
descr = curve.getDescription();
if (curve instanceof SinglePoint) {
bPoint = true;
}
}
} else {
if (userROIArr[i] instanceof SpatialSelectionMembrane) {
SampledCurve selectionSource = ((SpatialSelectionMembrane) userROIArr[i]).getSelectionSource();
descr = selectionSource.getDescription();
if (selectionSource instanceof SinglePoint) {
bPoint = true;
}
}
}
// Add Area User ROI
BitSet fillBitSet = null;
if (userROIArr[i] instanceof SpatialSelectionVolume) {
fillBitSet = getFillROI((SpatialSelectionVolume) userROIArr[i]);
if (fillBitSet != null) {
tableModel.addRow(new Object[] { "User Defined", descr, "Area Enclosed Volume ROI" });
auxInfoV.add(fillBitSet);
}
}
// Add Point and Line User ROI
if (fillBitSet == null) {
tableModel.addRow(new Object[] { "User Defined", descr, (bPoint ? "Point" : "Line") + (isVolume ? " Volume" : " Membrane") + " ROI " });
auxInfoV.add(userROIArr[i]);
}
}
// Add sorted Geometry ROI
final CartesianMesh cartesianMesh = getPdeDataContext().getCartesianMesh();
HashMap<Integer, ?> regionMapSubvolumesHashMap = (isVolume ? cartesianMesh.getVolumeRegionMapSubvolume() : cartesianMesh.getMembraneRegionMapSubvolumesInOut());
Set<?> regionMapSubvolumesEntrySet = regionMapSubvolumesHashMap.entrySet();
Iterator<?> regionMapSubvolumesEntryIter = regionMapSubvolumesEntrySet.iterator();
TreeSet<Object[]> sortedGeomROITreeSet = new TreeSet<Object[]>(new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
int result = ((String) ((Object[]) o1[0])[1]).compareToIgnoreCase((String) ((Object[]) o2[0])[1]);
if (result == 0) {
result = (((Entry<Integer, ?>) o1[1]).getKey()).compareTo(((Entry<Integer, ?>) o2[1]).getKey());
}
return result;
}
});
while (regionMapSubvolumesEntryIter.hasNext()) {
Entry<Integer, ?> regionMapSubvolumesEntry = (Entry<Integer, ?>) regionMapSubvolumesEntryIter.next();
sortedGeomROITreeSet.add(new Object[] { new Object[] { "Geometry", (isVolume ? getSimulationModelInfo().getVolumeNamePhysiology(((Integer) regionMapSubvolumesEntry.getValue())) : getSimulationModelInfo().getMembraneName(((int[]) regionMapSubvolumesEntry.getValue())[0], ((int[]) regionMapSubvolumesEntry.getValue())[1], false)), (isVolume ? "(svID=" + regionMapSubvolumesEntry.getValue() + " " : "(") + "vrID=" + regionMapSubvolumesEntry.getKey() + ") Predefined " + (isVolume ? "volume" : "membrane") + " region" }, regionMapSubvolumesEntry });
}
Iterator<Object[]> sortedGeomROIIter = sortedGeomROITreeSet.iterator();
while (sortedGeomROIIter.hasNext()) {
Object[] sortedGeomROIObjArr = (Object[]) sortedGeomROIIter.next();
tableModel.addRow((Object[]) sortedGeomROIObjArr[0]);
auxInfoV.add(sortedGeomROIObjArr[1]);
}
final ScrollTable roiTable = new ScrollTable();
roiTable.setModel(tableModel);
roiTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
roiTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
final JPanel mainJPanel = new JPanel();
BoxLayout mainBL = new BoxLayout(mainJPanel, BoxLayout.Y_AXIS);
mainJPanel.setLayout(mainBL);
MiniTimePanel timeJPanel = new MiniTimePanel();
ActionListener okAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (((Double) timeJPanel.jcb_time_begin.getSelectedItem()).compareTo((Double) timeJPanel.jcb_time_end.getSelectedItem()) > 0) {
PopupGenerator.showErrorDialog(PDEDataViewer.this, "Selected 'Begin Time' must be less than or equal to 'End Time'");
return;
}
int[] selectedRows = roiTable.getSelectedRows();
if (selectedRows != null) {
try {
BitSet dataBitSet = new BitSet(getPdeDataContext().getDataValues().length);
for (int i = 0; i < selectedRows.length; i++) {
Object auxInfo = auxInfoV.elementAt(selectedRows[i]);
if (auxInfo instanceof BitSet) {
dataBitSet.or((BitSet) auxInfo);
} else if (auxInfo instanceof SpatialSelectionMembrane) {
int[] roiIndexes = ((SpatialSelectionMembrane) auxInfo).getIndexSamples().getSampledIndexes();
for (int j = 0; j < roiIndexes.length; j += 1) {
dataBitSet.set(roiIndexes[j], true);
}
} else if (auxInfo instanceof SpatialSelectionVolume) {
int[] roiIndexes = ((SpatialSelectionVolume) auxInfo).getIndexSamples(0, 1).getSampledIndexes();
for (int j = 0; j < roiIndexes.length; j += 1) {
dataBitSet.set(roiIndexes[j], true);
}
} else if (auxInfo instanceof Entry) {
Entry<Integer, Integer> entry = (Entry<Integer, Integer>) auxInfo;
if (isVolume) {
int volumeRegionID = entry.getKey();
dataBitSet.or(cartesianMesh.getVolumeROIFromVolumeRegionID(volumeRegionID));
} else {
int membraneRegionID = entry.getKey();
dataBitSet.or(cartesianMesh.getMembraneROIFromMembraneRegionID(membraneRegionID));
}
} else if (auxInfo instanceof BitSet) {
dataBitSet.or((BitSet) auxInfo);
} else {
throw new Exception("ROI table, Unknown data type: " + auxInfo.getClass().getName());
}
}
TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifier.getName() }, new BitSet[] { dataBitSet }, ((Double) timeJPanel.jcb_time_begin.getSelectedItem()).doubleValue(), 1, ((Double) timeJPanel.jcb_time_end.getSelectedItem()).doubleValue(), true, false, VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieve data for '" + dataIdentifier + "'", PDEDataViewer.this, getPdeDataContext());
AsynchClientTask task2 = new AsynchClientTask("Showing stat for '" + dataIdentifier + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) hashTable.get(StringKey_timeSeriesJobResults);
plotSpaceStats(tsJobResultsSpaceStats);
}
};
ClientTaskDispatcher.dispatch(PDEDataViewer.this, hash, new AsynchClientTask[] { task1, task2 }, true, true, null);
} catch (Exception e1) {
e1.printStackTrace();
PopupGenerator.showErrorDialog(PDEDataViewer.this, "ROI Error.\n" + e1.getMessage(), e1);
}
}
BeanUtils.disposeParentWindow(mainJPanel);
}
};
ActionListener cancelAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
BeanUtils.disposeParentWindow(mainJPanel);
}
};
OkCancelSubPanel okCancelJPanel = new OkCancelSubPanel(okAction, cancelAction);
roiTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (roiTable.getSelectedRows() != null && roiTable.getSelectedRows().length > 0) {
okCancelJPanel.okButton.setEnabled(true);
} else {
okCancelJPanel.okButton.setEnabled(false);
}
}
});
mainJPanel.add(timeJPanel);
mainJPanel.add(roiTable.getEnclosingScrollPane());
mainJPanel.add(okCancelJPanel);
// showComponentInFrame(mainJPanel,
// "Calculate "+(isVolume?"volume":"membrane")+" statistics for '"+getPdeDataContext().getVariableName()+"'."+
// " Choose times and 1 or more ROI(s).");
Frame dialogOwner = JOptionPane.getFrameForComponent(this);
JOptionPane inputDialog = new JOptionPane(mainJPanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[0]);
final JDialog d = inputDialog.createDialog(dialogOwner, "Calculate " + (isVolume ? "volume" : "membrane") + " statistics for '" + getPdeDataContext().getVariableName() + "'." + " Choose times and 1 or more ROI(s).");
d.setResizable(true);
try {
DialogUtils.showModalJDialogOnTop(d, PDEDataViewer.this);
} finally {
d.dispose();
}
} finally {
BeanUtils.setCursorThroughout(this, Cursor.getDefaultCursor());
}
}
use of javax.swing.event.ListSelectionEvent in project vcell by virtualcell.
the class DialogUtils method showComponentOptionsTableList.
public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
// //Create hidden column with original row index so original row index can
// //be returned for user selections even if rows are sorted
// final int hiddenColumnIndex = rowDataOrig[0].length;
// final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
// for (int i = 0; i < rowDataHiddenIndex.length; i++) {
// for (int j = 0; j < rowDataOrig[i].length; j++) {
// rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
// }
// rowDataHiddenIndex[i][hiddenColumnIndex] = i;
// }
Producer<TableListResult> prod = () -> {
// Create hidden column with original row index so original row index can
// be returned for user selections even if rows are sorted
int hiddenColumnIndex = rowDataOrig[0].length;
Object[][] rowDataHiddenIndex = rowDataOrig;
if (rowSortComparator != null) {
rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
for (int i = 0; i < rowDataHiddenIndex.length; i++) {
for (int j = 0; j < rowDataOrig[i].length; j++) {
rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
}
rowDataHiddenIndex[i][hiddenColumnIndex] = i;
}
}
@SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {
@Override
public boolean isSortable(int col) {
if (rowSortComparator != null) {
return true;
}
return false;
}
public Object getValueAt(int row, int column) {
return getValueAt(row)[column];
}
@Override
public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
return new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if (ascending) {
return rowSortComparator.compare(o1[col], o2[col]);
}
return rowSortComparator.compare(o2[col], o1[col]);
}
};
}
};
final JSortTable table = new JSortTable();
// table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setModel(tableModel);
tableModel.setData(Arrays.asList(rowDataHiddenIndex));
if (listSelectionModel_SelectMode != null) {
table.setSelectionMode(listSelectionModel_SelectMode);
} else {
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
}
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.disableUneditableForeground();
OKEnabler tableListOKEnabler = null;
if (listSelectionModel_SelectMode != null) {
tableListOKEnabler = new OKEnabler() {
private JOptionPane jop;
public void setJOptionPane(JOptionPane joptionPane) {
jop = joptionPane;
setInternalNotCancelEnabled(joptionPane, false, false);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
if (table.getSelectedRowCount() != 0) {
setInternalNotCancelEnabled(jop, true, false);
} else {
setInternalNotCancelEnabled(jop, false, false);
}
}
}
});
}
};
}
if (listSelectionListener != null) {
table.getSelectionModel().addListSelectionListener(listSelectionListener);
}
TableListResult tableListResult = new TableListResult();
// HACK to fix horizontal scrollbar not showing for large horizontal tables
// workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
Component[] components = table.getEnclosingScrollPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof JScrollPane) {
jScrollPaneArr[0] = (JScrollPane) components[i];
break;
}
}
if (jScrollPaneArr[0] != null) {
jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
});
}
if (options == null) {
if (bModal) {
if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} else {
// display non-modal
JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
JDialog jDialog = jOptionPane.createDialog(requester, title);
jDialog.setResizable(true);
jDialog.setModal(false);
jDialog.pack();
jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog.setVisible(true);
}
tableListResult.selectedTableRows = table.getSelectedRows();
} else {
tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
tableListResult.selectedTableRows = table.getSelectedRows();
}
if (rowSortComparator != null) {
// return the index of the original unsorted object array that corresponds to the user row selections
for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
}
}
return tableListResult;
};
return VCSwingFunction.executeAsRuntimeException(prod);
}
use of javax.swing.event.ListSelectionEvent in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method showComponentOKCancelTableList.
public int[] showComponentOKCancelTableList(final Component requester, String title, String[] columnNames, Object[][] rowData, int listSelectionModel_SelectMode, final RegionInfo[] regionInfoArr, final short[] multiObjectROIPixels) throws UserCancelException {
DefaultTableModel tableModel = new DefaultTableModel() {
public boolean isCellEditable(int row, int column) {
return false;
}
};
tableModel.setDataVector(rowData, columnNames);
final JTable table = new JTable(tableModel);
table.setSelectionMode(listSelectionModel_SelectMode);
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
try {
int index = table.getSelectedRow();
// System.out.println("list index="+index);
RegionInfo keepRegion = regionInfoArr[index];
short[] removePixels = multiObjectROIPixels.clone();
for (int i = 0; i < removePixels.length; i++) {
if (!keepRegion.isIndexInRegion(i)) {
removePixels[i] = 0;
}
}
UShortImage ushortImage = new UShortImage(removePixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
final ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
frapData.addReplaceRoi(newCellROI);
} catch (Exception e2) {
e2.printStackTrace();
throw new RuntimeException("Error selecting resolved ROI", e2);
}
}
}
});
ScopedExpressionTableCellRenderer.formatTableCellSizes(table);
int result = DialogUtils.showComponentOKCancelDialog(requester, scrollPane, title);
if (result != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
return table.getSelectedRows();
}
use of javax.swing.event.ListSelectionEvent in project intellij-plugins by JetBrains.
the class CPUSnapshotView method createHotSpotsTreeTable.
private void createHotSpotsTreeTable() {
myHotSpotsTreeTable = new CallTreeTable(getProject());
myHotSpotsTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
final Object node = myHotSpotsTreeTable.getSelectedValue();
if (!(node instanceof MergedCallNode))
return;
myAlarm.cancelAllRequests();
final MergedCallNode mergedCallNode = (MergedCallNode) node;
myAlarm.addRequest(() -> {
FrameInfo[] frames = new FrameInfo[] { mergedCallNode.getFrameInfo() };
final Pair<Map<FrameInfo, Long>, Map<FrameInfo, Long>> countMaps = mergedCallNode.getCallTree().getCalleesTimeMaps(frames);
final Map<FrameInfo, Long> countMap = countMaps.getFirst();
final Map<FrameInfo, Long> selfCountMap = countMaps.getSecond();
DefaultMutableTreeNode tracesRoot = (DefaultMutableTreeNode) myTracesTreeTable.getSortableTreeTableModel().getRoot();
JTreeUtil.removeChildren(tracesRoot, myTracesTreeTable.getSortableTreeTableModel());
fillTreeModelRoot(tracesRoot, mergedCallNode.getCallTree(), countMap, selfCountMap, false, frames);
myTracesTreeTable.reload();
TreeUtil.expand(myTracesTreeTable.getTree(), 1);
}, 500);
}
});
}
use of javax.swing.event.ListSelectionEvent in project gitblit by gitblit.
the class SubscriptionsDialog method initialize.
private void initialize() {
NameRenderer nameRenderer = new NameRenderer();
model = new FeedsTableModel(feeds);
feedsTable = Utils.newTable(model, Utils.DATE_FORMAT);
feedsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
int viewRow = feedsTable.getSelectedRow();
if (viewRow == -1) {
return;
}
int modelRow = feedsTable.convertRowIndexToModel(viewRow);
FeedModel feed = model.get(modelRow);
feed.subscribed = !feed.subscribed;
model.fireTableDataChanged();
}
});
String repository = feedsTable.getColumnName(FeedsTableModel.Columns.Repository.ordinal());
feedsTable.getColumn(repository).setCellRenderer(nameRenderer);
String branch = feedsTable.getColumnName(FeedsTableModel.Columns.Branch.ordinal());
feedsTable.getColumn(branch).setCellRenderer(new BranchRenderer());
String subscribed = feedsTable.getColumnName(FeedsTableModel.Columns.Subscribed.ordinal());
feedsTable.getColumn(subscribed).setCellRenderer(new BooleanCellRenderer());
feedsTable.getColumn(subscribed).setMinWidth(30);
feedsTable.getColumn(subscribed).setMaxWidth(30);
Utils.packColumns(feedsTable, 5);
final JButton cancel = new JButton(Translation.get("gb.cancel"));
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setVisible(false);
}
});
final JButton save = new JButton(Translation.get("gb.save"));
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
save();
}
});
feedsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
}
});
JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
controls.add(cancel);
controls.add(save);
final Insets insets = new Insets(5, 5, 5, 5);
JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return insets;
}
};
centerPanel.add(new HeaderPanel(Translation.get("gb.subscribe") + "...", "feed_16x16.png"), BorderLayout.NORTH);
centerPanel.add(new JScrollPane(feedsTable), BorderLayout.CENTER);
centerPanel.add(controls, BorderLayout.SOUTH);
getContentPane().setLayout(new BorderLayout(5, 5));
getContentPane().add(centerPanel, BorderLayout.CENTER);
}
Aggregations