Example usage for java.awt.event WindowEvent getNewState

List of usage examples for java.awt.event WindowEvent getNewState

Introduction

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

Prototype

public int getNewState() 

Source Link

Document

For WINDOW_STATE_CHANGED events returns the new state of the window.

Usage

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
        public void windowStateChanged(WindowEvent evt) {
            int oldState = evt.getOldState();
            int newState = evt.getNewState();

            if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) {
                System.out.println("Frame was iconized");
            } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
                System.out.println("Frame was deiconized");
            }/* w  w  w .  jav  a 2 s . c  om*/

            if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
                System.out.println("Frame was maximized");
            } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
                System.out.println("Frame was minimized");
            }
        }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
}

From source file:Main.java

protected void processWindowEvent(WindowEvent e) {
    System.out.println(e.getNewState() == WindowEvent.WINDOW_ACTIVATED);
    super.processWindowEvent(e); // Pass on the event
}

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
        @Override//from   ww w.  jav a  2  s  .  c o  m
        public Dimension getPreferredSize() {
            return new Dimension(300, 300);
        }
    };
    frame.add(panel);
    frame.addWindowStateListener(new WindowAdapter() {
        @Override
        public void windowStateChanged(WindowEvent we) {
            super.windowStateChanged(we);
            if (we.getNewState() == Frame.ICONIFIED) {
                System.out.println("Here");
            }
        }
    });
    frame.pack();
    frame.setVisible(true);
}

From source file:WindowEventDemo.java

void displayStateMessage(String prefix, WindowEvent e) {
    int state = e.getNewState();
    int oldState = e.getOldState();
    String msg = prefix + newline + space + "New state: " + convertStateToString(state) + newline + space
            + "Old state: " + convertStateToString(oldState);
    display.append(msg + newline);/*  ww w.j ava2s.  c o  m*/
    System.out.println(msg);
}

From source file:WindowEventDemo.java

private void displayStateMessage(String prefix, WindowEvent e) {
    int state = e.getNewState();
    int oldState = e.getOldState();
    String msg = prefix + newline + space + "New state: " + convertStateToString(state) + newline + space
            + "Old state: " + convertStateToString(oldState);
    displayMessage(msg);//w  w  w  .ja v  a2 s. c  om
}

From source file:velocitekProStartAnalyzer.MainWindow.java

private void initialize() {
    JDBCPointDao jdbcPointDao = new JDBCPointDao();
    //SQLiteDB.createNewDatabase(dbName);
    jdbcPointDao.getConnection(dbName);/*from www. j av a  2 s . com*/
    SQLiteDB.createNewTable(dbName);

    frame = new JFrame();
    frame.setBounds(1, 1, 1280, 720);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.getContentPane().setLayout(new BorderLayout(0, 0));
    setScrollTable(new JScrollPane());
    frame.getContentPane().add(copyrightLabel, BorderLayout.PAGE_END);
    btnPanel = new JPanel();
    frame.getContentPane().add(btnPanel, BorderLayout.NORTH);

    frame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent event) {
            boolean isMaximized = isMaximized(event.getNewState());
            boolean wasMaximized = isMaximized(event.getOldState());

            if (isMaximized && !wasMaximized) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        defaultSize();
                    }
                });
            } else if (wasMaximized && !isMaximized) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        defaultSize();
                    }
                });
            }
        }
    });

    ReadXMLFile readXmlFile = new ReadXMLFile();

    btnLoadRouteData = new JButton("Reload");
    btnPanel.add(btnLoadRouteData);
    if (getFilePath() == null) {
        btnLoadRouteData.setEnabled(false);
    }
    btnLoadRouteData.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            readXmlFile.ReadXmlFile(getFilePath());
            loadDataFromDB();
        }
    });

    btnPanel.add(btnShowFileDialogButton);

    tableContainer = new JScrollPane(pointTable);
    frame.getContentPane().add(tableContainer, BorderLayout.SOUTH);
    graphMapSplitPanel = new JSplitPane();
    tableGraphMapSplitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    graphMapSplitPanel.setResizeWeight(.5d);
    frame.getContentPane().add(tableGraphMapSplitPanel, BorderLayout.CENTER);
    JPanel dataAnalysisPanel = new JPanel();
    dataAnalysisPanel.add(dataAnalysisLabel);
    JPanel tableContainerPanel = new JPanel(new BorderLayout());
    tableContainerPanel.add(dataAnalysisPanel, BorderLayout.NORTH);
    tableContainerPanel.add(tableContainer);

    tableGraphMapSplitPanel.setTopComponent(graphMapSplitPanel);
    tableGraphMapSplitPanel.setBottomComponent(tableContainerPanel);

    graphMapSplitPanel.setLeftComponent(graphPanel);
    //mapPanel.setVisible(true);
    graphMapSplitPanel.setRightComponent(mapPanel);

    btnPanel.add(statusLabel);
    statusLabel.setVisible(true);
    //frame.add(statusLabel);

    openFile();
    loadDataFromDB();

    pointTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            if (!JDBCPointDao.points.isEmpty()) {
                getMapPanel().map().removeAllMapMarkers();
                for (int pointTableID : pointTable.getSelectedRows()) {
                    MapMarkerDot mapPoint = new MapMarkerDot(null, null,
                            (double) pointTable.getValueAt(pointTableID, 4),
                            (double) pointTable.getValueAt(pointTableID, 5));
                    if (!getMapPanel().map().getMapMarkerList().contains(mapPoint)) {
                        getMapPanel().map().addMapMarker(mapPoint);
                    }
                    // mapPanel.map().setDisplayToFitMapMarkers();
                }
                int index = 0;
                for (int pointTableID : pointTable.getSelectedRows()) {
                    index = pointTableID;
                }
                Double x = Double.valueOf(pointTable.getValueAt(index, 0).toString());
                Double y = Double.valueOf(pointTable.getValueAt(index, 3).toString());

                //int test2 = (int) pointTable.getValueAt(pointTable.getSelectedRow(), 3);

                xCrosshair.setValue(x);
                yCrosshair.setValue(y);

            }
        }

    });

    popup = new JPopupMenu();

    btnDeleteSelected = new JMenuItem("Delete Selected");
    popup.add(btnDeleteSelected);
    btnDeleteSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            deleteSelected();
            loadDataFromDB();
        }
    });

    btnDeleteAllButNotSelected = new JMenuItem("Set Selected as New Database");
    popup.add(btnDeleteAllButNotSelected);
    btnDeleteAllButNotSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            deleteAllButNotSelected();
            loadDataFromDB();
            setStartFinishMapMarkers();
        }
    });

    btnSetStartTime = new JMenuItem("Set Race Time");
    popup.add(btnSetStartTime);

    btnSetStartTime.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                JDBCPointDao.pointsOld.clear();
                JDBCPointDao.pointsOld.addAll(JDBCPointDao.points);
                setStartTime(showSetStartTimeDialog());
                loadDataFromDB();
                setEndTime(showSetEndTimeDialog());
                loadDataFromDB();
                setStartFinishMapMarkers();
            } catch (NullPointerException exception) {
                return;
            }

        }
    });

    btnSetStartFinishMapMarkers = new JMenuItem("Show Start Finish");
    popup.add(btnSetStartFinishMapMarkers);
    popup.addSeparator();
    btnSetStartFinishMapMarkers.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setStartFinishMapMarkers();
        }
    });

    btnMenuSaveSubmenu.add(btnSaveChartAsPng);
    btnSaveMapAsPng = new JMenuItem("Save Map as PNG");
    btnMenuSaveSubmenu.add(btnSaveMapAsPng);
    btnSaveTableAsPng = new JMenuItem("Save Table as PNG");
    btnMenuSaveSubmenu.add(btnSaveTableAsPng);
    btnMenuSaveSubmenu.add(btnSaveMapAsPng);
    btnMenuSaveSubmenu.addSeparator();
    btnMenuSaveSubmenu.add(btnSaveAsVCCForChart);
    if (JDBCPointDao.points.isEmpty()) {
        btnSaveAsVCC.setEnabled(false);
        btnSaveAsVCCForChart.setEnabled(false);
    }
    btnBackData = new JMenuItem("Back");
    popup.add(btnBackData);
    popup.addSeparator();

    if (JDBCPointDao.pointsOld.isEmpty()) {
        btnBackData.setEnabled(false);
    }

    JMenuItem btnResizeWindow = new JMenuItem("Resize Windows");
    popup.add(btnResizeWindow);
    popup.addSeparator();
    btnResizeWindow.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                defaultSize();
            } catch (NullPointerException exception) {
                return;
            }

        }
    });
    popup.add(btnMenuSaveSubmenu);
    popup.addSeparator();
    popup.add(btnAbout);

    btnAbout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(frame,
                    "Velocitek Prostart Analyser v.1.4 - Copyright (C) 2017 Maciej Jdrzejko"
                            + "\n\nThis program is free software: you can redistribute it and/or modify"
                            + "\nit under the terms of the GNU General Public License as published by "
                            + "\nthe Free Software Foundation, either version 3 of the License, or"
                            + "\n(at your option) any later version."
                            + "\n\nThis program is distributed in the hope that it will be useful,"
                            + "\nbut WITHOUT ANY WARRANTY; without even the implied warranty of"
                            + "\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
                            + "\nGNU General Public License for more details."
                            + "\n\nYou should have received a copy of the GNU General Public License"
                            + "\nalong with this program.  If not, see http://www.gnu.org/licenses/ ");
        }
    });

    btnResetSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            loadDataFromDB();
        }
    });

    btnMedianSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int howManyTimes = selectHowManyTimes();
            for (int i = 0; i < howManyTimes; i++) {
                int iterator = 1;
                JDBCPointDao.dataSet.removeAllSeries();
                JDBCPointDao.speedTimeSeries.clear();
                for (Double medianSpeed : dataAnalysis.getMedianForChart()) {
                    JDBCPointDao.speedTimeSeries.add(iterator, medianSpeed);
                    iterator++;
                }
                JDBCPointDao.dataSet.addSeries(JDBCPointDao.speedTimeSeries);
                createChartPanel();

            }
        }
    });

    btnAvgSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int howManyTimes = selectHowManyTimes();
            for (int i = 0; i < howManyTimes; i++) {
                int iterator = 1;
                JDBCPointDao.dataSet.removeAllSeries();
                JDBCPointDao.speedTimeSeries.clear();
                for (Double avgSpeed : dataAnalysis.getAvgSpeedForChart()) {
                    JDBCPointDao.speedTimeSeries.add(iterator, avgSpeed);
                    iterator++;
                }
                JDBCPointDao.dataSet.addSeries(JDBCPointDao.speedTimeSeries);
                createChartPanel();
            }
        }
    });

    //Add listener to components that can bring up popup menus.

    frame.addMouseListener(popupListener);
    graphMapSplitPanel.addMouseListener(popupListener);
    tableContainer.addMouseListener(popupListener);
    pointTable.addMouseListener(popupListener);
    mapPanel.addMouseListener(popupListener);
    saveMapAsPng(mapPanel);
    saveTableAsPng(tableContainer);

    saveNewVCC();
    backData();

}

From source file:at.becast.youploader.gui.FrmMain.java

/**
 * Creates new form frmMain/*from w ww .  j a  va  2s  . c o  m*/
 */
public FrmMain() {
    self = this;
    this.tos = false;
    this.setMinimumSize(new Dimension(900, 580));
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            LOG.info(Main.APP_NAME + " " + Main.VERSION + " closing.", FrmMain.class);
            Main.s.put("left", String.valueOf(getX()));
            Main.s.put("top", String.valueOf(getY()));
            Main.s.put("width", String.valueOf(getWidth()));
            Main.s.put("height", String.valueOf(getHeight()));
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            loggerContext.stop();
            e.getWindow().dispose();
        }
    });
    UploadMgr = UploadManager.getInstance();
    TemplateMgr = TemplateManager.getInstance();
    UploadMgr.setParent(this);
    String sspeed = Main.s.setting.get("speed");
    if (sspeed != null) {
        speed = Integer.parseInt(sspeed);
    } else {
        speed = 0;
    }
    initComponents();
    initMenuBar();
    loadAccounts();
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/yp.png")));
    try {
        loadQueue();
    } catch (SQLException | IOException e) {
        LOG.error("Error: ", e);
    }
    this.setVisible(true);
    if (Main.firstlaunch) {
        int n = JOptionPane.showConfirmDialog(null, LANG.getString("frmMain.initialAccount.Message"),
                LANG.getString("frmMain.initialAccount.title"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (n == JOptionPane.YES_OPTION) {
            mntmAddAccountActionPerformed();
        }
    } else {
        PlaylistUpdater pu = new PlaylistUpdater(this);
        Thread updater = new Thread(pu);
        updater.start();
        AccountUpdater au = new AccountUpdater(this);
        Thread aupdater = new Thread(au);
        aupdater.start();
    }
    EditPanel edit = (EditPanel) ss1.contentPane;
    if (edit.getCmbTemplate().getModel().getSize() > 0) {
        edit.getCmbTemplate().setSelectedIndex(0);
    }
    tray = new TrayManager(this);
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == ICONIFIED) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == 7) {
                tray.add();
                setVisible(false);
            }
            if (e.getNewState() == MAXIMIZED_BOTH) {
                tray.remove();
                setVisible(true);
            }
            if (e.getNewState() == NORMAL) {
                tray.remove();
                setVisible(true);
            }
        }
    });
}

From source file:studio.ui.Studio.java

public void windowStateChanged(WindowEvent event) {
    if (event.getID() == WindowEvent.WINDOW_STATE_CHANGED) {
        try {//w ww .  ja v  a  2 s .  c om
            studioConfig.setMaximized((event.getNewState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH);
        } catch (ConfigException ignored) {
        }
    }
}