OSDN Git Service

MIDIデバイス画面の改良
[midichordhelper/MIDIChordHelper.git] / src / camidion / chordhelper / mididevice / MidiDeviceDialog.java
1 package camidion.chordhelper.mididevice;
2
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
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;
15
16 /**
17  * MIDIデバイスダイアログ (View)
18  */
19 public class MidiDeviceDialog extends JDialog implements ActionListener {
20         private JEditorPane deviceInfoPane;
21         private MidiOpenedDevicesView desktopPane;
22         @Override
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() {
29                                 @Override
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>"
41                                                         + "</tbody></table>";
42                                         }
43                                         else if( lastSelected instanceof MidiDeviceInOutType ) {
44                                                 MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
45                                                 html += "<b>"+ioType+"</b><br/>";
46                                                 html += ioType.getDescription()+"<br/>";
47                                         }
48                                         else if( lastSelected != null ) {
49                                                 html += lastSelected.toString();
50                                         }
51                                         html += "</body></html>";
52                                         deviceInfoPane.setText(html);
53                                 }
54                         });
55                 }};
56                 deviceInfoPane = new JEditorPane("text/html","<html></html>") {{ setEditable(false); }};
57                 desktopPane = new MidiOpenedDevicesView(deviceTree);
58                 add(new JSplitPane(
59                         JSplitPane.HORIZONTAL_SPLIT,
60                         new JSplitPane(
61                                 JSplitPane.VERTICAL_SPLIT,
62                                 new JScrollPane(deviceTree),
63                                 new JScrollPane(deviceInfoPane)
64                         ){{
65                                 setDividerLocation(260);
66                         }},
67                         desktopPane
68                 ){{
69                         setOneTouchExpandable(true);
70                         setDividerLocation(250);
71                 }});
72                 addWindowListener(new WindowAdapter() {
73                         private void setTimer(boolean flag) { desktopPane.setAllDeviceTimestampTimers(flag); }
74                         @Override
75                         public void windowClosing(WindowEvent e) { setTimer(false); }
76                         @Override
77                         public void windowActivated(WindowEvent e) { setTimer(true); }
78                 });
79         }
80 }