Example usage for java.awt.event WindowAdapter WindowAdapter

List of usage examples for java.awt.event WindowAdapter WindowAdapter

Introduction

In this page you can find the example usage for java.awt.event WindowAdapter WindowAdapter.

Prototype

WindowAdapter

Source Link

Usage

From source file:ch.unibas.fittingwizard.application.Visualization.java

public void show(File xyzFile) {
    if (jmolWindow == null) {
        logger.info("Creating Jmol window.");
        jmolWindow = new JFrame("Visualization of " + xyzFile.getName());
        jmolWindow.addWindowListener(new WindowAdapter() {
            @Override//from  w  ww . j  a  v  a  2 s  .  c o m
            public void windowClosing(WindowEvent e) {
                logger.info("Jmol window closing.");
                jmolWindow = null;
                jmolViewer = null;
                currentOpenFile = null;
            }
        });
        jmolWindow.setSize(600, 600);

        Container contentPane = jmolWindow.getContentPane();
        JmolPanel jmolPanel = new JmolPanel();

        // main panel -- Jmol panel on top
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(jmolPanel);
        contentPane.add(panel);
        jmolViewer = jmolPanel.viewer;

        alignWindowPositionToWizard();
        jmolWindow.setVisible(true);
    } else {
        logger.debug("Bringing existing Jmol window to front.");
    }
    openFile(xyzFile.getAbsoluteFile());
    jmolWindow.toFront();
}

From source file:PlayerOfMedia.java

/***************************************************************************
 * Construct a PlayerOfMedia. The Frame will have the title supplied by the
 * user. All initial actions on the PlayerOfMedia object are initiated
 * through its menu (or shotcut key)./*from  w  w  w  .  jav  a2s .com*/
 **************************************************************************/
PlayerOfMedia(String name) {

    super(name);
    ///////////////////////////////////////////////////////////
    // Setup the menu system: a "File" menu with Open and Quit.
    ///////////////////////////////////////////////////////////
    bar = new MenuBar();
    fileMenu = new Menu("File");
    MenuItem openMI = new MenuItem("Open...", new MenuShortcut(KeyEvent.VK_O));
    openMI.setActionCommand("OPEN");
    openMI.addActionListener(this);
    fileMenu.add(openMI);
    MenuItem quitMI = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q));
    quitMI.addActionListener(this);
    quitMI.setActionCommand("QUIT");
    fileMenu.add(quitMI);
    bar.add(fileMenu);
    setMenuBar(bar);

    ///////////////////////////////////////////////////////
    // Layout the frame, its position on screen, and ensure
    // window closes are dealt with properly, including
    // relinquishing the resources of any Player.
    ///////////////////////////////////////////////////////
    setLayout(new BorderLayout());
    setLocation(100, 100);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            if (player != null) {
                player.stop();
                player.close();
            }
            System.exit(0);
        }
    });

    /////////////////////////////////////////////////////
    // Build the Dialog box by which the user can select
    // the media to play.
    /////////////////////////////////////////////////////
    selectionDialog = new Dialog(this, "Media Selection");
    Panel pan = new Panel();
    pan.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    mediaName = new TextField(40);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    pan.add(mediaName, gbc);
    choose = new Button("Choose File...");
    gbc.ipadx = 10;
    gbc.ipady = 10;
    gbc.gridx = 2;
    gbc.gridwidth = 1;
    pan.add(choose, gbc);
    choose.addActionListener(this);
    open = new Button("Open");
    gbc.gridy = 1;
    gbc.gridx = 1;
    pan.add(open, gbc);
    open.addActionListener(this);
    cancel = new Button("Cancel");
    gbc.gridx = 2;
    pan.add(cancel, gbc);
    cancel.addActionListener(this);
    selectionDialog.add(pan);
    selectionDialog.pack();
    selectionDialog.setLocation(200, 200);

    ////////////////////////////////////////////////////
    // Build the error Dialog box by which the user can
    // be informed of any errors or problems.
    ////////////////////////////////////////////////////
    errorDialog = new Dialog(this, "Error", true);
    errorLabel = new Label("");
    errorDialog.add(errorLabel, "North");
    ok = new Button("OK");
    ok.addActionListener(this);
    errorDialog.add(ok, "South");
    errorDialog.pack();
    errorDialog.setLocation(150, 300);

    Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true));
}

From source file:MDIApp.java

/*************************************************************************
 * METHODS/* ww w .  j a  va2  s.co m*/
 *************************************************************************/

public MDIApp() {
    super("Java Media Player");

    // Add the desktop pane
    setLayout(new BorderLayout());
    desktop = new JDesktopPane();
    desktop.setDoubleBuffered(true);
    add("Center", desktop);
    setMenuBar(createMenuBar());
    setSize(640, 480);
    setVisible(true);

    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception e) {
        System.err.println("Could not initialize java.awt Metal lnf");
    }
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });

    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
}

From source file:edu.gmu.isa681.client.controller.Controller.java

public Controller(final Client client, final JFrame container) {
    this.client = client;
    this.container = container;

    this.client.addEventListener(new ClientEventListener() {
        @Override/*  w  w w  .ja  v a 2 s  . c om*/
        public void responseReceived(Response response) {
            handleResponse(response);
        }

        @Override
        public void exceptionOccured(Throwable ex) {
            handleException(ex);
        }
    });

    this.container.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            log.info("WindowClosing");

            if (client.isConnected()) {
                logout(WindowEvent.class);
            } else {
                exit();
            }
        }
    });
}

From source file:com.emental.mindraider.ui.dialogs.NewRdfModelJDialog.java

/**
 * Constructor.//from   ww  w . j  av a  2 s. co m
 */
public NewRdfModelJDialog() {

    super(Messages.getString("NewRdfModelJDialog.title"));

    JPanel framePanel = new JPanel();
    framePanel.setLayout(new GridLayout(3, 1));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(Messages.getString("NewRdfModelJDialog.subject")));

    subjectNs = new JTextField(30);
    subjectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    p.add(subjectNs);
    p.add(new JLabel("#"));

    subjectLocalName = new JTextField(15);
    p.add(subjectLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox literalCheckBox = new JCheckBox("literal", false);
    p.add(literalCheckBox);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton(Messages.getString("NewRdfModelJDialog.create"));
    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            createModel(literalCheckBox);
        }
    });

    JButton cancelButton = new JButton(Messages.getString("NewRdfModelJDialog.cancel"));
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            NewRdfModelJDialog.this.dispose();
        }
    });
    framePanel.add(p);

    subjectLocalName.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                createModel(literalCheckBox);
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);

    addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            subjectLocalName.requestFocusInWindow();
        }
    });
}

From source file:gtu._work.ui.TextScanUI.java

private void initGUI() {
    try {/*from  w ww  . java2  s .c  om*/
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent evt) {
                thisComponentResized(evt);
            }
        });
        this.addWindowStateListener(new WindowStateListener() {
            public void windowStateChanged(WindowEvent evt) {
                System.out.println("this.windowStateChanged, event=" + evt);
                // TODO add your code for this.windowStateChanged
            }
        });
        this.addWindowListener(new WindowAdapter() {
            public void windowIconified(WindowEvent evt) {
                System.out.println("this.windowIconified, event=" + evt);
                // TODO add your code for this.windowIconified
            }
        });
        this.setTitle(TITLE);
        {
            jPanel1 = new JPanel();
            getContentPane().add(jPanel1, BorderLayout.NORTH);
            GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1.setPreferredSize(new java.awt.Dimension(521, 89));
            jPanel1.setBounds(0, 0, 521, 89);
            {
                jButton1 = new JButton();
                jButton1.setText("File");
                jButton1.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });
            }
            {
                jButton2 = new JButton();
                jButton2.setText("Clipboard");
                jButton2.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jButton2ActionPerformed(evt);
                    }
                });
            }
            {
                contentFilter = new JTextField();
                contentFilter.getDocument().addDocumentListener(new DocumentListener() {
                    public void insertUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField2filterAgain();
                    }

                    public void removeUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField2filterAgain();
                    }

                    public void changedUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField2filterAgain();
                    }
                });
            }
            {
                fileFilter = new JTextField();
                fileFilter.getDocument().addDocumentListener(new DocumentListener() {
                    public void insertUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField1DocumentListener(paramDocumentEvent);
                    }

                    public void removeUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField1DocumentListener(paramDocumentEvent);
                    }

                    public void changedUpdate(DocumentEvent paramDocumentEvent) {
                        jTextField1DocumentListener(paramDocumentEvent);
                    }
                });
            }
            {
                totalLabel = new JLabel();
            }
            {
                matchLabel = new JLabel();
            }
            {
                jLabel4 = new JLabel();
                jLabel4.setText("Match : ");
            }
            {
                jLabel2 = new JLabel();
                jLabel2.setText("Total : ");
            }
            {
                ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "All", "Match" });
                contextFilter = new JComboBox();
                contextFilter.setModel(jComboBox1Model);
                contextFilter.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jTextField2filterAgain();
                    }
                });
            }
            {
                ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "Regex", "find" });
                fileChk = new JComboBox();
                fileChk.setModel(jComboBox1Model);
                fileChk.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        fileChkActionPerformed(evt);
                    }
                });
            }
            {
                jScrollPane2 = new JScrollPane();
                {
                    ListModel groupListModel = new DefaultComboBoxModel();
                    groupList = new JList();
                    jScrollPane2.setViewportView(groupList);
                    groupList.setModel(groupListModel);
                    groupList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            groupListKeyPressed(evt);
                        }
                    });
                }
            }
            jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(16, 16)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                            .addComponent(jButton1, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addComponent(fileFilter, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(fileChk, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup().addGroup(jPanel1Layout
                                            .createParallelGroup(GroupLayout.Alignment.BASELINE)
                                            .addComponent(jButton2, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addComponent(contentFilter, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel4, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(contextFilter, GroupLayout.Alignment.BASELINE,
                                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE))
                                            .addComponent(matchLabel, GroupLayout.Alignment.LEADING,
                                                    GroupLayout.PREFERRED_SIZE, 24,
                                                    GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createParallelGroup()
                                    .addComponent(totalLabel, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane2, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(12, 12));
            jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(12, 12)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addComponent(contextFilter, GroupLayout.Alignment.LEADING,
                                    GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
                            .addComponent(fileChk, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    87, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addComponent(jLabel4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    45, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addComponent(matchLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    67, GroupLayout.PREFERRED_SIZE)
                            .addComponent(totalLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    67, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addComponent(contentFilter, GroupLayout.Alignment.LEADING,
                                    GroupLayout.PREFERRED_SIZE, 266, GroupLayout.PREFERRED_SIZE)
                            .addComponent(fileFilter, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    266, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup()
                            .addComponent(jButton1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    91, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    91, GroupLayout.PREFERRED_SIZE))
                    .addGap(19)
                    .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(16, 16));
        }
        {
            jScrollPane1 = new JScrollPane();
            getContentPane().add(jScrollPane1, BorderLayout.CENTER);
            jScrollPane1.setPreferredSize(new java.awt.Dimension(581, 235));
            {
                ListModel jList1Model = new DefaultComboBoxModel();
                matchList = new JList();
                jScrollPane1.setViewportView(matchList);

                // matchList.setPreferredSize(new java.awt.Dimension(575,
                // 232));// ???
                // ??
                // XXX
                // TODO
                // IMPORT
                // !!!!

                matchList.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent evt) {
                        jList1MouseClicked(evt);
                    }
                });
                matchList.setModel(jList1Model);
            }
        }
        this.setSize(697, 440);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:QueryDB.java

public QueryDBFrame() {
        setTitle("QueryDB");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        setLayout(new GridBagLayout());

        authors = new JComboBox();
        authors.setEditable(false);/* w w w  . j ava2s.co m*/
        authors.addItem("Any");

        publishers = new JComboBox();
        publishers.setEditable(false);
        publishers.addItem("Any");

        result = new JTextArea(4, 50);
        result.setEditable(false);

        priceChange = new JTextField(8);
        priceChange.setText("-5.00");

        try {
            conn = getConnection();
            Statement stat = conn.createStatement();

            String query = "SELECT Name FROM Authors";
            ResultSet rs = stat.executeQuery(query);
            while (rs.next())
                authors.addItem(rs.getString(1));
            rs.close();

            query = "SELECT Name FROM Publishers";
            rs = stat.executeQuery(query);
            while (rs.next())
                publishers.addItem(rs.getString(1));
            rs.close();
            stat.close();
        } catch (SQLException e) {
            for (Throwable t : e)
                result.append(t.getMessage());
        } catch (IOException e) {
            result.setText("" + e);
        }

        // we use the GBC convenience class of Core Java Volume 1 Chapter 9
        add(authors, new GBC(0, 0, 2, 1));

        add(publishers, new GBC(2, 0, 2, 1));

        JButton queryButton = new JButton("Query");
        queryButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                executeQuery();
            }
        });
        add(queryButton, new GBC(0, 1, 1, 1).setInsets(3));

        JButton changeButton = new JButton("Change prices");
        changeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                changePrices();
            }
        });
        add(changeButton, new GBC(2, 1, 1, 1).setInsets(3));

        add(priceChange, new GBC(3, 1, 1, 1).setFill(GBC.HORIZONTAL));

        add(new JScrollPane(result), new GBC(0, 2, 4, 1).setFill(GBC.BOTH).setWeight(100, 100));

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                try {
                    if (conn != null)
                        conn.close();
                } catch (SQLException e) {
                    for (Throwable t : e)
                        t.printStackTrace();
                }
            }
        });
    }

From source file:it.osm.gtfs.GTFSOSMImport.java

@Command(description = "Analyze the diff between osm relations and gtfs trips")
public void reldiffx() throws IOException, ParserConfigurationException, SAXException {
    final Object lock = new Object();
    final GTFSRouteDiffGui app = new GTFSRouteDiffGui();

    app.setVisible(true);//from  ww  w  .  ja v a 2s  .  co m
    app.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent arg0) {
            synchronized (lock) {
                app.setVisible(false);
                lock.notify();
            }
        }

    });

    synchronized (lock) {
        while (app.isVisible())
            try {
                lock.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }
    app.dispose();
    System.out.println("Done");
}

From source file:es.emergya.ui.gis.popups.SDSDialog.java

public SDSDialog(Recurso r) {
    super();//from  ww w.j  a va 2  s .com
    setAlwaysOnTop(true);
    setResizable(false);
    iconTransparente = LogicConstants.getIcon("48x48_transparente");
    iconEnviando = LogicConstants.getIcon("anim_enviando");
    destino = r;
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cancel.doClick();
        }
    });

    // setPreferredSize(new Dimension(400, 150));
    setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador());
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    JPanel base = new JPanel();

    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"),
            LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT);

    titleLabel.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(titleLabel);
    title.setOpaque(false);
    base.add(title);

    // Espacio para el mensaje
    sds = new JTextArea(7, 40);
    sds.setLineWrap(true);

    final JScrollPane sdsp = new JScrollPane(sds);

    sdsp.setOpaque(false);
    sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),
            i18n.getString("Admin.message") + "\t (0/" + maxChars + ")"));
    sds.setDocument(new PlainDocument() {
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= maxChars) {
                super.insertString(offs, str, a);
            }
        }
    });
    sds.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateChars(e);
        }

        private void updateChars(DocumentEvent e) {
            ((TitledBorder) sdsp.getBorder()).setTitle(
                    i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")");
            sdsp.repaint();
            send.setEnabled(!sds.getText().isEmpty());
            notification.setForeground(Color.WHITE);
            notification.setText("PLACEHOLDER");
        }
    });
    base.add(sdsp);

    // Area para mensajes
    JPanel notificationArea = new JPanel();

    notificationArea.setOpaque(false);
    notification = new JLabel("TEXT");
    notification.setForeground(Color.WHITE);
    notificationArea.add(notification);
    base.add(notificationArea);

    JPanel buttons = new JPanel();

    buttons.setOpaque(false);
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    send = new JButton(i18n.getString("Buttons.send"),
            LogicConstants.getIcon("ventanacontextual_button_enviarsds"));
    send.addActionListener(this);
    send.setEnabled(false);
    buttons.add(send);
    buttons.add(Box.createHorizontalGlue());
    progressIcon = new JLabel(iconTransparente);
    buttons.add(progressIcon);
    buttons.add(Box.createHorizontalGlue());
    cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    base.add(buttons);
    getContentPane().add(base);
    pack();

    int x;
    int y;
    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent arg0) {
            deleteErrorMessage();
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
            deleteErrorMessage();
        }

        private void deleteErrorMessage() {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    if (bandejaSalida != null) {
                        MessageGenerator.remove(bandejaSalida.getId());
                    }

                    bandejaSalida = null;

                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    SDSDialog.this.sds.setText("");
                    SDSDialog.this.sds.setEnabled(true);
                    SDSDialog.this.sds.repaint();
                    SDSDialog.this.progressIcon.setIcon(iconTransparente);
                    SDSDialog.this.progressIcon.repaint();
                    SDSDialog.this.notification.setText("");
                    SDSDialog.this.notification.repaint();
                }
            };

            sw.execute();
        }
    });
}

From source file:com.employee.scheduler.common.swingui.SolverAndPersistenceFrame.java

private void registerListeners() {
    solutionBusiness.registerForBestSolutionChanges(this);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            // This async, so it doesn't stop the solving immediately
            solutionBusiness.terminateSolvingEarly();
        }/*w  w w.j  a v  a  2  s .c  om*/
    });
}