Subversion Repositories svn.mios

Rev

Rev 628 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)MidiParameterControlSpinner.java beta8   2006/04/23
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
5
 *
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.midi.gui;
22
 
23
import java.awt.BorderLayout;
24
import java.awt.FlowLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.util.Observable;
28
 
29
import javax.swing.JCheckBoxMenuItem;
30
import javax.swing.JPanel;
31
import javax.swing.JPopupMenu;
32
import javax.swing.JSpinner;
33
import javax.swing.SpinnerNumberModel;
34
import javax.swing.event.ChangeEvent;
35
import javax.swing.event.ChangeListener;
36
 
37
import org.midibox.midi.MidiParameterControl;
38
import org.midibox.utils.gui.FontLoader;
39
 
40
public class MidiParameterControlSpinner extends MidiParameterControlGUI
41
        implements ChangeListener {
42
 
43
    private JSpinner spinner;
44
 
45
    public MidiParameterControlSpinner(MidiParameterControl midiParameter,
46
            JSpinner spinner, String name) {
47
        super(midiParameter, true, BorderLayout.NORTH, false, false);
48
        this.spinner = spinner;
49
        midiParameterLabel.setText(name);
50
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
51
        panel.setOpaque(false);
52
        panel.add(spinner);
53
        add(panel, BorderLayout.CENTER);
54
        spinner.addChangeListener(this);
55
        spinner.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
56
        spinner.addMouseListener(this);
57
        updateGraphics();
58
    }
59
 
60
    public void stateChanged(ChangeEvent ce) {
61
        if (update) {
62
            update = false;
721 adamjking 63
            midiParameterControl
628 adamjking 64
                    .setMidiValue(
65
                            (int) (((float) ((Integer) spinner.getModel()
66
                                    .getValue()).intValue() / (float) ((Integer) ((SpinnerNumberModel) spinner
721 adamjking 67
                                    .getModel()).getMaximum()).intValue()) * (float) midiParameterControl
628 adamjking 68
                                    .getMidiMaxValue()), true);
69
            update = true;
70
        }
71
    }
72
 
73
    protected JPopupMenu createPopMenu() {
74
        JPopupMenu popup = new JPopupMenu();
75
 
76
        final JCheckBoxMenuItem channelMenuItem = new JCheckBoxMenuItem(
721 adamjking 77
                "Global Channel", (midiParameterControl.isGlobal()));
628 adamjking 78
        channelMenuItem.addActionListener(new ActionListener() {
79
            public void actionPerformed(ActionEvent ae) {
721 adamjking 80
                midiParameterControl.setGlobal(channelMenuItem.isSelected());
628 adamjking 81
            }
82
        });
83
 
84
        popup.add(channelMenuItem);
85
 
86
        for (int i = 0; i < 16; i++) {
87
            JCheckBoxMenuItem channelItem = new JCheckBoxMenuItem("Channel "
721 adamjking 88
                    + (i + 1), (midiParameterControl.getMidiChannel() == i));
89
            channelItem.setEnabled(!midiParameterControl.isGlobal());
628 adamjking 90
            popup.add(channelItem);
91
 
92
            final int channelNo = i;
93
 
94
            channelItem.addActionListener(new ActionListener() {
95
                public void actionPerformed(ActionEvent ae) {
721 adamjking 96
                    midiParameterControl.setMidiChannel(channelNo);
628 adamjking 97
                }
98
            });
99
        }
100
        return popup;
101
    }
102
 
103
    public void updateGraphics() {
104
        super.updateGraphics();
105
        if (update) {
106
            update = false;
107
            spinner
108
                    .setValue(new Integer(
721 adamjking 109
                            (int) ((((float) midiParameterControl.getMidiValue() / (float) midiParameterControl
628 adamjking 110
                                    .getMidiMaxValue())) * (float) (((Integer) ((SpinnerNumberModel) spinner
111
                                    .getModel()).getMaximum()).intValue()))));
112
            update = true;
113
        }
114
    }
115
 
116
    public void update(Observable observable, Object object) {
117
 
118
    }
119
}