package turgen;

import java.awt.Image;
import java.awt.Rectangle;
import turgen.config.Configuration;
import java.awt.event.ActionEvent;
import java.io.File;
import turgen.playlist.AbstractPlayListItem;
import javax.swing.*;
import turgen.output.AudioOutput;

import turgen.output.TapeImageOutput;
import turgen.output.WaveOutput;


/** Main Frame*/
public class TurgenFrame extends javax.swing.JFrame implements UIPersistor {
    
    private JComponent[] daComponents;
    private JComponent[] cwComponents;
    private JComponent[] tiComponents;
    
    /**New instance */
    public TurgenFrame() {
        
        initComponents();
        status=new TurgenStatus(this.jlbMessage);
        
        daComponents= new JComponent[2];
        daComponents[0] = this.jmiDirect;
        daComponents[1] = this.jbtPlayWav;
        
        cwComponents = new JComponent[2];
        cwComponents[0] = this.jmiWave;
        cwComponents[1] = jbtWaveGen;
        
        tiComponents = new JComponent[2];
        tiComponents[0]=this.jmiTapeImage;
        tiComponents[1]=this.jbtTapeImage;
        
        setIconImage(new ImageIcon(getClass().getResource("/turgen/resources/windowicon.png")).getImage());
        
    }
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        fcPlaylist = new javax.swing.JFileChooser();
        jPanel3 = new javax.swing.JPanel();
        jlbMessage = new javax.swing.JLabel();
        pMain = new javax.swing.JPanel();
        jspMain = new javax.swing.JSplitPane();
        pTable = new javax.swing.JPanel();
        jspTableScroll = new javax.swing.JScrollPane();
        tblPlayList = new javax.swing.JTable();
        pMainControlButtons = new javax.swing.JPanel();
        jtbItem = new javax.swing.JToolBar();
        jbtAdd = new javax.swing.JButton();
        jbtEdit = new javax.swing.JButton();
        jbtRemove = new javax.swing.JButton();
        jbtAll = new javax.swing.JButton();
        jbtWizard = new javax.swing.JButton();
        jbtUp = new javax.swing.JButton();
        jbtDown = new javax.swing.JButton();
        jtbGen = new javax.swing.JToolBar();
        jbtWaveGen = new javax.swing.JButton();
        jbtPlayWav = new javax.swing.JButton();
        jbtTapeImage = new javax.swing.JButton();
        jtbFiller = new javax.swing.JToolBar();
        pConsole = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        pProgress = new javax.swing.JPanel();
        jmbMainMenu = new javax.swing.JMenuBar();
        jmTurgen = new javax.swing.JMenu();
        jmiAbout = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jmiExit = new javax.swing.JMenuItem();
        jmPlayList = new javax.swing.JMenu();
        jmiAdd = new javax.swing.JMenuItem();
        jmiEdit = new javax.swing.JMenuItem();
        jmiRemove = new javax.swing.JMenuItem();
        jmiSelectAll = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jmiWizard = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        jmiLoadPlayList = new javax.swing.JMenuItem();
        jmiSavePlayList = new javax.swing.JMenuItem();
        jmGenerator = new javax.swing.JMenu();
        jmiWave = new javax.swing.JMenuItem();
        jmiDirect = new javax.swing.JMenuItem();
        jmiTapeImage = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        jmiPostProcessingEnabled = new javax.swing.JCheckBoxMenuItem();
        jmiTapeImagePostProcessingEnabled = new javax.swing.JCheckBoxMenuItem();
        jmTools = new javax.swing.JMenu();
        jmiMerge = new javax.swing.JMenuItem();
        jmiDecoder = new javax.swing.JMenuItem();
        jmiPackBasicToBinary = new javax.swing.JMenuItem();
        jmiTapeImageExtractor = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JSeparator();
        jmiPreferences = new javax.swing.JMenuItem();
        jmiSavePreferences = new javax.swing.JMenuItem();
        jmiReloadConfig = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle(Turgen.version);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                window_closing(evt);
            }
        });
        getContentPane().setLayout(new java.awt.BorderLayout(0, 4));

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 1));

        jlbMessage.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
        jlbMessage.setText("Ready");
        jPanel3.add(jlbMessage);

        getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);

        pMain.setLayout(new java.awt.BorderLayout());
        getContentPane().add(pMain, java.awt.BorderLayout.CENTER);

        jspMain.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jspMain.setResizeWeight(0.75);

        pTable.setLayout(new java.awt.BorderLayout(2, 2));

        jspTableScroll.setPreferredSize(new java.awt.Dimension(450, 320));

        tblPlayList.setModel(Turgen.playList);
        tblPlayList.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tblPlayList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                on_tblPlayListClicked(evt);
            }
        });
        jspTableScroll.setViewportView(tblPlayList);

        pTable.add(jspTableScroll, java.awt.BorderLayout.CENTER);

        pMainControlButtons.setPreferredSize(new java.awt.Dimension(350, 40));
        pMainControlButtons.setLayout(new java.awt.GridBagLayout());

        jtbItem.setFloatable(false);
        jtbItem.setRollover(true);

        jbtAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_add.png"))); // NOI18N
        jbtAdd.setToolTipText("Add item to playlist");
        jbtAdd.setAlignmentY(0.0F);
        jbtAdd.setFocusable(false);
        jbtAdd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtAdd.setIconTextGap(0);
        jbtAdd.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtAdd.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtAdd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAddActionPerformed(evt);
            }
        });
        jtbItem.add(jbtAdd);

        jbtEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_edit.png"))); // NOI18N
        jbtEdit.setToolTipText("Edit selected playlist item");
        jbtEdit.setAlignmentY(0.0F);
        jbtEdit.setFocusable(false);
        jbtEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtEdit.setIconTextGap(0);
        jbtEdit.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtEdit.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtEdit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtEditActionPerformed(evt);
            }
        });
        jtbItem.add(jbtEdit);

        jbtRemove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_delete.png"))); // NOI18N
        jbtRemove.setToolTipText("Remove selected playlist items");
        jbtRemove.setAlignmentY(0.0F);
        jbtRemove.setFocusable(false);
        jbtRemove.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtRemove.setIconTextGap(0);
        jbtRemove.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtRemove.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtRemove.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtRemove.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtRemoveActionPerformed(evt);
            }
        });
        jtbItem.add(jbtRemove);

        jbtAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_all.png"))); // NOI18N
        jbtAll.setToolTipText("Select all playlist items");
        jbtAll.setAlignmentY(0.0F);
        jbtAll.setFocusable(false);
        jbtAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtAll.setIconTextGap(0);
        jbtAll.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtAll.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtAll.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAllActionPerformed(evt);
            }
        });
        jtbItem.add(jbtAll);

        jbtWizard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_wiz.png"))); // NOI18N
        jbtWizard.setToolTipText("Wizard for binary files");
        jbtWizard.setAlignmentY(0.0F);
        jbtWizard.setFocusable(false);
        jbtWizard.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtWizard.setIconTextGap(0);
        jbtWizard.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtWizard.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtWizard.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtWizard.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtWizard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtWizardActionPerformed(evt);
            }
        });
        jtbItem.add(jbtWizard);

        jbtUp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_up_small.png"))); // NOI18N
        jbtUp.setToolTipText("Move 1 playlist item up");
        jbtUp.setAlignmentY(0.0F);
        jbtUp.setFocusable(false);
        jbtUp.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtUp.setIconTextGap(0);
        jbtUp.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jbtUp.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtUp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                on_moveUp(evt);
            }
        });
        jtbItem.add(jbtUp);

        jbtDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_down_small.png"))); // NOI18N
        jbtDown.setToolTipText("Move 1 playlist item down");
        jbtDown.setAlignmentY(0.0F);
        jbtDown.setFocusable(false);
        jbtDown.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtDown.setIconTextGap(0);
        jbtDown.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jbtDown.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtDown.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                on_moveDown(evt);
            }
        });
        jtbItem.add(jbtDown);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        pMainControlButtons.add(jtbItem, gridBagConstraints);

        jtbGen.setFloatable(false);
        jtbGen.setRollover(true);

        jbtWaveGen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_wave.png"))); // NOI18N
        jbtWaveGen.setMnemonic('W');
        jbtWaveGen.setToolTipText("Generate WAVE file");
        jbtWaveGen.setAlignmentY(0.0F);
        jbtWaveGen.setFocusable(false);
        jbtWaveGen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtWaveGen.setIconTextGap(0);
        jbtWaveGen.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtWaveGen.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtWaveGen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtWaveGen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtWaveGen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtWaveGenActionPerformed(evt);
            }
        });
        jtbGen.add(jbtWaveGen);

        jbtPlayWav.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_direct.png"))); // NOI18N
        jbtPlayWav.setMnemonic('d');
        jbtPlayWav.setToolTipText("Generate AUDIO directly");
        jbtPlayWav.setAlignmentY(0.0F);
        jbtPlayWav.setFocusable(false);
        jbtPlayWav.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtPlayWav.setIconTextGap(0);
        jbtPlayWav.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtPlayWav.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtPlayWav.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtPlayWav.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtPlayWav.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtPlayWavActionPerformed(evt);
            }
        });
        jtbGen.add(jbtPlayWav);

        jbtTapeImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_instructions.png"))); // NOI18N
        jbtTapeImage.setMnemonic('i');
        jbtTapeImage.setToolTipText("Generate tape image");
        jbtTapeImage.setAlignmentY(0.0F);
        jbtTapeImage.setFocusable(false);
        jbtTapeImage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtTapeImage.setIconTextGap(0);
        jbtTapeImage.setMargin(new java.awt.Insets(1, 2, 1, 2));
        jbtTapeImage.setPreferredSize(new java.awt.Dimension(36, 36));
        jbtTapeImage.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtTapeImage.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                onButtonsMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                onButtonsMouseExited(evt);
            }
        });
        jbtTapeImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtTapeImageActionPerformed(evt);
            }
        });
        jtbGen.add(jbtTapeImage);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        pMainControlButtons.add(jtbGen, gridBagConstraints);

        jtbFiller.setFloatable(false);
        jtbFiller.setRollover(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        pMainControlButtons.add(jtbFiller, gridBagConstraints);

        pTable.add(pMainControlButtons, java.awt.BorderLayout.SOUTH);

        jspMain.setLeftComponent(pTable);

        pConsole.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        pProgress.setLayout(new javax.swing.BoxLayout(pProgress, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane1.setViewportView(pProgress);

        pConsole.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jspMain.setRightComponent(pConsole);

        getContentPane().add(jspMain, java.awt.BorderLayout.CENTER);

        jmbMainMenu.setBorder(null);

        jmTurgen.setMnemonic('T');
        jmTurgen.setText("Turgen");
        jmTurgen.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

        jmiAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/help-browser.png"))); // NOI18N
        jmiAbout.setMnemonic('A');
        jmiAbout.setText("About...");
        jmiAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                on_about(evt);
            }
        });
        jmTurgen.add(jmiAbout);
        jmTurgen.add(jSeparator1);

        jmiExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK));
        jmiExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/system-log-out.png"))); // NOI18N
        jmiExit.setMnemonic('X');
        jmiExit.setText("Exit program");
        jmiExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiExit_actionPerformed(evt);
            }
        });
        jmTurgen.add(jmiExit);

        jmbMainMenu.add(jmTurgen);

        jmPlayList.setMnemonic('P');
        jmPlayList.setText("Playlist");
        jmPlayList.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

        jmiAdd.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        jmiAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/document-new.png"))); // NOI18N
        jmiAdd.setMnemonic('A');
        jmiAdd.setText("Add item...");
        jmiAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiAddActionPerformed(evt);
            }
        });
        jmPlayList.add(jmiAdd);

        jmiEdit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
        jmiEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/document-open.png"))); // NOI18N
        jmiEdit.setMnemonic('E');
        jmiEdit.setText("Edit item...");
        jmiEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiEditActionPerformed(evt);
            }
        });
        jmPlayList.add(jmiEdit);

        jmiRemove.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
        jmiRemove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/edit-delete.png"))); // NOI18N
        jmiRemove.setMnemonic('R');
        jmiRemove.setText("Remove selected items");
        jmiRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiRemoveActionPerformed(evt);
            }
        });
        jmPlayList.add(jmiRemove);

        jmiSelectAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_all_small.png"))); // NOI18N
        jmiSelectAll.setMnemonic('i');
        jmiSelectAll.setText("Select all items");
        jmiSelectAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSelectAllActionPerformed(evt);
            }
        });
        jmPlayList.add(jmiSelectAll);
        jmPlayList.add(jSeparator3);

        jmiWizard.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
        jmiWizard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_wiz_small.png"))); // NOI18N
        jmiWizard.setText("Wizard for binary files...");
        jmiWizard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onWizardMenuItem(evt);
            }
        });
        jmPlayList.add(jmiWizard);
        jmPlayList.add(jSeparator4);

        jmiLoadPlayList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiLoadPlayList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/document-open.png"))); // NOI18N
        jmiLoadPlayList.setMnemonic('L');
        jmiLoadPlayList.setText("Load...");
        jmiLoadPlayList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLoadPlayList_actionPerformed(evt);
            }
        });
        jmPlayList.add(jmiLoadPlayList);

        jmiSavePlayList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiSavePlayList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/document-save.png"))); // NOI18N
        jmiSavePlayList.setMnemonic('S');
        jmiSavePlayList.setText("Save...");
        jmiSavePlayList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSavePlayList_actionPerformed(evt);
            }
        });
        jmPlayList.add(jmiSavePlayList);

        jmbMainMenu.add(jmPlayList);

        jmGenerator.setMnemonic('G');
        jmGenerator.setText("Generator");
        jmGenerator.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

        jmiWave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.ALT_MASK));
        jmiWave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/media-playback-start.png"))); // NOI18N
        jmiWave.setMnemonic('W');
        jmiWave.setText("Generate WAVE file");
        jmiWave.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jmiWave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiWaveActionPerformed(evt);
            }
        });
        jmGenerator.add(jmiWave);

        jmiDirect.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK));
        jmiDirect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/audio-card.png"))); // NOI18N
        jmiDirect.setMnemonic('D');
        jmiDirect.setText("Generate AUDIO directly");
        jmiDirect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiDirectActionPerformed(evt);
            }
        });
        jmGenerator.add(jmiDirect);

        jmiTapeImage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
        jmiTapeImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/turgen/resources/action_instructions_small.png"))); // NOI18N
        jmiTapeImage.setMnemonic('C');
        jmiTapeImage.setText("Generate tape image");
        jmiTapeImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiTapeImageActionPerformed(evt);
            }
        });
        jmGenerator.add(jmiTapeImage);
        jmGenerator.add(jSeparator5);

        jmiPostProcessingEnabled.setMnemonic('p');
        jmiPostProcessingEnabled.setText("WAVE postprocessing");
        jmGenerator.add(jmiPostProcessingEnabled);

        jmiTapeImagePostProcessingEnabled.setMnemonic('s');
        jmiTapeImagePostProcessingEnabled.setText("Tape image postprocessing");
        jmGenerator.add(jmiTapeImagePostProcessingEnabled);

        jmbMainMenu.add(jmGenerator);

        jmTools.setMnemonic('o');
        jmTools.setText("Tools");
        jmTools.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

        jmiMerge.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK));
        jmiMerge.setMnemonic('M');
        jmiMerge.setText("Merge segments of binary file...");
        jmiMerge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiMergeActionPerformed(evt);
            }
        });
        jmTools.add(jmiMerge);

        jmiDecoder.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiDecoder.setMnemonic('d');
        jmiDecoder.setText("Turbo decoder...");
        jmiDecoder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                on_turboDecoder(evt);
            }
        });
        jmTools.add(jmiDecoder);

        jmiPackBasicToBinary.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiPackBasicToBinary.setMnemonic('B');
        jmiPackBasicToBinary.setText("Embed BASIC to binary file...");
        jmiPackBasicToBinary.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onEmbedBasicToBinary(evt);
            }
        });
        jmTools.add(jmiPackBasicToBinary);

        jmiTapeImageExtractor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiTapeImageExtractor.setMnemonic('T');
        jmiTapeImageExtractor.setText("Tape image extractor...");
        jmiTapeImageExtractor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onTapeImageExtractor(evt);
            }
        });
        jmTools.add(jmiTapeImageExtractor);
        jmTools.add(jSeparator6);

        jmiPreferences.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jmiPreferences.setMnemonic('p');
        jmiPreferences.setText("Preferences...");
        jmiPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiPreferencesActionPerformed(evt);
            }
        });
        jmTools.add(jmiPreferences);

        jmiSavePreferences.setMnemonic('s');
        jmiSavePreferences.setText("Save preferences");
        jmiSavePreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSavePreferencesActionPerformed(evt);
            }
        });
        jmTools.add(jmiSavePreferences);

        jmiReloadConfig.setText("Reload preferences");
        jmiReloadConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiReloadConfigActionPerformed(evt);
            }
        });
        jmTools.add(jmiReloadConfig);

        jmbMainMenu.add(jmTools);

        setJMenuBar(jmbMainMenu);

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

    private void showNoFilesToGenerateFrom() {
        JOptionPane.showMessageDialog(this, "<HTML>No playlist items selected !<BR>To convert files, select some playlist items first.</HTML>","Warning",JOptionPane.WARNING_MESSAGE);
    }

    private void on_moveDown(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_on_moveDown
        int[] i=this.tblPlayList.getSelectedRows();
        if (i==null || i.length<1) return;
        if (i.length>1) {
            JOptionPane.showMessageDialog(this,"Exactly one playlist item can be moved","Warning",JOptionPane.WARNING_MESSAGE);
        }
        else {
            if (Turgen.playList.moveItemDown(i[0])) {
                tblPlayList.getSelectionModel().setSelectionInterval(i[0]+1,i[0]+1);
            }
        }
    }//GEN-LAST:event_on_moveDown

    private void on_moveUp(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_on_moveUp
        int[] i=this.tblPlayList.getSelectedRows();
        if (i==null || i.length<1) return;
        if (i.length>1) {
            JOptionPane.showMessageDialog(this,"Exactly one playlist item can be moved","Warning",JOptionPane.WARNING_MESSAGE);
        }
        else {
            if (Turgen.playList.moveItemUp(i[0])) {
                tblPlayList.getSelectionModel().setSelectionInterval(i[0]-1,i[0]-1);
            }
        }
    }//GEN-LAST:event_on_moveUp

    private void jmiDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiDirectActionPerformed
        this.jbtPlayWavActionPerformed(evt);
    }//GEN-LAST:event_jmiDirectActionPerformed

    private void jmiWaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiWaveActionPerformed
        this.jbtWaveGenActionPerformed(evt);
    }//GEN-LAST:event_jmiWaveActionPerformed

    private void on_about(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_on_about
        /*About...*/
        String msg = Turgen.getProgramInfoString();
        JOptionPane.showMessageDialog(this,msg,"About",JOptionPane.INFORMATION_MESSAGE);
        
    }//GEN-LAST:event_on_about
    
    private void jbtPlayWavActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtPlayWavActionPerformed
        Thread xt = new Thread(new Runnable() {
            public void run() {
                on_direct_play();
            }
        });
        xt.start();
    }//GEN-LAST:event_jbtPlayWavActionPerformed
    
    private void jbtWaveGenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtWaveGenActionPerformed
       Thread xt = new Thread(new Runnable() {
            public void run() {
                on_wave_gen();
            }
        });
        xt.start();
    }//GEN-LAST:event_jbtWaveGenActionPerformed
    
    private void jmiRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiRemoveActionPerformed
        jbtRemoveActionPerformed(evt);
    }//GEN-LAST:event_jmiRemoveActionPerformed
    
    private void jmiEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiEditActionPerformed
        jbtEditActionPerformed(evt);
    }//GEN-LAST:event_jmiEditActionPerformed
    
    private void jmiAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiAddActionPerformed
        jbtAddActionPerformed(evt);
    }//GEN-LAST:event_jmiAddActionPerformed
        
    private void jbtAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAllActionPerformed
        this.tblPlayList.selectAll();
    }//GEN-LAST:event_jbtAllActionPerformed
    
    private void jbtRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtRemoveActionPerformed
        int[] i = this.tblPlayList.getSelectedRows();
        if (i.length<1) return;
        int k=0;
        for(int c=0;c<i.length;c++) {
            
            Turgen.playList.removeItem(i[c]-c);
            
        }
    }//GEN-LAST:event_jbtRemoveActionPerformed
    
    private void jbtEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtEditActionPerformed
        
        int i=this.tblPlayList.getSelectedRow();
        editPlaylistRow(i);
        
    }//GEN-LAST:event_jbtEditActionPerformed
    
    private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAddActionPerformed
        boolean shift = ((evt.getModifiers() & ActionEvent.SHIFT_MASK)==0)?false:true;
        
        if (shift==false) Turgen.dlm.dlgRecord.clear(true);
        Turgen.dlm.dlgRecord.setVisible(true);
        AbstractPlayListItem apr = Turgen.dlm.dlgRecord.getLastItem();
        if (apr!=null) Turgen.playList.addItem(apr);
    }//GEN-LAST:event_jbtAddActionPerformed
        
    private void window_closing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_window_closing
        Turgen.exit();
    }//GEN-LAST:event_window_closing
    
    private void jmiMergeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiMergeActionPerformed
        Turgen.dlm.setMergeTransientDialogVisible();
        
    }//GEN-LAST:event_jmiMergeActionPerformed
        
    private void jmiExit_actionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiExit_actionPerformed
        Turgen.exit();
    }//GEN-LAST:event_jmiExit_actionPerformed
    
    private void jmiSavePlayList_actionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiSavePlayList_actionPerformed
        
        if(fcPlaylist.showSaveDialog(this)!=JFileChooser.APPROVE_OPTION) return;
        File f = fcPlaylist.getSelectedFile();
        
        if (f!=null) {
            Turgen.savePlaylist(f.getAbsolutePath());
        }
    }//GEN-LAST:event_jmiSavePlayList_actionPerformed
    
    private void miLoadPlayList_actionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadPlayList_actionPerformed
        if(fcPlaylist.showOpenDialog(this)!=JFileChooser.APPROVE_OPTION) return;
        File f = fcPlaylist.getSelectedFile();
        
        if (f!=null) {
            Turgen.loadPlaylist(f.getAbsolutePath());
        }
    }//GEN-LAST:event_miLoadPlayList_actionPerformed

    private void jbtTapeImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtTapeImageActionPerformed
         Thread xt = new Thread(new Runnable() {
            public void run() {
                on_tape_image();
            }
        });
        xt.start();
}//GEN-LAST:event_jbtTapeImageActionPerformed

    private void jmiReloadConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiReloadConfigActionPerformed
        Configuration.loadOptions();
    }//GEN-LAST:event_jmiReloadConfigActionPerformed

    private void jmiTapeImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiTapeImageActionPerformed
        this.jbtTapeImageActionPerformed(evt);
}//GEN-LAST:event_jmiTapeImageActionPerformed

    private void jmiPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPreferencesActionPerformed
        /*Show preferences*/
        JPanel p = Configuration.getConfigPanel();
        if (p!=null) {
            Turgen.dlm.dlgConfig.setConfigPanel(p);
        }
        Turgen.dlm.dlgConfig.setVisible(true);
    }//GEN-LAST:event_jmiPreferencesActionPerformed

    private void jmiSavePreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiSavePreferencesActionPerformed
        String s = Configuration.saveOptions();
        JOptionPane.showMessageDialog(null, s);
    }//GEN-LAST:event_jmiSavePreferencesActionPerformed

private void on_tblPlayListClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_on_tblPlayListClicked
    if (evt.getClickCount()!=2) return;
    int index = tblPlayList.rowAtPoint(evt.getPoint());
    editPlaylistRow(index);
    
}//GEN-LAST:event_on_tblPlayListClicked

private void on_turboDecoder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_on_turboDecoder
    Turgen.dlm.frmDecoder.setVisible(true);
}//GEN-LAST:event_on_turboDecoder

private void jbtWizardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtWizardActionPerformed
    Turgen.dlm.setWizardTransientDialogVisible(true);
}//GEN-LAST:event_jbtWizardActionPerformed

private void onWizardMenuItem(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onWizardMenuItem
    jbtWizardActionPerformed(evt);
}//GEN-LAST:event_onWizardMenuItem

private void jmiSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiSelectAllActionPerformed
    jbtAllActionPerformed(evt);
}//GEN-LAST:event_jmiSelectAllActionPerformed

private void onButtonsMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onButtonsMouseEntered
    JButton b= (JButton)evt.getSource();
    b.setContentAreaFilled(true);

}//GEN-LAST:event_onButtonsMouseEntered

private void onButtonsMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onButtonsMouseExited
    JButton b= (JButton)evt.getSource();
    b.setContentAreaFilled(false);

}//GEN-LAST:event_onButtonsMouseExited

    private void onEmbedBasicToBinary(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onEmbedBasicToBinary
        Turgen.dlm.setEmbedBasicTransientDialogVisible();
        
    }//GEN-LAST:event_onEmbedBasicToBinary

    private void onTapeImageExtractor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onTapeImageExtractor
        Turgen.dlm.setExtractorTransientDialogVisible();
    }//GEN-LAST:event_onTapeImageExtractor


private void editPlaylistRow(int index) {
    if (index >= 0 && index < tblPlayList.getRowCount()) {
        AbstractPlayListItem apr = Turgen.playList.getItem(index);
        if (Turgen.dlm.dlgRecord.prepareEdit(apr) == false) {
            JOptionPane.showMessageDialog(this, "Unable to edit playlist item. Plugin " + apr.pluginClass + " is not loaded.","Unable to edit playlist item",JOptionPane.ERROR_MESSAGE);
            return;
        }
        Turgen.dlm.dlgRecord.setVisible(true);
        AbstractPlayListItem pl = Turgen.dlm.dlgRecord.getLastItem();
        if (pl != null) {
            Turgen.playList.replaceItem(index, pl);
        }
    }
}

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TurgenFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser fcPlaylist;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JButton jbtAdd;
    private javax.swing.JButton jbtAll;
    private javax.swing.JButton jbtDown;
    private javax.swing.JButton jbtEdit;
    private javax.swing.JButton jbtPlayWav;
    private javax.swing.JButton jbtRemove;
    private javax.swing.JButton jbtTapeImage;
    private javax.swing.JButton jbtUp;
    private javax.swing.JButton jbtWaveGen;
    private javax.swing.JButton jbtWizard;
    private javax.swing.JLabel jlbMessage;
    private javax.swing.JMenu jmGenerator;
    private javax.swing.JMenu jmPlayList;
    private javax.swing.JMenu jmTools;
    private javax.swing.JMenu jmTurgen;
    private javax.swing.JMenuBar jmbMainMenu;
    private javax.swing.JMenuItem jmiAbout;
    private javax.swing.JMenuItem jmiAdd;
    private javax.swing.JMenuItem jmiDecoder;
    private javax.swing.JMenuItem jmiDirect;
    private javax.swing.JMenuItem jmiEdit;
    private javax.swing.JMenuItem jmiExit;
    private javax.swing.JMenuItem jmiLoadPlayList;
    private javax.swing.JMenuItem jmiMerge;
    private javax.swing.JMenuItem jmiPackBasicToBinary;
    private javax.swing.JCheckBoxMenuItem jmiPostProcessingEnabled;
    private javax.swing.JMenuItem jmiPreferences;
    private javax.swing.JMenuItem jmiReloadConfig;
    private javax.swing.JMenuItem jmiRemove;
    private javax.swing.JMenuItem jmiSavePlayList;
    private javax.swing.JMenuItem jmiSavePreferences;
    private javax.swing.JMenuItem jmiSelectAll;
    private javax.swing.JMenuItem jmiTapeImage;
    private javax.swing.JMenuItem jmiTapeImageExtractor;
    private javax.swing.JCheckBoxMenuItem jmiTapeImagePostProcessingEnabled;
    private javax.swing.JMenuItem jmiWave;
    private javax.swing.JMenuItem jmiWizard;
    private javax.swing.JSplitPane jspMain;
    private javax.swing.JScrollPane jspTableScroll;
    private javax.swing.JToolBar jtbFiller;
    private javax.swing.JToolBar jtbGen;
    private javax.swing.JToolBar jtbItem;
    private javax.swing.JPanel pConsole;
    private javax.swing.JPanel pMain;
    private javax.swing.JPanel pMainControlButtons;
    public javax.swing.JPanel pProgress;
    private javax.swing.JPanel pTable;
    private javax.swing.JTable tblPlayList;
    // End of variables declaration//GEN-END:variables
    
    
    private TurgenStatus status;
    
    /**WAVE file generation. This method is called in separate thread*/
    private void on_wave_gen() {
         /*Rows selected*/
        int i=this.tblPlayList.getSelectedRowCount();
        
        /*At least one row selected*/
        if (i!=0) {
            int[] rows=this.tblPlayList.getSelectedRows();
            WaveOutput.processPlaylistItems(rows, cwComponents,status,this.jmiPostProcessingEnabled.isSelected());
        }
        else showNoFilesToGenerateFrom();
    }
    
    /**Direct output to audio system. In separate thread
     */
    private void on_direct_play() {
        
        /*Rows selected*/
        int i=this.tblPlayList.getSelectedRowCount();
        
        /*At least one row selected*/
        if (i!=0) {
            int[] rows=this.tblPlayList.getSelectedRows();
            AudioOutput.processPlaylistItems(rows, daComponents,status);
        }
        else showNoFilesToGenerateFrom();
        
        
    }
    
     private void on_tape_image() {
        
        /*Rows selected*/
        int i=this.tblPlayList.getSelectedRowCount();
        
        /*At least one row selected*/
        if (i!=0) {
            int[] rows=this.tblPlayList.getSelectedRows();
            TapeImageOutput.processPlaylistItems(rows, tiComponents, status,this.jmiTapeImagePostProcessingEnabled.isSelected());
            
        }
        else showNoFilesToGenerateFrom();
    }
    
    
    public void setPostProcessingMenuItem(boolean b) {
        this.jmiPostProcessingEnabled.setSelected(b);
    }
    
    public void setTapeImagePostProcessingMenuItem(boolean b) {
        this.jmiTapeImagePostProcessingEnabled.setSelected(b);
    }
    
    public TurgenStatus getStatusObject() {
        return status;
    }

    void setFileDialogDirectiories(String[] d) {
        fcPlaylist.setCurrentDirectory(new File(d[0]));
    }
    
    void updateFileDialogUI() {
        SwingUtilities.updateComponentTreeUI(fcPlaylist);
    }

    public Object[] getPersistenceData() {

        Object[] pData = new Object[7];

        /*Bounds and frame stare*/
        pData[0]=this.getBounds();
        pData[1]=new Integer(this.getExtendedState());

        /*File dialog directories*/
        pData[2]=fcPlaylist.getCurrentDirectory().getAbsolutePath();

        /*Column sizes in playlist*/
        int cc = tblPlayList.getColumnCount();
        int[] colSizes = new int[cc];
        for(int i=0;i<cc;i++) {
            colSizes[i]=tblPlayList.getColumn(tblPlayList.getColumnName(i)).getWidth();
        }
        pData[3]=colSizes;

        /*JSplitPane location*/
        pData[4]=new Integer(jspMain.getDividerLocation());

        /*Postprocessing control*/
        pData[5]=new Boolean(jmiPostProcessingEnabled.isSelected());
        pData[6]=new Boolean(jmiTapeImagePostProcessingEnabled.isSelected());

        return pData;
        

    }

    public void setPersistenceData(Object[] data) throws Exception {

        /*Bounds and frame stare*/
        this.setBounds((Rectangle)data[0]);
        this.setExtendedState(((Integer)data[1]).intValue());

        /*File dialog directories*/
        fcPlaylist.setCurrentDirectory(new File((String)data[2]));

        /*Column sizes in playlist*/
        int[] colSizes = (int[])data[3];
        for(int i=0;i<colSizes.length;i++) {
            tblPlayList.getColumn(tblPlayList.getColumnName(i)).setWidth(colSizes[i]);
            tblPlayList.getColumn(tblPlayList.getColumnName(i)).setPreferredWidth(colSizes[i]);
        }

        /*JSplitPane location*/
        jspMain.setDividerLocation(((Integer)data[4]).intValue());

        /*Postprocessing control*/
        jmiPostProcessingEnabled.setSelected(((Boolean)data[5]).booleanValue());
        jmiTapeImagePostProcessingEnabled.setSelected(((Boolean)data[6]).booleanValue());
        

    }

    public String getPersistenceId() {
        return getClass().getName();
    }

    public void setPersistenceDefaults() {
    }
 
}
