Example usage for javax.swing JProgressBar JProgressBar

List of usage examples for javax.swing JProgressBar JProgressBar

Introduction

In this page you can find the example usage for javax.swing JProgressBar JProgressBar.

Prototype

public JProgressBar() 

Source Link

Document

Creates a horizontal progress bar that displays a border but no progress string.

Usage

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Initializes the visible components in this dialog.
 *///from www .  j a  v a  2 s .  c  om
private void initComponents() {

    this.addComponentListener(dialogPositionListener);
    /* Interrupts the searchThread by setting the State-Array to 0 */
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            threadState.set(false);
        }
    });

    panelDirectory = new JPanel();
    panelSearchArea = new JPanel();
    panelFiles = new JPanel();
    panelOptions = new JPanel();
    panelEntryTypesSelection = new JPanel();
    panelButtons = new JPanel();
    panelImportArea = new JPanel();

    buttonBrowse = new JButton(Localization.lang("Browse"));
    buttonBrowse.setMnemonic('B');
    buttonBrowse.setToolTipText(Localization.lang("Opens the file browser."));
    buttonScan = new JButton(Localization.lang("Scan directory"));
    buttonScan.setMnemonic('S');
    buttonScan.setToolTipText(Localization.lang("Searches the selected directory for unlinked files."));
    buttonApply = new JButton(Localization.lang("Apply"));
    buttonApply.setMnemonic('I');
    buttonApply.setToolTipText(Localization.lang("Starts the import of BibTeX entries."));
    buttonClose = new JButton(Localization.lang("Close"));
    buttonClose.setToolTipText(Localization.lang("Leave this dialog."));
    buttonClose.setMnemonic('C');

    /* Options for the TreeView */
    buttonOptionSelectAll = new JButton();
    buttonOptionSelectAll.setMnemonic('A');
    buttonOptionSelectAll.setAction(actionSelectAll);
    buttonOptionUnselectAll = new JButton();
    buttonOptionUnselectAll.setMnemonic('U');
    buttonOptionUnselectAll.setAction(actionUnselectAll);
    buttonOptionExpandAll = new JButton();
    buttonOptionExpandAll.setMnemonic('E');
    buttonOptionExpandAll.setAction(actionExpandTree);
    buttonOptionCollapseAll = new JButton();
    buttonOptionCollapseAll.setMnemonic('L');
    buttonOptionCollapseAll.setAction(actionCollapseTree);

    checkboxCreateKeywords = new JCheckBox(Localization.lang("Create directory based keywords"));
    checkboxCreateKeywords
            .setToolTipText(Localization.lang("Creates keywords in created entrys with directory pathnames"));
    checkboxCreateKeywords.setSelected(checkBoxWhyIsThereNoGetSelectedStupidSwing);
    checkboxCreateKeywords.addItemListener(
            e -> checkBoxWhyIsThereNoGetSelectedStupidSwing = !checkBoxWhyIsThereNoGetSelectedStupidSwing);

    textfieldDirectoryPath = new JTextField();
    textfieldDirectoryPath
            .setText(lastSelectedDirectory == null ? "" : lastSelectedDirectory.toAbsolutePath().toString());

    labelDirectoryDescription = new JLabel(
            Localization.lang("Select a directory where the search shall start."));
    labelFileTypesDescription = new JLabel(Localization.lang("Select file type:"));
    labelFilesDescription = new JLabel(Localization.lang("These files are not linked in the active database."));
    labelEntryTypeDescription = new JLabel(Localization.lang("Entry type to be created:"));
    labelSearchingDirectoryInfo = new JLabel(Localization.lang("Searching file system..."));
    labelSearchingDirectoryInfo.setHorizontalAlignment(JTextField.CENTER);
    labelSearchingDirectoryInfo.setVisible(false);
    labelImportingInfo = new JLabel(Localization.lang("Importing into Database..."));
    labelImportingInfo.setHorizontalAlignment(JTextField.CENTER);
    labelImportingInfo.setVisible(false);

    tree = new JTree();
    scrollpaneTree = new JScrollPane(tree);
    scrollpaneTree.setWheelScrollingEnabled(true);

    progressBarSearching = new JProgressBar();
    progressBarSearching.setIndeterminate(true);
    progressBarSearching.setVisible(false);
    progressBarSearching.setStringPainted(true);

    progressBarImporting = new JProgressBar();
    progressBarImporting.setIndeterminate(false);
    progressBarImporting.setVisible(false);
    progressBarImporting.setStringPainted(true);

}

From source file:com.sciaps.view.SpectrumShotPanel.java

private void doSpectrumNormalization() {

    BackgroundTask.runBackgroundTask(new BackgroundTask() {

        private JDialog mDialog;
        private JProgressBar mProgress;

        @Override// www.  ja  va 2s.  c  o  m
        public void onBefore() {
            mProgress = new JProgressBar();
            mProgress.setIndeterminate(true);

            mDialog = new JDialog(Constants.MAIN_FRAME);
            mDialog.setLocationRelativeTo(Constants.MAIN_FRAME);
            mDialog.setAlwaysOnTop(true);
            mDialog.setResizable(false);
            mDialog.setContentPane(mProgress);
            mDialog.setSize(400, 100);
            mDialog.setVisible(true);
        }

        @Override
        public void onBackground() {

            int[] selectedRow = getSelectedRows();
            if (selectedRow == null || selectedRow.length == 0) {
                return;
            }

            final ArrayList<SpectrumShotItem> tmpList = new ArrayList<SpectrumShotItem>();
            final StringBuilder errMsg = new StringBuilder();

            SpectrumNormalization spectrumNormalization = new SpectrumNormalization();
            for (int rowIndex = 0; rowIndex < selectedRow.length; rowIndex++) {
                SpectrumShotItem selectedItem = shotListTableModel_.getRow(selectedRow[rowIndex]);

                String name = selectedItem.getName();
                name = name + "N";

                if (selectedItem.getSeriesDataType() != SpectrumShotItem.NORMALIZED) {

                    Spectrum normalizedSpectrum = null;
                    if (selectedItem.getSeriesDataType() == SpectrumShotItem.BG_REMOVED) {
                        normalizedSpectrum = spectrumNormalization
                                .normalize((RawDataSpectrum) selectedItem.getShot());
                    } else {
                        RawDataSpectrum tempSpectrum = doBackgroundRemoval(selectedItem.getShot());
                        normalizedSpectrum = doSpectrumNormalization(tempSpectrum);
                    }

                    if (normalizedSpectrum != null) {
                        SpectrumShotItem shotItem = new SpectrumShotItem(name);
                        shotItem.setShot(normalizedSpectrum, SpectrumShotItem.NORMALIZED);
                        tmpList.add(shotItem);
                    } else {
                        errMsg.append(name).append("\n");
                    }

                } else {
                    errMsg.append(name).append("\n");
                }
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    for (SpectrumShotItem shot : tmpList) {
                        shotListTableModel_.addRow(0, shot);
                    }

                    if (tmpList.isEmpty() == false) {
                        shotListTableModel_.showSeries(0);
                    }

                    if (errMsg.length() > 0) {
                        errMsg.insert(0, "The following shot(s) already exist, skipped:\n");
                        showErrorDialog(errMsg.toString());
                    }

                }
            });

        }

        @Override
        public void onAfter() {
            mDialog.setVisible(false);
        }
    });
}

From source file:edu.harvard.mcz.imagecapture.MainFrame.java

/**
 * This method initializes jProgressBar   
 *    //w ww  . ja  va 2 s.co m
 * @return javax.swing.JProgressBar   
 */
private JProgressBar getJProgressBar() {
    if (jProgressBar == null) {
        jProgressBar = new JProgressBar();
    }
    return jProgressBar;
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java

/**
 * Initialises the interface of the results panel.
 *///from  www  . j av  a 2 s.  c o m
protected void initialize() {

    setLayout(null);
    isSimulated = false;

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                double[] selectedValues;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                final int day = 24;
                File csvFile = new File(csvPath);
                try {
                    OMCampaign campaign;
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    csvOutput.write("\"ID\";\"Room\";\"Radon\"");
                    csvOutput.newLine();
                    selectedValues = campaign.getValueChain();
                    int x = 0;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[0].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[1].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[2].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[3].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[4].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[5].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[6].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                OMCampaign campaign;
                try {
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    JFreeChart chart = OMCharts.createCampaignChart(campaign, false);
                    String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                            + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                            + ", Start: " + start;
                    int height = (int) PageSize.A4.getWidth();
                    int width = (int) PageSize.A4.getHeight();
                    try {
                        OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                        JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                                JOptionPane.INFORMATION_MESSAGE);
                    } catch (IOException ioe) {
                        JOptionPane.showMessageDialog(null,
                                "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                                JOptionPane.ERROR_MESSAGE);
                        ioe.printStackTrace();
                    }
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null, "Failed to create chart!\n" + ioe.getMessage(),
                            "Failed", JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectProject = new JLabel("Select Project");
    lblSelectProject.setBounds(10, 65, 132, 14);
    lblSelectProject.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectProject);

    lblSelectRooms = new JLabel("Select Rooms");
    lblSelectRooms.setBounds(10, 94, 132, 14);
    lblSelectRooms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectRooms);

    lblStartTime = new JLabel("Start Time");
    lblStartTime.setBounds(10, 123, 132, 14);
    lblStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblStartTime);

    lblWarning = new JLabel("Select 6 rooms and 1 cellar!");
    lblWarning.setForeground(Color.RED);
    lblWarning.setBounds(565, 123, 175, 14);
    lblWarning.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblWarning.setVisible(false);
    add(lblWarning);

    sliderStartTime = new JSlider();
    sliderStartTime.setMaximum(0);
    sliderStartTime.setBounds(152, 119, 285, 24);
    sliderStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(sliderStartTime);

    spnrStartTime = new JSpinner();
    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, 0, 1));
    spnrStartTime.setBounds(447, 120, 108, 22);
    spnrStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(spnrStartTime);

    btnRefresh = new JButton("Load");
    btnRefresh.setBounds(616, 61, 124, 23);
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnRefresh);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnMaximize);

    panelCampaign = new JPanel();
    panelCampaign.setBounds(10, 150, 730, 315);
    panelCampaign.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(panelCampaign);

    progressBar = new JProgressBar();
    progressBar.setBounds(10, 475, 730, 23);
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setVisible(false);
    add(progressBar);

    lblOpenOmbfile = new JLabel("Open OMB-File");
    lblOpenOmbfile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblOpenOmbfile.setBounds(10, 36, 132, 14);
    add(lblOpenOmbfile);

    lblHelp = new JLabel("Select an OMB-Object file to manually simulate virtual campaigns.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    txtOmbFile = new JTextField();
    txtOmbFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmbFile.setColumns(10);
    txtOmbFile.setBounds(152, 33, 454, 20);
    add(txtOmbFile);

    btnBrowse = new JButton("Browse");
    btnBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnBrowse.setBounds(616, 32, 124, 23);
    add(btnBrowse);

    comboBoxRoom1 = new JComboBox<OMRoom>();
    comboBoxRoom1.setBounds(152, 90, 75, 22);
    comboBoxRoom1.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom1);

    comboBoxRoom2 = new JComboBox<OMRoom>();
    comboBoxRoom2.setBounds(237, 90, 75, 22);
    comboBoxRoom2.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom2);

    comboBoxRoom3 = new JComboBox<OMRoom>();
    comboBoxRoom3.setBounds(323, 90, 75, 22);
    comboBoxRoom3.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom3);

    comboBoxRoom4 = new JComboBox<OMRoom>();
    comboBoxRoom4.setBounds(408, 90, 75, 22);
    comboBoxRoom4.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom4);

    comboBoxRoom5 = new JComboBox<OMRoom>();
    comboBoxRoom5.setBounds(494, 90, 75, 22);
    comboBoxRoom5.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom5);

    comboBoxRoom6 = new JComboBox<OMRoom>();
    comboBoxRoom6.setBounds(579, 90, 75, 22);
    comboBoxRoom6.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom6);

    comboBoxRoom7 = new JComboBox<OMRoom>();
    comboBoxRoom7.setBounds(665, 90, 75, 22);
    comboBoxRoom7.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom7);

    comboBoxProjects = new JComboBox<OMBuilding>();
    comboBoxProjects.setBounds(152, 61, 454, 22);
    comboBoxProjects.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxProjects);

    comboBoxRoom1.addActionListener(this);
    comboBoxRoom1.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom2.addActionListener(this);
    comboBoxRoom2.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom3.addActionListener(this);
    comboBoxRoom3.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom4.addActionListener(this);
    comboBoxRoom4.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom5.addActionListener(this);
    comboBoxRoom5.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom6.addActionListener(this);
    comboBoxRoom6.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom7.addActionListener(this);
    comboBoxRoom7.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });

    sliderStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    spnrStartTime.setValue((int) sliderStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    spnrStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    sliderStartTime.setValue((Integer) spnrStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("")
                    && !txtOmbFile.getText().equals(" ")) {
                txtOmbFile.setBackground(Color.WHITE);
                String ombPath = txtOmbFile.getText();
                String omb;
                String[] tmpFileName = ombPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(ombPath + omb);
                setOmbFile(ombPath + omb);
                File ombFile = new File(ombPath + omb);
                if (ombFile.exists()) {
                    txtOmbFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxProjects.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setVisible(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    progressBar.setIndeterminate(true);
                    progressBar.setStringPainted(true);
                    refreshTask = new Refresh();
                    refreshTask.execute();
                } else {
                    txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                        + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                        + ", Start: " + start;
                OMCampaign campaign;
                if (isResult) {
                    campaign = getResultCampaign();
                } else {
                    campaign = new OMCampaign(start, rooms, 0);
                }
                JPanel campaignChart = createCampaignPanel(campaign, false, true);
                JFrame chartFrame = new JFrame();
                chartFrame.getContentPane().add(campaignChart);
                chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                chartFrame.setTitle(title);
                chartFrame.setResizable(true);
                chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                chartFrame.setVisible(true);
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    });
    txtOmbFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            setOmbFile(txtOmbFile.getText());
        }
    });
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String omb;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(file.getAbsolutePath() + omb);
                setOmbFile(file.getAbsolutePath() + omb);
            }
        }
    });
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Initialises the interface of the results panel.
 *//*w ww  . j a  va2 s  .c  om*/
protected void initialize() {
    setLayout(null);

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    JFrame chartFrame = new JFrame();
                    OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                    String title = simulation.toString();
                    DescriptiveStatistics statistics = null;
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    OMRoomType roomType = null;
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomGeometricMeans:
                        title = "R_GM, " + title;
                        statistics = simulation.getRoomGmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMedianQ50:
                        title = "R_MED, " + title;
                        statistics = simulation.getRoomMedDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMaxima:
                        title = "R_MAX, " + title;
                        statistics = simulation.getRoomMaxDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case CellarArithmeticMeans:
                        title = "C_AM, " + title;
                        statistics = simulation.getCellarAmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarGeometricMeans:
                        title = "C_GM, " + title;
                        statistics = simulation.getCellarGmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMedianQ50:
                        title = "C_MED, " + title;
                        statistics = simulation.getCellarMedDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMaxima:
                        title = "C_MAX, " + title;
                        statistics = simulation.getCellarMaxDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    default:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Misc;
                        break;
                    }
                    JPanel chartPanel = createDistributionPanel(title, statistics, roomType, false, true, true);
                    chartFrame.getContentPane().add(chartPanel);
                    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                    chartFrame.setTitle("OM Simulation Tool: " + title);
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    add(btnMaximize);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    String head = "";
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        head = "R_AM";
                        break;
                    case RoomGeometricMeans:
                        head = "R_GM";
                        break;
                    case RoomMedianQ50:
                        head = "R_MED";
                        break;
                    case RoomMaxima:
                        head = "R_MAX";
                        break;
                    case CellarArithmeticMeans:
                        head = "C_AM";
                        break;
                    case CellarGeometricMeans:
                        head = "C_GM";
                        break;
                    case CellarMedianQ50:
                        head = "C_MED";
                        break;
                    case CellarMaxima:
                        head = "C_MAX";
                        break;
                    default:
                        head = "R_AM";
                        break;
                    }
                    csvOutput.write("\"ID\";\"CAMPAIGN\";\"START\";\"" + head + "\"");
                    csvOutput.newLine();
                    int value = 0;
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (statisticsType) {
                        case RoomArithmeticMeans:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            value = (int) campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            value = (int) campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            value = (int) campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            value = (int) campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            value = (int) campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            value = (int) campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            value = (int) campaigns[i].getCellarMaximum();
                            break;
                        default:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        }
                        csvOutput.write("\"" + i + "\";\"" + campaigns[i].getVariation() + "\";\""
                                + campaigns[i].getStart() + "\";\"" + value + "\"");
                        csvOutput.newLine();
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                String title = simulation.toString();
                DescriptiveStatistics statistics = null;
                OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                OMRoomType roomType = null;
                switch (statisticsType) {
                case RoomArithmeticMeans:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomGeometricMeans:
                    title = "R_GM, " + title;
                    statistics = simulation.getRoomGmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMedianQ50:
                    title = "R_MED, " + title;
                    statistics = simulation.getRoomMedDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMaxima:
                    title = "R_MAX, " + title;
                    statistics = simulation.getRoomMaxDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case CellarArithmeticMeans:
                    title = "C_AM, " + title;
                    statistics = simulation.getCellarAmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarGeometricMeans:
                    title = "C_GM, " + title;
                    statistics = simulation.getCellarGmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMedianQ50:
                    title = "C_MED, " + title;
                    statistics = simulation.getCellarMedDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMaxima:
                    title = "C_MAX, " + title;
                    statistics = simulation.getCellarMaxDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                default:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Misc;
                    break;
                }
                JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, false);
                int height = (int) PageSize.A4.getWidth();
                int width = (int) PageSize.A4.getHeight();
                try {
                    OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                    JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectSimulation = new JLabel("Select Simulation");
    lblSelectSimulation.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectSimulation.setBounds(10, 65, 132, 14);
    add(lblSelectSimulation);

    lblSelectStatistics = new JLabel("Select Statistics");
    lblSelectStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectStatistics.setBounds(10, 94, 132, 14);
    add(lblSelectStatistics);

    comboBoxSimulations = new JComboBox<OMSimulation>();
    comboBoxSimulations.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxSimulations.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                    comboBoxStatistics.setSelectedIndex(0);
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.setBounds(152, 61, 454, 22);
    add(comboBoxSimulations);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmsFile.getText() != null && !txtOmsFile.getText().equals("")
                    && !txtOmsFile.getText().equals(" ")) {
                txtOmsFile.setBackground(Color.WHITE);
                String omsPath = txtOmsFile.getText();
                String oms;
                String[] tmpFileName = omsPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(omsPath + oms);
                setOmsFile(omsPath + oms);
                File omsFile = new File(omsPath + oms);
                if (omsFile.exists()) {
                    txtOmsFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxSimulations.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setStringPainted(true);
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    refreshSimulationsTask = new RefreshSimulations();
                    refreshSimulationsTask.execute();
                } else {
                    txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMS-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMS-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    comboBoxStatistics = new JComboBox<OMStatistics>();
    comboBoxStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxStatistics.setBounds(152, 90, 454, 22);
    comboBoxStatistics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            updateDistribution();
        }
    });
    add(comboBoxStatistics);

    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    panelDistribution = new JPanel();
    panelDistribution.setBounds(10, 118, 730, 347);
    add(panelDistribution);

    progressBar = new JProgressBar();
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setBounds(10, 475, 730, 23);
    add(progressBar);

    progressBar.setEnabled(false);
    comboBoxStatistics.setEnabled(false);
    lblSelectStatistics.setEnabled(false);
    btnPdf.setVisible(false);
    btnCsv.setVisible(false);
    btnMaximize.setVisible(false);
    lblExportChartTo.setVisible(false);

    lblHelp = new JLabel("Select an OMS-Simulation file to analyse the simulation results and "
            + "display the distribution chart.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    lblSelectOms = new JLabel("Open OMS-File");
    lblSelectOms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblSelectOms.setBounds(10, 36, 132, 14);
    add(lblSelectOms);

    txtOmsFile = new JTextField();
    txtOmsFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            setOmsFile(txtOmsFile.getText());
        }
    });
    txtOmsFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmsFile.setColumns(10);
    txtOmsFile.setBounds(152, 33, 454, 20);
    add(txtOmsFile);

    buttonBrowse = new JButton("Browse");
    buttonBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String oms;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(file.getAbsolutePath() + oms);
                setOmsFile(file.getAbsolutePath() + oms);
            }
        }
    });
    buttonBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    buttonBrowse.setBounds(616, 32, 124, 23);
    add(buttonBrowse);
    progressBar.setVisible(false);
}

From source file:com.sciaps.view.SpectrumShotPanel.java

private void doFindPeak() {

    final int[] selectedRows = tblShots_.getSelectedRows();
    if (selectedRows == null || selectedRows.length == 0) {
        showErrorDialog("No spectrum is selected to find peak on.");
        return;/* ww w.  j  a  v a 2s  .com*/
    }

    if (selectedRows.length != 1) {
        showErrorDialog("Select 1 spectrum to continue.");
        return;
    }

    BackgroundTask.runBackgroundTask(new BackgroundTask() {

        private JDialog mDialog;
        private JProgressBar mProgress;

        @Override
        public void onBefore() {
            mProgress = new JProgressBar();
            mProgress.setIndeterminate(true);

            mDialog = new JDialog(Constants.MAIN_FRAME);
            mDialog.setLocationRelativeTo(Constants.MAIN_FRAME);
            mDialog.setAlwaysOnTop(true);
            mDialog.setResizable(false);
            mDialog.setContentPane(mProgress);
            mDialog.setSize(400, 100);
            mDialog.setVisible(true);
        }

        @Override
        public void onBackground() {
            StringBuilder errMsg = new StringBuilder();

            SpectrumPeakFinding peakFinding = new SpectrumPeakFinding(30);

            int modelIndex = tblShots_.convertRowIndexToModel(selectedRows[0]);
            final SpectrumShotItem selectedItem = shotListTableModel_.getRow(modelIndex);
            final double[] peaksOnX;

            if (selectedItem.getSeriesDataType() == SpectrumShotItem.NORMALIZED) {

                peaksOnX = peakFinding.getPeaks(selectedItem.getShot());
            } else if (selectedItem.getSeriesDataType() == SpectrumShotItem.BG_REMOVED) {

                RawDataSpectrum tmp = doSpectrumNormalization((RawDataSpectrum) selectedItem.getShot());
                peaksOnX = peakFinding.getPeaks(tmp);
            } else {

                RawDataSpectrum tmp = doBackgroundRemoval(selectedItem.getShot());
                tmp = doSpectrumNormalization(tmp);
                peaksOnX = peakFinding.getPeaks(tmp);
            }

            if (peaksOnX.length > 0) {

                peakMarkers_ = new IntervalMarker[peaksOnX.length];
                double min;
                double max;
                for (int i = 0; i < peaksOnX.length; i++) {

                    min = peaksOnX[i] - MARKER_THRESHOLD;
                    max = peaksOnX[i] + MARKER_THRESHOLD;
                    IntervalMarker marker = Util.createMarker(min, max);
                    peakMarkers_[i] = marker;
                }

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {

                        // unselected all other series
                        tblShots_.selectAll();
                        SpectrumShotItem tmpItem;
                        for (int i : tblShots_.getSelectedRows()) {
                            tmpItem = shotListTableModel_.getRow(i);
                            tmpItem.setSelected(false);
                            callback_.doDeleteShotXYSeries(tmpItem);
                        }

                        shotListTableModel_.showSeries(selectedRows[0]);
                        tblShots_.setRowSelectionInterval(selectedRows[0], selectedRows[0]);
                        callback_.doAddMarker(peakMarkers_);
                    }
                });
            }
        }

        @Override
        public void onAfter() {
            mDialog.setVisible(false);
        }

    });
}

From source file:gui_pack.MainGui.java

private void runTestsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runTestsButtonActionPerformed
    int rangeMin, rangeMax, spacing;
    int passing = 0;

    {//  Beginning of input validation
        String errorTitle, errorMessage;

        //make sure at least one sort algorithm is selected
        if (!(insertionCheckBox.isSelected() || mergeCheckBox.isSelected() || quickCheckBox.isSelected()
                || selectionCheckBox.isSelected())) {
            errorTitle = "Selection Error";
            errorMessage = "At least one sort algorithm (Insertion Sort, "
                    + "Merge Sort, Quick Sort, or Selection Sort) must be selected.";
            JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE);
            return;
        }/*  www .  j ava2s  . com*/

        //make sure at least one order is selected
        if (!(ascendingCheckBox.isSelected() || descendingCheckBox.isSelected()
                || randomCheckBox.isSelected())) {
            errorTitle = "Selection Error";
            errorMessage = "At least one order (Ascending Order, Descending Order, or Random Order) "
                    + "must be selected.";
            JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE);
            return;
        }

        //make sure all the proper fields contain data
        try {
            rangeMin = Integer.parseInt(rangeMinField.getText());
            rangeMax = Integer.parseInt(rangeMaxField.getText());
            spacing = Integer.parseInt(spacingField.getText());
            //for the multithreaded version of this program "iterations" cannot be a variable
            //this was left in to catch if the iteration field is left blank or has no value
            if (iterationField.isEnabled()) {
                Integer.parseInt(iterationField.getText());
            }
        } catch (NumberFormatException arbitraryName) {
            errorTitle = "Input Error";
            if (iterationField.isEnabled()) {
                errorMessage = "The size, intervals, and iterations fields must contain "
                        + "integer values and only integer values.";
            } else {
                errorMessage = "The size and intervals fields must contain "
                        + "integer values and only integer values.";
            }
            JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE);
            return;
        }

        //make sure field data is appropriate
        if (rangeMin > rangeMax) {
            errorTitle = "Range Error";
            errorMessage = "Minimum Size must be less than or equal to Maximum Size.";
            JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE);
            return;
        }

        if (spacing < 1 || rangeMin < 1 || rangeMax < 1
                || (iterationField.isEnabled() && Integer.parseInt(iterationField.getText()) < 1)) {
            errorTitle = "Value Error";
            if (iterationField.isEnabled()) {
                errorMessage = "Intervals, sizes, and iterations must be in the positive domain. "
                        + "Spacing, Range(min), Range(max), and Iterations must be greater than or"
                        + " equal to one.";
            } else {
                errorMessage = "Intervals and sizes must be in the positive domain. "
                        + "Spacing, Range(min) and Range(max) be greater than or" + " equal to one.";
            }
            JOptionPane.showMessageDialog(null, errorMessage, errorTitle, JOptionPane.WARNING_MESSAGE);
            return;
        }

        if (!iterationField.isEnabled()) {
            passing = 0;
        }

    } // End of input validation

    //here's where we set up a loading bar in case the tests take a while
    JProgressBar loadBar = new JProgressBar();
    JFrame loadFrame = new JFrame();
    JLabel displayLabel1 = new JLabel();
    loadBar.setIndeterminate(true);
    loadBar.setVisible(true);
    displayLabel1.setText("Running large tests, or many tests, using inefficient algorithms \n"
            + "may take a while. Please be patient.");
    loadFrame.setLayout(new FlowLayout());
    loadFrame.add(loadBar);
    loadFrame.add(displayLabel1);
    loadFrame.setSize(600, 100);
    loadFrame.setTitle("Loading");
    loadFrame.setVisible(true);

    //now we will leave this open until the tests are completed
    //now we can conduct the actual tests
    SwingWorker worker = new SwingWorker<XYSeriesCollection, Void>() {
        XYSeriesCollection results = new XYSeriesCollection();

        @Override
        protected XYSeriesCollection doInBackground() {
            XYSeries insertSeries = new XYSeries("Insertion Sort");
            XYSeries mergeSeries = new XYSeries("Merge Sort");
            XYSeries quickSeries = new XYSeries("Quick Sort");
            XYSeries selectSeries = new XYSeries("Selection Sort");

            final boolean ascending = ascendingCheckBox.isSelected();
            final boolean descending = descendingCheckBox.isSelected();
            final boolean insertion = insertionCheckBox.isSelected();
            final boolean merge = mergeCheckBox.isSelected();
            final boolean quick = quickCheckBox.isSelected();
            final boolean selection = selectionCheckBox.isSelected();

            final int iterations = Integer.parseInt(iterationField.getText());

            ListGenerator generator = new ListGenerator();
            int[] list;
            for (int count = rangeMin; count <= rangeMax; count = count + spacing) {

                if (ascending) {

                    list = generator.ascending(count);
                    if (insertion) {
                        insertSeries.add(count, insertionSort.sort(list));
                    }
                    if (merge) {
                        mergeSeries.add(count, mergeSort.sort(list));
                    }
                    if (quick) {
                        quickSeries.add(count, quickSort.sort(list));
                    }
                    if (selection) {
                        selectSeries.add(count, selectionSort.sort(list));
                    }
                }
                if (descending) {

                    list = generator.descending(count);
                    if (insertion) {
                        insertSeries.add(count, insertionSort.sort(list));
                    }
                    if (merge) {
                        mergeSeries.add(count, mergeSort.sort(list));
                    }
                    if (quick) {
                        quickSeries.add(count, quickSort.sort(list));
                    }
                    if (selection) {
                        selectSeries.add(count, selectionSort.sort(list));
                    }
                }

                for (int iteration = 0; iteration < iterations; iteration++) {
                    list = generator.random(count);

                    if (insertion) {
                        insertSeries.add(count, insertionSort.sort(list));
                    }
                    if (merge) {
                        mergeSeries.add(count, mergeSort.sort(list));
                    }
                    if (quick) {
                        quickSeries.add(count, quickSort.sort(list));
                    }
                    if (selection) {
                        selectSeries.add(count, selectionSort.sort(list));
                    }
                }

            }

            //now we aggregate the results
            if (insertion) {
                results.addSeries(insertSeries);
            }
            if (merge) {
                results.addSeries(mergeSeries);
            }
            if (quick) {
                results.addSeries(quickSeries);
            }
            if (selection) {
                results.addSeries(selectSeries);
            }
            return results;
        }

        @Override
        protected void done() {
            //finally, we display the results
            JFreeChart chart = ChartFactory.createScatterPlot("SortExplorer", // chart title
                    "List Size", // x axis label
                    "Number of Comparisons", // y axis label
                    results, // data  
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
            );
            ChartFrame frame = new ChartFrame("First", chart);
            frame.pack();
            frame.setVisible(true);
            loadFrame.setVisible(false);
        }
    };

    //having set up the multithreading 'worker' we can finally conduct the 
    //test
    worker.execute();

}

From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java

private void initFrame() {
    frame = new JFrame();
    frame.setTitle("libautocaptcha vodafone.it tool");
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    JPanel setupPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) setupPanel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Setup", null, setupPanel, null);

    JPanel setupFormPanel = new JPanel();
    setupPanel.add(setupFormPanel);/* www. j ava 2  s. c om*/
    GridBagLayout gbl_setupFormPanel = new GridBagLayout();
    gbl_setupFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_setupFormPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_setupFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_setupFormPanel.rowWeights = new double[] { 0.0, 0.0, 0.0 };
    setupFormPanel.setLayout(gbl_setupFormPanel);

    JLabel usernameLabel = new JLabel("Username");
    GridBagConstraints gbc_usernameLabel = new GridBagConstraints();
    gbc_usernameLabel.anchor = GridBagConstraints.WEST;
    gbc_usernameLabel.fill = GridBagConstraints.VERTICAL;
    gbc_usernameLabel.insets = new Insets(0, 0, 5, 5);
    gbc_usernameLabel.gridx = 0;
    gbc_usernameLabel.gridy = 0;
    setupFormPanel.add(usernameLabel, gbc_usernameLabel);
    usernameField = new JTextField();
    GridBagConstraints gbc_usernameField = new GridBagConstraints();
    gbc_usernameField.fill = GridBagConstraints.BOTH;
    gbc_usernameField.insets = new Insets(0, 0, 5, 0);
    gbc_usernameField.gridx = 1;
    gbc_usernameField.gridy = 0;
    setupFormPanel.add(usernameField, gbc_usernameField);
    usernameField.setColumns(10);

    JLabel passwordLabel = new JLabel("Password");
    GridBagConstraints gbc_passwordLabel = new GridBagConstraints();
    gbc_passwordLabel.anchor = GridBagConstraints.WEST;
    gbc_passwordLabel.fill = GridBagConstraints.VERTICAL;
    gbc_passwordLabel.insets = new Insets(0, 0, 5, 5);
    gbc_passwordLabel.gridx = 0;
    gbc_passwordLabel.gridy = 1;
    setupFormPanel.add(passwordLabel, gbc_passwordLabel);
    passwordField = new JPasswordField();
    GridBagConstraints gbc_passwordField = new GridBagConstraints();
    gbc_passwordField.fill = GridBagConstraints.BOTH;
    gbc_passwordField.insets = new Insets(0, 0, 5, 0);
    gbc_passwordField.gridx = 1;
    gbc_passwordField.gridy = 1;
    setupFormPanel.add(passwordField, gbc_passwordField);
    passwordField.setColumns(10);

    JLabel receiverLabel = new JLabel("Mobile number");
    GridBagConstraints gbc_receiverLabel = new GridBagConstraints();
    gbc_receiverLabel.fill = GridBagConstraints.VERTICAL;
    gbc_receiverLabel.anchor = GridBagConstraints.WEST;
    gbc_receiverLabel.insets = new Insets(0, 0, 5, 5);
    gbc_receiverLabel.gridx = 0;
    gbc_receiverLabel.gridy = 2;
    setupFormPanel.add(receiverLabel, gbc_receiverLabel);

    receiverField = new JTextField();
    GridBagConstraints gbc_receiverField = new GridBagConstraints();
    gbc_receiverField.insets = new Insets(0, 0, 5, 0);
    gbc_receiverField.fill = GridBagConstraints.BOTH;
    gbc_receiverField.gridx = 1;
    gbc_receiverField.gridy = 2;
    setupFormPanel.add(receiverField, gbc_receiverField);
    receiverField.setColumns(10);

    JPanel backgroundPanel = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) backgroundPanel.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Background", null, backgroundPanel, null);

    JPanel backgroundFormPanel = new JPanel();
    backgroundPanel.add(backgroundFormPanel);
    GridBagLayout gbl_backgroundFormPanel = new GridBagLayout();
    gbl_backgroundFormPanel.columnWidths = new int[] { 150, 50, 100, 0 };
    gbl_backgroundFormPanel.rowHeights = new int[] { 0, 25, 0 };
    gbl_backgroundFormPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_backgroundFormPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    backgroundFormPanel.setLayout(gbl_backgroundFormPanel);

    JLabel numberLabel = new JLabel("Number of CAPTCHAs");
    GridBagConstraints gbc_numberLabel = new GridBagConstraints();
    gbc_numberLabel.anchor = GridBagConstraints.WEST;
    gbc_numberLabel.insets = new Insets(0, 0, 5, 5);
    gbc_numberLabel.gridx = 0;
    gbc_numberLabel.gridy = 0;
    backgroundFormPanel.add(numberLabel, gbc_numberLabel);

    numberField = new JTextField();
    numberField.setText("5");
    GridBagConstraints gbc_numberField = new GridBagConstraints();
    gbc_numberField.anchor = GridBagConstraints.WEST;
    gbc_numberField.insets = new Insets(0, 0, 5, 5);
    gbc_numberField.gridx = 1;
    gbc_numberField.gridy = 0;
    backgroundFormPanel.add(numberField, gbc_numberField);
    numberField.setColumns(3);

    JButton numberButton = new JButton("Download");
    numberButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int counter = 0;

            do {
                BufferedImage captcha = downloadCAPTCHA();
                if (captcha != null) {
                    try {
                        int number = new File(tempFolder.getAbsolutePath()).listFiles().length;
                        File file = new File(tempFolder.getAbsolutePath() + "/background_" + number + ".png");
                        ImageIO.write(captcha, "png", file);
                        Thread.sleep(2500);
                    } catch (Exception x) {
                        x.printStackTrace();
                    }
                }
            } while (++counter < Integer.valueOf(numberField.getText()));

            Image background = loadBackground();
            if (background != null) {
                backgroundImage.setIcon(new ImageIcon(background));
            }
        }
    });
    GridBagConstraints gbc_numberButton = new GridBagConstraints();
    gbc_numberButton.anchor = GridBagConstraints.NORTHWEST;
    gbc_numberButton.insets = new Insets(0, 0, 5, 0);
    gbc_numberButton.gridx = 2;
    gbc_numberButton.gridy = 0;
    backgroundFormPanel.add(numberButton, gbc_numberButton);

    JLabel backgroundLabel = new JLabel("Current background");
    GridBagConstraints gbc_backgroundLabel = new GridBagConstraints();
    gbc_backgroundLabel.anchor = GridBagConstraints.WEST;
    gbc_backgroundLabel.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundLabel.gridx = 0;
    gbc_backgroundLabel.gridy = 1;
    backgroundFormPanel.add(backgroundLabel, gbc_backgroundLabel);

    backgroundImage = new JLabel("");
    GridBagConstraints gbc_backgroundImage = new GridBagConstraints();
    gbc_backgroundImage.anchor = GridBagConstraints.WEST;
    gbc_backgroundImage.gridwidth = 2;
    gbc_backgroundImage.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundImage.gridx = 1;
    gbc_backgroundImage.gridy = 1;
    backgroundFormPanel.add(backgroundImage, gbc_backgroundImage);

    JPanel trainingPanel = new JPanel();
    tabbedPane.addTab("Training", null, trainingPanel, null);
    GridBagLayout gbl_trainingPanel = new GridBagLayout();
    gbl_trainingPanel.columnWidths = new int[] { 437, 0 };
    gbl_trainingPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_trainingPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_trainingPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingPanel.setLayout(gbl_trainingPanel);

    trainingLoadPanel = new JPanel();
    GridBagConstraints gbc_trainingLoadPanel = new GridBagConstraints();
    gbc_trainingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_trainingLoadPanel.gridx = 0;
    gbc_trainingLoadPanel.gridy = 0;
    trainingPanel.add(trainingLoadPanel, gbc_trainingLoadPanel);
    trainingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton trainingLoadButton = new JButton("Download");
    trainingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            trainingCaptcha = downloadCAPTCHA();
            if (trainingCaptcha != null) {
                trainingCaptchaImage.setIcon(new ImageIcon(trainingCaptcha));
                List<Image> glyphs = loadGlyphs(trainingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    trainingGlyphImage[g].setIcon(null);
                    trainingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    trainingGlyph[g] = glyphs.get(g);
                    trainingGlyphImage[g].setIcon(new ImageIcon(trainingGlyph[g]));
                }
                trainingLoadPanel.invalidate();
                trainingSavePanel.invalidate();
            }
        }
    });
    trainingLoadPanel.add(trainingLoadButton);

    trainingCaptchaImage = new JLabel("");
    trainingLoadPanel.add(trainingCaptchaImage);

    trainingSavePanel = new JPanel();
    GridBagConstraints gbc_trainingSavePanel = new GridBagConstraints();
    gbc_trainingSavePanel.insets = new Insets(0, 5, 0, 0);
    gbc_trainingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingSavePanel.gridx = 0;
    gbc_trainingSavePanel.gridy = 1;
    trainingPanel.add(trainingSavePanel, gbc_trainingSavePanel);
    GridBagLayout gbl_trainingSavePanel = new GridBagLayout();
    gbl_trainingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_trainingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_trainingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_trainingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingSavePanel.setLayout(gbl_trainingSavePanel);

    trainingGlyph = new Image[5];
    trainingGlyphImage = new JLabel[5];
    trainingGlyphField = new JTextField[5];

    trainingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_glyphImage0 = new GridBagConstraints();
    gbc_glyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage0.gridx = 0;
    gbc_glyphImage0.gridy = 0;
    trainingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[0], gbc_glyphImage0);

    trainingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_glyphImage1 = new GridBagConstraints();
    gbc_glyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage1.gridx = 1;
    gbc_glyphImage1.gridy = 0;
    trainingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[1], gbc_glyphImage1);

    trainingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_glyphImage2 = new GridBagConstraints();
    gbc_glyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage2.gridx = 2;
    gbc_glyphImage2.gridy = 0;
    trainingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[2], gbc_glyphImage2);

    trainingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_glyphImage3 = new GridBagConstraints();
    gbc_glyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage3.gridx = 3;
    gbc_glyphImage3.gridy = 0;
    trainingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[3], gbc_glyphImage3);

    trainingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_glyphImage4 = new GridBagConstraints();
    gbc_glyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage4.gridx = 4;
    gbc_glyphImage4.gridy = 0;
    trainingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[4], gbc_glyphImage4);

    JButton trainingSaveButton = new JButton("Train");
    trainingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int g = 0; g < 5; ++g) {
                String s = trainingGlyphField[g].getText();
                if (s.length() == 1) {
                    char c = Character.toUpperCase(s.charAt(0));
                    net.sourceforge.javaocr.Image glyph = convertImage(trainingGlyph[g]);
                    grayFilter.process(glyph);
                    ThresholdFilter thresholdFilter = new ThresholdFilter(0, FG, BG);
                    thresholdFilter.process(glyph);
                    train(glyph, c);
                }
                trainingGlyphField[g].setText("");
            }

            for (Map.Entry<Character, Cluster> m : clusters.entrySet()) {
                System.out.println("****************************************");
                System.out.print(" character:  ");
                //          int samples = ((EuclidianDistanceCluster) m.getValue()).getAmountSamples();
                int samples = ((SigmaWeightedEuclidianDistanceCluster) m.getValue()).getAmountSamples();
                for (int s = 0; s < samples; ++s)
                    System.out.print(m.getKey());
                System.out.println();
                double[] c = m.getValue().center();
                for (int i = 0; i < c.length; ++i)
                    System.out.println(" centroid[" + i + "]: " + c[i]);
            }

            System.out.println("****************************************");
            System.out.println("TOTAL CLUSTERS: " + clusters.size());
        }
    });
    GridBagConstraints gbc_trainingSaveButton = new GridBagConstraints();
    gbc_trainingSaveButton.gridheight = 2;
    gbc_trainingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_trainingSaveButton.gridx = 5;
    gbc_trainingSaveButton.gridy = 0;
    trainingSavePanel.add(trainingSaveButton, gbc_trainingSaveButton);

    trainingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_glyphField0 = new GridBagConstraints();
    gbc_glyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField0.gridx = 0;
    gbc_glyphField0.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[0], gbc_glyphField0);
    trainingGlyphField[0].setColumns(2);

    trainingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_glyphField1 = new GridBagConstraints();
    gbc_glyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField1.gridx = 1;
    gbc_glyphField1.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[1], gbc_glyphField1);
    trainingGlyphField[1].setColumns(2);

    trainingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_glyphField2 = new GridBagConstraints();
    gbc_glyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField2.gridx = 2;
    gbc_glyphField2.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[2], gbc_glyphField2);
    trainingGlyphField[2].setColumns(2);

    trainingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_glyphField3 = new GridBagConstraints();
    gbc_glyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField3.gridx = 3;
    gbc_glyphField3.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[3], gbc_glyphField3);
    trainingGlyphField[3].setColumns(2);

    trainingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_glyphField4 = new GridBagConstraints();
    gbc_glyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField4.gridx = 4;
    gbc_glyphField4.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[4], gbc_glyphField4);
    trainingGlyphField[4].setColumns(2);

    JPanel testingPanel = new JPanel();
    tabbedPane.addTab("Testing", null, testingPanel, null);
    GridBagLayout gbl_testingPanel = new GridBagLayout();
    gbl_testingPanel.columnWidths = new int[] { 437, 0 };
    gbl_testingPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_testingPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_testingPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
    testingPanel.setLayout(gbl_testingPanel);

    testingLoadPanel = new JPanel();
    GridBagConstraints gbc_testingLoadPanel = new GridBagConstraints();
    gbc_testingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_testingLoadPanel.gridx = 0;
    gbc_testingLoadPanel.gridy = 0;
    testingPanel.add(testingLoadPanel, gbc_testingLoadPanel);
    testingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton testingLoadButton = new JButton("Download");
    testingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            testingCaptcha = downloadCAPTCHA();
            if (testingCaptcha != null) {
                testingCaptchaImage.setIcon(new ImageIcon(testingCaptcha));
                List<Image> glyphs = loadGlyphs(testingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    testingGlyphImage[g].setIcon(null);
                    testingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    testingGlyph[g] = glyphs.get(g);
                    testingGlyphImage[g].setIcon(new ImageIcon(testingGlyph[g]));
                }
                testingLoadPanel.invalidate();
                testingSavePanel.invalidate();
            }
        }
    });
    testingLoadPanel.add(testingLoadButton);

    testingCaptchaImage = new JLabel("");
    testingLoadPanel.add(testingCaptchaImage);

    testingSavePanel = new JPanel();
    GridBagConstraints gbc_testingSavePanel = new GridBagConstraints();
    gbc_testingSavePanel.insets = new Insets(0, 5, 5, 0);
    gbc_testingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingSavePanel.gridx = 0;
    gbc_testingSavePanel.gridy = 1;
    testingPanel.add(testingSavePanel, gbc_testingSavePanel);
    GridBagLayout gbl_testingSavePanel = new GridBagLayout();
    gbl_testingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_testingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_testingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_testingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    testingSavePanel.setLayout(gbl_testingSavePanel);

    testingGlyph = new Image[5];
    testingGlyphImage = new JLabel[5];
    testingGlyphField = new JTextField[5];

    testingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage0 = new GridBagConstraints();
    gbc_testingGlyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage0.gridx = 0;
    gbc_testingGlyphImage0.gridy = 0;
    testingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[0], gbc_testingGlyphImage0);

    testingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage1 = new GridBagConstraints();
    gbc_testingGlyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage1.gridx = 1;
    gbc_testingGlyphImage1.gridy = 0;
    testingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[1], gbc_testingGlyphImage1);

    testingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage2 = new GridBagConstraints();
    gbc_testingGlyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage2.gridx = 2;
    gbc_testingGlyphImage2.gridy = 0;
    testingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[2], gbc_testingGlyphImage2);

    testingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage3 = new GridBagConstraints();
    gbc_testingGlyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage3.gridx = 3;
    gbc_testingGlyphImage3.gridy = 0;
    testingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[3], gbc_testingGlyphImage3);

    testingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage4 = new GridBagConstraints();
    gbc_testingGlyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage4.gridx = 4;
    gbc_testingGlyphImage4.gridy = 0;
    testingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[4], gbc_testingGlyphImage4);

    JButton testingSaveButton = new JButton("Save and test");
    testingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "";
            for (int g = 0; g < 5; ++g) {
                String s = testingGlyphField[g].getText();
                if (s.length() == 1)
                    text += s.toUpperCase();
                trainingGlyphField[g].setText("");
            }

            if (text.length() != 5)
                return;

            try {
                File file = new File(tempFolder.getAbsolutePath() + "/captcha_" + text + ".png");
                ImageIO.write(testingCaptcha, "png", file);
            } catch (IOException x) {
                x.printStackTrace();
            }

            testingViewArea.setText(loadStatistics());
        }
    });
    GridBagConstraints gbc_testingSaveButton = new GridBagConstraints();
    gbc_testingSaveButton.gridheight = 2;
    gbc_testingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_testingSaveButton.gridx = 5;
    gbc_testingSaveButton.gridy = 0;
    testingSavePanel.add(testingSaveButton, gbc_testingSaveButton);

    testingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_testingGlyphField0 = new GridBagConstraints();
    gbc_testingGlyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField0.gridx = 0;
    gbc_testingGlyphField0.gridy = 1;
    testingSavePanel.add(testingGlyphField[0], gbc_testingGlyphField0);
    testingGlyphField[0].setColumns(2);

    testingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_testingGlyphField1 = new GridBagConstraints();
    gbc_testingGlyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField1.gridx = 1;
    gbc_testingGlyphField1.gridy = 1;
    testingSavePanel.add(testingGlyphField[1], gbc_testingGlyphField1);
    testingGlyphField[1].setColumns(2);

    testingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_testingGlyphField2 = new GridBagConstraints();
    gbc_testingGlyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField2.gridx = 2;
    gbc_testingGlyphField2.gridy = 1;
    testingSavePanel.add(testingGlyphField[2], gbc_testingGlyphField2);
    testingGlyphField[2].setColumns(2);

    testingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_testingGlyphField3 = new GridBagConstraints();
    gbc_testingGlyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField3.gridx = 3;
    gbc_testingGlyphField3.gridy = 1;
    testingSavePanel.add(testingGlyphField[3], gbc_testingGlyphField3);
    testingGlyphField[3].setColumns(2);

    testingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_testingGlyphField4 = new GridBagConstraints();
    gbc_testingGlyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField4.gridx = 4;
    gbc_testingGlyphField4.gridy = 1;
    testingSavePanel.add(testingGlyphField[4], gbc_testingGlyphField4);

    JPanel testingViewPanel = new JPanel();
    GridBagConstraints gbc_testingViewPanel = new GridBagConstraints();
    gbc_testingViewPanel.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingViewPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewPanel.gridx = 0;
    gbc_testingViewPanel.gridy = 2;
    testingPanel.add(testingViewPanel, gbc_testingViewPanel);
    GridBagLayout gbl_testingViewPanel = new GridBagLayout();
    gbl_testingViewPanel.columnWidths = new int[] { 330, 0 };
    gbl_testingViewPanel.rowHeights = new int[] { 75, 0 };
    gbl_testingViewPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_testingViewPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    testingViewPanel.setLayout(gbl_testingViewPanel);

    testingViewArea = new JTextArea();
    testingViewArea.setRows(5);
    testingViewArea.setColumns(30);
    GridBagConstraints gbc_testingViewArea = new GridBagConstraints();
    gbc_testingViewArea.fill = GridBagConstraints.BOTH;
    gbc_testingViewArea.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewArea.gridx = 0;
    gbc_testingViewArea.gridy = 0;
    testingViewPanel.add(testingViewArea, gbc_testingViewArea);
    testingGlyphField[4].setColumns(2);

    JPanel outputPanel = new JPanel();
    FlowLayout flowLayout2 = (FlowLayout) outputPanel.getLayout();
    flowLayout2.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Output", null, outputPanel, null);

    JPanel outputFormPanel = new JPanel();
    outputPanel.add(outputFormPanel);
    GridBagLayout gbl_outputFormPanel = new GridBagLayout();
    gbl_outputFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_outputFormPanel.rowHeights = new int[] { 0 };
    gbl_outputFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_outputFormPanel.rowWeights = new double[] { 0.0 };
    outputFormPanel.setLayout(gbl_outputFormPanel);

    JLabel javaLabel = new JLabel("Output .java file");
    GridBagConstraints gbc_javaLabel = new GridBagConstraints();
    gbc_javaLabel.anchor = GridBagConstraints.WEST;
    gbc_javaLabel.fill = GridBagConstraints.VERTICAL;
    gbc_javaLabel.insets = new Insets(0, 0, 5, 5);
    gbc_javaLabel.gridx = 0;
    gbc_javaLabel.gridy = 0;
    outputFormPanel.add(javaLabel, gbc_javaLabel);

    javaField = new JTextField();
    javaField.addFocusListener(new FocusListener() {
        public void focusLost(FocusEvent e) {
            javaField.removeFocusListener(this);
        }

        public void focusGained(FocusEvent e) {
            JFileChooser chooser = new JFileChooser(outFolderName);
            chooser.setSelectedFile(new File(outFileName));
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (chooser.showDialog(frame, "Save .java file") == JFileChooser.APPROVE_OPTION) {
                javaField.setText(chooser.getSelectedFile().getAbsolutePath());

                try {
                    PrintWriter output = new PrintWriter(
                            new FileWriter(chooser.getSelectedFile().getAbsolutePath()));
                    output.println("package com.googlecode.libautocaptcha.decoder.data;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.Cluster;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.MahalanobisDistanceCluster;");
                    output.println("public class VodafoneItalyData {");

                    output.println("  public static final int[] " + BACKGROUND_FIELD + " = ");
                    output.print("    new int[] { ");
                    for (int y = 0; y < HEIGHT; ++y)
                        for (int x = 0; x < WIDTH; ++x)
                            output.print(background.get(x, y) + ", ");
                    output.println("};");

                    output.println("  public static final char[] " + CHARACTERS_FIELD + " = ");
                    output.print("    new char[] { ");
                    for (Character c : clusters.keySet())
                        output.print("'" + c + "', ");
                    output.println("};");

                    output.println("  public static final Cluster[] " + CLUSTERS_FIELD + " = ");
                    output.print("    new MahalanobisDistanceCluster[] { ");
                    for (Cluster c : clusters.values()) {
                        output.print("new MahalanobisDistanceCluster(new double[] { ");
                        double[] mx = ((MahalanobisDistanceCluster) c).getMx();
                        for (double i : mx)
                            output.print(i + ", ");
                        output.print("}, new double[][] { ");
                        double[][] invcov = ((MahalanobisDistanceCluster) c).getInvcov();
                        for (double[] row : invcov) {
                            output.print("new double[] { ");
                            for (double i : row)
                                output.print(i + ", ");
                            output.print("}, ");
                        }
                        output.print("}), ");
                    }
                    output.println("};");

                    output.println("}");
                    output.close();
                } catch (IOException x) {
                    x.printStackTrace();
                }
            }
        }
    });
    GridBagConstraints gbc_javaField = new GridBagConstraints();
    gbc_javaField.fill = GridBagConstraints.BOTH;
    gbc_javaField.insets = new Insets(0, 0, 5, 0);
    gbc_javaField.gridx = 1;
    gbc_javaField.gridy = 0;
    outputFormPanel.add(javaField, gbc_javaField);
    javaField.setColumns(10);

    JPanel statusPanel = new JPanel();
    frame.getContentPane().add(statusPanel, BorderLayout.SOUTH);
    GridBagLayout gbl_statusPanel = new GridBagLayout();
    gbl_statusPanel.columnWidths = new int[] { 150, 0, 0 };
    gbl_statusPanel.rowHeights = new int[] { 14, 0 };
    gbl_statusPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_statusPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    statusPanel.setLayout(gbl_statusPanel);

    statusBar = new JProgressBar();
    GridBagConstraints gbc_statusBar = new GridBagConstraints();
    gbc_statusBar.insets = new Insets(0, 0, 0, 5);
    gbc_statusBar.gridx = 0;
    gbc_statusBar.gridy = 0;
    statusPanel.add(statusBar, gbc_statusBar);

    statusLabel = new JLabel("");
    GridBagConstraints gbc_statusLabel = new GridBagConstraints();
    gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL;
    gbc_statusLabel.gridx = 1;
    gbc_statusLabel.gridy = 0;
    statusPanel.add(statusLabel, gbc_statusLabel);
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void initGUI() {
    try {//from  ww  w . j a v a  2 s.c  o m
        language = Utf8ResourceBundle.getBundle("language_" + Setting.getInstance().getCurrentLanguage());

        // $hide>>$
        if (os == OSType.win) {
            if (!new File("PauseBochs.exe").exists() || !new File("StopBochs.exe").exists()) {
                JOptionPane.showMessageDialog(null, MyLanguage.getString("PauseBochsExe"),
                        MyLanguage.getString("Error"), JOptionPane.ERROR_MESSAGE);
                System.exit(1);
            }
            if (!new File("ndisasm.exe").exists()) {
                JOptionPane.showMessageDialog(null, MyLanguage.getString("NdisasmExe"),
                        MyLanguage.getString("Error"), JOptionPane.ERROR_MESSAGE);
                System.exit(1);
            }
        }
        // $hide<<$
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        {
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            if (Global.isBeta) {
                this.setTitle(MyLanguage.getString("Title") + " " + Global.version
                        + " , This is beta version, if you found a bug, please try older official release");
            } else {
                this.setTitle(MyLanguage.getString("Title") + " " + Global.version);
            }

            this.setIconImage(
                    new ImageIcon(getClass().getClassLoader().getResource("com/peterbochs/icons/peter.png"))
                            .getImage());
            this.addWindowListener(new WindowAdapter() {
                public void windowOpened(WindowEvent evt) {
                    thisWindowOpened(evt);
                }

                public void windowActivated(WindowEvent evt) {
                    thisWindowActivated(evt);
                }

                public void windowClosing(WindowEvent evt) {
                    thisWindowClosing(evt);
                }
            });
        }
        {
            jToolBar1 = new JToolBar();
            getContentPane().add(jToolBar1, BorderLayout.NORTH);
            {
                startBochsButton = new JButton();
                jToolBar1.add(startBochsButton);
                startBochsButton.setText(MyLanguage.getString("Start_bochs"));
                startBochsButton.setToolTipText("Launch bochs");
                startBochsButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/peterbochs/icons/famfam_icons/accept.png")));
                startBochsButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        startBochsButtonActionPerformed(evt);
                    }
                });
            }
            {
                stopBochsButton = new JButton();
                jToolBar1.add(stopBochsButton);
                stopBochsButton.setText(MyLanguage.getString("Stop_bochs"));
                stopBochsButton.setToolTipText("Quit bochs");
                stopBochsButton.setIcon(new ImageIcon(
                        getClass().getClassLoader().getResource("com/peterbochs/icons/famfam_icons/stop.png")));
                stopBochsButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        stopBochsButtonActionPerformed(evt);
                    }
                });
            }
            {
                runBochsButton = new JDropDownButton();
                jToolBar1.add(runBochsButton);
                runBochsButton.setText(MyLanguage.getString("Run_bochs"));
                runBochsButton.setToolTipText("Start emulation");
                runBochsButton.setMaximumSize(new java.awt.Dimension(85, 26));
                runBochsButton.add(getJRunBochsAndSkipBreakpointMenuItem());
                runBochsButton.add(getJRunCustomCommandMenuItem());
                runBochsButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/peterbochs/icons/famfam_icons/resultset_next.png")));
                runBochsButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        runBochsButtonActionPerformed(evt);
                    }
                });
            }
            {
                stepBochsButton = new JDropDownButton();
                jToolBar1.add(stepBochsButton);
                jToolBar1.add(getJStepOverDropDownButton());
                jToolBar1.add(getJFastStepBochsButton());
                stepBochsButton.setIcon(new ImageIcon(
                        getClass().getClassLoader().getResource("com/peterbochs/icons/famfam_icons/step.png")));
                stepBochsButton.setText(MyLanguage.getString("Step"));
                stepBochsButton.setMaximumSize(new java.awt.Dimension(85, 26));
                stepBochsButton.add(getJStep10MenuItem());
                stepBochsButton.add(getJStep100MenuItem());
                stepBochsButton.add(getJStepNMenuItem());
                stepBochsButton.add(getJStepUntilCallOrJumpMenuItem());
                stepBochsButton.add(getJStepUntilRetMenuItem());
                stepBochsButton.add(getJStepUntilIRetMenuItem());
                stepBochsButton.add(getJStepUntilMovMenuItem());
                stepBochsButton.add(getJStepUntilIPBigChangeMenuItem());
                stepBochsButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        stepBochsButtonActionPerformed(evt);
                    }
                });
            }
            {
                nextButton = new JButton();
                nextButton.setIcon(new ImageIcon(
                        getClass().getClassLoader().getResource("com/peterbochs/icons/famfam_icons/step.png")));
                nextButton.setText(MyLanguage.getString("Nexti"));
                nextButton.setToolTipText("c/c++ level step-in");
                jToolBar1.add(nextButton);
                jToolBar1.add(getNextOverButton());
                nextButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        nextButtonActionPerformed(evt);
                    }
                });
            }
            {
                jUpdateBochsButton = new JButton();
                jToolBar1.add(jUpdateBochsButton);
                jToolBar1.add(getJExportToExcelButton());
                jToolBar1.add(getJSettingButton());
                jToolBar1.add(getJRegisterToggleButton());
                jToolBar1.add(getJSourceLevelDebuggerButton());
                jToolBar1.add(getJProfilerToggleButton());
                jToolBar1.add(getJLogToggleButton());
                jToolBar1.add(getJOSLogToggleButton());
                jUpdateBochsButton.setEnabled(true);
                jUpdateBochsButton.setText(MyLanguage.getString("Update"));
                jUpdateBochsButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/peterbochs/icons/famfam_icons/arrow_refresh.png")));
                jUpdateBochsButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jUpdateBochsButtonActionPerformed(evt);
                    }
                });
            }
        }
        {
            jStatusPanel = new JPanel();
            BorderLayout jStatusPanelLayout = new BorderLayout();
            jStatusPanel.setLayout(jStatusPanelLayout);
            getContentPane().add(jStatusPanel, BorderLayout.SOUTH);
            getContentPane().add(getJMainPanel());
            {
                jStatusProgressBar = new JProgressBar();
                jStatusPanel.add(jStatusProgressBar, BorderLayout.WEST);
                jStatusPanel.add(getJPanel25(), BorderLayout.CENTER);
            }
        }
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenu3.setText(MyLanguage.getString("File"));
                {
                    jSeparator2 = new JSeparator();
                    jMenu3.add(jSeparator2);
                }
                {
                    exitMenuItem = new JMenuItem();
                    jMenu3.add(exitMenuItem);
                    exitMenuItem.setText(MyLanguage.getString("Exit"));
                    exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            exitMenuItemActionPerformed(evt);
                        }
                    });
                }
            }
            {
                jMenu4 = new JMenu();
                jMenuBar1.add(jMenu4);
                jMenuBar1.add(getJFontMenu());
                jMenuBar1.add(getJMenu6());
                jMenuBar1.add(getJSystemMenu());
                jMenu4.setText(MyLanguage.getString("Bochs"));
                {
                    startBochsMenuItem = new JMenuItem();
                    jMenu4.add(startBochsMenuItem);
                    startBochsMenuItem.setText(MyLanguage.getString("Start_bochs"));
                    startBochsMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            startBochsMenuItemActionPerformed(evt);
                        }
                    });
                }
                {
                    stopBochsMenuItem = new JMenuItem();
                    jMenu4.add(stopBochsMenuItem);
                    stopBochsMenuItem.setText(MyLanguage.getString("Stop_bochs"));
                    stopBochsMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            stopBochsMenuItemActionPerformed(evt);
                        }
                    });
                }
                {
                    jSeparator1 = new JSeparator();
                    jMenu4.add(jSeparator1);
                }
                {
                    runBochsMenuItem = new JMenuItem();
                    jMenu4.add(runBochsMenuItem);
                    runBochsMenuItem.setText(MyLanguage.getString("Run_bochs"));
                    runBochsMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            runBochsMenuItemActionPerformed(evt);
                        }
                    });
                }
                {
                    pauseBochsMenuItem = new JMenuItem();
                    jMenu4.add(pauseBochsMenuItem);
                    pauseBochsMenuItem.setText(MyLanguage.getString("Pause_bochs"));
                    pauseBochsMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            pauseBochsMenuItemActionPerformed(evt);
                        }
                    });
                }
                {
                    jUpdateBochsStatusMenuItem = new JMenuItem();
                    jMenu4.add(jUpdateBochsStatusMenuItem);
                    jUpdateBochsStatusMenuItem.setText(MyLanguage.getString("Update_bochs_status"));
                    jUpdateBochsStatusMenuItem.setBounds(83, 86, 79, 20);
                    jUpdateBochsStatusMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jUpdateBochsStatusMenuItemActionPerformed(evt);
                        }
                    });
                }
            }
            {
                jMenu5 = new JMenu();
                jMenuBar1.add(jMenu5);
                jMenu5.setText(MyLanguage.getString("Help"));
                {
                    aboutUsMenuItem = new JMenuItem();
                    jMenu5.add(aboutUsMenuItem);
                    jMenu5.add(getJHelpRequestMenuItem());
                    jMenu5.add(getJJVMMenuItem());
                    jMenu5.add(getShortcutHelpMenuItem());
                    jMenu5.add(getJLicenseMenuItem());
                    aboutUsMenuItem.setText(MyLanguage.getString("About_us"));
                    aboutUsMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            aboutUsMenuItemActionPerformed(evt);
                        }
                    });
                }
            }
        }
        if (Setting.getInstance().getWidth() == 0 || Setting.getInstance().getHeight() == 0) {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setSize(screenSize.width * 2 / 3, screenSize.height * 4 / 5);
        } else {
            setSize(Setting.getInstance().getWidth(), Setting.getInstance().getHeight());
        }
        int x = Setting.getInstance().getX();
        int y = Setting.getInstance().getY();
        if (x <= 0 || y <= 0) {
            this.setLocationRelativeTo(null);
        } else {
            setLocation(x, y);
        }

        jSplitPane1.setDividerLocation(Setting.getInstance().getDivX());
        jSplitPane2.setDividerLocation(Setting.getInstance().getDivY());

        jOSDebugInformationPanel1.getjMainSplitPane()
                .setDividerLocation(Setting.getInstance().getOsDebugSplitPane_DividerLocation());
        // pack();
        initGlobalFontSetting(new Font(Setting.getInstance().getFontFamily(), Font.PLAIN,
                Setting.getInstance().getFontsize()));
        jInstrumentPanel.setThing(jStatusProgressBar, jStatusLabel);

        // prevent null jmenuitem
        getJInstructionPanelPopupMenu();
        // end prevent null jmenuitem

        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
            public boolean dispatchKeyEvent(KeyEvent e) {
                if (e.getID() == KeyEvent.KEY_RELEASED) {
                    int keycode = e.getKeyCode();
                    if (keycode == 112) {
                        jTabbedPane3.setSelectedIndex(0);
                    } else if (keycode == 113) {
                        jTabbedPane3.setSelectedIndex(1);
                    } else if (keycode == 114) {
                        jTabbedPane3.setSelectedIndex(2);
                    } else if (keycode == 115) {
                        jTabbedPane3.setSelectedIndex(3);
                    } else if (keycode == 116) {
                        if (startBochsButton.isEnabled()) {
                            startBochsButtonActionPerformed(null);
                        }
                    } else if (keycode == 117) {
                        if (stopBochsButton.isEnabled()) {
                            stopBochsButtonActionPerformed(null);
                        }
                    } else if (keycode == 118) {
                        if (runBochsButton.isEnabled()) {
                            runBochsButtonActionPerformed(null);
                        }
                    } else if (keycode == 119) {
                        if (stepBochsButton.isEnabled()) {
                            stepBochsButtonActionPerformed(null);
                        }
                    } else if (keycode == 120) {
                        if (fastStepBochsButton.isEnabled()) {
                            fastStepButtonActionPerformed(null);
                        }
                    }
                }

                // If the key should not be dispatched to the
                // focused component, set discardEvent to true
                boolean discardEvent = false;
                return discardEvent;
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(ERROR);
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

public static JProgressBar createProgressBar() {
    JProgressBar pb = new JProgressBar();
    setControlSize(pb);
    return pb;
}