Search in sources :

Example 11 with LWTitledOptionPaneDialog

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

the class DialogUtils method showInfoDialog.

/**
 * 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 showInfoDialog(final Component requester, final String title, final String message) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Doer doer = () -> {
        JPanel panel = MessagePanelFactory.createSimple(message);
        JOptionPane pane = new JOptionPane(panel, JOptionPane.INFORMATION_MESSAGE);
        LWDialog dialog = new LWTitledOptionPaneDialog(lwParent, title, pane);
        dialog.setResizable(true);
        showOnce(dialog);
    };
    VCSwingFunction.executeAsRuntimeException(doer);
}
Also used : JPanel(javax.swing.JPanel) LWDialog(org.vcell.client.logicalwindow.LWDialog) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) Doer(org.vcell.util.gui.VCSwingFunction.Doer) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane)

Example 12 with LWTitledOptionPaneDialog

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

the class DialogUtils method showListDialog.

/**
 * 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 Object showListDialog(final Component requester, final Object[] names, final String dialogTitle, final ListCellRenderer<Object> listCellRenderer) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Producer<Object> prod = () -> {
        JPanel panel = new JPanel(new BorderLayout());
        final JOptionPane pane = new JOptionPane(null, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
        JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        final JList<Object> list = new JList<>(names);
        if (listCellRenderer != null) {
            list.setCellRenderer(listCellRenderer);
        }
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        scroller.setViewportView(list);
        Dimension size = new Dimension(list.getPreferredSize());
        size.width = Math.max(80, Math.min(500, size.width + 40));
        size.height = Math.max(75, Math.min(500, size.height + 40));
        scroller.getViewport().setPreferredSize(size);
        panel.add(scroller, BorderLayout.CENTER);
        pane.setMessage(panel);
        setInternalNotCancelEnabled(pane, false, false);
        list.addListSelectionListener(new javax.swing.event.ListSelectionListener() {

            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    DialogUtils.setInternalNotCancelEnabled(pane, list.getSelectedIndex() != -1, false);
                }
            }
        });
        final JDialog dialog = new LWTitledOptionPaneDialog(lwParent, dialogTitle, 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)) {
                return null;
            } else {
                int index = list.getSelectedIndex();
                if (index >= 0 && index < names.length) {
                    return names[index];
                }
                // Should never get here
                return null;
            }
        } finally {
            dialog.dispose();
        }
    };
    return VCSwingFunction.executeAsRuntimeException(prod);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) JList(javax.swing.JList) 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