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;
8 import javax.sound.midi.MidiDevice;
9 import javax.swing.JDialog;
10 import javax.swing.JEditorPane;
11 import javax.swing.JScrollPane;
12 import javax.swing.JSplitPane;
13 import javax.swing.event.TreeSelectionEvent;
14 import javax.swing.event.TreeSelectionListener;
17 * MIDIデバイスダイアログ (View)
19 public class MidiDeviceDialog extends JDialog implements ActionListener {
20 private JEditorPane deviceInfoPane;
21 private MidiOpenedDevicesView desktopPane;
23 public void actionPerformed(ActionEvent event) { setVisible(true); }
24 public MidiDeviceDialog(MidiDeviceModelList deviceModelList) {
25 setTitle("MIDI device connection");
26 setBounds( 300, 300, 800, 500 );
27 MidiDeviceTreeView deviceTree = new MidiDeviceTreeView(new MidiDeviceTreeModel(deviceModelList)) {{
28 addTreeSelectionListener(new TreeSelectionListener() {
30 public void valueChanged(TreeSelectionEvent e) {
31 String html = "<html><head></head><body>";
32 Object lastSelected = e.getNewLeadSelectionPath().getLastPathComponent();
33 if( lastSelected instanceof MidiConnecterListModel ) {
34 MidiConnecterListModel deviceModel = (MidiConnecterListModel)lastSelected;
35 MidiDevice.Info info = deviceModel.getMidiDevice().getDeviceInfo();
36 html += "<b>"+deviceModel+"</b><br/>"
37 + "<table border=\"1\"><tbody>"
38 + "<tr><th>Version</th><td>"+info.getVersion()+"</td></tr>"
39 + "<tr><th>Description</th><td>"+info.getDescription()+"</td></tr>"
40 + "<tr><th>Vendor</th><td>"+info.getVendor()+"</td></tr>"
43 else if( lastSelected instanceof MidiDeviceInOutType ) {
44 MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
45 html += "<b>"+ioType+"</b><br/>";
46 html += ioType.getDescription()+"<br/>";
48 else if( lastSelected != null ) {
49 html += lastSelected.toString();
51 html += "</body></html>";
52 deviceInfoPane.setText(html);
56 deviceInfoPane = new JEditorPane("text/html","<html></html>") {{ setEditable(false); }};
57 desktopPane = new MidiOpenedDevicesView(deviceTree);
59 JSplitPane.HORIZONTAL_SPLIT,
61 JSplitPane.VERTICAL_SPLIT,
62 new JScrollPane(deviceTree),
63 new JScrollPane(deviceInfoPane)
65 setDividerLocation(260);
69 setOneTouchExpandable(true);
70 setDividerLocation(250);
72 addWindowListener(new WindowAdapter() {
73 private void setTimer(boolean flag) { desktopPane.setAllDeviceTimestampTimers(flag); }
75 public void windowClosing(WindowEvent e) { setTimer(false); }
77 public void windowActivated(WindowEvent e) { setTimer(true); }