[Japi-cvs] SF.net SVN: japi:[1342] libs/midi/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2009-06-14 09:26:57
|
Revision: 1342 http://japi.svn.sourceforge.net/japi/?rev=1342&view=rev Author: christianhujer Date: 2009-06-14 09:26:56 +0000 (Sun, 14 Jun 2009) Log Message: ----------- Add a MidiDeviceListModel. Added Paths: ----------- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListModel.java libs/midi/trunk/src/tst/test/ libs/midi/trunk/src/tst/test/net/ libs/midi/trunk/src/tst/test/net/sf/ libs/midi/trunk/src/tst/test/net/sf/japi/ libs/midi/trunk/src/tst/test/net/sf/japi/midi/ libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/ libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/MidiDeviceListModelTry.java Added: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListModel.java =================================================================== --- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListModel.java (rev 0) +++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListModel.java 2009-06-14 09:26:56 UTC (rev 1342) @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009 Christian Hujer. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.sf.japi.midi.gui; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.Arrays; +import java.util.List; +import javax.sound.midi.MidiDevice; +import javax.sound.midi.MidiSystem; +import javax.swing.AbstractListModel; + +/** ListModel which shows midi devices. + * TODO:2009-06-11:christianhujer:Documentation. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.2 + */ +public class MidiDeviceListModel extends AbstractListModel { + + /** Serial Version. */ + private static final long serialVersionUID = 1L; + + /** The List with the data. */ + // IntelliJ IDEA does not detect that the invocation of update() sets deviceInfos. + @SuppressWarnings({"InstanceVariableMayNotBeInitializedByReadObject", "InstanceVariableMayNotBeInitialized"}) + private transient List<MidiDevice.Info> deviceInfos; + + /** Creates a MidiDeviceListModel. */ + public MidiDeviceListModel() { + update(); + } + + @SuppressWarnings({"JavaDoc"}) + private void readObject(final ObjectInputStream in) throws ClassNotFoundException, IOException { + in.defaultReadObject(); + update(); + } + + /** {@inheritDoc} */ + public int getSize() { + return deviceInfos.size(); + } + + /** {@inheritDoc} */ + public MidiDevice.Info getElementAt(final int index) { + return deviceInfos.get(index); + } + + /** Updates the listmodel. + * This rescans the MidiSystem for devices. + */ + public void update() { + deviceInfos = Arrays.asList(MidiSystem.getMidiDeviceInfo()); + } +} Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/MidiDeviceListModelTry.java =================================================================== --- libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/MidiDeviceListModelTry.java (rev 0) +++ libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/MidiDeviceListModelTry.java 2009-06-14 09:26:56 UTC (rev 1342) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2009 Christian Hujer. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package test.net.sf.japi.midi.gui; + +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JScrollPane; +import net.sf.japi.midi.gui.MidiDeviceListModel; + +/** + * TODO:2009-06-11:christianhujer:Documentation. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.2 + */ +public class MidiDeviceListModelTry { + + /** Tries the MidiDeviceListModel. + * @param args Command line arguments (ignored). + */ + public static void main(final String... args) { + final JFrame f = new JFrame("foo"); + final JList list = new JList(new MidiDeviceListModel()); + f.add(new JScrollPane(list)); + f.pack(); + f.setVisible(true); + } +} Property changes on: libs/midi/trunk/src/tst/test/net/sf/japi/midi/gui/MidiDeviceListModelTry.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |