Subversion Repositories svn.mios

Rev

Rev 670 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)MidiParameterControlKnob.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.MouseWheelEvent;
26
import java.awt.event.MouseWheelListener;
657 adamjking 27
import java.util.Observable;
628 adamjking 28
 
29
import javax.swing.JPanel;
30
import javax.swing.event.ChangeEvent;
31
import javax.swing.event.ChangeListener;
32
 
33
import org.midibox.midi.MidiParameterControl;
34
import org.midibox.utils.gui.Knob;
35
 
36
public class MidiParameterControlKnob extends MidiParameterControlGUI implements
37
        ChangeListener, MouseWheelListener {
38
 
670 adamjking 39
    public static float mouseWheelResolution = 0.1f;
628 adamjking 40
 
41
    private Knob knob;
42
 
43
    public MidiParameterControlKnob(MidiParameterControl midiParameter,
44
            Knob knob, boolean showLabel, String labelLocation,
45
            boolean valueBelow, boolean showValue) {
46
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
47
        this.knob = knob;
48
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
49
        panel.setOpaque(false);
50
        panel.add(knob);
657 adamjking 51
 
668 adamjking 52
        knob.setMinimum(midiParameter.getMidiMinValue());
53
        knob.setMaximum(midiParameter.getMidiMaxValue());
657 adamjking 54
 
628 adamjking 55
        add(panel, BorderLayout.CENTER);
56
        knob.addChangeListener(this);
57
        knob.addMouseListener(this);
58
        knob.addMouseWheelListener(this);
59
        updateGraphics();
60
    }
61
 
62
    public void mouseWheelMoved(MouseWheelEvent mwe) {
670 adamjking 63
        knob.setValue((int) (knob.getValue() - ((mwe.getWheelRotation() * Math
64
                .max(mouseWheelResolution
65
                        * (knob.getMaximum() - knob.getMinimum()), 1)))));
628 adamjking 66
    }
67
 
68
    public void stateChanged(ChangeEvent ce) {
668 adamjking 69
 
628 adamjking 70
        if (update) {
668 adamjking 71
 
628 adamjking 72
            update = false;
657 adamjking 73
 
721 adamjking 74
            midiParameterControl.setMidiValue(knob.getValue(), true);
657 adamjking 75
 
628 adamjking 76
            update = true;
77
        }
78
    }
79
 
80
    public void updateGraphics() {
668 adamjking 81
 
628 adamjking 82
        super.updateGraphics();
668 adamjking 83
 
628 adamjking 84
        if (update) {
668 adamjking 85
 
628 adamjking 86
            update = false;
657 adamjking 87
 
721 adamjking 88
            knob.setValue(midiParameterControl.getMidiValue());
657 adamjking 89
 
628 adamjking 90
            update = true;
91
        }
92
    }
657 adamjking 93
 
94
    public void update(Observable observable, Object object) {
95
        super.update(observable, object);
721 adamjking 96
        if (object == midiParameterControl.HIGH_RESOLUTION) {
657 adamjking 97
 
721 adamjking 98
            knob.setMinimum(midiParameterControl.getMidiMinValue());
99
            knob.setMaximum(midiParameterControl.getMidiMaxValue());
657 adamjking 100
        }
101
    }
628 adamjking 102
}