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