pl.dpbz.poid.zadanie4.gui.GUI.java Source code

Java tutorial

Introduction

Here is the source code for pl.dpbz.poid.zadanie4.gui.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.zadanie4.gui;

import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import pl.dpbz.poid.zadanie3.chart.ChartDrawer;
import pl.dpbz.poid.zadanie3.converter.WaveToSamplesConverter;
import pl.dpbz.poid.zadanie4.*;
import pl.dpbz.poid.zadanie4.equalizer.Equalizer;
import pl.dpbz.poid.zadanie4.filter.SOIFilter;
import pl.dpbz.poid.zadanie4.filter.SOIFilterConvolution;
import pl.dpbz.poid.zadanie4.filter.SOIFilterEqualizer;
import pl.dpbz.poid.zadanie4.filter.SOIFilterSpectrum;
import pl.dpbz.poid.zadanie4.filter.SOIWahWah;
import pl.dpbz.poid.zadanie4.soi.WindowType;
import pl.dpbz.poid.zadanie4.utils.SamplesToWave;

/**
 *
 * @author bzielinski91
 */
public class GUI extends javax.swing.JFrame {
    private File f = new File("");
    private WindowType typeOfWindow = WindowType.VON_HANN;
    private SOIFilter filter = new SOIFilterSpectrum();
    private Equalizer eq = new Equalizer();
    private Integer[] samples;
    private AudioFormat af;
    private SOIWahWah filterWahWah = new SOIWahWah();

    /**
     * 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() {

        fileOpenJButton = new javax.swing.JButton();
        signalStartChartJPanel = new javax.swing.JPanel();
        filterSpectrumJRadioButton = new javax.swing.JRadioButton();
        filterConvolutionJRadioButton = new javax.swing.JRadioButton();
        NjTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        MjTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        RjTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        LjTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        FcJTextField = new javax.swing.JTextField();
        SquareJRadioButton = new javax.swing.JRadioButton();
        hanningJRadioButton = new javax.swing.JRadioButton();
        hammingJRadioButton = new javax.swing.JRadioButton();
        filterEqualizerJRadioButton = new javax.swing.JRadioButton();
        jSlider0 = new javax.swing.JSlider();
        jSlider1 = new javax.swing.JSlider();
        jSlider2 = new javax.swing.JSlider();
        jSlider3 = new javax.swing.JSlider();
        jSlider4 = new javax.swing.JSlider();
        signalOutputChartJPanel = new javax.swing.JPanel();
        updateChangesJButton = new javax.swing.JButton();
        saveJButton = new javax.swing.JButton();
        wahWahJRadioButton = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        amplifyJTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        frequencyJTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        LeftSideFreqJTextField = new javax.swing.JTextField();
        RighttSideFreqJTextField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        widhtJTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

        javax.swing.GroupLayout signalStartChartJPanelLayout = new javax.swing.GroupLayout(signalStartChartJPanel);
        signalStartChartJPanel.setLayout(signalStartChartJPanelLayout);
        signalStartChartJPanelLayout.setHorizontalGroup(signalStartChartJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 930, Short.MAX_VALUE));
        signalStartChartJPanelLayout.setVerticalGroup(signalStartChartJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 315, Short.MAX_VALUE));

        filterSpectrumJRadioButton.setSelected(true);
        filterSpectrumJRadioButton.setText("Spectrum");
        filterSpectrumJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterSpectrumJRadioButtonActionPerformed(evt);
            }
        });

        filterConvolutionJRadioButton.setText("Convolution");
        filterConvolutionJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterConvolutionJRadioButtonActionPerformed(evt);
            }
        });

        NjTextField.setText("11");
        NjTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NjTextFieldActionPerformed(evt);
            }
        });

        jLabel1.setText("N:");

        jLabel2.setText("M:");

        MjTextField.setText("1024");

        jLabel3.setText("R:");

        RjTextField.setText("1024");

        jLabel4.setText("L:");

        LjTextField.setText("1024");

        jLabel5.setText("Fc:");

        FcJTextField.setText("500");

        SquareJRadioButton.setText("Square");
        SquareJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SquareJRadioButtonActionPerformed(evt);
            }
        });

        hanningJRadioButton.setSelected(true);
        hanningJRadioButton.setText("Hanning");
        hanningJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hanningJRadioButtonActionPerformed(evt);
            }
        });

        hammingJRadioButton.setText("Hamming");
        hammingJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hammingJRadioButtonActionPerformed(evt);
            }
        });

        filterEqualizerJRadioButton.setText("Equalizer");
        filterEqualizerJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterEqualizerJRadioButtonActionPerformed(evt);
            }
        });

        jSlider0.setMajorTickSpacing(1);
        jSlider0.setMaximum(10);
        jSlider0.setMinimum(-10);
        jSlider0.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider0.setPaintTicks(true);
        jSlider0.setSnapToTicks(true);
        jSlider0.setToolTipText("");
        jSlider0.setValue(1);

        jSlider1.setMajorTickSpacing(1);
        jSlider1.setMaximum(10);
        jSlider1.setMinimum(-10);
        jSlider1.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider1.setPaintTicks(true);
        jSlider1.setSnapToTicks(true);
        jSlider1.setValue(1);

        jSlider2.setMajorTickSpacing(1);
        jSlider2.setMaximum(10);
        jSlider2.setMinimum(-10);
        jSlider2.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider2.setPaintTicks(true);
        jSlider2.setSnapToTicks(true);
        jSlider2.setValue(1);

        jSlider3.setMajorTickSpacing(1);
        jSlider3.setMaximum(10);
        jSlider3.setMinimum(-10);
        jSlider3.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider3.setPaintTicks(true);
        jSlider3.setSnapToTicks(true);
        jSlider3.setValue(1);

        jSlider4.setMajorTickSpacing(1);
        jSlider4.setMaximum(10);
        jSlider4.setMinimum(-10);
        jSlider4.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider4.setPaintTicks(true);
        jSlider4.setSnapToTicks(true);
        jSlider4.setToolTipText("");
        jSlider4.setValue(1);

        javax.swing.GroupLayout signalOutputChartJPanelLayout = new javax.swing.GroupLayout(
                signalOutputChartJPanel);
        signalOutputChartJPanel.setLayout(signalOutputChartJPanelLayout);
        signalOutputChartJPanelLayout.setHorizontalGroup(signalOutputChartJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        signalOutputChartJPanelLayout.setVerticalGroup(signalOutputChartJPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 315, Short.MAX_VALUE));

        updateChangesJButton.setText("Update changes");
        updateChangesJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateChangesJButtonActionPerformed(evt);
            }
        });

        saveJButton.setText("Save to file");
        saveJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveJButtonActionPerformed(evt);
            }
        });

        wahWahJRadioButton.setText("WahWah");
        wahWahJRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wahWahJRadioButtonActionPerformed(evt);
            }
        });

        jLabel6.setText("Amplify:");

        amplifyJTextField.setText("2");

        jLabel7.setText("Frequency:");

        frequencyJTextField.setText("5");

        jLabel8.setText("Left side freq:");

        LeftSideFreqJTextField.setText("200");

        RighttSideFreqJTextField.setText("800");

        jLabel9.setText("Right side freq:");

        jLabel10.setText("Width:");

        widhtJTextField.setText("20");

        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)
                        .addGroup(layout.createSequentialGroup().addGap(42, 42, 42).addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(35, 35, 35)
                                        .addComponent(fileOpenJButton))
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(NjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(MjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(RjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addGap(39, 39, 39).addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(LjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(FcJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addComponent(SquareJRadioButton)
                                        .addGap(18, 18, 18).addComponent(hanningJRadioButton).addGap(18, 18, 18)
                                        .addComponent(hammingJRadioButton))
                                .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(saveJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 163,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup().addGap(29, 29, 29).addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jSlider0,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jSlider1,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jSlider2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jSlider3,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jSlider4,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(updateChangesJButton)))))
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(amplifyJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(frequencyJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                50, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup().addGap(15, 15, 15)
                                .addComponent(filterSpectrumJRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(filterConvolutionJRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(filterEqualizerJRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(wahWahJRadioButton))
                        .addGroup(layout.createSequentialGroup().addGap(31, 31, 31).addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addComponent(jLabel10)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(widhtJTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(LeftSideFreqJTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jLabel9)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(RighttSideFreqJTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(signalStartChartJPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(signalOutputChartJPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup().addComponent(fileOpenJButton).addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(filterSpectrumJRadioButton)
                                        .addComponent(filterConvolutionJRadioButton)
                                        .addComponent(filterEqualizerJRadioButton).addComponent(wahWahJRadioButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(NjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel1)
                                                .addComponent(MjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel2)
                                                .addComponent(RjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(LjTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel4)
                                        .addComponent(FcJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(amplifyJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel6)
                                        .addComponent(frequencyJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel7))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(LeftSideFreqJTextField,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel8)
                                        .addComponent(RighttSideFreqJTextField,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel9))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(widhtJTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(SquareJRadioButton).addComponent(hanningJRadioButton)
                                        .addComponent(hammingJRadioButton))
                                .addGap(18, 18, 18)
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jSlider0, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jSlider4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jSlider3, javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(40, 40, 40)
                                .addComponent(updateChangesJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(saveJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                                .addComponent(signalStartChartJPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(signalOutputChartJPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(28, Short.MAX_VALUE)));

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

    private void fileOpenJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileOpenJButtonActionPerformed
        // TODO otwiera plik dwikowy
        this.f = new File(readSoundFile());

        try {

            this.samples = WaveToSamplesConverter.convertWaveToIntSamples(this.f);
            this.af = WaveToSamplesConverter.getAudioFormat(this.f);

            updateChartStartSignal();

            if (this.wahWahJRadioButton.isSelected()) {
                setAndComputeForWahWah();
                updateChartOutputSignalForWahWah();
            } else {

                setAndCompute();
                updateChartOutputSignal();
            }

        } 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_fileOpenJButtonActionPerformed

    private void setAndComputeForWahWah() {
        this.filterWahWah.setAmplify(Integer.parseInt(this.amplifyJTextField.getText()));
        this.filterWahWah.setFrequency(Integer.parseInt(this.frequencyJTextField.getText()));
        this.filterWahWah.setLeftSideFreq(Integer.parseInt(this.LeftSideFreqJTextField.getText()));
        this.filterWahWah.setRightSideFreq(Integer.parseInt(this.RighttSideFreqJTextField.getText()));
        this.filterWahWah.setWidth(Integer.parseInt(this.widhtJTextField.getText()));
        this.filterWahWah.setM(Integer.parseInt(this.MjTextField.getText()));
        this.filterWahWah.setN(Integer.parseInt(this.NjTextField.getText()));
        this.filterWahWah.setR(Integer.parseInt(this.RjTextField.getText()));
        this.filterWahWah.setSignalWindows(samples);
        filterWahWah.computeFilter();
        //ChartDrawer.drawChart(filterWahWah.getOutputSignal(), "Wah Wah Muachachacha");
    }

    private void setAndCompute() {

        setSlidersEqualizer();

        filter.setN(Integer.parseInt(this.NjTextField.getText())); //d
        filter.setM(Integer.parseInt(this.MjTextField.getText()));
        filter.setR(Integer.parseInt(this.RjTextField.getText()));
        filter.setL(Integer.parseInt(this.LjTextField.getText()));
        filter.setFc(Integer.parseInt(this.FcJTextField.getText()));
        this.filter.setWindowType(WindowType.VON_HANN);
        System.out.println("Okna");
        this.filter.setSignalWindows(this.samples);
        System.out.println("Odpowied impulsowa");
        this.filter.computeLowPassFilterParameters();
        System.out.println("Widma");
        this.filter.computeFilter();
    }

    private void updateChartOutputSignal() {
        JFreeChart chart = ChartDrawer.drawChart(this.filter.getOutputSignal(), "output signal");

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

    private void updateChartOutputSignalForWahWah() {
        JFreeChart chart = ChartDrawer.drawChart(this.filterWahWah.getOutputSignal(), "WahWah");
        ChartPanel cp = new ChartPanel(chart);
        this.signalOutputChartJPanel.removeAll();
        this.signalOutputChartJPanel.setLayout(new java.awt.BorderLayout());
        this.signalOutputChartJPanel.add(cp, BorderLayout.CENTER);
        this.signalOutputChartJPanel.validate();
    }

    private void filterSpectrumJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterSpectrumJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.filterConvolutionJRadioButton.setSelected(false);
        this.filterEqualizerJRadioButton.setSelected(false);
        this.wahWahJRadioButton.setSelected(false);
        this.filter = new SOIFilterSpectrum();
    }//GEN-LAST:event_filterSpectrumJRadioButtonActionPerformed

    private void filterConvolutionJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterConvolutionJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.filterSpectrumJRadioButton.setSelected(false);
        this.filterEqualizerJRadioButton.setSelected(false);
        this.wahWahJRadioButton.setSelected(false);
        this.filter = new SOIFilterConvolution();
    }//GEN-LAST:event_filterConvolutionJRadioButtonActionPerformed

    private void SquareJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SquareJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.hanningJRadioButton.setSelected(false);
        this.hammingJRadioButton.setSelected(false);
        this.typeOfWindow = WindowType.SQUARE;
    }//GEN-LAST:event_SquareJRadioButtonActionPerformed

    private void hanningJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hanningJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.SquareJRadioButton.setSelected(false);
        this.hammingJRadioButton.setSelected(false);
        this.typeOfWindow = WindowType.VON_HANN;
    }//GEN-LAST:event_hanningJRadioButtonActionPerformed

    private void hammingJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hammingJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.SquareJRadioButton.setSelected(false);
        this.hanningJRadioButton.setSelected(false);
        this.typeOfWindow = WindowType.HAMMING;
    }//GEN-LAST:event_hammingJRadioButtonActionPerformed

    private void filterEqualizerJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterEqualizerJRadioButtonActionPerformed
        // TODO add your handling code here:
        this.filterSpectrumJRadioButton.setSelected(false);
        this.filterConvolutionJRadioButton.setSelected(false);
        this.wahWahJRadioButton.setSelected(false);

        setSlidersEqualizer();

        this.filter = new SOIFilterEqualizer(this.eq);

    }//GEN-LAST:event_filterEqualizerJRadioButtonActionPerformed

    private void updateChangesJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateChangesJButtonActionPerformed
        // TODO update Changes
        if (this.wahWahJRadioButton.isSelected()) {
            setAndComputeForWahWah();
            updateChartOutputSignalForWahWah();
        } else {
            setAndCompute();
            updateChartOutputSignal();
        }
    }//GEN-LAST:event_updateChangesJButtonActionPerformed

    private void saveJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveJButtonActionPerformed
        // TODO save sound to file
        JFileChooser fc = new JFileChooser();
        fc.showSaveDialog(this);
        String path = fc.getSelectedFile().getAbsolutePath();
        path += ".wav";
        SamplesToWave saver;

        if (this.wahWahJRadioButton.isSelected()) {
            saver = new SamplesToWave(44100, this.filterWahWah.getOutputSignal(), this.af);

        } else {
            saver = new SamplesToWave(SOIFilter.SAMPLING_FREQUENCY, this.filter.getOutputSignal(), this.af);
        }

        try {
            saver.saveWave(path);
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Zapisane");

    }//GEN-LAST:event_saveJButtonActionPerformed

    private void NjTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NjTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NjTextFieldActionPerformed

    private void wahWahJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wahWahJRadioButtonActionPerformed
        // TODO wybierz efekt wah wah
        this.filterSpectrumJRadioButton.setSelected(false);
        this.filterEqualizerJRadioButton.setSelected(false);
        this.filterConvolutionJRadioButton.setSelected(false);
    }//GEN-LAST:event_wahWahJRadioButtonActionPerformed

    private void setSlidersEqualizer() {
        System.out.println(this.jSlider0.getValue());
        System.out.println(this.jSlider1.getValue());
        System.out.println(this.jSlider2.getValue());
        System.out.println(this.jSlider3.getValue());
        System.out.println(this.jSlider4.getValue());
        this.eq.getSliders().get(0).setEdge(this.jSlider0.getValue());
        this.eq.getSliders().get(1).setEdge(this.jSlider1.getValue());
        this.eq.getSliders().get(2).setEdge(this.jSlider2.getValue());
        this.eq.getSliders().get(3).setEdge(this.jSlider3.getValue());
        this.eq.getSliders().get(4).setEdge(this.jSlider4.getValue());
    }

    private void updateChartStartSignal() {

        JFreeChart chart = ChartDrawer.drawChart(this.samples, "start signal");
        ChartPanel cp = new ChartPanel(chart);
        this.signalStartChartJPanel.removeAll();
        this.signalStartChartJPanel.setLayout(new java.awt.BorderLayout());
        this.signalStartChartJPanel.add(cp, BorderLayout.CENTER);
        this.signalStartChartJPanel.validate();
    }

    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;
    }

    /**
     * @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 FcJTextField;
    private javax.swing.JTextField LeftSideFreqJTextField;
    private javax.swing.JTextField LjTextField;
    private javax.swing.JTextField MjTextField;
    private javax.swing.JTextField NjTextField;
    private javax.swing.JTextField RighttSideFreqJTextField;
    private javax.swing.JTextField RjTextField;
    private javax.swing.JRadioButton SquareJRadioButton;
    private javax.swing.JTextField amplifyJTextField;
    private javax.swing.JButton fileOpenJButton;
    private javax.swing.JRadioButton filterConvolutionJRadioButton;
    private javax.swing.JRadioButton filterEqualizerJRadioButton;
    private javax.swing.JRadioButton filterSpectrumJRadioButton;
    private javax.swing.JTextField frequencyJTextField;
    private javax.swing.JRadioButton hammingJRadioButton;
    private javax.swing.JRadioButton hanningJRadioButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    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.JSlider jSlider0;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JSlider jSlider2;
    private javax.swing.JSlider jSlider3;
    private javax.swing.JSlider jSlider4;
    private javax.swing.JButton saveJButton;
    private javax.swing.JPanel signalOutputChartJPanel;
    private javax.swing.JPanel signalStartChartJPanel;
    private javax.swing.JButton updateChangesJButton;
    private javax.swing.JRadioButton wahWahJRadioButton;
    private javax.swing.JTextField widhtJTextField;
    // End of variables declaration//GEN-END:variables
}