Subversion Repositories svn.mios

Rev

Rev 272 | Rev 649 | 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;
628 adamjking 24
import java.awt.Dimension;
213 tk 25
import java.awt.FlowLayout;
26
import java.awt.event.MouseWheelEvent;
27
import java.awt.event.MouseWheelListener;
28
 
29
import javax.swing.JPanel;
30
import javax.swing.JSlider;
31
import javax.swing.event.ChangeEvent;
32
import javax.swing.event.ChangeListener;
33
 
628 adamjking 34
import org.midibox.sidedit.SIDSysexParameterControl;
213 tk 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
 
628 adamjking 43
    public SIDSysexParameterControlSlider(
44
            SIDSysexParameterControl midiParameter, JSlider slider,
45
            boolean showLabel, String labelLocation, boolean valueBelow,
46
            boolean showValue) {
213 tk 47
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
48
        this.slider = slider;
628 adamjking 49
        slider.setMaximum(midiParameter.getMidiMaxValue()
50
                - midiParameter.getMidiMinValue());
213 tk 51
        slider.setOpaque(false);
52
        slider.setOrientation(JSlider.VERTICAL);
628 adamjking 53
        slider.setPreferredSize(new Dimension(20, 80));
213 tk 54
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
55
        panel.setOpaque(false);
56
        panel.add(slider);
57
        add(panel, BorderLayout.CENTER);
58
        slider.addChangeListener(this);
59
        slider.addMouseWheelListener(this);
60
        slider.addMouseListener(this);
61
        updateGraphics();
62
    }
628 adamjking 63
 
213 tk 64
    public void setHeight(int height) {
628 adamjking 65
        slider.setPreferredSize(new Dimension(20, height));
213 tk 66
    }
67
 
68
    public void mouseWheelMoved(MouseWheelEvent mwe) {
69
        slider
70
                .setValue((int) (slider.getValue() - (mwe.getWheelRotation() * ((mouseWheelResolution / 100f) * (float) ((slider
71
                        .getMaximum() - slider.getMinimum()))))));
72
    }
73
 
74
    public void stateChanged(ChangeEvent ce) {
75
        if (update) {
76
            update = false;
628 adamjking 77
            int newval = (int) ((((float) slider.getValue() / (float) slider
78
                    .getMaximum()) * ((float) midiParameter.getMidiMaxValue() - (float) midiParameter
79
                    .getMidiMinValue())) + (float) midiParameter
80
                    .getMidiMinValue());
213 tk 81
            midiParameter.setMidiValue(newval, true);
628 adamjking 82
 
213 tk 83
            for (int c = 0; c < midiParameters.size(); c++) {
628 adamjking 84
                SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
85
                        .elementAt(c);
272 rutgerv 86
                mp.setMidiValue(newval, false);
213 tk 87
            }
628 adamjking 88
 
213 tk 89
            update = true;
90
        }
91
    }
628 adamjking 92
 
213 tk 93
    public void updateGraphics() {
94
        super.updateGraphics();
95
        if (update) {
96
            update = false;
628 adamjking 97
            int newval = (int) ((((float) midiParameter.getMidiValue() - (float) midiParameter
98
                    .getMidiMinValue()) / ((float) midiParameter
99
                    .getMidiMaxValue() - (float) midiParameter
100
                    .getMidiMinValue())) * (float) slider.getMaximum());
213 tk 101
            slider.setValue(newval);
102
            update = true;
103
        }
104
    }
105
}