Subversion Repositories svn.mios

Rev

Rev 272 | 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.awt.event.ActionEvent;
628 adamjking 26
 
213 tk 27
import javax.swing.JPanel;
28
import javax.swing.JToggleButton;
29
 
628 adamjking 30
import org.midibox.sidedit.SIDSysexParameterControl;
213 tk 31
 
628 adamjking 32
public class SIDSysexParameterControlToggleButton extends
33
        SIDSysexParameterControlGUI {
213 tk 34
 
35
    private JToggleButton toggleButton;
36
 
37
    private boolean momentary = false;
628 adamjking 38
 
213 tk 39
    private SIDSysexParameterControlGUI snapGUI = null;
40
 
628 adamjking 41
    public SIDSysexParameterControlToggleButton(
42
            SIDSysexParameterControl midiParameter, JToggleButton toggleButton,
43
            boolean momentary, boolean showLabel, String labelLocation,
44
            boolean valueBelow, boolean showValue) {
213 tk 45
        super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
46
        this.toggleButton = toggleButton;
47
        this.momentary = momentary;
48
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
49
        panel.setOpaque(false);
50
        panel.add(toggleButton);
51
        add(panel, BorderLayout.CENTER);
52
        toggleButton.addActionListener(this);
53
        toggleButton.addMouseListener(this);
54
        updateGraphics();
55
    }
628 adamjking 56
 
213 tk 57
    public JToggleButton getToggleButton() {
58
        return toggleButton;
59
    }
60
 
61
    public void actionPerformed(ActionEvent ae) {
62
 
63
        super.actionPerformed(ae);
64
 
65
        if (ae.getSource() == toggleButton) {
66
            if (update) {
67
                update = false;
628 adamjking 68
                midiParameter.setMidiValue((toggleButton.isSelected()) ? 1 : 0,
69
                        true);
213 tk 70
                for (int c = 0; c < midiParameters.size(); c++) {
628 adamjking 71
                    SIDSysexParameterControl mp = (SIDSysexParameterControl) midiParameters
72
                            .elementAt(c);
73
                    mp.setMidiValue((toggleButton.isSelected()) ? 1 : 0, false);
213 tk 74
                }
628 adamjking 75
                if (snapGUI != null) {
213 tk 76
                    snapGUI.setSnap(toggleButton.isSelected());
77
                }
78
                update = true;
79
            }
80
            if (momentary && toggleButton.isSelected()) {
81
                toggleButton.doClick();
82
            }
83
        }
628 adamjking 84
    }
85
 
213 tk 86
    public void setSnapParameter(SIDSysexParameterControlGUI snapGUI) {
87
        this.snapGUI = snapGUI;
88
    }
628 adamjking 89
 
213 tk 90
    public void updateGraphics() {
91
        super.updateGraphics();
92
        if (update) {
93
            update = false;
94
            toggleButton.setSelected((midiParameter.getMidiValue() != 0));
628 adamjking 95
            if (snapGUI != null) {
213 tk 96
                snapGUI.setSnap(toggleButton.isSelected());
97
            }
98
            update = true;
99
        }
100
    }
101
}