pl.dpbz.poid.zadanie3.GUI.java Source code

Java tutorial

Introduction

Here is the source code for pl.dpbz.poid.zadanie3.GUI.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.dpbz.poid.zadanie3;

import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import pl.dpbz.poid.zadanie3.converter.CombFilteringSampleConverter;
import pl.dpbz.poid.zadanie3.converter.PhaseSpaceSampleConverter;
import pl.dpbz.poid.zadanie3.converter.SamplesToWaveConverter;
import pl.dpbz.poid.zadanie3.converter.WaveToSamplesConverter;
import pl.dpbz.poid.zadanie3.fourier.CombFiltering;
import pl.dpbz.poid.zadanie3.phase.Maps;
import pl.dpbz.poid.zadanie3.phase.PhaseSpaceMultiDimensional;
import pl.dpbz.poid.zadanie3.sound.ComplexSound;
import pl.dpbz.poid.zadanie3.sound.Sound;

/**
 *
 * @author bzielinski91
 */
public class GUI extends javax.swing.JFrame {
    private File f = new File("");

    /**
     * Creates new form GUI
     */
    public GUI() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        wczytajPlikJButton1 = new javax.swing.JButton();
        chartJPanel1 = new javax.swing.JPanel();
        chartJPanel2 = new javax.swing.JPanel();
        savePhaseJButton1 = new javax.swing.JButton();
        samplesPerPartJTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        saveCombJButton1 = new javax.swing.JButton();
        chartJPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        combFrequencyJLabel5 = new javax.swing.JLabel();
        phaseFrequencyJLabel4 = new javax.swing.JLabel();
        phaseFreqencyJTextField1 = new javax.swing.JTextField();
        combFreqencyJTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        combAmplitudejTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        combVerticesCountJTextField1 = new javax.swing.JTextField();
        updateJButton = new javax.swing.JButton();
        chartJPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        spaceSizeJTextField1 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        windowJTextField2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        kJTextField1 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        startSampleJTextField1 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        limitJTextField1 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        edgeForHistogramJTextField1 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        minHistogramPartsJTextField1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        histogramIntervalJTextField1 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        bitsJTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        wczytajPlikJButton1.setText("Wczytaj plik dwikowy");
        wczytajPlikJButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wczytajPlikJButton1ActionPerformed(evt);
            }
        });

        chartJPanel1.setMaximumSize(new java.awt.Dimension(800, 135));

        javax.swing.GroupLayout chartJPanel1Layout = new javax.swing.GroupLayout(chartJPanel1);
        chartJPanel1.setLayout(chartJPanel1Layout);
        chartJPanel1Layout.setHorizontalGroup(chartJPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 800, Short.MAX_VALUE));
        chartJPanel1Layout.setVerticalGroup(chartJPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE));

        chartJPanel2.setMaximumSize(new java.awt.Dimension(800, 135));

        javax.swing.GroupLayout chartJPanel2Layout = new javax.swing.GroupLayout(chartJPanel2);
        chartJPanel2.setLayout(chartJPanel2Layout);
        chartJPanel2Layout.setHorizontalGroup(chartJPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 800, Short.MAX_VALUE));
        chartJPanel2Layout.setVerticalGroup(chartJPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE));

        savePhaseJButton1.setText("Zapisz sekw. na fazie");
        savePhaseJButton1.setEnabled(false);
        savePhaseJButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                savePhaseJButton1ActionPerformed(evt);
            }
        });

        samplesPerPartJTextField1.setText("3000");

        jLabel1.setText("Prbki na okno:");

        saveCombJButton1.setText("Zapisz sekw. na grzeb.");
        saveCombJButton1.setEnabled(false);
        saveCombJButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveCombJButton1ActionPerformed(evt);
            }
        });

        chartJPanel4.setMaximumSize(new java.awt.Dimension(800, 135));
        chartJPanel4.setPreferredSize(new java.awt.Dimension(800, 140));

        javax.swing.GroupLayout chartJPanel4Layout = new javax.swing.GroupLayout(chartJPanel4);
        chartJPanel4.setLayout(chartJPanel4Layout);
        chartJPanel4Layout.setHorizontalGroup(chartJPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 800, Short.MAX_VALUE));
        chartJPanel4Layout.setVerticalGroup(chartJPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Przestrze fazowa");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Filtracja grzebieniowa");

        combFrequencyJLabel5.setText("Czstotliwo podstawowa: ");

        phaseFrequencyJLabel4.setText("Czstotliwo podstawowa: ");

        phaseFreqencyJTextField1.setEnabled(false);

        combFreqencyJTextField1.setEnabled(false);

        jLabel4.setText("Amplituda:");

        combAmplitudejTextField1.setText("500000");

        jLabel5.setText("Liczba wierzchokw:");

        combVerticesCountJTextField1.setText("10");

        updateJButton.setText("Aktualizuj");
        updateJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateJButtonActionPerformed(evt);
            }
        });

        chartJPanel3.setMaximumSize(new java.awt.Dimension(800, 135));
        chartJPanel3.setPreferredSize(new java.awt.Dimension(800, 140));

        javax.swing.GroupLayout chartJPanel3Layout = new javax.swing.GroupLayout(chartJPanel3);
        chartJPanel3.setLayout(chartJPanel3Layout);
        chartJPanel3Layout.setHorizontalGroup(chartJPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 800, Short.MAX_VALUE));
        chartJPanel3Layout.setVerticalGroup(chartJPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE));

        jLabel6.setText("Space size:");

        spaceSizeJTextField1.setText("15");

        jLabel7.setText("Window:");

        windowJTextField2.setText("1000");

        jLabel8.setText("K:");

        kJTextField1.setText("2");

        jLabel9.setText("Start sample:");

        startSampleJTextField1.setText("3500");

        jLabel10.setText("Limit:");

        limitJTextField1.setText("10");

        jLabel11.setText("Edge for histogram:");

        edgeForHistogramJTextField1.setText("0.05");

        jLabel12.setText("Min histogram parts:");

        minHistogramPartsJTextField1.setText("70");

        jLabel13.setText("Histogram interval:");

        histogramIntervalJTextField1.setText("100");

        jLabel14.setText("Licza bitw:");

        bitsJTextField1.setText("15");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(chartJPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(chartJPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(chartJPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(chartJPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGap(36, 36, 36).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(jLabel2,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(wczytajPlikJButton1,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup()
                                                                .addComponent(phaseFrequencyJLabel4)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(phaseFreqencyJTextField1,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 260,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addGroup(layout.createSequentialGroup()
                                                                        .addGap(33, 33, 33)
                                                                        .addGroup(layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                .addGroup(layout
                                                                                        .createSequentialGroup()
                                                                                        .addComponent(jLabel8)
                                                                                        .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                        .addComponent(kJTextField1,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                51,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                .addGroup(layout
                                                                                        .createSequentialGroup()
                                                                                        .addComponent(jLabel6)
                                                                                        .addPreferredGap(
                                                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                        .addComponent(
                                                                                                spaceSizeJTextField1,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                52,
                                                                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                                .addGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        layout.createSequentialGroup()
                                                                                .addGap(71, 71, 71)
                                                                                .addComponent(jLabel10)
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addComponent(limitJTextField1,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        49,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addGroup(layout.createSequentialGroup()
                                                                                .addGap(128, 128, 128)
                                                                                .addGroup(layout
                                                                                        .createParallelGroup(
                                                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                                                        .addGroup(layout
                                                                                                .createSequentialGroup()
                                                                                                .addComponent(
                                                                                                        jLabel7)
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                                .addComponent(
                                                                                                        windowJTextField2,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                        55,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                                        .addGroup(layout
                                                                                                .createSequentialGroup()
                                                                                                .addComponent(
                                                                                                        jLabel9)
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                .addComponent(
                                                                                                        startSampleJTextField1,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                                        55,
                                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                                        .addGroup(layout.createSequentialGroup()
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        Short.MAX_VALUE)
                                                                                .addComponent(jLabel11)
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                .addComponent(
                                                                                        edgeForHistogramJTextField1,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        52,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup().addGap(161, 161, 161)
                                                                .addComponent(updateJButton,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 123,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel12)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(minHistogramPartsJTextField1,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 46,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(104, 104, 104).addComponent(jLabel13)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(histogramIntervalJTextField1))))
                                        .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(jLabel3,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup()
                                                                .addComponent(combFrequencyJLabel5)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(combFreqencyJTextField1))
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup().addGap(21, 21, 21)
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING)
                                                                        .addGroup(layout.createSequentialGroup()
                                                                                .addComponent(jLabel5)
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addComponent(
                                                                                        combVerticesCountJTextField1,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        62,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                                        .addGroup(layout.createSequentialGroup()
                                                                                .addComponent(jLabel4)
                                                                                .addPreferredGap(
                                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                .addComponent(
                                                                                        combAmplitudejTextField1,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        65,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addGap(105, 105, 105).addComponent(jLabel14)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(bitsJTextField1,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 48,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                        .addGap(39, 41, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        layout.createSequentialGroup().addGap(52, 52, 52)
                                                                .addComponent(jLabel1).addGap(18, 18, 18)
                                                                .addComponent(samplesPerPartJTextField1,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 43,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                        .createSequentialGroup().addComponent(savePhaseJButton1)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(saveCombJButton1)))
                                        .addGap(57, 57, 57)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup().addComponent(wczytajPlikJButton1)
                                .addGap(40, 40, 40).addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(phaseFrequencyJLabel4).addComponent(phaseFreqencyJTextField1,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(8, 8, 8)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel6)
                                        .addComponent(spaceSizeJTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel7).addComponent(windowJTextField2,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(chartJPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(chartJPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel8)
                                                .addComponent(kJTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel9).addComponent(startSampleJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel10)
                                                .addComponent(limitJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel11).addComponent(edgeForHistogramJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel12)
                                                .addComponent(minHistogramPartsJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel13).addComponent(histogramIntervalJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(chartJPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel3).addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(combFrequencyJLabel5)
                                                .addComponent(combFreqencyJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel4).addComponent(combAmplitudejTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel5)
                                                .addComponent(combVerticesCountJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel14).addComponent(bitsJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(chartJPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(51, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(updateJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(samplesPerPartJTextField1,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel1))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(savePhaseJButton1).addComponent(saveCombJButton1))
                                        .addGap(24, 24, 24)))));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void wczytajPlikJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wczytajPlikJButton1ActionPerformed
        // TODO wczytaj plik dwikowy

        //File f = new File(readSoundFile());
        this.f = new File(readSoundFile());

        this.savePhaseJButton1.setEnabled(true);
        this.saveCombJButton1.setEnabled(true);

        updateCharts();
    }//GEN-LAST:event_wczytajPlikJButton1ActionPerformed

    private void updateCharts() {
        try {
            Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(f);
            double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(f);

            //prosty dwik za pomoc fazwki
            computeFrequencyByPhaseSpace(ints, samplingFrequency);

            //zoony dwik
            computeFrequencyForComplexSound(ints, samplingFrequency);

            drawChartOfSoundSignal(ints, samplingFrequency);

            System.out.println("FINISHED");

        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void savePhaseJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePhaseJButton1ActionPerformed
        try {
            // TODO zapis sekwencji na fazie do pliku
            JFileChooser fc = new JFileChooser();
            fc.showSaveDialog(this);
            String path = fc.getSelectedFile().getAbsolutePath();
            path += ".wav";

            Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f);
            double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f);
            System.out.println("Samples overview " + ints.length);

            int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText());
            SamplesToWaveConverter conv = new PhaseSpaceSampleConverter(samplingFrequency, samplesPerPart,
                    WaveToSamplesConverter.getAudioFormat(f));

            conv.setupFrequenciesFromSamples(ints);
            System.out.println("Zapisuj");

            conv.saveGeneratedSamples(path);
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_savePhaseJButton1ActionPerformed

    private void saveCombJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCombJButton1ActionPerformed
        try {
            // TODO zapisz sekwencje na grzebieniu
            //Test sekwencji na grzebieniu
            JFileChooser fc = new JFileChooser();
            fc.showSaveDialog(this);
            String path = fc.getSelectedFile().getAbsolutePath();
            path += ".wav";

            Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f);
            double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f);
            System.out.println("Samples overview " + ints.length);

            int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText());

            SamplesToWaveConverter conv2 = new CombFilteringSampleConverter(samplingFrequency, samplesPerPart,
                    WaveToSamplesConverter.getAudioFormat(f));

            conv2.setupFrequenciesFromSamples(ints);
            System.out.println("Zapisuj");
            conv2.saveGeneratedSamples(path);
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_saveCombJButton1ActionPerformed

    private void updateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateJButtonActionPerformed
        // TODO update 
        updateCharts();
    }//GEN-LAST:event_updateJButtonActionPerformed

    private String readSoundFile() {
        final JFileChooser fc = new JFileChooser();
        fc.setAcceptAllFileFilterUsed(false);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("WAV sounds", "wav");
        fc.addChoosableFileFilter(filter);
        int returnVal = fc.showOpenDialog(this);
        String path = fc.getSelectedFile().getAbsolutePath();
        System.out.println("path: " + path);

        return path;
    }

    private void computeFrequencyByPhaseSpace(Integer[] ints, double samplingFrequency) {
        //Zwyky sound, ktry nie potrzebuje zespolonych elementw
        Sound s = new Sound(ints, samplingFrequency);

        //Obliczenie czstotliwoci przy pomocy fazwki
        PhaseSpaceMultiDimensional pS = new PhaseSpaceMultiDimensional(s);

        pS.setSpaceSize(Integer.parseInt(this.spaceSizeJTextField1.getText()));
        pS.setWindow(Integer.parseInt(this.windowJTextField2.getText()));
        pS.setK(Integer.parseInt(this.kJTextField1.getText()));
        pS.setStartSample(Integer.parseInt(this.startSampleJTextField1.getText()));
        pS.setStartingComputingSample(Integer.parseInt(this.limitJTextField1.getText()));
        pS.setEdgeForHistogram(Double.parseDouble(this.edgeForHistogramJTextField1.getText()));
        pS.setMinHistogramParts(Integer.parseInt(this.minHistogramPartsJTextField1.getText()));
        pS.setHistogramInterval(Integer.parseInt(this.histogramIntervalJTextField1.getText()));

        pS.setupPhaseSpace();

        Maps maps = new Maps();
        maps = pS.computeFrequency();

        ChartPanel cp1 = new ChartPanel(pS.drawElements(maps.getMap()));
        this.chartJPanel1.removeAll();
        this.chartJPanel1.setLayout(new java.awt.BorderLayout());
        this.chartJPanel1.add(cp1, BorderLayout.CENTER);
        this.chartJPanel1.validate();

        ChartPanel cp2 = new ChartPanel(pS.drawHistogram(maps.getHistogramWithoutZeros()));
        this.chartJPanel2.removeAll();
        this.chartJPanel2.setLayout(new java.awt.BorderLayout());
        this.chartJPanel2.add(cp2, BorderLayout.CENTER);
        this.chartJPanel2.validate();

        System.out.println("Phase space " + pS.getFrequency());
        this.phaseFreqencyJTextField1.setText(Double.toString(pS.getFrequency()));
    }

    private void computeFrequencyForComplexSound(Integer[] ints, double samplingFrequency) {
        //Zespolony dwik, ktry jest bardziej zoony
        ComplexSound cs = new ComplexSound(ints, samplingFrequency, 15);
        cs.setBits(Integer.parseInt(this.bitsJTextField1.getText()));
        //To oblicza fouriera
        cs.setupElementsOfComplexSound();
        //Tutaj obliczanie czstotliwoci przy pomocy fouriera
        CombFiltering cf = new CombFiltering(cs, samplingFrequency);

        cf.setCombAmplitude(Double.parseDouble(this.combAmplitudejTextField1.getText()));
        cf.setCombVerticesCount(Integer.parseInt(this.combVerticesCountJTextField1.getText()));

        cf.computeFrequency();
        ChartPanel cp3 = new ChartPanel(cf.drawComplexSound());
        this.chartJPanel3.removeAll();
        this.chartJPanel3.setLayout(new java.awt.BorderLayout());
        this.chartJPanel3.add(cp3, BorderLayout.CENTER);
        this.chartJPanel3.validate();

        System.out.println("Comb Filtering " + cf.getFrequency());
        this.combFreqencyJTextField1.setText(Double.toString(cf.getFrequency()));
    }

    private void drawChartOfSoundSignal(Integer[] ints, double samplingFrequency) {
        //Rysowanie wykresu sygnau dwikowego
        final XYSeries dist = new XYSeries("P0");
        int index = 0;
        for (Integer i : ints) {
            dist.add(index / samplingFrequency, i);
            index++;
        }
        final XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(dist);

        JFreeChart chart = ChartFactory.createXYLineChart(f.getName(), "index", "Distance", dataset,
                PlotOrientation.VERTICAL, true, true, false);
        XYPlot xyPlot = (XYPlot) chart.getPlot();
        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setRangeCrosshairVisible(true);
        XYItemRenderer renderer = xyPlot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        NumberAxis domain = (NumberAxis) xyPlot.getRangeAxis();
        domain.setRange(-32768, 32768);
        //ChartDrawer.drawChart(chart);

        ChartPanel cp4 = new ChartPanel(chart);
        this.chartJPanel4.removeAll();
        this.chartJPanel4.setLayout(new java.awt.BorderLayout());
        this.chartJPanel4.add(cp4, BorderLayout.CENTER);
        this.chartJPanel4.validate();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField bitsJTextField1;
    private javax.swing.JPanel chartJPanel1;
    private javax.swing.JPanel chartJPanel2;
    private javax.swing.JPanel chartJPanel3;
    private javax.swing.JPanel chartJPanel4;
    private javax.swing.JTextField combAmplitudejTextField1;
    private javax.swing.JTextField combFreqencyJTextField1;
    private javax.swing.JLabel combFrequencyJLabel5;
    private javax.swing.JTextField combVerticesCountJTextField1;
    private javax.swing.JTextField edgeForHistogramJTextField1;
    private javax.swing.JTextField histogramIntervalJTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField kJTextField1;
    private javax.swing.JTextField limitJTextField1;
    private javax.swing.JTextField minHistogramPartsJTextField1;
    private javax.swing.JTextField phaseFreqencyJTextField1;
    private javax.swing.JLabel phaseFrequencyJLabel4;
    private javax.swing.JTextField samplesPerPartJTextField1;
    private javax.swing.JButton saveCombJButton1;
    private javax.swing.JButton savePhaseJButton1;
    private javax.swing.JTextField spaceSizeJTextField1;
    private javax.swing.JTextField startSampleJTextField1;
    private javax.swing.JButton updateJButton;
    private javax.swing.JButton wczytajPlikJButton1;
    private javax.swing.JTextField windowJTextField2;
    // End of variables declaration//GEN-END:variables
}