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) 

Source Link

Document

Creates a modeless dialog with the specified Window as its owner and an empty title.

Usage

From source file:tvbrowser.ui.mainframe.MainFrame.java

private void quit(boolean log, boolean export) {
    mTimer.stop(); // disable the update timer to avoid new update events
    if (log && downloadingThread != null && downloadingThread.isAlive()) {
        final JDialog info = new JDialog(UiUtilities.getLastModalChildOf(this));
        info.setModal(true);//  w w w.  j a va 2  s.  c o m
        info.setUndecorated(true);
        info.toFront();

        JPanel main = new JPanel(new FormLayout("5dlu,pref,5dlu", "5dlu,pref,5dlu"));
        main.setBorder(BorderFactory.createLineBorder(Color.black));
        main.add(
                new JLabel(mLocalizer.msg("downloadinfo",
                        "A data update is running. TV-Browser will be closed when the update is done.")),
                new CellConstraints().xy(2, 2));

        info.setContentPane(main);
        info.pack();
        info.setLocationRelativeTo(this);

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if (downloadingThread != null && downloadingThread.isAlive()) {
                    try {
                        downloadingThread.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                info.setVisible(false);
                info.dispose();
            }
        });

        info.setVisible(true);
    }
    if (log && this.isUndecorated()) {
        switchFullscreenMode();
    }
    if (mShuttingDown) {
        return;
    }
    mShuttingDown = true;

    if (log) {
        FavoritesPlugin.getInstance().handleTvBrowserIsShuttingDown();
    }

    if (log) {
        mLog.info("Finishing plugins");
    }
    PluginProxyManager.getInstance().shutdownAllPlugins(log);

    if (log) {
        mLog.info("Storing dataservice settings");
    }
    TvDataServiceProxyManager.getInstance().shutDown();

    FavoritesPlugin.getInstance().store();
    ReminderPlugin.getInstance().store();

    TVBrowser.shutdown(log);

    if (log) {
        mLog.info("Closing TV data base");
    }

    try {
        TvDataBase.getInstance().close();
    } catch (Exception exc) {
        if (log) {
            mLog.log(Level.WARNING, "Closing database failed", exc);
        }
    }

    if (export) {
        Settings.propTVDataDirectory.resetToDefault();
        Settings.copyToSystem();
    }

    if (log) {
        mLog.info("Quitting");
        System.exit(0);
    }
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudLoginDialog.java

public PasswordAuthentication getPasswordAuthentication(final String prompt) {
    // Set the default background colour to white
    UIManager UI = new UIManager();
    UI.put("OptionPane.background", Color.white);
    UI.put("Panel.background", Color.white);

    String defaultUserName = "";
    if (giftCloudProperties.getLastUserName().isPresent()) {
        defaultUserName = giftCloudProperties.getLastUserName().get();
    }//  ww  w.  j  av a  2 s  .co  m

    // Create a panel for entering username and password
    final JPanel usernamePasswordPanel = new JPanel(new GridBagLayout());

    final JLabel promptField = new JLabel(prompt, SwingConstants.CENTER);
    final JTextField usernameField = new JTextField(defaultUserName, 16);
    final JPasswordField passwordField = new JPasswordField(16);

    // Add a special listener to get the focus onto the username field when the component is created, or password if the username has already been populated from the default value
    if (StringUtils.isBlank(defaultUserName)) {
        usernameField.addAncestorListener(new RequestFocusListener());
    } else {
        passwordField.addAncestorListener(new RequestFocusListener());
    }

    usernamePasswordPanel.add(promptField, promptConstraint);
    usernamePasswordPanel.add(new JLabel("Username:"), labelConstraint);
    usernamePasswordPanel.add(usernameField, fieldConstraint);
    usernamePasswordPanel.add(new JLabel("Password:"), labelConstraint);
    usernamePasswordPanel.add(passwordField, fieldConstraint);

    // Show the login dialog
    final int returnValue = JOptionPane.showConfirmDialog(new JDialog(getFrame(parent)), usernamePasswordPanel,
            LOGIN_DIALOG_TITLE, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon);

    if (JOptionPane.OK_OPTION == returnValue) {
        giftCloudProperties.setLastUserName(usernameField.getText());
        giftCloudProperties.setLastPassword(passwordField.getPassword());
        giftCloudProperties.save();

        return new PasswordAuthentication(usernameField.getText(), passwordField.getPassword());
    } else {
        return null;
    }
}

From source file:util.ui.UiUtilities.java

/**
 * @param parent//from   ww  w  .  j a va 2 s.  c  o m
 *          A component in the component tree where the dialog should be
 *          created for.
 * @param modal
 *          Should the new dialog be modal?
 * @return A new JDialog.
 */
public static JDialog createDialog(Component parent, boolean modal) {
    Window parentWin = getBestDialogParent(parent);
    final JDialog result = new JDialog(parentWin);
    result.setModal(modal);
    return result;
}