/*
 * PainelCentral.java
 *
 * Created on 28 de Novembro de 2008, 15:42
 */

package ambienteGrafico.componentes;

import ambienteGrafico.componentes.OptionPaneMultiple;
import javax.swing.JFrame;

/**
 *
 * @author  Marília
 */
public class PainelCentral extends MeuPainel {

    private int valor_eixo_y = 10;//10km
    private int valor_eixo_x = 10;
    
    /** Creates new form PainelCentral */
    public PainelCentral() {
        super.mudarLookAndFeel();
        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() {

        bt_Eixos = new javax.swing.JButton();
        js_EixoVertical = new javax.swing.JSlider();
        js_EixoHorizontal = new javax.swing.JSlider();

        setMinimumSize(new java.awt.Dimension(600, 500));
        setPreferredSize(new java.awt.Dimension(600, 500));

        bt_Eixos.setText("("+ valor_eixo_x+","+valor_eixo_y+")");
        bt_Eixos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_EixosActionPerformed(evt);
            }
        });

        js_EixoVertical.setForeground(new java.awt.Color(0, 0, 0));
        js_EixoVertical.setMajorTickSpacing(valor_eixo_y/10);
        js_EixoVertical.setMaximum(valor_eixo_y);
        js_EixoVertical.setMinorTickSpacing(1);
        js_EixoVertical.setOrientation(javax.swing.JSlider.VERTICAL);
        js_EixoVertical.setPaintLabels(true);
        js_EixoVertical.setPaintTicks(true);
        js_EixoVertical.setValue(valor_eixo_y);
        js_EixoVertical.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                js_EixoVerticalStateChanged(evt);
            }
        });

        js_EixoHorizontal.setMajorTickSpacing(valor_eixo_x/10);
        js_EixoHorizontal.setMaximum(valor_eixo_x);
        js_EixoHorizontal.setMinorTickSpacing(1);
        js_EixoHorizontal.setPaintLabels(true);
        js_EixoHorizontal.setPaintTicks(true);
        js_EixoHorizontal.setValue(valor_eixo_x);
        js_EixoHorizontal.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                js_EixoHorizontalStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(10, 10, 10)
                .add(js_EixoHorizontal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bt_Eixos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(js_EixoVertical, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 52, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(js_EixoVertical, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bt_Eixos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 33, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(js_EixoHorizontal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void js_EixoVerticalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_js_EixoVerticalStateChanged
    if (!js_EixoVertical.getValueIsAdjusting()) {
        int valorSlider = (int)js_EixoVertical.getValue();
        valor_eixo_y = valorSlider;
        bt_Eixos.setText("("+ valor_eixo_x+","+valor_eixo_y+")");
    }
}//GEN-LAST:event_js_EixoVerticalStateChanged

private void js_EixoHorizontalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_js_EixoHorizontalStateChanged
    if (!js_EixoHorizontal.getValueIsAdjusting()) {
        int valorSlider = (int)js_EixoHorizontal.getValue();
        valor_eixo_x = valorSlider;
        bt_Eixos.setText("("+ valor_eixo_x+","+valor_eixo_y+")");
    }
}//GEN-LAST:event_js_EixoHorizontalStateChanged

private void bt_EixosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_EixosActionPerformed
    OptionPaneMultiple a =new OptionPaneMultiple();
    String[] valoresMaxDosEixos= a.showInputDialog(valor_eixo_x+"",valor_eixo_y+"");
    if(valoresMaxDosEixos!=null){
        if(!valoresMaxDosEixos[0].equalsIgnoreCase("") && !valoresMaxDosEixos[1].equalsIgnoreCase("")){
                js_EixoHorizontal.setMaximum(Integer.parseInt(valoresMaxDosEixos[0]));
                js_EixoVertical.setMaximum(Integer.parseInt(valoresMaxDosEixos[1]));
        }
    }
}//GEN-LAST:event_bt_EixosActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_Eixos;
    private javax.swing.JSlider js_EixoHorizontal;
    private javax.swing.JSlider js_EixoVertical;
    // End of variables declaration//GEN-END:variables

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame =  new JFrame();
                frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                PainelCentral panel = new PainelCentral();
                panel.setVisible(true);
                frame.setContentPane(panel);
                frame.setVisible(true);
                frame.pack();
            }
        });
    }
}
