Subversion Repositories svn.mios

Rev

Rev 710 | 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;
22
 
23
import java.awt.BorderLayout;
24
import java.awt.Dimension;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.util.Observable;
28
import java.util.Observer;
29
 
30
import javax.swing.BorderFactory;
31
import javax.swing.BoxLayout;
738 adamjking 32
import javax.swing.JButton;
213 tk 33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35
import javax.swing.JToggleButton;
628 adamjking 36
import javax.swing.border.BevelBorder;
213 tk 37
 
628 adamjking 38
import org.midibox.sidedit.SIDEditController;
39
import org.midibox.sidedit.gui.bassline.BasslineGUI;
40
import org.midibox.sidedit.gui.drum.DrumGUI;
738 adamjking 41
import org.midibox.sidedit.gui.ensemble.EnsembleGUI;
628 adamjking 42
import org.midibox.sidedit.gui.lead.LeadGUI;
43
import org.midibox.sidedit.gui.multi.MultiGUI;
213 tk 44
import org.midibox.sidlibr.Patch;
45
import org.midibox.utils.gui.ImageLoader;
46
import org.midibox.utils.gui.MyButtonUI;
47
 
647 adamjking 48
public class MBSIDV2EditorGUI extends JPanel implements Observer,
628 adamjking 49
        ActionListener {
50
 
213 tk 51
    private SIDEditController sidEditController;
52
 
53
    private JPanel editPanel;
628 adamjking 54
 
213 tk 55
    private JLabel tooltipLabel;
628 adamjking 56
 
738 adamjking 57
    private JToggleButton stereoLink, oscillatorLink, core1Button, core2Button,
58
            core3Button, core4Button;
692 rutgerv 59
    private JButton playButton, panicButton;
628 adamjking 60
 
647 adamjking 61
    public MBSIDV2EditorGUI() {
628 adamjking 62
 
213 tk 63
        setLayout(new BorderLayout());
628 adamjking 64
 
213 tk 65
        add(createStatusBar(), BorderLayout.SOUTH);
66
        editPanel = new JPanel();
67
        add(editPanel, BorderLayout.NORTH);
68
    }
628 adamjking 69
 
70
    public void editThis(SIDEditController sidEditController, int cores) {
71
 
213 tk 72
        this.sidEditController = sidEditController;
73
        sidEditController.setTooltipListener(this);
272 rutgerv 74
        oscillatorLink.setSelected(false);
213 tk 75
        setTooltip("");
628 adamjking 76
        core1Button.setSelected(((cores & 0x01) > 0));
77
        core2Button.setSelected(((cores & 0x02) > 0));
78
        core3Button.setSelected(((cores & 0x04) > 0));
79
        core4Button.setSelected(((cores & 0x08) > 0));
647 adamjking 80
 
213 tk 81
        sidEditController.addObserver(this);
628 adamjking 82
        remove(editPanel);
738 adamjking 83
 
666 rutgerv 84
        if (sidEditController.getPatch().isEnsemble()) {
738 adamjking 85
            editPanel = new EnsembleGUI(sidEditController);
666 rutgerv 86
        } else {
738 adamjking 87
            Patch p = (Patch) sidEditController.getPatch();
666 rutgerv 88
            if (p.getEngine() == p.LEAD) {
89
                editPanel = new LeadGUI(sidEditController);
710 rutgerv 90
                stereoLink.setSelected(true);
666 rutgerv 91
            } else if (p.getEngine() == p.BASSLINE) {
92
                editPanel = new BasslineGUI(sidEditController);
710 rutgerv 93
                stereoLink.setSelected(false);
666 rutgerv 94
            } else if (p.getEngine() == p.DRUM) {
95
                editPanel = new DrumGUI(sidEditController);
710 rutgerv 96
                stereoLink.setSelected(false);
666 rutgerv 97
            } else if (p.getEngine() == p.MULTI) {
98
                editPanel = new MultiGUI(sidEditController);
710 rutgerv 99
                stereoLink.setSelected(false);
666 rutgerv 100
            }
738 adamjking 101
        }
213 tk 102
        add(editPanel);
628 adamjking 103
        repaint();
213 tk 104
        setVisible(true);
105
    }
106
 
107
    public SIDEditController getSIDEditController() {
108
        return sidEditController;
109
    }
110
 
111
    public void setSIDEditController(SIDEditController sidEditController) {
112
        this.sidEditController = sidEditController;
113
    }
114
 
115
    public void update(Observable observable, Object object) {
628 adamjking 116
 
213 tk 117
    }
628 adamjking 118
 
213 tk 119
    public JPanel createStatusBar() {
120
        JPanel statusBar = new JPanel();
628 adamjking 121
        statusBar.setLayout(new BorderLayout());
213 tk 122
        statusBar.setBorder(BorderFactory.createRaisedBevelBorder());
628 adamjking 123
 
706 rutgerv 124
        stereoLink = new JToggleButton();
125
        stereoLink.setIcon(ImageLoader.getImageIcon("stereo.png"));
738 adamjking 126
        stereoLink.setPreferredSize(new Dimension(
127
                stereoLink.getPreferredSize().width, 20));
272 rutgerv 128
        stereoLink.addActionListener(this);
628 adamjking 129
 
706 rutgerv 130
        oscillatorLink = new JToggleButton();
131
        oscillatorLink.setIcon(ImageLoader.getImageIcon("link.png"));
738 adamjking 132
        oscillatorLink.setPreferredSize(new Dimension(oscillatorLink
133
                .getPreferredSize().width, 20));
272 rutgerv 134
        oscillatorLink.addActionListener(this);
738 adamjking 135
 
706 rutgerv 136
        playButton = new JButton();
137
        playButton.setIcon(ImageLoader.getImageIcon("play.png"));
738 adamjking 138
        playButton.setPreferredSize(new Dimension(
139
                playButton.getPreferredSize().width, 14));
692 rutgerv 140
        playButton.addActionListener(this);
738 adamjking 141
 
706 rutgerv 142
        panicButton = new JButton();
143
        panicButton.setIcon(ImageLoader.getImageIcon("panic.png"));
738 adamjking 144
        panicButton.setPreferredSize(new Dimension(panicButton
145
                .getPreferredSize().width, 14));
692 rutgerv 146
        panicButton.addActionListener(this);
628 adamjking 147
 
213 tk 148
        JPanel buttonPanel = new JPanel();
628 adamjking 149
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
150
        buttonPanel.setBorder(BorderFactory
151
                .createBevelBorder(BevelBorder.LOWERED));
213 tk 152
        JLabel coreLabel = new JLabel("Cores: ");
628 adamjking 153
        core1Button = new JToggleButton();
154
        core1Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
155
                ImageLoader.getImageIcon("txOff.png")));
213 tk 156
        core1Button.setEnabled(false);
628 adamjking 157
        core2Button = new JToggleButton();
738 adamjking 158
        core2Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
159
                ImageLoader.getImageIcon("txOff.png")));
213 tk 160
        core2Button.setEnabled(false);
628 adamjking 161
        core3Button = new JToggleButton();
162
        core3Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
163
                ImageLoader.getImageIcon("txOff.png")));
213 tk 164
        core3Button.setEnabled(false);
628 adamjking 165
        core4Button = new JToggleButton();
166
        core4Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
167
                ImageLoader.getImageIcon("txOff.png")));
213 tk 168
        core4Button.setEnabled(false);
169
        buttonPanel.add(coreLabel);
170
        buttonPanel.add(core1Button);
171
        buttonPanel.add(core2Button);
172
        buttonPanel.add(core3Button);
173
        buttonPanel.add(core4Button);
628 adamjking 174
 
175
        JLabel empty1Label = new JLabel();
738 adamjking 176
        empty1Label.setBorder(BorderFactory
177
                .createBevelBorder(BevelBorder.LOWERED));
628 adamjking 178
 
179
        tooltipLabel = new JLabel("");
738 adamjking 180
        tooltipLabel.setBorder(BorderFactory
181
                .createBevelBorder(BevelBorder.LOWERED));
628 adamjking 182
 
272 rutgerv 183
        JPanel linkPanel = new JPanel();
184
        linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS));
185
        linkPanel.add(stereoLink);
186
        linkPanel.add(oscillatorLink);
692 rutgerv 187
        linkPanel.add(playButton);
188
        linkPanel.add(panicButton);
628 adamjking 189
 
190
        statusBar.add(linkPanel, BorderLayout.WEST);
213 tk 191
        statusBar.add(tooltipLabel, BorderLayout.CENTER);
192
        statusBar.add(buttonPanel, BorderLayout.EAST);
628 adamjking 193
 
213 tk 194
        return statusBar;
195
    }
628 adamjking 196
 
197
    public void setTooltip(String s) {
198
        tooltipLabel.setText(s);
199
    }
200
 
213 tk 201
    public void actionPerformed(ActionEvent ae) {
202
        editPanel.repaint();
628 adamjking 203
        if (ae.getSource() == stereoLink) {
204
            if (editPanel.getClass() == LeadGUI.class) {
205
                ((LeadGUI) editPanel).stereoLink(stereoLink.isSelected());
206
            } else if (editPanel.getClass() == BasslineGUI.class) {
207
                ((BasslineGUI) editPanel).stereoLink(stereoLink.isSelected());
208
            } else if (editPanel.getClass() == DrumGUI.class) {
209
                ((DrumGUI) editPanel).stereoLink(stereoLink.isSelected());
210
            } else if (editPanel.getClass() == MultiGUI.class) {
211
                ((MultiGUI) editPanel).stereoLink(stereoLink.isSelected());
212
            }
213
        } else if (ae.getSource() == oscillatorLink) {
214
            if (editPanel.getClass() == LeadGUI.class) {
215
                ((LeadGUI) editPanel).oscLink(oscillatorLink.isSelected());
216
            } else if (editPanel.getClass() == BasslineGUI.class) {
272 rutgerv 217
                // Do nothing
628 adamjking 218
            } else if (editPanel.getClass() == DrumGUI.class) {
272 rutgerv 219
                // Do nothing
628 adamjking 220
            } else if (editPanel.getClass() == MultiGUI.class) {
221
                ((MultiGUI) editPanel).oscLink(oscillatorLink.isSelected());
222
            }
692 rutgerv 223
        } else if (ae.getSource() == playButton) {
224
            sidEditController.getPatch().sendPlay();
225
        } else if (ae.getSource() == panicButton) {
226
            sidEditController.getPatch().sendPanic();
213 tk 227
        }
228
    }
628 adamjking 229
}