Package jrackattack.gui

Source Code of jrackattack.gui.TestSettings_1

/* For License see bottom */
/*
* TestSettings_1.java
*
* Created on 21. Juli 2007, 13:25
*/

package jrackattack.gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;

import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

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

import org.apache.log4j.Logger;

/**
*
* @author methke01
*/
@VersionInformation(//
lastChanged = "$LastChangedDate: 2009-09-15 13:42:26 -0500 (Tue, 15 Sep 2009) $", //
authors = { "Alexander Methke" }, //
revision = "$LastChangedRevision: 12 $", //
lastEditor = "$LastChangedBy: onkobu $", //
id = "$Id")
public class TestSettings_1 extends JPanel implements Serializable {
  private final Logger log = Logger.getLogger(TestSettings_1.class);

  public TestSettings_1() {
    this(null);
  }

  /**
   * Creates new form TestSettings_1
   */
  public TestSettings_1(MidiSettings p) {
    initComponents();
    initValues();
    parent = p;
  }

  protected void initValues() {
    java.util.ResourceBundle bundle = java.util.ResourceBundle
        .getBundle("jrackattack/gui");

    programBox.removeAllItems();
    for (int i = 0; i < 50; i++) {
      programBox.addItem(bundle.getString("text.program") + " #" + i);
    }
    programBox.setSelectedIndex(0);
    ButtonGroup bg = new ButtonGroup();
    bg.add(this.melodyButton);
    bg.add(this.drumButton);
    bg.add(this.chordButton);
    melodyButton.setSelected(true);

  }

  /**
   * 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.
   */
  private void initComponents() {
    GridBagConstraints gridBagConstraints;

    chordButton = new JRadioButton();
    drumButton = new JRadioButton();
    melodyButton = new JRadioButton();
    programBox = new JComboBox();
    programCheck = new JCheckBox();
    testButton = new JButton();

    setLayout(new GridBagLayout());

    java.util.ResourceBundle bundle = java.util.ResourceBundle
        .getBundle("jrackattack/gui"); // NOI18N
    chordButton.setText(bundle.getString("radio.test_chord")); // NOI18N
    chordButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    chordButton.setMargin(new Insets(0, 0, 0, 0));
    chordButton.setMinimumSize(new Dimension(83, 15));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.weightx = 0.2;
    add(chordButton, gridBagConstraints);

    drumButton.setText(bundle.getString("radio.test_drums")); // NOI18N
    drumButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    drumButton.setMargin(new Insets(0, 0, 0, 0));
    drumButton.setMinimumSize(new Dimension(83, 15));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.weightx = 0.2;
    add(drumButton, gridBagConstraints);

    melodyButton.setText(bundle.getString("radio.melody")); // NOI18N
    melodyButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    melodyButton.setMargin(new Insets(0, 0, 0, 0));
    melodyButton.setMinimumSize(new Dimension(83, 15));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.weightx = 0.2;
    add(melodyButton, gridBagConstraints);

    programBox.setEnabled(false);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.NORTH;
    gridBagConstraints.weightx = 0.2;
    add(programBox, gridBagConstraints);

    programCheck.setText(bundle.getString("checkbox.transmitPCC")); // NOI18N
    programCheck.setToolTipText(bundle
        .getString("checkbox.transmitPCC.tooltip")); // NOI18N
    programCheck.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    programCheck.setMargin(new Insets(0, 0, 0, 0));
    programCheck.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        programCheckStateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.NORTH;
    add(programCheck, gridBagConstraints);

    testButton.setText(bundle.getString("button.test")); // NOI18N
    testButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        testButtonActionPerformed(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = GridBagConstraints.EAST;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(testButton, gridBagConstraints);

  }

  private void testButtonActionPerformed(ActionEvent evt) {

    try {
      MidiDevice.Info info = parent.getSelectedOutDevice();
      log.debug("trying output on: " + info);
      MidiDevice dev;
      dev = MidiSystem.getMidiDevice(info);
      int chan = parent.getSelectedChannel();
      MidiThread.TestModes tm = MidiThread.TestModes.MELODY;
      if (drumButton.isSelected()) {
        tm = MidiThread.TestModes.DRUMS;
      } else if (chordButton.isSelected()) {
        tm = MidiThread.TestModes.CHORD;
      }
      MidiThread mt = MidiThread.getTestInstance(dev, chan, tm,
          programCheck.isSelected() ? programBox.getSelectedIndex()
              : -1);
      // nur ein Durchlauf
      mt.start();
      mt.setRunOnce(true);
    } catch (MidiUnavailableException e) {
      log.error("error", e);
    }
  }

  private void programCheckStateChanged(ChangeEvent evt) {

    programBox.setEnabled(programCheck.isSelected());
  }

  public void setSettingsParent(MidiSettings set) {
    parent = set;
  }

  public MidiSettings getSettingsParent() {
    return parent;
  }

  private MidiSettings parent;

  // Variables declaration - do not modify
  private JRadioButton chordButton;
  private JRadioButton drumButton;
  private JRadioButton melodyButton;
  private JComboBox programBox;
  private JCheckBox programCheck;
  private JButton testButton;
  // End of variables declaration

}
/*
* 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.TestSettings_1

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.