package twitter.action;
+import java.awt.TrayIcon;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import twitter.manage.TweetManager;
+import twitter.manage.TweetNotifyManager;
import twitter4j.Status;
import twitter4j.TwitterException;
//tweet管理用
private TweetManager tweetManager;
+ //通知
+ private TweetNotifyManager notifyManager = null;
+ //1回目の最初の呼び出しかどうか, 1回目の呼び出しの際は通知バーにメッセージを表示しない
+ private boolean isFirstTime = true;
/**
*
}
/**
+ *
+ * @param tweetManager
+ * @param trayIcon
+ */
+ public TweetDirectMessageGetter(TweetManager tweetManager, TrayIcon trayIcon) {
+ this.tweetManager = tweetManager;
+ this.notifyManager = new TweetNotifyManager(trayIcon, "あなた宛のダイレクトメッセージ");
+ }
+
+ /**
* DirectMessageツイートを指定した数だけ取得
* @param num
* @return
List<Status> status = null;
try {
status = tweetManager.getDirectMessages(num);
+ if( notifyManager != null && isFirstTime == false) {
+ this.notifyManager.showNotifyMessage(status);
+ }
+ isFirstTime = false;
} catch (TwitterException ex) {
Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
}
List<Status> status = null;
try {
status = tweetManager.getNewDirectMessages();
+ if( notifyManager != null && isFirstTime == false) {
+ this.notifyManager.showNotifyMessage(status);
+ }
+ isFirstTime = false;
} catch (TwitterException ex) {
Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
}
package twitter.action;
+import java.awt.TrayIcon;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import twitter.manage.TweetManager;
+import twitter.manage.TweetNotifyManager;
import twitter4j.Status;
import twitter4j.TwitterException;
//tweet管理用
private TweetManager tweetManager;
+ //通知
+ private TweetNotifyManager notifyManager = null;
+ //1回目の最初の呼び出しかどうか, 1回目の呼び出しの際は通知バーにメッセージを表示しない
+ private boolean isFirstTime = true;
/**
*
}
/**
+ *
+ * @param tweetManager
+ * @param trayIcon タスクバーの通知用アイコン
+ */
+ public TweetMentionGetter(TweetManager tweetManager, TrayIcon trayIcon) {
+ this.tweetManager = tweetManager;
+ this.notifyManager = new TweetNotifyManager(trayIcon);
+ }
+
+ /**
* Mentionツイートを指定した数だけ取得
* @param num
* @return
List<Status> status = null;
try {
status = tweetManager.getMentions(num);
+ if( notifyManager != null && isFirstTime == false) {
+ this.notifyManager.showNotifyMessage(status);
+ }
+ isFirstTime = false;
} catch (TwitterException ex) {
Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
}
List<Status> status = null;
try {
status = tweetManager.getNewMentionData();
+ if( notifyManager != null && isFirstTime == false) {
+ this.notifyManager.showNotifyMessage(status);
+ }
+ isFirstTime = false;
} catch (TwitterException ex) {
Logger.getLogger(TweetMentionGetter.class.getName()).log(Level.SEVERE, null, ex);
}
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
+import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
private JLabel tweetMessageCountLabel = null;
private int uncheckedDirectMessageCount = 0;
private int uncheckedMentionTweetCount = 0;
+ //自分宛のメッセージを通知バーに表示するか
+ private boolean isNotifyMentionMessage = true;
+ private boolean isNotifyDirectMessage = true;
//Tweetの詳細情報を表示する部分
private JLabel userImageLabel = null;
private JLabel updateLabel = null;
private JEditorPane userIntroBox = null;
private JEditorPane userWebBox = null;
+ //トレイアイコン
+ private TrayIcon trayIcon = null;
//checkbox関係
private javax.swing.JToggleButton timelineToggleButton;
JCheckBoxMenuItem timelineCheckBoxMenuItem,
JCheckBoxMenuItem mentionCheckBoxMenuItem,
JCheckBoxMenuItem dmCheckBoxMenuItem,
- JCheckBoxMenuItem sendCheckBoxMenuItem) {
+ JCheckBoxMenuItem sendCheckBoxMenuItem,
+ TrayIcon trayIcon) {
this.mainFrame = mainFrame;
this.tweetManager = tweetManager;
this.statusBarLabel = statusBarLabel;
this.sendCheckBoxMenuItem = sendCheckBoxMenuItem;
this.sendDMToggleButton = sendToggleButton;
+ //トレイアイコン
+ this.trayIcon = trayIcon;
+
//罰ボタンを押した時のイベントを追加
if( this.tweetMainTab instanceof DnDTabbedPane ) {
((DnDTabbedPane)this.tweetMainTab).setMainAction(this);
//既にIDが存在していたらここで例外発生
timerID.addID(id);
//検索結果を表示するタブを生成
- actionAddTab(id, period, new TweetMentionGetter(tweetManager),
- TweetMainAction.TAB_MENTION_STRING);
+ if( this.isNotifyMentionMessage ) {
+ //メッセージが到着したら通知を行う
+ actionAddTab(id, period, new TweetMentionGetter(tweetManager, this.trayIcon),
+ TweetMainAction.TAB_MENTION_STRING);
+ }else {
+ actionAddTab(id, period, new TweetMentionGetter(tweetManager),
+ TweetMainAction.TAB_MENTION_STRING);
+ }
} catch (ExistTimerIDException ex) {
JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
"Error", JOptionPane.ERROR_MESSAGE);
//既にIDが存在していたらここで例外発生
timerID.addID(id);
//検索結果を表示するタブを生成
- actionAddTab(id, period, new TweetDirectMessageGetter(tweetManager),
- TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
+ if( this.isNotifyDirectMessage == true ) {
+ actionAddTab(id, period, new TweetDirectMessageGetter(tweetManager, this.trayIcon),
+ TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
+ }else {
+ actionAddTab(id, period, new TweetDirectMessageGetter(tweetManager),
+ TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
+ }
} catch (ExistTimerIDException ex) {
JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
"Error", JOptionPane.ERROR_MESSAGE);
String mfw = this.property.getProperty("mainFrameWidth");
String mfh = this.property.getProperty("mainFrameHeight");
+ //メッセージ通知を行うか
+ String nm = this.property.getProperty("notifyMessage");
+ String ndm = this.property.getProperty("notifyDirectMessage");
+
try {
this.newTableColor = new Color(Integer.parseInt(ntrgb));
this.tlFontSize = Integer.parseInt(tfs);
this.getMentionPeriod = Integer.parseInt(gmp);
this.getDirectMessagePeriod = Integer.parseInt(gdmp);
this.getSendDirectMessagePeriod = Integer.parseInt(gsdmp);
+
+ //通知関係
+ this.isNotifyMentionMessage = Boolean.parseBoolean(nm);
+ this.isNotifyMentionMessage = Boolean.parseBoolean(ndm);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
this.property.setProperty("mainFrameWidth", this.mainFrameWidth + "");
this.property.setProperty("mainFrameHeight", this.mainFrameHeight + "");
+
+ //メッセージ通知を行うか
+ this.property.setProperty("notifyMention", this.isNotifyMentionMessage + "");
+ this.property.setProperty("notifyDirectMessage", this.isNotifyDirectMessage + "");
+
// プロパティのリストを保存
property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
+ BASIC_SETTING_FILENAME), null);
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane9" min="-2" pref="53" max="-2" attributes="0"/>
- <EmptySpace max="32767" attributes="0"/>
+ <EmptySpace pref="29" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
userNameLabel, updateTimeLabel, followerLabel, followingLabel, locationLabel,
clientNameLabel, updateLabel, userIntroBox, userWebBox,
jToggleButton3, jToggleButton4, jToggleButton5, jToggleButton6,
- jCheckBoxMenuItem3,jCheckBoxMenuItem4, jCheckBoxMenuItem5, jCheckBoxMenuItem6);
+ jCheckBoxMenuItem3,jCheckBoxMenuItem4, jCheckBoxMenuItem5, jCheckBoxMenuItem6, trayIcon);
//ハッシュタグ用のハイパーリンクリスナーにアクション登録
this.hashTagHyperlinkListener.setMainAction(mainAction);
//もしログインに失敗したら,アカウント設定画面を出す
--- /dev/null
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package twitter.manage;
+
+import java.awt.SystemTray;
+import java.awt.TrayIcon;
+import java.util.List;
+import twitter4j.Status;
+
+/**
+ * 通知すべきメッセージの管理を行う
+ * @author nishio
+ */
+public class TweetNotifyManager {
+
+ //トレイアイコン
+ private TrayIcon trayIcon = null;
+ //タイトル
+ private String title = "あなた宛のメッセージ";
+
+ /**
+ *
+ * @param trayIcon
+ */
+ public TweetNotifyManager(TrayIcon trayIcon) {
+ this.trayIcon = trayIcon;
+ }
+
+ public TweetNotifyManager(TrayIcon trayIcon, String title) {
+ this.trayIcon = trayIcon;
+ this.title = title;
+ }
+
+ /**
+ * ツイート情報を通知バーに表示
+ * @param status
+ */
+ public void showNotifyMessage(List<Status> status) {
+ for(Status s : status) {
+ if( s.getUser() == null ) {
+ String message = s.getText();
+ this.trayIcon.displayMessage(title, message,TrayIcon.MessageType.INFO);
+ }else {
+ String name = s.getUser().getScreenName();
+ String message = s.getText();
+ this.trayIcon.displayMessage(title, name + "さんの発言: " + message, TrayIcon.MessageType.INFO);
+ }
+ }
+ }
+
+}