Subversion Repositories svn.mios

Rev

Rev 293 | Rev 639 | 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;
22
 
23
import java.awt.BorderLayout;
24
import java.awt.Dimension;
628 adamjking 25
import java.awt.Frame;
213 tk 26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
628 adamjking 28
import java.awt.event.WindowAdapter;
29
import java.awt.event.WindowEvent;
213 tk 30
import java.util.Observable;
31
import java.util.Observer;
32
 
33
import javax.swing.BorderFactory;
34
import javax.swing.BoxLayout;
628 adamjking 35
import javax.swing.JDialog;
213 tk 36
import javax.swing.JLabel;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39
import javax.swing.JToggleButton;
628 adamjking 40
import javax.swing.border.BevelBorder;
213 tk 41
 
628 adamjking 42
import org.midibox.sidedit.SIDEditController;
43
import org.midibox.sidedit.gui.bassline.BasslineGUI;
44
import org.midibox.sidedit.gui.drum.DrumGUI;
45
import org.midibox.sidedit.gui.lead.LeadGUI;
46
import org.midibox.sidedit.gui.multi.MultiGUI;
213 tk 47
import org.midibox.sidlibr.Patch;
48
import org.midibox.utils.gui.ImageLoader;
49
import org.midibox.utils.gui.MyButtonUI;
50
 
628 adamjking 51
public class MBSIDV2EditorGUI extends JDialog implements Observer,
52
        ActionListener {
53
 
213 tk 54
    private SIDEditController sidEditController;
55
 
56
    private JPanel editPanel;
628 adamjking 57
 
213 tk 58
    private JLabel tooltipLabel;
628 adamjking 59
 
60
    private JToggleButton stereoLink, oscillatorLink, core1Button, core2Button,
61
            core3Button, core4Button;
62
 
213 tk 63
    public MBSIDV2EditorGUI(Frame owner, boolean modal) {
628 adamjking 64
        super(owner, modal);
65
 
66
        setTitle("MidiBox SID V2 Editor - no patch selected");
67
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
213 tk 68
        setResizable(false);
69
        setLayout(new BorderLayout());
628 adamjking 70
 
213 tk 71
        addWindowListener(new WindowAdapter() {
628 adamjking 72
            public void windowClosing(WindowEvent we) {
73
                saveAndClose();
74
            }
213 tk 75
        });
628 adamjking 76
 
213 tk 77
        add(createStatusBar(), BorderLayout.SOUTH);
78
        editPanel = new JPanel();
79
        add(editPanel, BorderLayout.NORTH);
80
        pack();
81
    }
628 adamjking 82
 
83
    public void editThis(SIDEditController sidEditController, int cores) {
84
        if (isVisible()) {
85
 
86
            int result = JOptionPane
87
                    .showConfirmDialog(
88
                            null,
89
                            "The current patch has been changed. Would you like to save?",
90
                            "Save patch?", JOptionPane.YES_NO_CANCEL_OPTION,
91
                            JOptionPane.QUESTION_MESSAGE);
92
            switch (result) {
93
            case JOptionPane.YES_OPTION:
94
                sidEditController.Save();
95
                break;
96
            case JOptionPane.NO_OPTION:
97
                break;
98
            case JOptionPane.CANCEL_OPTION:
99
                return;
100
            default:
101
                break;
102
            }
103
 
104
        }
105
 
213 tk 106
        this.sidEditController = sidEditController;
107
        sidEditController.setTooltipListener(this);
108
        Patch p = sidEditController.getPatch();
272 rutgerv 109
        stereoLink.setSelected(true);
110
        oscillatorLink.setSelected(false);
213 tk 111
        setTooltip("");
628 adamjking 112
        core1Button.setSelected(((cores & 0x01) > 0));
113
        core2Button.setSelected(((cores & 0x02) > 0));
114
        core3Button.setSelected(((cores & 0x04) > 0));
115
        core4Button.setSelected(((cores & 0x08) > 0));
116
        this.setTitle("MidiBox SID V2 Editor - " + p.getEngineStr()
117
                + " engine: " + p.getPatchName());
213 tk 118
        sidEditController.addObserver(this);
628 adamjking 119
        remove(editPanel);
120
 
121
        if (p.getEngine() == p.LEAD) {
213 tk 122
            editPanel = new LeadGUI(sidEditController);
628 adamjking 123
        } else if (p.getEngine() == p.BASSLINE) {
124
            editPanel = new BasslineGUI(sidEditController);
125
        } else if (p.getEngine() == p.DRUM) {
126
            editPanel = new DrumGUI(sidEditController);
127
        } else if (p.getEngine() == p.MULTI) {
213 tk 128
            editPanel = new MultiGUI(sidEditController);
628 adamjking 129
        }
130
 
213 tk 131
        add(editPanel);
132
        pack();
628 adamjking 133
        repaint();
213 tk 134
        setVisible(true);
135
    }
136
 
137
    public SIDEditController getSIDEditController() {
138
        return sidEditController;
139
    }
140
 
141
    public void setSIDEditController(SIDEditController sidEditController) {
142
        this.sidEditController = sidEditController;
143
    }
144
 
145
    public void update(Observable observable, Object object) {
628 adamjking 146
 
213 tk 147
    }
628 adamjking 148
 
213 tk 149
    public JPanel createStatusBar() {
150
        JPanel statusBar = new JPanel();
628 adamjking 151
        statusBar.setLayout(new BorderLayout());
213 tk 152
        statusBar.setBorder(BorderFactory.createRaisedBevelBorder());
628 adamjking 153
 
272 rutgerv 154
        stereoLink = new JToggleButton("Stereo link");
628 adamjking 155
        stereoLink.setPreferredSize(new Dimension(
156
                stereoLink.getPreferredSize().width, 20));
272 rutgerv 157
        stereoLink.addActionListener(this);
628 adamjking 158
 
272 rutgerv 159
        oscillatorLink = new JToggleButton("Oscillator link");
628 adamjking 160
        oscillatorLink.setPreferredSize(new Dimension(oscillatorLink
161
                .getPreferredSize().width, 20));
272 rutgerv 162
        oscillatorLink.addActionListener(this);
628 adamjking 163
 
213 tk 164
        JPanel buttonPanel = new JPanel();
628 adamjking 165
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
166
        buttonPanel.setBorder(BorderFactory
167
                .createBevelBorder(BevelBorder.LOWERED));
213 tk 168
        JLabel coreLabel = new JLabel("Cores: ");
628 adamjking 169
        core1Button = new JToggleButton();
170
        core1Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
171
                ImageLoader.getImageIcon("txOff.png")));
213 tk 172
        core1Button.setEnabled(false);
628 adamjking 173
        core2Button = new JToggleButton();
174
        core2Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
175
                ImageLoader.getImageIcon("txOff.png")));
213 tk 176
        core2Button.setEnabled(false);
628 adamjking 177
        core3Button = new JToggleButton();
178
        core3Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
179
                ImageLoader.getImageIcon("txOff.png")));
213 tk 180
        core3Button.setEnabled(false);
628 adamjking 181
        core4Button = new JToggleButton();
182
        core4Button.setUI(new MyButtonUI(ImageLoader.getImageIcon("txOn.png"),
183
                ImageLoader.getImageIcon("txOff.png")));
213 tk 184
        core4Button.setEnabled(false);
185
        buttonPanel.add(coreLabel);
186
        buttonPanel.add(core1Button);
187
        buttonPanel.add(core2Button);
188
        buttonPanel.add(core3Button);
189
        buttonPanel.add(core4Button);
628 adamjking 190
 
191
        JLabel empty1Label = new JLabel();
192
        empty1Label.setBorder(BorderFactory
193
                .createBevelBorder(BevelBorder.LOWERED));
194
 
195
        tooltipLabel = new JLabel("");
196
        tooltipLabel.setBorder(BorderFactory
197
                .createBevelBorder(BevelBorder.LOWERED));
198
 
272 rutgerv 199
        JPanel linkPanel = new JPanel();
200
        linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS));
201
        linkPanel.add(stereoLink);
202
        linkPanel.add(oscillatorLink);
628 adamjking 203
 
204
        statusBar.add(linkPanel, BorderLayout.WEST);
213 tk 205
        statusBar.add(tooltipLabel, BorderLayout.CENTER);
206
        statusBar.add(buttonPanel, BorderLayout.EAST);
628 adamjking 207
 
213 tk 208
        return statusBar;
209
    }
628 adamjking 210
 
211
    private void saveAndClose() {
212
        int result = JOptionPane.showConfirmDialog(null,
213
                "The current patch has been changed. Would you like to save?",
214
                "Save patch?", JOptionPane.YES_NO_CANCEL_OPTION,
215
                JOptionPane.QUESTION_MESSAGE);
216
        switch (result) {
217
        case JOptionPane.YES_OPTION:
218
            sidEditController.Save();
219
            this.setVisible(false);
220
            break;
221
        case JOptionPane.NO_OPTION:
222
            this.setVisible(false);
223
            break;
224
        case JOptionPane.CANCEL_OPTION:
225
            break;
226
        default:
227
            break;
213 tk 228
        }
628 adamjking 229
    }
230
 
231
    public void setTooltip(String s) {
232
        tooltipLabel.setText(s);
233
    }
234
 
213 tk 235
    public void actionPerformed(ActionEvent ae) {
236
        editPanel.repaint();
628 adamjking 237
        if (ae.getSource() == stereoLink) {
238
            if (editPanel.getClass() == LeadGUI.class) {
239
                ((LeadGUI) editPanel).stereoLink(stereoLink.isSelected());
240
            } else if (editPanel.getClass() == BasslineGUI.class) {
241
                ((BasslineGUI) editPanel).stereoLink(stereoLink.isSelected());
242
            } else if (editPanel.getClass() == DrumGUI.class) {
243
                ((DrumGUI) editPanel).stereoLink(stereoLink.isSelected());
244
            } else if (editPanel.getClass() == MultiGUI.class) {
245
                ((MultiGUI) editPanel).stereoLink(stereoLink.isSelected());
246
            }
247
        } else if (ae.getSource() == oscillatorLink) {
248
            if (editPanel.getClass() == LeadGUI.class) {
249
                ((LeadGUI) editPanel).oscLink(oscillatorLink.isSelected());
250
            } else if (editPanel.getClass() == BasslineGUI.class) {
272 rutgerv 251
                // Do nothing
628 adamjking 252
            } else if (editPanel.getClass() == DrumGUI.class) {
272 rutgerv 253
                // Do nothing
628 adamjking 254
            } else if (editPanel.getClass() == MultiGUI.class) {
255
                ((MultiGUI) editPanel).oscLink(oscillatorLink.isSelected());
256
            }
213 tk 257
        }
258
    }
628 adamjking 259
}