Example usage for java.awt.event WindowAdapter WindowAdapter

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

Introduction

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

Prototype

WindowAdapter

Source Link

Usage

From source file:com.vgi.mafscaling.MafCompare.java

/**
 * Initialize the contents of the frame.
 *//*w  w  w . j a va 2 s .  c o  m*/
private void initialize() {
    try {
        ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg"));
        setTitle(Title);
        setIconImage(tableImage.getImage());
        setBounds(100, 100, 621, 372);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(Config.getCompWindowSize());
        setLocation(Config.getCompWindowLocation());
        setLocationRelativeTo(null);
        setVisible(false);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                Utils.clearTable(origMafTable);
                Utils.clearTable(newMafTable);
                Utils.clearTable(compMafTable);
                Config.setCompWindowSize(getSize());
                Config.setCompWindowLocation(getLocation());
                origMafData.clear();
                newMafData.clear();
            }
        });

        JPanel dataPanel = new JPanel();
        GridBagLayout gbl_dataPanel = new GridBagLayout();
        gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 };
        gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 };
        gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 };
        gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
        dataPanel.setLayout(gbl_dataPanel);
        getContentPane().add(dataPanel);

        JLabel origLabel = new JLabel(origMaf);
        GridBagConstraints gbc_origLabel = new GridBagConstraints();
        gbc_origLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origLabel.weightx = 0;
        gbc_origLabel.weighty = 0;
        gbc_origLabel.gridx = 0;
        gbc_origLabel.gridy = 0;
        gbc_origLabel.gridheight = 2;
        dataPanel.add(origLabel, gbc_origLabel);

        JLabel newLabel = new JLabel(newMaf);
        GridBagConstraints gbc_newLabel = new GridBagConstraints();
        gbc_newLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newLabel.weightx = 0;
        gbc_newLabel.weighty = 0;
        gbc_newLabel.gridx = 0;
        gbc_newLabel.gridy = 2;
        gbc_newLabel.gridheight = 2;
        dataPanel.add(newLabel, gbc_newLabel);

        JLabel compLabel = new JLabel("Change");
        GridBagConstraints gbc_compLabel = new GridBagConstraints();
        gbc_compLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compLabel.weightx = 0;
        gbc_compLabel.weighty = 0;
        gbc_compLabel.gridx = 0;
        gbc_compLabel.gridy = 4;
        dataPanel.add(compLabel, gbc_compLabel);

        JLabel origVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_origVoltLabel = new GridBagConstraints();
        gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origVoltLabel.weightx = 0;
        gbc_origVoltLabel.weighty = 0;
        gbc_origVoltLabel.gridx = 1;
        gbc_origVoltLabel.gridy = 0;
        dataPanel.add(origVoltLabel, gbc_origVoltLabel);

        JLabel origGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_origGsLabel = new GridBagConstraints();
        gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origGsLabel.weightx = 0;
        gbc_origGsLabel.weighty = 0;
        gbc_origGsLabel.gridx = 1;
        gbc_origGsLabel.gridy = 1;
        dataPanel.add(origGsLabel, gbc_origGsLabel);

        JLabel newVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_newVoltLabel = new GridBagConstraints();
        gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newVoltLabel.weightx = 0;
        gbc_newVoltLabel.weighty = 0;
        gbc_newVoltLabel.gridx = 1;
        gbc_newVoltLabel.gridy = 2;
        dataPanel.add(newVoltLabel, gbc_newVoltLabel);

        JLabel newGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_newGsLabel = new GridBagConstraints();
        gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newGsLabel.weightx = 0;
        gbc_newGsLabel.weighty = 0;
        gbc_newGsLabel.gridx = 1;
        gbc_newGsLabel.gridy = 3;
        dataPanel.add(newGsLabel, gbc_newGsLabel);

        JLabel compPctLabel = new JLabel(" %  ");
        GridBagConstraints gbc_compPctLabel = new GridBagConstraints();
        gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compPctLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compPctLabel.weightx = 0;
        gbc_compPctLabel.weighty = 0;
        gbc_compPctLabel.gridx = 1;
        gbc_compPctLabel.gridy = 4;
        dataPanel.add(compPctLabel, gbc_compPctLabel);

        JPanel tablesPanel = new JPanel();
        GridBagLayout gbl_tablesPanel = new GridBagLayout();
        gbl_tablesPanel.columnWidths = new int[] { 0 };
        gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 };
        gbl_tablesPanel.columnWeights = new double[] { 0.0 };
        gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 };
        tablesPanel.setLayout(gbl_tablesPanel);

        JScrollPane mafScrollPane = new JScrollPane(tablesPanel);
        mafScrollPane.setMinimumSize(new Dimension(1600, 107));
        mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20));
        mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        GridBagConstraints gbc_mafScrollPane = new GridBagConstraints();
        gbc_mafScrollPane.weightx = 1.0;
        gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START;
        gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL;
        gbc_mafScrollPane.gridx = 2;
        gbc_mafScrollPane.gridy = 0;
        gbc_mafScrollPane.gridheight = 5;
        dataPanel.add(mafScrollPane, gbc_mafScrollPane);

        origMafTable = new JTable();
        origMafTable.setColumnSelectionAllowed(true);
        origMafTable.setCellSelectionEnabled(true);
        origMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        origMafTable.setRowHeight(RowHeight);
        origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        origMafTable.setTableHeader(null);
        Utils.initializeTable(origMafTable, ColumnWidth);
        GridBagConstraints gbc_origMafTable = new GridBagConstraints();
        gbc_origMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_origMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_origMafTable.weightx = 1.0;
        gbc_origMafTable.weighty = 0;
        gbc_origMafTable.gridx = 0;
        gbc_origMafTable.gridy = 0;
        tablesPanel.add(origMafTable, gbc_origMafTable);
        excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true);

        newMafTable = new JTable();
        newMafTable.setColumnSelectionAllowed(true);
        newMafTable.setCellSelectionEnabled(true);
        newMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        newMafTable.setRowHeight(RowHeight);
        newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        newMafTable.setTableHeader(null);
        Utils.initializeTable(newMafTable, ColumnWidth);
        GridBagConstraints gbc_newMafTable = new GridBagConstraints();
        gbc_newMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_newMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_newMafTable.weightx = 1.0;
        gbc_newMafTable.weighty = 0;
        gbc_newMafTable.gridx = 0;
        gbc_newMafTable.gridy = 1;
        tablesPanel.add(newMafTable, gbc_newMafTable);
        excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true);

        compMafTable = new JTable();
        compMafTable.setColumnSelectionAllowed(true);
        compMafTable.setCellSelectionEnabled(true);
        compMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        compMafTable.setRowHeight(RowHeight);
        compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount));
        compMafTable.setTableHeader(null);
        Utils.initializeTable(compMafTable, ColumnWidth);
        NumberFormatRenderer numericRenderer = new NumberFormatRenderer();
        numericRenderer.setFormatter(new DecimalFormat("0.000"));
        compMafTable.setDefaultRenderer(Object.class, numericRenderer);
        GridBagConstraints gbc_compMafTable = new GridBagConstraints();
        gbc_compMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_compMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_compMafTable.weightx = 1.0;
        gbc_compMafTable.weighty = 0;
        gbc_compMafTable.gridx = 0;
        gbc_compMafTable.gridy = 2;
        tablesPanel.add(compMafTable, gbc_compMafTable);
        compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true);

        TableModelListener origTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = origMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, newMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    origMafData.clear();
                    String origY, origX, newY;
                    for (int i = 0; i < colCount; ++i) {
                        origY = origMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, origY)) {
                            origX = origMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origX))
                                origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false);
                            newY = newMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    origMafData.fireSeriesChanged();
                }
            }
        };

        TableModelListener newTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = newMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, origMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    newMafData.clear();
                    String newY, newX, origY;
                    for (int i = 0; i < colCount; ++i) {
                        newY = newMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, newY)) {
                            newX = newMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newX))
                                newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false);
                            origY = origMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    newMafData.fireSeriesChanged();
                }
            }
        };

        origMafTable.getModel().addTableModelListener(origTableListener);
        newMafTable.getModel().addTableModelListener(newTableListener);

        Action action = new AbstractAction() {
            private static final long serialVersionUID = 8148393537657380215L;

            public void actionPerformed(ActionEvent e) {
                TableCellListener tcl = (TableCellListener) e.getSource();
                if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) {
                    if (Pattern.matches(Utils.fpRegex,
                            origMafTable.getValueAt(1, tcl.getColumn()).toString())) {
                        double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString())
                                / 100.0 + 1.0;
                        newMafTable.setValueAt(
                                Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr,
                                1, tcl.getColumn());
                    }
                } else
                    compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn());
            }
        };

        setCompMafCellListener(new TableCellListener(compMafTable, action));

        // CHART

        JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL,
                false, true, false);
        chart.setBorderVisible(true);
        chartPanel = new ChartPanel(chart, true, true, true, true, true);
        chartPanel.setAutoscrolls(true);

        GridBagConstraints gbl_chartPanel = new GridBagConstraints();
        gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
        gbl_chartPanel.fill = GridBagConstraints.BOTH;
        gbl_chartPanel.insets = new Insets(1, 1, 1, 1);
        gbl_chartPanel.weightx = 1.0;
        gbl_chartPanel.weighty = 1.0;
        gbl_chartPanel.gridx = 0;
        gbl_chartPanel.gridy = 5;
        gbl_chartPanel.gridheight = 1;
        gbl_chartPanel.gridwidth = 3;
        dataPanel.add(chartPanel, gbl_chartPanel);

        XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
        lineRenderer.setUseFillPaint(true);
        lineRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new DecimalFormat("0.00"), new DecimalFormat("0.00")));

        Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
        lineRenderer.setSeriesStroke(0, stroke);
        lineRenderer.setSeriesStroke(1, stroke);
        lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
        lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
        lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
        lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5));
        lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
            private static final long serialVersionUID = -4045338273187150888L;

            public String generateLabel(XYDataset dataset, int series) {
                XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
                return xys.getDescription();
            }
        });

        NumberAxis mafvDomain = new NumberAxis(XAxisName);
        mafvDomain.setAutoRangeIncludesZero(false);
        mafvDomain.setAutoRange(true);
        mafvDomain.setAutoRangeStickyZero(false);
        NumberAxis mafgsRange = new NumberAxis(YAxisName);
        mafgsRange.setAutoRangeIncludesZero(false);
        mafgsRange.setAutoRange(true);
        mafgsRange.setAutoRangeStickyZero(false);

        XYSeriesCollection lineDataset = new XYSeriesCollection();
        origMafData.setDescription(origMaf);
        newMafData.setDescription(newMaf);
        lineDataset.addSeries(origMafData);
        lineDataset.addSeries(newMafData);

        XYPlot plot = chart.getXYPlot();
        plot.setRangePannable(true);
        plot.setDomainPannable(true);
        plot.setDomainGridlinePaint(Color.DARK_GRAY);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setBackgroundPaint(new Color(224, 224, 224));

        plot.setDataset(0, lineDataset);
        plot.setRenderer(0, lineRenderer);
        plot.setDomainAxis(0, mafvDomain);
        plot.setRangeAxis(0, mafgsRange);
        plot.mapDatasetToDomainAxis(0, 0);
        plot.mapDatasetToRangeAxis(0, 0);

        LegendTitle legend = new LegendTitle(plot.getRenderer());
        legend.setItemFont(new Font("Arial", 0, 10));
        legend.setPosition(RectangleEdge.TOP);
        chart.addLegend(legend);

    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:search2go.UIFrame.java

public UIFrame() throws IOException, ParseException {
    topLevels = new TopLevelGTermSet[] { CCs, MFs, BPs };

    this.addWindowListener(new WindowAdapter() {
        @Override/*from  w ww. j a v a 2s  .  c  o m*/
        public void windowClosing(WindowEvent et) {
            try {
                if (os.isWindows()) {
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastx.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastn.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastp.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM python.exe -F");
                } else {
                    Runtime.getRuntime().exec("killAll -KILL blastx");
                    Runtime.getRuntime().exec("killAll -KILL blastn");
                    Runtime.getRuntime().exec("killAll -KILL blastp");
                    Runtime.getRuntime().exec("killAll -KILL python");
                }
            } catch (IOException ex) {
                System.out.println("Error closing child processes");
            }
        }
    });

    initComponents();

    txtBlastOutput.getDocument().addDocumentListener(new BufferEnforcer(txtBlastOutput));
    txtFullOutput.getDocument().addDocumentListener(new BufferEnforcer(txtFullOutput));
    txtMapOutput.getDocument().addDocumentListener(new BufferEnforcer(txtMapOutput));

    ((DefaultCaret) txtBlastOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ((DefaultCaret) txtMapOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ((DefaultCaret) txtFullOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    webSaveMenu = new JPopupMenu();
    JMenuItem saveWeb = new JMenuItem();
    saveWeb.setText("Save");
    saveWeb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            webSaveDialogue.showSaveDialog(pnlChartHolder);
            File saveFile = webSaveDialogue.getSelectedFile();
            if (!saveFile.getPath().contains(".png"))
                saveFile = new File(saveFile.getPath() + ".png");
            try {
                BufferedImage webChartImage = new BufferedImage(pnlChartHolder.getWidth(),
                        pnlChartHolder.getHeight(), BufferedImage.TYPE_INT_RGB);
                pnlChartHolder.print(webChartImage.getGraphics());
                ImageIO.write(webChartImage, "png", saveFile);
            } catch (Exception ex) {
                javax.swing.JOptionPane.showMessageDialog(pnlChartHolder,
                        "Error saving chart. Please try again.");
            }
        }

    });
    webSaveMenu.add(saveWeb);
    pnlChartHolder.add(webSaveMenu);
    pnlChartHolder.setLayout(new java.awt.BorderLayout());

    try {
        currentProj = Workspace.open(new Path("Search2GO_Data"));
        chkDoCCs.setState(currentProj.willDoCC());
        chkDoBPs.setState(currentProj.willDoBP());
        chkDoMFs.setState(currentProj.willDoMF());
        txtQuery.setText(currentProj.getQueryPath());
        txtQueryFP.setText(currentProj.getQueryPath());
        txtDatabase.setText(currentProj.getPathToDB());
        txtDatabaseFP.setText(currentProj.getPathToDB());
        txtThreads.setValue(currentProj.getThreadNo());
        txtThreadsFP.setValue(currentProj.getThreadNo());
        cbxNXP.setSelectedIndex(currentProj.getBlastTypeIndex());
        cbxNXPFP.setSelectedIndex(currentProj.getBlastTypeIndex());
        cbxDBID.setSelectedIndex(currentProj.getSelectedDBIndex());
        cbxDBIDFP.setSelectedIndex(currentProj.getSelectedDBIndex());
        txtBitScore.setValue(currentProj.getBitScoreThreshold());
        txtBitScoreFP.setValue(currentProj.getBitScoreThreshold());
        txtBlastE.setValue(currentProj.getEThreshold());
        txtMapE.setValue(currentProj.getEThreshold());
        txtEFP.setValue(currentProj.getEThreshold());
    } catch (FileNotFoundException e) {
        currentProj = Workspace.create(new Path("Search2GO_Data"));
        chkDoCCs.setState(currentProj.willDoCC());
        chkDoBPs.setState(currentProj.willDoBP());
        chkDoMFs.setState(currentProj.willDoMF());
    }
    this.setTitle("Search2GO " + currentProj.getPath().toString());

    GTermTableModel = new DefaultTableModel();
    GTermTableModel.setColumnCount(2);
    GTermTableModel.setColumnIdentifiers(new String[] { "GO ID", "Frequency" });

    ListSelectionModel GTermSelector = tblGOFreq.getSelectionModel();
    GTermSelector.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (tblGOFreq.getSelectedRow() > -1) {
                    DefaultListModel emptyModel = new DefaultListModel();
                    lstQueries.setModel(emptyModel);
                    txtTermInfo.setText("");
                    String selectedID = (String) tblGOFreq.getValueAt(tblGOFreq.getSelectedRow(), 0);
                    JTextArea tempHolderInfo = new JTextArea();
                    JTextArea tempHolderQueries = new JTextArea();

                    if (tblGOFreq.getSelectedRow() != -1) {
                        ResetGTermInfoGetter(tempHolderInfo, tempHolderQueries);
                        gTermInfoGetter.getProcess(0).addParameter("id",
                                selectedID.substring(0, selectedID.indexOf("[")));
                        gTermInfoGetter.getProcess(1).addParameter("id",
                                selectedID.substring(0, selectedID.indexOf("[")));
                        GTerm currentGTerm = gTerms.getGTerm(selectedID.substring(0, selectedID.indexOf("[")));
                        gTermInfoGetter.getProcess(1).addParameter("db", currentGTerm.getTopLevel().getCode());
                        gTermInfoGetter.setTail(new ProcessSequenceEnd() {
                            @Override
                            public void run() {
                                tempHolderInfo.setText("id: " + selectedID + "\n" + tempHolderInfo.getText());
                                txtTermInfo.setText(tempHolderInfo.getText());

                                DefaultListModel queryList = new DefaultListModel();
                                for (String str : tempHolderQueries.getText().split(";")) {
                                    queryList.addElement(str.replaceAll("Query: ", ""));
                                }

                                lstQueries.setModel(queryList);
                                prgIdentification.setIndeterminate(false);
                            }
                        });
                        try {
                            gTermInfoGetter.start();
                            prgIdentification.setIndeterminate(true);
                        } catch (IOException ex) {
                            Logger.getLogger(UIFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
        }
    });

    lstQueries.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && !e.toString().contains("invalid")
                    && lstQueries.getSelectedValue() != null) {
                JTextArea tempHolder = new JTextArea();

                ProcessSequence fetchLocusSequence = new ProcessSequence(new ProcessSequenceEnd() {
                    @Override
                    public void run() {
                        if (txtTermInfo.getText().contains("Score")) {
                            txtTermInfo.setText(
                                    txtTermInfo.getText().substring(0, txtTermInfo.getText().indexOf("Score")));
                        }
                        txtTermInfo.append(tempHolder.getText());
                        prgIdentification.setIndeterminate(false);
                    }
                });
                Path fetchLocusPath = new Path("Processes");
                fetchLocusPath.append("fetchLocus.py");
                Process fetchLocus = new Process(tempHolder);
                fetchLocus.setScriptCommand(fetchLocusPath.toEscString());
                fetchLocus.addParameter("dir", currentProj.getPath().toEscString());
                fetchLocus.addParameter("q",
                        new ParameterString(lstQueries.getSelectedValue().replace("\n", "")).toString());

                String selectedID = (String) tblGOFreq.getValueAt(tblGOFreq.getSelectedRow(), 0);
                GTerm currentGTerm = gTerms.getGTerm(selectedID.substring(0, selectedID.indexOf("[")));
                fetchLocus.addParameter("db", currentGTerm.getTopLevel().getCode());
                fetchLocus.addParameter("id", currentGTerm.getID());
                fetchLocusSequence.addProcess(fetchLocus);

                try {
                    fetchLocusSequence.start();
                    prgIdentification.setIndeterminate(true);
                } catch (IOException ex) {
                    Logger.getLogger(UIFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

    DocumentListener filterListener = new DocumentListener() {
        private void anyUpdate() {
            gTerms.getFilter().setFilterString(txtSearchTerms.getText());
            if (!txtMinFreqFilter.getText().equals(""))
                gTerms.getFilter().setMinFreq(Integer.parseInt(txtMinFreqFilter.getText()));
            else
                gTerms.getFilter().setMinFreq(0);
            if (!txtMaxFreqFilter.getText().equals(""))
                gTerms.getFilter().setMaxFreq(Integer.parseInt(txtMaxFreqFilter.getText()));
            else
                gTerms.getFilter().setMaxFreq(-1);
            fillIdentTable(gTerms.stringFilter(), false);
        }

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

        @Override
        public void removeUpdate(DocumentEvent e) {
            anyUpdate();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            anyUpdate();
        }
    };
    txtSearchTerms.getDocument().addDocumentListener(filterListener);
    txtMinFreqFilter.getDocument().addDocumentListener(filterListener);
    txtMaxFreqFilter.getDocument().addDocumentListener(filterListener);

    NumberFormat numberMask = NumberFormat.getIntegerInstance();
    numberMask.setGroupingUsed(false);
    NumberFormatter numberMasker = new NumberFormatter(numberMask);
    NumberFormatter numberMaskerAndBlank = new NumberFormatter(numberMask) {
        @Override
        public Object stringToValue(String s) throws ParseException {
            if (s == null || s.length() == 0)
                return null;
            return super.stringToValue(s);
        }
    };
    DefaultFormatterFactory numberMaskFactory = new DefaultFormatterFactory(numberMasker);
    DefaultFormatterFactory numberMaskAndBlankFactory = new DefaultFormatterFactory(numberMaskerAndBlank);

    txtThreads.setFormatterFactory(numberMaskFactory);
    txtThreadsFP.setFormatterFactory(numberMaskFactory);
    txtBitScore.setFormatterFactory(numberMaskAndBlankFactory);
    txtBitScoreFP.setFormatterFactory(numberMaskAndBlankFactory);
    txtMinFreqFilter.setFormatterFactory(numberMaskFactory);
    txtMaxFreqFilter.setFormatterFactory(numberMaskFactory);
    txtBlastE.setFormatterFactory(numberMaskAndBlankFactory);
    txtMapE.setFormatterFactory(numberMaskAndBlankFactory);
    txtEFP.setFormatterFactory(numberMaskAndBlankFactory);

    blastButton = new StopButton(btnBlast);
    mapButton = new StopButton(btnMapIDs);
    identButton = new StopButton(btnGTermIdent);
    fullButton = new StopButton(btnProcessFP);

    if (currentProj.getStage() >= 2)
        identify(false);
}

From source file:econtroller.gui.ControllerGUI.java

private void addWindowListener() {
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0); //
        }/*from  www  .j a v a  2s.c  o m*/
    });
}

From source file:com.lfv.lanzius.server.WorkspaceView.java

/**
 * Set up the ISA chart/*w  ww. ja v  a  2 s .  co m*/
 * @param selectionList selected terminals
 */
public void initIsaChart() {
    if (isaChart == null) {
        // Create a chart:
        isaChart = new ZoomableChart();
    }

    if (isaFrame == null) {
        // Make it visible:
        // Create a frame.
        isaFrame = new JFrame("ISADynamicChart");
        // add the chart to the frame:
        isaChart.getAxisY().setPaintGrid(true);
        isaChart.setGridColor(Color.LIGHT_GRAY);
        isaChart.getAxisX().setRangePolicy(new RangePolicyHighestValues());
        if (server.getIsaExtendedMode()) {
            isaChart.getAxisY().setRangePolicy(new RangePolicyFixedViewport(new Range(0, 9)));
        } else {
            isaChart.getAxisY().setRangePolicy(new RangePolicyFixedViewport(new Range(0, 5)));
        }
        isaChart.getAxisX().setAxisTitle(new AxisTitle("Time (minutes)"));
        isaChart.getAxisY().setAxisTitle(new AxisTitle("ISA value"));

        isaFrame.getContentPane().add(isaChart);

        // Add popup menues to the pane
        isaFrame.getContentPane().add(new ChartPanel(isaChart));

        if (server.getIsaExtendedMode()) {
            isaFrame.setSize(1000, 300);
        } else {
            isaFrame.setSize(1000, 205);
        }
        isaFrame.setAlwaysOnTop(true);
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle rect = graphicsEnvironment.getMaximumWindowBounds();
        isaFrame.setLocation(rect.width - 1020, rect.height - 370);
        // Enable the termination button [cross on the upper right edge]:
        isaFrame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                panel.updateButtons(false, null);
            }
        });
        server.setIsaStartTime(System.currentTimeMillis());
    }
    isaFrame.setVisible(true);
}

From source file:aurelienribon.gdxsetupui.ui.MainPanel.java

public MainPanel() {
    SwingUtils.importFont(Res.getStream("fonts/SquareFont.ttf"));
    setLayout(new BorderLayout());
    add(rootPanel, BorderLayout.CENTER);

    HttpUtils.setReferer("http://aurelienribon-dev.com/gdx-setup-ui");

    versionLabel.initAndCheck("3.0.0", "versions",
            "https://raw.github.com/libgdx/libgdx/master/extensions/gdx-setup-ui/config/config.txt",
            "https://github.com/AurelienRibon/gdx-setup-ui/downloads");

    initUI();//ww  w. j  a v  a2 s  .c o m
    initLibgdx();
    initStyle();
    initConfigurations();
    rootPanel.initialize(initCfg);

    SLAnimator.start();
    rootPanel.setTweenManager(SLAnimator.createTweenManager());
    taskPanel.setTweenManager(SLAnimator.createTweenManager());

    if (Ctx.testLibUrl != null)
        Ctx.libs.addUrl("__test_url__", Ctx.testLibUrl);
    if (Ctx.testLibDef != null)
        Ctx.libs.addDef("__test_def__", Ctx.testLibDef);
    if (Ctx.testLibDef != null)
        librarySelectionPanel.rebuildLibraries();

    SwingUtils.addWindowListener(this, new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            DownloadTask task = Ctx.libs.downloadConfigFile();
            task.addListener(configFileDownloadListener);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            Ctx.libs.cleanUpDownloads();
        }
    });
}

From source file:net.java.sip.communicator.impl.osdependent.jdic.TrayMenuFactory.java

/**
 * Creates a tray menu for the given system tray.
 *
 * @param tray the system tray for which we're creating a menu
 * @param swing indicates if we should create a Swing or an AWT menu
 * @return a tray menu for the given system tray (first) and the default
 *         menu item (second)/*w  w w.j a  v  a2  s  . c  o  m*/
 */
public static Pair<Object, Object> createTrayMenu(SystrayServiceJdicImpl tray, boolean swing,
        boolean accountMenuSupported) {
    final Object trayMenu = swing ? new JPopupMenu() : new PopupMenu();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            TrayMenuFactory.actionPerformed(event);
        }
    };

    Boolean showOptions = OsDependentActivator.getConfigurationService()
            .getBoolean("net.java.sip.communicator.impl.gui.main.configforms." + "SHOW_OPTIONS_WINDOW", true);

    if (showOptions.booleanValue()) {
        add(trayMenu,
                createTrayMenuItem("settings",
                        (OSUtils.IS_MAC) ? "service.gui.PREFERENCES" : "service.gui.SETTINGS",
                        "service.systray.CONFIGURE_ICON", listener, swing));
    }

    add(trayMenu, createTrayMenuItem("addContact", "service.gui.ADD_CONTACT",
            "service.gui.icons.ADD_CONTACT_16x16_ICON", listener, swing));
    addSeparator(trayMenu);

    Boolean chatPresenceDisabled = OsDependentActivator.getConfigurationService()
            .getBoolean("net.java.sip.communicator.impl.gui.main.presence." + "CHAT_PRESENCE_DISABLED", false);

    if (!chatPresenceDisabled.booleanValue() && accountMenuSupported) {
        add(trayMenu, new StatusSubMenu(swing, accountMenuSupported).getMenu());
        addSeparator(trayMenu);
    }

    String showHideName;
    String showHideTextId;
    String showHideIconId;

    if (OsDependentActivator.getUIService().isVisible()) {
        showHideName = "service.gui.HIDE";
        showHideTextId = "service.gui.HIDE";
        showHideIconId = "service.gui.icons.SEARCH_ICON_16x16";
    } else {
        showHideName = "service.gui.SHOW";
        showHideTextId = "service.gui.SHOW";
        showHideIconId = "service.gui.icons.SEARCH_ICON_16x16";
    }

    final Object showHideMenuItem = createTrayMenuItem(showHideName, showHideTextId, showHideIconId, listener,
            swing);

    add(trayMenu, showHideMenuItem);

    add(trayMenu, createTrayMenuItem("service.gui.QUIT", "service.gui.QUIT", "service.systray.QUIT_MENU_ICON",
            listener, swing));

    OsDependentActivator.getUIService().addWindowListener(new WindowAdapter() {
        /**
         * Invoked when a window is activated.
         */
        @Override
        public void windowActivated(WindowEvent e) {
            changeTrayMenuItem(showHideMenuItem, "service.gui.HIDE", "service.gui.HIDE",
                    "service.gui.icons.SEARCH_ICON_16x16");
        }

        /**
         * Invoked when a window is de-activated.
         */
        @Override
        public void windowDeactivated(WindowEvent e) {
            changeTrayMenuItem(showHideMenuItem, "service.gui.SHOW", "service.gui.SHOW",
                    "service.gui.icons.SEARCH_ICON_16x16");
        }
    });

    return Pair.of(trayMenu, showHideMenuItem);
}

From source file:com.diversityarrays.update.UpdateDialog.java

public UpdateDialog(UpdateCheckRequest updateCheckRequest, UpdateCheckContext ctx, long exp_ms) {
    super(updateCheckRequest.owner, Msg.TITLE_UPDATE_CHECK(), ModalityType.APPLICATION_MODAL);

    this.updateCheckRequest = updateCheckRequest;
    this.updateCheckContext = ctx;

    setKDXploreUpdate(null);// www . j  ava2  s  .c  om
    installUpdateAction.setEnabled(false);

    cardPanel.setBorder(new EmptyBorder(20, 20, 20, 20));

    progressBar.setIndeterminate(true);
    cardPanel.add(progressBar, CARD_PROGRESS);
    if (exp_ms > 0) {
        daysToGo = 1 + ChronoUnit.DAYS.between(new Date().toInstant(), new Date(exp_ms).toInstant());
        JPanel tmp = new JPanel(new BorderLayout());
        tmp.add(new JLabel(Msg.HTML_THIS_VERSION_EXPIRES_IN_N_DAYS((int) daysToGo)), BorderLayout.NORTH);
        tmp.add(messageLabel, BorderLayout.CENTER);
        cardPanel.add(tmp, CARD_MESSAGE);
    } else {
        daysToGo = 0;
        cardPanel.add(messageLabel, CARD_MESSAGE);
    }

    cardLayout.show(cardPanel, CARD_PROGRESS);

    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(closeAction));
    buttons.add(new JButton(moreAction));
    if (RunMode.getRunMode().isDeveloper()) {
        buttons.add(new JButton(installUpdateAction));
    }
    buttons.add(Box.createHorizontalGlue());
    buttons.add(backupDatabaseButton);
    backupDatabaseButton.setVisible(false);
    backupDatabaseAction.setEnabled(updateCheckContext.canBackupDatabase());

    Container cp = getContentPane();

    cp.add(buttons, BorderLayout.SOUTH);
    cp.add(cardPanel, BorderLayout.CENTER);

    pack();

    GuiUtil.centreOnOwner(this);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            removeWindowListener(this);
            checkForUpdates(updateCheckContext.getPrintStream());
        }
    });
}

From source file:com.vgi.mafscaling.LogPlay.java

private void initialize() {
    lastRow = logDataTable.getRowCount() - 1;
    playNext = new AtomicInteger(1);
    playIcon = new ImageIcon(getClass().getResource("/play.png"));
    pauseIcon = new ImageIcon(getClass().getResource("/pause.png"));
    zeroInsets.put("Button.contentMargins", insets0);
    timer = new Timer(timerDelay, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            progressBar.setValue(progressBar.getValue() + playNext.get());
        }//w  ww.j  a  va  2  s . co  m
    });

    JPanel dataPanel = new JPanel();
    GridBagLayout gbl_dataPanel = new GridBagLayout();
    gbl_dataPanel.columnWidths = new int[] { 0 };
    gbl_dataPanel.rowHeights = new int[] { 0, 1 };
    gbl_dataPanel.columnWeights = new double[] { 1.0 };
    gbl_dataPanel.rowWeights = new double[] { 0.0, 1.0 };
    dataPanel.setLayout(gbl_dataPanel);
    getContentPane().add(dataPanel);

    createSelectionPanel(dataPanel);
    createPlayer(dataPanel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            timer.stop();
            synchronized (lock) {
                for (TableHolder t : tables)
                    t.table.dispose();
                tables.clear();
            }
            logView.disposeLogView();
        }
    });

    pack();
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setIconImage((new ImageIcon(getClass().getResource("/player.png"))).getImage());
    setResizable(false);
    setLocationRelativeTo(SwingUtilities.windowForComponent(logView));
    setVisible(true);
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateImportDialog.java

public CodeTemplateImportDialog(Frame owner, List<CodeTemplateLibrary> importLibraries,
        boolean unassignedCodeTemplates, boolean showCancelAlert) {
    super(owner, "Import Code Templates / Libraries", true);
    this.importLibraries = importLibraries;
    this.unassignedCodeTemplates = unassignedCodeTemplates;
    this.showCancelAlert = showCancelAlert;

    importLibraryMap = new HashMap<String, CodeTemplateLibrary>();
    importCodeTemplateMap = new HashMap<String, CodeTemplate>();

    initComponents();/*from   ww w  . ja  v  a 2s .co m*/
    initLayout();

    if (showCancelAlert) {
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent evt) {
                if (confirmClose()) {
                    dispose();
                }
            }
        });

        ActionListener closeAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (confirmClose()) {
                    dispose();
                }
            }
        };

        getRootPane().registerKeyboardAction(closeAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);
    } else {
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    updateErrorsAndWarnings();

    setPreferredSize(new Dimension(420, 420));
    pack();
    setLocationRelativeTo(owner);
    setResizable(false);
    setVisible(true);
}

From source file:EditorPaneExample12.java

public static void main(String[] args) {
    try {/*  w w w.j  a  v a 2 s.  c  o m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    JFrame f = new EditorPaneExample12();

    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);
        }
    });
    f.setSize(500, 400);
    f.setVisible(true);
}