OSDN Git Service

自分のツイートがFavられた時に通知する機能を実装 #26111
authorU-nishio-PC8\nishio <spark_xp@users.sourceforge.jp>
Wed, 31 Aug 2011 20:33:01 +0000 (05:33 +0900)
committerU-nishio-PC8\nishio <spark_xp@users.sourceforge.jp>
Wed, 31 Aug 2011 20:33:01 +0000 (05:33 +0900)
src/twitter/gui/action/TweetMainAction.java
src/twitter/gui/form/ConfigurationDialog.form
src/twitter/gui/form/ConfigurationDialog.java
src/twitter/manage/TweetFavNotifyManager.java [new file with mode: 0644]
src/twitter/manage/TweetUserStream.java
src/twitter/manage/TweetUserStreamManager.java

index dbe2f10..75227d0 100644 (file)
@@ -81,6 +81,7 @@ import twitter.gui.form.UserListDialog;
 import twitter.gui.form.UserSearchDialog;
 import twitter.log.TwitterLogManager;
 import twitter.manage.TweetConfiguration;
+import twitter.manage.TweetFavNotifyManager;
 import twitter.manage.TweetManager;
 import twitter.manage.URLBitlyConverter;
 import twitter.task.ExistTimerIDException;
@@ -199,6 +200,8 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
         private boolean isUsingStreaming = true;
        //現在streaming apiが開始されているかどうか
        private boolean isCurrentUsingStreaming = false;
+       //favられた時に通知をするかどうか
+       private boolean favNotify = true;
 
        // Tweetの詳細情報を表示する部分
        private JLabel userImageLabel = null;
@@ -352,6 +355,8 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
                mainFrame.setSize(this.mainFrameWidth, this.mainFrameHeight);
                mainFrame.setPreferredSize(new Dimension(this.mainFrameWidth,
                                this.mainFrameHeight));
+               //update通知の更新
+               updateNotifyInformation();
                
                //streaming apiの状態listener設定
                this.tweetManager.getStreamManager().addCollectionLifeCycleListener(this);
@@ -454,6 +459,16 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
                        e.printStackTrace();
                }
        }
+       
+       /**
+        * notify通知ウィンドウ情報の更新
+        */
+       public void updateNotifyInformation() {
+           //streaming api利用時、fav通知
+           if( this.favNotify ) {
+               this.tweetManager.getStreamManager().setFavNotifyManager(new TweetFavNotifyManager(this.trayIcon));
+           }
+       }
 
        /**
         * 新しいタブを追加
@@ -1973,6 +1988,11 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
                if( ius == null ) {
                    ius = this.isUsingStreaming + "";
                }
+               
+               String fav = this.property.getProperty("isFavNotify");
+               if( fav == null ) {
+                   fav = this.favNotify + "";
+               }
 
                try {
                        this.newTableColor = new Color(Integer.parseInt(ntrgb));
@@ -2009,6 +2029,9 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
                        
                        //using streaming
                        this.isUsingStreaming = Boolean.parseBoolean(ius);
+                       
+                       //fav
+                       this.favNotify = Boolean.parseBoolean(fav);
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                }
@@ -2083,6 +2106,9 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
                
                //streaming
                this.property.setProperty("isUsingStreaming", this.isUsingStreaming + "");
+               
+               //fav通知
+               this.property.setProperty("isFavNotify", this.favNotify + "");
 
                // プロパティのリストを保存
                property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
@@ -2441,4 +2467,19 @@ public class TweetMainAction implements ConnectionLifeCycleListener{
        public boolean isStartedStreamingAPI() {
            return this.isCurrentUsingStreaming;
        }
+       
+       /**
+        * Fav通知を行うかどうか
+        * @return 
+        */
+       public boolean isFavNotify() {
+           return this.favNotify;
+       }
+       
+       /**
+        * fav通知を行うかどうか設定
+        */
+       public void setFavNotify(boolean notify) {
+           this.favNotify = notify;
+       }
 }
index f8464d9..6cc5bbd 100644 (file)
                   <Group type="102" alignment="0" attributes="0">
                       <EmptySpace max="-2" attributes="0"/>
                       <Group type="103" groupAlignment="0" attributes="0">
+                          <Component id="jCheckBox3" alignment="0" pref="431" max="32767" attributes="0"/>
                           <Component id="jCheckBox1" alignment="0" pref="431" max="32767" attributes="0"/>
                           <Component id="jCheckBox2" alignment="0" pref="431" max="32767" attributes="0"/>
                           <Group type="102" alignment="0" attributes="0">
                                   <Component id="jSpinner6" alignment="0" pref="290" max="32767" attributes="0"/>
                               </Group>
                           </Group>
-                          <Component id="jCheckBox3" alignment="0" pref="431" max="32767" attributes="0"/>
+                          <Component id="jCheckBox4" alignment="0" pref="431" max="32767" attributes="0"/>
                       </Group>
                       <EmptySpace max="-2" attributes="0"/>
                   </Group>
                       <Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
                       <EmptySpace max="-2" attributes="0"/>
                       <Component id="jCheckBox2" min="-2" max="-2" attributes="0"/>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Component id="jCheckBox4" min="-2" max="-2" attributes="0"/>
                       <EmptySpace max="-2" attributes="0"/>
                       <Component id="jCheckBox3" min="-2" max="-2" attributes="0"/>
-                      <EmptySpace min="-2" pref="194" max="-2" attributes="0"/>
+                      <EmptySpace min="-2" pref="171" max="-2" attributes="0"/>
                   </Group>
               </Group>
             </DimensionLayout>
                 <Property name="text" type="java.lang.String" value="&#x30af;&#x30e9;&#x30a4;&#x30a2;&#x30f3;&#x30c8;&#x306e;&#x6700;&#x65b0;&#x60c5;&#x5831;&#x3092;&#x901a;&#x77e5;&#x3059;&#x308b;"/>
               </Properties>
             </Component>
+            <Component class="javax.swing.JCheckBox" name="jCheckBox4">
+              <Properties>
+                <Property name="text" type="java.lang.String" value="&#x81ea;&#x5206;&#x306e;&#x767a;&#x8a00;&#x304c;&#x304a;&#x6c17;&#x306b;&#x5165;&#x308a;&#x306b;&#x767b;&#x9332;&#x3055;&#x308c;&#x305f;&#x3089;&#x901a;&#x77e5;&#x3059;&#x308b;(&#x30b9;&#x30c8;&#x30ea;&#x30fc;&#x30df;&#x30f3;&#x30b0;API&#x5229;&#x7528;&#x6642;&#x306e;&#x307f;)"/>
+              </Properties>
+            </Component>
           </SubComponents>
         </Container>
       </SubComponents>
index 167420b..8dbbacc 100644 (file)
@@ -65,37 +65,38 @@ public class ConfigurationDialog extends javax.swing.JDialog {
      * 読み込んだ情報を反映
      */
     public void applyLoadInformation() {
-        try {
-            // 画面が見えたときに情報更新
-            jSpinner1.setValue( mainAction.getGetTimelinePeriod() );
-            jSpinner2.setValue( mainAction.getGetMentionPeriod() );
-            jSpinner3.setValue( mainAction.getGetDirectMessagePeriod() );
-            jSpinner4.setValue( mainAction.getGetSendDirectMessagePeriod() );
-
-                       jLabel10.setBackground(mainAction.getNewTableColor());
-
-                       // font関係
-                       if (mainAction.getTlFontName() != null) {
-                               jComboBox1.setSelectedItem(mainAction.getTlFontName());
-                       }
-                       if (mainAction.getDetailFontName() != null) {
-                               jComboBox2.setSelectedItem(mainAction.getDetailFontName());
-                       }
-                       jComboBox3.setSelectedItem(mainAction.getTlFontSize() + "");
-                       jComboBox4.setSelectedItem(mainAction.getDetailFontSize() + "");
-
-                       // 表示
-                       jSpinner5.setValue(mainAction.getTableElementHeight());
-                        jCheckBox1.setSelected( mainAction.getNotifyMention() );
-                        jCheckBox2.setSelected( mainAction.getNotifyDirectMessage() );
-                        jCheckBox3.setSelected( mainAction.isUpdateNotify() );
-                        
-                        //テーブルに表示するツイート数
-                        jSpinner6.setValue(mainAction.getTableElementMaxSize());
-            
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
+       try {
+           // 画面が見えたときに情報更新
+           jSpinner1.setValue( mainAction.getGetTimelinePeriod() );
+           jSpinner2.setValue( mainAction.getGetMentionPeriod() );
+           jSpinner3.setValue( mainAction.getGetDirectMessagePeriod() );
+           jSpinner4.setValue( mainAction.getGetSendDirectMessagePeriod() );
+           
+           jLabel10.setBackground(mainAction.getNewTableColor());
+           
+           // font関係
+           if (mainAction.getTlFontName() != null) {
+               jComboBox1.setSelectedItem(mainAction.getTlFontName());
+           }
+           if (mainAction.getDetailFontName() != null) {
+               jComboBox2.setSelectedItem(mainAction.getDetailFontName());
+           }
+           jComboBox3.setSelectedItem(mainAction.getTlFontSize() + "");
+           jComboBox4.setSelectedItem(mainAction.getDetailFontSize() + "");
+           
+           // 表示
+           jSpinner5.setValue(mainAction.getTableElementHeight());
+           jCheckBox1.setSelected( mainAction.getNotifyMention() );
+           jCheckBox2.setSelected( mainAction.getNotifyDirectMessage() );
+           jCheckBox3.setSelected( mainAction.isUpdateNotify() );
+           jCheckBox4.setSelected( mainAction.isFavNotify() );
+           
+           //テーブルに表示するツイート数
+           jSpinner6.setValue(mainAction.getTableElementMaxSize());
+           
+       } catch (Exception e) {
+           e.printStackTrace();
+       }
     }
 
     /**
@@ -149,6 +150,7 @@ public class ConfigurationDialog extends javax.swing.JDialog {
         jSpinner6 = new javax.swing.JSpinner();
         jLabel12 = new javax.swing.JLabel();
         jCheckBox3 = new javax.swing.JCheckBox();
+        jCheckBox4 = new javax.swing.JCheckBox();
         jButton1 = new javax.swing.JButton();
         jButton2 = new javax.swing.JButton();
 
@@ -373,6 +375,8 @@ public class ConfigurationDialog extends javax.swing.JDialog {
 
         jCheckBox3.setText("クライアントの最新情報を通知する");
 
+        jCheckBox4.setText("自分の発言がお気に入りに登録されたら通知する(ストリーミングAPI利用時のみ)");
+
         javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
         jPanel4.setLayout(jPanel4Layout);
         jPanel4Layout.setHorizontalGroup(
@@ -380,6 +384,7 @@ public class ConfigurationDialog extends javax.swing.JDialog {
             .addGroup(jPanel4Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(jCheckBox3, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                     .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                     .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                     .addGroup(jPanel4Layout.createSequentialGroup()
@@ -390,7 +395,7 @@ public class ConfigurationDialog extends javax.swing.JDialog {
                         .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(jSpinner5, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                             .addComponent(jSpinner6, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)))
-                    .addComponent(jCheckBox3, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE))
+                    .addComponent(jCheckBox4, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE))
                 .addContainerGap())
         );
         jPanel4Layout.setVerticalGroup(
@@ -408,9 +413,11 @@ public class ConfigurationDialog extends javax.swing.JDialog {
                 .addComponent(jCheckBox1)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jCheckBox2)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(jCheckBox4)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jCheckBox3)
-                .addGap(194, 194, 194))
+                .addGap(171, 171, 171))
         );
 
         jTabbedPane1.addTab("表示", jPanel4);
@@ -508,6 +515,9 @@ public class ConfigurationDialog extends javax.swing.JDialog {
             mainAction.setNotifyMention( jCheckBox1.isSelected() );
             mainAction.setNotifyDirectMessage( jCheckBox2.isSelected() );
             mainAction.setUpdateNotify( jCheckBox3.isSelected() );
+           //fav通知ウィンドウ変更
+           mainAction.setFavNotify( jCheckBox4.isSelected());
+           mainAction.updateNotifyInformation();
             
             //ツイート表示数
             mainAction.setTableElementMaxSize(Integer.parseInt( jSpinner6.getValue().toString() ));
@@ -601,6 +611,7 @@ private void jSpinner6StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIR
     private javax.swing.JCheckBox jCheckBox1;
     private javax.swing.JCheckBox jCheckBox2;
     private javax.swing.JCheckBox jCheckBox3;
+    private javax.swing.JCheckBox jCheckBox4;
     private javax.swing.JComboBox jComboBox1;
     private javax.swing.JComboBox jComboBox2;
     private javax.swing.JComboBox jComboBox3;
diff --git a/src/twitter/manage/TweetFavNotifyManager.java b/src/twitter/manage/TweetFavNotifyManager.java
new file mode 100644 (file)
index 0000000..f0edf33
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package twitter.manage;
+
+import java.awt.TrayIcon;
+import java.util.List;
+import twitter4j.Status;
+import twitter4j.User;
+
+/**
+ *
+ * @author nishio
+ */
+public class TweetFavNotifyManager{
+    
+    //トレイアイコン
+    protected TrayIcon trayIcon = null;
+    //タイトル
+    protected String title = "お気に入り登録情報";
+   
+    public TweetFavNotifyManager(TrayIcon trayIcon) {
+        this.trayIcon = trayIcon;
+    }
+    
+    public TweetFavNotifyManager(TrayIcon trayIcon, String title) {
+        this.trayIcon = trayIcon;
+       this.title = title;
+    }
+    
+    /**
+     * ツイート情報を通知バーに表示
+     * @param status
+     */
+    public void showNotifyMessage(User source, User target, Status favoritedStatus) {
+        if( trayIcon != null ) {
+           String message = favoritedStatus.getText();
+           if( message.length() > 80) {
+               message = message.substring(0, 80);
+               message = message + "...";
+           }
+           this.trayIcon.displayMessage(title, source.getScreenName() + "さんが、あなたの発言:\n "
+                   + message + " をお気に入りに登録しました",TrayIcon.MessageType.INFO);
+       }
+    }
+}
index 19860c5..e3153e8 100644 (file)
@@ -28,9 +28,11 @@ public class TweetUserStream extends UserStreamAdapter{
        //direct message監視\r
        private TweetStreamingListener directMessageListener = null;\r
        //mention通知\r
-    private TweetNotifyManager mentionNotifyManager = null;\r
-    //directmessage通知\r
-    private TweetNotifyManager directMessageNotifyManager = null;\r
+       private TweetNotifyManager mentionNotifyManager = null;\r
+       //directmessage通知\r
+       private TweetNotifyManager directMessageNotifyManager = null;\r
+       //fav通知を行うかどうか\r
+       private TweetFavNotifyManager favNotifyManager = null;\r
        //ログインユーザ名\r
        private String loginUsername = null;\r
        //tweet manager\r
@@ -97,6 +99,13 @@ public class TweetUserStream extends UserStreamAdapter{
        public void setMentionNotifyManager(TweetNotifyManager notifyManager) {\r
                this.mentionNotifyManager = notifyManager;\r
        }\r
+       \r
+       /**\r
+        * お気に入り登録通知\r
+        */\r
+       public void setFavNotifyManager(TweetFavNotifyManager notifyManager) {\r
+           this.favNotifyManager = notifyManager;\r
+       }\r
 \r
        /**\r
         * direct message通知バー\r
@@ -163,12 +172,17 @@ public class TweetUserStream extends UserStreamAdapter{
                }\r
        }\r
 \r
+       /**\r
+        * お気に入り登録通知\r
+        * @param source\r
+        * @param target\r
+        * @param favoritedStatus \r
+        */\r
        @Override\r
        public void onFavorite(User source, User target, Status favoritedStatus) {\r
-               /*System.out.println(source.getScreenName() + " favorited "\r
-                               + target.getScreenName() + "'s Status. StatusId: "\r
-                               + favoritedStatus.getId() );\r
-               System.out.println("FAV MESSAGE:" + favoritedStatus.getText());*/\r
+           if( favNotifyManager != null ) {\r
+               favNotifyManager.showNotifyMessage(source, target, favoritedStatus);\r
+           }\r
        }\r
 \r
        @Override\r
index 775e288..413bdf6 100644 (file)
@@ -67,6 +67,20 @@ public class TweetUserStreamManager extends UserStreamAdapter {
        public void stopDirectMessageListener() {\r
                this.userStream.setDirectMessageListener(null);\r
        }\r
+       \r
+       /**\r
+        * Favられた時に通知\r
+        */\r
+       public void setFavNotifyManager(TweetFavNotifyManager notify) {\r
+           this.userStream.setFavNotifyManager(notify);\r
+       }\r
+       \r
+       /**\r
+        * Favられた時の通知をやめる\r
+        */\r
+       public void resetFavNotifyManager() {\r
+           this.userStream.setFavNotifyManager(null);\r
+       }\r
 \r
        /**\r
         * Mentionを監視するリスナー\r