Subversion Repositories svn.mios

Rev

Rev 753 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 753 Rev 762
1
/*
1
/*
2
 * @(#)MidiFilterGUI.java   beta8   2006/04/23
2
 * @(#)MidiFilterGUI.java   beta8   2006/04/23
3
 *
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
5
 *
5
 *
6
 * This application is free software; you can redistribute it and/or modify
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
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
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
9
 * (at your option) any later version.
10
 *
10
 *
11
 * This application is distributed in the hope that it will be useful,
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
14
 * GNU General Public License for more details.
15
 *
15
 *
16
 * You should have received a copy of the GNU General Public License
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
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
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
19
 */
20
20
21
package org.midibox.midi.gui;
21
package org.midibox.midi.gui;
22
22
23
import java.awt.BorderLayout;
23
import java.awt.BorderLayout;
24
import java.awt.Component;
24
import java.awt.Component;
25
import java.awt.Dimension;
25
import java.awt.Dimension;
26
import java.awt.GridBagConstraints;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
28
import java.awt.Insets;
29
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
30
import java.awt.event.ActionListener;
31
import java.io.File;
31
import java.io.File;
32
import java.util.Iterator;
32
import java.util.Iterator;
33
import java.util.Observable;
33
import java.util.Observable;
34
import java.util.Observer;
34
import java.util.Observer;
35
import java.util.Vector;
35
import java.util.Vector;
36
36
37
import javax.sound.midi.ShortMessage;
37
import javax.sound.midi.ShortMessage;
38
import javax.swing.AbstractCellEditor;
38
import javax.swing.AbstractCellEditor;
39
import javax.swing.BorderFactory;
39
import javax.swing.BorderFactory;
40
import javax.swing.Box;
40
import javax.swing.Box;
41
import javax.swing.JButton;
41
import javax.swing.JButton;
42
import javax.swing.JCheckBox;
42
import javax.swing.JCheckBox;
43
import javax.swing.JComponent;
43
import javax.swing.JComponent;
44
import javax.swing.JFileChooser;
44
import javax.swing.JFileChooser;
45
import javax.swing.JMenuItem;
45
import javax.swing.JMenuItem;
46
import javax.swing.JOptionPane;
46
import javax.swing.JOptionPane;
47
import javax.swing.JPanel;
47
import javax.swing.JPanel;
48
import javax.swing.JPopupMenu;
48
import javax.swing.JPopupMenu;
49
import javax.swing.JScrollPane;
49
import javax.swing.JScrollPane;
50
import javax.swing.JTable;
50
import javax.swing.JTable;
51
import javax.swing.JToolBar;
51
import javax.swing.JToolBar;
52
import javax.swing.event.PopupMenuEvent;
52
import javax.swing.event.PopupMenuEvent;
53
import javax.swing.event.PopupMenuListener;
53
import javax.swing.event.PopupMenuListener;
54
import javax.swing.table.DefaultTableCellRenderer;
54
import javax.swing.table.DefaultTableCellRenderer;
55
import javax.swing.table.DefaultTableModel;
55
import javax.swing.table.DefaultTableModel;
56
import javax.swing.table.TableCellEditor;
56
import javax.swing.table.TableCellEditor;
57
57
58
import org.midibox.midi.MidiFilter;
58
import org.midibox.midi.MidiFilter;
59
import org.midibox.midi.MidiUtils;
59
import org.midibox.midi.MidiUtils;
60
import org.midibox.midi.xml.MidiFilterXML;
60
import org.midibox.midi.xml.MidiFilterXML;
61
import org.midibox.mios.gui.HexFileUploadGUI;
-
 
62
import org.midibox.utils.gui.ImageLoader;
61
import org.midibox.utils.gui.ImageLoader;
63
import org.midibox.utils.gui.SimpleFileChooserFilter;
62
import org.midibox.utils.gui.SimpleFileChooserFilter;
64
import org.midibox.utils.gui.SplitButton;
63
import org.midibox.utils.gui.SplitButton;
65
64
66
public class MidiFilterGUI extends JPanel implements Observer, ActionListener {
65
public class MidiFilterGUI extends JPanel implements Observer, ActionListener {
67
66
68
    private MidiFilter midiFilter;
67
    private MidiFilter midiFilter;
69
68
70
    private JCheckBox voiceMessages;
69
    private JCheckBox voiceMessages;
71
70
72
    private JCheckBox systemCommonMessages;
71
    private JCheckBox systemCommonMessages;
73
72
74
    private JCheckBox systemRealtimeMessages;
73
    private JCheckBox systemRealtimeMessages;
75
74
76
    private JCheckBox sysexMessages;
75
    private JCheckBox sysexMessages;
77
76
78
    private JCheckBox metaMessages;
77
    private JCheckBox metaMessages;
79
78
80
    private JCheckBox activeSensing;
79
    private JCheckBox activeSensing;
81
80
82
    private JCheckBox channelPressure;
81
    private JCheckBox channelPressure;
83
82
84
    private JCheckBox continueMessage;
83
    private JCheckBox continueMessage;
85
84
86
    private JCheckBox controlChange;
85
    private JCheckBox controlChange;
87
86
88
    private JCheckBox midiTimeCode;
87
    private JCheckBox midiTimeCode;
89
88
90
    private JCheckBox noteOff;
89
    private JCheckBox noteOff;
91
90
92
    private JCheckBox noteOn;
91
    private JCheckBox noteOn;
93
92
94
    private JCheckBox pitchBend;
93
    private JCheckBox pitchBend;
95
94
96
    private JCheckBox polyPressure;
95
    private JCheckBox polyPressure;
97
96
98
    private JCheckBox programChange;
97
    private JCheckBox programChange;
99
98
100
    private JCheckBox songPositionPointer;
99
    private JCheckBox songPositionPointer;
101
100
102
    private JCheckBox songSelect;
101
    private JCheckBox songSelect;
103
102
104
    private JCheckBox start;
103
    private JCheckBox start;
105
104
106
    private JCheckBox stop;
105
    private JCheckBox stop;
107
106
108
    private JCheckBox systemReset;
107
    private JCheckBox systemReset;
109
108
110
    private JCheckBox timingClock;
109
    private JCheckBox timingClock;
111
110
112
    private JCheckBox tuneRequest;
111
    private JCheckBox tuneRequest;
113
112
114
    private JTable controlChangeTable;
113
    private JTable controlChangeTable;
115
114
116
    private DefaultTableModel controlChangeModel;
115
    private DefaultTableModel controlChangeModel;
117
116
118
    private JTable channelsTable;
117
    private JTable channelsTable;
119
118
120
    private DefaultTableModel channelsModel;
119
    private DefaultTableModel channelsModel;
121
   
120
   
122
    private JPopupMenu MRUPopupMenu;
121
    private JPopupMenu MRUPopupMenu;
123
   
122
   
124
    private SplitButton openMRUButton;
123
    private SplitButton openMRUButton;
125
124
126
    private static int maxMRU = 10;
125
    private static int maxMRU = 10;
127
126
128
    private static String currentDirectory = "";
127
    private static String currentDirectory = "";
129
   
128
   
130
    private static Vector MRU = new Vector();
129
    private static Vector MRU = new Vector();
131
130
132
    private static JFileChooser fc = null;
131
    private static JFileChooser fc = null;
133
132
134
    public MidiFilterGUI(MidiFilter midiFilter) {
133
    public MidiFilterGUI(MidiFilter midiFilter) {
135
        super(new BorderLayout(5, 5));
134
        super(new BorderLayout(5, 5));
136
        this.midiFilter = midiFilter;
135
        this.midiFilter = midiFilter;
137
136
138
        midiFilter.addObserver(this);
137
        midiFilter.addObserver(this);
139
138
140
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
139
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
141
140
142
        // voice messages
141
        // voice messages
143
        JPanel masterPanel = new JPanel(new GridBagLayout());
142
        JPanel masterPanel = new JPanel(new GridBagLayout());
144
        GridBagConstraints gbc = new GridBagConstraints();
143
        GridBagConstraints gbc = new GridBagConstraints();
145
        gbc.gridx = 0;
144
        gbc.gridx = 0;
146
        gbc.gridy = 0;
145
        gbc.gridy = 0;
147
        gbc.anchor = GridBagConstraints.NORTHWEST;
146
        gbc.anchor = GridBagConstraints.NORTHWEST;
148
        gbc.fill = GridBagConstraints.BOTH;
147
        gbc.fill = GridBagConstraints.BOTH;
149
        gbc.weightx = 1.0;
148
        gbc.weightx = 1.0;
150
        gbc.insets = new Insets(0, 2, 0, 2);
149
        gbc.insets = new Insets(0, 2, 0, 2);
151
150
152
        masterPanel.setBorder(BorderFactory.createTitledBorder("Message Type"));
151
        masterPanel.setBorder(BorderFactory.createTitledBorder("Message Type"));
153
152
154
        voiceMessages = new JCheckBox("Voice", midiFilter.isVoiceMessages());
153
        voiceMessages = new JCheckBox("Voice", midiFilter.isVoiceMessages());
155
        voiceMessages.addActionListener(this);
154
        voiceMessages.addActionListener(this);
156
155
157
        masterPanel.add(voiceMessages, gbc);
156
        masterPanel.add(voiceMessages, gbc);
158
        gbc.gridy++;
157
        gbc.gridy++;
159
158
160
        systemCommonMessages = new JCheckBox("System Common", midiFilter
159
        systemCommonMessages = new JCheckBox("System Common", midiFilter
161
                .isSystemCommonMessages());
160
                .isSystemCommonMessages());
162
        systemCommonMessages.addActionListener(this);
161
        systemCommonMessages.addActionListener(this);
163
162
164
        masterPanel.add(systemCommonMessages, gbc);
163
        masterPanel.add(systemCommonMessages, gbc);
165
        gbc.gridy++;
164
        gbc.gridy++;
166
165
167
        systemRealtimeMessages = new JCheckBox("System Realtime", midiFilter
166
        systemRealtimeMessages = new JCheckBox("System Realtime", midiFilter
168
                .isSystemRealtimeMessages());
167
                .isSystemRealtimeMessages());
169
        systemRealtimeMessages.addActionListener(this);
168
        systemRealtimeMessages.addActionListener(this);
170
169
171
        masterPanel.add(systemRealtimeMessages, gbc);
170
        masterPanel.add(systemRealtimeMessages, gbc);
172
        gbc.gridy++;
171
        gbc.gridy++;
173
172
174
        sysexMessages = new JCheckBox("SysEx", midiFilter.isSysexMessages());
173
        sysexMessages = new JCheckBox("SysEx", midiFilter.isSysexMessages());
175
        sysexMessages.addActionListener(this);
174
        sysexMessages.addActionListener(this);
176
175
177
        masterPanel.add(sysexMessages, gbc);
176
        masterPanel.add(sysexMessages, gbc);
178
        gbc.gridy++;
177
        gbc.gridy++;
179
178
180
        metaMessages = new JCheckBox("Meta", midiFilter.isMetaMessages());
179
        metaMessages = new JCheckBox("Meta", midiFilter.isMetaMessages());
181
        metaMessages.addActionListener(this);
180
        metaMessages.addActionListener(this);
182
181
183
        masterPanel.add(metaMessages, gbc);
182
        masterPanel.add(metaMessages, gbc);
184
        gbc.gridy++;
183
        gbc.gridy++;
185
184
186
        gbc.weighty = 1.0;
185
        gbc.weighty = 1.0;
187
        masterPanel.add(Box.createVerticalGlue(), gbc);
186
        masterPanel.add(Box.createVerticalGlue(), gbc);
188
187
189
        JPanel voicePanel = new JPanel(new GridBagLayout());
188
        JPanel voicePanel = new JPanel(new GridBagLayout());
190
        gbc.gridy = 0;
189
        gbc.gridy = 0;
191
        gbc.weighty = 0.0;
190
        gbc.weighty = 0.0;
192
191
193
        voicePanel.setBorder(BorderFactory.createTitledBorder("Voice"));
192
        voicePanel.setBorder(BorderFactory.createTitledBorder("Voice"));
194
193
195
        noteOff = new JCheckBox("Note Off", midiFilter
194
        noteOff = new JCheckBox("Note Off", midiFilter
196
                .getVoiceMessage(ShortMessage.NOTE_OFF));
195
                .getVoiceMessage(ShortMessage.NOTE_OFF));
197
        noteOff.addActionListener(this);
196
        noteOff.addActionListener(this);
198
        voicePanel.add(noteOff, gbc);
197
        voicePanel.add(noteOff, gbc);
199
        gbc.gridy++;
198
        gbc.gridy++;
200
199
201
        noteOn = new JCheckBox("Note On", midiFilter
200
        noteOn = new JCheckBox("Note On", midiFilter
202
                .getVoiceMessage(ShortMessage.NOTE_ON));
201
                .getVoiceMessage(ShortMessage.NOTE_ON));
203
        noteOn.addActionListener(this);
202
        noteOn.addActionListener(this);
204
        voicePanel.add(noteOn, gbc);
203
        voicePanel.add(noteOn, gbc);
205
        gbc.gridy++;
204
        gbc.gridy++;
206
205
207
        polyPressure = new JCheckBox("Aftertouch", midiFilter
206
        polyPressure = new JCheckBox("Aftertouch", midiFilter
208
                .getVoiceMessage(ShortMessage.POLY_PRESSURE));
207
                .getVoiceMessage(ShortMessage.POLY_PRESSURE));
209
        polyPressure.addActionListener(this);
208
        polyPressure.addActionListener(this);
210
        voicePanel.add(polyPressure, gbc);
209
        voicePanel.add(polyPressure, gbc);
211
        gbc.gridy++;
210
        gbc.gridy++;
212
211
213
        controlChange = new JCheckBox("Control Change", midiFilter
212
        controlChange = new JCheckBox("Control Change", midiFilter
214
                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
213
                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
215
        controlChange.addActionListener(this);
214
        controlChange.addActionListener(this);
216
        voicePanel.add(controlChange, gbc);
215
        voicePanel.add(controlChange, gbc);
217
        gbc.gridy++;
216
        gbc.gridy++;
218
217
219
        programChange = new JCheckBox("Program Change", midiFilter
218
        programChange = new JCheckBox("Program Change", midiFilter
220
                .getVoiceMessage(ShortMessage.PROGRAM_CHANGE));
219
                .getVoiceMessage(ShortMessage.PROGRAM_CHANGE));
221
        programChange.addActionListener(this);
220
        programChange.addActionListener(this);
222
        voicePanel.add(programChange, gbc);
221
        voicePanel.add(programChange, gbc);
223
        gbc.gridy++;
222
        gbc.gridy++;
224
223
225
        channelPressure = new JCheckBox("Channel Pressure", midiFilter
224
        channelPressure = new JCheckBox("Channel Pressure", midiFilter
226
                .getVoiceMessage(ShortMessage.CHANNEL_PRESSURE));
225
                .getVoiceMessage(ShortMessage.CHANNEL_PRESSURE));
227
        channelPressure.addActionListener(this);
226
        channelPressure.addActionListener(this);
228
        voicePanel.add(channelPressure, gbc);
227
        voicePanel.add(channelPressure, gbc);
229
        gbc.gridy++;
228
        gbc.gridy++;
230
229
231
        pitchBend = new JCheckBox("Pitch Bend", midiFilter
230
        pitchBend = new JCheckBox("Pitch Bend", midiFilter
232
                .getVoiceMessage(ShortMessage.PITCH_BEND));
231
                .getVoiceMessage(ShortMessage.PITCH_BEND));
233
        pitchBend.addActionListener(this);
232
        pitchBend.addActionListener(this);
234
        voicePanel.add(pitchBend, gbc);
233
        voicePanel.add(pitchBend, gbc);
235
        gbc.gridy++;
234
        gbc.gridy++;
236
235
237
        gbc.weighty = 1.0;
236
        gbc.weighty = 1.0;
238
        voicePanel.add(Box.createVerticalGlue(), gbc);
237
        voicePanel.add(Box.createVerticalGlue(), gbc);
239
238
240
        gbc.gridheight = 8;
239
        gbc.gridheight = 8;
241
        gbc.weighty = 0.0;
240
        gbc.weighty = 0.0;
242
        gbc.gridy = 0;
241
        gbc.gridy = 0;
243
242
244
        gbc.gridx++;
243
        gbc.gridx++;
245
244
246
        controlChangeModel = new MidiFilterTableModel(
245
        controlChangeModel = new MidiFilterTableModel(
247
                new String[] { "Controller" }, 128);
246
                new String[] { "Controller" }, 128);
248
        controlChangeTable = new JTable(controlChangeModel);
247
        controlChangeTable = new JTable(controlChangeModel);
249
248
250
        JScrollPane ccScroll = new JScrollPane(controlChangeTable);
249
        JScrollPane ccScroll = new JScrollPane(controlChangeTable);
251
        ccScroll
250
        ccScroll
252
                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
251
                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
253
        ccScroll.setPreferredSize(new Dimension(200, 200));
252
        ccScroll.setPreferredSize(new Dimension(200, 200));
254
        controlChangeTable.setRowSelectionAllowed(false);
253
        controlChangeTable.setRowSelectionAllowed(false);
255
        controlChangeTable.setShowGrid(false);
254
        controlChangeTable.setShowGrid(false);
256
        controlChangeTable.setDefaultRenderer(Boolean.class,
255
        controlChangeTable.setDefaultRenderer(Boolean.class,
257
                new MidiFilterTableCellRenderer());
256
                new MidiFilterTableCellRenderer());
258
        controlChangeTable.setDefaultEditor(Boolean.class,
257
        controlChangeTable.setDefaultEditor(Boolean.class,
259
                new MidiFilterTableCellEditor());
258
                new MidiFilterTableCellEditor());
260
259
261
        voicePanel.add(ccScroll, gbc);
260
        voicePanel.add(ccScroll, gbc);
262
261
263
        gbc.gridx++;
262
        gbc.gridx++;
264
263
265
        channelsModel = new MidiFilterTableModel(new String[] { "Channel" }, 16);
264
        channelsModel = new MidiFilterTableModel(new String[] { "Channel" }, 16);
266
        channelsTable = new JTable(channelsModel);
265
        channelsTable = new JTable(channelsModel);
267
266
268
        JScrollPane channelsScroll = new JScrollPane(channelsTable);
267
        JScrollPane channelsScroll = new JScrollPane(channelsTable);
269
        channelsScroll
268
        channelsScroll
270
                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
269
                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
271
        channelsScroll.setPreferredSize(new Dimension(150, 200));
270
        channelsScroll.setPreferredSize(new Dimension(150, 200));
272
        channelsTable.setCellSelectionEnabled(false);
271
        channelsTable.setCellSelectionEnabled(false);
273
        channelsTable.setShowGrid(false);
272
        channelsTable.setShowGrid(false);
274
        channelsTable.setDefaultRenderer(Boolean.class,
273
        channelsTable.setDefaultRenderer(Boolean.class,
275
                new MidiFilterTableCellRenderer());
274
                new MidiFilterTableCellRenderer());
276
        channelsTable.setDefaultEditor(Boolean.class,
275
        channelsTable.setDefaultEditor(Boolean.class,
277
                new MidiFilterTableCellEditor());
276
                new MidiFilterTableCellEditor());
278
277
279
        voicePanel.add(channelsScroll, gbc);
278
        voicePanel.add(channelsScroll, gbc);
280
279
281
        // system common
280
        // system common
282
        JPanel systemCommonPanel = new JPanel(new GridBagLayout());
281
        JPanel systemCommonPanel = new JPanel(new GridBagLayout());
283
        gbc.gridy = 0;
282
        gbc.gridy = 0;
284
        gbc.weighty = 0.0;
283
        gbc.weighty = 0.0;
285
        gbc.gridheight = 1;
284
        gbc.gridheight = 1;
286
        systemCommonPanel.setBorder(BorderFactory
285
        systemCommonPanel.setBorder(BorderFactory
287
                .createTitledBorder("System Common"));
286
                .createTitledBorder("System Common"));
288
287
289
        midiTimeCode = new JCheckBox("MTC Quarter Frame", midiFilter
288
        midiTimeCode = new JCheckBox("MTC Quarter Frame", midiFilter
290
                .getSystemCommonMessage(ShortMessage.MIDI_TIME_CODE));
289
                .getSystemCommonMessage(ShortMessage.MIDI_TIME_CODE));
291
        midiTimeCode.addActionListener(this);
290
        midiTimeCode.addActionListener(this);
292
        systemCommonPanel.add(midiTimeCode, gbc);
291
        systemCommonPanel.add(midiTimeCode, gbc);
293
        gbc.gridy++;
292
        gbc.gridy++;
294
293
295
        songPositionPointer = new JCheckBox("Song Position Pointer", midiFilter
294
        songPositionPointer = new JCheckBox("Song Position Pointer", midiFilter
296
                .getSystemCommonMessage(ShortMessage.SONG_POSITION_POINTER));
295
                .getSystemCommonMessage(ShortMessage.SONG_POSITION_POINTER));
297
        songPositionPointer.addActionListener(this);
296
        songPositionPointer.addActionListener(this);
298
        systemCommonPanel.add(songPositionPointer, gbc);
297
        systemCommonPanel.add(songPositionPointer, gbc);
299
        gbc.gridy++;
298
        gbc.gridy++;
300
299
301
        songSelect = new JCheckBox("Song Select", midiFilter
300
        songSelect = new JCheckBox("Song Select", midiFilter
302
                .getSystemCommonMessage(ShortMessage.SONG_SELECT));
301
                .getSystemCommonMessage(ShortMessage.SONG_SELECT));
303
        songSelect.addActionListener(this);
302
        songSelect.addActionListener(this);
304
        systemCommonPanel.add(songSelect, gbc);
303
        systemCommonPanel.add(songSelect, gbc);
305
        gbc.gridy++;
304
        gbc.gridy++;
306
305
307
        tuneRequest = new JCheckBox("Tune Request", midiFilter
306
        tuneRequest = new JCheckBox("Tune Request", midiFilter
308
                .getSystemCommonMessage(ShortMessage.TUNE_REQUEST));
307
                .getSystemCommonMessage(ShortMessage.TUNE_REQUEST));
309
        tuneRequest.addActionListener(this);
308
        tuneRequest.addActionListener(this);
310
        systemCommonPanel.add(tuneRequest, gbc);
309
        systemCommonPanel.add(tuneRequest, gbc);
311
        gbc.gridy++;
310
        gbc.gridy++;
312
311
313
        gbc.weighty = 1.0;
312
        gbc.weighty = 1.0;
314
        systemCommonPanel.add(Box.createVerticalGlue(), gbc);
313
        systemCommonPanel.add(Box.createVerticalGlue(), gbc);
315
314
316
        // system realtime
315
        // system realtime
317
        JPanel systemRealtimePanel = new JPanel(new GridBagLayout());
316
        JPanel systemRealtimePanel = new JPanel(new GridBagLayout());
318
        gbc.gridy = 0;
317
        gbc.gridy = 0;
319
        gbc.weighty = 0.0;
318
        gbc.weighty = 0.0;
320
        systemRealtimePanel.setBorder(BorderFactory
319
        systemRealtimePanel.setBorder(BorderFactory
321
                .createTitledBorder("System Realtime"));
320
                .createTitledBorder("System Realtime"));
322
321
323
        timingClock = new JCheckBox("Timing Clock", midiFilter
322
        timingClock = new JCheckBox("Timing Clock", midiFilter
324
                .getSystemRealtimeMessage(ShortMessage.TIMING_CLOCK));
323
                .getSystemRealtimeMessage(ShortMessage.TIMING_CLOCK));
325
        timingClock.addActionListener(this);
324
        timingClock.addActionListener(this);
326
        systemRealtimePanel.add(timingClock, gbc);
325
        systemRealtimePanel.add(timingClock, gbc);
327
        gbc.gridy++;
326
        gbc.gridy++;
328
327
329
        start = new JCheckBox("Start", midiFilter
328
        start = new JCheckBox("Start", midiFilter
330
                .getSystemRealtimeMessage(ShortMessage.START));
329
                .getSystemRealtimeMessage(ShortMessage.START));
331
        start.addActionListener(this);
330
        start.addActionListener(this);
332
        systemRealtimePanel.add(start, gbc);
331
        systemRealtimePanel.add(start, gbc);
333
        gbc.gridy++;
332
        gbc.gridy++;
334
333
335
        continueMessage = new JCheckBox("Continue", midiFilter
334
        continueMessage = new JCheckBox("Continue", midiFilter
336
                .getSystemRealtimeMessage(ShortMessage.CONTINUE));
335
                .getSystemRealtimeMessage(ShortMessage.CONTINUE));
337
        continueMessage.addActionListener(this);
336
        continueMessage.addActionListener(this);
338
        systemRealtimePanel.add(continueMessage, gbc);
337
        systemRealtimePanel.add(continueMessage, gbc);
339
        gbc.gridy++;
338
        gbc.gridy++;
340
339
341
        stop = new JCheckBox("Stop", midiFilter
340
        stop = new JCheckBox("Stop", midiFilter
342
                .getSystemRealtimeMessage(ShortMessage.STOP));
341
                .getSystemRealtimeMessage(ShortMessage.STOP));
343
        stop.addActionListener(this);
342
        stop.addActionListener(this);
344
        systemRealtimePanel.add(stop, gbc);
343
        systemRealtimePanel.add(stop, gbc);
345
        gbc.gridy++;
344
        gbc.gridy++;
346
345
347
        activeSensing = new JCheckBox("Active Sensing", midiFilter
346
        activeSensing = new JCheckBox("Active Sensing", midiFilter
348
                .getSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING));
347
                .getSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING));
349
        activeSensing.addActionListener(this);
348
        activeSensing.addActionListener(this);
350
        systemRealtimePanel.add(activeSensing, gbc);
349
        systemRealtimePanel.add(activeSensing, gbc);
351
        gbc.gridy++;
350
        gbc.gridy++;
352
351
353
        systemReset = new JCheckBox("System Reset", midiFilter
352
        systemReset = new JCheckBox("System Reset", midiFilter
354
                .getSystemRealtimeMessage(ShortMessage.SYSTEM_RESET));
353
                .getSystemRealtimeMessage(ShortMessage.SYSTEM_RESET));
355
        systemReset.addActionListener(this);
354
        systemReset.addActionListener(this);
356
        systemRealtimePanel.add(systemReset, gbc);
355
        systemRealtimePanel.add(systemReset, gbc);
357
        gbc.gridy++;
356
        gbc.gridy++;
358
357
359
        gbc.weighty = 1.0;
358
        gbc.weighty = 1.0;
360
        systemRealtimePanel.add(Box.createVerticalGlue(), gbc);
359
        systemRealtimePanel.add(Box.createVerticalGlue(), gbc);
361
360
362
        JPanel mainPanel = new JPanel(new GridBagLayout());
361
        JPanel mainPanel = new JPanel(new GridBagLayout());
363
        gbc.gridx = 0;
362
        gbc.gridx = 0;
364
        gbc.gridy = 0;
363
        gbc.gridy = 0;
365
364
366
        mainPanel.add(masterPanel, gbc);
365
        mainPanel.add(masterPanel, gbc);
367
        gbc.gridx++;
366
        gbc.gridx++;
368
367
369
        mainPanel.add(voicePanel, gbc);
368
        mainPanel.add(voicePanel, gbc);
370
        gbc.gridx++;
369
        gbc.gridx++;
371
370
372
        mainPanel.add(systemCommonPanel, gbc);
371
        mainPanel.add(systemCommonPanel, gbc);
373
        gbc.gridx++;
372
        gbc.gridx++;
374
373
375
        mainPanel.add(systemRealtimePanel, gbc);
374
        mainPanel.add(systemRealtimePanel, gbc);
376
375
377
        add(mainPanel, BorderLayout.CENTER);
376
        add(mainPanel, BorderLayout.CENTER);
378
377
379
        add(createToolBar(), BorderLayout.NORTH);
378
        add(createToolBar(), BorderLayout.NORTH);
380
379
381
        setButtonStates();
380
        setButtonStates();
382
    }
381
    }
383
382
384
    private JToolBar createToolBar() {
383
    private JToolBar createToolBar() {
385
384
386
        JToolBar toolBar = new JToolBar();
385
        JToolBar toolBar = new JToolBar();
387
386
388
        toolBar.setRollover(true);
387
        toolBar.setRollover(true);
389
388
390
        toolBar.setFloatable(false);
389
        toolBar.setFloatable(false);
391
390
392
        JButton button = new JButton(ImageLoader.getImageIcon("open.png"));
391
        JButton button = new JButton(ImageLoader.getImageIcon("open.png"));
393
392
394
        button.addActionListener(this);
393
        button.addActionListener(this);
395
394
396
        button.setMargin(new Insets(2, 2, 2, 2));
395
        button.setMargin(new Insets(2, 2, 2, 2));
397
396
398
        button.setToolTipText("Load MIDI filter definition");
397
        button.setToolTipText("Load MIDI filter definition");
399
398
400
        button.setActionCommand("load");
399
        button.setActionCommand("load");
401
400
402
        MRUPopupMenu = new JPopupMenu();
401
        MRUPopupMenu = new JPopupMenu();
403
        MRUPopupMenu.addPopupMenuListener(new PopupMenuListener() {
402
        MRUPopupMenu.addPopupMenuListener(new PopupMenuListener() {
404
403
405
            public void popupMenuCanceled(PopupMenuEvent e) {
404
            public void popupMenuCanceled(PopupMenuEvent e) {
406
405
407
            }
406
            }
408
407
409
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
408
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
410
409
411
            }
410
            }
412
411
413
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
412
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
414
413
415
                MidiFilterGUI.this.buildMRUMenu(MRUPopupMenu);
414
                MidiFilterGUI.this.buildMRUMenu(MRUPopupMenu);
416
415
417
            }
416
            }
418
        });
417
        });
419
418
420
        openMRUButton = new SplitButton(button, MRUPopupMenu);
419
        openMRUButton = new SplitButton(button, MRUPopupMenu);
421
        openMRUButton.setRollover(true);
420
        openMRUButton.setRollover(true);
422
       
421
       
423
        toolBar.add(openMRUButton);
422
        toolBar.add(openMRUButton);
424
423
425
        button = new JButton(ImageLoader.getImageIcon("save.png"));
424
        button = new JButton(ImageLoader.getImageIcon("save.png"));
426
425
427
        button.setToolTipText("Save MIDI filter definition");
426
        button.setToolTipText("Save MIDI filter definition");
428
427
429
        button.setActionCommand("save");
428
        button.setActionCommand("save");
430
429
431
        button.addActionListener(this);
430
        button.addActionListener(this);
432
431
433
        button.setMargin(new Insets(2, 2, 2, 2));
432
        button.setMargin(new Insets(2, 2, 2, 2));
434
433
435
        toolBar.add(button);
434
        toolBar.add(button);
436
435
437
        return toolBar;
436
        return toolBar;
438
    }
437
    }
439
438
440
    protected void loadFilterDefinition() {
439
    protected void loadFilterDefinition() {
441
440
442
        if (fc == null) {
441
        if (fc == null) {
443
            fc = new JFileChooser(currentDirectory);
442
            fc = new JFileChooser(currentDirectory);
444
            SimpleFileChooserFilter fileFilter = new SimpleFileChooserFilter(
443
            SimpleFileChooserFilter fileFilter = new SimpleFileChooserFilter(
445
                    "XML files", "xml", "XML Filter Definition");
444
                    "XML files", "xml", "XML Filter Definition");
446
            fc.addChoosableFileFilter(fileFilter);
445
            fc.addChoosableFileFilter(fileFilter);
447
            fc.setAcceptAllFileFilterUsed(false);
446
            fc.setAcceptAllFileFilterUsed(false);
448
        }
447
        }
449
448
450
        File noFile = new File("");
449
        File noFile = new File("");
451
        File noFiles[] = { noFile };
450
        File noFiles[] = { noFile };
452
        fc.setSelectedFile(noFile);
451
        fc.setSelectedFile(noFile);
453
        fc.setSelectedFiles(noFiles);
452
        fc.setSelectedFiles(noFiles);
454
453
455
        int nRetVal = fc.showOpenDialog(this);
454
        int nRetVal = fc.showOpenDialog(this);
456
455
457
        if (nRetVal == JFileChooser.APPROVE_OPTION) {
456
        if (nRetVal == JFileChooser.APPROVE_OPTION) {
458
            File file = fc.getSelectedFile();
457
            File file = fc.getSelectedFile();
459
458
460
            loadFilterDefinition(file);
459
            loadFilterDefinition(file);
461
460
462
            setButtonStates();
461
            setButtonStates();
463
462
464
            currentDirectory = fc.getCurrentDirectory().toString();
463
            currentDirectory = fc.getCurrentDirectory().toString();
465
        }
464
        }
466
    }
465
    }
467
   
466
   
468
    protected void loadFilterDefinition(File file) {
467
    protected void loadFilterDefinition(File file) {
469
       
468
       
470
        if (file.exists()) {
469
        if (file.exists()) {
471
           
470
           
472
            MidiFilterXML midiFilterXML = new MidiFilterXML(midiFilter,
471
            MidiFilterXML midiFilterXML = new MidiFilterXML(midiFilter,
473
                    MidiFilterXML.TAG_ROOT_ELEMENT);
472
                    MidiFilterXML.TAG_ROOT_ELEMENT);
474
473
475
            midiFilterXML.loadXML(file);
474
            midiFilterXML.loadXML(file);
476
           
475
           
477
            saveMRU(file.getPath());
476
            saveMRU(file.getPath());
478
           
477
           
479
        } else {
478
        } else {
480
            JOptionPane.showMessageDialog(this,
479
            JOptionPane.showMessageDialog(this,
481
                    "MIDI filter definition no longer exists",
480
                    "MIDI filter definition no longer exists",
482
                    "File does not exist", JOptionPane.ERROR_MESSAGE);
481
                    "File does not exist", JOptionPane.ERROR_MESSAGE);
483
        }
482
        }
484
    }
483
    }
485
   
484
   
486
    private void buildMRUMenu(JComponent menu) {
485
    private void buildMRUMenu(JComponent menu) {
487
486
488
        menu.removeAll();
487
        menu.removeAll();
489
488
490
        Iterator it = MRU.iterator();
489
        Iterator it = MRU.iterator();
491
490
492
        while (it.hasNext()) {
491
        while (it.hasNext()) {
493
492
494
            final JMenuItem menuItem = new JMenuItem((String) it.next());
493
            final JMenuItem menuItem = new JMenuItem((String) it.next());
495
494
496
            menuItem.addActionListener(new ActionListener() {
495
            menuItem.addActionListener(new ActionListener() {
497
496
498
                public void actionPerformed(ActionEvent ae) {
497
                public void actionPerformed(ActionEvent ae) {
499
498
500
                    File file = new File(menuItem.getText());
499
                    File file = new File(menuItem.getText());
501
500
502
                    loadFilterDefinition(file);
501
                    loadFilterDefinition(file);
503
                }
502
                }
504
            });
503
            });
505
504
506
            menu.add(menuItem, 0);
505
            menu.add(menuItem, 0);
507
        }
506
        }
508
    }
507
    }
509
   
508
   
510
    public static void saveMRU(String file) {
509
    public static void saveMRU(String file) {
511
510
512
        MRU.remove(file);
511
        MRU.remove(file);
513
512
514
        MRU.add(file);
513
        MRU.add(file);
515
514
516
        for (int i = MRU.size() - maxMRU; i > 0; i--) {
515
        for (int i = MRU.size() - maxMRU; i > 0; i--) {
517
516
518
            MRU.removeElementAt(i - 1);
517
            MRU.removeElementAt(i - 1);
519
        }
518
        }
520
    }
519
    }
521
   
520
   
522
    public static Vector getMRU() {
521
    public static Vector getMRU() {
523
        return MRU;
522
        return MRU;
524
    }
523
    }
525
524
526
    protected void saveFilterDefinition() {
525
    protected void saveFilterDefinition() {
527
526
528
        if (fc == null) {
527
        if (fc == null) {
529
            fc = new JFileChooser(currentDirectory);
528
            fc = new JFileChooser(currentDirectory);
530
            SimpleFileChooserFilter fileFilter = new SimpleFileChooserFilter(
529
            SimpleFileChooserFilter fileFilter = new SimpleFileChooserFilter(
531
                    "XML files", "xml", "XML Filter Definition");
530
                    "XML files", "xml", "XML Filter Definition");
532
            fc.addChoosableFileFilter(fileFilter);
531
            fc.addChoosableFileFilter(fileFilter);
533
            fc.setAcceptAllFileFilterUsed(false);
532
            fc.setAcceptAllFileFilterUsed(false);
534
        }
533
        }
535
534
536
        File noFile = new File("");
535
        File noFile = new File("");
537
        File noFiles[] = { noFile };
536
        File noFiles[] = { noFile };
538
        fc.setSelectedFile(noFile);
537
        fc.setSelectedFile(noFile);
539
        fc.setSelectedFiles(noFiles);
538
        fc.setSelectedFiles(noFiles);
540
539
541
        int nRetVal = fc.showSaveDialog(this);
540
        int nRetVal = fc.showSaveDialog(this);
542
541
543
        if (nRetVal == JFileChooser.APPROVE_OPTION) {
542
        if (nRetVal == JFileChooser.APPROVE_OPTION) {
544
            File file = fc.getSelectedFile();
543
            File file = fc.getSelectedFile();
545
544
546
            MidiFilterXML midiFilterXML = new MidiFilterXML(midiFilter,
545
            MidiFilterXML midiFilterXML = new MidiFilterXML(midiFilter,
547
                    MidiFilterXML.TAG_ROOT_ELEMENT);
546
                    MidiFilterXML.TAG_ROOT_ELEMENT);
548
547
549
            midiFilterXML.saveXML(file);
548
            midiFilterXML.saveXML(file);
550
549
551
            saveMRU(file.getPath());
550
            saveMRU(file.getPath());
552
               
551
               
553
            currentDirectory = fc.getCurrentDirectory().toString();
552
            currentDirectory = fc.getCurrentDirectory().toString();
554
        }
553
        }
555
    }
554
    }
556
555
557
    public static String getCurrentDirectory() {
556
    public static String getCurrentDirectory() {
558
        return currentDirectory;
557
        return currentDirectory;
559
    }
558
    }
560
559
561
    public static void setCurrentDirectory(String currentDirectory) {
560
    public static void setCurrentDirectory(String currentDirectory) {
562
        MidiFilterGUI.currentDirectory = currentDirectory;
561
        MidiFilterGUI.currentDirectory = currentDirectory;
563
    }
562
    }
564
563
565
    public void update(Observable observable, Object object) {
564
    public void update(Observable observable, Object object) {
566
565
567
        setButtonStates();
566
        setButtonStates();
568
    }
567
    }
569
568
570
    public void actionPerformed(ActionEvent ae) {
569
    public void actionPerformed(ActionEvent ae) {
571
570
572
        Object source = ae.getSource();
571
        Object source = ae.getSource();
573
572
574
        if (source == voiceMessages)
573
        if (source == voiceMessages)
575
            midiFilter.setVoiceMessages(voiceMessages.isSelected());
574
            midiFilter.setVoiceMessages(voiceMessages.isSelected());
576
575
577
        if (source == systemCommonMessages)
576
        if (source == systemCommonMessages)
578
            midiFilter.setSystemCommonMessages(systemCommonMessages
577
            midiFilter.setSystemCommonMessages(systemCommonMessages
579
                    .isSelected());
578
                    .isSelected());
580
579
581
        if (source == systemRealtimeMessages)
580
        if (source == systemRealtimeMessages)
582
            midiFilter.setSystemRealtimeMessages(systemRealtimeMessages
581
            midiFilter.setSystemRealtimeMessages(systemRealtimeMessages
583
                    .isSelected());
582
                    .isSelected());
584
583
585
        if (source == sysexMessages)
584
        if (source == sysexMessages)
586
            midiFilter.setSysexMessages(sysexMessages.isSelected());
585
            midiFilter.setSysexMessages(sysexMessages.isSelected());
587
586
588
        if (source == metaMessages)
587
        if (source == metaMessages)
589
            midiFilter.setMetaMessages(metaMessages.isSelected());
588
            midiFilter.setMetaMessages(metaMessages.isSelected());
590
589
591
        if (source == noteOff)
590
        if (source == noteOff)
592
            midiFilter.setVoiceMessage(ShortMessage.NOTE_OFF, noteOff
591
            midiFilter.setVoiceMessage(ShortMessage.NOTE_OFF, noteOff
593
                    .isSelected());
592
                    .isSelected());
594
593
595
        if (source == noteOn)
594
        if (source == noteOn)
596
            midiFilter.setVoiceMessage(ShortMessage.NOTE_ON, noteOn
595
            midiFilter.setVoiceMessage(ShortMessage.NOTE_ON, noteOn
597
                    .isSelected());
596
                    .isSelected());
598
597
599
        if (source == polyPressure)
598
        if (source == polyPressure)
600
            midiFilter.setVoiceMessage(ShortMessage.POLY_PRESSURE, polyPressure
599
            midiFilter.setVoiceMessage(ShortMessage.POLY_PRESSURE, polyPressure
601
                    .isSelected());
600
                    .isSelected());
602
601
603
        if (source == controlChange)
602
        if (source == controlChange)
604
            midiFilter.setVoiceMessage(ShortMessage.CONTROL_CHANGE,
603
            midiFilter.setVoiceMessage(ShortMessage.CONTROL_CHANGE,
605
                    controlChange.isSelected());
604
                    controlChange.isSelected());
606
605
607
        if (source == programChange)
606
        if (source == programChange)
608
            midiFilter.setVoiceMessage(ShortMessage.PROGRAM_CHANGE,
607
            midiFilter.setVoiceMessage(ShortMessage.PROGRAM_CHANGE,
609
                    programChange.isSelected());
608
                    programChange.isSelected());
610
609
611
        if (source == channelPressure)
610
        if (source == channelPressure)
612
            midiFilter.setVoiceMessage(ShortMessage.CHANNEL_PRESSURE,
611
            midiFilter.setVoiceMessage(ShortMessage.CHANNEL_PRESSURE,
613
                    channelPressure.isSelected());
612
                    channelPressure.isSelected());
614
613
615
        if (source == pitchBend)
614
        if (source == pitchBend)
616
            midiFilter.setVoiceMessage(ShortMessage.PITCH_BEND, pitchBend
615
            midiFilter.setVoiceMessage(ShortMessage.PITCH_BEND, pitchBend
617
                    .isSelected());
616
                    .isSelected());
618
617
619
        if (source == midiTimeCode)
618
        if (source == midiTimeCode)
620
            midiFilter.setSystemCommonMessage(ShortMessage.MIDI_TIME_CODE,
619
            midiFilter.setSystemCommonMessage(ShortMessage.MIDI_TIME_CODE,
621
                    midiTimeCode.isSelected());
620
                    midiTimeCode.isSelected());
622
621
623
        if (source == songPositionPointer)
622
        if (source == songPositionPointer)
624
            midiFilter.setSystemCommonMessage(
623
            midiFilter.setSystemCommonMessage(
625
                    ShortMessage.SONG_POSITION_POINTER, songPositionPointer
624
                    ShortMessage.SONG_POSITION_POINTER, songPositionPointer
626
                            .isSelected());
625
                            .isSelected());
627
626
628
        if (source == songSelect)
627
        if (source == songSelect)
629
            midiFilter.setSystemCommonMessage(ShortMessage.SONG_SELECT,
628
            midiFilter.setSystemCommonMessage(ShortMessage.SONG_SELECT,
630
                    songSelect.isSelected());
629
                    songSelect.isSelected());
631
630
632
        if (source == tuneRequest)
631
        if (source == tuneRequest)
633
            midiFilter.setSystemCommonMessage(ShortMessage.TUNE_REQUEST,
632
            midiFilter.setSystemCommonMessage(ShortMessage.TUNE_REQUEST,
634
                    tuneRequest.isSelected());
633
                    tuneRequest.isSelected());
635
634
636
        if (source == timingClock)
635
        if (source == timingClock)
637
            midiFilter.setSystemRealtimeMessage(ShortMessage.TIMING_CLOCK,
636
            midiFilter.setSystemRealtimeMessage(ShortMessage.TIMING_CLOCK,
638
                    timingClock.isSelected());
637
                    timingClock.isSelected());
639
638
640
        if (source == start)
639
        if (source == start)
641
            midiFilter.setSystemRealtimeMessage(ShortMessage.START, start
640
            midiFilter.setSystemRealtimeMessage(ShortMessage.START, start
642
                    .isSelected());
641
                    .isSelected());
643
642
644
        if (source == continueMessage)
643
        if (source == continueMessage)
645
            midiFilter.setSystemRealtimeMessage(ShortMessage.CONTINUE,
644
            midiFilter.setSystemRealtimeMessage(ShortMessage.CONTINUE,
646
                    continueMessage.isSelected());
645
                    continueMessage.isSelected());
647
646
648
        if (source == stop)
647
        if (source == stop)
649
            midiFilter.setSystemRealtimeMessage(ShortMessage.STOP, stop
648
            midiFilter.setSystemRealtimeMessage(ShortMessage.STOP, stop
650
                    .isSelected());
649
                    .isSelected());
651
650
652
        if (source == activeSensing)
651
        if (source == activeSensing)
653
            midiFilter.setSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING,
652
            midiFilter.setSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING,
654
                    activeSensing.isSelected());
653
                    activeSensing.isSelected());
655
654
656
        if (source == systemReset)
655
        if (source == systemReset)
657
            midiFilter.setSystemRealtimeMessage(ShortMessage.SYSTEM_RESET,
656
            midiFilter.setSystemRealtimeMessage(ShortMessage.SYSTEM_RESET,
658
                    systemReset.isSelected());
657
                    systemReset.isSelected());
659
658
660
        if (ae.getActionCommand() == "load")
659
        if (ae.getActionCommand() == "load")
661
            loadFilterDefinition();
660
            loadFilterDefinition();
662
661
663
        if (ae.getActionCommand() == "save")
662
        if (ae.getActionCommand() == "save")
664
            saveFilterDefinition();
663
            saveFilterDefinition();
665
    }
664
    }
666
665
667
    protected void setButtonStates() {
666
    protected void setButtonStates() {
668
667
669
        voiceMessages.setSelected(midiFilter.isVoiceMessages());
668
        voiceMessages.setSelected(midiFilter.isVoiceMessages());
670
669
671
        systemCommonMessages.setSelected(midiFilter.isSystemCommonMessages());
670
        systemCommonMessages.setSelected(midiFilter.isSystemCommonMessages());
672
671
673
        systemRealtimeMessages.setSelected(midiFilter
672
        systemRealtimeMessages.setSelected(midiFilter
674
                .isSystemRealtimeMessages());
673
                .isSystemRealtimeMessages());
675
674
676
        sysexMessages.setSelected(midiFilter.isSysexMessages());
675
        sysexMessages.setSelected(midiFilter.isSysexMessages());
677
676
678
        metaMessages.setSelected(midiFilter.isMetaMessages());
677
        metaMessages.setSelected(midiFilter.isMetaMessages());
679
678
680
        noteOff.setSelected(midiFilter.getVoiceMessage(ShortMessage.NOTE_OFF));
679
        noteOff.setSelected(midiFilter.getVoiceMessage(ShortMessage.NOTE_OFF));
681
        noteOff.setEnabled(midiFilter.isVoiceMessages());
680
        noteOff.setEnabled(midiFilter.isVoiceMessages());
682
681
683
        noteOn.setSelected(midiFilter.getVoiceMessage(ShortMessage.NOTE_ON));
682
        noteOn.setSelected(midiFilter.getVoiceMessage(ShortMessage.NOTE_ON));
684
        noteOn.setEnabled(midiFilter.isVoiceMessages());
683
        noteOn.setEnabled(midiFilter.isVoiceMessages());
685
684
686
        polyPressure.setSelected(midiFilter
685
        polyPressure.setSelected(midiFilter
687
                .getVoiceMessage(ShortMessage.POLY_PRESSURE));
686
                .getVoiceMessage(ShortMessage.POLY_PRESSURE));
688
        polyPressure.setEnabled(midiFilter.isVoiceMessages());
687
        polyPressure.setEnabled(midiFilter.isVoiceMessages());
689
688
690
        controlChange.setSelected(midiFilter
689
        controlChange.setSelected(midiFilter
691
                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
690
                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
692
        controlChange.setEnabled(midiFilter.isVoiceMessages());
691
        controlChange.setEnabled(midiFilter.isVoiceMessages());
693
692
694
        programChange.setSelected(midiFilter
693
        programChange.setSelected(midiFilter
695
                .getVoiceMessage(ShortMessage.PROGRAM_CHANGE));
694
                .getVoiceMessage(ShortMessage.PROGRAM_CHANGE));
696
        programChange.setEnabled(midiFilter.isVoiceMessages());
695
        programChange.setEnabled(midiFilter.isVoiceMessages());
697
696
698
        channelPressure.setSelected(midiFilter
697
        channelPressure.setSelected(midiFilter
699
                .getVoiceMessage(ShortMessage.CHANNEL_PRESSURE));
698
                .getVoiceMessage(ShortMessage.CHANNEL_PRESSURE));
700
        channelPressure.setEnabled(midiFilter.isVoiceMessages());
699
        channelPressure.setEnabled(midiFilter.isVoiceMessages());
701
700
702
        pitchBend.setSelected(midiFilter
701
        pitchBend.setSelected(midiFilter
703
                .getVoiceMessage(ShortMessage.PITCH_BEND));
702
                .getVoiceMessage(ShortMessage.PITCH_BEND));
704
        pitchBend.setEnabled(midiFilter.isVoiceMessages());
703
        pitchBend.setEnabled(midiFilter.isVoiceMessages());
705
704
706
        controlChangeModel.fireTableDataChanged();
705
        controlChangeModel.fireTableDataChanged();
707
706
708
        channelsModel.fireTableDataChanged();
707
        channelsModel.fireTableDataChanged();
709
708
710
        midiTimeCode.setSelected(midiFilter
709
        midiTimeCode.setSelected(midiFilter
711
                .getSystemCommonMessage(ShortMessage.MIDI_TIME_CODE));
710
                .getSystemCommonMessage(ShortMessage.MIDI_TIME_CODE));
712
        midiTimeCode.setEnabled(midiFilter.isSystemCommonMessages());
711
        midiTimeCode.setEnabled(midiFilter.isSystemCommonMessages());
713
712
714
        songPositionPointer.setSelected(midiFilter
713
        songPositionPointer.setSelected(midiFilter
715
                .getSystemCommonMessage(ShortMessage.SONG_POSITION_POINTER));
714
                .getSystemCommonMessage(ShortMessage.SONG_POSITION_POINTER));
716
        songPositionPointer.setEnabled(midiFilter.isSystemCommonMessages());
715
        songPositionPointer.setEnabled(midiFilter.isSystemCommonMessages());
717
716
718
        songSelect.setSelected(midiFilter
717
        songSelect.setSelected(midiFilter
719
                .getSystemCommonMessage(ShortMessage.SONG_SELECT));
718
                .getSystemCommonMessage(ShortMessage.SONG_SELECT));
720
        songSelect.setEnabled(midiFilter.isSystemCommonMessages());
719
        songSelect.setEnabled(midiFilter.isSystemCommonMessages());
721
720
722
        tuneRequest.setSelected(midiFilter
721
        tuneRequest.setSelected(midiFilter
723
                .getSystemCommonMessage(ShortMessage.TUNE_REQUEST));
722
                .getSystemCommonMessage(ShortMessage.TUNE_REQUEST));
724
        tuneRequest.setEnabled(midiFilter.isSystemCommonMessages());
723
        tuneRequest.setEnabled(midiFilter.isSystemCommonMessages());
725
724
726
        timingClock.setSelected(midiFilter
725
        timingClock.setSelected(midiFilter
727
                .getSystemRealtimeMessage(ShortMessage.TIMING_CLOCK));
726
                .getSystemRealtimeMessage(ShortMessage.TIMING_CLOCK));
728
        timingClock.setEnabled(midiFilter.isSystemRealtimeMessages());
727
        timingClock.setEnabled(midiFilter.isSystemRealtimeMessages());
729
728
730
        start.setSelected(midiFilter
729
        start.setSelected(midiFilter
731
                .getSystemRealtimeMessage(ShortMessage.START));
730
                .getSystemRealtimeMessage(ShortMessage.START));
732
        start.setEnabled(midiFilter.isSystemRealtimeMessages());
731
        start.setEnabled(midiFilter.isSystemRealtimeMessages());
733
732
734
        continueMessage.setSelected(midiFilter
733
        continueMessage.setSelected(midiFilter
735
                .getSystemRealtimeMessage(ShortMessage.CONTINUE));
734
                .getSystemRealtimeMessage(ShortMessage.CONTINUE));
736
        continueMessage.setEnabled(midiFilter.isSystemRealtimeMessages());
735
        continueMessage.setEnabled(midiFilter.isSystemRealtimeMessages());
737
736
738
        stop
737
        stop
739
                .setSelected(midiFilter
738
                .setSelected(midiFilter
740
                        .getSystemRealtimeMessage(ShortMessage.STOP));
739
                        .getSystemRealtimeMessage(ShortMessage.STOP));
741
        stop.setEnabled(midiFilter.isSystemRealtimeMessages());
740
        stop.setEnabled(midiFilter.isSystemRealtimeMessages());
742
741
743
        activeSensing.setSelected(midiFilter
742
        activeSensing.setSelected(midiFilter
744
                .getSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING));
743
                .getSystemRealtimeMessage(ShortMessage.ACTIVE_SENSING));
745
        activeSensing.setEnabled(midiFilter.isSystemRealtimeMessages());
744
        activeSensing.setEnabled(midiFilter.isSystemRealtimeMessages());
746
745
747
        systemReset.setSelected(midiFilter
746
        systemReset.setSelected(midiFilter
748
                .getSystemRealtimeMessage(ShortMessage.SYSTEM_RESET));
747
                .getSystemRealtimeMessage(ShortMessage.SYSTEM_RESET));
749
        systemReset.setEnabled(midiFilter.isSystemRealtimeMessages());
748
        systemReset.setEnabled(midiFilter.isSystemRealtimeMessages());
750
    }
749
    }
751
750
752
    class MidiFilterTableCellEditor extends AbstractCellEditor implements
751
    class MidiFilterTableCellEditor extends AbstractCellEditor implements
753
            TableCellEditor {
752
            TableCellEditor {
754
753
755
        private JCheckBox checkBox;
754
        private JCheckBox checkBox;
756
755
757
        public Component getTableCellEditorComponent(JTable table,
756
        public Component getTableCellEditorComponent(JTable table,
758
                Object value, boolean isSelected, int row, int column) {
757
                Object value, boolean isSelected, int row, int column) {
759
758
760
            if (table.getRowCount() == 128) {
759
            if (table.getRowCount() == 128) {
761
760
762
                checkBox = new JCheckBox(row + ": " + MidiUtils.ccNames[row],
761
                checkBox = new JCheckBox(row + ": " + MidiUtils.ccNames[row],
763
                        midiFilter.getControlChange(row));
762
                        midiFilter.getControlChange(row));
764
763
765
                checkBox.setEnabled(midiFilter.isVoiceMessages()
764
                checkBox.setEnabled(midiFilter.isVoiceMessages()
766
                        && midiFilter
765
                        && midiFilter
767
                                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
766
                                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
768
767
769
            } else {
768
            } else {
770
769
771
                checkBox = new JCheckBox("Channel " + (row + 1), midiFilter
770
                checkBox = new JCheckBox("Channel " + (row + 1), midiFilter
772
                        .getChannel(row));
771
                        .getChannel(row));
773
            }
772
            }
774
773
775
            checkBox.setOpaque(false);
774
            checkBox.setOpaque(false);
776
775
777
            checkBox.addActionListener(new ActionListener() {
776
            checkBox.addActionListener(new ActionListener() {
778
                public void actionPerformed(ActionEvent ae) {
777
                public void actionPerformed(ActionEvent ae) {
779
                    fireEditingStopped();
778
                    fireEditingStopped();
780
                }
779
                }
781
            });
780
            });
782
781
783
            return checkBox;
782
            return checkBox;
784
        }
783
        }
785
784
786
        public Object getCellEditorValue() {
785
        public Object getCellEditorValue() {
787
786
788
            return new Boolean(checkBox.isSelected());
787
            return new Boolean(checkBox.isSelected());
789
        }
788
        }
790
    }
789
    }
791
790
792
    class MidiFilterTableCellRenderer extends DefaultTableCellRenderer {
791
    class MidiFilterTableCellRenderer extends DefaultTableCellRenderer {
793
792
794
        public Component getTableCellRendererComponent(JTable table,
793
        public Component getTableCellRendererComponent(JTable table,
795
                Object value, boolean isSelected, boolean hasFocus, int row,
794
                Object value, boolean isSelected, boolean hasFocus, int row,
796
                int column) {
795
                int column) {
797
796
798
            JCheckBox checkBox;
797
            JCheckBox checkBox;
799
798
800
            if (table.getRowCount() == 128) {
799
            if (table.getRowCount() == 128) {
801
800
802
                checkBox = new JCheckBox(row + ": " + MidiUtils.ccNames[row],
801
                checkBox = new JCheckBox(row + ": " + MidiUtils.ccNames[row],
803
                        midiFilter.getControlChange(row));
802
                        midiFilter.getControlChange(row));
804
803
805
                checkBox.setEnabled(midiFilter.isVoiceMessages()
804
                checkBox.setEnabled(midiFilter.isVoiceMessages()
806
                        && midiFilter
805
                        && midiFilter
807
                                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
806
                                .getVoiceMessage(ShortMessage.CONTROL_CHANGE));
808
807
809
            } else {
808
            } else {
810
809
811
                checkBox = new JCheckBox("Channel " + (row + 1), midiFilter
810
                checkBox = new JCheckBox("Channel " + (row + 1), midiFilter
812
                        .getChannel(row));
811
                        .getChannel(row));
813
812
814
                checkBox.setEnabled(midiFilter.isVoiceMessages());
813
                checkBox.setEnabled(midiFilter.isVoiceMessages());
815
            }
814
            }
816
815
817
            checkBox.setOpaque(false);
816
            checkBox.setOpaque(false);
818
817
819
            return checkBox;
818
            return checkBox;
820
        }
819
        }
821
    }
820
    }
822
821
823
    class MidiFilterTableModel extends DefaultTableModel {
822
    class MidiFilterTableModel extends DefaultTableModel {
824
823
825
        public MidiFilterTableModel(Object[] a, int b) {
824
        public MidiFilterTableModel(Object[] a, int b) {
826
            super(a, b);
825
            super(a, b);
827
        }
826
        }
828
827
829
        public Class getColumnClass(int c) {
828
        public Class getColumnClass(int c) {
830
            return getValueAt(0, c).getClass();
829
            return getValueAt(0, c).getClass();
831
        }
830
        }
832
831
833
        public Object getValueAt(int row, int column) {
832
        public Object getValueAt(int row, int column) {
834
833
835
            if (column == 0) {
834
            if (column == 0) {
836
835
837
                if (getRowCount() == 128) {
836
                if (getRowCount() == 128) {
838
837
839
                    return new Boolean(midiFilter.getControlChange(row));
838
                    return new Boolean(midiFilter.getControlChange(row));
840
                } else {
839
                } else {
841
840
842
                    return new Boolean(midiFilter.getChannel(row));
841
                    return new Boolean(midiFilter.getChannel(row));
843
                }
842
                }
844
            }
843
            }
845
844
846
            return super.getValueAt(row, column);
845
            return super.getValueAt(row, column);
847
        }
846
        }
848
847
849
        public void setValueAt(Object value, int row, int column) {
848
        public void setValueAt(Object value, int row, int column) {
850
849
851
            if (column == 0) {
850
            if (column == 0) {
852
851
853
                if (getRowCount() == 128) {
852
                if (getRowCount() == 128) {
854
853
855
                    midiFilter.setControlChange(row, ((Boolean) value)
854
                    midiFilter.setControlChange(row, ((Boolean) value)
856
                            .booleanValue());
855
                            .booleanValue());
857
                } else {
856
                } else {
858
857
859
                    midiFilter
858
                    midiFilter
860
                            .setChannel(row, ((Boolean) value).booleanValue());
859
                            .setChannel(row, ((Boolean) value).booleanValue());
861
                }
860
                }
862
            } else {
861
            } else {
863
862
864
                super.setValueAt(value, row, column);
863
                super.setValueAt(value, row, column);
865
            }
864
            }
866
        }
865
        }
867
866
868
        public boolean isCellEditable(int row, int col) {
867
        public boolean isCellEditable(int row, int col) {
869
868
870
            if (col == 0) {
869
            if (col == 0) {
871
                return true;
870
                return true;
872
            }
871
            }
873
            return false;
872
            return false;
874
        }
873
        }
875
    }
874
    }
876
}
875
}
877
 
876