1 package camidion.chordhelper.mididevice;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.awt.event.WindowAdapter;
6 import java.awt.event.WindowEvent;
7 import java.beans.PropertyVetoException;
10 import javax.sound.midi.MidiDevice;
11 import javax.swing.JDialog;
12 import javax.swing.JEditorPane;
13 import javax.swing.JScrollPane;
14 import javax.swing.JSplitPane;
15 import javax.swing.event.TreeSelectionEvent;
16 import javax.swing.event.TreeSelectionListener;
19 * MIDIデバイスダイアログ (View)
21 public class MidiDeviceDialog extends JDialog
22 implements ActionListener, TreeSelectionListener
24 private JEditorPane deviceInfoPane;
25 private MidiDesktopPane desktopPane;
26 private MidiDeviceTree deviceTree;
27 public MidiDeviceDialog(List<MidiConnecterListModel> deviceModelList) {
28 setTitle("MIDI device connection");
29 setBounds( 300, 300, 800, 500 );
30 deviceTree = new MidiDeviceTree(new MidiDeviceTreeModel(deviceModelList));
31 deviceTree.addTreeSelectionListener(this);
32 deviceInfoPane = new JEditorPane("text/html","<html></html>") {
37 desktopPane = new MidiDesktopPane(deviceTree);
39 JSplitPane.HORIZONTAL_SPLIT,
41 JSplitPane.VERTICAL_SPLIT,
42 new JScrollPane(deviceTree),
43 new JScrollPane(deviceInfoPane)
45 setDividerLocation(260);
49 setOneTouchExpandable(true);
50 setDividerLocation(250);
52 addWindowListener(new WindowAdapter() {
54 public void windowClosing(WindowEvent e) {
55 desktopPane.setAllDeviceTimestampTimers(false);
58 public void windowActivated(WindowEvent e) {
59 desktopPane.setAllDeviceTimestampTimers(true);
64 public void actionPerformed(ActionEvent event) {
68 public void valueChanged(TreeSelectionEvent e) {
69 Object lastSelected = deviceTree.getLastSelectedPathComponent();
70 String html = "<html><head></head><body>";
71 if( lastSelected instanceof MidiConnecterListModel ) {
72 MidiConnecterListModel deviceModel = (MidiConnecterListModel)lastSelected;
73 MidiDevice.Info info = deviceModel.getMidiDevice().getDeviceInfo();
74 html += "<b>"+deviceModel+"</b><br/>"
75 + "<table border=\"1\"><tbody>"
76 + "<tr><th>Version</th><td>"+info.getVersion()+"</td></tr>"
77 + "<tr><th>Description</th><td>"+info.getDescription()+"</td></tr>"
78 + "<tr><th>Vendor</th><td>"+info.getVendor()+"</td></tr>"
80 MidiDeviceFrame frame = desktopPane.getFrameOf(deviceModel);
83 frame.setSelected(true);
84 } catch( PropertyVetoException ex ) {
89 else if( lastSelected instanceof MidiDeviceInOutType ) {
90 MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
91 html += "<b>"+ioType+"</b><br/>";
92 html += ioType.getDescription()+"<br/>";
94 else if( lastSelected != null ) {
95 html += lastSelected.toString();
97 html += "</body></html>";
98 deviceInfoPane.setText(html);