Subversion Repositories svn.mios

Rev

Rev 738 | Rev 753 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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