/*
 * PreferencesDialog.java
 *
 * Created on 16. August 2005, 14:22
 */

package org.rosuda.JClaR;
import java.awt.Component;
import java.util.prefs.PreferenceChangeListener;
import javax.swing.JPanel;
import javax.swing.SpinnerNumberModel;

/**
 *
 * @author  tobias
 */
public class PreferencesDialog extends javax.swing.JDialog {
    
    private PreferenceChangeListener listener;
    
    private static final int DEFAULT_GRID=50;
    private static final int MIN_GRID=2;
    private static final int MAX_GRID=1000;
    
    /** Creates new form PreferencesDialog */
    PreferencesDialog(final ClassificationWindow owner) {
        super(owner, true);
        listener = owner;
        initComponents();
        
        SpinnerNumberModel snm = new SpinnerNumberModel(DEFAULT_GRID, MIN_GRID, MAX_GRID, 5);
        spinGrid.setModel(snm);
        
        //set tooltip texts
        lblGrid.setToolTipText("granularity for contour plot. [default: " + DEFAULT_GRID + "]");
    }
    
    private void addPreferencesPanel(final String title, final JPanel prefP){
        tabbedPane.add(title,prefP);
    }
    
    int getGrid(){
        return ((Integer)spinGrid.getValue()).intValue();
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        butOk = new javax.swing.JButton();
        tabbedPane = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        lblGrid = new javax.swing.JLabel();
        spinGrid = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        butOk.setText("Ok");
        butOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butOkActionPerformed(evt);
            }
        });

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

        jPanel1.setLayout(new java.awt.GridLayout());

        lblGrid.setText("Grid:");
        jPanel1.add(lblGrid);

        jPanel1.add(spinGrid);

        tabbedPane.addTab("General", jPanel1);

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

        pack();
    }
    // </editor-fold>//GEN-END:initComponents
    
    private void butOkActionPerformed(final java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butOkActionPerformed
        //TODO: determine whether changes have been made and tell listener where
        if(listener!=null) listener.preferenceChange(null);
        hide();
    }//GEN-LAST:event_butOkActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butOk;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblGrid;
    private javax.swing.JSpinner spinGrid;
    private javax.swing.JTabbedPane tabbedPane;
    // End of variables declaration//GEN-END:variables
    
}
