use of javax.swing.JDialog 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.JDialog in project vcell by virtualcell.
the class DialogUtils method showErrorDialog.
/**
* show error dialog in standard way. If modelInfo is not null user is prompted to allow sending of context information
* @param requester parent Component, may be null
* @param message message to display
* @param exception exception to dialog and possibility email to VCellSupport; may be null
* @param modelInfo information to include in email to VCellSupport; may be null
*/
public static void showErrorDialog(final Component requester, final String message, final Throwable exception, final ErrorContext errorContext) {
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Doer doer = () -> {
String errMsg = message;
boolean sendErrorReport = false;
if (errMsg == null || errMsg.trim().length() == 0) {
errMsg = "Virtual Cell has encountered a problem. Please tell Virtual Cell about this problem to help improve Virtual Cell.";
if (exception != null) {
sendErrorReport = true;
}
}
if (exception instanceof ClassCastException || exception instanceof ArrayIndexOutOfBoundsException || exception instanceof NullPointerException || exception instanceof Error) {
sendErrorReport = true;
}
final boolean goingToEmail = sendErrorReport && VCellClientTest.getVCellClient() != null;
DialogMessagePanel dialogMessagePanel;
if (goingToEmail) {
dialogMessagePanel = MessagePanelFactory.createExtended(errMsg, errorContext);
} else {
dialogMessagePanel = MessagePanelFactory.createNonSending(errMsg);
}
Collection<String> suggestions = ExceptionInterpreter.instance().suggestions(message);
if (suggestions != null) {
SuggestionPanel sp = new SuggestionPanel();
sp.setSuggestedSolution(suggestions);
dialogMessagePanel.add(sp, BorderLayout.NORTH);
}
JOptionPane pane = new JOptionPane(dialogMessagePanel, JOptionPane.ERROR_MESSAGE, dialogMessagePanel.optionType());
JDialog dialog = new LWTitledOptionPaneDialog(lwParent, "Error", pane);
dialog.setResizable(true);
try {
dialog.setVisible(true);
if (goingToEmail) {
Object ro = pane.getValue();
Integer reply = BeanUtils.downcast(Integer.class, ro);
boolean userSaidYes = reply != null ? reply == JOptionPane.YES_OPTION : false;
if (userSaidYes) {
Throwable throwableToSend = exception;
String extra = dialogMessagePanel.getSupplemental();
extra = BeanUtils.PLAINTEXT_EMAIL_NEWLINE + (extra == null ? "" : extra) + collectRecordedUserEvents();
throwableToSend = new RuntimeException(extra, exception);
VCellClientTest.getVCellClient().getClientServerManager().sendErrorReport(throwableToSend);
}
}
} finally {
dialog.dispose();
}
};
VCSwingFunction.executeConsumeException(doer);
}
use of javax.swing.JDialog in project vcell by virtualcell.
the class DialogUtils method showComponentOKCancelDialog.
public static int showComponentOKCancelDialog(final Component requester, final Component stayOnTopComponent, final String title, final OKEnabler okEnabler, boolean isResizeable) {
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Producer<Integer> prod = () -> {
JOptionPane inputDialog = new JOptionPane(stayOnTopComponent, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[] { getOKText(), getCancelText() });
JDialog d = new LWTitledOptionPaneDialog(lwParent, title, inputDialog);
d.setResizable(isResizeable);
if (okEnabler != null) {
okEnabler.setJOptionPane(inputDialog);
}
try {
d.setVisible(true);
if (inputDialog.getValue() instanceof String) {
if (inputDialog.getValue().equals(getOKText())) {
return JOptionPane.OK_OPTION;
}
if (inputDialog.getValue().equals(getCancelText())) {
return JOptionPane.CANCEL_OPTION;
}
} else if (inputDialog.getValue() == null) {
return JOptionPane.CLOSED_OPTION;
} else if (inputDialog.getValue().equals(JOptionPane.UNINITIALIZED_VALUE)) {
return JOptionPane.CLOSED_OPTION;
}
throw new RuntimeException("Unexpected return value=" + inputDialog.getValue().toString());
} finally {
d.dispose();
}
};
return VCSwingFunction.executeAsRuntimeException(prod);
}
use of javax.swing.JDialog in project vcell by virtualcell.
the class DialogUtils method showComponentCloseDialog.
/**
* Insert the method's description here.
* Creation date: (5/21/2004 3:17:45 AM)
* @param owner java.awt.Component
* @param message java.lang.Object
*/
public static void showComponentCloseDialog(final Component requester, final Component stayOnTopComponent, final String title) {
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Doer doer = () -> {
JOptionPane inputDialog = new JOptionPane(stayOnTopComponent, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[] { "Close" });
final JDialog d = new LWTitledOptionPaneDialog(lwParent, title, inputDialog);
d.setResizable(true);
try {
d.setVisible(true);
} finally {
d.dispose();
}
};
VCSwingFunction.executeAsRuntimeException(doer);
}
use of javax.swing.JDialog 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);
}
Aggregations