OSDN Git Service

ローカルリポジトリ作成→初コミット
[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 import java.beans.PropertyVetoException;
8 import java.util.List;
9
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;
17
18 /**
19  * MIDIデバイスダイアログ (View)
20  */
21 public class MidiDeviceDialog extends JDialog
22         implements ActionListener, TreeSelectionListener
23 {
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>") {
33                         {
34                                 setEditable(false);
35                         }
36                 };
37                 desktopPane = new MidiDesktopPane(deviceTree);
38                 add(new JSplitPane(
39                         JSplitPane.HORIZONTAL_SPLIT,
40                         new JSplitPane(
41                                 JSplitPane.VERTICAL_SPLIT,
42                                 new JScrollPane(deviceTree),
43                                 new JScrollPane(deviceInfoPane)
44                         ){{
45                                 setDividerLocation(260);
46                         }},
47                         desktopPane
48                 ){{
49                         setOneTouchExpandable(true);
50                         setDividerLocation(250);
51                 }});
52                 addWindowListener(new WindowAdapter() {
53                         @Override
54                         public void windowClosing(WindowEvent e) {
55                                 desktopPane.setAllDeviceTimestampTimers(false);
56                         }
57                         @Override
58                         public void windowActivated(WindowEvent e) {
59                                 desktopPane.setAllDeviceTimestampTimers(true);
60                         }
61                 });
62         }
63         @Override
64         public void actionPerformed(ActionEvent event) {
65                 setVisible(true);
66         }
67         @Override
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>"
79                                 + "</tbody></table>";
80                         MidiDeviceFrame frame = desktopPane.getFrameOf(deviceModel);
81                         if( frame != null ) {
82                                 try {
83                                         frame.setSelected(true);
84                                 } catch( PropertyVetoException ex ) {
85                                         ex.printStackTrace();
86                                 }
87                         }
88                 }
89                 else if( lastSelected instanceof MidiDeviceInOutType ) {
90                         MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
91                         html += "<b>"+ioType+"</b><br/>";
92                         html += ioType.getDescription()+"<br/>";
93                 }
94                 else if( lastSelected != null ) {
95                         html += lastSelected.toString();
96                 }
97                 html += "</body></html>";
98                 deviceInfoPane.setText(html);
99         }
100 }