Example usage for javax.swing JDialog addWindowListener

List of usage examples for javax.swing JDialog addWindowListener

Introduction

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

Prototype

public synchronized void addWindowListener(WindowListener l) 

Source Link

Document

Adds the specified window listener to receive window events from this window.

Usage

From source file:Main.java

public static void main(String[] a) {
    JDialog f = new JDialog();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//from  w w w  .ja  v  a  2 s .  com
        }
    });

    JButton btOK = new JButton("Press Enter to click me, I am the default.");
    btOK.setToolTipText("Save and exit");
    f.getRootPane().setDefaultButton(btOK);

    JPanel p = new JPanel();
    p.add(btOK);
    p.add(new JButton("I am NOT the default."));
    f.getContentPane().add(p);

    f.pack();
    f.setSize(new Dimension(300, 200));

    f.setVisible(true);

}

From source file:DefaultButton.java

public static void main(String[] a) {
    JDialog f = new JDialog();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/* w w  w.  j av  a  2s. c  o  m*/
        }
    });

    JButton btOK = new JButton("Press Enter to click me, I am the default.");
    btOK.setToolTipText("Save and exit");
    f.getRootPane().setDefaultButton(btOK);

    JPanel p = new JPanel();
    p.add(btOK);
    p.add(new JButton("I am NOT the default."));
    f.getContentPane().add(p);

    f.pack();
    f.setSize(new Dimension(300, 200));

    f.show();

}

From source file:Main.java

public static void main(String[] argv) {
    final JColorChooser chooser = new JColorChooser();
    ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Color newColor = chooser.getColor();
        }/*from   www  .ja va 2 s . com*/
    };

    ActionListener cancelListener = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Color newColor = chooser.getColor();
        }
    };

    boolean modal = false;

    JDialog dialog = JColorChooser.createDialog(null, "Dialog Title", modal, chooser, okListener,
            cancelListener);

    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            Color newColor = chooser.getColor();
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    MyFileChooser chooser = new MyFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    final JDialog dialog = chooser.createDialog(null);
    chooser.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent evt) {
            JFileChooser chooser = (JFileChooser) evt.getSource();
            if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
                dialog.setVisible(false);
            } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
                dialog.setVisible(false);
            }//from  w w w.j  a  v a  2  s.  com
        }
    });

    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dialog.setVisible(false);
        }
    });

    dialog.setVisible(true);
}

From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java

public static void show(ClientFrame frame, final JSONArray data) {
    final JDialog dialog = new JDialog(frame, "Katalog whlen", true);
    dialog.setSize(400, 300);//from w w w .j a v a2  s  .co  m
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    });

    JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    dialog.setContentPane(contentPane);
    DefaultListModel dlm = new DefaultListModel();
    for (int i = 0; i < data.length(); i++) {
        try {
            dlm.addElement(data.getJSONObject(i).getString("name"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    final JList catalogs = new JList(dlm);
    catalogs.setDragEnabled(false);
    catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    jsp.setPreferredSize(new Dimension(396, 200));
    contentPane.add(jsp);

    JPanel mods = new JPanel(new GridLayout(1, 2));
    mods.setPreferredSize(new Dimension(50, 22));
    mods.add(new JButton(new AbstractAction("+") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = JOptionPane.showInputDialog(dialog,
                    "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen",
                    JOptionPane.PLAIN_MESSAGE);
            if (name != null && name.length() > 0) {
                DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                for (int i = 0; i < dlm.getSize(); i++) {
                    if (dlm.get(i).toString().equals(name)) {
                        JOptionPane.showMessageDialog(dialog,
                                "Es existert bereits ein Katalog mit diesem Namen!",
                                "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE);
                        actionPerformed(e);
                        return;
                    }
                }

                try {
                    dlm.addElement(name);
                    JSONObject o = new JSONObject();
                    o.put("name", name);
                    o.put("sources", new JSONArray());
                    o.put("tags", new JSONArray());
                    data.put(o);
                    Client.currentClient.sendPacket(new Packet0Catalogs(data));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));
    mods.add(new JButton(new AbstractAction("-") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                if (JOptionPane.showConfirmDialog(dialog,
                        "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?",
                        "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    DefaultListModel dlm = (DefaultListModel) catalogs.getModel();
                    data.remove(catalogs.getSelectedIndex());
                    dlm.remove(catalogs.getSelectedIndex());
                    try {
                        Client.currentClient.sendPacket(new Packet0Catalogs(data));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }));

    contentPane.add(mods);

    JLabel l = new JLabel("");
    l.setPreferredSize(new Dimension(396, 14));
    contentPane.add(l);

    JSeparator sep = new JSeparator(JSeparator.HORIZONTAL);
    sep.setPreferredSize(new Dimension(396, 10));
    contentPane.add(sep);

    JPanel buttons = new JPanel(new GridLayout(1, 2));
    buttons.setPreferredSize(new Dimension(396, 22));
    buttons.add(new JButton(new AbstractAction("Abbrechen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            Client.currentClient.disconnect();
            System.exit(0);
        }
    }));
    buttons.add(new JButton(new AbstractAction("Katalog whlen") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (catalogs.getSelectedIndex() != -1) {
                try {
                    Client.currentClient
                            .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex())));
                    Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName());
                    dialog.dispose();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }));

    dialog.add(buttons);

    dialog.setLocationRelativeTo(frame);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:IHM.GialogGraph.java

public void Show() {
    VisualizationViewer<String, String> vv;
    vv = new VisualizationViewer<>(new CircleLayout<String, String>(JungGraph), dim);

    Transformer<String, String> transformer = new Transformer<String, String>() {
        @Override/*from   w  ww  .  j av a  2s .  co  m*/
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setVertexLabelTransformer(transformer);
    transformer = new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(transformer);
    vv.getRenderer().setVertexRenderer(new MyRenderer());
    DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    JDialog frame = new JDialog(MymainWidow);
    frame.getContentPane().add(vv);
    frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            MymainWidow.enable();
        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }
    });
    frame.pack();
    frame.setLocationRelativeTo(MymainWidow);
    frame.setResizable(true);
    frame.setVisible(true);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java

private void displayShutdownDialog() {
    String serverId = ServerDetector.getServerId();
    log.info("Running in: " + (serverId != null ? serverId : "unknown server"));
    log.info("Console: " + ((System.console() != null) ? "available" : "not available"));
    log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no"));

    // Show this only when run from the standalone JAR via a double-click
    if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) {
        log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'");

        EventQueue.invokeLater(new Runnable() {
            @Override//  w w  w.ja  va  2s  . c om
            public void run() {
                final JOptionPane optionPane = new JOptionPane(new JLabel(
                        "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>"
                                + "WebAnno works best with the browsers Google Chrome or Safari.<br>"
                                + "Use this dialog to shut WebAnno down.</HTML>"),
                        JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null,
                        new String[] { "Shutdown" });

                final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent we) {
                        // Avoid closing window by other means than button
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent aEvt) {
                        if (dialog.isVisible() && (aEvt.getSource() == optionPane)
                                && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) {
                            System.exit(0);
                        }
                    }
                });
                dialog.pack();
                dialog.setVisible(true);
            }
        });
    } else {
        log.info("Running in server environment or from command line: disabling interactive shutdown dialog.");
    }
}

From source file:com.haulmont.cuba.desktop.exception.DefaultExceptionHandler.java

@Override
public boolean handle(Thread thread, Throwable exception) {
    JXErrorPane errorPane = new JXErrorPaneExt();

    errorPane.setErrorInfo(createErrorInfo(exception));
    JDialog dialog = JXErrorPane.createDialog(App.getInstance().getMainFrame(), errorPane);
    dialog.setMinimumSize(new Dimension(600, (int) dialog.getMinimumSize().getHeight()));

    final DialogWindow lastDialogWindow = getLastDialogWindow();
    dialog.addWindowListener(new WindowAdapter() {
        @Override/*  ww w. j  a v a2  s.  c o m*/
        public void windowClosed(WindowEvent e) {
            if (lastDialogWindow != null)
                lastDialogWindow.enableWindow();
            else
                App.getInstance().getMainFrame().activate();
        }
    });
    dialog.setModal(false);

    if (lastDialogWindow != null)
        lastDialogWindow.disableWindow(null);
    else
        App.getInstance().getMainFrame().deactivate(null);

    dialog.setVisible(true);
    return true;
}

From source file:de.juwimm.cms.http.AuthenticationStreamSupportingHttpInvokerRequestExecutor.java

@Override
protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient,
        PostMethod postMethod) throws IOException {
    HttpClientWrapper.getInstance().setHostConfiguration(super.getHttpClient(),
            new URL(config.getServiceUrl()));
    try {//from ww w .j av a2 s .  c  o  m
        super.executePostMethod(config, httpClient, postMethod);
        //if call succeeds 
        isErrorMessageShown = false;
    } catch (IOException e) {
        if ((e instanceof SocketException && e.getMessage().equals("Connection reset"))
                || (e instanceof ConnectException && e.getMessage().equals("Connection refused"))) {
            if (!isErrorMessageShown) {
                isErrorMessageShown = true;
                JOptionPane errorOptionPane = new JOptionPane(
                        Constants.rb.getString("exception.connectionToServerLost"),
                        JOptionPane.INFORMATION_MESSAGE);
                JDialog errorDialogPane = errorOptionPane.createDialog(UIConstants.getMainFrame(),
                        rb.getString("dialog.title"));
                errorDialogPane.setModalityType(ModalityType.MODELESS);
                errorDialogPane.setVisible(true);
                errorDialogPane.setEnabled(true);
                errorDialogPane.addWindowListener(new WindowAdapter() {
                    public void windowDeactivated(WindowEvent e) {
                        if (((JDialog) e.getSource()).isVisible() == false) {
                            isErrorMessageShown = false;
                        }
                    }
                });

            }
            log.error("server is not reachable");
        } else {
            e.printStackTrace();
        }
    }
    System.out.println(postMethod.getResponseHeaders());
}

From source file:com.aw.swing.mvp.JDialogView.java

private void initializeDlg() {
    if (pst.isEmbeddedView()) {
        return;//from  w ww  . j  ava 2 s.  co m
    }
    JDialog dlg = (JDialog) parentContainer;

    dlg.add(viewLayout.mainPanel, BorderLayout.CENTER);

    //        SwingUtils.locateOnScreenCenter(dlg);
    SwingUtils.locateRelativeToMenu(dlg);
    dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dlg.addWindowListener(new java.awt.event.WindowAdapter() {
        // todo ver cmo se va a hacer esto en la versin Filthy
        public void windowOpened(WindowEvent e) {
            if (pst != null) {
                pst.onWindowsOpened(e);
                pst.onWindowsOpenedInternalOnlyForAWFW(e);
                if (!pst.isReadOnly()) {
                    //                        pst.setFocusToCmpOnWindowOpen();
                    //                        ActionManager.instance().getVisualMgrForActions().repaintMainDisabledActions(pst.getActionRsr());
                } else {
                    pst.configureAsReanOnly();
                    JButton btnCancel = (JButton) pst.getIpView().getComponent("btnCancel");
                    if (btnCancel != null) {
                        btnCancel.requestFocusInWindow();
                    }
                }
            }
        }

        public void windowClosing(WindowEvent e) {
            MsgDisplayer.showMessage("sw.common.closeWindowDisabled");
        }

        public void windowActivated(WindowEvent e) {
            Object oppositeWindow = e.getOppositeWindow();

            if (oppositeWindow instanceof DlgMensaje) {
                logger.debug("Ignoring Windows activated for DlgMensaje");
                return;
            }
            if (oppositeWindow instanceof JDialog) {
                JDialog dlg = (JDialog) oppositeWindow;
                if (MessageDisplayer.GENERIC_MESSAGE_TITLE.equals(dlg.getTitle())) {
                    logger.debug("Ignoring Windows activated for System Msg");
                    return;
                }
            }
            logger.debug("Windows Activated:" + pst);
            AWWindowsManager.instance().setPresenterActivated(pst);
        }
    });
}