OSDN Git Service

リファクタリング、テキスト修正
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Mon, 10 Apr 2017 15:42:43 +0000 (00:42 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Mon, 10 Apr 2017 15:42:43 +0000 (00:42 +0900)
src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/MidiChordHelper.java
src/camidion/chordhelper/midieditor/NewSequenceDialog.java

index b915f25..c4ce6cc 100644 (file)
@@ -272,7 +272,7 @@ public class ChordHelperApplet extends JApplet {
         */
        public static class VersionInfo {
                public static final String NAME = "MIDI Chord Helper";
-               public static final String VERSION = "Ver.20170409.1";
+               public static final String VERSION = "Ver.20170410.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/";
@@ -283,16 +283,14 @@ public class ChordHelperApplet extends JApplet {
                                VersionInfo.NAME, VersionInfo.VERSION,
                                VersionInfo.COPYRIGHT ,VersionInfo.AUTHER, VersionInfo.URL);
        }
-       /**
-        * ボタンの余白を詰めたいときに setMargin() の引数に指定するインセット
-        */
+       /** ボタンの余白を詰めたいときに setMargin() の引数に指定するインセット */
        public static final Insets ZERO_INSETS = new Insets(0,0,0,0);
 
-       // GUIコンポーネント(Javaアプリメインからの参照用
+       // MIDIエディタダイアログ(Javaアプリメインからもアクセスできるようprivateにしていない
        MidiSequenceEditorDialog midiEditor;
-       PlaylistTableModel playlistModel;
 
        // GUIコンポーネント(内部保存用)
+       private PlaylistTableModel playlistModel;
        private MidiSequencerModel sequencerModel;
        private ChordMatrix chordMatrix;
        private JPanel keyboardSequencerPanel;
index a83ca82..1726e0f 100644 (file)
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
 
 import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 import javax.swing.WindowConstants;
 import javax.swing.event.TableModelEvent;
@@ -64,8 +65,8 @@ public class MidiChordHelper {
                        updateFilename(((PlaylistTableModel)event.getSource()).getSequencerModel());
                }
                public AppletFrame(ChordHelperApplet applet, List<File> fileList) {
-                       add( applet, BorderLayout.CENTER );
-                       add( status_, BorderLayout.SOUTH );
+                       add(applet, BorderLayout.CENTER);
+                       add(status_, BorderLayout.SOUTH);
                        applet.setStub(this);
                        applet.init();
                        setIconImage(applet.getIconImage());
@@ -75,19 +76,27 @@ public class MidiChordHelper {
                        addWindowListener(new WindowAdapter() {
                                @Override
                                public void windowClosing(WindowEvent event) {
-                                       if( ! applet.isModified() || applet.midiEditor.confirm(
-                                               "MIDI file not saved, exit anyway ?\n"+
-                                               "保存されていないMIDIファイルがありますが、終了してよろしいですか?"
-                                       )) { applet.destroy(); System.exit(0); }
+                                       if( applet.isModified() && ! confirmBeforeExit() ) return;
+                                       applet.destroy();
+                                       System.exit(0);
                                }
                        });
-                       applet.playlistModel.getSequencerModel().addChangeListener(e->updateFilename((MidiSequencerModel)e.getSource()));
-                       applet.playlistModel.addTableModelListener(e->updateFilename(e));
-                       updateFilename(applet.playlistModel.getSequencerModel());
+                       PlaylistTableModel playlistModel = applet.midiEditor.sequenceListTable.getModel();
+                       playlistModel.getSequencerModel().addChangeListener(e->updateFilename((MidiSequencerModel)e.getSource()));
+                       playlistModel.addTableModelListener(e->updateFilename(e));
+                       updateFilename(playlistModel.getSequencerModel());
                        setVisible(true);
                        applet.start();
                        applet.midiEditor.play(fileList);
                }
+               private boolean confirmBeforeExit() {
+                       String message = "MIDI file not saved, exit anyway ?\n"+
+                                       "MIDIファイルが保存されていません。終了してよろしいですか?";
+                       return JOptionPane.showConfirmDialog(
+                                       null, message, ChordHelperApplet.VersionInfo.NAME,
+                                       JOptionPane.YES_NO_OPTION,
+                                       JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION ;
+               }
                @Override
                public boolean isActive() { return true; }
                @Override
index 7ff2f03..f089410 100644 (file)
@@ -4,7 +4,6 @@ import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GridLayout;
-import java.awt.Insets;
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
@@ -55,7 +54,6 @@ import camidion.chordhelper.pianokeyboard.PianoKeyboardPanel;
  * 新しいMIDIシーケンスを生成するダイアログ
  */
 public class NewSequenceDialog extends JDialog {
-       private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
        private static final Integer[] PPQList = {
                48,60,80,96,120,160,192,240,320,384,480,960
        };
@@ -138,7 +136,7 @@ public class NewSequenceDialog extends JDialog {
                                        add(measureSelecter);
                                }});
                                add(new JButton("Randomize (Tempo, Time signature, Chord progression)") {{
-                                       setMargin(ZERO_INSETS);
+                                       setMargin(ChordHelperApplet.ZERO_INSETS);
                                        addActionListener(e->setRandomChordProgression(measureSelecter.getMeasureDuration()));
                                }});
                                add(new JPanel() {{
@@ -154,7 +152,7 @@ public class NewSequenceDialog extends JDialog {
                                        add(new JLabel("Chord progression :"));
                                        add(new JLabel("Transpose"));
                                        add(new JButton(" + Up ") {{
-                                               setMargin(ZERO_INSETS);
+                                               setMargin(ChordHelperApplet.ZERO_INSETS);
                                                addActionListener(e->{
                                                        ChordProgression cp = createChordProgression();
                                                        cp.transpose(1);
@@ -162,7 +160,7 @@ public class NewSequenceDialog extends JDialog {
                                                });
                                        }});
                                        add(new JButton(" - Down ") {{
-                                               setMargin(ZERO_INSETS);
+                                               setMargin(ChordHelperApplet.ZERO_INSETS);
                                                addActionListener(e->{
                                                        ChordProgression cp = createChordProgression();
                                                        cp.transpose(-1);
@@ -170,7 +168,7 @@ public class NewSequenceDialog extends JDialog {
                                                });
                                        }});
                                        add(new JButton(" Enharmonic ") {{
-                                               setMargin(ZERO_INSETS);
+                                               setMargin(ChordHelperApplet.ZERO_INSETS);
                                                addActionListener(e->{
                                                        ChordProgression cp = createChordProgression();
                                                        cp.toggleEnharmonically();
@@ -178,7 +176,7 @@ public class NewSequenceDialog extends JDialog {
                                                });
                                        }});
                                        add(new JButton("Relative key") {{
-                                               setMargin(ZERO_INSETS);
+                                               setMargin(ChordHelperApplet.ZERO_INSETS);
                                                addActionListener(e->{
                                                        ChordProgression cp = createChordProgression();
                                                        cp.toggleKeyMajorMinor();
@@ -189,7 +187,9 @@ public class NewSequenceDialog extends JDialog {
                                add(new JScrollPane(chordText));
                                add(new JPanel() {{
                                        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
-                                       add(new JButton(generateAction){{setMargin(ZERO_INSETS);}});
+                                       add(new JButton(generateAction){{
+                                               setMargin(ChordHelperApplet.ZERO_INSETS);
+                                       }});
                                }});
                        }});
                        add("Track", trackSpecPanel);