Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
213 tk 1
/*
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
3
 *
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
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.sidedit.gui.controls;
22
 
23
import java.awt.BorderLayout;
24
import java.awt.FlowLayout;
25
import java.awt.event.MouseWheelEvent;
26
import java.awt.event.MouseWheelListener;
27
import java.awt.Dimension;
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.sidedit.*;
35
 
36
public class SIDSysexParameterControlSlider extends SIDSysexParameterControlGUI
37
        implements ChangeListener, MouseWheelListener {
38
 
39
    public static float mouseWheelResolution = 10.0f;
40
 
41
    private JSlider slider;
42
 
43
    public SIDSysexParameterControlSlider(SIDSysexParameterControl midiParameter,
44
            JSlider slider, boolean showLabel, String labelLocation,
45
            boolean valueBelow, boolean showValue) {
46
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
47
        this.slider = slider;
48
        slider.setMaximum(midiParameter.getMidiMaxValue()-midiParameter.getMidiMinValue());
49
        slider.setOpaque(false);
50
        slider.setOrientation(JSlider.VERTICAL);
51
        slider.setPreferredSize(new Dimension(20,80));
52
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
53
        panel.setOpaque(false);
54
        panel.add(slider);
55
        add(panel, BorderLayout.CENTER);
56
        slider.addChangeListener(this);
57
        slider.addMouseWheelListener(this);
58
        slider.addMouseListener(this);
59
        updateGraphics();
60
    }
61
 
62
    public void setHeight(int height) {
63
        slider.setPreferredSize(new Dimension(20,height));
64
    }
65
 
66
    public void mouseWheelMoved(MouseWheelEvent mwe) {
67
        slider
68
                .setValue((int) (slider.getValue() - (mwe.getWheelRotation() * ((mouseWheelResolution / 100f) * (float) ((slider
69
                        .getMaximum() - slider.getMinimum()))))));
70
    }
71
 
72
    public void stateChanged(ChangeEvent ce) {
73
        if (update) {
74
            update = false;
75
            int newval = (int)((((float)slider.getValue() / (float)slider.getMaximum()) * ((float)midiParameter.getMidiMaxValue() - (float)midiParameter.getMidiMinValue())) + (float)midiParameter.getMidiMinValue());
76
            midiParameter.setMidiValue(newval, true);
77
 
78
            for (int c = 0; c < midiParameters.size(); c++) {
79
                SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters.elementAt(c);
272 rutgerv 80
                mp.setMidiValue(newval, false);
213 tk 81
            }
82
 
83
            update = true;
84
        }
85
    }
86
 
87
    public void updateGraphics() {
88
        super.updateGraphics();
89
        if (update) {
90
            update = false;
91
            int newval = (int) ((((float)midiParameter.getMidiValue()-(float)midiParameter.getMidiMinValue())/((float)midiParameter.getMidiMaxValue() - (float)midiParameter.getMidiMinValue())) * (float) slider.getMaximum());
92
            slider.setValue(newval);
93
            update = true;
94
        }
95
    }
96
}