Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
505 rutgerv 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.event.ActionEvent;
25
 
628 adamjking 26
import javax.swing.BoxLayout;
27
import javax.swing.ButtonGroup;
28
import javax.swing.JPanel;
29
import javax.swing.JRadioButton;
505 rutgerv 30
 
628 adamjking 31
import org.midibox.sidedit.SIDSysexParameterControl;
505 rutgerv 32
 
33
public class SIDSysexParameterControlRadio extends SIDSysexParameterControlGUI {
34
 
35
    public static float mouseWheelResolution = 10.0f;
36
    private JRadioButton[] radioButtons;
37
 
628 adamjking 38
    public SIDSysexParameterControlRadio(
39
            SIDSysexParameterControl midiParameter, boolean showLabel,
40
            String labelLocation, boolean valueBelow, boolean showValue) {
505 rutgerv 41
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
628 adamjking 42
 
505 rutgerv 43
        JPanel panel = new JPanel();
44
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
45
        panel.setOpaque(false);
46
        ButtonGroup bg = new ButtonGroup();
47
        String[] str = midiParameter.getSparseValAlias();
48
        radioButtons = new JRadioButton[str.length];
628 adamjking 49
        for (int i = 0; i < str.length; i++) {
505 rutgerv 50
            radioButtons[i] = new JRadioButton(str[i], false);
51
            radioButtons[i].addActionListener(this);
52
            radioButtons[i].setOpaque(false);
53
            bg.add(radioButtons[i]);
54
            panel.add(radioButtons[i]);
628 adamjking 55
        }
505 rutgerv 56
        updateGraphics();
57
        add(panel, BorderLayout.CENTER);
628 adamjking 58
        updateGraphics();
505 rutgerv 59
    }
628 adamjking 60
 
505 rutgerv 61
    public void actionPerformed(ActionEvent ae) {
628 adamjking 62
        super.actionPerformed(ae);
63
        for (int i = 0; i < radioButtons.length; i++) {
64
            if ((ae.getSource() == radioButtons[i])
65
                    && (radioButtons[i].isSelected())) {
505 rutgerv 66
                if (update) {
67
                    update = false;
628 adamjking 68
                    int newval = midiParameter
69
                            .lookUpAlias((String) radioButtons[i].getText());
70
                    midiParameter.setMidiValue(newval, true);
505 rutgerv 71
                    for (int c = 0; c < midiParameters.size(); c++) {
628 adamjking 72
                        SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
73
                                .elementAt(c);
505 rutgerv 74
                        mp.setMidiValue(newval, false);
628 adamjking 75
                    }
505 rutgerv 76
                    update = true;
77
                    break;
78
                }
79
            }
80
        }
81
    }
628 adamjking 82
 
505 rutgerv 83
    public void updateGraphics() {
84
        super.updateGraphics();
85
        if (update) {
86
            update = false;
628 adamjking 87
            for (int i = 0; i < radioButtons.length; i++) {
88
                if (i == midiParameter
89
                        .lookUpValue(midiParameter.getMidiValue())) {
505 rutgerv 90
                    radioButtons[i].setSelected(true);
91
                } else {
92
                    radioButtons[i].setSelected(false);
93
                }
94
            }
95
            update = true;
96
        }
97
    }
98
}