import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.beans.PropertyVetoException;
-import java.util.List;
-import javax.sound.midi.MidiDevice;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
import javax.swing.JDialog;
-import javax.swing.JEditorPane;
+import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
+
+import camidion.chordhelper.ButtonIcon;
/**
* MIDIデバイスダイアログ (View)
*/
-public class MidiDeviceDialog extends JDialog
- implements ActionListener, TreeSelectionListener
-{
- private JEditorPane deviceInfoPane;
- private MidiDesktopPane desktopPane;
- private MidiDeviceTree deviceTree;
- public MidiDeviceDialog(List<MidiConnecterListModel> deviceModelList) {
- setTitle("MIDI device connection");
+public class MidiDeviceDialog extends JDialog {
+ /**
+ * MIDIデバイスダイアログを開くアクション
+ */
+ public Action openAction = new AbstractAction() {
+ {
+ putValue(NAME, "MIDI device connection");
+ putValue(SHORT_DESCRIPTION, "MIDIデバイス間の接続を編集");
+ putValue(LARGE_ICON_KEY, new ButtonIcon(ButtonIcon.MIDI_CONNECTOR_ICON));
+ }
+ @Override
+ public void actionPerformed(ActionEvent event) { setVisible(true); }
+ };
+ /**
+ * MIDIデバイスダイアログを構築します。
+ * @param deviceModelList デバイスモデル(MIDIコネクタリストモデル)のリスト
+ */
+ public MidiDeviceDialog(final MidiTransceiverListModelList deviceModelList) {
+ setTitle(openAction.getValue(Action.NAME).toString());
setBounds( 300, 300, 800, 500 );
- deviceTree = new MidiDeviceTree(new MidiDeviceTreeModel(deviceModelList));
- deviceTree.addTreeSelectionListener(this);
- deviceInfoPane = new JEditorPane("text/html","<html></html>") {
- {
- setEditable(false);
- }
- };
- desktopPane = new MidiDesktopPane(deviceTree);
+ MidiDeviceTreeModel deviceTreeModel = new MidiDeviceTreeModel(deviceModelList);
+ MidiDeviceTreeView deviceTreeView = new MidiDeviceTreeView(deviceTreeModel);
+ final MidiDeviceInfoPane deviceInfoPane = new MidiDeviceInfoPane();
+ MidiOpenedDevicesView desktopPane = new MidiOpenedDevicesView(deviceTreeView, deviceInfoPane, this);
+ deviceTreeView.addTreeSelectionListener(deviceInfoPane);
+ deviceTreeView.addTreeSelectionListener(desktopPane);
+ deviceTreeView.setSelectionRow(0);
add(new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JSplitPane(
JSplitPane.VERTICAL_SPLIT,
- new JScrollPane(deviceTree),
- new JScrollPane(deviceInfoPane)
+ new JScrollPane(deviceTreeView),
+ new JPanel() {{
+ add(new JScrollPane(deviceInfoPane));
+ add(new JButton("Reset time on MIDI devices") {{
+ addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ deviceModelList.resetMicrosecondPosition();
+ }
+ });
+ }});
+ setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
+ }}
){{
setDividerLocation(260);
}},
setOneTouchExpandable(true);
setDividerLocation(250);
}});
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- desktopPane.setAllDeviceTimestampTimers(false);
- }
- @Override
- public void windowActivated(WindowEvent e) {
- desktopPane.setAllDeviceTimestampTimers(true);
- }
- });
- }
- @Override
- public void actionPerformed(ActionEvent event) {
- setVisible(true);
- }
- @Override
- public void valueChanged(TreeSelectionEvent e) {
- Object lastSelected = deviceTree.getLastSelectedPathComponent();
- String html = "<html><head></head><body>";
- if( lastSelected instanceof MidiConnecterListModel ) {
- MidiConnecterListModel deviceModel = (MidiConnecterListModel)lastSelected;
- MidiDevice.Info info = deviceModel.getMidiDevice().getDeviceInfo();
- html += "<b>"+deviceModel+"</b><br/>"
- + "<table border=\"1\"><tbody>"
- + "<tr><th>Version</th><td>"+info.getVersion()+"</td></tr>"
- + "<tr><th>Description</th><td>"+info.getDescription()+"</td></tr>"
- + "<tr><th>Vendor</th><td>"+info.getVendor()+"</td></tr>"
- + "</tbody></table>";
- MidiDeviceFrame frame = desktopPane.getFrameOf(deviceModel);
- if( frame != null ) {
- try {
- frame.setSelected(true);
- } catch( PropertyVetoException ex ) {
- ex.printStackTrace();
- }
- }
- }
- else if( lastSelected instanceof MidiDeviceInOutType ) {
- MidiDeviceInOutType ioType = (MidiDeviceInOutType)lastSelected;
- html += "<b>"+ioType+"</b><br/>";
- html += ioType.getDescription()+"<br/>";
- }
- else if( lastSelected != null ) {
- html += lastSelected.toString();
- }
- html += "</body></html>";
- deviceInfoPane.setText(html);
}
}