OSDN Git Service

ソフトウェアアップデート通知をするように改良
authorU-nishio-PC8\nishio <spark_xp@users.sourceforge.jp>
Sun, 28 Aug 2011 09:27:51 +0000 (18:27 +0900)
committerU-nishio-PC8\nishio <spark_xp@users.sourceforge.jp>
Sun, 28 Aug 2011 09:27:51 +0000 (18:27 +0900)
src/twitter/gui/action/TweetMainAction.java
src/twitter/gui/form/AboutDialog.form
src/twitter/gui/form/AboutDialog.java
src/twitter/gui/form/NishioTweetManager.java
src/twitter/gui/form/UpdateNotifyDialog.form
src/twitter/gui/form/UpdateNotifyDialog.java
src/twitter/manage/ClientVersionManager.java

index 9417b1d..7ba4afe 100644 (file)
@@ -76,6 +76,7 @@ import twitter.gui.form.FollowingFollowerDialog;
 import twitter.gui.form.HashtagSearchDialog;
 import twitter.gui.form.KeywordSearchDialog;
 import twitter.gui.form.OutputCSVLogDialog;
+import twitter.gui.form.UpdateNotifyDialog;
 import twitter.gui.form.UserListDialog;
 import twitter.gui.form.UserSearchDialog;
 import twitter.log.TwitterLogManager;
@@ -191,6 +192,8 @@ public class TweetMainAction {
        private boolean isTempOpenedSendDMTab = true;
         //ログを保存するかどうか
         private boolean saveLog = false;
+        //update通知をするかどうか
+        private boolean isUpdateNotify = true;
 
        // Tweetの詳細情報を表示する部分
        private JLabel userImageLabel = null;
@@ -220,6 +223,8 @@ public class TweetMainAction {
        // 新しく取得したtweetでまだ参照していない数
        private int uncheckedTimelineTweetCount = 0;
        private AboutDialog aboutDialog = null;
+        //update dialog
+        private UpdateNotifyDialog updateDialog = null;
        // アカウント情報表示ダイアログ
        private AccountDialog accountDialog;
        // ツイートを表示するテーブル管理
@@ -1328,6 +1333,15 @@ public class TweetMainAction {
                // dialog.setLocation(loc);
                dialog.setVisible(true);
        }
+        
+        /**
+         * 最新クライアント情報通知ダイアログを表示
+         */
+        public void actionShowUpdateDialog() {
+            UpdateNotifyDialog dialog = getUpdateNotifyDialog();
+            dialog.setLocationRelativeTo(null);
+            dialog.setVisible(true);
+        }
 
        /**
         * アカウントダイアログを表示
@@ -1806,6 +1820,17 @@ public class TweetMainAction {
                }
                return aboutDialog;
        }
+        
+        /**
+         * update dialog
+         * @return 
+         */
+        public UpdateNotifyDialog getUpdateNotifyDialog() {
+            if( updateDialog == null ) {
+                updateDialog = new UpdateNotifyDialog(mainFrame, true, this);
+            }
+            return updateDialog;
+        }
 
        /**
         * テーブルで選択した場所のTweet情報を取得
@@ -1914,6 +1939,12 @@ public class TweetMainAction {
 
                 //表示可能ツイート数
                 String nost = this.property.getProperty("numOfShowTweet");
+                
+                //最新クライアント情報を通知するか
+                String unt = this.property.getProperty("updateNotify");
+                if( unt == null ) {
+                    unt = this.isUpdateNotify + "";
+                }
 
                try {
                        this.newTableColor = new Color(Integer.parseInt(ntrgb));
@@ -1944,6 +1975,9 @@ public class TweetMainAction {
 
                         //表示可能ツイート数
                         this.tableElementMaxSize = Integer.parseInt(nost);
+                        
+                        //update notify
+                        this.isUpdateNotify = Boolean.parseBoolean(unt);
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                }
@@ -2012,6 +2046,9 @@ public class TweetMainAction {
 
                 //テーブルに表示可能なツイートの数
                 this.property.setProperty("numOfShowTweet", this.getTableElementMaxSize() + "");
+                
+                //update notify
+                this.property.setProperty("updateNotify", this.isUpdateNotify + "");
 
                // プロパティのリストを保存
                property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
@@ -2163,6 +2200,20 @@ public class TweetMainAction {
        public void setNotifyDirectMessage(boolean notify) {
                this.isNotifyDirectMessage = notify;
        }
+        
+        /**
+         * 最新クライアント情報を通知するかどうか
+         */
+        public boolean isUpdateNotify() {
+            return this.isUpdateNotify;
+        }
+        
+        /**
+         * 最新クライアント情報を通知するかどうか設定
+         */
+        public void setUpdateNotify(boolean notify) {
+            this.isUpdateNotify = notify;
+        }
 
        /**
         *
index f53ad7c..182e7cc 100644 (file)
@@ -58,7 +58,7 @@
   <SubComponents>
     <Component class="javax.swing.JLabel" name="jLabel1">
       <Properties>
-        <Property name="text" type="java.lang.String" value="Nishio Tweet Manager version 0.6"/>
+        <Property name="text" type="java.lang.String" value="Version Information"/>
       </Properties>
     </Component>
     <Component class="javax.swing.JButton" name="jButton1">
index 22de6a8..b207348 100644 (file)
@@ -12,6 +12,7 @@ package twitter.gui.form;
 
 import java.awt.Desktop;
 import java.net.URL;
+import twitter.manage.ClientVersionManager;
 
 /**
  *
@@ -26,6 +27,8 @@ public class AboutDialog extends javax.swing.JDialog {
 
         //デフォルトボタン
         this.getRootPane().setDefaultButton(jButton1);
+        //version情報
+        this.jLabel1.setText("Nishio Tweet Manager version " + ClientVersionManager.getInstance().getCurrentversion());
     }
 
     /** This method is called from within the constructor to
@@ -46,7 +49,7 @@ public class AboutDialog extends javax.swing.JDialog {
         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
         setTitle("About Nishio Tweet Manager");
 
-        jLabel1.setText("Nishio Tweet Manager version 0.6");
+        jLabel1.setText("Version Information");
 
         jButton1.setText("OK");
         jButton1.addActionListener(new java.awt.event.ActionListener() {
@@ -106,7 +109,8 @@ public class AboutDialog extends javax.swing.JDialog {
     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
         try {
             // クリック時
-            URL url = new URL("http://densan-labs.net/software/ntm");
+            String u = ClientVersionManager.getInstance().getNishiotweetmanagerurl();
+            URL url = new URL(u);
             // デフォルトのブラウザを使ってリンク先を表示
             Desktop dp = Desktop.getDesktop();
             dp.browse(url.toURI());
index 6b27eac..bc8c1d1 100644 (file)
@@ -40,7 +40,9 @@ import twitter.gui.action.TweetMainAction;
 import twitter.gui.component.TweetHashtagHyperlinkHandler;
 import twitter.gui.component.TweetHyperlinkHandler;
 import twitter.gui.component.TweetTextFieldPopupMenu;
+import twitter.manage.ClientVersionManager;
 import twitter.manage.TweetManager;
+import twitter.manage.VersionInfo;
 import twitter.task.TimerID;
 
 /**
@@ -1497,6 +1499,18 @@ private void logSaveCheckItemActionPerformed(java.awt.event.ActionEvent evt) {//
                        // フォーカスを一番初めのテーブルに移す
                        this.mainAction.actionRequestFocusToTab(0);
                }
+                try {
+                    ClientVersionManager version = ClientVersionManager.getInstance();
+                    VersionInfo latest = version.getLatestVersionInfo();
+                    if( latest != null && !latest.getVersion().equals( version.getCurrentversion() )) {
+                        if( this.mainAction.isUpdateNotify() ) {
+                            //最新クライアント情報を通知するかどうか
+                            this.mainAction.actionShowUpdateDialog();
+                        }
+                    }
+                }catch(Exception e) {
+                    e.printStackTrace();
+                }
        }
 
        /**
index 36ed2e8..9c75b2f 100644 (file)
       <Properties>
         <Property name="text" type="java.lang.String" value="&#x30b5;&#x30a4;&#x30c8;&#x3078;&#x79fb;&#x52d5;"/>
       </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
+      </Events>
     </Component>
     <Component class="javax.swing.JButton" name="jButton2">
       <Properties>
         <Property name="text" type="java.lang.String" value="&#x4e86;&#x89e3;"/>
       </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
+      </Events>
     </Component>
     <Component class="javax.swing.JCheckBox" name="jCheckBox1">
       <Properties>
         <Property name="text" type="java.lang.String" value="&#x6b21;&#x56de;&#x304b;&#x3089;&#x30a2;&#x30c3;&#x30d7;&#x30c7;&#x30fc;&#x30c8;&#x901a;&#x77e5;&#x3092;&#x884c;&#x308f;&#x306a;&#x3044;"/>
       </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jCheckBox1ActionPerformed"/>
+      </Events>
     </Component>
   </SubComponents>
 </Form>
index addd7c3..67642ee 100644 (file)
  */
 package twitter.gui.form;
 
+import java.awt.Desktop;
+import java.io.IOException;
+import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import twitter.gui.action.TweetMainAction;
+import twitter.manage.ClientVersionManager;
+import twitter.manage.VersionInfo;
+
 /**
  *
  * @author nishio
@@ -17,9 +26,27 @@ package twitter.gui.form;
 public class UpdateNotifyDialog extends javax.swing.JDialog {
 
     /** Creates new form UpdateNotifyDialog */
-    public UpdateNotifyDialog(java.awt.Frame parent, boolean modal) {
+    public UpdateNotifyDialog(java.awt.Frame parent, boolean modal, TweetMainAction mainAction) {
         super(parent, modal);
         initComponents();
+        this.mainAction = mainAction;
+        init();
+    }
+    
+    /**
+     * 初期化
+     */
+    public void init() {
+        ClientVersionManager version = ClientVersionManager.getInstance();
+        //現在のバージョン
+        this.jLabel4.setText(version.getCurrentversion());
+        latest = version.getLatestVersionInfo();
+        if( latest != null ) {
+            String newVersion = latest.getVersion();
+            this.jLabel5.setText(newVersion);
+            String log = latest.getLog();
+            jTextArea1.setText(log);
+        }
     }
 
     /** This method is called from within the constructor to
@@ -60,10 +87,25 @@ public class UpdateNotifyDialog extends javax.swing.JDialog {
         jScrollPane1.setViewportView(jTextArea1);
 
         jButton1.setText("サイトへ移動");
+        jButton1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButton1ActionPerformed(evt);
+            }
+        });
 
         jButton2.setText("了解");
+        jButton2.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButton2ActionPerformed(evt);
+            }
+        });
 
         jCheckBox1.setText("次回からアップデート通知を行わない");
+        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jCheckBox1ActionPerformed(evt);
+            }
+        });
 
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
@@ -116,49 +158,38 @@ public class UpdateNotifyDialog extends javax.swing.JDialog {
         pack();
     }// </editor-fold>//GEN-END:initComponents
 
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String args[]) {
-        /* Set the Nimbus look and feel */
-        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
-        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
-         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
-         */
+private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
+    boolean update = jCheckBox1.isSelected();
+    this.mainAction.setUpdateNotify(!update);
         try {
-            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
-                if ("Nimbus".equals(info.getName())) {
-                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
-                    break;
-                }
-            }
-        } catch (ClassNotFoundException ex) {
-            java.util.logging.Logger.getLogger(UpdateNotifyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (InstantiationException ex) {
-            java.util.logging.Logger.getLogger(UpdateNotifyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (IllegalAccessException ex) {
-            java.util.logging.Logger.getLogger(UpdateNotifyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
-            java.util.logging.Logger.getLogger(UpdateNotifyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+            this.mainAction.saveProperties();
+        } catch (IOException ex) {
+            Logger.getLogger(UpdateNotifyDialog.class.getName()).log(Level.SEVERE, null, ex);
         }
-        //</editor-fold>
-
-        /* Create and display the dialog */
-        java.awt.EventQueue.invokeLater(new Runnable() {
-
-            public void run() {
-                UpdateNotifyDialog dialog = new UpdateNotifyDialog(new javax.swing.JFrame(), true);
-                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
-
-                    @Override
-                    public void windowClosing(java.awt.event.WindowEvent e) {
-                        System.exit(0);
-                    }
-                });
-                dialog.setVisible(true);
-            }
-        });
+    this.setVisible(false);
+}//GEN-LAST:event_jButton2ActionPerformed
+
+private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
+// TODO add your handling code here:
+}//GEN-LAST:event_jCheckBox1ActionPerformed
+
+private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+    try {
+        // クリック時
+        ClientVersionManager version = ClientVersionManager.getInstance();
+        URL url = new URL( version.getNishiotweetmanagerurl() );
+        // デフォルトのブラウザを使ってリンク先を表示
+        Desktop dp = Desktop.getDesktop();
+        dp.browse(url.toURI());
+    } catch (Exception ex) {
+        ex.printStackTrace();
     }
+}//GEN-LAST:event_jButton1ActionPerformed
+
+    private TweetMainAction mainAction = null;
+    //latestVersion
+    private VersionInfo latest = null;
+    
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JButton jButton1;
     private javax.swing.JButton jButton2;
index 290c3a6..cc6b9b4 100644 (file)
@@ -94,12 +94,11 @@ public class ClientVersionManager {
         * クライアントの最新バージョンの情報を取得する\r
         * @return\r
         */\r
-       public static VersionInfo getLatestVersionInfo() {\r
-               ClientVersionManager manager = ClientVersionManager.getInstance();\r
-               String log = manager.getLatestInformation();\r
+       public VersionInfo getLatestVersionInfo() {\r
+               String log = getLatestInformation();\r
                VersionInfo info = null;\r
                try {\r
-                       info = manager.XMLToVersionInfo(log);\r
+                       info = XMLToVersionInfo(log);\r
                } catch (SAXParseException e) {\r
                        e.printStackTrace();\r
                }\r