Subversion Repositories svn.mios

Rev

Rev 696 | 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.drum;
22
 
23
import java.awt.BorderLayout;
628 adamjking 24
import java.awt.Dimension;
213 tk 25
import java.awt.Font;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.Vector;
31
 
32
import javax.swing.BorderFactory;
33
import javax.swing.BoxLayout;
696 rutgerv 34
import javax.swing.ButtonGroup;
213 tk 35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
696 rutgerv 37
import javax.swing.JRadioButton;
213 tk 38
 
39
import org.midibox.sidedit.SIDSysexParameterControl;
628 adamjking 40
import org.midibox.sidedit.gui.SequencerButton;
41
import org.midibox.sidedit.gui.controls.SIDSysexParameterControlGUI;
42
 
43
public class SequencerGUI extends JPanel implements ActionListener {
44
    private JPanel seqPanel, currentPanel, seq1, seq2, seq3, seq4, seq5, seq6,
45
            seq7, seq8;
696 rutgerv 46
    private JRadioButton radioButtons[];
738 adamjking 47
 
213 tk 48
    protected SequencerGUI(Vector V1GUIv, Vector V2GUIv) {
49
        setLayout(new BorderLayout());
50
        this.setOpaque(false);
628 adamjking 51
 
52
        JPanel mainPanel = new JPanel();
213 tk 53
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
54
        mainPanel.setOpaque(false);
628 adamjking 55
 
213 tk 56
        seqPanel = new JPanel();
57
        seqPanel.setLayout(new BoxLayout(seqPanel, BoxLayout.X_AXIS));
58
        seqPanel.setBorder(BorderFactory.createEtchedBorder());
59
        seqPanel.setBorder(BorderFactory.createTitledBorder("Sequencer data"));
60
        seqPanel.setOpaque(false);
628 adamjking 61
 
696 rutgerv 62
        JPanel comboPanel = new JPanel();
63
        comboPanel.setLayout(new BoxLayout(comboPanel, BoxLayout.Y_AXIS));
213 tk 64
        comboPanel.setOpaque(false);
738 adamjking 65
        String[] s = { "Sequence #1", "Sequence #2", "Sequence #3",
66
                "Sequence #4", "Sequence #5", "Sequence #6", "Sequence #7",
67
                "Sequence #8" };
696 rutgerv 68
        ButtonGroup bg = new ButtonGroup();
69
        radioButtons = new JRadioButton[s.length];
70
        for (int i = 0; i < s.length; i++) {
71
            radioButtons[i] = new JRadioButton(s[i], true);
72
            radioButtons[i].setOpaque(false);
73
            radioButtons[i].addActionListener(this);
74
            radioButtons[i].setFont(new Font("sansserif", Font.BOLD, 10));
75
            bg.add(radioButtons[i]);
76
            comboPanel.add(radioButtons[i]);
77
        }
738 adamjking 78
 
628 adamjking 79
        seqPanel.add(comboPanel);
80
 
81
        seq1 = createSeqData(V2GUIv, 0);
82
        seq2 = createSeqData(V2GUIv, 1);
83
        seq3 = createSeqData(V2GUIv, 2);
84
        seq4 = createSeqData(V2GUIv, 3);
85
        seq5 = createSeqData(V2GUIv, 4);
86
        seq6 = createSeqData(V2GUIv, 5);
87
        seq7 = createSeqData(V2GUIv, 6);
88
        seq8 = createSeqData(V2GUIv, 7);
89
 
213 tk 90
        currentPanel = seq1;
91
        seqPanel.add(currentPanel);
628 adamjking 92
 
93
        mainPanel.add(createConfig(V1GUIv, "Sequencer setup"));
213 tk 94
        mainPanel.add(seqPanel);
628 adamjking 95
        this.add(mainPanel, BorderLayout.NORTH);
213 tk 96
    }
628 adamjking 97
 
98
    protected JPanel createConfig(Vector vGUI, String s) {
213 tk 99
        JPanel configPanel = new JPanel();
628 adamjking 100
        configPanel.setLayout(new BoxLayout(configPanel, BoxLayout.X_AXIS));
213 tk 101
        configPanel.setBorder(BorderFactory.createEtchedBorder());
102
        configPanel.setBorder(BorderFactory.createTitledBorder(s));
103
        configPanel.setOpaque(false);
628 adamjking 104
 
213 tk 105
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(3));
106
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(4));
628 adamjking 107
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(0));
213 tk 108
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(1));
628 adamjking 109
        configPanel.add((SIDSysexParameterControlGUI) vGUI.elementAt(2));
213 tk 110
        return configPanel;
628 adamjking 111
    }
213 tk 112
 
628 adamjking 113
    protected JPanel createSeqData(Vector vGUI, int seqNr) {
213 tk 114
        JPanel chanPanel = new JPanel();
628 adamjking 115
        chanPanel.setLayout(new GridBagLayout());
213 tk 116
        chanPanel.setOpaque(false);
628 adamjking 117
 
118
        GridBagConstraints c = new GridBagConstraints();
119
        c.fill = GridBagConstraints.HORIZONTAL;
213 tk 120
        c.anchor = GridBagConstraints.CENTER;
628 adamjking 121
 
213 tk 122
        // Loop over all channels
628 adamjking 123
        for (int chan = 0; chan < 8; chan++) {
213 tk 124
            // Dummy panel to fill
628 adamjking 125
            c.gridx = 0;
126
            c.gridy = (2 * chan) + 2;
127
            c.gridheight = 1;
213 tk 128
            JPanel transp = new JPanel();
129
            transp.setOpaque(false);
130
            chanPanel.add(transp, c);
628 adamjking 131
 
213 tk 132
            // Row labels
628 adamjking 133
            c.gridwidth = 2;
134
            if (chan == 0) {
135
                c.gridx = 0;
136
                c.gridy = (2 * chan);
137
                chanPanel.add(createSeqLabel("Step"), c);
138
            }
139
            c.gridx = 0;
140
            c.gridy = (2 * chan) + 1;
141
            chanPanel.add(createSeqLabel("Chan." + Integer.toString(chan + 1)),
142
                    c);
143
            c.gridwidth = 1;
144
 
145
            int offset = (32 * chan) + (seqNr * 256);
146
            for (int col = 0; col < 16; col++) {
213 tk 147
                // Column labels
628 adamjking 148
                if (chan == 0) {
149
                    JLabel label = new JLabel(Integer.toString(col + 1));
213 tk 150
                    label.setHorizontalAlignment(JLabel.CENTER);
628 adamjking 151
                    label.setFont(new Font("serif", Font.BOLD, 10));
213 tk 152
                    label.setOpaque(false);
628 adamjking 153
                    c.gridx = col + 2;
154
                    c.gridy = (2 * chan);
213 tk 155
                    chanPanel.add(label, c);
156
                }
628 adamjking 157
 
250 rutgerv 158
                // Buttons
628 adamjking 159
                c.gridx = col + 2;
160
                c.gridy = 1 + (2 * chan);
161
                SIDSysexParameterControl mp1 = ((SIDSysexParameterControlGUI) vGUI
162
                        .elementAt(0 + offset + col)).getMidiParameter();
163
                SIDSysexParameterControl mp2 = ((SIDSysexParameterControlGUI) vGUI
164
                        .elementAt(0 + offset + col + 16)).getMidiParameter();
165
                chanPanel.add(new SequencerButton(mp1, mp2), c);
166
            }
213 tk 167
        }
628 adamjking 168
        return chanPanel;
169
    }
170
 
213 tk 171
    public JLabel createSeqLabel(String s) {
172
        JLabel label = new JLabel(s);
173
        label.setVerticalAlignment(JLabel.CENTER);
628 adamjking 174
        label.setFont(new Font("serif", Font.BOLD, 10));
175
        label.setOpaque(false);
176
        label.setPreferredSize(new Dimension(35, 10));
213 tk 177
        return label;
178
    }
628 adamjking 179
 
213 tk 180
    public void actionPerformed(ActionEvent ae) {
696 rutgerv 181
        for (int i = 1; i < radioButtons.length; i++) {
182
            if ((ae.getSource() == radioButtons[i])
183
                    && (radioButtons[i].isSelected())) {
184
                seqPanel.remove(currentPanel);
185
                switch (i) {
186
                case 0:
187
                    currentPanel = seq1;
188
                    break;
189
                case 1:
190
                    currentPanel = seq2;
191
                    break;
192
                case 2:
193
                    currentPanel = seq3;
194
                    break;
195
                case 3:
196
                    currentPanel = seq4;
197
                    break;
198
                case 4:
199
                    currentPanel = seq5;
200
                    break;
201
                case 5:
202
                    currentPanel = seq6;
203
                    break;
204
                case 6:
205
                    currentPanel = seq7;
206
                    break;
207
                case 7:
208
                    currentPanel = seq8;
209
                    break;
210
                }
211
                seqPanel.add(currentPanel);
212
                this.repaint();
628 adamjking 213
                break;
213 tk 214
            }
215
        }
216
    }
217
}