Search in sources :

Example 6 with LWTitledOptionPaneDialog

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);
    }
}
Also used : JPanel(javax.swing.JPanel) UtilCancelException(org.vcell.util.UtilCancelException) Hashtable(java.util.Hashtable) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) JLabel(javax.swing.JLabel) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) BorderLayout(java.awt.BorderLayout) JDialog(javax.swing.JDialog)

Example 7 with LWTitledOptionPaneDialog

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) LWDialog(org.vcell.client.logicalwindow.LWDialog) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) Dimension(java.awt.Dimension) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) BorderLayout(java.awt.BorderLayout)

Example 8 with LWTitledOptionPaneDialog

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) Doer(org.vcell.util.gui.VCSwingFunction.Doer) Dimension(java.awt.Dimension) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 9 with LWTitledOptionPaneDialog

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();
    }
}
Also used : JPanel(javax.swing.JPanel) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 10 with LWTitledOptionPaneDialog

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();
    }
}
Also used : LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JOptionPane (javax.swing.JOptionPane)12 LWContainerHandle (org.vcell.client.logicalwindow.LWContainerHandle)12 LWTitledOptionPaneDialog (org.vcell.client.logicalwindow.LWTitledOptionPaneDialog)12 JDialog (javax.swing.JDialog)8 JPanel (javax.swing.JPanel)8 Doer (org.vcell.util.gui.VCSwingFunction.Doer)5 BorderLayout (java.awt.BorderLayout)4 LWDialog (org.vcell.client.logicalwindow.LWDialog)4 Dimension (java.awt.Dimension)3 JScrollPane (javax.swing.JScrollPane)3 JTextArea (javax.swing.JTextArea)2 Collection (java.util.Collection)1 Hashtable (java.util.Hashtable)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 UserCancelException (org.vcell.util.UserCancelException)1 UtilCancelException (org.vcell.util.UtilCancelException)1