1 package twitter.gui.action;
4 import java.awt.Desktop;
5 import java.awt.Dimension;
8 import java.awt.event.ActionEvent;
10 import java.io.FileInputStream;
11 import java.io.FileNotFoundException;
12 import java.io.FileOutputStream;
13 import java.io.IOException;
14 import java.io.UnsupportedEncodingException;
17 import java.net.URLEncoder;
18 import java.text.DateFormat;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Properties;
23 import java.util.TreeSet;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28 import javax.swing.ImageIcon;
30 import javax.swing.JEditorPane;
31 import javax.swing.JFrame;
32 import javax.swing.JLabel;
33 import javax.swing.JOptionPane;
34 import javax.swing.JPanel;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTabbedPane;
37 import javax.swing.JTable;
38 import javax.swing.JTextPane;
39 import javax.swing.table.TableModel;
40 import javax.swing.text.Style;
41 import javax.swing.text.StyleConstants;
42 import javax.swing.text.html.HTMLDocument;
43 import javax.swing.text.html.StyleSheet;
44 import twitter.action.TweetDirectMessageGetter;
45 import twitter.action.TweetGetter;
46 import twitter.action.TweetMentionGetter;
47 import twitter.action.TweetSearchResultGetter;
48 import twitter.action.TweetSendDirectMessageGetter;
49 import twitter.action.TweetTimelineGetter;
51 import twitter.gui.component.TweetTabbedTable;
52 import twitter.gui.component.TweetTableModel;
53 import twitter.gui.form.AboutDialog;
54 import twitter.gui.form.AccountDialog;
55 import twitter.gui.form.ConfigurationDialog;
56 import twitter.gui.form.DirectMessageDialog;
57 import twitter.gui.form.KeywordSearchDialog;
58 import twitter.manage.TweetConfiguration;
59 import twitter.manage.TweetManager;
60 import twitter.task.ExistTimerIDException;
61 import twitter.task.TimerID;
62 import twitter.task.TweetTaskException;
63 import twitter.task.TweetTaskManager;
64 import twitter.task.TweetUpdateTask;
65 import twitter4j.Status;
66 import twitter4j.TwitterException;
74 public class TweetMainAction {
77 public static final String BASIC_SETTING_FILENAME = TweetConfiguration.BASIC_SETTING_FILENAME;
79 private static final Pattern convURLLinkPtn = Pattern.compile(
80 "(http://|https://){1}[\\w\\.\\-/:\\#\\?\\=\\&\\;\\%\\~\\+]+",
81 Pattern.CASE_INSENSITIVE);
82 // default char encoding
83 private static final String DEFAULT_CHARACTER_ENCODING = "UTF-8";
85 public static final String PROPERTIES_DIRECTORY = "properties";
87 private static final String SEARCH_QUERY = "search?q=";
89 private static final String SEARCH_TWITTER_URL = "http://search.twitter.com/";
90 // Direct Messageタブに表示する文字
91 public static final String TAB_DIRECT_MESSAGE_STRING = "Message";
93 public static final String TAB_MENTION_STRING = "Mention";
95 public static final String TAB_TIMELINE_STRING = "Timeline";
96 //Send Direct Messageタブに表示する文字
97 public static final String TAB_SEND_DIRECT_MESSAGE_STRING = "Send";
98 // テーブルのデータ量が以下の値を超えたら古いデータから削除
99 private static final int TABLE_ELEMENT_MAX_SIZE = 200;
101 private static final String TWITTER_URL = "http://twitter.com/";
103 private ConfigurationDialog configurationDialog = null;
105 private Status currentStatus = null;
107 private JPanel detailInfoPanel = null;
108 // ダイレクトメッセージ送信用ダイアログ
109 private DirectMessageDialog directMessageDialog = null;
110 //Twitter全体からキーワード検索ダイアログ
111 private KeywordSearchDialog keywordSearchDialog = null;
113 private Color newTableColor = new Color(224, 255, 255);
115 private String tlFontName = "Takao Pゴシック";
117 private int tlFontSize = 13;
119 private String detailFontName = "Takao Pゴシック";
121 private int detailFontSize = 13;
123 private int tableElementHeight = 50;
125 private int mainFrameWidth = 729;
127 private int mainFrameHeight = 629;
129 private JFrame mainFrame = null;
131 private Properties property = null;
132 // 現在テーブルで選択しているユーザ画像のURL
133 private URL selectedUserImageURL = null;
134 // 現在テーブルで選択しているユーザの名前
135 private String selectedUsername = null;
137 private JLabel statusBarLabel = null;
139 private JTextPane tweetBoxPane = null;
140 //自分がつぶやきを書く領域のスクロールペーン
141 private JScrollPane tweetBoxScrollPane = null;
143 private JTabbedPane tweetMainTab = null;
145 private TweetManager tweetManager = null;
146 // tweetを表示するTextPane
147 private JEditorPane tweetMessageBox = null;
148 // つぶやくことができる文字数を表示するラベル
149 private JLabel tweetMessageCountLabel = null;
150 private int uncheckedDirectMessageCount = 0;
151 private int uncheckedMentionTweetCount = 0;
154 private JLabel userImageLabel = null;
155 private JLabel userNameLabel = null;
156 private JLabel updateTimeLabel = null;
157 private JLabel followerLabel = null;
158 private JLabel followingLabel = null;
159 private JLabel locationLabel = null;
160 private JEditorPane clientNameLabel = null;
161 private JLabel updateLabel = null;
162 private JEditorPane userIntroBox = null;
163 private JEditorPane userWebBox = null;
165 // 新しく取得したtweetでまだ参照していない数
166 private int uncheckedTimelineTweetCount = 0;
167 private AboutDialog aboutDialog = null;
169 private AccountDialog accountDialog;
171 private List<TweetTabbedTable> tweetTabbedTableList = new ArrayList<TweetTabbedTable>();
172 //ツイートテーブルの情報を一定間隔で更新するクラスを作成
173 private TweetTaskManager tweetTaskManager = new TweetTaskManager();
176 private int getTimelinePeriod = 60;
177 private int getMentionPeriod = 60 * 3;
178 private int getDirectMessagePeriod = 60 * 15;
179 private int getSendDirectMessagePeriod = 60 * 30;
184 * @param tweetManager
185 * @param statusBarLabel
186 * @param tweetTableModel
187 * @param mentionTableModel
188 * @param directMessageTableModel
189 * @param sendDirectMessageTableModel
190 * @param mainTweetTable
191 * @param mentionTable
192 * @param directMessageTable
193 * @param sendDirectMessageTable
194 * @param tweetBoxPane
195 * @param tweetBoxScrollPane
196 * @param tweetMessageCountLabel
197 * @param detailInfoPanel
198 * @param tweetMainTab
199 * @param tweetMessageBox
200 * @param userImageLabel
201 * @param userNameLabel
202 * @param updateTimeLabel
203 * @param followerLabel
204 * @param followingLabel
205 * @param locationLabel
206 * @param clientNameLabel
208 * @param userIntroBox
211 public TweetMainAction(JFrame mainFrame,
212 TweetManager tweetManager,
213 JLabel statusBarLabel,
214 JTextPane tweetBoxPane,
215 JScrollPane tweetBoxScrollPane,
216 JLabel tweetMessageCountLabel,
217 JPanel detailInfoPanel,
218 JTabbedPane tweetMainTab,
219 JEditorPane tweetMessageBox,
220 JLabel userImageLabel,
221 JLabel userNameLabel,
222 JLabel updateTimeLabel,
223 JLabel followerLabel,
224 JLabel followingLabel,
225 JLabel locationLabel,
226 JEditorPane clientNameLabel,
228 JEditorPane userIntroBox,
229 JEditorPane userWebBox) {
230 this.mainFrame = mainFrame;
231 this.tweetManager = tweetManager;
232 this.statusBarLabel = statusBarLabel;
233 this.tweetBoxPane = tweetBoxPane;
234 this.tweetMessageCountLabel = tweetMessageCountLabel;
235 this.detailInfoPanel = detailInfoPanel;
236 this.tweetMainTab = tweetMainTab;
237 this.tweetMessageBox = tweetMessageBox;
238 this.tweetBoxScrollPane = tweetBoxScrollPane;
241 this.userImageLabel = userImageLabel;
242 this.userNameLabel = userNameLabel;
243 this.updateTimeLabel = updateTimeLabel;
244 this.userIntroBox = userIntroBox;
245 this.followerLabel = followerLabel;
246 this.followingLabel = followingLabel;
247 this.locationLabel = locationLabel;
248 this.userWebBox = userWebBox;
249 this.clientNameLabel = clientNameLabel;
250 this.updateLabel = updateLabel;
255 } catch (FileNotFoundException e) {
257 } catch (IOException e) {
261 updateFontInformationToComponent();
264 mainFrame.setSize(this.mainFrameWidth, this.mainFrameHeight);
265 mainFrame.setPreferredSize(new Dimension(this.mainFrameWidth, this.mainFrameHeight));
269 * Timeline, Mention , DM, SendDMの情報更新間隔を取得し,その情報をテーブルに反映
271 public void updatePeriodInformationToComponent() {
273 for (TweetTabbedTable t : this.tweetTabbedTableList) {
274 String timerID = t.getTimerID();
275 if( timerID.equals( TimerID.createTimelineID() ) ) {
277 this.tweetTaskManager.updateTaskPeriod(timerID, this.getGetTimelinePeriod());
278 }else if( timerID.equals( TimerID.createMentionID() ) ) {
280 this.tweetTaskManager.updateTaskPeriod(timerID, this.getGetMentionPeriod() );
281 }else if( timerID.equals( TimerID.createDirectMessageID() ) ) {
283 this.tweetTaskManager.updateTaskPeriod(timerID, this.getGetDirectMessagePeriod());
284 }else if( timerID.equals( TimerID.createSendDirectMessageID() ) ) {
286 this.tweetTaskManager.updateTaskPeriod(timerID, this.getGetSendDirectMessagePeriod());
292 public void updateFontInformationToComponent() {
295 if (this.tlFontName != null) {
296 tlFont = new Font(this.tlFontName, Font.PLAIN, this.tlFontSize);
298 Font detailFont = null;
299 if (this.detailFontName != null) {
300 detailFont = new Font(this.detailFontName, Font.PLAIN,
301 this.detailFontSize);
305 for( TweetTabbedTable t : this.tweetTabbedTableList) {
306 t.getTable().setFont(tlFont);
309 // tweetメッセージボックスのフォントはhtmlレベルで変更する必要がある
310 this.tweetMessageBox.setFont(detailFont);
312 HTMLDocument doc = (HTMLDocument) this.tweetMessageBox.getDocument();
313 StyleSheet[] style = doc.getStyleSheet().getStyleSheets();
314 for (int i = style.length - 1; i >= 0; i--) {
315 Style body = style[i].getStyle("body");
317 StyleConstants.setFontFamily(body, detailFont.getFontName());
318 StyleConstants.setFontSize(body, detailFont.getSize());
322 } catch (Exception e) {
329 * @param timerID TimerIDクラスで生成したタイマーID
330 * @param period 情報更新間隔[sec]
331 * @param tweetGetter 実行するアクション
332 * @param tabTitle 追加するタブのタイトル
334 public void actionAddTab(String timerID, int period, TweetGetter tweetGetter, String tabTitle) {
335 int numOfTab = this.tweetTabbedTableList.size();
342 final TweetTabbedTable table = new TweetTabbedTable(tweetGetter, tabTitle,
343 this.tweetMainTab, numOfTab,
344 this.tableElementHeight, this.tweetManager,
345 this, newTableColor, tableElementHeight, timerID);
347 this.tweetTaskManager.addTask(timerID, new TweetUpdateTask() {
350 public void runTask() throws TweetTaskException {
352 table.updateTweetTable();
356 this.tweetTaskManager.startTask(timerID, period * 1000L);
359 table.addTableToTab();
361 this.tweetTabbedTableList.add(table);
362 //searchTable.updateTweetTable();
363 } catch (TweetTaskException ex) {
364 Logger.getLogger(TweetMainAction.class.getName()).log(Level.SEVERE, null, ex);
369 this.updateFontInformationToComponent();
371 this.updateTableHeight( this.getTableElementHeight() );
376 * @param period 情報更新間隔[sec]
378 public void actionAddMentionTab(int period) {
379 TimerID timerID = TimerID.getInstance();
380 String id = TimerID.createMentionID();
382 //既にIDが存在していたらここで例外発生
385 actionAddTab(id, period, new TweetMentionGetter(tweetManager),
386 TweetMainAction.TAB_MENTION_STRING);
387 } catch (ExistTimerIDException ex) {
388 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
389 "Error", JOptionPane.ERROR_MESSAGE);
397 public void actionAddTimelineTab(int period) {
398 TimerID timerID = TimerID.getInstance();
399 String id = TimerID.createTimelineID();
401 //既にIDが存在していたらここで例外発生
404 actionAddTab(id, period, new TweetTimelineGetter(tweetManager),
405 TweetMainAction.TAB_TIMELINE_STRING);
406 } catch (ExistTimerIDException ex) {
407 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
408 "Error", JOptionPane.ERROR_MESSAGE);
414 * @param period 更新間隔[sec]
416 public void actionAddDirectMessageTab(int period) {
417 TimerID timerID = TimerID.getInstance();
418 String id = TimerID.createDirectMessageID();
420 //既にIDが存在していたらここで例外発生
423 actionAddTab(id, period, new TweetDirectMessageGetter(tweetManager),
424 TweetMainAction.TAB_DIRECT_MESSAGE_STRING);
425 } catch (ExistTimerIDException ex) {
426 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
427 "Error", JOptionPane.ERROR_MESSAGE);
435 public void actionAddSendDirectMessageTab(int period) {
436 TimerID timerID = TimerID.getInstance();
437 String id = TimerID.createSendDirectMessageID();
439 //既にIDが存在していたらここで例外発生
442 actionAddTab(id, period, new TweetSendDirectMessageGetter(tweetManager),
443 TweetMainAction.TAB_SEND_DIRECT_MESSAGE_STRING);
444 } catch (ExistTimerIDException ex) {
445 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
446 "Error", JOptionPane.ERROR_MESSAGE);
452 * ツイート検索結果を表示するタブを新しく追加
454 * @param period 更新周期[sec] 0以下の場合は更新しない
456 public void actionAddNewSearchResultTab(String searchWord, int period) {
457 TimerID timerID = TimerID.getInstance();
458 String id = TimerID.createSearchTimerID(searchWord);
460 //既にIDが存在していたらここで例外発生
463 actionAddTab(id, period, new TweetSearchResultGetter(this.tweetManager, searchWord), searchWord);
464 } catch (ExistTimerIDException ex) {
465 JOptionPane.showMessageDialog(null, "そのタブは既に存在しています",
466 "Error", JOptionPane.ERROR_MESSAGE);
473 public void actionBasicSettingDialog() {
474 // ダイレクトメッセージ送信用ダイアログを開く
475 Point loc = getConfigurationDialog().getLocation();
476 loc.translate(20, 20);
477 ConfigurationDialog dialog = getConfigurationDialog();
478 dialog.setLocation(loc);
479 dialog.setVisible(true);
485 public void actionCopySelectedStatusToTweetBoxPane() {
487 String username = this.currentStatus.getUser().getScreenName();
489 String message = this.currentStatus.getText();
490 this.tweetBoxPane.setText("RT: @" + username + ": " + message);
498 public void actionDetailInfoButton(ActionEvent e) {
499 if (detailInfoPanel.isVisible()) {
500 detailInfoPanel.setVisible(false);
502 detailInfoPanel.setVisible(true);
507 * 書き込みメッセージボックスの表示ONOFFボタンを押した時の動作
510 public void actionShowTweetboxButton(ActionEvent e) {
511 if( this.tweetBoxScrollPane.isVisible() ) {
512 this.tweetBoxScrollPane.setVisible(false);
514 this.tweetBoxScrollPane.setVisible(true);
521 public void actionRemoveFocusedTabbedTable() {
522 int selected = this.tweetMainTab.getSelectedIndex();
523 int deleteTabIndex = selected;
525 if( deleteTabIndex >= 0 ) {
527 this.tweetMainTab.remove(deleteTabIndex);
528 int tabSetNum = this.tweetTabbedTableList.get(deleteTabIndex).getTabSetNum();
530 String timerID = this.tweetTabbedTableList.get(deleteTabIndex).getTimerID();
533 this.tweetTabbedTableList.remove(deleteTabIndex);
535 //削除した分,既存のタブ番号を1つずつずらさなければならない
536 int tabNum = this.tweetTabbedTableList.size();
537 for(int i = tabSetNum; i < tabNum; i++) {
538 TweetTabbedTable table = this.tweetTabbedTableList.get( i );
539 table.setTabSetNum( table.getTabSetNum() - 1);
543 this.tweetTaskManager.shutdownTask( timerID );
545 TimerID idManager = TimerID.getInstance();
546 idManager.removeID(timerID);
555 public void actionExitButton(ActionEvent e) {
562 public void actionOpenStatusURL() {
565 String userName = this.currentStatus.getUser().getScreenName();
567 long statusID = this.currentStatus.getId();
568 Desktop.getDesktop().browse(
569 new URI(TWITTER_URL + userName + "/statuses/" + statusID));
570 } catch (Exception ex) {
571 ex.printStackTrace();
572 JOptionPane.showMessageDialog(null, "エラーによりブラウザを起動できませんでした.",
573 "Error", JOptionPane.ERROR_MESSAGE);
580 public void actionOpenUserURL() {
582 String userName = this.currentStatus.getUser().getScreenName();
583 Desktop.getDesktop().browse(new URI(TWITTER_URL + userName));
584 } catch (Exception ex) {
585 ex.printStackTrace();
586 JOptionPane.showMessageDialog(null, "エラーによりブラウザを起動できませんでした.",
587 "Error", JOptionPane.ERROR_MESSAGE);
594 public void actionRefreshTime() {
596 for(TweetTabbedTable t : this.tweetTabbedTableList ) {
597 TweetTableModel model = t.getModel();
598 if( model != null ) {
605 * TweetMessageBox内にある#ハッシュタグ の部分をa hrefリンクに変換
609 public String actionReplaceTweetMessageBoxHashTab(String message) {
611 Pattern userPtn = Pattern.compile("#[0-9A-Z_]+",
612 Pattern.CASE_INSENSITIVE);
613 Matcher matcher = userPtn.matcher(message);
615 * if( matcher.matches() ) { matcher. }
618 Set<String> findList = new TreeSet<String>();
619 while (matcher.find()) {
620 findList.add(matcher.group(0));
623 for (String f : findList) {
625 message = message.replaceAll(f, "<a href=\""
626 + SEARCH_TWITTER_URL + SEARCH_QUERY
627 + URLEncoder.encode(f, DEFAULT_CHARACTER_ENCODING)
628 + "\">" + f + "</a>");
629 } catch (UnsupportedEncodingException e) {
637 * TweetMessageBox内にあるリンクをa hrefリンクに変換
641 public String actionReplaceTweetMessageBoxURLLink(String message) {
642 Matcher matcher = convURLLinkPtn.matcher(message);
643 return matcher.replaceAll("<a href=\"$0\">$0</a>");
647 * @ユーザ名の部分をa hrefリンクに変換
650 public String actionReplaceTweetMessageBoxUserInfo(String message) {
652 Pattern userPtn = Pattern.compile("@[0-9A-Z_]+",
653 Pattern.CASE_INSENSITIVE);
654 Matcher matcher = userPtn.matcher(message);
656 Set<String> findList = new TreeSet<String>();
657 while (matcher.find()) {
658 findList.add(matcher.group(0));
660 // 指定したユーザ名をすべてリンクへ変更
661 for (String f : findList) {
662 message = message.replaceAll(f, "<a href=\"" + TWITTER_URL
663 + f.substring(1) + "\">" + f + "</a>");
669 * まだ見ていないdirectMessage数を0にする
671 public void actionResetUncheckedDirectMessageCount() {
672 uncheckedDirectMessageCount = 0;
673 tweetMainTab.setTitleAt(2, TAB_DIRECT_MESSAGE_STRING);
677 * まだ見ていないmention数を0にする
679 public void actionResetUncheckedMentionTweetCount() {
680 uncheckedMentionTweetCount = 0;
681 tweetMainTab.setTitleAt(1, TAB_MENTION_STRING);
687 public void actionResetUncheckedTimelineTweetCount() {
688 uncheckedTimelineTweetCount = 0;
689 tweetMainTab.setTitleAt(0, TAB_TIMELINE_STRING);
693 * 現在選択しているステータスを公式Retweet
695 public void actionRetweet() {
696 // 選択しているtweetのstatus id
697 long statusID = this.currentStatus.getId();
699 String username = this.currentStatus.getUser().getScreenName();
701 String message = this.currentStatus.getText();
703 if (message.length() > 30) {
704 message = message.substring(0, 30) + " ...(以下略)";
706 // Retweetしていいかどうかの確認
707 int ret = JOptionPane.showConfirmDialog(mainFrame, username + " さんの発言:"
708 + message + "\nをRetweetしますか?", "Retweetの確認",
709 JOptionPane.YES_NO_OPTION);
710 if (ret == JOptionPane.YES_OPTION) {
713 this.tweetManager.retweet(statusID);
714 } catch (TwitterException e) {
715 JOptionPane.showMessageDialog(null, "エラーによりRetweetできませんでした.",
716 "Retweet Error", JOptionPane.ERROR_MESSAGE);
726 public void updateTableHeight(int height) {
727 this.tableElementHeight = height;
728 for( TweetTabbedTable t : this.tweetTabbedTableList) {
729 t.getTable().setRowHeight(tableElementHeight);
736 public void actionShowDirectMessageDialog() {
737 // ダイレクトメッセージ送信用ダイアログを開く
738 Point loc = getDirectMessageDialog().getLocation();
739 //loc.translate(20, 20);
740 DirectMessageDialog dialog = getDirectMessageDialog();
741 //dialog.setLocation(loc);
742 dialog.setLocationRelativeTo(null);
743 dialog.setVisible(true);
744 dialog.setUserInformation(this.selectedUsername,
745 this.selectedUserImageURL, this.tweetManager);
751 public void actionShowAboutDialog() {
752 Point loc = getDirectMessageDialog().getLocation();
753 //loc.translate(20, 20);
754 AboutDialog dialog = getAboutDialog();
755 dialog.setLocationRelativeTo(null);
756 //dialog.setLocation(loc);
757 dialog.setVisible(true);
763 public void actionShowAccountDialog() {
764 Point loc = getDirectMessageDialog().getLocation();
765 //loc.translate(20, 20);
766 AccountDialog dialog = getAccountDialog();
767 dialog.setLocationRelativeTo(null);
768 // dialog.setLocation(loc);
769 dialog.setVisible(true);
773 * Twitter全体からキーワード検索ダイアログを表示
775 public void actionShowKeywordSearchDialog() {
776 Point loc = getDirectMessageDialog().getLocation();
777 KeywordSearchDialog dialog = getKeywordSearchDialog();
778 dialog.setLocationRelativeTo(null);
779 dialog.setVisible(true);
783 * tweetBoxPaneに書かれた文字をつぶやく
785 public void actionTweet() {
786 tweetManager.tweet(tweetBoxPane.getText());
787 tweetBoxPane.setText(""); // テキストをクリア
795 public void actionUpdateButton(java.awt.event.ActionEvent e) {
798 for(TweetTabbedTable t : this.tweetTabbedTableList ) {
799 t.updateTweetTable();
803 int remainingHits = tweetManager.getRateLimitStatus().getRemainingHits();
804 // 取得したコメント数をステータスバーに表示
805 information("新しいツイートを取得しました. (APIリクエスト残数は" + remainingHits
807 } catch (Exception e1) {
808 e1.printStackTrace();
817 public void actionUpdateTweetMessageCount() {
818 int len = 140 - (tweetBoxPane.getText().length());
822 tweetMessageCountLabel.setText(len + "");
830 public ConfigurationDialog getConfigurationDialog() {
831 if (configurationDialog == null) {
832 configurationDialog = new ConfigurationDialog(mainFrame, this);
834 return configurationDialog;
838 * twitter全体からキーワード検索ダイアログを表示
841 public KeywordSearchDialog getKeywordSearchDialog() {
842 if( keywordSearchDialog == null ) {
843 keywordSearchDialog = new KeywordSearchDialog(mainFrame, true, this);
845 return keywordSearchDialog;
852 public AccountDialog getAccountDialog() {
853 if( accountDialog == null ) {
854 accountDialog = new AccountDialog(mainFrame, true, tweetManager, this);
856 return accountDialog;
860 * ダイレクトメッセージ送信用ダイアログを取得
864 public DirectMessageDialog getDirectMessageDialog() {
865 if (directMessageDialog == null) {
866 directMessageDialog = new DirectMessageDialog(mainFrame);
867 directMessageDialog.setTitle("ダイレクトメッセージを送信");
869 return directMessageDialog;
873 * テーブルで選択したツイートを詳細情報としてセット
876 public void setDetailInformationFromTable(JTable table) {
877 int sc = table.getSelectedRowCount();
878 String infoMessage = "";
881 Status st = getTweetTableInformation(table, table.getModel());
882 infoMessage = st.getText();
883 // tweetMessageBox内のURLをhtmlリンクへ変換
884 infoMessage = actionReplaceTweetMessageBoxURLLink(infoMessage);
886 infoMessage = actionReplaceTweetMessageBoxUserInfo(infoMessage);
887 // #ハッシュタグ情報をhtmlリンクへ変換
888 infoMessage = actionReplaceTweetMessageBoxHashTab(infoMessage);
889 // 詳細情報にテーブルで選択した人のツイート情報を表示
890 tweetMessageBox.setText(infoMessage);
892 userImageLabel.setIcon(new ImageIcon(st.getUser().getProfileImageURL()));
894 userNameLabel.setText(st.getUser().getName()
895 + " / " + st.getUser().getScreenName());
897 updateTimeLabel.setText(DateFormat.getInstance().format( st.getCreatedAt() ));
899 userIntroBox.setText(st.getUser().getDescription());
901 followerLabel.setText(st.getUser().getFollowersCount()
904 followingLabel.setText(st.getUser().getFriendsCount()
907 locationLabel.setText(st.getUser().getLocation());
909 if (st.getUser().getURL() != null) {
910 userWebBox.setText("<a href=\""
911 + st.getUser().getURL() + "\">"
912 + st.getUser().getScreenName()
913 + "のWebを開く" + "</a>");
915 userWebBox.setText("");
918 clientNameLabel.setText(" via " + st.getSource());
920 updateLabel.setText(st.getUser().getStatusesCount()
929 public AboutDialog getAboutDialog() {
930 if (aboutDialog == null) {
931 aboutDialog = new AboutDialog(mainFrame, true);
937 * テーブルで選択した場所のTweet情報を取得
941 public Status getTweetTableInformation(JTable table, TableModel model) {
942 int index = table.convertRowIndexToModel(table.getSelectedRow());
943 Status status = null;
944 if (model instanceof TweetTableModel) {
945 status = ((TweetTableModel) model).getTweetStatus(index);
946 // 現在選択したセルのユーザ名を保存しておく
947 this.selectedUsername = status.getUser().getScreenName();
948 // 現在選択したセルのユーザURLを保存しておく
949 this.selectedUserImageURL = status.getUser().getProfileImageURL();
951 this.currentStatus = status;
961 public void information(String message) {
962 statusBarLabel.setText(message);
968 * @throws IOException
969 * @throws FileNotFoundException
971 public void loadProperties() throws FileNotFoundException, IOException {
972 if (property == null) {
973 this.property = new Properties();
975 property.load(new FileInputStream("./" + PROPERTIES_DIRECTORY + "/"
976 + BASIC_SETTING_FILENAME));
978 String gtp = this.property.getProperty("getTimelinePeriod");
979 String gmp = this.property.getProperty("getMentionPeriod");
980 String gdmp = this.property.getProperty("getDirectMessagePeriod");
981 String gsdmp = this.property.getProperty("getSendDirectMessagePeriod");
983 String ntrgb = this.property.getProperty("newTableColorRGB");
985 this.tlFontName = this.property.getProperty("tlFontName");
986 this.detailFontName = this.property.getProperty("detailFontName");
988 String tfs = this.property.getProperty("tlFontSize");
989 String dfs = this.property.getProperty("detailFontSize");
990 String teh = this.property.getProperty("tableElementHeight");
993 String mfw = this.property.getProperty("mainFrameWidth");
994 String mfh = this.property.getProperty("mainFrameHeight");
997 this.newTableColor = new Color(Integer.parseInt(ntrgb));
998 this.tlFontSize = Integer.parseInt(tfs);
999 this.detailFontSize = Integer.parseInt(dfs);
1000 this.tableElementHeight = Integer.parseInt(teh);
1001 this.mainFrameWidth = Integer.parseInt(mfw);
1002 this.mainFrameHeight = Integer.parseInt(mfh);
1005 this.getTimelinePeriod = Integer.parseInt(gtp);
1006 this.getMentionPeriod = Integer.parseInt(gmp);
1007 this.getDirectMessagePeriod = Integer.parseInt(gdmp);
1008 this.getSendDirectMessagePeriod = Integer.parseInt(gsdmp);
1009 } catch (NumberFormatException e) {
1010 e.printStackTrace();
1017 * @throws IOException
1019 public void saveProperties() throws IOException {
1021 File logDir = new File("./" + PROPERTIES_DIRECTORY);
1022 if (!logDir.exists()) {
1023 // ディレクトリが存在しないので作成する
1024 if (logDir.mkdir() == false) {
1025 throw new IOException(PROPERTIES_DIRECTORY
1026 + "ディレクトリを作成できませんでした.");
1029 if (property == null) {
1030 this.property = new Properties();
1034 this.property.setProperty("getTimelinePeriod", this.getTimelinePeriod + "");
1035 this.property.setProperty("getMentionPeriod", this.getMentionPeriod + "");
1036 this.property.setProperty("getDirectMessagePeriod", this.getDirectMessagePeriod + "");
1037 this.property.setProperty("getSendDirectMessagePeriod", this.getSendDirectMessagePeriod + "");
1039 this.property.setProperty("newTableColorRGB", newTableColor.getRGB()
1041 this.property.setProperty("tlFontName", this.tlFontName);
1042 this.property.setProperty("tlFontSize", this.tlFontSize + "");
1043 this.property.setProperty("detailFontName", this.detailFontName);
1044 this.property.setProperty("detailFontSize", this.detailFontSize + "");
1045 this.property.setProperty("tableElementHeight", this.tableElementHeight
1049 if( this.mainFrame.getExtendedState() == JFrame.NORMAL ) {
1050 this.mainFrameWidth = this.mainFrame.getWidth();
1051 this.mainFrameHeight = this.mainFrame.getHeight();
1053 this.property.setProperty("mainFrameWidth", this.mainFrameWidth + "");
1054 this.property.setProperty("mainFrameHeight", this.mainFrameHeight + "");
1056 property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
1057 + BASIC_SETTING_FILENAME), null);
1061 * newTableColorを取得します。
1063 * @return newTableColor
1065 public Color getNewTableColor() {
1066 return newTableColor;
1070 * newTableColorを設定します。
1072 * @param newTableColor
1075 public void setNewTableColor(Color newTableColor) {
1076 this.newTableColor = newTableColor;
1082 * @return tlFontName
1084 public String getTlFontName() {
1094 public void setTlFontName(String tlFontName) {
1095 this.tlFontName = tlFontName;
1101 * @return tlFontSize
1103 public int getTlFontSize() {
1113 public void setTlFontSize(int tlFontSize) {
1114 this.tlFontSize = tlFontSize;
1118 * detailFontNameを取得します。
1120 * @return detailFontName
1122 public String getDetailFontName() {
1123 return detailFontName;
1127 * detailFontNameを設定します。
1129 * @param detailFontName
1132 public void setDetailFontName(String detailFontName) {
1133 this.detailFontName = detailFontName;
1137 * detailFontSizeを取得します。
1139 * @return detailFontSize
1141 public int getDetailFontSize() {
1142 return detailFontSize;
1146 * detailFontSizeを設定します。
1148 * @param detailFontSize
1151 public void setDetailFontSize(int detailFontSize) {
1152 this.detailFontSize = detailFontSize;
1156 * tableElementHeightを取得します。
1158 * @return tableElementHeight
1160 public int getTableElementHeight() {
1161 return tableElementHeight;
1165 * tableElementHeightを設定します。
1167 * @param tableElementHeight
1168 * tableElementHeight
1170 public void setTableElementHeight(int tableElementHeight) {
1171 this.tableElementHeight = tableElementHeight;
1175 * @return the getTimelinePeriod
1177 public int getGetTimelinePeriod() {
1178 return getTimelinePeriod;
1182 * @param getTimelinePeriod the getTimelinePeriod to set
1184 public void setGetTimelinePeriod(int getTimelinePeriod) {
1185 this.getTimelinePeriod = getTimelinePeriod;
1189 * @return the getMentionPeriod
1191 public int getGetMentionPeriod() {
1192 return getMentionPeriod;
1196 * @param getMentionPeriod the getMentionPeriod to set
1198 public void setGetMentionPeriod(int getMentionPeriod) {
1199 this.getMentionPeriod = getMentionPeriod;
1203 * @return the getDirectMessagePeriod
1205 public int getGetDirectMessagePeriod() {
1206 return getDirectMessagePeriod;
1210 * @param getDirectMessagePeriod the getDirectMessagePeriod to set
1212 public void setGetDirectMessagePeriod(int getDirectMessagePeriod) {
1213 this.getDirectMessagePeriod = getDirectMessagePeriod;
1217 * @return the getSendDirectMessagePeriod
1219 public int getGetSendDirectMessagePeriod() {
1220 return getSendDirectMessagePeriod;
1224 * @param getSendDirectMessagePeriod the getSendDirectMessagePeriod to set
1226 public void setGetSendDirectMessagePeriod(int getSendDirectMessagePeriod) {
1227 this.getSendDirectMessagePeriod = getSendDirectMessagePeriod;