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 implements ActionListener
23 private MidiDeviceTreeView deviceTree;
24 private JEditorPane deviceInfoPane;
25 private MidiOpenedDevicesView desktopPane;
27 public void actionPerformed(ActionEvent event) { setVisible(true); }
29 public MidiDeviceDialog(List<MidiConnecterListModel> deviceModelList) {
30 setTitle("MIDI device connection");
31 setBounds( 300, 300, 800, 500 );
32 deviceTree = new MidiDeviceTreeView(new MidiDeviceTreeModel(deviceModelList)) {{
33 addTreeSelectionListener(new TreeSelectionListener() {
35 public void valueChanged(TreeSelectionEvent e) {
36 Object lastSelected = deviceTree.getLastSelectedPathComponent();
37 String html = "<html><head></head><body>";
38 if( lastSelected instanceof MidiConnecterListModel ) {
39 MidiConnecterListModel deviceModel = (MidiConnecterListModel)lastSelected;
40 MidiDevice.Info info = deviceModel.getMidiDevice().getDeviceInfo();
41 html += "<b>"+deviceModel+"</b><br/>"
42 + "<table border=\"1\"><tbody>"
43 + "<tr><th>Version</th><td>"+info.getVersion()+"</td></tr>"
44 + "<tr><th>Description</th><td>"+info.getDescription()+"</td></tr>"
45 + "<tr><th>Vendor</th><td>"+info.getVendor()+"</td></tr>"
47 MidiDeviceFrame deviceFrame = desktopPane.getMidiDeviceFrameOf(deviceModel);
48 if( deviceFrame != null ) {
50 deviceFrame.setSelected(true);
51 } catch( PropertyVetoException ex ) {
56 else if( lastSelected instanceof MidiDeviceInOutType ) {
57 MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
58 html += "<b>"+ioType+"</b><br/>";
59 html += ioType.getDescription()+"<br/>";
61 else if( lastSelected != null ) {
62 html += lastSelected.toString();
64 html += "</body></html>";
65 deviceInfoPane.setText(html);
69 deviceInfoPane = new JEditorPane("text/html","<html></html>") {{ setEditable(false); }};
70 desktopPane = new MidiOpenedDevicesView(deviceTree);
72 JSplitPane.HORIZONTAL_SPLIT,
74 JSplitPane.VERTICAL_SPLIT,
75 new JScrollPane(deviceTree),
76 new JScrollPane(deviceInfoPane)
78 setDividerLocation(260);
82 setOneTouchExpandable(true);
83 setDividerLocation(250);
85 addWindowListener(new WindowAdapter() {
86 private void setTimer(boolean flag) { desktopPane.setAllDeviceTimestampTimers(flag); }
88 public void windowClosing(WindowEvent e) { setTimer(false); }
90 public void windowActivated(WindowEvent e) { setTimer(true); }