OSDN Git Service

お気に入りに追加,削除機能を実装.
authorspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Fri, 17 Sep 2010 15:04:26 +0000 (15:04 +0000)
committerspark_xp <spark_xp@d8c9ecd3-d47d-4367-8645-de82c00e513f>
Fri, 17 Sep 2010 15:04:26 +0000 (15:04 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/nt-manager/NishioTweetManager/trunk@61 d8c9ecd3-d47d-4367-8645-de82c00e513f

src/twitter/gui/action/TweetMainAction.java
src/twitter/gui/component/TweetTabbedTable.java
src/twitter/manage/TweetManager.java

index 1df8100..127f494 100644 (file)
@@ -756,6 +756,76 @@ public class TweetMainAction {
     }
 
     /**
+     * 選択しているツイートをお気に入りに追加
+     */
+    public void actionCreateFavorite() {
+        Status status = null;
+        if( this.getCurrentStatus().isRetweet() ) {
+            status = this.getCurrentStatus().getRetweetedStatus();
+        }else {
+            status = this.getCurrentStatus();
+        }
+        // 選択しているtweetのstatus id
+        long statusID = status.getId();
+        // コメントしたユーザ名
+        String username = status.getUser().getScreenName();
+        // コメント
+        String message = status.getText();
+        // 発言が長すぎる場合,後半をカット
+        if (message.length() > 30) {
+            message = message.substring(0, 30) + " ...(以下略)";
+        }
+        // Retweetしていいかどうかの確認
+        int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
+                + message + "\nをお気に入りに追加しますか?", "Favの確認",
+                JOptionPane.YES_NO_OPTION);
+        if (ret == JOptionPane.YES_OPTION) {
+            try {
+                // Retweetを行う
+                this.tweetManager.createFavorite(statusID);
+            } catch (TwitterException e) {
+                JOptionPane.showMessageDialog(null, "エラーによりお気に入りに追加できませんでした.",
+                        "Fav Error", JOptionPane.ERROR_MESSAGE);
+            }
+        }
+    }
+
+    /**
+     * 選択しているツイートをお気に入りから外す
+     */
+    public void actionDestroyFavorite() {
+        Status status = null;
+        if( this.getCurrentStatus().isRetweet() ) {
+            status = this.getCurrentStatus().getRetweetedStatus();
+        }else {
+            status = this.getCurrentStatus();
+        }
+        // 選択しているtweetのstatus id
+        long statusID = status.getId();
+        // コメントしたユーザ名
+        String username = status.getUser().getScreenName();
+        // コメント
+        String message = status.getText();
+        // 発言が長すぎる場合,後半をカット
+        if (message.length() > 30) {
+            message = message.substring(0, 30) + " ...(以下略)";
+        }
+        // Retweetしていいかどうかの確認
+        int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
+                + message + "\nをお気に入りから削除しますか?", "Favの確認",
+                JOptionPane.YES_NO_OPTION);
+        if (ret == JOptionPane.YES_OPTION) {
+            try {
+                // Retweetを行う
+                this.tweetManager.destroyFavorite(statusID);
+            } catch (TwitterException e) {
+                JOptionPane.showMessageDialog(null, "エラーによりお気に入りから削除できませんでした.",
+                        "Fav Error", JOptionPane.ERROR_MESSAGE);
+            }
+        }
+    }
+
+    /**
      * 現在選択しているステータスを公式Retweet
      */
     public void actionRetweet() {
index a99024a..db663a3 100644 (file)
@@ -288,7 +288,7 @@ public class TweetTabbedTable {
         //if (rightClickPopup == null) {
         JPopupMenu rightClickPopup = new JPopupMenu();
 
-        JMenuItem replyMenuItem = new JMenuItem("この発言に返信する(Reply)");
+        JMenuItem replyMenuItem = new JMenuItem("この発言に返信(Reply)");
         replyMenuItem.addActionListener(new java.awt.event.ActionListener() {
 
             public void actionPerformed(java.awt.event.ActionEvent e) {
@@ -357,6 +357,29 @@ public class TweetTabbedTable {
                 mainAction.actionOpenUserURL();
             }
         });
+        
+        JMenuItem createFavMenuItem = new JMenuItem(
+                "この発言をお気に入りに追加");
+        createFavMenuItem.addActionListener(new java.awt.event.ActionListener() {
+
+            @Override
+            public void actionPerformed(java.awt.event.ActionEvent e) {
+                // 選択したセルのユーザ情報をブラウザで開く
+                mainAction.actionCreateFavorite();
+            }
+        });
+
+        JMenuItem destroyFavMenuItem = new JMenuItem(
+                "この発言をお気に入りから削除");
+        destroyFavMenuItem.addActionListener(new java.awt.event.ActionListener() {
+
+            @Override
+            public void actionPerformed(java.awt.event.ActionEvent e) {
+                // 選択したセルのユーザ情報をブラウザで開く
+                mainAction.actionDestroyFavorite();
+            }
+        });
+
 
         //指定した発言がRTかどうか判定
         int sc = table.getSelectedRowCount();
@@ -384,6 +407,10 @@ public class TweetTabbedTable {
             }
             if( st.isFavorited() ) {
                 //お気に入りに追加されている時のみ表示するメニュー
+                //お気に入り追加
+                rightClickPopup.add(destroyFavMenuItem);
+            }else {
+                rightClickPopup.add(createFavMenuItem);
             }
         }
         //}
index bbf2497..832ea24 100644 (file)
@@ -823,6 +823,23 @@ public class TweetManager {
     }
 
     /**
+     * 指定した発言をお気に入りに追加
+     * @param statusID
+     * @throws TwitterException
+     */
+    public void createFavorite(long statusID) throws TwitterException {
+        twitter.createFavorite(statusID);
+    }
+
+    /**
+     * 指定した発言のお気に入りを取り下げる
+     * @param statusID
+     */
+    public void destroyFavorite(long statusID) throws TwitterException {
+        twitter.destroyFavorite(statusID);
+    }
+
+    /**
      * API制限数を取得
      *
      * @return