From 8e8e2a0dd08e99daf7f0929a76c0fa8f18ac1ffc Mon Sep 17 00:00:00 2001 From: Akiyoshi Kamide Date: Sat, 7 May 2016 01:42:04 +0900 Subject: [PATCH] =?utf8?q?MIDI=E3=82=B1=E3=83=BC=E3=83=96=E3=83=AB?= =?utf8?q?=E3=82=926=E8=89=B2=E4=BD=BF=E3=81=84=E5=88=87=E3=82=8B=E3=81=BE?= =?utf8?q?=E3=81=A7=E8=89=B2=E3=82=92=E9=87=8D=E8=A4=87=E3=81=95=E3=81=9B?= =?utf8?q?=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/camidion/chordhelper/ChordHelperApplet.java | 2 +- .../chordhelper/mididevice/MidiCablePane.java | 23 +++++++++++++++------- .../chordhelper/mididevice/MidiDeviceFrame.java | 10 ---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/camidion/chordhelper/ChordHelperApplet.java b/src/camidion/chordhelper/ChordHelperApplet.java index 3643166..52522c3 100644 --- a/src/camidion/chordhelper/ChordHelperApplet.java +++ b/src/camidion/chordhelper/ChordHelperApplet.java @@ -284,7 +284,7 @@ public class ChordHelperApplet extends JApplet { */ public static class VersionInfo { public static final String NAME = "MIDI Chord Helper"; - public static final String VERSION = "Ver.20160506.1"; + public static final String VERSION = "Ver.20160506.2"; public static final String COPYRIGHT = "Copyright (C) 2004-2016"; public static final String AUTHER = "@きよし - Akiyoshi Kamide"; public static final String URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/"; diff --git a/src/camidion/chordhelper/mididevice/MidiCablePane.java b/src/camidion/chordhelper/mididevice/MidiCablePane.java index eb5b56b..cd311d0 100644 --- a/src/camidion/chordhelper/mididevice/MidiCablePane.java +++ b/src/camidion/chordhelper/mididevice/MidiCablePane.java @@ -12,6 +12,7 @@ import java.awt.dnd.DragSourceMotionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; +import java.util.Arrays; import java.util.Hashtable; import java.util.List; @@ -71,8 +72,11 @@ public class MidiCablePane extends JComponent { JInternalFrame frame = e.getInternalFrame(); if( ! (frame instanceof MidiDeviceFrame) ) return; MidiDeviceFrame f = (MidiDeviceFrame)frame; - List rxList = f.getMidiConnecterListView().getModel().getMidiDevice().getReceivers(); + MidiConnecterListModel m = f.getMidiConnecterListView().getModel(); + List rxList = m.getMidiDevice().getReceivers(); for( Receiver rx : rxList ) colorMap.remove(rx); + m.closeDevice(); + frame.setVisible(m.getMidiDevice().isOpen()); repaint(); } }; @@ -98,23 +102,28 @@ public class MidiCablePane extends JComponent { private static final Stroke CABLE_STROKE = new BasicStroke( 3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); - private static final Color[] CABLE_COLORS = { + private static final List CABLE_COLORS = Arrays.asList( new Color(255, 0, 0,144), new Color(0, 255, 0,144), new Color(0, 0, 255,144), new Color(191,191,0,144), new Color(0,191,191,144), - new Color(191,0,191,144), - }; + new Color(191,0,191,144) + ); private static final Color ADDING_CABLE_COLOR = new Color(0, 0, 0, 144); private static final Color REMOVING_CABLE_COLOR = new Color(128, 128, 128, 144); - private int nextColorIndex = 0; private Hashtable colorMap = new Hashtable<>(); private Color colorOf(Receiver rx) { Color color = colorMap.get(rx); if( color == null ) { - colorMap.put(rx, color=CABLE_COLORS[nextColorIndex++]); - if( nextColorIndex >= CABLE_COLORS.length ) nextColorIndex = 0; + for( Color c : CABLE_COLORS ) { + if( ! colorMap.containsValue(c) ) { + colorMap.put(rx, c); + return c; + } + } + color = CABLE_COLORS.get((int)( Math.random() * CABLE_COLORS.size() )); + colorMap.put(rx, color); } return color; } diff --git a/src/camidion/chordhelper/mididevice/MidiDeviceFrame.java b/src/camidion/chordhelper/mididevice/MidiDeviceFrame.java index f5b0fc4..2f6049d 100644 --- a/src/camidion/chordhelper/mididevice/MidiDeviceFrame.java +++ b/src/camidion/chordhelper/mididevice/MidiDeviceFrame.java @@ -12,8 +12,6 @@ import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.Timer; -import javax.swing.event.InternalFrameAdapter; -import javax.swing.event.InternalFrameEvent; /** * MIDIデバイスフレームビュー @@ -48,14 +46,6 @@ public class MidiDeviceFrame extends JInternalFrame { addComponentListener(cablePane.midiDeviceFrameComponentListener); setTitle("[" + model.getMidiDeviceInOutType().getShortName() + "] " + model); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addInternalFrameListener(new InternalFrameAdapter() { - @Override - public void internalFrameClosing(InternalFrameEvent e) { - MidiConnecterListModel m = listView.getModel(); - m.closeDevice(); - setVisible(m.getMidiDevice().isOpen()); - } - }); add(new JLabel("--:--") {{ timer = new Timer(50, new ActionListener() { private long sec = -2; -- 2.11.0