1 package twitter.gui.action;
4 import java.awt.Desktop;
5 import java.awt.Dimension;
8 import java.awt.TrayIcon;
9 import java.awt.event.ActionEvent;
11 import java.io.FileInputStream;
12 import java.io.FileNotFoundException;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.UnsupportedEncodingException;
18 import java.net.URLEncoder;
19 import java.text.DateFormat;
20 import java.util.ArrayList;
21 import java.util.BitSet;
22 import java.util.Comparator;
23 import java.util.List;
24 import java.util.Locale;
25 import java.util.Properties;
27 import java.util.TreeSet;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern;
32 import javax.swing.ImageIcon;
33 import javax.swing.JCheckBoxMenuItem;
35 import javax.swing.JEditorPane;
36 import javax.swing.JFrame;
37 import javax.swing.JLabel;
38 import javax.swing.JOptionPane;
39 import javax.swing.JPanel;
40 import javax.swing.JTabbedPane;
41 import javax.swing.JTable;
42 import javax.swing.JTextPane;
43 import javax.swing.JToggleButton;
44 import javax.swing.table.TableModel;
45 import javax.swing.text.Style;
46 import javax.swing.text.StyleConstants;
47 import javax.swing.text.html.HTMLDocument;
48 import javax.swing.text.html.StyleSheet;
50 import org.xml.sax.SAXParseException;
52 import twitter.action.TweetDirectMessageGetter;
53 import twitter.action.TweetFavoriteGetter;
54 import twitter.action.TweetGetter;
55 import twitter.action.TweetListGetter;
56 import twitter.action.TweetMentionGetter;
57 import twitter.action.TweetSearchResultGetter;
58 import twitter.action.TweetSendDirectMessageGetter;
59 import twitter.action.TweetTimelineGetter;
60 import twitter.action.TweetUserTimelineGetter;
61 import twitter.action.list.ListGetterSelection;
62 import twitter.action.list.UserListGetter;
63 import twitter.action.list.UserListMembershipsGetter;
64 import twitter.action.list.UserListSpecificUserListsGetter;
65 import twitter.action.list.UserListSubscriptionGetter;
66 import twitter.cache.TwitterImageCache;
67 import twitter.gui.component.DnDTabbedPane;
69 import twitter.gui.component.TweetTabbedTable;
70 import twitter.gui.component.TweetTableModel;
71 import twitter.gui.form.AboutDialog;
72 import twitter.gui.form.AccountDialog;
73 import twitter.gui.form.ConfigurationDialog;
74 import twitter.gui.form.DirectMessageDialog;
75 import twitter.gui.form.FollowingFollowerDialog;
76 import twitter.gui.form.HashtagSearchDialog;
77 import twitter.gui.form.KeywordSearchDialog;
78 import twitter.gui.form.OutputCSVLogDialog;
79 import twitter.gui.form.UpdateNotifyDialog;
80 import twitter.gui.form.UserListDialog;
81 import twitter.gui.form.UserSearchDialog;
82 import twitter.log.TwitterLogManager;
83 import twitter.manage.TweetConfiguration;
84 import twitter.manage.TweetFavNotifyManager;
85 import twitter.manage.TweetManager;
86 import twitter.manage.URLBitlyConverter;
87 import twitter.task.ExistTimerIDException;
88 import twitter.task.TimerID;
89 import twitter.task.TweetTaskException;
90 import twitter.task.TweetTaskManager;
91 import twitter.task.TweetUpdateTask;
92 import twitter.util.HTMLEncode;
93 import twitter4j.ConnectionLifeCycleListener;
94 import twitter4j.Status;
95 import twitter4j.TwitterException;
96 import twitter4j.User;
104 public class TweetMainAction implements ConnectionLifeCycleListener{
107 public static final String BASIC_SETTING_FILENAME = TweetConfiguration.BASIC_SETTING_FILENAME;
109 private static final Pattern convURLLinkPtn = Pattern.compile(
110 "(http://|https://){1}[\\w\\.\\-/:\\#\\?\\=\\&\\;\\%\\~\\+]+",
111 Pattern.CASE_INSENSITIVE);
112 // default char encoding
113 private static final String DEFAULT_CHARACTER_ENCODING = "UTF-8";
114 // 設定ファイルを保存するディレクトリ名
115 public static final String PROPERTIES_DIRECTORY = "properties";
116 // search twitterのクエリ
117 private static final String SEARCH_QUERY = "search?q=";
118 // search twitterのURL
119 private static final String SEARCH_TWITTER_URL = "http://"
120 + TweetConfiguration.SEARCH_TWITTER_HOSTNAME + "/";
121 // Direct Messageタブに表示する文字
122 public static final String TAB_DIRECT_MESSAGE_STRING = "Message";
124 public static final String TAB_MENTION_STRING = "Mention";
126 public static final String TAB_TIMELINE_STRING = "Timeline";
127 // Send Direct Messageタブに表示する文字
128 public static final String TAB_SEND_DIRECT_MESSAGE_STRING = "Send";
129 // テーブルのデータ量が以下の値を超えたら古いデータから削除
130 private static int tableElementMaxSize = 200;
132 private static final String TWITTER_URL = "http://twitter.com/";
134 private ConfigurationDialog configurationDialog = null;
136 private Status currentStatus = null;
138 private Status replyStatus = null;
140 private JPanel detailInfoPanel = null;
141 // ダイレクトメッセージ送信用ダイアログ
142 private DirectMessageDialog directMessageDialog = null;
143 // Twitter全体からキーワード検索ダイアログ
144 private KeywordSearchDialog keywordSearchDialog = null;
145 // hashtag search dialog
146 private HashtagSearchDialog hashtagSearchDialog = null;
148 private Color newTableColor = new Color(230,230,250);
150 private String tlFontName = "MS Pゴシック";
152 private int tlFontSize = 12;
154 private String detailFontName = "MS Pゴシック";
156 private int detailFontSize = 12;
158 private int tableElementHeight = 40;
160 private int mainFrameWidth = 729;
162 private int mainFrameHeight = 629;
164 private JFrame mainFrame = null;
166 private Properties property = null;
167 // 現在テーブルで選択しているユーザ画像のURL
168 private URL selectedUserImageURL = null;
169 // 現在テーブルで選択しているユーザの名前
170 private String selectedUsername = null;
172 private JLabel statusBarLabel = null;
174 private JTextPane tweetBoxPane = null;
175 // 自分がつぶやきを書く領域のスクロールペーン
176 private JPanel tweetBoxRegionPane = null;
178 private JTabbedPane tweetMainTab = null;
180 private TweetManager tweetManager = null;
181 // tweetを表示するTextPane
182 private JEditorPane tweetMessageBox = null;
183 // つぶやくことができる文字数を表示するラベル
184 private JLabel tweetMessageCountLabel = null;
185 private int uncheckedDirectMessageCount = 0;
186 private int uncheckedMentionTweetCount = 0;
187 // 自分宛のメッセージを通知バーに表示するか
188 private boolean isNotifyMentionMessage = true;
189 private boolean isNotifyDirectMessage = true;
190 //前回開いていたタブの情報を復活する際に利用する(最初の一回だけ利用)
191 private boolean isTempOpenedTimelineTab = true;
192 private boolean isTempOpenedMentionTab = true;
193 private boolean isTempOpenedDMTab = true;
194 private boolean isTempOpenedSendDMTab = true;
196 private boolean saveLog = false;
198 private boolean isUpdateNotify = true;
199 //streaming apiを利用するかどうか
200 private boolean isUsingStreaming = true;
201 //現在streaming apiが開始されているかどうか
202 private boolean isCurrentUsingStreaming = false;
204 private boolean favNotify = true;
207 private JLabel userImageLabel = null;
208 private JLabel userNameLabel = null;
209 private JLabel updateTimeLabel = null;
210 private JLabel followerLabel = null;
211 private JLabel followingLabel = null;
212 private JLabel locationLabel = null;
213 private JEditorPane clientNameLabel = null;
214 private JLabel updateLabel = null;
215 private JEditorPane userIntroBox = null;
216 private JEditorPane userWebBox = null;
218 private TrayIcon trayIcon = null;
221 private javax.swing.JToggleButton timelineToggleButton;
222 private javax.swing.JToggleButton mentionToggleButton;
223 private javax.swing.JToggleButton dmToggleButton;
224 private javax.swing.JToggleButton sendDMToggleButton;
226 private javax.swing.JCheckBoxMenuItem timelineCheckBoxMenuItem;
227 private javax.swing.JCheckBoxMenuItem mentionCheckBoxMenuItem;
228 private javax.swing.JCheckBoxMenuItem dmCheckBoxMenuItem;
229 private javax.swing.JCheckBoxMenuItem sendCheckBoxMenuItem;
231 // 新しく取得したtweetでまだ参照していない数
232 private int uncheckedTimelineTweetCount = 0;
233 private AboutDialog aboutDialog = null;
235 private UpdateNotifyDialog updateDialog = null;
237 private AccountDialog accountDialog;
239 private List<TweetTabbedTable> tweetTabbedTableList = new ArrayList<TweetTabbedTable>();
240 // ツイートテーブルの情報を一定間隔で更新するクラスを作成
241 private TweetTaskManager tweetTaskManager = new TweetTaskManager();
244 private UserListDialog userListDialog = null;
246 private UserSearchDialog userSearchDialog = null;
248 private OutputCSVLogDialog outputCSVLogDialog = null;
249 //following follower表示ダイアログ
250 private FollowingFollowerDialog followingFollowerDialog = null;
253 private int getTimelinePeriod = 60;
254 private int getMentionPeriod = 60 * 3;
255 private int getDirectMessagePeriod = 60 * 15;
256 private int getSendDirectMessagePeriod = 60 * 30;
261 * @param tweetManager
262 * @param statusBarLabel
263 * @param tweetTableModel
264 * @param mentionTableModel
265 * @param directMessageTableModel
266 * @param sendDirectMessageTableModel
267 * @param mainTweetTable
268 * @param mentionTable
269 * @param directMessageTable
270 * @param sendDirectMessageTable
271 * @param tweetBoxPane
272 * @param tweetBoxScrollPane
273 * @param tweetMessageCountLabel
274 * @param detailInfoPanel
275 * @param tweetMainTab
276 * @param tweetMessageBox
277 * @param userImageLabel
278 * @param userNameLabel
279 * @param updateTimeLabel
280 * @param followerLabel
281 * @param followingLabel
282 * @param locationLabel
283 * @param clientNameLabel
285 * @param userIntroBox
288 public TweetMainAction(JFrame mainFrame, TweetManager tweetManager,
289 JLabel statusBarLabel, JTextPane tweetBoxPane,
290 JPanel tweetBoxScrollPane, JLabel tweetMessageCountLabel,
291 JPanel detailInfoPanel, JTabbedPane tweetMainTab,
292 JEditorPane tweetMessageBox, JLabel userImageLabel,
293 JLabel userNameLabel, JLabel updateTimeLabel, JLabel followerLabel,
294 JLabel followingLabel, JLabel locationLabel,
295 JEditorPane clientNameLabel, JLabel updateLabel,
296 JEditorPane userIntroBox, JEditorPane userWebBox,
297 JToggleButton timelineToggleButton,
298 JToggleButton mentionToggleButton, JToggleButton dmToggleButton,
299 JToggleButton sendToggleButton,
300 JCheckBoxMenuItem timelineCheckBoxMenuItem,
301 JCheckBoxMenuItem mentionCheckBoxMenuItem,
302 JCheckBoxMenuItem dmCheckBoxMenuItem,
303 JCheckBoxMenuItem sendCheckBoxMenuItem, TrayIcon trayIcon) {
304 this.mainFrame = mainFrame;
305 this.tweetManager = tweetManager;
306 this.statusBarLabel = statusBarLabel;
307 this.tweetBoxPane = tweetBoxPane;
308 this.tweetMessageCountLabel = tweetMessageCountLabel;
309 this.detailInfoPanel = detailInfoPanel;
310 this.tweetMainTab = tweetMainTab;
311 this.tweetMessageBox = tweetMessageBox;
312 this.tweetBoxRegionPane = tweetBoxScrollPane;
315 this.userImageLabel = userImageLabel;
316 this.userNameLabel = userNameLabel;
317 this.updateTimeLabel = updateTimeLabel;
318 this.userIntroBox = userIntroBox;
319 this.followerLabel = followerLabel;
320 this.followingLabel = followingLabel;
321 this.locationLabel = locationLabel;
322 this.userWebBox = userWebBox;
323 this.clientNameLabel = clientNameLabel;
324 this.updateLabel = updateLabel;
326 this.timelineCheckBoxMenuItem = timelineCheckBoxMenuItem;
327 this.timelineToggleButton = timelineToggleButton;
328 this.mentionCheckBoxMenuItem = mentionCheckBoxMenuItem;
329 this.mentionToggleButton = mentionToggleButton;
330 this.dmCheckBoxMenuItem = dmCheckBoxMenuItem;
331 this.dmToggleButton = dmToggleButton;
332 this.sendCheckBoxMenuItem = sendCheckBoxMenuItem;
333 this.sendDMToggleButton = sendToggleButton;
336 this.trayIcon = trayIcon;
339 if (this.tweetMainTab instanceof DnDTabbedPane) {
340 ((DnDTabbedPane) this.tweetMainTab).setMainAction(this);
346 } catch (FileNotFoundException e) {
348 } catch (IOException e) {
352 updateFontInformationToComponent();
355 mainFrame.setSize(this.mainFrameWidth, this.mainFrameHeight);
356 mainFrame.setPreferredSize(new Dimension(this.mainFrameWidth,
357 this.mainFrameHeight));
359 updateNotifyInformation();
361 //streaming apiの状態listener設定
362 this.tweetManager.getStreamManager().addCollectionLifeCycleListener(this);
368 public void updateCheckboxInformation() {
369 boolean timeline = this.isExistTimelineTab();
370 boolean mention = this.isExistMentionTab();
371 boolean dm = this.isExistDirectMessageTab();
372 boolean send = this.isExistSendDirectMessageTab();
374 this.timelineCheckBoxMenuItem.setSelected(timeline);
375 this.timelineToggleButton.setSelected(timeline);
376 this.mentionCheckBoxMenuItem.setSelected(mention);
377 this.mentionToggleButton.setSelected(mention);
378 this.dmCheckBoxMenuItem.setSelected(dm);
379 this.dmToggleButton.setSelected(dm);
380 this.sendCheckBoxMenuItem.setSelected(send);
381 this.sendDMToggleButton.setSelected(send);
385 * Timeline, Mention , DM, SendDMの情報更新間隔を取得し,その情報をテーブルに反映
387 public void updatePeriodInformationToComponent() {
388 // すべてのテーブルにフォント情報を反映
389 for (TweetTabbedTable t : this.tweetTabbedTableList) {
390 String timerID = t.getTimerID();
391 if (timerID.equals(TimerID.createTimelineID())) {
393 if( isCurrentUsingStreaming ) {
394 //streaming api利用時は定期的に情報更新を行わない
395 //更新時間をとてつもなく伸ばすことで対応することにした
396 this.tweetTaskManager.updateTaskPeriod(timerID, 100000, false);
398 this.tweetTaskManager.updateTaskPeriod(timerID, this
399 .getGetTimelinePeriod(), false);
401 } else if (timerID.equals(TimerID.createMentionID())) {
403 if( isCurrentUsingStreaming ) {
404 this.tweetTaskManager.updateTaskPeriod(timerID, 100000, false);
406 this.tweetTaskManager.updateTaskPeriod(timerID, this
407 .getGetMentionPeriod(), false);
409 } else if (timerID.equals(TimerID.createDirectMessageID())) {
410 if( isCurrentUsingStreaming ) {
411 this.tweetTaskManager.updateTaskPeriod(timerID, 100000, false);
414 this.tweetTaskManager.updateTaskPeriod(timerID, this
415 .getGetDirectMessagePeriod(), false);
417 } else if (timerID.equals(TimerID.createSendDirectMessageID())) {
419 this.tweetTaskManager.updateTaskPeriod(timerID, this
420 .getGetSendDirectMessagePeriod(), false);
426 public void updateFontInformationToComponent() {
429 if (this.tlFontName != null) {
430 tlFont = new Font(this.tlFontName, Font.PLAIN, this.tlFontSize);
432 Font detailFont = null;
433 if (this.detailFontName != null) {
434 detailFont = new Font(this.detailFontName, Font.PLAIN,
435 this.detailFontSize);
438 // すべてのテーブルにフォント情報を反映
439 for (TweetTabbedTable t : this.tweetTabbedTableList) {
440 t.getTable().setFont(tlFont);
443 // tweetメッセージボックスのフォントはhtmlレベルで変更する必要がある
444 this.tweetMessageBox.setFont(detailFont);
446 HTMLDocument doc = (HTMLDocument) this.tweetMessageBox
448 StyleSheet[] style = doc.getStyleSheet().getStyleSheets();
449 for (int i = style.length - 1; i >= 0; i--) {
450 Style body = style[i].getStyle("body");
453 .setFontFamily(body, detailFont.getFontName());
454 StyleConstants.setFontSize(body, detailFont.getSize());
458 } catch (Exception e) {
466 public void updateNotifyInformation() {
467 //streaming api利用時、fav通知
468 if( this.favNotify ) {
469 this.tweetManager.getStreamManager().setFavNotifyManager(new TweetFavNotifyManager(this.trayIcon));
477 * TimerIDクラスで生成したタイマーID
485 public void actionAddTab(String timerID, int period,
486 TweetGetter tweetGetter, String tabTitle) {
491 final TweetTabbedTable table = new TweetTabbedTable(
492 tweetGetter, tabTitle, this.tweetMainTab,
493 this.tweetManager, this,
494 this.tableElementMaxSize, timerID);
496 this.tweetTaskManager.addTask(timerID, new TweetUpdateTask() {
499 public void runTask() throws TweetTaskException {
501 table.updateTweetTable();
505 this.tweetTaskManager.startTask(timerID, period * 1000L);
508 table.addTableToTab();
510 this.tweetTabbedTableList.add(table);
512 this.saveProperties();
513 // searchTable.updateTweetTable();
515 this.actionRequestForusToLastTab();
516 } catch (TweetTaskException ex) {
517 Logger.getLogger(TweetMainAction.class.getName()).log(
518 Level.SEVERE, null, ex);
519 } catch (IOException e) {
525 this.updateFontInformationToComponent();
527 this.updateTableHeight(this.getTableElementHeight());
536 public void actionAddMentionTab(int period) {
537 TimerID timerID = TimerID.getInstance();
538 String id = TimerID.createMentionID();
540 // 既にIDが存在していたらここで例外発生
543 if (this.isNotifyMentionMessage) {
545 actionAddTab(id, period, new TweetMentionGetter(tweetManager,
546 this.trayIcon), TweetMainAction.TAB_MENTION_STRING);
548 actionAddTab(id, period, new TweetMentionGetter(tweetManager),
549 TweetMainAction.TAB_MENTION_STRING);
551 } catch (ExistTimerIDException ex) {
552 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
553 JOptionPane.ERROR_MESSAGE);
561 * nullで自分自身を取得,指定するとscreenNameのFav取得
563 public void actionAddFavoriteTab(String screenName) {
564 TimerID timerID = TimerID.getInstance();
565 String id = TimerID.createFavoriteID(screenName);
567 // 既にIDが存在していたらここで例外発生
570 if (screenName == null) {
573 favTitle = screenName + "のお気に入り";
576 actionAddTab(id, Integer.MAX_VALUE, new TweetFavoriteGetter(
577 tweetManager, screenName), favTitle);
578 } catch (ExistTimerIDException ex) {
579 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
580 JOptionPane.ERROR_MESSAGE);
590 public void actionAddTimelineTab(int period) {
591 TimerID timerID = TimerID.getInstance();
592 String id = TimerID.createTimelineID();
594 // 既にIDが存在していたらここで例外発生
597 actionAddTab(id, period, new TweetTimelineGetter(tweetManager, this),
598 TweetMainAction.TAB_TIMELINE_STRING);
599 } catch (ExistTimerIDException ex) {
600 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
601 JOptionPane.ERROR_MESSAGE);
611 public void actionAddDirectMessageTab(int period) {
612 TimerID timerID = TimerID.getInstance();
613 String id = TimerID.createDirectMessageID();
615 // 既にIDが存在していたらここで例外発生
618 if (this.isNotifyDirectMessage == true) {
619 actionAddTab(id, period, new TweetDirectMessageGetter(
620 tweetManager, this.trayIcon),
621 TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
623 actionAddTab(id, period, new TweetDirectMessageGetter(
625 TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
627 } catch (ExistTimerIDException ex) {
628 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
629 JOptionPane.ERROR_MESSAGE);
638 public void actionAddSendDirectMessageTab(int period) {
639 TimerID timerID = TimerID.getInstance();
640 String id = TimerID.createSendDirectMessageID();
642 // 既にIDが存在していたらここで例外発生
645 actionAddTab(id, period, new TweetSendDirectMessageGetter(
647 TweetMainAction.TAB_SEND_DIRECT_MESSAGE_STRING);
648 } catch (ExistTimerIDException ex) {
649 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
650 JOptionPane.ERROR_MESSAGE);
659 * @param listFullname
662 public void actionAddListTab(String username, int listID,
663 String listFullname, int period) {
664 TimerID timerID = TimerID.getInstance();
665 String id = TimerID.createUserListID(username, listID);
667 // 既にIDが存在していたらここで例外発生
670 actionAddTab(id, period, new TweetListGetter(tweetManager,
671 username, listID), listFullname);
672 } catch (ExistTimerIDException ex) {
673 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
674 JOptionPane.ERROR_MESSAGE);
679 * ツイート検索結果を表示するタブを新しく追加
683 * 更新周期[sec] 0以下の場合は更新しない
685 public void actionAddNewSearchResultTab(String searchWord, int period) {
686 TimerID timerID = TimerID.getInstance();
687 String id = TimerID.createSearchTimerID(searchWord);
689 // 既にIDが存在していたらここで例外発生
692 actionAddTab(id, period, new TweetSearchResultGetter(
693 this.tweetManager, searchWord), searchWord);
694 } catch (ExistTimerIDException ex) {
695 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
696 JOptionPane.ERROR_MESSAGE);
708 public void actionAddUserTimelineTab(String username,
710 TimerID timerID = TimerID.getInstance();
711 String id = TimerID.createUserTimelineID(username);
713 // 既にIDが存在していたらここで例外発生
716 actionAddTab(id, period, new TweetUserTimelineGetter(tweetManager,
717 username), username + "の発言");
718 } catch (ExistTimerIDException ex) {
719 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
720 JOptionPane.ERROR_MESSAGE);
729 public boolean isExistTimelineTab() {
730 TimerID timerID = TimerID.getInstance();
731 String id = TimerID.createTimelineID();
732 return timerID.contains(id);
740 public boolean isExistMentionTab() {
741 TimerID timerID = TimerID.getInstance();
742 String id = TimerID.createMentionID();
743 return timerID.contains(id);
751 public boolean isExistDirectMessageTab() {
752 TimerID timerID = TimerID.getInstance();
753 String id = TimerID.createDirectMessageID();
754 return timerID.contains(id);
762 public boolean isExistSendDirectMessageTab() {
763 TimerID timerID = TimerID.getInstance();
764 String id = TimerID.createSendDirectMessageID();
765 return timerID.contains(id);
771 public void actionBasicSettingDialog() {
772 // ダイレクトメッセージ送信用ダイアログを開く
773 Point loc = getConfigurationDialog().getLocation();
774 loc.translate(20, 20);
775 ConfigurationDialog dialog = getConfigurationDialog();
776 dialog.setLocation(loc);
777 dialog.setVisible(true);
783 public void actionSetReplyStatusToTweetBoxPane() {
785 this.setReplyStatus(currentStatus);
787 Status s = this.getCurrentStatus();
789 s = s.getRetweetedStatus();
792 String username = s.getUser().getScreenName();
793 this.tweetBoxPane.setText("@" + username + " ");
796 this.information(username + "さんに返信");
802 public void actionSetReplyAllStatusToTweetBoxPane() {
804 this.setReplyStatus(null);
806 Status s = this.getCurrentStatus();
808 s = s.getRetweetedStatus();
811 String username = s.getUser().getScreenName();
812 this.tweetBoxPane.setText("@" + username + " ");
815 this.information(username + "さんに返信");
821 public void actionSetQuoteStatusToTweetBoxPane() {
823 this.setReplyStatus(currentStatus);
824 Status s = this.getCurrentStatus();
826 s = s.getRetweetedStatus();
829 String username = s.getUser().getScreenName();
831 String message = s.getText();
832 this.tweetBoxPane.setText("QT @" + username + ": " + message);
835 this.information(username + "さんのメッセージを引用ツイート");
841 public void actionCopySelectedStatusToTweetBoxPane() {
842 Status s = this.getCurrentStatus();
844 s = s.getRetweetedStatus();
847 String username = s.getUser().getScreenName();
849 String message = s.getText();
850 this.tweetBoxPane.setText("RT @" + username + ": " + message);
858 public void actionDetailInfoButton(ActionEvent e) {
859 if (detailInfoPanel.isVisible()) {
860 detailInfoPanel.setVisible(false);
862 detailInfoPanel.setVisible(true);
871 public boolean isDetailInfoPanelVisible() {
872 return detailInfoPanel.isVisible();
876 * 書き込みメッセージボックスの表示ONOFFボタンを押した時の動作
880 public void actionShowTweetboxButton(ActionEvent e) {
881 if (this.tweetBoxRegionPane.isVisible()) {
882 this.tweetBoxRegionPane.setVisible(false);
884 this.tweetBoxRegionPane.setVisible(true);
889 * 書き込みメッセージボックス領域が表示されているか
891 public boolean isShowTweetBoxVisible() {
892 return this.tweetBoxRegionPane.isVisible();
898 public void actionRemoveFocusedTabbedTable() {
899 int selected = this.tweetMainTab.getSelectedIndex();
900 actionRemoveTabbedTable(selected);
908 public void actionRemoveTabbedTable(String timerID) {
909 int deleteTabIndex = -1;
911 for (int i = 0; i < tweetTabbedTableList.size(); i++) {
912 TweetTabbedTable table = tweetTabbedTableList.get(i);
913 if (table.getTimerID().equals(timerID)) {
919 actionRemoveTabbedTable(deleteTabIndex);
925 * @param removeTabIndex
927 public void actionRemoveTabbedTable(int removeTabIndex) {
928 int selected = removeTabIndex;
929 // タブの何番目に消したいテーブルがあるのかと,tweetTabbedTableListの何番目に消したいテーブルがあるのかは違う
933 int deleteTabIndex = -1;
934 for (int i = 0; i < tweetTabbedTableList.size(); i++) {
935 TweetTabbedTable table = tweetTabbedTableList.get(i);
936 if (selected == table.getTabSetNum()) {
943 if (deleteTabIndex >= 0) {
945 this.tweetMainTab.remove(selected);
947 String timerID = this.tweetTabbedTableList.get(deleteTabIndex)
950 TweetTabbedTable table = this.tweetTabbedTableList.get(deleteTabIndex);
951 if( table != null ) {
952 //streaming api使っている場合はlistenerをストップ
953 TweetGetter getter = table.getTweetGetter();
954 if( getter != null ) {
956 getter.stopUpdateListener();
960 this.tweetTabbedTableList.remove(deleteTabIndex);
962 this.tweetTaskManager.shutdownTask(timerID);
964 TimerID idManager = TimerID.getInstance();
965 idManager.removeID(timerID);
968 this.updateCheckboxInformation();
972 } catch (IOException e) {
983 public void actionExitButton(ActionEvent e) {
990 public void actionOpenStatusURL() {
993 String userName = this.getCurrentStatus().getUser().getScreenName();
995 long statusID = this.getCurrentStatus().getId();
996 Desktop.getDesktop().browse(
997 new URI(TWITTER_URL + userName + "/statuses/" + statusID));
998 } catch (Exception ex) {
999 ex.printStackTrace();
1000 JOptionPane.showMessageDialog(null, "エラーによりブラウザを起動できませんでした.",
1001 "Error", JOptionPane.ERROR_MESSAGE);
1006 * 選択したユーザのfollowingを表示
1008 public void actionOpenFollowing() {
1011 String userName = this.getCurrentStatus().getUser().getScreenName();
1012 this.actionShowFollowingFollowerDialog(userName, true);
1013 }catch(Exception e) {
1014 e.printStackTrace();
1019 * 選択したユーザのfollowingを表示
1021 public void actionOpenFollower() {
1024 String userName = this.getCurrentStatus().getUser().getScreenName();
1025 this.actionShowFollowingFollowerDialog(userName, false);
1026 }catch(Exception e) {
1027 e.printStackTrace();
1034 public void actionOpenUserFav() {
1036 Status s = this.getCurrentStatus();
1037 if (s.isRetweet()) {
1038 s = s.getRetweetedStatus();
1040 String userName = s.getUser().getScreenName();
1041 this.actionAddFavoriteTab(userName);
1042 } catch (Exception ex) {
1043 ex.printStackTrace();
1050 public void actionOpenFav() {
1051 String username = this.tweetManager.getScreenName();
1052 this.actionAddFavoriteTab(username);
1058 public void actionOpenUserURL() {
1060 Status s = this.getCurrentStatus();
1061 if (s.isRetweet()) {
1062 s = s.getRetweetedStatus();
1064 String userName = s.getUser().getScreenName();
1065 Desktop.getDesktop().browse(new URI(TWITTER_URL + userName));
1066 } catch (Exception ex) {
1067 ex.printStackTrace();
1068 JOptionPane.showMessageDialog(null, "エラーによりブラウザを起動できませんでした.",
1069 "Error", JOptionPane.ERROR_MESSAGE);
1076 public void actionRefreshTime() {
1078 for (TweetTabbedTable t : this.tweetTabbedTableList) {
1079 TweetTableModel model = t.getModel();
1080 if (model != null) {
1081 model.refreshTime();
1087 * TweetMessageBox内にある#ハッシュタグ の部分をa hrefリンクに変換
1091 public String actionReplaceTweetMessageBoxHashTab(String message) {
1093 Pattern userPtn = Pattern.compile( TweetConfiguration.HASHTAG_PATTERN,
1094 Pattern.CASE_INSENSITIVE);
1095 Matcher matcher = userPtn.matcher(message);
1098 Set<String> findList = new TreeSet<String>();
1099 while (matcher.find()) {
1100 findList.add(matcher.group(0));
1103 for (String f : findList) {
1105 message = message.replaceAll(f + "$|" + f + "\\s", "<a href=\""
1106 + SEARCH_TWITTER_URL + SEARCH_QUERY
1107 + URLEncoder.encode(f, DEFAULT_CHARACTER_ENCODING)
1108 + "\">" + "$0</a>");
1109 } catch (UnsupportedEncodingException e) {
1110 e.printStackTrace();
1117 * TweetMessageBox内にあるリンクをa hrefリンクに変換
1121 public String actionReplaceTweetMessageBoxURLLink(String message) {
1122 Matcher matcher = convURLLinkPtn.matcher(message);
1123 return matcher.replaceAll("<a href=\"$0\">$0</a>");
1127 * メッセージ内にあるURLをBitlyに変換する
1131 public String actionConvertURLToBitly(String message) {
1132 String result = new String( message );
1134 Matcher matcher = convURLLinkPtn.matcher(message);
1135 while( matcher.find() ) {
1136 String source = matcher.group();
1137 String conv = URLBitlyConverter.convertUrlToBitly( source );
1138 result = result.replace( source , conv );
1144 * つぶやきボックス内のURLをbitlyに変換
1146 public void actionConvertTweetBoxURLToBitly() {
1147 String message = this.tweetBoxPane.getText();
1148 String conv = actionConvertURLToBitly(message);
1149 this.tweetBoxPane.setText( conv );
1153 * @ユーザ名の部分をa hrefリンクに変換
1156 public String actionReplaceTweetMessageBoxUserInfo(String message) {
1158 Pattern userPtn = Pattern.compile("@[0-9A-Z_]+",
1159 Pattern.CASE_INSENSITIVE);
1160 Matcher matcher = userPtn.matcher(message);
1162 Set<String> findList = new TreeSet<String>();
1163 while (matcher.find()) {
1164 findList.add(matcher.group(0));
1166 // 指定したユーザ名をすべてリンクへ変更
1167 for (String f : findList) {
1168 message = message.replaceAll(f, "<a href=\"" + TWITTER_URL
1169 + f.substring(1) + "\">" + f + "</a>");
1175 * まだ見ていないdirectMessage数を0にする
1177 public void actionResetUncheckedDirectMessageCount() {
1178 uncheckedDirectMessageCount = 0;
1179 tweetMainTab.setTitleAt(2, TAB_DIRECT_MESSAGE_STRING);
1183 * まだ見ていないmention数を0にする
1185 public void actionResetUncheckedMentionTweetCount() {
1186 uncheckedMentionTweetCount = 0;
1187 tweetMainTab.setTitleAt(1, TAB_MENTION_STRING);
1191 * まだ見ていないtweet数を0にする
1193 public void actionResetUncheckedTimelineTweetCount() {
1194 uncheckedTimelineTweetCount = 0;
1195 tweetMainTab.setTitleAt(0, TAB_TIMELINE_STRING);
1201 public void actionSelectedUserTimeline() {
1202 Status status = null;
1203 if (this.getCurrentStatus().isRetweet()) {
1204 status = this.getCurrentStatus().getRetweetedStatus();
1206 status = this.getCurrentStatus();
1208 String username = status.getUser().getScreenName();
1210 actionAddUserTimelineTab(username, this.getGetTimelinePeriod());
1214 * 選択したユーザが作成したリスト一覧を表示
1218 public void actionShowSelectedUserList(ListGetterSelection selection) {
1219 Status status = null;
1220 if (this.getCurrentStatus().isRetweet()) {
1221 status = this.getCurrentStatus().getRetweetedStatus();
1223 status = this.getCurrentStatus();
1225 String username = status.getUser().getScreenName();
1226 actionShowUserListDialog(status.getUser().getScreenName(), selection);
1230 * 選択しているツイートをお気に入りに追加
1232 public void actionCreateFavorite() {
1233 Status status = null;
1234 if (this.getCurrentStatus().isRetweet()) {
1235 status = this.getCurrentStatus().getRetweetedStatus();
1237 status = this.getCurrentStatus();
1239 // 選択しているtweetのstatus id
1240 long statusID = status.getId();
1242 String username = status.getUser().getScreenName();
1244 String message = status.getText();
1246 if (message.length() > 30) {
1247 message = message.substring(0, 30) + " ...(以下略)";
1249 // Retweetしていいかどうかの確認
1250 int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
1251 + message + "\nをお気に入りに追加しますか?", "Favの確認",
1252 JOptionPane.YES_NO_OPTION);
1253 if (ret == JOptionPane.YES_OPTION) {
1256 this.tweetManager.createFavorite(statusID);
1257 } catch (TwitterException e) {
1258 JOptionPane.showMessageDialog(null, "エラーによりお気に入りに追加できませんでした.",
1259 "Fav Error", JOptionPane.ERROR_MESSAGE);
1265 * 選択しているツイートをお気に入りから外す
1267 public void actionDestroyFavorite() {
1268 Status status = null;
1269 if (this.getCurrentStatus().isRetweet()) {
1270 status = this.getCurrentStatus().getRetweetedStatus();
1272 status = this.getCurrentStatus();
1274 // 選択しているtweetのstatus id
1275 long statusID = status.getId();
1277 String username = status.getUser().getScreenName();
1279 String message = status.getText();
1281 if (message.length() > 30) {
1282 message = message.substring(0, 30) + " ...(以下略)";
1284 // Retweetしていいかどうかの確認
1285 int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
1286 + message + "\nをお気に入りから削除しますか?", "Favの確認",
1287 JOptionPane.YES_NO_OPTION);
1288 if (ret == JOptionPane.YES_OPTION) {
1291 this.tweetManager.destroyFavorite(statusID);
1292 } catch (TwitterException e) {
1293 JOptionPane.showMessageDialog(null, "エラーによりお気に入りから削除できませんでした.",
1294 "Fav Error", JOptionPane.ERROR_MESSAGE);
1300 * 現在選択しているステータスを公式Retweet
1302 public void actionRetweet() {
1303 Status status = null;
1304 if (this.getCurrentStatus().isRetweet()) {
1305 status = this.getCurrentStatus().getRetweetedStatus();
1307 status = this.getCurrentStatus();
1310 // 選択しているtweetのstatus id
1311 long statusID = status.getId();
1313 String username = status.getUser().getScreenName();
1315 String message = status.getText();
1317 if (message.length() > 30) {
1318 message = message.substring(0, 30) + " ...(以下略)";
1320 // Retweetしていいかどうかの確認
1321 int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
1322 + message + "\nをRetweetしますか?", "Retweetの確認",
1323 JOptionPane.YES_NO_OPTION);
1324 if (ret == JOptionPane.YES_OPTION) {
1327 this.tweetManager.retweet(statusID);
1328 } catch (TwitterException e) {
1329 JOptionPane.showMessageDialog(null, "エラーによりRetweetできませんでした.",
1330 "Retweet Error", JOptionPane.ERROR_MESSAGE);
1340 public void updateTableHeight(int height) {
1341 this.tableElementHeight = height;
1342 for (TweetTabbedTable t : this.tweetTabbedTableList) {
1343 t.getTable().setRowHeight(tableElementHeight);
1350 public void actionShowDirectMessageDialog() {
1351 // ダイレクトメッセージ送信用ダイアログを開く
1352 Point loc = getDirectMessageDialog().getLocation();
1353 // loc.translate(20, 20);
1354 DirectMessageDialog dialog = getDirectMessageDialog();
1355 // dialog.setLocation(loc);
1356 dialog.setLocationRelativeTo(null);
1357 dialog.setVisible(true);
1358 dialog.setUserInformation(this.selectedUsername,
1359 this.selectedUserImageURL, this.tweetManager);
1365 public void actionShowAboutDialog() {
1366 Point loc = getDirectMessageDialog().getLocation();
1367 // loc.translate(20, 20);
1368 AboutDialog dialog = getAboutDialog();
1369 dialog.setLocationRelativeTo(null);
1370 // dialog.setLocation(loc);
1371 dialog.setVisible(true);
1375 * 最新クライアント情報通知ダイアログを表示
1377 public void actionShowUpdateDialog() {
1378 UpdateNotifyDialog dialog = getUpdateNotifyDialog();
1379 dialog.setLocationRelativeTo(null);
1380 dialog.setVisible(true);
1386 public void actionShowAccountDialog() {
1387 // TODO: location取得のコードおかしい
1388 Point loc = getDirectMessageDialog().getLocation();
1389 // loc.translate(20, 20);
1390 AccountDialog dialog = getAccountDialog();
1391 dialog.setLocationRelativeTo(null);
1392 // dialog.setLocation(loc);
1393 dialog.setVisible(true);
1397 * Twitter全体からキーワード検索ダイアログを表示
1399 public void actionShowKeywordSearchDialog() {
1400 Point loc = getDirectMessageDialog().getLocation();
1401 KeywordSearchDialog dialog = getKeywordSearchDialog();
1402 dialog.setSearchWord("");
1403 dialog.setLocationRelativeTo(null);
1404 dialog.setVisible(true);
1408 * Twitter全体からキーワード検索ダイアログを表示
1411 * searchwordボックスに予め設定するワード
1413 public void actionShowKeywordSearchDialog(String searchWord) {
1414 Point loc = getDirectMessageDialog().getLocation();
1415 KeywordSearchDialog dialog = getKeywordSearchDialog();
1416 dialog.setSearchWord(searchWord);
1417 dialog.setLocationRelativeTo(null);
1418 dialog.setVisible(true);
1424 public void actionShowUserSearchDialog() {
1425 UserSearchDialog dialog = getUserSearchDialog();
1426 dialog.setLocationRelativeTo(null);
1427 dialog.setVisible(true);
1433 public void actionShowOutputCSVLogDialog() {
1434 OutputCSVLogDialog dialog = getOutputCSVLogDialog();
1435 dialog.setLocationRelativeTo(null);
1436 dialog.setVisible(true);
1440 * following follower表示ダイアログを表示
1442 public void actionShowFollowingFollowerDialog() {
1443 FollowingFollowerDialog dialog = getFollowingFollowerDialog();
1444 dialog.setLocationRelativeTo(null);
1445 dialog.setVisible(true);
1449 * following follower表示ダイアログを表示
1450 * @param username 取得したいユーザ
1451 * @param ff trueでfollowing/ falseでfollower取得
1453 public void actionShowFollowingFollowerDialog(String username, boolean ff) {
1454 FollowingFollowerDialog dialog = getFollowingFollowerDialog();
1455 //following follower取得開始
1456 dialog.actionUserSearch(username, ff);
1458 dialog.setLocationRelativeTo(null);
1459 dialog.setVisible(true);
1465 public void actionShowHashtagSearchDialog() {
1466 Point loc = getDirectMessageDialog().getLocation();
1467 HashtagSearchDialog dialog = getHashtagSearchDialog();
1468 dialog.setLocationRelativeTo(null);
1469 dialog.setVisible(true);
1475 * @param listUserName
1478 * CREATED: 指定したユーザが作成したリスト SUBSCRIPTION: 指定したユーザがフォローしているリスト
1479 * MEMBERSHIPS: 指定したユーザが追加されているリスト
1481 public void actionShowUserListDialog(String listUserName,
1482 ListGetterSelection selection) {
1483 UserListDialog dialog = getUserListDialog(listUserName, selection);
1484 Point loc = dialog.getLocation();
1485 dialog.setLocationRelativeTo(null);
1486 dialog.setVisible(true);
1490 * tweetBoxPaneに書かれた文字をつぶやく
1492 public void actionTweet() {
1493 boolean isTweet = false;
1495 if (this.replyStatus != null) {
1496 tweetManager.replyTweet(tweetBoxPane.getText(),
1497 this.replyStatus.getId());
1499 tweetManager.tweet(tweetBoxPane.getText());
1502 } catch (Exception e) {
1503 e.printStackTrace();
1508 this.information("メッセージをつぶやきました. 発言:" + tweetBoxPane.getText());
1509 tweetBoxPane.setText(""); // テキストをクリア
1511 this.information("つぶやきに失敗しました");
1512 JOptionPane.showMessageDialog(null,
1513 "つぶやきに失敗しました。文字数がオーバーしているか、ツイッターに接続ができませんでした。",
1514 "Tweet Error", JOptionPane.ERROR_MESSAGE);
1524 public void actionUpdateButton(java.awt.event.ActionEvent e) {
1526 // タブ上に存在するテーブルの情報を更新
1527 for (TweetTabbedTable t : this.tweetTabbedTableList) {
1528 String timerID = t.getTimerID();
1529 this.tweetTaskManager.resetTask(timerID, true);
1533 int remainingHits = tweetManager.getRateLimitStatus()
1534 .getRemainingHits();
1535 // 取得したコメント数をステータスバーに表示
1536 information("新しいツイートを取得しました. (APIリクエスト残数は" + remainingHits + "回です)");
1537 } catch (Exception e1) {
1538 e1.printStackTrace();
1543 * 新しく追加したタブにフォーカスを移す
1545 public void actionRequestForusToLastTab() {
1546 int lasttab = this.tweetMainTab.getTabCount() - 1;
1548 this.tweetMainTab.setSelectedIndex(lasttab);
1553 * 指定した番号のタブにフォーカスを移す
1557 public void actionRequestFocusToTab(int index) {
1559 this.tweetMainTab.setSelectedIndex(index);
1564 * 選択しているタブにあるテーブル情報だけを更新
1566 public void actionFocusedTableUpdate() {
1567 int selected = this.tweetMainTab.getSelectedIndex();
1569 if (selected >= 0) {
1570 // タブ上に存在するテーブルの情報を更新
1571 TweetTabbedTable t = this.tweetTabbedTableList.get(selected);
1572 String timerID = t.getTimerID();
1573 this.tweetTaskManager.resetTask(timerID, true);
1575 int remainingHits = tweetManager.getRateLimitStatus()
1576 .getRemainingHits();
1577 // 取得したコメント数をステータスバーに表示
1578 information(t.getTitle() + "タブのツイートを" + t.getUncheckedTweet()
1579 + "件取得しました. (APIリクエスト残数は" + remainingHits + "回です)");
1581 } catch (Exception e1) {
1582 e1.printStackTrace();
1591 public void actionUpdateTweetMessageCount() {
1592 int len = 140 - (tweetBoxPane.getText().length());
1593 boolean over = false;
1600 tweetMessageCountLabel.setForeground(Color.RED);
1602 tweetMessageCountLabel.setText("Over(" + len + ")");
1604 tweetMessageCountLabel.setForeground(Color.BLACK);
1606 tweetMessageCountLabel.setText(len + "");
1609 // 残りつぶやき数140の場合,reply状態も解除する
1611 this.setReplyStatus(null);
1618 public void debug() {
1619 //this.actionShowFollowingFollowerDialog("nishio_dens", false);
1624 * @param outputFilePath
1625 * @param showUsername
1626 * @param showScreenName
1628 * @param showUpdateTime
1630 * @param showUserDescription
1631 * @param showFollowing
1632 * @param showFollower
1633 * @param showUpdateCount
1634 * @param showUserURL
1635 * @param showProfileImageURL
1636 * @throws SAXParseException
1637 * @throws IOException
1639 public void outputLogToCSV(String outputFilePath,
1640 boolean showUsername, boolean showScreenName,
1642 boolean showUpdateTime, boolean showClient,
1643 boolean showUserDescription,
1644 boolean showFollowing, boolean showFollower,
1645 boolean showUpdateCount, boolean showUserURL,
1646 boolean showProfileImageURL) throws SAXParseException, IOException {
1647 TwitterLogManager logManager = new TwitterLogManager();
1648 List<Status> statuses = logManager.get();
1650 logManager.outputCSVLog( outputFilePath, statuses, showUsername, showScreenName,
1651 showText, showUpdateTime, showClient,
1652 showUserDescription, showFollowing, showFollower,
1653 showUpdateCount, showUserURL,showProfileImageURL);
1661 public ConfigurationDialog getConfigurationDialog() {
1662 if (configurationDialog == null) {
1663 configurationDialog = new ConfigurationDialog(mainFrame, true, this);
1665 return configurationDialog;
1671 * @param listUserName
1676 public UserListDialog getUserListDialog(String listUserName,
1677 ListGetterSelection selection) {
1678 UserListGetter getter = null;
1679 switch (selection) {
1681 getter = new UserListSpecificUserListsGetter(tweetManager);
1684 getter = new UserListMembershipsGetter(tweetManager);
1686 case SUBSCRIPTION: /* fall through */
1688 getter = new UserListSubscriptionGetter(tweetManager);
1691 userListDialog = new UserListDialog(mainFrame, true, this, getter,
1693 return userListDialog;
1701 public String getScreenName() {
1702 return tweetManager.getScreenName();
1706 * twitter全体からキーワード検索ダイアログを表示
1710 public KeywordSearchDialog getKeywordSearchDialog() {
1711 if (keywordSearchDialog == null) {
1712 keywordSearchDialog = new KeywordSearchDialog(mainFrame, true, this);
1714 return keywordSearchDialog;
1721 public UserSearchDialog getUserSearchDialog() {
1722 if( this.userSearchDialog == null ) {
1723 this.userSearchDialog = new UserSearchDialog(mainFrame, true, this);
1725 return this.userSearchDialog;
1732 public OutputCSVLogDialog getOutputCSVLogDialog() {
1733 if( this.outputCSVLogDialog == null ) {
1734 this.outputCSVLogDialog = new OutputCSVLogDialog(mainFrame, true, this);
1736 return this.outputCSVLogDialog;
1740 * Following follower表示ダイアログ
1743 public FollowingFollowerDialog getFollowingFollowerDialog() {
1744 if( this.followingFollowerDialog == null ) {
1745 this.followingFollowerDialog =
1746 new FollowingFollowerDialog(mainFrame, true, this.tweetManager);
1748 return this.followingFollowerDialog;
1756 public HashtagSearchDialog getHashtagSearchDialog() {
1757 if (hashtagSearchDialog == null) {
1758 hashtagSearchDialog = new HashtagSearchDialog(mainFrame, true,
1759 this, tweetManager);
1761 return hashtagSearchDialog;
1769 public AccountDialog getAccountDialog() {
1770 if (accountDialog == null) {
1771 accountDialog = new AccountDialog(mainFrame, true, tweetManager,
1774 return accountDialog;
1778 * ダイレクトメッセージ送信用ダイアログを取得
1782 public DirectMessageDialog getDirectMessageDialog() {
1783 if (directMessageDialog == null) {
1784 directMessageDialog = new DirectMessageDialog(mainFrame);
1785 directMessageDialog.setTitle("ダイレクトメッセージを送信");
1787 return directMessageDialog;
1791 * テーブルで選択したツイートを詳細情報としてセット
1795 public void setDetailInformationFromTable(JTable table) {
1796 int sc = table.getSelectedRowCount();
1797 String infoMessage = "";
1799 // 選択している行が1行だけの場合,情報を表示する
1800 if (sc == 1 && table != null) {
1801 Status st = getTweetTableInformation(table, table.getModel());
1803 if (st.isRetweet()) {
1804 st = st.getRetweetedStatus();
1806 infoMessage = st.getText();
1807 // メッセージのHTMLエンコードを行う
1808 infoMessage = HTMLEncode.encode(infoMessage);
1809 // tweetMessageBox内のURLをhtmlリンクへ変換
1810 infoMessage = actionReplaceTweetMessageBoxURLLink(infoMessage);
1811 // @ユーザ情報をhtmlリンクへ変換
1812 infoMessage = actionReplaceTweetMessageBoxUserInfo(infoMessage);
1813 // #ハッシュタグ情報をhtmlリンクへ変換
1814 infoMessage = actionReplaceTweetMessageBoxHashTab(infoMessage);
1815 // 詳細情報にテーブルで選択した人のツイート情報を表示
1816 tweetMessageBox.setText(infoMessage);
1819 ImageIcon icon = TwitterImageCache.getInstance().getProfileImage(
1820 st.getUser().getProfileImageURL().toString());
1821 userImageLabel.setIcon(icon);
1823 userNameLabel.setText(st.getUser().getName() + " / "
1824 + st.getUser().getScreenName());
1826 updateTimeLabel.setText(DateFormat.getInstance().format(
1827 st.getCreatedAt()));
1829 userIntroBox.setText(st.getUser().getDescription());
1831 followerLabel.setText(st.getUser().getFollowersCount() + "");
1833 followingLabel.setText(st.getUser().getFriendsCount() + "");
1835 locationLabel.setText(st.getUser().getLocation());
1837 if (st.getUser().getURL() != null) {
1838 userWebBox.setText("<a href=\"" + st.getUser().getURL() + "\">"
1839 + st.getUser().getScreenName() + "のWebを開く" + "</a>");
1841 userWebBox.setText("");
1844 clientNameLabel.setText(" via " + st.getSource());
1846 updateLabel.setText(st.getUser().getStatusesCount() + "");
1854 public AboutDialog getAboutDialog() {
1855 if (aboutDialog == null) {
1856 aboutDialog = new AboutDialog(mainFrame, true);
1865 public UpdateNotifyDialog getUpdateNotifyDialog() {
1866 if( updateDialog == null ) {
1867 updateDialog = new UpdateNotifyDialog(mainFrame, true, this);
1869 return updateDialog;
1873 * テーブルで選択した場所のTweet情報を取得
1877 public Status getTweetTableInformation(JTable table, TableModel model) {
1878 int index = table.convertRowIndexToModel(table.getSelectedRow());
1879 Status status = null;
1880 if (model instanceof TweetTableModel) {
1881 status = ((TweetTableModel) model).getTweetStatus(index);
1882 // 現在選択したセルのユーザ名を保存しておく
1883 this.selectedUsername = status.getUser().getScreenName();
1884 // 現在選択したセルのユーザURLを保存しておく
1885 this.selectedUserImageURL = status.getUser().getProfileImageURL();
1886 // 選択したStatusを保存しておく
1887 this.setCurrentStatus(status);
1897 public void information(String message) {
1898 statusBarLabel.setText(message);
1905 public boolean isTempOpenedTimelineTab() {
1906 return isTempOpenedTimelineTab;
1913 public boolean isTempOpenedMentionTab() {
1914 return isTempOpenedMentionTab;
1921 public boolean isTempOpenedDMTab() {
1922 return isTempOpenedDMTab;
1929 public boolean isTempOpenedSendDMTab() {
1930 return isTempOpenedSendDMTab;
1936 * @throws IOException
1937 * @throws FileNotFoundException
1939 public void loadProperties() throws FileNotFoundException, IOException {
1940 if (property == null) {
1941 this.property = new Properties();
1943 property.load(new FileInputStream("./" + PROPERTIES_DIRECTORY + "/"
1944 + BASIC_SETTING_FILENAME));
1946 String gtp = this.property.getProperty("getTimelinePeriod");
1947 String gmp = this.property.getProperty("getMentionPeriod");
1948 String gdmp = this.property.getProperty("getDirectMessagePeriod");
1949 String gsdmp = this.property.getProperty("getSendDirectMessagePeriod");
1951 String ntrgb = this.property.getProperty("newTableColorRGB");
1953 this.tlFontName = this.property.getProperty("tlFontName");
1954 this.detailFontName = this.property.getProperty("detailFontName");
1956 String tfs = this.property.getProperty("tlFontSize");
1957 String dfs = this.property.getProperty("detailFontSize");
1958 String teh = this.property.getProperty("tableElementHeight");
1961 String mfw = this.property.getProperty("mainFrameWidth");
1962 String mfh = this.property.getProperty("mainFrameHeight");
1965 String nm = this.property.getProperty("notifyMention");
1966 String ndm = this.property.getProperty("notifyDirectMessage");
1969 String ptl = this.property.getProperty("openTimelineTab");
1970 String pm = this.property.getProperty("openMentionTab");
1971 String podm = this.property.getProperty("openDirectMessageTab");
1972 String posdmt = this.property.getProperty("openSendDirectMessageTab");
1975 String log = this.property.getProperty("saveLog");
1978 String nost = this.property.getProperty("numOfShowTweet");
1981 String unt = this.property.getProperty("updateNotify");
1983 unt = this.isUpdateNotify + "";
1987 String ius = this.property.getProperty("isUsingStreaming");
1989 ius = this.isUsingStreaming + "";
1992 String fav = this.property.getProperty("isFavNotify");
1994 fav = this.favNotify + "";
1998 this.newTableColor = new Color(Integer.parseInt(ntrgb));
1999 this.tlFontSize = Integer.parseInt(tfs);
2000 this.detailFontSize = Integer.parseInt(dfs);
2001 this.tableElementHeight = Integer.parseInt(teh);
2002 this.mainFrameWidth = Integer.parseInt(mfw);
2003 this.mainFrameHeight = Integer.parseInt(mfh);
2006 this.getTimelinePeriod = Integer.parseInt(gtp);
2007 this.getMentionPeriod = Integer.parseInt(gmp);
2008 this.getDirectMessagePeriod = Integer.parseInt(gdmp);
2009 this.getSendDirectMessagePeriod = Integer.parseInt(gsdmp);
2012 this.isNotifyMentionMessage = Boolean.parseBoolean(nm);
2013 this.isNotifyDirectMessage = Boolean.parseBoolean(ndm);
2016 this.isTempOpenedTimelineTab = Boolean.parseBoolean(ptl);
2017 this.isTempOpenedMentionTab = Boolean.parseBoolean(pm);
2018 this.isTempOpenedDMTab = Boolean.parseBoolean(podm);
2019 this.isTempOpenedSendDMTab = Boolean.parseBoolean(posdmt);
2022 this.saveLog = Boolean.parseBoolean(log);
2025 this.tableElementMaxSize = Integer.parseInt(nost);
2028 this.isUpdateNotify = Boolean.parseBoolean(unt);
2031 this.isUsingStreaming = Boolean.parseBoolean(ius);
2034 this.favNotify = Boolean.parseBoolean(fav);
2035 } catch (NumberFormatException e) {
2036 e.printStackTrace();
2043 * @throws IOException
2045 public void saveProperties() throws IOException {
2047 File logDir = new File("./" + PROPERTIES_DIRECTORY);
2048 if (!logDir.exists()) {
2049 // ディレクトリが存在しないので作成する
2050 if (logDir.mkdir() == false) {
2051 throw new IOException(PROPERTIES_DIRECTORY
2052 + "ディレクトリを作成できませんでした.");
2055 if (property == null) {
2056 this.property = new Properties();
2060 this.property.setProperty("getTimelinePeriod", this.getTimelinePeriod
2062 this.property.setProperty("getMentionPeriod", this.getMentionPeriod
2064 this.property.setProperty("getDirectMessagePeriod",
2065 this.getDirectMessagePeriod + "");
2066 this.property.setProperty("getSendDirectMessagePeriod",
2067 this.getSendDirectMessagePeriod + "");
2069 this.property.setProperty("newTableColorRGB", newTableColor.getRGB()
2071 this.property.setProperty("tlFontName", this.tlFontName);
2072 this.property.setProperty("tlFontSize", this.tlFontSize + "");
2073 this.property.setProperty("detailFontName", this.detailFontName);
2074 this.property.setProperty("detailFontSize", this.detailFontSize + "");
2075 this.property.setProperty("tableElementHeight", this.tableElementHeight
2079 if (this.mainFrame.getExtendedState() == JFrame.NORMAL) {
2080 this.mainFrameWidth = this.mainFrame.getWidth();
2081 this.mainFrameHeight = this.mainFrame.getHeight();
2083 this.property.setProperty("mainFrameWidth", this.mainFrameWidth + "");
2084 this.property.setProperty("mainFrameHeight", this.mainFrameHeight + "");
2087 this.property.setProperty("notifyMention", this.isNotifyMentionMessage
2089 this.property.setProperty("notifyDirectMessage",
2090 this.isNotifyDirectMessage + "");
2093 this.property.setProperty("openTimelineTab", this.isExistTimelineTab() + "");
2094 this.property.setProperty("openMentionTab", this.isExistMentionTab() + "");
2095 this.property.setProperty("openDirectMessageTab", this.isExistDirectMessageTab() + "");
2096 this.property.setProperty("openSendDirectMessageTab", this.isExistSendDirectMessageTab() + "");
2099 this.property.setProperty("saveLog", this.isSaveLog() + "");
2102 this.property.setProperty("numOfShowTweet", this.getTableElementMaxSize() + "");
2105 this.property.setProperty("updateNotify", this.isUpdateNotify + "");
2108 this.property.setProperty("isUsingStreaming", this.isUsingStreaming + "");
2111 this.property.setProperty("isFavNotify", this.favNotify + "");
2114 property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
2115 + BASIC_SETTING_FILENAME), null);
2119 * newTableColorを取得します。
2121 * @return newTableColor
2123 public Color getNewTableColor() {
2124 return newTableColor;
2128 * newTableColorを設定します。
2130 * @param newTableColor
2133 public void setNewTableColor(Color newTableColor) {
2134 this.newTableColor = newTableColor;
2140 * @return tlFontName
2142 public String getTlFontName() {
2152 public void setTlFontName(String tlFontName) {
2153 this.tlFontName = tlFontName;
2159 * @return tlFontSize
2161 public int getTlFontSize() {
2171 public void setTlFontSize(int tlFontSize) {
2172 this.tlFontSize = tlFontSize;
2176 * detailFontNameを取得します。
2178 * @return detailFontName
2180 public String getDetailFontName() {
2181 return detailFontName;
2185 * detailFontNameを設定します。
2187 * @param detailFontName
2190 public void setDetailFontName(String detailFontName) {
2191 this.detailFontName = detailFontName;
2195 * detailFontSizeを取得します。
2197 * @return detailFontSize
2199 public int getDetailFontSize() {
2200 return detailFontSize;
2204 * detailFontSizeを設定します。
2206 * @param detailFontSize
2209 public void setDetailFontSize(int detailFontSize) {
2210 this.detailFontSize = detailFontSize;
2214 * tableElementHeightを取得します。
2216 * @return tableElementHeight
2218 public int getTableElementHeight() {
2219 return tableElementHeight;
2223 * tableElementHeightを設定します。
2225 * @param tableElementHeight
2226 * tableElementHeight
2228 public void setTableElementHeight(int tableElementHeight) {
2229 this.tableElementHeight = tableElementHeight;
2233 * @return the getTimelinePeriod
2235 public int getGetTimelinePeriod() {
2236 return getTimelinePeriod;
2243 public void setNotifyMention(boolean notify) {
2244 this.isNotifyMentionMessage = notify;
2251 public boolean getNotifyMention() {
2252 return this.isNotifyMentionMessage;
2260 public void setNotifyDirectMessage(boolean notify) {
2261 this.isNotifyDirectMessage = notify;
2265 * 最新クライアント情報を通知するかどうか
2267 public boolean isUpdateNotify() {
2268 return this.isUpdateNotify;
2272 * 最新クライアント情報を通知するかどうか設定
2274 public void setUpdateNotify(boolean notify) {
2275 this.isUpdateNotify = notify;
2282 public boolean getNotifyDirectMessage() {
2283 return this.isNotifyDirectMessage;
2287 * @param getTimelinePeriod
2288 * the getTimelinePeriod to set
2290 public void setGetTimelinePeriod(int getTimelinePeriod) {
2291 this.getTimelinePeriod = getTimelinePeriod;
2295 * @return the getMentionPeriod
2297 public int getGetMentionPeriod() {
2298 return getMentionPeriod;
2302 * @param getMentionPeriod
2303 * the getMentionPeriod to set
2305 public void setGetMentionPeriod(int getMentionPeriod) {
2306 this.getMentionPeriod = getMentionPeriod;
2310 * @return the getDirectMessagePeriod
2312 public int getGetDirectMessagePeriod() {
2313 return getDirectMessagePeriod;
2317 * @param getDirectMessagePeriod
2318 * the getDirectMessagePeriod to set
2320 public void setGetDirectMessagePeriod(int getDirectMessagePeriod) {
2321 this.getDirectMessagePeriod = getDirectMessagePeriod;
2325 * @return the getSendDirectMessagePeriod
2327 public int getGetSendDirectMessagePeriod() {
2328 return getSendDirectMessagePeriod;
2332 * @param getSendDirectMessagePeriod
2333 * the getSendDirectMessagePeriod to set
2335 public void setGetSendDirectMessagePeriod(int getSendDirectMessagePeriod) {
2336 this.getSendDirectMessagePeriod = getSendDirectMessagePeriod;
2340 * @return the currentStatus
2342 public Status getCurrentStatus() {
2343 return currentStatus;
2347 * @param currentStatus
2348 * the currentStatus to set
2350 public void setCurrentStatus(Status currentStatus) {
2351 this.currentStatus = currentStatus;
2358 public Status getReplyStatus() {
2367 public void setReplyStatus(Status status) {
2368 this.replyStatus = status;
2375 public boolean isSaveLog() {
2376 return this.saveLog;
2383 public void setSaveLog(boolean check) {
2384 this.saveLog = check;
2391 public void setTableElementMaxSize(int size) {
2393 this.tableElementMaxSize = size;
2401 public int getTableElementMaxSize() {
2402 return this.tableElementMaxSize;
2408 public void startStreaming() {
2409 this.isUsingStreaming = true;
2410 this.tweetManager.getStreamManager().start();
2413 } catch (IOException ex) {
2414 Logger.getLogger(TweetMainAction.class.getName()).log(Level.SEVERE, null, ex);
2421 public void stopStreaming() {
2422 this.isUsingStreaming = false;
2423 this.tweetManager.getStreamManager().stop();
2426 } catch (IOException ex) {
2427 Logger.getLogger(TweetMainAction.class.getName()).log(Level.SEVERE, null, ex);
2432 * ストリーミング処理を利用するかどうか
2435 public boolean isUsingStreaming() {
2436 return this.isUsingStreaming;
2442 public void onConnect() {
2443 this.isCurrentUsingStreaming = true;
2444 updatePeriodInformationToComponent();
2448 * streaming api stop
2451 public void onDisconnect() {
2452 this.isCurrentUsingStreaming = false;
2453 updatePeriodInformationToComponent();
2460 public void onCleanUp() {
2465 * 現在streaming apiが起動しているかどうか
2467 public boolean isStartedStreamingAPI() {
2468 return this.isCurrentUsingStreaming;
2475 public boolean isFavNotify() {
2476 return this.favNotify;
2482 public void setFavNotify(boolean notify) {
2483 this.favNotify = notify;