Subversion Repositories svn.mios

Rev

Rev 650 | Rev 668 | 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;
649 adamjking 35
import org.midibox.utils.gui.FaderUI;
36
import org.midibox.utils.gui.ImageLoader;
213 tk 37
 
38
public class SIDSysexParameterControlSlider extends SIDSysexParameterControlGUI
39
        implements ChangeListener, MouseWheelListener {
40
 
41
    public static float mouseWheelResolution = 10.0f;
42
 
43
    private JSlider slider;
44
 
628 adamjking 45
    public SIDSysexParameterControlSlider(
46
            SIDSysexParameterControl midiParameter, JSlider slider,
47
            boolean showLabel, String labelLocation, boolean valueBelow,
48
            boolean showValue) {
213 tk 49
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
50
        this.slider = slider;
649 adamjking 51
 
657 adamjking 52
        FaderUI faderUI = new FaderUI(ImageLoader
650 adamjking 53
                .getImageIcon("plasticSlider_horiz.png"), ImageLoader
657 adamjking 54
                .getImageIcon("plasticSlider_vert.png"), false);
649 adamjking 55
 
657 adamjking 56
        faderUI.setTrackWidth(3);
650 adamjking 57
 
657 adamjking 58
        slider.setUI(faderUI);
649 adamjking 59
 
628 adamjking 60
        slider.setMaximum(midiParameter.getMidiMaxValue()
61
                - midiParameter.getMidiMinValue());
213 tk 62
        slider.setOpaque(false);
63
        slider.setOrientation(JSlider.VERTICAL);
628 adamjking 64
        slider.setPreferredSize(new Dimension(20, 80));
213 tk 65
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
66
        panel.setOpaque(false);
67
        panel.add(slider);
68
        add(panel, BorderLayout.CENTER);
69
        slider.addChangeListener(this);
70
        slider.addMouseWheelListener(this);
71
        slider.addMouseListener(this);
72
        updateGraphics();
73
    }
628 adamjking 74
 
213 tk 75
    public void setHeight(int height) {
628 adamjking 76
        slider.setPreferredSize(new Dimension(20, height));
213 tk 77
    }
78
 
79
    public void mouseWheelMoved(MouseWheelEvent mwe) {
80
        slider
81
                .setValue((int) (slider.getValue() - (mwe.getWheelRotation() * ((mouseWheelResolution / 100f) * (float) ((slider
82
                        .getMaximum() - slider.getMinimum()))))));
83
    }
84
 
85
    public void stateChanged(ChangeEvent ce) {
86
        if (update) {
87
            update = false;
628 adamjking 88
            int newval = (int) ((((float) slider.getValue() / (float) slider
89
                    .getMaximum()) * ((float) midiParameter.getMidiMaxValue() - (float) midiParameter
90
                    .getMidiMinValue())) + (float) midiParameter
91
                    .getMidiMinValue());
213 tk 92
            midiParameter.setMidiValue(newval, true);
628 adamjking 93
 
213 tk 94
            for (int c = 0; c < midiParameters.size(); c++) {
628 adamjking 95
                SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
96
                        .elementAt(c);
272 rutgerv 97
                mp.setMidiValue(newval, false);
213 tk 98
            }
628 adamjking 99
 
213 tk 100
            update = true;
101
        }
102
    }
628 adamjking 103
 
213 tk 104
    public void updateGraphics() {
105
        super.updateGraphics();
106
        if (update) {
107
            update = false;
628 adamjking 108
            int newval = (int) ((((float) midiParameter.getMidiValue() - (float) midiParameter
109
                    .getMidiMinValue()) / ((float) midiParameter
110
                    .getMidiMaxValue() - (float) midiParameter
111
                    .getMidiMinValue())) * (float) slider.getMaximum());
213 tk 112
            slider.setValue(newval);
113
            update = true;
114
        }
115
    }
116
}