Package jrackattack.gui

Source Code of jrackattack.gui.CrackPanel

/* For License see bottom */
/*
* CrackPanel.java
*
* Created on 25. Juli 2007, 20:23
*/

package jrackattack.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import jonkoshare.util.VersionInformation;
import jrackattack.midi.MidiThread;
import jrackattack.midi.RackAttack;
import jrackattack.midi.SoundParameter;

import org.jdesktop.layout.GroupLayout;

/**
*
* @author  methke01
*/
@VersionInformation (
  lastChanged="$LastChangedDate: 2009-09-15 14:15:46 -0500 (Tue, 15 Sep 2009) $",
  authors={"Alexander Methke"},
  revision="$LastChangedRevision: 15 $",
  lastEditor="$LastChangedBy: onkobu $",
  id="$Id"
)
public class CrackPanel extends JPanel {
 
  /** Creates new form CrackPanel */
  public CrackPanel() {
    initiating=true;
    initComponents();
    initValues();
    initiating=false;
  }
 
  protected void initValues() {
    ((SpinnerNumberModel)speedSpinner.getModel()).setMinimum(0);
    ((SpinnerNumberModel)speedSpinner.getModel()).setMaximum(127);
    speedSpinner.setValue(new Integer(0));
    ((SpinnerNumberModel)mixSpinner.getModel()).setMinimum(0);
    ((SpinnerNumberModel)mixSpinner.getModel()).setMaximum(127);
    mixSpinner.setValue(new Integer(0));
    ((SpinnerNumberModel)lengthSpinner.getModel()).setMinimum(0);
    ((SpinnerNumberModel)lengthSpinner.getModel()).setMaximum(50);
    lengthSpinner.setValue(new Integer(0));
  }
 
  public void soundParameterChanged(SoundParameter sp) {
    initiating=true;
    mixKnob.setIntValue(sp.getCrackLevel());
    lengthKnob.setIntValue(sp.getCrackLength());
    speedKnob.setIntValue(sp.getCrackSpeed());
    syncSpinner();
    initiating=false;
  }
 
  protected void syncSpinner() {
    mixSpinner.setValue(new Integer(mixKnob.getIntValue()));
    lengthSpinner.setValue(new Integer(lengthKnob.getIntValue()));
    speedSpinner.setValue(new Integer(speedKnob.getIntValue()));
  }
 
  /** 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 ">
    private void initComponents() {
        GridBagConstraints gridBagConstraints;

        speedKnob = new JKnob();
        lengthKnob = new JKnob();
        mixKnob = new JKnob();
        speedSpinner = new JSpinner();
        lengthSpinner = new JSpinner();
        mixSpinner = new JSpinner();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();

        setLayout(new GridBagLayout());

        speedKnob.setIntValue(0);
        speedKnob.setMaximumValue(127);
        speedKnob.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                speedKnobStateChanged(evt);
            }
        });

        GroupLayout speedKnobLayout = new GroupLayout(speedKnob);
        speedKnob.setLayout(speedKnobLayout);
        speedKnobLayout.setHorizontalGroup(
            speedKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        speedKnobLayout.setVerticalGroup(
            speedKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(speedKnob, gridBagConstraints);

        lengthKnob.setIntValue(0);
        lengthKnob.setMaximumValue(50);
        lengthKnob.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                lengthKnobStateChanged(evt);
            }
        });

        GroupLayout lengthKnobLayout = new GroupLayout(lengthKnob);
        lengthKnob.setLayout(lengthKnobLayout);
        lengthKnobLayout.setHorizontalGroup(
            lengthKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        lengthKnobLayout.setVerticalGroup(
            lengthKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(lengthKnob, gridBagConstraints);

        mixKnob.setIntValue(0);
        mixKnob.setMaximumValue(127);
        mixKnob.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                mixKnobStateChanged(evt);
            }
        });

        GroupLayout mixKnobLayout = new GroupLayout(mixKnob);
        mixKnob.setLayout(mixKnobLayout);
        mixKnobLayout.setHorizontalGroup(
            mixKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        mixKnobLayout.setVerticalGroup(
            mixKnobLayout.createParallelGroup(GroupLayout.LEADING)
            .add(0, 80, Short.MAX_VALUE)
        );
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(mixKnob, gridBagConstraints);

        speedSpinner.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                speedSpinnerStateChanged(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(speedSpinner, gridBagConstraints);

        lengthSpinner.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                lengthSpinnerStateChanged(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(lengthSpinner, gridBagConstraints);

        mixSpinner.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent evt) {
                mixSpinnerStateChanged(evt);
            }
        });

        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(mixSpinner, gridBagConstraints);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jrackattack/gui"); // NOI18N
        jLabel1.setText(bundle.getString("label.speed")); // NOI18N
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(jLabel1, gridBagConstraints);

        jLabel2.setText(bundle.getString("label.length")); // NOI18N
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(jLabel2, gridBagConstraints);

        jLabel3.setText(bundle.getString("label.mix")); // NOI18N
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        add(jLabel3, gridBagConstraints);

    }// </editor-fold>

  private void mixKnobStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    mixSpinner.setValue(new Integer(mixKnob.getIntValue()));
    MidiThread.getInstance().emitParamChange(this,
      getSoundBuffer().getActiveSoundNumber(),
      RackAttack.CRACK_LEVEL,
      mixKnob.getIntValue());

  }

  private void lengthKnobStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    lengthSpinner.setValue(new Integer(lengthKnob.getIntValue()));
    MidiThread.getInstance().emitParamChange(this,
      getSoundBuffer().getActiveSoundNumber(),
      RackAttack.CRACK_LENGTH,
      lengthKnob.getIntValue());
   
  }

  private void speedKnobStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    speedSpinner.setValue(new Integer(speedKnob.getIntValue()));
    MidiThread.getInstance().emitParamChange(this,
      getSoundBuffer().getActiveSoundNumber(),
      RackAttack.CRACK_SPEED,
      speedKnob.getIntValue());
  }

  private void mixSpinnerStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    mixKnob.setIntValue(((Integer)mixSpinner.getValue()).intValue());
  }

  private void lengthSpinnerStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    lengthKnob.setIntValue(((Integer)lengthSpinner.getValue()).intValue());
  }

  private void speedSpinnerStateChanged(ChangeEvent evt) {

    if (initiating) {
      return;
    }
    speedKnob.setIntValue(((Integer)speedSpinner.getValue()).intValue());
  }
 
  private boolean initiating;
 
    // Variables declaration - do not modify
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JKnob lengthKnob;
    private JSpinner lengthSpinner;
    private JKnob mixKnob;
    private JSpinner mixSpinner;
    private JKnob speedKnob;
    private JSpinner speedSpinner;
    // End of variables declaration

  /**
   * Holds value of property soundBuffer.
   */
  private SoundBuffer soundBuffer;

  /**
   * Getter for property soundBuffer.
   * @return Value of property soundBuffer.
   */
  public SoundBuffer getSoundBuffer() {
    return this.soundBuffer;
  }

  /**
   * Setter for property soundBuffer.
   * @param soundBuffer New value of property soundBuffer.
   */
  public void setSoundBuffer(SoundBuffer soundBuffer) {
    this.soundBuffer = soundBuffer;
  }
 
}
/*
    Copyright (C) 2008  Alexander Methke

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program (gplv3.txt).
*/
TOP

Related Classes of jrackattack.gui.CrackPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.