Example usage for javax.swing JDialog JDialog

List of usage examples for javax.swing JDialog JDialog

Introduction

In this page you can find the example usage for javax.swing JDialog JDialog.

Prototype

public JDialog(Window owner, String title) 

Source Link

Document

Creates a modeless dialog with the specified title and owner Window .

Usage

From source file:DataExchangeTest.java

/**
 * Show the chooser panel in a dialog//  w  ww  .  jav a2 s. c o  m
 * @param parent a component in the owner frame or null
 * @param title the dialog window title
 */
public boolean showDialog(Component parent, String title) {
    ok = false;

    // locate the owner frame

    Frame owner = null;
    if (parent instanceof Frame)
        owner = (Frame) parent;
    else
        owner = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    // if first time, or if owner has changed, make new dialog

    if (dialog == null || dialog.getOwner() != owner) {
        dialog = new JDialog(owner, true);
        dialog.add(this);
        dialog.getRootPane().setDefaultButton(okButton);
        dialog.pack();
    }

    // set title and show dialog

    dialog.setTitle(title);
    dialog.setVisible(true);
    return ok;
}

From source file:de.freese.base.swing.mac_os_x.MyApp.java

/**
 *
 */// w w  w.jav  a 2 s  .  co m
public MyApp() {
    super("OSXAdapter");

    addMenus();

    // Main content area; set up a JLabel to display images selected by the user
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(this.imageLabel = new JLabel("Open an image to view it"));
    this.imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
    this.imageLabel.setVerticalAlignment(SwingConstants.CENTER);
    this.imageLabel.setOpaque(true);

    // set up a simple about box
    this.aboutBox = new JDialog(this, "About OSXAdapter");
    this.aboutBox.getContentPane().setLayout(new BorderLayout());
    this.aboutBox.getContentPane().add(new JLabel("OSXAdapter", SwingConstants.CENTER));
    this.aboutBox.getContentPane().add(new JLabel("\u00A92003-2007 Apple, Inc.", SwingConstants.CENTER),
            BorderLayout.SOUTH);
    this.aboutBox.setSize(160, 120);
    this.aboutBox.setResizable(false);

    // Preferences dialog lets you select the background color when displaying an image
    this.prefs = new JDialog(this, "OSXAdapter Preferences");
    this.colorComboBox = new JComboBox<>(this.colorNames);
    this.colorComboBox.addActionListener(new ActionListener() {
        /**
         * @see
         * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         */
        @Override
        public void actionPerformed(final ActionEvent ev) {
            if (MyApp.this.currentImage != null) {
                MyApp.this.imageLabel
                        .setBackground(MyApp.this.colors[MyApp.this.colorComboBox.getSelectedIndex()]);
            }
        }
    });

    JPanel masterPanel = new JPanel();
    masterPanel.setBorder(new TitledBorder("Window background color:"));
    masterPanel.add(this.colorComboBox);
    this.prefs.getContentPane().add(masterPanel);
    this.prefs.setSize(240, 100);
    this.prefs.setResizable(false);

    // Set up our application to respond to the Mac OS X application menu
    registerForMacOSXEvents();

    setSize(320, 240);
}

From source file:com.tascape.qa.th.android.driver.App.java

/**
 * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting
 * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction.
 *
 * @param timeoutMinutes timeout in minutes to fail the manual steps
 *
 * @throws Exception if case of error//ww  w .  j a v  a  2s . com
 */
public void interactManually(int timeoutMinutes) throws Exception {
    LOG.info("Start manual UI interaction");
    long end = System.currentTimeMillis() + timeoutMinutes * 60000L;

    AtomicBoolean visible = new AtomicBoolean(true);
    AtomicBoolean pass = new AtomicBoolean(false);
    String tName = Thread.currentThread().getName() + "m";
    SwingUtilities.invokeLater(() -> {
        JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail());
        jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        JPanel jpContent = new JPanel(new BorderLayout());
        jd.setContentPane(jpContent);
        jpContent.setPreferredSize(new Dimension(1088, 828));
        jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        JPanel jpInfo = new JPanel();
        jpContent.add(jpInfo, BorderLayout.PAGE_START);
        jpInfo.setLayout(new BorderLayout());
        {
            JButton jb = new JButton("PASS");
            jb.setForeground(Color.green.darker());
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_START);
            jb.addActionListener(event -> {
                pass.set(true);
                jd.dispose();
                visible.set(false);
            });
        }
        {
            JButton jb = new JButton("FAIL");
            jb.setForeground(Color.red);
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_END);
            jb.addActionListener(event -> {
                pass.set(false);
                jd.dispose();
                visible.set(false);
            });
        }

        JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        new SwingWorker<Long, Long>() {
            @Override
            protected Long doInBackground() throws Exception {
                while (System.currentTimeMillis() < end) {
                    Thread.sleep(1000);
                    long left = (end - System.currentTimeMillis()) / 1000;
                    this.publish(left);
                }
                return 0L;
            }

            @Override
            protected void process(List<Long> chunks) {
                Long l = chunks.get(chunks.size() - 1);
                jlTimeout.setText(l + " seconds left");
                if (l < 850) {
                    jlTimeout.setForeground(Color.red);
                }
            }
        }.execute();

        JPanel jpResponse = new JPanel(new BorderLayout());
        JPanel jpProgress = new JPanel(new BorderLayout());
        jpResponse.add(jpProgress, BorderLayout.PAGE_START);

        JTextArea jtaJson = new JTextArea();
        jtaJson.setEditable(false);
        jtaJson.setTabSize(4);
        Font font = jtaJson.getFont();
        jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize()));

        JTree jtView = new JTree();

        JTabbedPane jtp = new JTabbedPane();
        jtp.add("tree", new JScrollPane(jtView));
        jtp.add("json", new JScrollPane(jtaJson));

        jpResponse.add(jtp, BorderLayout.CENTER);

        JPanel jpScreen = new JPanel();
        jpScreen.setMinimumSize(new Dimension(200, 200));
        jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS));
        JScrollPane jsp1 = new JScrollPane(jpScreen);
        jpResponse.add(jsp1, BorderLayout.LINE_START);

        JPanel jpJs = new JPanel(new BorderLayout());
        JTextArea jtaJs = new JTextArea();
        jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER);

        JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs);
        jSplitPane.setResizeWeight(0.88);
        jpContent.add(jSplitPane, BorderLayout.CENTER);

        JPanel jpLog = new JPanel();
        jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
        jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS));

        JCheckBox jcbTap = new JCheckBox("Enable Click", null, false);
        jpLog.add(jcbTap);
        jpLog.add(Box.createHorizontalStrut(8));

        JButton jbLogUi = new JButton("Log Screen");
        jpResponse.add(jpLog, BorderLayout.PAGE_END);
        {
            jpLog.add(jbLogUi);
            jbLogUi.addActionListener((ActionEvent event) -> {
                jtaJson.setText("waiting for screenshot...");
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        LOG.debug("\n\n");
                        try {
                            WindowHierarchy wh = device.loadWindowHierarchy();
                            jtView.setModel(getModel(wh));

                            jtaJson.setText("");
                            jtaJson.append(wh.root.toJson().toString(2));
                            jtaJson.append("\n");

                            File png = device.takeDeviceScreenshot();
                            BufferedImage image = ImageIO.read(png);

                            int w = device.getDisplayWidth();
                            int h = device.getDisplayHeight();

                            BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                            Graphics2D g2 = resizedImg.createGraphics();
                            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                            g2.drawImage(image, 0, 0, w, h, null);
                            g2.dispose();

                            JLabel jLabel = new JLabel(new ImageIcon(resizedImg));
                            jpScreen.removeAll();
                            jsp1.setPreferredSize(new Dimension(w + 30, h));
                            jpScreen.add(jLabel);

                            jLabel.addMouseListener(new MouseAdapter() {
                                @Override
                                public void mouseClicked(MouseEvent e) {
                                    LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY());
                                    if (jcbTap.isSelected()) {
                                        device.click(e.getPoint().x, e.getPoint().y);
                                        device.waitForIdle();
                                        jbLogUi.doClick();
                                    }
                                }
                            });
                        } catch (Exception ex) {
                            LOG.error("Cannot log screen", ex);
                            jtaJson.append("Cannot log screen");
                        }
                        jtaJson.append("\n\n\n");
                        LOG.debug("\n\n");

                        jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1);
                        jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1);
                    }
                };
                t.start();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbLogMsg = new JButton("Log Message");
            jpLog.add(jbLogMsg);
            JTextField jtMsg = new JTextField(10);
            jpLog.add(jtMsg);
            jtMsg.addFocusListener(new FocusListener() {
                @Override
                public void focusLost(final FocusEvent pE) {
                }

                @Override
                public void focusGained(final FocusEvent pE) {
                    jtMsg.selectAll();
                }
            });
            jtMsg.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(java.awt.event.KeyEvent e) {
                    if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                        jbLogMsg.doClick();
                    }
                }
            });
            jbLogMsg.addActionListener(event -> {
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        String msg = jtMsg.getText();
                        if (StringUtils.isNotBlank(msg)) {
                            LOG.info("{}", msg);
                            jtMsg.selectAll();
                        }
                    }
                };
                t.start();
                try {
                    t.join();
                } catch (InterruptedException ex) {
                    LOG.error("Cannot take screenshot", ex);
                }
                jtMsg.requestFocus();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbClear = new JButton("Clear");
            jpLog.add(jbClear);
            jbClear.addActionListener(event -> {
                jtaJson.setText("");
            });
        }

        JPanel jpAction = new JPanel();
        jpContent.add(jpAction, BorderLayout.PAGE_END);
        jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS));
        jpJs.add(jpAction, BorderLayout.PAGE_END);

        jd.pack();
        jd.setVisible(true);
        jd.setLocationRelativeTo(null);

        jbLogUi.doClick();
    });

    while (visible.get()) {
        if (System.currentTimeMillis() > end) {
            LOG.error("Manual UI interaction timeout");
            break;
        }
        Thread.sleep(500);
    }

    if (pass.get()) {
        LOG.info("Manual UI Interaction returns PASS");
    } else {
        Assert.fail("Manual UI Interaction returns FAIL");
    }
}

From source file:emailplugin.MailCreator.java

/**
 * Show the EMail-Open Dialog.// w  ww. ja  va 2  s.  c  o m
 *
 * This Dialog says that the EMail should have been opened. It gives the User
 * a chance to specify another EMail Program if it went wrong.
 *
 * @param parent
 *          Parent-Frame
 */
private void showEMailOpenedDialog(Frame parent) {
    final JDialog dialog = new JDialog(parent, true);

    dialog.setTitle(mLocalizer.msg("EMailOpenedTitel", "Email was opened"));

    JPanel panel = (JPanel) dialog.getContentPane();
    panel.setLayout(new FormLayout("fill:200dlu:grow", "default, 3dlu, default, 3dlu, default"));
    panel.setBorder(Borders.DIALOG_BORDER);

    CellConstraints cc = new CellConstraints();

    panel.add(UiUtilities.createHelpTextArea(mLocalizer.msg("EMailOpened", "Email was opened. Configure it?")),
            cc.xy(1, 1));

    final JCheckBox dontShowAgain = new JCheckBox(
            mLocalizer.msg("DontShowAgain", "Don't show this Dialog again"));
    panel.add(dontShowAgain, cc.xy(1, 3));

    JButton configure = new JButton(mLocalizer.msg("configure", "Configure"));
    configure.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Plugin.getPluginManager().showSettings(mPlugin);
            dialog.setVisible(false);
        }
    });

    JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (dontShowAgain.isSelected()) {
                mSettings.setShowEmailOpened(false);
            }
            dialog.setVisible(false);
        }
    });

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonPanel.add(configure);
    buttonPanel.add(ok);
    panel.add(buttonPanel, cc.xy(1, 5));

    UiUtilities.registerForClosing(new WindowClosingIf() {
        public void close() {
            dialog.setVisible(false);
        }

        public JRootPane getRootPane() {
            return dialog.getRootPane();
        }
    });

    dialog.getRootPane().setDefaultButton(ok);

    dialog.pack();
    UiUtilities.centerAndShow(dialog);
}

From source file:edu.ku.brc.specify.dbsupport.SpecifyDeleteHelper.java

/**
 * @param workerArg//w  w  w  .  j  av a  2s  .  c  o  m
 * @param title (already localized)
 * @return a modal dialog showing the progress
 */
public JDialog initProgress(final SwingWorker<?, ?> workerArg, final String title) {
    this.worker = workerArg;

    if (workerArg != null) {
        JDialog dialog = new JDialog((Dialog) null, true);

        titleLbl = new JLabel(title);
        progressBar = new JProgressBar(0, 100);

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,p,4px,p,f:p:g"));

        pb.add(titleLbl, cc.xy(1, 2));
        pb.add(progressBar, cc.xy(1, 4));
        pb.setDefaultDialogBorder();
        dialog.setContentPane(pb.getPanel());

        dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        dialog.pack();
        dialog.setSize(500, 150);
        workerArg.addPropertyChangeListener(new SwingWorkerCompletionWaiter(dialog));
        return dialog;
    }
    return null;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static JDialog createMessageDialog(Window parent, String title, String msg) {

    final JDialog dialog = new JDialog(parent, title);

    final JTextArea message = createMultiLineLabel(msg);

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;//from   w  w  w.  ja v  a  2s.c  o  m
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right         
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);
    dialog.pack();
    return dialog;
}

From source file:com.anrisoftware.prefdialog.spreadsheetimportdialog.dialog.SpreadsheetImportDialogWorker.java

@Override
protected JDialog createDialog() {
    JDialog jdialog = new JDialog(parentWindow, APPLICATION_MODAL);
    jdialog.setLocale(getLocale());/*from w w  w. j  a v a 2s.c  o  m*/
    SpreadsheetImportDialog importDialog;
    importDialog = spreadsheetImportDialogFactory.create(savedProperties);
    importDialog.setParentInjector(parent);
    importDialog.setDialog(jdialog);
    importDialog.createDialog(parentWindow, importerFactory);
    setupSavedProperties(properties, savedProperties);
    importDialog.setPropertiesNoChecks(properties);
    jdialog.pack();
    jdialog.setSize(size);
    jdialog.setTitle(getDialogTitleFromResource());
    jdialog.setLocationRelativeTo(parentWindow);
    insertListeners(importDialog);
    this.importDialog = new SoftReference<SpreadsheetImportDialog>(importDialog);
    return jdialog;
}

From source file:idontwant2see.IDontWant2See.java

public ActionMenu getButtonAction() {
    final ContextMenuAction baseAction = new ContextMenuAction(mLocalizer.msg("name", "I don't want to see!"),
            createImageIcon("apps", "idontwant2see", 16));

    final ContextMenuAction openExclusionList = new ContextMenuAction(
            mLocalizer.msg("editExclusionList", "Edit exclusion list"),
            createImageIcon("apps", "idontwant2see", 16));
    openExclusionList.putValue(Plugin.BIG_ICON, createImageIcon("apps", "idontwant2see", 22));
    openExclusionList.setActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            final Window w = UiUtilities.getLastModalChildOf(getParentFrame());

            JDialog temDlg = null;

            if (w instanceof JDialog) {
                temDlg = new JDialog((JDialog) w, true);
            } else {
                temDlg = new JDialog((JFrame) w, true);
            }/*from w  w w . j ava 2  s .c o  m*/

            final JDialog exclusionListDlg = temDlg;
            exclusionListDlg.setTitle(mLocalizer.msg("name", "I don't want to see!") + " - "
                    + mLocalizer.msg("editExclusionList", "Edit exclusion list"));

            UiUtilities.registerForClosing(new WindowClosingIf() {
                public void close() {
                    exclusionListDlg.dispose();
                }

                public JRootPane getRootPane() {
                    return exclusionListDlg.getRootPane();
                }
            });

            final ExclusionTablePanel exclusionPanel = new ExclusionTablePanel(mSettings);

            final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
            ok.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent e) {
                    exclusionPanel.saveSettings(mSettings);
                    exclusionListDlg.dispose();
                }
            });

            final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
            cancel.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent e) {
                    exclusionListDlg.dispose();
                }
            });

            final FormLayout layout = new FormLayout("0dlu:grow,default,3dlu,default",
                    "fill:500px:grow,2dlu,default,5dlu,default");
            layout.setColumnGroups(new int[][] { { 2, 4 } });

            final CellConstraints cc = new CellConstraints();
            final PanelBuilder pb = new PanelBuilder(layout, (JPanel) exclusionListDlg.getContentPane());
            pb.setDefaultDialogBorder();

            pb.add(exclusionPanel, cc.xyw(1, 1, 4));
            pb.addSeparator("", cc.xyw(1, 3, 4));
            pb.add(ok, cc.xy(2, 5));
            pb.add(cancel, cc.xy(4, 5));

            layoutWindow("exclusionListDlg", exclusionListDlg, new Dimension(600, 450));
            exclusionListDlg.setVisible(true);
        }
    });

    final ContextMenuAction undo = new ContextMenuAction(
            mLocalizer.msg("undoLastExclusion", "Undo last exclusion"),
            createImageIcon("actions", "edit-undo", 16));
    undo.putValue(Plugin.BIG_ICON, createImageIcon("actions", "edit-undo", 22));
    undo.setActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            String lastEnteredExclusionString = mSettings.getLastEnteredExclusionString();
            if (lastEnteredExclusionString.length() > 0) {
                for (int i = mSettings.getSearchList().size() - 1; i >= 0; i--) {
                    if (mSettings.getSearchList().get(i).getSearchText().equals(lastEnteredExclusionString)) {
                        mSettings.getSearchList().remove(i);
                    }
                }

                mSettings.setLastEnteredExclusionString("");

                updateFilter(true);
            }
        }
    });

    return new ActionMenu(baseAction, new Action[] { openExclusionList, undo });
}

From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java

License:asdf

/**
 * Initialize the GUI components//from   w w  w  .j  ava2s .  c om
 */
protected void initGUI() {
    //Global stuff
    setSize(fullWidth, fullHeight);

    eventPropertiesTable = new QuantEvent.QuantEventPropertiesTable();
    eventPropertiesTable.setVisible(true);
    JScrollPane eventPropsScrollPane = new JScrollPane();
    eventPropsScrollPane.setViewportView(eventPropertiesTable);
    eventPropsScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog = new JDialog(this, "Event Properties");
    eventPropertiesDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    eventPropertiesDialog.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog.setContentPane(eventPropsScrollPane);

    ListenerHelper helper = new ListenerHelper(this);
    setTitle("Protein Summary");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    try {
        (getOwner()).setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/ProteinQuantSummaryFrame.xml", this);
        assert null != contentPanel;
        setContentPane(contentPanel);
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    buttonSelectAllVisible.setEnabled(false);
    helper.addListener(buttonSelectAllVisible, "buttonSelectAllVisible_actionPerformed");
    buttonDeselectAll.setEnabled(false);
    helper.addListener(buttonDeselectAll, "buttonDeselectAll_actionPerformed");

    buildTurkHITsButton.setEnabled(false);
    helper.addListener(buildTurkHITsButton, "buttonBuildTurkHITs_actionPerformed");
    loadSelectedEventsButton.setEnabled(false);
    helper.addListener(loadSelectedEventsButton, "buttonLoadSelected_actionPerformed");
    autoAssessSelectedEventsButton.setEnabled(false);
    helper.addListener(autoAssessSelectedEventsButton, "buttonAutoAssess_actionPerformed");

    showPropertiesButton.setEnabled(false);
    helper.addListener(showPropertiesButton, "buttonShowProperties_actionPerformed");
    showProteinRatiosButton.setEnabled(false);
    helper.addListener(showProteinRatiosButton, "buttonShowProteinRatios_actionPerformed");

    //summary panel
    summaryPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    summaryPanel.setPreferredSize(new Dimension(fullWidth, summaryPanelHeight));
    summaryPanel.setMinimumSize(new Dimension(200, summaryPanelHeight));
    gbc.fill = GridBagConstraints.NONE;

    gbc.gridwidth = 1;
    summaryPanel.add(buttonSelectAllVisible, gbc);
    summaryPanel.add(buttonDeselectAll, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(showPropertiesButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(showProteinRatiosButton, gbc);

    gbc.gridwidth = 1;

    summaryPanel.add(loadSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(autoAssessSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(buildTurkHITsButton, gbc);

    gbc.fill = GridBagConstraints.BOTH;

    eventsScrollPane = new JScrollPane();
    eventsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    eventsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    eventsPanel = new JPanel();
    eventsPanel.setLayout(new GridBagLayout());

    eventsTable = new QuantEventsSummaryTable();
    eventsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    eventsTable.getSelectionModel().addListSelectionListener(new EventsTableListSelectionHandler());
    eventsScrollPane.setViewportView(eventsTable);
    eventsScrollPane.setMinimumSize(new Dimension(400, 400));

    gbc.insets = new Insets(0, 0, 0, 0);
    mainPanel.add(eventsScrollPane, gbc);

    logRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    logRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    logRatioHistogramPanel.setPreferredSize(new Dimension(width - 10, 300));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 100;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    add(logRatioHistogramPanel, gbc);

    //status message
    messageLabel = new JLabel();
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");
    statusPanel = new JPanel();
    gbc.weighty = 1;
    statusPanel.setPreferredSize(new Dimension(width - 10, 50));
    statusPanel.add(messageLabel, gbc);
    add(statusPanel, gbc);

    //per-protein event summary table; disembodied
    //todo: move this into its own class? it's getting kind of complicated
    proteinRatiosTable = new JTable();
    proteinRatiosTable.setVisible(true);
    ListSelectionModel proteinTableSelectionModel = proteinRatiosTable.getSelectionModel();
    proteinTableSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    proteinTableSelectionModel.addListSelectionListener(new ProteinTableListSelectionHandler());
    JScrollPane proteinRatiosScrollPane = new JScrollPane();
    proteinRatiosScrollPane.setViewportView(proteinRatiosTable);
    proteinRatiosScrollPane.setPreferredSize(new Dimension(proteinDialogWidth,
            proteinDialogHeight - PROTEINTABLE_HISTPANEL_HEIGHT - PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT - 70));
    proteinRatiosDialog = new JDialog(this, "Protein Ratios");
    proteinRatiosDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    proteinRatiosDialog.setSize(proteinDialogWidth, proteinDialogHeight);
    JPanel proteinRatiosContentPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    proteinRatiosContentPanel.add(proteinRatiosScrollPane, gbc);
    proteinRatiosDialog.setContentPane(proteinRatiosContentPanel);
    perProteinLogRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    perProteinLogRatioHistogramPanel.addRangeUpdateListener(new ProteinTableLogRatioHistogramListener());

    perProteinLogRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    perProteinLogRatioHistogramPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_HISTPANEL_HEIGHT));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    proteinRatiosDialog.add(perProteinLogRatioHistogramPanel, gbc);

    perProteinPeptideLogRatioPanel = new JPanel();
    perProteinPeptideLogRatioPanel.setBorder(BorderFactory.createTitledBorder("By Peptide"));
    perProteinPeptideLogRatioPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT));
    proteinRatiosDialog.add(perProteinPeptideLogRatioPanel, gbc);
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static void showErrorDialog(Component parent, String title, String textMessage, Throwable cause) {
    final String stacktrace;
    if (cause == null) {
        stacktrace = null;//  ww  w.ja  va 2s.  com
    } else {
        final ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        cause.printStackTrace(new PrintStream(stackTrace));
        stacktrace = new String(stackTrace.toByteArray());
    }

    final JDialog dialog = new JDialog((Window) null, title);

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(textMessage);
    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(okButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    cnstrs.weightx = 1;
    cnstrs.weighty = 0.1;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    if (stacktrace != null) {
        final JTextArea createMultiLineLabel = new JTextArea(stacktrace);

        createMultiLineLabel.setBackground(null);
        createMultiLineLabel.setEditable(false);
        createMultiLineLabel.setBorder(null);
        createMultiLineLabel.setLineWrap(false);
        createMultiLineLabel.setWrapStyleWord(false);

        final JScrollPane pane = new JScrollPane(createMultiLineLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        cnstrs = constraints(0, 1, true, true, GridBagConstraints.BOTH);
        cnstrs.weightx = 1.0;
        cnstrs.weighty = 0.9;
        cnstrs.gridwidth = GridBagConstraints.REMAINDER;
        cnstrs.gridheight = GridBagConstraints.REMAINDER;
        messagePanel.add(pane, cnstrs);
    }

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 1.0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right           
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);

    dialog.setMinimumSize(new Dimension(600, 400));
    dialog.setPreferredSize(new Dimension(600, 400));
    dialog.setMaximumSize(new Dimension(600, 400));

    dialog.pack();
    dialog.setVisible(true);
}