Example usage for javax.swing JFrame addWindowListener

List of usage examples for javax.swing JFrame addWindowListener

Introduction

In this page you can find the example usage for javax.swing JFrame 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:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JFrame createJDialog(final String titulo) {
    final JFrame d = new JFrame(titulo);
    d.setResizable(false);//from   w  w w  .ja  va  2 s. c  om
    d.setAlwaysOnTop(true);
    d.setIconImage(window.getIconImage());
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    d.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(d,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    d.setLayout(new BorderLayout(5, 5));
    d.setBackground(Color.WHITE);
    d.getContentPane().setBackground(Color.WHITE);
    return d;
}

From source file:interpolation.InterpolantFileChooser.java

public InterpolantFileChooser() {

    final JFrame frame = new JFrame("Welcome to the Regression fits");

    Track = new JButton("Choose file");

    panelCont.add(panelIntro, "1");
    /* Instantiation */
    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints c = new GridBagConstraints();

    panelIntro.setLayout(layout);//from w  w w . j a  va 2s.  co m

    final Label LoadtrackText = new Label("Input the .txt file of time-series");

    LoadtrackText.setBackground(new Color(1, 0, 1));
    LoadtrackText.setForeground(new Color(255, 255, 255));
    final Checkbox Simplemode = new Checkbox("Open simple time-series file", Simplefile);
    /* Location */

    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 1.5;

    ++c.gridy;
    c.insets = new Insets(10, 10, 10, 0);
    panelIntro.add(LoadtrackText, c);

    ++c.gridy;
    c.insets = new Insets(10, 10, 10, 0);
    panelIntro.add(Track, c);

    panelIntro.setVisible(true);
    Track.addActionListener(new OpenTrackListener(frame));
    Simplemode.addItemListener(new SimpleListener(frame));
    frame.addWindowListener(new FrameListener(frame));
    frame.add(panelCont, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

}

From source file:com.diversityarrays.kdxplore.specgroup.SpecimenGroupEditor.java

public void setOwnerWindow(JFrame frame) {
    if (ownerFrame != null) {
        throw new IllegalStateException("Already have an ownerFrame");
    }/*from   w  ww.  j  ava 2  s.c  o  m*/
    ownerFrame = frame;
    if (backgroundRunner instanceof DefaultBackgroundRunner) {
        DefaultBackgroundRunner dbr = (DefaultBackgroundRunner) backgroundRunner;
        ownerFrame.setGlassPane(dbr.getBlockingPane());
    }
    title = frame.getTitle();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            setDividerLocation(0.3);
            searcher.addPropertyChangeListener(DatabaseSearcher.PROP_CLIENT_CHANGED, clientChangedListener);
        }

        @Override
        public void windowClosed(WindowEvent e) {
            searcher.removePropertyChangeListener(DatabaseSearcher.PROP_CLIENT_CHANGED, clientChangedListener);
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTabSheet.java

protected void detachTab(final int tabIndex) {
    final JComponent tabContent = (JComponent) impl.getComponentAt(tabIndex);
    TabImpl tabAtIndex = null;/*from  w  w w . j av  a  2  s.  c o  m*/
    for (TabImpl tab : tabs) {
        if (DesktopComponentsHelper.getComposition(tab.getComponent()) == tabContent) {
            tabAtIndex = tab;
            if (tab.isLazy() && !tab.isLazyInitialized()) {
                initLazyTab(tabContent);
            }
            break;
        }
    }
    if (tabAtIndex == null) {
        throw new IllegalStateException("Unable to find tab to detach");
    }
    final TabImpl tabToDetach = tabAtIndex;
    final ButtonTabComponent tabComponent = tabToDetach.getButtonTabComponent();
    final JFrame frame = new DetachedFrame(tabComponent.getCaption(), impl);

    frame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(this));
    impl.remove(tabContent);
    updateTabsEnabledState();
    frame.setSize(impl.getSize());
    frame.add(tabContent);

    final HierarchyListener listener = new HierarchyListener() {
        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags()
                    & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED
                    && !impl.isDisplayable()) {
                attachTab(frame, tabToDetach);
                impl.removeHierarchyListener(this);
            }
        }
    };

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            attachTab(frame, tabToDetach);
            impl.removeHierarchyListener(listener);
        }
    });

    impl.addHierarchyListener(listener);
    frame.setVisible(true);
}

From source file:com.isencia.passerelle.hmi.HMIBase.java

protected void showModelGraph(final String modelKey) {
    try {/* w  w  w  .j  av a 2 s  . c  o m*/
        final JFrame gf = new JFrame(HMIMessages.getString(HMIMessages.GRAPH_TITLE));
        gf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        if (graphPanelEffigy == null) {
            graphPanelEffigy = new PtolemyEffigy(getPtolemyConfiguration(), modelKey);
        }
        graphPanel = new ModelGraphPanel(currentModel, graphPanelEffigy);

        // TODO BEWARE : animation now happens in the actor
        // thread and blocks for a second!!
        // graphPanel.setAnimationDelay(1000);
        gf.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(final WindowEvent e) {
                clearModelGraphs();
            }
        });
        gf.getContentPane().add(graphPanel);
        gf.setLocation(400, 300);
        gf.setSize(700, 400);
        gf.setVisible(true);

    } catch (final Throwable t) {
        logger.error(HMIMessages.getString(HMIMessages.ERROR_GENERIC), t);
    }
}

From source file:com.jug.MoMA.java

/**
 * Initializes the MotherMachine main app. This method contains platform
 * specific code like setting icons, etc.
 *
 * @param guiFrame/*from  w w  w  .  j av  a  2  s . co m*/
 *            the JFrame containing the MotherMachine.
 */
private void initMainWindow(final JFrame guiFrame) {
    setDatasetName(datasetName);

    guiFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(final WindowEvent we) {
            saveParams();
            System.exit(0);
        }
    });

    if (!HEADLESS) {
        Image image = null;
        try {
            image = new ImageIcon(MoMA.class.getClassLoader().getResource("IconMpiCbg128.png")).getImage();
        } catch (final Exception e) {
            try {
                image = new ImageIcon(MoMA.class.getClassLoader().getResource("resources/IconMpiCbg128.png"))
                        .getImage();
            } catch (final Exception e2) {
                System.out.println(">>> Error: app icon not found...");
            }
        }

        if (image != null) {
            if (OSValidator.isMac()) {
                System.out.println("On a Mac! --> trying to set icons...");
                Application.getApplication().setDockIconImage(image);
            } else {
                System.out.println("Not a Mac! --> trying to set icons...");
                guiFrame.setIconImage(image);
            }
        }
    }
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * System Tray Icon setup/*from  w  ww  .  ja v a 2 s  .  co  m*/
 * @param frame owner JFrame
 */
private void setupTrayIcon(final JFrame frame) {

    // Idle Icon
    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png"));

    // Active Icon
    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {

        // Set Icon
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

private static void createAndShowLightGUI() {
    // Create and setup window
    final JFrame jframe = new JFrame(Constants.APP_NAME);
    int min_width = CML_OPT_WIDTH;
    int min_height = CML_OPT_HEIGHT;

    jframe.setPreferredSize(new Dimension(min_width, min_height));
    jframe.setMinimumSize(new Dimension(min_width, min_height));
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - min_width) / 2;
    int y = (screen.height - min_height) / 2;
    jframe.setBounds(x, y, min_width, min_height);

    // Action listeners
    jframe.addWindowListener(new WindowListener() {
        // Use WindowAdapter!
        @Override/*from ww w .j a  v a2  s  .  c o m*/
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
            m_web_panel.dispose();
            Runtime.getRuntime().exit(0);
        }

        @Override
        public void windowClosing(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });

    // Container
    final Container container = jframe.getContentPane();
    container.setBackground(Color.WHITE);
    container.setLayout(new BorderLayout());

    // ==== Light panel ====
    JPanel light_panel = new JPanel();
    light_panel.setBackground(Color.WHITE);
    light_panel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(2, 2, 2, 2);

    // ---- Section titles ----
    m_section_titles = null;
    if (Utilities.appLanguage().equals("de")) {
        m_section_titles = new IndexPanel(SectionTitle_DE);
    } else if (Utilities.appLanguage().equals("fr")) {
        m_section_titles = new IndexPanel(SectionTitle_FR);
    }
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 8;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(m_section_titles, gbc);
    if (m_section_titles != null)
        light_panel.add(m_section_titles, gbc);

    // ---- Fachinformation ----
    m_web_panel = new WebPanel2();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    gbc.gridheight = 20;
    gbc.weightx = 2.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.EAST;
    // --> container.add(m_web_panel, gbc);
    light_panel.add(m_web_panel, gbc);

    // ---- Add panel to main container ----
    container.add(light_panel, BorderLayout.CENTER);

    // Display window
    jframe.pack();
    // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    // jframe.setAlwaysOnTop(true);
    jframe.setVisible(true);

    // If command line options are provided start app with a particular
    // title or eancode
    if (commandLineOptionsProvided()) {
        final JToggleButton but_dummy = new JToggleButton("dummy_button");
        if (!CML_OPT_TITLE.isEmpty())
            startAppWithTitle(but_dummy);
        else if (!CML_OPT_EANCODE.isEmpty())
            startAppWithEancode(but_dummy);
        else if (!CML_OPT_REGNR.isEmpty())
            startAppWithRegnr(but_dummy);
        else if (CML_OPT_SERVER == true) {
            // Start thread that reads data from TCP server
            Thread server_thread = new Thread() {
                public void run() {
                    while (true) {
                        String tcpServerInput = "";
                        // Wait until new data is available from input stream
                        // Note: the TCP client defines the update rate!
                        // System.out.print("Waiting for input...");
                        while ((tcpServerInput = mTcpServer.getInput()).isEmpty())
                            ;
                        /*
                         * Important note: we use invokeLater to post a "job" to Swing, which will then be run on the
                         * event dispatch thread at Swing's next convenience. Failing to do so will freeze the main thread.
                         */

                        // Detect type of search (t=title, e=eancode, r=regnr)
                        char typeOfSearch = tcpServerInput.charAt(0);
                        if (typeOfSearch == 't') {
                            // Extract title from received string
                            CML_OPT_TITLE = tcpServerInput.substring(2);
                            // System.out.println(" title -> " +
                            // CML_OPT_TITLE);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithTitle(but_dummy);
                                }
                            });
                        } else if (typeOfSearch == 'e') {
                            // Extract ean code from received string
                            CML_OPT_EANCODE = tcpServerInput.substring(2);
                            // System.out.println(" eancode -> " +
                            // CML_OPT_EANCODE);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithEancode(but_dummy);
                                }
                            });
                        } else if (typeOfSearch == 'r') {
                            // Extract registration number from received
                            // string
                            CML_OPT_REGNR = tcpServerInput.substring(2);
                            // System.out.println(" regnr -> " +
                            // CML_OPT_REGNR);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithRegnr(but_dummy);
                                }
                            });
                        }
                    }
                }
            };
            server_thread.start();
        }
    }
}

From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java

private JFrame addGraphOrPlotPanel(DesktopObject dobj) {
    JFrame frame = windowOpener.addDesktopObject(dobj);
    JMenuBar mbar = new JMenuBar();
    frame.setJMenuBar(getJMenuBar());//from w  ww.j  a  v a  2 s. c om
    toolFrames.add(frame);

    frame.addWindowListener(plotTitleUncounter);

    Dimension size = this.getSize();
    size.width = Math.max(size.width / 2, 640);
    size.height = Math.max(size.height / 2, 640);
    frame.setSize(size);
    frame.setLocationRelativeTo(null);

    windowsMenuManager.addWindow(frame, dobj.getTitle());
    refreshToolAll();
    return frame;
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Bring up the PPApp demo by showing the frame (only applicable if coming up
 * as an application, not an applet);//from w ww.j  av a2  s .co  m
 */
public void showApp() {
    JFrame f = getFrame();
    f.setTitle(getTitle());
    f.getContentPane().add(this, BorderLayout.CENTER);
    f.pack();

    f.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doExit(true);
        }
    });

    UIHelper.centerWindow(f);
    Rectangle r = f.getBounds();
    int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x);
    int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y);
    int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width);
    int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height);
    boolean isMacAndMaxed = UIHelper.isMacOS()
            && AppPreferences.getLocalPrefs().getBoolean("APP.MAXIMIZED", true);
    if (isMacAndMaxed) {
        f.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else {
        UIHelper.positionAndFitToScreen(f, x, y, w, h);
    }
    f.setVisible(true);
}