use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.
the class DialogUtils method showInputDialog0.
/**
* Insert the method's description here.
* Creation date: (5/21/2004 3:23:18 AM)
* @return int
* @param owner java.awt.Component
* @param message java.lang.String
* @param preferences cbit.vcell.client.UserPreferences
* @param preferenceName java.lang.String
*/
public static String showInputDialog0(final Component requester, final String message, final String initialValue) throws UtilCancelException {
// TODO: rename showInputDialog after trunk merge
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Producer<String> prod = () -> {
JPanel panel = new JPanel(new BorderLayout());
JOptionPane inputDialog = new JOptionPane(null, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
if (message.indexOf('\n') == -1) {
panel.add(new JLabel(message), BorderLayout.NORTH);
} else {
JPanel msgPanel = MessagePanelFactory.createSimple(message);
panel.add(msgPanel, BorderLayout.NORTH);
}
inputDialog.setMessage(panel);
inputDialog.setWantsInput(true);
if (initialValue != null) {
inputDialog.setInitialSelectionValue(initialValue);
}
final JDialog d = new LWTitledOptionPaneDialog(lwParent, "INPUT:", inputDialog);
d.setResizable(false);
String id = Long.toString(System.currentTimeMillis());
Hashtable<String, Object> choices = new Hashtable<String, Object>();
try {
d.setVisible(true);
if (inputDialog.getValue() instanceof Integer && ((Integer) inputDialog.getValue()).intValue() == JOptionPane.CANCEL_OPTION) {
throw UtilCancelException.CANCEL_GENERIC;
}
choices.put(id, inputDialog.getInputValue());
} catch (Exception exc) {
if (exc instanceof UtilCancelException) {
throw (UtilCancelException) exc;
}
exc.printStackTrace(System.out);
choices.put(id, JOptionPane.UNINITIALIZED_VALUE);
} finally {
d.dispose();
}
String input = (String) choices.get(id);
return input == JOptionPane.UNINITIALIZED_VALUE ? null : input;
};
try {
return VCSwingFunction.execute(prod);
} catch (Exception e) {
if (e instanceof UtilCancelException) {
throw (UtilCancelException) e;
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.
the class DialogUtils method showAnnotationDialog.
public static String showAnnotationDialog(final Component requester, final String oldAnnotation) throws Exception {
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Producer<String> prod = () -> {
JPanel panel = new JPanel(new BorderLayout());
JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JTextArea textArea = new JTextArea(oldAnnotation, 8, 60);
textArea.setEditable(true);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
scroller.setViewportView(textArea);
scroller.getViewport().setPreferredSize(new Dimension(400, 200));
panel.add(scroller, BorderLayout.CENTER);
JOptionPane pane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
final LWDialog dialog = new LWTitledOptionPaneDialog(lwParent, "Edit Annotation:", pane);
dialog.setResizable(true);
try {
dialog.setVisible(true);
Object selectedValue = pane.getValue();
if (selectedValue == null || (((Integer) selectedValue).intValue() == JOptionPane.CLOSED_OPTION) || (((Integer) selectedValue).intValue() == JOptionPane.CANCEL_OPTION)) {
throw UtilCancelException.CANCEL_GENERIC;
} else {
return textArea.getText();
}
} finally {
dialog.dispose();
}
};
return VCSwingFunction.execute(prod);
}
use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.
the class DialogUtils method showReportDialog.
/**
* Insert the method's description here.
* Creation date: (5/21/2004 3:23:18 AM)
* @return int
* @param owner java.awt.Component
* @param message java.lang.String
* @param preferences cbit.vcell.client.UserPreferences
* @param preferenceName java.lang.String
*/
protected static void showReportDialog(final Component requester, final String reportText) {
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
Doer doer = () -> {
JPanel panel = new JPanel(new BorderLayout());
JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JTextArea textArea = new JTextArea(reportText);
scroller.setViewportView(textArea);
scroller.getViewport().setPreferredSize(new Dimension(600, 400));
panel.add(scroller, BorderLayout.CENTER);
JOptionPane pane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION);
final JDialog dialog = new LWTitledOptionPaneDialog(lwParent, "Complete Report", pane);
showOnce(dialog);
};
VCSwingFunction.executeAsRuntimeException(doer);
}
use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.
the class DialogUtils method showDialog.
/**
* Insert the method's description here.
* Creation date: (5/21/2004 3:23:18 AM)
* @return int
* @param owner java.awt.Component
* @param message java.lang.String
* @param preferences cbit.vcell.client.UserPreferences
* @param preferenceName java.lang.String
*/
private static String showDialog(final Component requester, String title, final SimpleUserMessage userMessage, final String replacementText, final int JOptionPaneMessageType) {
VCellThreadChecker.checkSwingInvocation();
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
String message = userMessage.getMessage(replacementText);
JPanel panel = MessagePanelFactory.createSimple(message);
JOptionPane pane = new JOptionPane(panel, JOptionPaneMessageType, 0, null, userMessage.getOptions(), userMessage.getDefaultSelection());
final JDialog dialog = new LWTitledOptionPaneDialog(lwParent, title, pane);
dialog.setResizable(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.pack();
try {
dialog.setVisible(true);
Object selectedValue = pane.getValue();
if (selectedValue == null || selectedValue.equals(JOptionPane.UNINITIALIZED_VALUE)) {
return SimpleUserMessage.OPTION_CANCEL;
} else {
return selectedValue.toString();
}
} finally {
dialog.dispose();
}
}
use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.
the class DialogUtils method showOptionsDialog.
private static String showOptionsDialog(final Component requester, Component showComponent, final int JOptionPaneMessageType, String[] options, String initOption, OKEnabler okEnabler, String title) {
VCellThreadChecker.checkSwingInvocation();
checkForNull(requester);
LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
JOptionPane pane = new JOptionPane(showComponent, JOptionPaneMessageType, 0, null, options, initOption);
final JDialog dialog = new LWTitledOptionPaneDialog(lwParent, title, pane);
dialog.setResizable(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
if (okEnabler != null) {
okEnabler.setJOptionPane(pane);
}
try {
dialog.setVisible(true);
Object selectedValue = pane.getValue();
if (selectedValue == null || selectedValue.equals(JOptionPane.UNINITIALIZED_VALUE)) {
return SimpleUserMessage.OPTION_CANCEL;
} else {
return selectedValue.toString();
}
} finally {
dialog.dispose();
}
}
Aggregations