OSDN Git Service

・アプリ起動時に底辺のステータスバーが表示されていなかったので復活
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Thu, 19 May 2016 16:38:21 +0000 (01:38 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Thu, 19 May 2016 16:38:21 +0000 (01:38 +0900)
・リファクタリング

src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/MidiChordHelper.java
src/camidion/chordhelper/midieditor/MidiSequenceEditor.java

index f99df71..6641944 100644 (file)
@@ -289,7 +289,7 @@ public class ChordHelperApplet extends JApplet {
         */
        public static class VersionInfo {
                public static final String      NAME = "MIDI Chord Helper";
-               public static final String      VERSION = "Ver.20160518.1";
+               public static final String      VERSION = "Ver.20160519.1";
                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/";
@@ -368,21 +368,15 @@ public class ChordHelperApplet extends JApplet {
                        }
                };
        }
-       // 終了してよいか確認する
-       public boolean isConfirmedToExit() {
-               return ! isModified() || JOptionPane.showConfirmDialog(
-                       this,
-                       "MIDI file not saved, exit anyway ?\n保存されていないMIDIファイルがありますが、終了してよろしいですか?",
-                       VersionInfo.NAME,
-                       JOptionPane.YES_NO_OPTION,
-                       JOptionPane.WARNING_MESSAGE
-               ) == JOptionPane.YES_OPTION ;
-       }
        /**
-        * ã\82¢ã\83\97ã\83ªã\82±ã\83¼ã\82·ã\83§ã\83³ã\81®ã\82¢ã\82¤ã\82³ã\83³ã\82¤ã\83¡ã\83¼ã\82¸
+        * ã\82¢ã\83\97ã\83ªã\82±ã\83¼ã\82·ã\83§ã\83³ã\81®ã\82¤ã\83¡ã\83¼ã\82¸ã\82¢ã\82¤ã\82³ã\83³
         */
        public ImageIcon imageIcon;
        /**
+        * アプリケーションのアイコンイメージ
+        */
+       public Image iconImage;
+       /**
         * ボタンの余白を詰めたいときに setMargin() の引数に指定するインセット
         */
        public static final Insets ZERO_INSETS = new Insets(0,0,0,0);
@@ -416,12 +410,11 @@ public class ChordHelperApplet extends JApplet {
                URL imageIconUrl = getClass().getResource(imageIconPath);
                if( imageIconUrl == null ) {
                        System.out.println("Icon image "+imageIconPath+" not found");
-                       imageIcon = null;
                }
                else {
                        imageIcon = new ImageIcon(imageIconUrl);
+                       iconImage = imageIcon.getImage();
                }
-               Image iconImage = (imageIcon == null) ? null : imageIcon.getImage();
                rootPaneDefaultBgcolor = getContentPane().getBackground();
                chordMatrix = new ChordMatrix() {{
                        addChordMatrixListener(new ChordMatrixListener(){
index c4ce3f1..e2321a3 100644 (file)
@@ -11,6 +11,7 @@ import java.awt.Image;
 import java.awt.Toolkit;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -30,6 +31,7 @@ import javax.swing.event.TableModelEvent;
 import javax.swing.event.TableModelListener;
 
 import camidion.chordhelper.mididevice.MidiSequencerModel;
+import camidion.chordhelper.midieditor.MidiSequenceEditor;
 import camidion.chordhelper.midieditor.PlaylistTableModel;
 import camidion.chordhelper.midieditor.SequenceTrackListTableModel;
 
@@ -68,30 +70,31 @@ public class MidiChordHelper {
                        }
                });
        }
-       private static class AppletFrame extends JFrame
-               implements AppletStub, AppletContext
-       {
-               JLabel status_;
-               ChordHelperApplet applet;
+       private static class AppletFrame extends JFrame implements AppletStub, AppletContext {
+               private JLabel status_ = new JLabel("Welcome to "+ChordHelperApplet.VersionInfo.NAME) {
+                       { setFont(getFont().deriveFont(Font.PLAIN)); }
+               };
+               private ChordHelperApplet applet;
+               private WindowListener windowListener = new WindowAdapter() {
+                       @Override
+                       public void windowClosing(WindowEvent evt) {
+                               MidiSequenceEditor ed = applet.deviceModelList.getEditorDialog();
+                               if( ! ed.sequenceListTable.getModel().isModified() || ed.confirm(
+                                       "MIDI file not saved, exit anyway ?\n"+
+                                       "保存されていないMIDIファイルがありますが、終了してよろしいですか?"
+                               )) System.exit(0);
+                       }
+               };
                public AppletFrame(ChordHelperApplet applet) {
+                       this.applet = applet;
                        setTitle(ChordHelperApplet.VersionInfo.NAME);
-                       (status_ = new JLabel()).setFont(
-                               status_.getFont().deriveFont(Font.PLAIN)
-                       );
-                       add( this.applet = applet, BorderLayout.CENTER );
+                       add( applet, BorderLayout.CENTER );
                        add( status_, BorderLayout.SOUTH );
                        applet.setStub(this);
                        applet.init();
-                       Image iconImage = applet.imageIcon == null ? null : applet.imageIcon.getImage();
-                       setIconImage(iconImage);
+                       setIconImage(applet.iconImage);
                        setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
-                       addWindowListener(new WindowAdapter() {
-                               @Override
-                               public void windowClosing(WindowEvent evt) {
-                                       if( AppletFrame.this.applet.isConfirmedToExit() )
-                                               System.exit(0);
-                               }
-                       });
+                       addWindowListener(windowListener);
                        new TitleUpdater(applet);
                        pack();
                        setLocationRelativeTo(null);
@@ -102,7 +105,7 @@ public class MidiChordHelper {
                 * タイトルバー更新器
                 */
                private class TitleUpdater implements ChangeListener, TableModelListener {
-                       MidiSequencerModel sequencerModel;
+                       private MidiSequencerModel sequencerModel;
                        /**
                         * タイトルバー更新器の構築
                         * @param applet 対象アプレット
@@ -118,10 +121,7 @@ public class MidiChordHelper {
                        @Override
                        public void tableChanged(TableModelEvent e) {
                                int col = e.getColumn();
-                               if( col == PlaylistTableModel.Column.FILENAME.ordinal() ) {
-                                       setFilenameToTitle();
-                               }
-                               if( col == TableModelEvent.ALL_COLUMNS ) {
+                               if( col == PlaylistTableModel.Column.FILENAME.ordinal() || col == TableModelEvent.ALL_COLUMNS ) {
                                        setFilenameToTitle();
                                }
                        }
index 0b5e75d..3b5aa6a 100644 (file)
@@ -135,7 +135,7 @@ public class MidiSequenceEditor extends JDialog {
         * @param message 確認メッセージ
         * @return 確認OKのときtrue
         */
-       boolean confirm(String message) {
+       public boolean confirm(String message) {
                return JOptionPane.showConfirmDialog(this, message, ChordHelperApplet.VersionInfo.NAME,
                                JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION ;
        }
@@ -1135,7 +1135,7 @@ public class MidiSequenceEditor extends JDialog {
 
        /**
         * 新しい {@link MidiSequenceEditor} を構築します。
-        * @param deviceModelList MIDIデバイスモデルリスト
+        * @param sequencerModel シーケンサーモデル
         */
        public MidiSequenceEditor(MidiSequencerModel sequencerModel) {
                sequenceListTable = new SequenceListTable(new PlaylistTableModel(sequencerModel));