Subversion Repositories svn.mios

Rev

Rev 213 | 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.util.Observable;
26
 
27
import javax.swing.JPanel;
28
import javax.swing.JSpinner;
29
import javax.swing.SpinnerNumberModel;
30
import javax.swing.event.ChangeEvent;
31
import javax.swing.event.ChangeListener;
32
 
628 adamjking 33
import org.midibox.sidedit.SIDSysexParameterControl;
213 tk 34
import org.midibox.utils.gui.FontLoader;
35
 
628 adamjking 36
public class SIDSysexParameterControlSpinner extends
37
        SIDSysexParameterControlGUI implements ChangeListener {
213 tk 38
 
39
    private JSpinner spinner;
40
 
628 adamjking 41
    public SIDSysexParameterControlSpinner(
42
            SIDSysexParameterControl midiParameter, JSpinner spinner,
43
            String name) {
213 tk 44
        super(midiParameter, true, BorderLayout.NORTH, false, false);
45
        this.spinner = spinner;
46
        midiParameterLabel.setText(name);
47
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
48
        panel.setOpaque(false);
49
        panel.add(spinner);
50
        add(panel, BorderLayout.CENTER);
51
        spinner.addChangeListener(this);
52
        spinner.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
53
        spinner.addMouseListener(this);
54
        updateGraphics();
55
    }
56
 
57
    public void stateChanged(ChangeEvent ce) {
58
        if (update) {
59
            update = false;
60
            midiParameter
61
                    .setMidiValue(
62
                            (int) (((float) ((Integer) spinner.getModel()
63
                                    .getValue()).intValue() / (float) ((Integer) ((SpinnerNumberModel) spinner
64
                                    .getModel()).getMaximum()).intValue()) * (float) midiParameter
65
                                    .getMidiMaxValue()), true);
66
            update = true;
67
        }
68
    }
69
 
70
    public void updateGraphics() {
71
        super.updateGraphics();
72
        if (update) {
73
            update = false;
74
            spinner
75
                    .setValue(new Integer(
76
                            (int) ((((float) midiParameter.getMidiValue() / (float) midiParameter
77
                                    .getMidiMaxValue())) * (float) (((Integer) ((SpinnerNumberModel) spinner
78
                                    .getModel()).getMaximum()).intValue()))));
79
            update = true;
80
        }
81
    }
82
 
83
    public void update(Observable observable, Object object) {
84
 
85
    }
86
}