Example usage for java.awt.event WindowEvent getOldState

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

Introduction

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

Prototype

public int getOldState() 

Source Link

Document

For WINDOW_STATE_CHANGED events returns the previous 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");
            }/*  ww  w .j av a  2s . com*/

            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.getOldState() == WindowEvent.WINDOW_ACTIVATED);
    super.processWindowEvent(e); // Pass on the event
}

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);//  w w  w.  ja va  2s .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);/*from   w w  w .ja v a  2  s.  c o  m*/
}

From source file:velocitekProStartAnalyzer.MainWindow.java

private void initialize() {
    JDBCPointDao jdbcPointDao = new JDBCPointDao();
    //SQLiteDB.createNewDatabase(dbName);
    jdbcPointDao.getConnection(dbName);/* ww w  .ja va 2  s  .  c  o  m*/
    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();

}