import java.lang.*;
import java.util.*;
import java.io.*;

import javax.swing.event.*; 
import javax.swing.*;   
import javax.swing.table.*;
      
import java.awt.*;
import java.awt.event.*;                       
import java.awt.datatransfer.*;

import javax.imageio.*;
import java.awt.image.*;
import java.util.zip.*;

public class new_song_dialogc extends JDialog implements ActionListener{
  JLabel notes_per_octave_label;
  JTextField notes_per_octave_field;
  JLabel num_octaves_label;
  JTextField num_octaves_field;
  JLabel base_freq_label;
  JTextField base_freq_field;
  JLabel octave_cents_label;
  JTextField octave_cents_field;
  JLabel name_label;
  JTextField name_field;
  boolean result;
  new_song_dialogc(Frame owner,String title) {
    super(owner,title,true);
    setBounds(20,20,200,200);
    this.getContentPane().setLayout(new GridLayout(6,2));

    notes_per_octave_label = new JLabel("notes per octave:");
    this.getContentPane().add(notes_per_octave_label);
    notes_per_octave_field = new JTextField(Integer.toString(main_app.notes_per_octave));
    this.getContentPane().add(notes_per_octave_field);

    num_octaves_label = new JLabel("number of octaves:");
    this.getContentPane().add(num_octaves_label);
    num_octaves_field = new JTextField(Integer.toString(main_app.num_octaves));
    this.getContentPane().add(num_octaves_field);

    base_freq_label = new JLabel("lowest note freq:");
    this.getContentPane().add(base_freq_label);
    base_freq_field = new JTextField(Integer.toString(main_app.base_freq));
    this.getContentPane().add(base_freq_field);

    octave_cents_label = new JLabel("octave_cents:");
    this.getContentPane().add(octave_cents_label);
    octave_cents_field = new JTextField(Integer.toString(main_app.octave_cents));
    this.getContentPane().add(octave_cents_field);

    name_label = new JLabel("name of first pattern:");
    this.getContentPane().add(name_label);
    name_field = new JTextField("pattern");
    this.getContentPane().add(name_field);

    create_button("ok","ok");
    create_button("cancel","cancel");  
  }
  public void show() {
    super.show();
    notes_per_octave_field.setText(Integer.toString(main_app.notes_per_octave));
    num_octaves_field.setText(Integer.toString(main_app.num_octaves));
    base_freq_field.setText(Integer.toString(main_app.base_freq));
    octave_cents_field.setText(Integer.toString(main_app.octave_cents));
  }
  public void actionPerformed(ActionEvent e) {        
    String action = e.getActionCommand();
    //System.out.println(action);
    if (action.equals("ok")) {
      int old_vol = main_app.pattern_player.volume;
      main_app.pattern_player.volume = 0;
      if (main_app.song_modified == true) {
        main_app.save_song_prompt();
      }
      main_app.pattern_player.volume = old_vol;      
      main_app.notes_per_octave = Integer.parseInt(notes_per_octave_field.getText());
      main_app.num_octaves = Integer.parseInt(num_octaves_field.getText());
      main_app.base_freq = Integer.parseInt(base_freq_field.getText());
      main_app.octave_cents = Integer.parseInt(octave_cents_field.getText());

      main_app.pattern_player.paused = true;
      main_panelc.setup_scale34(main_app.notes_per_octave);
      main_app.new_song(main_app.notes_per_octave,name_field.getText()); 
      main_app.song_player.create_players();

      //pattern_list_model.update_pattern_list_ids();
      main_app.pattern_list_window.update_list_box();
      main_app.song_modified = false;
      result = true;
      main_app.main_panel.update_size();
      if (main_app.tunning_table_window.isVisible()) {
        main_app.tunning_table_window.show();
      }
      if (main_app.prime_table_window != null) {
        if (main_app.prime_table_window.isVisible()) {      
          main_app.prime_table_window.show();
        }
      }
      hide();
    }
    if (action.equals("cancel")) {
      result = false;         
      hide();
    }
  }
  boolean OK_Clicked() {
    return result;
  }
  JButton create_button(String text,String action) {  
    JButton button = new JButton(text);
    button.setActionCommand(action);    
    button.addActionListener(this);
    this.getContentPane().add(button);
    return button;
  }
}

