Search in sources :

Example 6 with LWContainerHandle

use of org.vcell.client.logicalwindow.LWContainerHandle 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 LWContainerHandle

use of org.vcell.client.logicalwindow.LWContainerHandle in project vcell by virtualcell.

the class DialogUtils method showModalJDialogOnTop.

/**
 * @deprecated -- use setVisible on LWDialog
 * @param jdialog
 * @param component
 */
public static void showModalJDialogOnTop(JDialog jdialog, Component component) {
    if (jdialog instanceof LWDialog) {
        jdialog.setVisible(true);
        return;
    }
    LWContainerHandle lwParent = LWNamespace.findLWOwner(component);
    LWJDialogDecorator deco = LWJDialogDecorator.decoratorFor(jdialog);
    lwParent.manage(deco);
    deco.getWindow().setVisible(true);
}
Also used : LWDialog(org.vcell.client.logicalwindow.LWDialog) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWJDialogDecorator(org.vcell.client.logicalwindow.transition.LWJDialogDecorator)

Example 8 with LWContainerHandle

use of org.vcell.client.logicalwindow.LWContainerHandle 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 9 with LWContainerHandle

use of org.vcell.client.logicalwindow.LWContainerHandle 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 10 with LWContainerHandle

use of org.vcell.client.logicalwindow.LWContainerHandle 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)

Aggregations

LWContainerHandle (org.vcell.client.logicalwindow.LWContainerHandle)15 JOptionPane (javax.swing.JOptionPane)12 LWTitledOptionPaneDialog (org.vcell.client.logicalwindow.LWTitledOptionPaneDialog)12 JDialog (javax.swing.JDialog)9 JPanel (javax.swing.JPanel)9 LWDialog (org.vcell.client.logicalwindow.LWDialog)5 Doer (org.vcell.util.gui.VCSwingFunction.Doer)5 BorderLayout (java.awt.BorderLayout)4 Dimension (java.awt.Dimension)4 JScrollPane (javax.swing.JScrollPane)3 Hashtable (java.util.Hashtable)2 JTextArea (javax.swing.JTextArea)2 UserCancelException (org.vcell.util.UserCancelException)2 UtilCancelException (org.vcell.util.UtilCancelException)2 DocumentEditorSubPanel (cbit.vcell.client.desktop.biomodel.DocumentEditorSubPanel)1 IssueManager (cbit.vcell.client.desktop.biomodel.IssueManager)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 ClientTaskDispatcher (cbit.vcell.client.task.ClientTaskDispatcher)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1