OSDN Git Service

・コードダイアグラムにコードを表示していないときに N.C.(Non Chord) と表示するようにした
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Thu, 12 Jan 2017 16:16:59 +0000 (01:16 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Thu, 12 Jan 2017 16:16:59 +0000 (01:16 +0900)
・リファクタリング、JavaDoc見直しなど

src/camidion/chordhelper/ChordDisplayLabel.java
src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/chorddiagram/ChordDiagram.java
src/camidion/chordhelper/chordmatrix/ChordMatrix.java
src/camidion/chordhelper/midieditor/MidiMessageForm.java
src/camidion/chordhelper/midieditor/NewSequenceDialog.java
src/camidion/chordhelper/midieditor/TimeSignatureSelecter.java
src/camidion/chordhelper/music/Chord.java
src/camidion/chordhelper/music/Key.java
src/camidion/chordhelper/pianokeyboard/MidiKeyboardPanel.java

index 0964730..c499ab2 100644 (file)
@@ -20,6 +20,7 @@ import camidion.chordhelper.pianokeyboard.PianoKeyboard;
  */
 public class ChordDisplayLabel extends JLabel {
        private String defaultString = null;
+       private String defaultToolTip = null;
        private Chord chord = null;
        private int noteNumber = -1;
        private boolean isDark = false;
@@ -27,12 +28,14 @@ public class ChordDisplayLabel extends JLabel {
        /**
         * 和音表示ラベルを構築します。
         * @param defaultString 初期表示する文字列
+        * @param defaultToolTip 初期設定するツールチップ
         * @param chordMatrix このラベルをクリックしたときに鳴らす和音ボタンマトリクス
         * @param keyboard このラベルをクリックしたときに鳴らす鍵盤
         */
-       public ChordDisplayLabel(String defaultString, ChordMatrix chordMatrix, PianoKeyboard keyboard) {
+       public ChordDisplayLabel(String defaultString, String defaultToolTip, ChordMatrix chordMatrix, PianoKeyboard keyboard) {
                super(defaultString, JLabel.CENTER);
                this.defaultString = defaultString;
+               setToolTipText(this.defaultToolTip = defaultToolTip);
                if( chordMatrix == null ) return;
                addMouseListener(new MouseAdapter() {
                        @Override
@@ -109,7 +112,7 @@ public class ChordDisplayLabel extends JLabel {
                this.noteNumber = -1;
                if( (this.chord = chord) == null ) {
                        setText(defaultString);
-                       setToolTipText(null);
+                       setToolTipText(defaultToolTip);
                }
                else {
                        setChordText();
index d4e9c1a..150ec63 100644 (file)
@@ -282,42 +282,37 @@ public class ChordHelperApplet extends JApplet {
         * バージョン情報
         */
        public static class VersionInfo {
-               public static final String      NAME = "MIDI Chord Helper";
-               public static final String      VERSION = "Ver.20170111.1";
-               public static final String      COPYRIGHT = "Copyright (C) 2004-2017";
-               public static final String      AUTHER = "@きよし - Akiyoshi Kamide";
-               public static final String      URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
-               /**
-                * バージョン情報を返します。
-                * @return バージョン情報
-                */
-               public static String getInfo() {
-                       return NAME + " " + VERSION + " " + COPYRIGHT + " " + AUTHER + " " + URL;
-               }
+               public static final String NAME = "MIDI Chord Helper";
+               public static final String VERSION = "Ver.20170112.1";
+               public static final String COPYRIGHT = "Copyright (C) 2004-2017";
+               public static final String AUTHER = "@きよし - Akiyoshi Kamide";
+               public static final String URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
        }
        @Override
-       public String getAppletInfo() { return VersionInfo.getInfo(); }
+       public String getAppletInfo() {
+               return VersionInfo.NAME
+                               + " " + VersionInfo.VERSION
+                               + " " + VersionInfo.COPYRIGHT
+                               + " " + VersionInfo.AUTHER
+                               + " " + VersionInfo.URL;
+       }
        private class AboutMessagePane extends JEditorPane {
-               URI uri = null;
-               public AboutMessagePane() { this(true); }
-               public AboutMessagePane(boolean link_enabled) {
-                       super( "text/html", "" );
-                       String link_string, tooltip = null;
-                       if( link_enabled && Desktop.isDesktopSupported() ) {
+               URI uri;
+               public AboutMessagePane() {
+                       super("text/html", "");
+                       boolean linkEnabled = Desktop.isDesktopSupported();
+                       String linkString = VersionInfo.URL;
+                       String tooltip = null;
+                       if( linkEnabled ) {
                                tooltip = "Click this URL to open with your web browser - URLをクリックしてWebブラウザで開く";
-                               link_string =
-                                       "<a href=\"" + VersionInfo.URL + "\" title=\"" +
-                                       tooltip + "\">" + VersionInfo.URL + "</a>" ;
+                               linkString = "<a href=\""+linkString+"\" title=\""+tooltip+"\">"+linkString+"</a>";
                        }
-                       else {
-                               link_enabled = false; link_string = VersionInfo.URL;
-                       }
-                       setText(
-                               "<html><center><font size=\"+1\">" + VersionInfo.NAME + "</font>  " +
-                                               VersionInfo.VERSION + "<br/><br/>" +
-                                               VersionInfo.COPYRIGHT + " " + VersionInfo.AUTHER + "<br/>" +
-                                               link_string + "</center></html>"
-                       );
+                       setText("<html><center><font size=\"+1\">" +
+                                       VersionInfo.NAME + "</font> " +
+                                       VersionInfo.VERSION + "<br/><br/>" +
+                                       VersionInfo.COPYRIGHT + " " +
+                                       VersionInfo.AUTHER + "<br/>" +
+                                       linkString + "</center></html>");
                        setToolTipText(tooltip);
                        setOpaque(false);
                        putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
@@ -326,7 +321,7 @@ public class ChordHelperApplet extends JApplet {
                        // メッセージ内の <a href=""> ~ </a> によるリンクを
                        // 実際に機能させる(ブラウザで表示されるようにする)ための設定
                        //
-                       if( ! link_enabled ) return;
+                       if( ! linkEnabled ) return;
                        try {
                                uri = new URI(VersionInfo.URL);
                        }catch( URISyntaxException use ) {
@@ -335,7 +330,7 @@ public class ChordHelperApplet extends JApplet {
                        }
                        addHyperlinkListener(new HyperlinkListener() {
                                public void hyperlinkUpdate(HyperlinkEvent e) {
-                                       if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
+                                       if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
                                                try{
                                                        Desktop.getDesktop().browse(uri);
                                                }catch(IOException ioe) {
@@ -575,12 +570,8 @@ public class ChordHelperApplet extends JApplet {
                                                msg = tickIndex.lastMetaMessageAt(
                                                        SequenceTickIndex.MetaMessageType.KEY_SIGNATURE, tickPos
                                                );
-                                               if( msg == null ) {
-                                                       keysigLabel.clear();
-                                               }
-                                               else {
-                                                       setKeySignature(new Key(msg.getData()));
-                                               }
+                                               if(msg == null) keysigLabel.clear();
+                                               else setKeySignature(new Key(msg.getData()));
                                        }
                                }
                        }
index ddfec12..36500c3 100644 (file)
@@ -133,7 +133,10 @@ public class ChordDiagram extends JPanel {
         * コードダイアグラムのタイトルラベル
         */
        public ChordDisplayLabel titleLabel =
-               new ChordDisplayLabel("Chord Diagram",null,null) {
+               new ChordDisplayLabel(
+                       "<html><span style=\"font-size: 170%\">N.C.</span></html>",
+                       "Non Chord",null,null
+               ) {
                        {
                                setHorizontalAlignment(SwingConstants.CENTER);
                                setVerticalAlignment(SwingConstants.BOTTOM);
index 7388657..1ab4e28 100644 (file)
@@ -57,7 +57,7 @@ public class ChordMatrix extends JPanel
        /** コードボタン */
        public ChordLabel chordLabels[] = new ChordLabel[N_COLUMNS * CHORD_BUTTON_ROWS];
        /** コードボタンの下のコード表示部 */
-       public ChordDisplayLabel chordDisplay = new ChordDisplayLabel("Chord Pad", this, null);
+       public ChordDisplayLabel chordDisplay = new ChordDisplayLabel("Chord Pad", null, this, null);
 
        private NoteWeight noteWeightArray[] = new NoteWeight[Note.SEMITONES_PER_OCTAVE];
        /**
index fc1b8af..0025fff 100644 (file)
@@ -41,14 +41,12 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                int i; String s;
                                // チャンネルメッセージ
                                for( i = 0x80; i <= 0xE0 ; i += 0x10 ) {
-                                       if( (s = MIDISpec.getStatusName(i)) == null )
-                                               continue;
+                                       if((s = MIDISpec.getStatusName(i)) == null) continue;
                                        addElement(String.format("0x%02X : %s", i, s));
                                }
                                // チャンネルを持たない SysEx やメタメッセージなど
                                for( i = 0xF0; i <= 0xFF ; i++ ) {
-                                       if( (s = MIDISpec.getStatusName(i)) == null )
-                                               continue;
+                                       if((s = MIDISpec.getStatusName(i)) == null) continue;
                                        addElement(String.format("0x%02X : %s", i, s));
                                }
                        }
@@ -59,9 +57,8 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        private ComboBoxModel<String> noteComboBoxModel =
                new DefaultComboBoxModel<String>() {
                        {
-                               for( int i = 0; i<=0x7F; i++ ) addElement(
-                                       String.format("0x%02X : %d : %s", i, i, Note.noteNumberToSymbol(i))
-                               );
+                               for(int i=0; i<=0x7F; i++)
+                                       addElement(String.format("0x%02X : %d : %s", i, i, Note.noteNumberToSymbol(i)));
                                // Center note C
                                setSelectedItem(getElementAt(60));
                        }
@@ -72,11 +69,8 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        private ComboBoxModel<String> percussionComboBoxModel =
                new DefaultComboBoxModel<String>() {
                        {
-                               for( int i = 0; i<=0x7F; i++ ) addElement(
-                                       String.format(
-                                               "0x%02X : %d : %s", i, i, MIDISpec.getPercussionName(i)
-                                       )
-                               );
+                               for( int i = 0; i<=0x7F; i++ )
+                                       addElement(String.format("0x%02X : %d : %s", i, i, MIDISpec.getPercussionName(i)));
                                setSelectedItem(getElementAt(35)); // Acoustic Bass Drum
                        }
                };
@@ -88,8 +82,7 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                        {
                                String s;
                                for( int i = 0; i<=0x7F; i++ ) {
-                                       if( (s = MIDISpec.getControllerName(i)) == null )
-                                               continue;
+                                       if((s = MIDISpec.getControllerName(i)) == null) continue;
                                        addElement(String.format("0x%02X : %d : %s", i, i, s));
                                }
                        }
@@ -100,11 +93,8 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        private ComboBoxModel<String> instrumentComboBoxModel =
                new DefaultComboBoxModel<String>() {
                        {
-                               for( int i = 0; i<=0x7F; i++ ) addElement(
-                                       String.format(
-                                               "0x%02X : %s", i, MIDISpec.instrumentNames[i]
-                                       )
-                               );
+                               for(int i = 0; i<=0x7F; i++)
+                                       addElement(String.format("0x%02X : %s", i, MIDISpec.instrumentNames[i]));
                        }
                };
        /**
@@ -114,17 +104,13 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                new DefaultComboBoxModel<String>() {
                        {
                                String s;
-                               String initial_type_string = null;
-                               for( int type = 0; type < 0x80 ; type++ ) {
-                                       if( (s = MIDISpec.getMetaName(type)) == null ) {
-                                               continue;
-                                       }
-                                       s = String.format("0x%02X : %s", type, s);
-                                       addElement(s);
-                                       if( type == 0x51 )
-                                               initial_type_string = s; // Tempo
+                               String initialTypeString = null;
+                               for(int type=0; type < 0x80 ; type++) {
+                                       if((s = MIDISpec.getMetaName(type)) == null) continue;
+                                       addElement(s = String.format("0x%02X : %s", type, s));
+                                       if( type == 0x51 ) initialTypeString = s; // Tempo
                                }
-                               setSelectedItem(initial_type_string);
+                               setSelectedItem(initialTypeString);
                        }
                };
        /**
@@ -133,9 +119,7 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        private ComboBoxModel<String> hexData1ComboBoxModel =
                new DefaultComboBoxModel<String>() {
                        {
-                               for( int i = 0; i<=0x7F; i++ ) {
-                                       addElement(String.format("0x%02X : %d", i, i ));
-                               }
+                               for(int i=0; i<=0x7F; i++) addElement(String.format("0x%02X : %d", i, i));
                        }
                };
        /**
@@ -144,17 +128,14 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        private ComboBoxModel<String> hexData2ComboBoxModel =
                new DefaultComboBoxModel<String>() {
                        {
-                               for( int i = 0; i<=0x7F; i++ ) {
-                                       addElement(String.format("0x%02X : %d", i, i ));
-                               }
+                               for(int i=0; i<=0x7F; i++) addElement(String.format("0x%02X : %d", i, i));
                        }
                };
        // データ選択操作部
        private HexSelecter statusText = new HexSelecter("Status/Command");
        private HexSelecter data1Text = new HexSelecter("[Data1] ");
        private HexSelecter data2Text = new HexSelecter("[Data2] ");
-       MidiChannelComboSelecter channelText =
-               new MidiChannelComboSelecter("MIDI Channel");
+       MidiChannelComboSelecter channelText = new MidiChannelComboSelecter("MIDI Channel");
 
        private JComboBox<String> statusComboBox = statusText.getComboBox();
        private JComboBox<String> data1ComboBox = data1Text.getComboBox();
@@ -175,15 +156,12 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                new PianoKeyboardAdapter() {
                                        public void pianoKeyPressed(int n, InputEvent e) {
                                                data1Text.setValue(n);
-                                               if( midiChannels != null )
-                                                       midiChannels[channelText.getSelectedChannel()].
-                                                       noteOn( n, data2Text.getValue() );
+                                               if( midiChannels == null ) return;
+                                               midiChannels[channelText.getSelectedChannel()].noteOn(n, data2Text.getValue());
                                        }
                                        public void pianoKeyReleased(int n, InputEvent e) {
-                                               if( midiChannels != null ) {
-                                                       midiChannels[channelText.getSelectedChannel()].
-                                                       noteOff( n, data2Text.getValue() );
-                                               }
+                                               if( midiChannels == null ) return;
+                                               midiChannels[channelText.getSelectedChannel()].noteOff(n, data2Text.getValue());
                                        }
                                }
                        );
@@ -198,14 +176,12 @@ public class MidiMessageForm extends JPanel implements ActionListener {
         */
        private TempoSelecter tempoSelecter = new TempoSelecter() {
                {
-                       tempoSpinnerModel.addChangeListener(
-                               new ChangeListener() {
-                                       @Override
-                                       public void stateChanged(ChangeEvent e) {
-                                               dataText.setValue(getTempoByteArray());
-                                       }
+                       tempoSpinnerModel.addChangeListener(new ChangeListener() {
+                               @Override
+                               public void stateChanged(ChangeEvent e) {
+                                       dataText.setValue(getTempoByteArray());
                                }
-                       );
+                       });
                }
        };
        /**
@@ -213,23 +189,16 @@ public class MidiMessageForm extends JPanel implements ActionListener {
         */
        private TimeSignatureSelecter timesigSelecter = new TimeSignatureSelecter() {
                {
-                       upperTimesigSpinnerModel.addChangeListener(
-                               new ChangeListener() {
-                                       @Override
-                                       public void stateChanged(ChangeEvent e) {
-                                               dataText.setValue(getByteArray());
-                                       }
-                               }
-                       );
-                       lowerTimesigCombobox.addActionListener(
-                               new ActionListener() {
-                                       @Override
-                                       public void actionPerformed(ActionEvent e) {
-                                               dataText.setValue(getByteArray());
-                                       }
-                               }
-                       );
+                       upperTimesigModel.addChangeListener(new ChangeListener() {
+                               @Override
+                               public void stateChanged(ChangeEvent e) { update(); }
+                       });
+                       lowerTimesigView.addActionListener(new ActionListener() {
+                               @Override
+                               public void actionPerformed(ActionEvent e) { update(); }
+                       });
                }
+               private void update() { dataText.setValue(getByteArray()); }
        };
        /**
         * 調号選択
@@ -266,15 +235,15 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                statusComboBox.addActionListener(this);
                channelComboBox.addActionListener(this);
                data1ComboBox.addActionListener(this);
-               setLayout(new BoxLayout( this, BoxLayout.Y_AXIS ));
+               setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                add(new JPanel() {{ add(statusText); add(channelText); }});
                add(durationForm);
                add(new JPanel() {{ add(data1Text); add(keyboardPanel); }});
                add(new JPanel() {{ add(data2Text); }});
-               add( tempoSelecter );
-               add( timesigSelecter );
-               add( keysigSelecter );
-               add( dataText );
+               add(tempoSelecter);
+               add(timesigSelecter);
+               add(keysigSelecter);
+               add(dataText);
                updateVisible();
        }
        @Override
@@ -300,14 +269,13 @@ public class MidiMessageForm extends JPanel implements ActionListener {
        /**
         * このMIDIメッセージフォームにMIDIチャンネルを設定します。
         *
-        * <p>設定したMIDIチャンネルには、
-        * ダイアログ内のピアノキーボードで音階を入力したときに
+        * <p>設定したMIDIチャンネルには、ダイアログ内のピアノキーボードで音階を入力したときに
         * ノートON/OFFが出力されます。これにより実際に音として聞けるようになります。
         * </p>
         *
         * @param midiChannels MIDIチャンネル
         */
-       public void setOutputMidiChannels( MidiChannel midiChannels[] ) {
+       public void setOutputMidiChannels(MidiChannel midiChannels[]) {
                this.midiChannels = midiChannels;
        }
        /**
@@ -315,16 +283,13 @@ public class MidiMessageForm extends JPanel implements ActionListener {
         * @param isVisible trueで表示、falseで非表示
         */
        public void setDurationVisible(boolean isVisible) {
-               isDurationVisible = isVisible;
-               updateVisible();
+               isDurationVisible = isVisible; updateVisible();
        }
        /**
         * 時間間隔入力の表示状態を返します。
         * @return true:表示中 false:非表示中
         */
-       public boolean isDurationVisible() {
-               return isDurationVisible;
-       }
+       public boolean isDurationVisible() { return isDurationVisible; }
        /**
         * 各入力欄の表示状態を更新します。
         */
@@ -400,17 +365,14 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                data1Text.setTitle("[Data1] MetaEvent Type");
                                data1ComboBox.setModel(metaTypeComboBoxModel);
                                int msgType = data1Text.getValue();
-                               tempoSelecter.setVisible( msgType == 0x51 );
-                               timesigSelecter.setVisible( msgType == 0x58 );
-                               keysigSelecter.setVisible( msgType == 0x59 );
-                               //
+                               tempoSelecter.setVisible(msgType == 0x51);
+                               timesigSelecter.setVisible(msgType == 0x58);
+                               keysigSelecter.setVisible(msgType == 0x59);
                                if( MIDISpec.isEOT(msgType) ) {
                                        dataText.clear();
                                        dataText.setVisible(false);
                                }
-                               else {
-                                       dataText.setTitle(MIDISpec.hasMetaMessageText(msgType)?"Text:":"Data:");
-                               }
+                               else dataText.setTitle(MIDISpec.hasMetaMessageText(msgType)?"Text:":"Data:");
                        }
                        else {
                                data1Text.setTitle("[Data1] ");
@@ -441,9 +403,7 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                msgData = new byte[0];
                        }
                        else {
-                               if( (msgData = dataText.getBytes() ) == null ) {
-                                       return null;
-                               }
+                               if( (msgData = dataText.getBytes() ) == null ) return null;
                        }
                        MetaMessage msg = new MetaMessage();
                        try {
@@ -472,12 +432,10 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                int msgData2 = data2Text.getValue();
                if( msgData2 < 0 ) msgData2 = 0;
                try {
-                       if( MIDISpec.isChannelMessage(msgStatus) ) {
+                       if( MIDISpec.isChannelMessage(msgStatus) )
                                msg.setMessage((msgStatus & 0xF0), channelText.getSelectedChannel(), msgData1, msgData2);
-                       }
-                       else {
+                       else
                                msg.setMessage(msgStatus, msgData1, msgData2);
-                       }
                } catch( InvalidMidiDataException e ) {
                        e.printStackTrace();
                        return null;
@@ -497,21 +455,21 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                                msgStatus = smsg.getCommand();
                                msgChannel = smsg.getChannel();
                        }
-                       statusText.setValue( msgStatus );
-                       channelText.setSelectedChannel( msgChannel );
-                       data1Text.setValue( smsg.getData1() );
-                       data2Text.setValue( smsg.getData2() );
+                       statusText.setValue(msgStatus);
+                       channelText.setSelectedChannel(msgChannel);
+                       data1Text.setValue(smsg.getData1());
+                       data2Text.setValue(smsg.getData2());
                }
                else if( msg instanceof SysexMessage ) {
                        SysexMessage sysexMsg = (SysexMessage)msg;
-                       statusText.setValue( sysexMsg.getStatus() );
-                       dataText.setValue( sysexMsg.getData() );
+                       statusText.setValue(sysexMsg.getStatus());
+                       dataText.setValue(sysexMsg.getData());
                }
                else if( msg instanceof MetaMessage ) {
                        MetaMessage metaMsg = (MetaMessage)msg;
                        int msgType = metaMsg.getType();
                        byte data[] = metaMsg.getData();
-                       statusText.setValue( 0xFF );
+                       statusText.setValue(0xFF);
                        data1Text.setValue(msgType);
                        switch(msgType) {
                        case 0x51: tempoSelecter.setTempo(data); break;
@@ -519,12 +477,10 @@ public class MidiMessageForm extends JPanel implements ActionListener {
                        case 0x59: keysigSelecter.setSelectedKey(new Key(data)); break;
                        default: break;
                        }
-                       if( MIDISpec.hasMetaMessageText(msgType) ) {
+                       if( MIDISpec.hasMetaMessageText(msgType) )
                                dataText.setString(new String(data,charset));
-                       }
-                       else {
+                       else
                                dataText.setValue(data);
-                       }
                        updateVisible();
                }
        }
@@ -545,9 +501,7 @@ public class MidiMessageForm extends JPanel implements ActionListener {
         * 入力内容がノートメッセージかどうか調べます。
         * @return ノートメッセージのときtrue
         */
-       public boolean isNote() {
-               return isNote(statusText.getValue());
-       }
+       public boolean isNote() { return isNote(statusText.getValue()); }
        /**
         * 入力内容がノートメッセージかどうか調べます。
         * @param status MIDIメッセージのステータス
index da9d302..fae7943 100644 (file)
@@ -215,7 +215,7 @@ public class NewSequenceDialog extends JDialog {
                        }});
                        add("Track", trackSpecPanel);
                }});
-               setBounds( 250, 200, 600, 540 );
+               setBounds(250,200,600,540);
        }
        /**
         * 新しいコード進行を生成して返します。
index 6b5a9a9..30f76ca 100644 (file)
@@ -10,83 +10,61 @@ import javax.swing.SpinnerNumberModel;
  * 拍子選択ビュー
  */
 public class TimeSignatureSelecter extends JPanel {
-       SpinnerNumberModel upperTimesigSpinnerModel = new SpinnerNumberModel(4, 1, 32, 1);
-       private JSpinner upperTimesigSpinner = new JSpinner(upperTimesigSpinnerModel) {
-               {
-                       setToolTipText("Time signature (upper digit) - 拍子の分子");
-               }
+       protected SpinnerNumberModel upperTimesigModel = new SpinnerNumberModel(4, 1, 32, 1);
+       private JSpinner upperTimesigView = new JSpinner(upperTimesigModel) {
+               { setToolTipText("Time signature (upper digit) - 拍子の分子"); }
        };
-       JComboBox<String> lowerTimesigCombobox = new JComboBox<String>() {
+       protected JComboBox<String> lowerTimesigView = new JComboBox<String>() {
                {
                        setToolTipText("Time signature (lower digit) - 拍子の分母");
-                       for( int i=0; i<6; i++ ) addItem( "/" + (1<<i) );
-                       setSelectedIndex(2);
+                       for(int i=0; i<6; i++) addItem("/"+(1<<i)); setSelectedIndex(2);
                }
        };
-       private class TimeSignatureLabel extends JLabel {
+       private static class TimeSignatureLabel extends JLabel {
+               { setToolTipText("Time signature - 拍子"); }
                private byte upper = -1;
-               private byte lower_index = -1;
-               {
-                       setToolTipText("Time signature - 拍子");
-               }
-               public void setTimeSignature(byte upper, byte lower_index) {
-                       if( this.upper == upper && this.lower_index == lower_index ) {
-                               return;
-                       }
-                       setText("<html><font size=\"+1\">" + upper + "/" + (1 << lower_index) + "</font></html>");
+               private byte lowerIndex = -1;
+               public void setTimeSignature(byte upper, byte lowerIndex) {
+                       if( this.upper == upper && this.lowerIndex == lowerIndex ) return;
+                       setText("<html><font size=\"+1\">"+upper+"/"+(1<<lowerIndex)+"</font></html>");
+                       this.upper = upper;
+                       this.lowerIndex = lowerIndex;
                }
        }
        private TimeSignatureLabel timesigValueLabel = new TimeSignatureLabel();
-       private boolean editable;
        public TimeSignatureSelecter() {
-               add(upperTimesigSpinner);
-               add(lowerTimesigCombobox);
+               add(upperTimesigView);
+               add(lowerTimesigView);
                add(timesigValueLabel);
                setEditable(true);
        }
        public void clear() {
-               upperTimesigSpinnerModel.setValue(4);
-               lowerTimesigCombobox.setSelectedIndex(2);
-       }
-       public int getUpperValue() {
-               return upperTimesigSpinnerModel.getNumber().intValue();
-       }
-       public byte getUpperByte() {
-               return upperTimesigSpinnerModel.getNumber().byteValue();
-       }
-       public int getLowerValueIndex() {
-               return lowerTimesigCombobox.getSelectedIndex();
-       }
-       public byte getLowerByte() {
-               return (byte)getLowerValueIndex();
+               upperTimesigModel.setValue(4);
+               lowerTimesigView.setSelectedIndex(2);
        }
        public byte[] getByteArray() {
-               byte[] data = new byte[4];
-               data[0] = getUpperByte();
-               data[1] = getLowerByte();
-               data[2] = (byte)( 96 >> getLowerValueIndex() );
-               data[3] = 8;
-               return data;
+               byte upper = upperTimesigModel.getNumber().byteValue();
+               byte lowerIndex = (byte)lowerTimesigView.getSelectedIndex();
+               return new byte[] { upper, lowerIndex, (byte)(96 >> lowerIndex), 8 };
        }
        public void setValue(byte upper, byte lowerIndex) {
-               upperTimesigSpinnerModel.setValue( upper );
-               lowerTimesigCombobox.setSelectedIndex( lowerIndex );
-               timesigValueLabel.setTimeSignature( upper, lowerIndex );
+               upperTimesigModel.setValue(upper);
+               lowerTimesigView.setSelectedIndex(lowerIndex);
+               timesigValueLabel.setTimeSignature(upper, lowerIndex);
        }
        public void setValue(byte[] data) {
-               if(data == null)
-                       clear();
-               else
-                       setValue(data[0], data[1]);
+               if(data == null) clear(); else setValue(data[0], data[1]);
        }
+       private boolean editable;
        public boolean isEditable() { return editable; }
-       public void setEditable( boolean editable ) {
+       public void setEditable(boolean editable) {
                this.editable = editable;
-               upperTimesigSpinner.setVisible(editable);
-               lowerTimesigCombobox.setVisible(editable);
+               upperTimesigView.setVisible(editable);
+               lowerTimesigView.setVisible(editable);
                timesigValueLabel.setVisible(!editable);
-               if( !editable ) {
-                       timesigValueLabel.setTimeSignature(getUpperByte(), getLowerByte());
-               }
+               if(!editable) timesigValueLabel.setTimeSignature(
+                       upperTimesigModel.getNumber().byteValue(),
+                       (byte)lowerTimesigView.getSelectedIndex()
+               );
        }
 }
\ No newline at end of file
index 548b4f5..6a91fb4 100644 (file)
@@ -522,20 +522,20 @@ public class Chord {
         * @return コード名のHTML
         */
        public String toHtmlString(String colorName) {
-               String span = "<span style=\"font-size: 120%\">";
+               String smallSpan = "<span style=\"font-size: 120%\">";
                String endSpan = "</span>";
                String root = rootNoteSymbol.toString();
-               String formattedRoot = (root.length() == 1) ? root + span :
-                       root.replace("#",span+"<sup>#</sup>").
-                       replace("b",span+"<sup>b</sup>").
-                       replace("x",span+"<sup>x</sup>");
+               String formattedRoot = (root.length() == 1) ? root + smallSpan :
+                       root.replace("#",smallSpan+"<sup>#</sup>").
+                       replace("b",smallSpan+"<sup>b</sup>").
+                       replace("x",smallSpan+"<sup>x</sup>");
                String formattedBass = "";
                if( ! rootNoteSymbol.equals(bassNoteSymbol) ) {
                        String bass = bassNoteSymbol.toString();
-                       formattedBass = (bass.length() == 1) ? bass + span :
-                               bass.replace("#",span+"<sup>#</sup>").
-                               replace("b",span+"<sup>b</sup>").
-                               replace("x",span+"<sup>x</sup>");
+                       formattedBass = (bass.length() == 1) ? bass + smallSpan :
+                               bass.replace("#",smallSpan+"<sup>#</sup>").
+                               replace("b",smallSpan+"<sup>b</sup>").
+                               replace("x",smallSpan+"<sup>x</sup>");
                        formattedBass = "/" + formattedBass + endSpan;
                }
                String suffix = symbolSuffix().
index f343fbe..6a0c657 100644 (file)
@@ -20,7 +20,6 @@ public class Key {
         * 調号が空(C/Am ハ長調またはイ短調)で、メジャー・マイナーの区別のない調
         */
        public static final Key C_MAJOR_OR_A_MINOR = new Key();
-       private Key() { }
        /**
         * キー指定(メジャー/マイナー/両方)
         */
@@ -81,16 +80,20 @@ public class Key {
                normalize();
        }
        /**
-        * MIDIの調データ(メタメッセージ2byteの配列)から調を構築します。
+        * MIDIの調データ(メタメッセージ2byte配列)から調を構築します。
+        * <p>デフォルト値は、ハ長調またはイ短調(両者の区別なし)です。
+        * 引数から取得できた値だけが、デフォルト値から変更されます。
+        * 例えば次のような場合、取得できなかった値はデフォルト値のままとなります。
+        * </p>
         * <ul>
-        * <li>長さ0の配列が与えられた場合は{@link #Key() 引数のないコンストラクタ}と同じ動作になります。</li>
-        * <li>メジャー・マイナーの区別を表す有効な値が見つからなかった場合、区別なしとして構築されます。</li>
+        * <li>引数がnull</li>
+        * <li>引数の配列が2byteに満たない</li>
+        * <li>長調・短調の区別が不明確(配列インデックス1の値が、0:長調、1:短調、のどちらでもない)</li>
         * </ul>
-        *
         * @param midiData MIDIの調データ
         */
-       public Key(byte midiData[]) {
-               if( midiData.length == 0 ) return;
+       public Key(byte ... midiData) {
+               if( midiData == null || midiData.length == 0 ) return;
                co5 = midiData[0];
                if( midiData.length > 1 ) {
                        switch(midiData[1]) {
@@ -207,7 +210,7 @@ public class Key {
        }
        /**
         * MIDIの調データ(メタメッセージ2byte)を生成して返します。
-        * @return  MIDIの調データ
+        * @return MIDIの調データ
         */
        public byte[] getBytes() {
                return new byte[] {(byte) co5, (byte) ((majorMinor == MajorMinor.MINOR) ? 1 : 0)};
index 367b762..d49f029 100644 (file)
@@ -40,7 +40,7 @@ public class MidiKeyboardPanel extends JPanel {
                keyboardCenterPanel = new PianoKeyboardPanel();
                keyboardCenterPanel.keyboard.chordMatrix = chordMatrix;
                keyboardCenterPanel.keyboard.chordDisplay =
-                       new ChordDisplayLabel("MIDI Keyboard", chordMatrix, keyboardCenterPanel.keyboard);
+                       new ChordDisplayLabel("MIDI Keyboard", null, chordMatrix, keyboardCenterPanel.keyboard);
                setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                add(keyboardChordPanel = new JPanel() {
                        {