Subversion Repositories svn.mios

Rev

Rev 272 | Rev 696 | 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.GridLayout;
24
import java.awt.event.ActionEvent;
25
import java.util.Vector;
26
 
27
import javax.swing.ButtonGroup;
28
import javax.swing.JPanel;
29
import javax.swing.JToggleButton;
30
 
628 adamjking 31
import org.midibox.sidedit.SIDSysexParameterControl;
213 tk 32
import org.midibox.utils.gui.ImageLoader;
33
import org.midibox.utils.gui.MyButtonUI;
34
 
628 adamjking 35
public class SIDSysexParameterControlLFOSelect extends
36
        SIDSysexParameterControlGUI {
37
    private static String[] onFig = { "sin_on.png", "tri_on.png", "saw_on.png",
38
            "pulse_on.png", "random_on.png", "sin_pos_on.png",
39
            "tri_pos_on.png", "saw_pos_on.png", "pulse_pos_on.png" };
40
    private static String[] offFig = { "sin.png", "tri.png", "saw.png",
41
            "pulse.png", "random.png", "sin_pos.png", "tri_pos.png",
42
            "saw_pos.png", "pulse_pos.png" };
213 tk 43
    private Vector buttonVec = new Vector();
628 adamjking 44
 
45
    public SIDSysexParameterControlLFOSelect(
46
            SIDSysexParameterControl midiParameter, boolean showLabel,
213 tk 47
            String labelLocation, boolean valueBelow, boolean showValue) {
48
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
628 adamjking 49
 
213 tk 50
        JPanel panel = new JPanel();
628 adamjking 51
        panel.setLayout(new GridLayout(2, 5));
213 tk 52
        panel.setOpaque(false);
628 adamjking 53
 
213 tk 54
        ButtonGroup group = new ButtonGroup();
55
        for (int c = 0; c < 9; c++) {
56
            JToggleButton toggle = new JToggleButton();
628 adamjking 57
            toggle.setUI(new MyButtonUI(ImageLoader.getImageIcon(onFig[c]),
58
                    ImageLoader.getImageIcon(offFig[c])));
213 tk 59
            toggle.addMouseListener(this);
60
            panel.add(toggle);
61
            group.add(toggle);
62
            buttonVec.add(toggle);
628 adamjking 63
            toggle.addActionListener(this);
213 tk 64
        }
65
        add(panel);
66
        updateGraphics();
67
    }
68
 
69
    public void actionPerformed(ActionEvent ae) {
70
        super.actionPerformed(ae);
71
        for (int c = 0; c < buttonVec.size(); c++) {
628 adamjking 72
            JToggleButton toggle = (JToggleButton) buttonVec.elementAt(c);
213 tk 73
            if (ae.getSource() == toggle) {
74
                if (update) {
75
                    update = false;
76
                    int newval = 0;
77
                    if (toggle.isSelected()) {
78
                        newval = c;
79
                    }
80
                    midiParameter.setMidiValue(newval, true);
81
                    for (int d = 0; d < midiParameters.size(); d++) {
628 adamjking 82
                        SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
83
                                .elementAt(d);
272 rutgerv 84
                        mp.setMidiValue(newval, false);
213 tk 85
                    }
86
                    update = true;
87
                }
88
            }
89
        }
628 adamjking 90
    }
91
 
213 tk 92
    public void updateGraphics() {
93
        super.updateGraphics();
94
        if (update) {
95
            update = false;
628 adamjking 96
            ((JToggleButton) buttonVec.elementAt(midiParameter.getMidiValue()))
97
                    .setSelected(true);
213 tk 98
            update = true;
99
        }
100
    }
101
}