Subversion Repositories svn.mios

Rev

Rev 628 | Rev 668 | Go to most recent revision | 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
 
39
    public static float mouseWheelResolution = 10.0f;
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
66
                .setValue((int) (slider.getValue() - (mwe.getWheelRotation() * ((mouseWheelResolution / 100f) * (float) ((slider
67
                        .getMaximum() - slider.getMinimum()))))));
68
    }
69
 
70
    public void updateGraphics() {
71
        super.updateGraphics();
72
        if (update) {
73
            update = false;
74
            slider
75
                    .setValue((int) ((((float) midiParameter.getMidiValue() / (float) midiParameter
76
                            .getMidiMaxValue())) * (float) (slider.getMaximum())));
77
            update = true;
78
        }
79
    }
80
 
81
    public void stateChanged(ChangeEvent ce) {
82
        if (update) {
83
            update = false;
84
            midiParameter.setMidiValue(Math
85
                    .round(((float) slider.getValue() / (float) slider
86
                            .getMaximum())
87
                            * (float) midiParameter.getMidiMaxValue()), true);
88
            update = true;
89
        }
90
    }
657 adamjking 91
 
92
    public void update(Observable observable, Object object) {
93
        super.update(observable, object);
94
 
95
        if (object == midiParameter.HIGH_RESOLUTION) {
96
 
97
            slider.setMinimum(midiParameter.getMidiMinValue());
98
            slider.setMaximum(midiParameter.getMidiMaxValue());
99
        }
100
    }
628 adamjking 101
}