Example usage for java.awt.event WindowStateListener WindowStateListener

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

Introduction

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

Prototype

WindowStateListener

Source Link

Usage

From source file:org.parosproxy.paros.view.AbstractFrame.java

/**
 * This is the default constructor/*from   ww w  . ja v a 2 s. co  m*/
 */
public AbstractFrame(String frameName) {
    super();
    this.frameName = frameName;
    setIconImage(Res.IMAGE_LOGO);
    setVisible(false);
    setTitle(Constant.PROGRAM_NAME);
    setFont(Res.FONT_DIALOG_11);
    restoreLocationAdnSize();
    /*       
           addComponentListener(new ComponentListener() {
             public void componentShown(ComponentEvent paramComponentEvent) {
             }
                     
             public void componentResized(ComponentEvent paramComponentEvent) {
    storeLocation();
             }
                     
             public void componentMoved(ComponentEvent paramComponentEvent) {
    storeLocation();
             }
                     
             public void componentHidden(ComponentEvent paramComponentEvent) {
    System.out.println("HIDE " + AbstractFrame.this.frameName);            
             }
          });
    */

    addWindowStateListener(new WindowStateListener() {

        public void windowStateChanged(WindowEvent paramWindowEvent) {
            System.out.println("  windowStateChanged " + AbstractFrame.this.frameName);
        }
    });

    addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent paramWindowEvent) {
        }

        public void windowIconified(WindowEvent paramWindowEvent) {
        }

        public void windowDeiconified(WindowEvent paramWindowEvent) {
        }

        public void windowDeactivated(WindowEvent paramWindowEvent) {
        }

        public void windowClosed(WindowEvent paramWindowEvent) {
        }

        public void windowActivated(WindowEvent paramWindowEvent) {
        }

        public void windowClosing(WindowEvent paramWindowEvent) {
            storeLocation();
        }

    });
}

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

private void initGUI() {
    try {//  w ww. j  a v a 2 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:com.tag.FramePreferences.java

public void install() {
    windowStateListener = new WindowStateListener() {

        public void windowStateChanged(WindowEvent e) {
            Object source = e.getSource();
            if (source instanceof JFrame) {
                JFrame frame = (JFrame) source;
                int extendedState = frame.getExtendedState();
                if (extendedState == JFrame.ICONIFIED)
                    return;

                Preferences prefs = getPreferences();
                prefs.putInt(KEY_EXTENDED_STATE, extendedState);
            }//from   w ww.  j ava 2s  .  c om
        }

    };
    frame.addWindowStateListener(windowStateListener);

    componentListener = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            Preferences prefs = getPreferences();
            Dimension size = frame.getSize();
            prefs.putInt(KEY_WIDTH, size.width);
            prefs.putInt(KEY_HEIGHT, size.height);
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            Preferences prefs = getPreferences();
            Point location = frame.getLocation();
            prefs.putInt(KEY_X, location.x);
            prefs.putInt(KEY_Y, location.y);
        }

    };
    frame.addComponentListener(componentListener);
}

From source file:velocitekProStartAnalyzer.MainWindow.java

private void initialize() {
    JDBCPointDao jdbcPointDao = new JDBCPointDao();
    //SQLiteDB.createNewDatabase(dbName);
    jdbcPointDao.getConnection(dbName);/*from  w ww.j a v 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  v  a 2  s. 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:org.fhcrc.cpl.viewer.quant.gui.QuantitationReviewer.java

/**
 * Initialize all GUI components and display the UI
 *///from   w  w w .  j  a v a 2 s.  co  m
protected void initGUI() {
    settingsCLM = new ProteinQuantChartsCLM(false);

    setTitle("Qurate");
    try {
        setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewer.xml", this);
        assert null != contentPanel;
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    //Menu
    openFileAction = new OpenFileAction(this);
    createChartsAction = new CreateChartsAction();
    filterPepXMLAction = new FilterPepXMLAction(this);
    proteinSummaryAction = new ProteinSummaryAction(this);

    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewerMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    //Global stuff
    setSize(fullWidth, fullHeight);
    setContentPane(contentPanel);
    ListenerHelper helper = new ListenerHelper(this);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    leftPanel.setLayout(new GridBagLayout());
    leftPanel.setBorder(BorderFactory.createLineBorder(Color.gray));

    //Properties panel stuff
    propertiesTable = new QuantEvent.QuantEventPropertiesTable();
    propertiesScrollPane = new JScrollPane();
    propertiesScrollPane.setViewportView(propertiesTable);
    propertiesScrollPane.setMinimumSize(new Dimension(propertiesWidth, propertiesHeight));

    //event summary table; disembodied
    eventSummaryTable = new QuantEventsSummaryTable();
    eventSummaryTable.setVisible(true);
    ListSelectionModel tableSelectionModel = eventSummaryTable.getSelectionModel();
    tableSelectionModel.addListSelectionListener(new EventSummaryTableListSelectionHandler());
    JScrollPane eventSummaryScrollPane = new JScrollPane();
    eventSummaryScrollPane.setViewportView(eventSummaryTable);
    eventSummaryScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventSummaryFrame = new Frame("All Events");
    eventSummaryFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            eventSummaryFrame.setVisible(false);
        }
    });
    eventSummaryFrame.setSize(950, 450);
    eventSummaryFrame.add(eventSummaryScrollPane);

    //fields related to navigation
    navigationPanel = new JPanel();
    backButton = new JButton("<");
    backButton.setToolTipText("Previous Event");
    backButton.setMaximumSize(new Dimension(50, 30));
    backButton.setEnabled(false);
    forwardButton = new JButton(">");
    forwardButton.setToolTipText("Next Event");
    forwardButton.setMaximumSize(new Dimension(50, 30));
    forwardButton.setEnabled(false);
    showEventSummaryButton = new JButton("Show All");
    showEventSummaryButton.setToolTipText("Show all events in a table");
    showEventSummaryButton.setEnabled(false);

    helper.addListener(backButton, "buttonBack_actionPerformed");
    helper.addListener(forwardButton, "buttonForward_actionPerformed");
    helper.addListener(showEventSummaryButton, "buttonShowEventSummary_actionPerformed");

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.WEST;
    navigationPanel.add(backButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    navigationPanel.add(forwardButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    navigationPanel.add(showEventSummaryButton, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    navigationPanel.setBorder(BorderFactory.createTitledBorder("Event"));
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Fields related to curation of events
    curationPanel = new JPanel();
    curationPanel.setLayout(new GridBagLayout());
    curationPanel.setBorder(BorderFactory.createTitledBorder("Curation"));
    //Quantitation curation
    JPanel quantCurationPanel = new JPanel();
    quantCurationPanel.setLayout(new GridBagLayout());
    quantCurationPanel.setBorder(BorderFactory.createTitledBorder("Quantitation"));
    quantCurationButtonGroup = new ButtonGroup();
    JRadioButton unknownRadioButton = new JRadioButton("?");
    JRadioButton goodRadioButton = new JRadioButton("Good");
    JRadioButton badRadioButton = new JRadioButton("Bad");
    onePeakRatioRadioButton = new JRadioButton("1-Peak");

    unknownRadioButton.setEnabled(false);
    goodRadioButton.setEnabled(false);
    badRadioButton.setEnabled(false);
    onePeakRatioRadioButton.setEnabled(false);

    quantCurationButtonGroup.add(unknownRadioButton);
    quantCurationButtonGroup.add(goodRadioButton);
    quantCurationButtonGroup.add(badRadioButton);
    quantCurationButtonGroup.add(onePeakRatioRadioButton);

    unknownRadioButtonModel = unknownRadioButton.getModel();
    goodRadioButtonModel = goodRadioButton.getModel();
    badRadioButtonModel = badRadioButton.getModel();
    onePeakRadioButtonModel = onePeakRatioRadioButton.getModel();

    helper.addListener(unknownRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(goodRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(badRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(onePeakRadioButtonModel, "buttonCuration_actionPerformed");

    gbc.anchor = GridBagConstraints.WEST;
    quantCurationPanel.add(unknownRadioButton, gbc);
    quantCurationPanel.add(badRadioButton, gbc);
    quantCurationPanel.add(goodRadioButton, gbc);
    quantCurationPanel.add(onePeakRatioRadioButton, gbc);

    gbc.anchor = GridBagConstraints.PAGE_START;
    //ID curation
    JPanel idCurationPanel = new JPanel();
    idCurationPanel.setLayout(new GridBagLayout());
    idCurationPanel.setBorder(BorderFactory.createTitledBorder("ID"));
    idCurationButtonGroup = new ButtonGroup();
    JRadioButton idUnknownRadioButton = new JRadioButton("?");
    JRadioButton idGoodRadioButton = new JRadioButton("Good");
    JRadioButton idBadRadioButton = new JRadioButton("Bad");
    idUnknownRadioButton.setEnabled(false);
    idGoodRadioButton.setEnabled(false);
    idBadRadioButton.setEnabled(false);

    idCurationButtonGroup.add(idUnknownRadioButton);
    idCurationButtonGroup.add(idGoodRadioButton);
    idCurationButtonGroup.add(idBadRadioButton);
    idUnknownRadioButtonModel = idUnknownRadioButton.getModel();
    idGoodRadioButtonModel = idGoodRadioButton.getModel();
    idBadRadioButtonModel = idBadRadioButton.getModel();
    helper.addListener(idUnknownRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idGoodRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idBadRadioButton, "buttonIDCuration_actionPerformed");
    gbc.anchor = GridBagConstraints.WEST;
    idCurationPanel.add(idUnknownRadioButton, gbc);
    idCurationPanel.add(idBadRadioButton, gbc);
    idCurationPanel.add(idGoodRadioButton, gbc);

    gbc.gridwidth = GridBagConstraints.RELATIVE;
    curationPanel.add(quantCurationPanel, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    curationPanel.add(idCurationPanel, gbc);

    //curation comment
    commentTextField = new JTextField();
    commentTextField.setToolTipText("Comment on this event");
    //saves after every keypress.  Would be more efficient to save when navigating away or saving to file
    commentTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (quantEvents == null)
                return;
            QuantEvent quantEvent = quantEvents.get(displayedEventIndex);
            //save the comment, being careful about tabs and new lines
            quantEvent.setComment(commentTextField.getText().replace("\t", " ").replace("\n", " "));
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
    curationPanel.add(commentTextField, gbc);

    assessmentPanel = new JPanel();
    assessmentPanel.setLayout(new GridBagLayout());
    assessmentPanel.setBorder(BorderFactory.createTitledBorder("Algorithmic Assessment"));
    assessmentTypeTextField = new JTextField();
    assessmentTypeTextField.setEditable(false);
    assessmentPanel.add(assessmentTypeTextField, gbc);
    assessmentDescTextField = new JTextField();
    assessmentDescTextField.setEditable(false);
    assessmentPanel.add(assessmentDescTextField, gbc);

    //Theoretical peak distribution
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    theoreticalPeaksPanel = new JPanel();
    theoreticalPeaksPanel.setBorder(BorderFactory.createTitledBorder("Theoretical Peaks"));
    theoreticalPeaksPanel.setLayout(new GridBagLayout());
    theoreticalPeaksPanel.setMinimumSize(new Dimension(leftPanelWidth - 10, theoreticalPeaksPanelHeight));
    theoreticalPeaksPanel.setMaximumSize(new Dimension(1200, theoreticalPeaksPanelHeight));
    showTheoreticalPeaks();

    //Add everything to the left panel
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    leftPanel.addComponentListener(new LeftPanelResizeListener());
    gbc.weighty = 10;
    gbc.fill = GridBagConstraints.VERTICAL;
    leftPanel.add(propertiesScrollPane, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_END;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(assessmentPanel, gbc);
    leftPanel.add(theoreticalPeaksPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(curationPanel, gbc);
    leftPanel.add(navigationPanel, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Chart display
    multiChartDisplay = new TabbedMultiChartDisplayPanel();
    multiChartDisplay.setResizeDelayMS(0);

    rightPanel.addComponentListener(new RightPanelResizeListener());
    rightPanel.add(multiChartDisplay, gbc);

    //status message
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    //paranoia.  Sometimes it seems Qurate doesn't exit when you close every window
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == WindowEvent.WINDOW_CLOSED) {
                dispose();
                System.exit(0);
            }
        }
    });

}

From source file:streamme.visuals.Main.java

public void loadTray() {
    if (SystemTray.isSupported()) {
        tray = SystemTray.getSystemTray();

        PopupMenu popup = new PopupMenu();
        MenuItem exitItem = new MenuItem("Exit");
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();/*from w  w  w  . j a va2  s.c  o m*/
            }
        });

        MenuItem openItem = new MenuItem("Open");
        openItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                minimizeToTray(false);
            }
        });

        popup.add(openItem);
        popup.add(exitItem);
        trayIcon = new TrayIcon(
                Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("res/icon16.png")),
                "StreamMe", popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                if (evt.getClickCount() == 2) {
                    //minimizeToTray(false);
                    return;
                }
                if (evt.getButton() == 1) {
                    minimizeToTray(!isMinimizedToTray());
                }
            }
        });

        addWindowStateListener(new WindowStateListener() {
            public void windowStateChanged(WindowEvent e) {
                if (e.getNewState() == ICONIFIED || e.getNewState() == 7) {
                    minimizeToTray(true);
                }
            }
        });

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                minimizeToTray(true);
            }
        });
        try {
            tray.add(trayIcon);
        } catch (AWTException ex) {
            System.out.println("Error adding icon to tray");
        }
    }
}