import java.net.URLEncoder;
import java.text.DateFormat;
import java.util.ArrayList;
+import java.util.BitSet;
import java.util.Comparator;
import java.util.List;
+import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
+
+import org.xml.sax.SAXParseException;
+
import twitter.action.TweetDirectMessageGetter;
import twitter.action.TweetFavoriteGetter;
import twitter.action.TweetGetter;
import twitter.gui.form.AccountDialog;
import twitter.gui.form.ConfigurationDialog;
import twitter.gui.form.DirectMessageDialog;
+import twitter.gui.form.FollowingFollowerDialog;
import twitter.gui.form.HashtagSearchDialog;
import twitter.gui.form.KeywordSearchDialog;
+import twitter.gui.form.OutputCSVLogDialog;
import twitter.gui.form.UserListDialog;
+import twitter.gui.form.UserSearchDialog;
+import twitter.log.TwitterLogManager;
import twitter.manage.TweetConfiguration;
import twitter.manage.TweetManager;
+import twitter.manage.URLBitlyConverter;
import twitter.task.ExistTimerIDException;
import twitter.task.TimerID;
import twitter.task.TweetTaskException;
import twitter.util.HTMLEncode;
import twitter4j.Status;
import twitter4j.TwitterException;
+import twitter4j.User;
/**
* GUIのアクション部分
- *
+ *
* @author nishio
- *
+ *
*/
public class TweetMainAction {
// Send Direct Messageタブに表示する文字
public static final String TAB_SEND_DIRECT_MESSAGE_STRING = "Send";
// テーブルのデータ量が以下の値を超えたら古いデータから削除
- private static final int TABLE_ELEMENT_MAX_SIZE = 200;
+ private static int tableElementMaxSize = 200;
// twitterの公式URL
private static final String TWITTER_URL = "http://twitter.com/";
// 基本設定用ダイアログ
// 自分宛のメッセージを通知バーに表示するか
private boolean isNotifyMentionMessage = true;
private boolean isNotifyDirectMessage = true;
+ //前回開いていたタブの情報を復活する際に利用する(最初の一回だけ利用)
+ private boolean isTempOpenedTimelineTab = true;
+ private boolean isTempOpenedMentionTab = true;
+ private boolean isTempOpenedDMTab = true;
+ private boolean isTempOpenedSendDMTab = true;
+ //ログを保存するかどうか
+ private boolean saveLog = false;
// Tweetの詳細情報を表示する部分
private JLabel userImageLabel = null;
// リストダイアログ
private UserListDialog userListDialog = null;
+ //ユーザサーチダイアログ
+ private UserSearchDialog userSearchDialog = null;
+ //CSVログ出力ダイアログ
+ private OutputCSVLogDialog outputCSVLogDialog = null;
+ //following follower表示ダイアログ
+ private FollowingFollowerDialog followingFollowerDialog = null;
// 情報更新間隔[sec]
private int getTimelinePeriod = 60;
private int getSendDirectMessagePeriod = 60 * 30;
/**
- *
+ *
* @param mainFrame
* @param tweetManager
* @param statusBarLabel
/**
* 新しいタブを追加
- *
+ *
* @param timerID
* TimerIDクラスで生成したタイマーID
* @param period
final TweetTabbedTable table = new TweetTabbedTable(
tweetGetter, tabTitle, this.tweetMainTab,
this.tableElementHeight, this.tweetManager, this,
- newTableColor, TABLE_ELEMENT_MAX_SIZE, timerID);
+ newTableColor, this.tableElementMaxSize, timerID);
this.tweetTaskManager.addTask(timerID, new TweetUpdateTask() {
table.addTableToTab();
// タブリストに追加
this.tweetTabbedTableList.add(table);
+ //設定を保存
+ this.saveProperties();
// searchTable.updateTweetTable();
// フォーカスを新しいタブに移す
this.actionRequestForusToLastTab();
} catch (TweetTaskException ex) {
Logger.getLogger(TweetMainAction.class.getName()).log(
Level.SEVERE, null, ex);
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
/**
* mentionタブを追加する
- *
+ *
* @param period
* 情報更新間隔[sec]
*/
/**
* お気に入りタブを追加
- *
+ *
* @param screenName
* nullで自分自身を取得,指定するとscreenNameのFav取得
*/
/**
* timelineタブを追加する
- *
+ *
* @param period
* [sec]
*/
// 既にIDが存在していたらここで例外発生
timerID.addID(id);
// 検索結果を表示するタブを生成
- actionAddTab(id, period, new TweetTimelineGetter(tweetManager),
+ actionAddTab(id, period, new TweetTimelineGetter(tweetManager, this),
TweetMainAction.TAB_TIMELINE_STRING);
} catch (ExistTimerIDException ex) {
JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
/**
* ダイレクトメッセージタブを追加する
- *
+ *
* @param period
* 更新間隔[sec]
*/
/**
* SendDMタブを追加する
- *
+ *
* @param period
*/
public void actionAddSendDirectMessageTab(int period) {
/**
* 指定したリストをタブに追加
- *
+ *
* @param username
* @param listID
* @param listFullname
/**
* ツイート検索結果を表示するタブを新しく追加
- *
+ *
* @param searchWord
* @param period
* 更新周期[sec] 0以下の場合は更新しない
/**
* 指定したユーザの発言を表示
- *
+ *
* @param username
* タブのタイトルにつけるユーザ名
- * @param userID
- * ユーザID
* @param period
* 更新周期[sec]
*/
- public void actionAddUserTimelineTab(String username, long userID,
+ public void actionAddUserTimelineTab(String username,
int period) {
TimerID timerID = TimerID.getInstance();
- String id = TimerID.createUserTimelineID(userID);
+ String id = TimerID.createUserTimelineID(username);
try {
// 既にIDが存在していたらここで例外発生
timerID.addID(id);
// 検索結果を表示するタブを生成
actionAddTab(id, period, new TweetUserTimelineGetter(tweetManager,
- userID), username + "の発言");
+ username), username + "の発言");
} catch (ExistTimerIDException ex) {
JOptionPane.showMessageDialog(null, "そのタブは既に存在しています", "Error",
JOptionPane.ERROR_MESSAGE);
/**
* タイムラインタブが存在しているか
- *
+ *
* @return
*/
public boolean isExistTimelineTab() {
/**
* Mentionタブが存在するか
- *
+ *
* @return
*/
public boolean isExistMentionTab() {
/**
* DMタブが存在するか
- *
+ *
* @return
*/
public boolean isExistDirectMessageTab() {
/**
* 送信済みDMタブが存在するか
- *
+ *
* @return
*/
public boolean isExistSendDirectMessageTab() {
/**
* 詳細情報表示ボタンを押した時の動作
- *
+ *
* @param e
*/
public void actionDetailInfoButton(ActionEvent e) {
/**
* 詳細情報ボタンが表示されているか
- *
+ *
* @return
*/
public boolean isDetailInfoPanelVisible() {
/**
* 書き込みメッセージボックスの表示ONOFFボタンを押した時の動作
- *
+ *
* @param e
*/
public void actionShowTweetboxButton(ActionEvent e) {
/**
* 指定したIDのタブを削除
- *
+ *
* @param timerID
*/
public void actionRemoveTabbedTable(String timerID) {
break;
}
}
-
- if (deleteTabIndex >= 0) {
- int selected = this.tweetTabbedTableList.get(deleteTabIndex)
- .getTabSetNum();
- // タブを削除
- this.tweetMainTab.remove(selected);
- // 削除
- this.tweetTabbedTableList.remove(deleteTabIndex);
- // 自動更新しているタブを削除
- this.tweetTaskManager.shutdownTask(timerID);
- // ID削除
- TimerID idManager = TimerID.getInstance();
- idManager.removeID(timerID);
-
- // checkboxの状態更新
- this.updateCheckboxInformation();
- }
+ actionRemoveTabbedTable(deleteTabIndex);
}
/**
* 指定した場所にあるタブを削除
- *
+ *
* @param removeTabIndex
*/
public void actionRemoveTabbedTable(int removeTabIndex) {
String timerID = this.tweetTabbedTableList.get(deleteTabIndex)
.getTimerID();
// 削除
+ TweetTabbedTable table = this.tweetTabbedTableList.get(deleteTabIndex);
+ if( table != null ) {
+ //streaming api使っている場合はlistenerをストップ
+ TweetGetter getter = table.getTweetGetter();
+ if( getter != null ) {
+ //streaming apiのストップ
+ getter.stopUpdateListener();
+ }
+ }
+ // 削除
this.tweetTabbedTableList.remove(deleteTabIndex);
// 自動更新しているタブを削除
this.tweetTaskManager.shutdownTask(timerID);
// checkboxの状態更新
this.updateCheckboxInformation();
+ //設定保存
+ try {
+ saveProperties();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
/**
* 終了ボタンを押した時の動作
- *
+ *
* @param e
*/
public void actionExitButton(ActionEvent e) {
}
}
+ /**
+ * 選択したユーザのfollowingを表示
+ */
+ public void actionOpenFollowing() {
+ // ユーザ名
+ try {
+ String userName = this.getCurrentStatus().getUser().getScreenName();
+ this.actionShowFollowingFollowerDialog(userName, true);
+ }catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 選択したユーザのfollowingを表示
+ */
+ public void actionOpenFollower() {
+ try {
+ // ユーザ名
+ String userName = this.getCurrentStatus().getUser().getScreenName();
+ this.actionShowFollowingFollowerDialog(userName, false);
+ }catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
/**
* 選択したユーザのFavを開く
*/
/**
* TweetMessageBox内にある#ハッシュタグ の部分をa hrefリンクに変換
- *
+ *
* @param message
*/
public String actionReplaceTweetMessageBoxHashTab(String message) {
// #で始まる情報
- Pattern userPtn = Pattern.compile("#[0-9A-Z_]+",
+ Pattern userPtn = Pattern.compile( TweetConfiguration.HASHTAG_PATTERN,
Pattern.CASE_INSENSITIVE);
Matcher matcher = userPtn.matcher(message);
/**
* TweetMessageBox内にあるリンクをa hrefリンクに変換
- *
+ *
* @param message
*/
public String actionReplaceTweetMessageBoxURLLink(String message) {
}
/**
+ * メッセージ内にあるURLをBitlyに変換する
+ * @param message
+ * @return
+ */
+ public String actionConvertURLToBitly(String message) {
+ String result = new String( message );
+ //URLをbitlyに変換
+ Matcher matcher = convURLLinkPtn.matcher(message);
+ while( matcher.find() ) {
+ String source = matcher.group();
+ String conv = URLBitlyConverter.convertUrlToBitly( source );
+ result = result.replace( source , conv );
+ }
+ return result;
+ }
+
+ /**
+ * つぶやきボックス内のURLをbitlyに変換
+ */
+ public void actionConvertTweetBoxURLToBitly() {
+ String message = this.tweetBoxPane.getText();
+ String conv = actionConvertURLToBitly(message);
+ this.tweetBoxPane.setText( conv );
+ }
+
+ /**
* @ユーザ名の部分をa hrefリンクに変換
* @param message
*/
status = this.getCurrentStatus();
}
String username = status.getUser().getScreenName();
- long userID = status.getUser().getId();
// ユーザ
- actionAddUserTimelineTab(username, userID, this.getGetTimelinePeriod());
+ actionAddUserTimelineTab(username, this.getGetTimelinePeriod());
}
/**
* 選択したユーザが作成したリスト一覧を表示
- *
+ *
* @param selection
*/
public void actionShowSelectedUserList(ListGetterSelection selection) {
/**
* テーブルの高さを更新
- *
+ *
* @param height
*/
public void updateTableHeight(int height) {
/**
* Twitter全体からキーワード検索ダイアログを表示
- *
+ *
* @param searchWord
* searchwordボックスに予め設定するワード
*/
dialog.setVisible(true);
}
+ /**
+ * 指定したユーザ検索ダイアログを表示
+ */
+ public void actionShowUserSearchDialog() {
+ UserSearchDialog dialog = getUserSearchDialog();
+ dialog.setLocationRelativeTo(null);
+ dialog.setVisible(true);
+ }
+
+ /**
+ * CSVログ出力ダイアログを表示
+ */
+ public void actionShowOutputCSVLogDialog() {
+ OutputCSVLogDialog dialog = getOutputCSVLogDialog();
+ dialog.setLocationRelativeTo(null);
+ dialog.setVisible(true);
+ }
+
+ /**
+ * following follower表示ダイアログを表示
+ */
+ public void actionShowFollowingFollowerDialog() {
+ FollowingFollowerDialog dialog = getFollowingFollowerDialog();
+ dialog.setLocationRelativeTo(null);
+ dialog.setVisible(true);
+ }
+
+ /**
+ * following follower表示ダイアログを表示
+ * @param username 取得したいユーザ
+ * @param ff trueでfollowing/ falseでfollower取得
+ */
+ public void actionShowFollowingFollowerDialog(String username, boolean ff) {
+ FollowingFollowerDialog dialog = getFollowingFollowerDialog();
+ //following follower取得開始
+ dialog.actionUserSearch(username, ff);
+
+ dialog.setLocationRelativeTo(null);
+ dialog.setVisible(true);
+ }
+
/**
* ハッシュタグ検索ダイアログを表示
*/
/**
* リストダイアログを表示
- *
+ *
* @param listUserName
* リストを保持しているユーザの名前
* @param selection
/**
* Tweet情報を更新
- *
+ *
* @param e
*/
public void actionUpdateButton(java.awt.event.ActionEvent e) {
/**
* 指定した番号のタブにフォーカスを移す
- *
+ *
* @param index
*/
public void actionRequestFocusToTab(int index) {
/**
* つぶやける残り文字数の更新
- *
+ *
* @param e
*/
public void actionUpdateTweetMessageCount() {
}
/**
+ * デバッグ用
+ */
+ public void debug() {
+ //this.actionShowFollowingFollowerDialog("nishio_dens", false);
+ }
+
+ /**
+ * ログデータを保存
+ * @param outputFilePath
+ * @param showUsername
+ * @param showScreenName
+ * @param showText
+ * @param showUpdateTime
+ * @param showClient
+ * @param showUserDescription
+ * @param showFollowing
+ * @param showFollower
+ * @param showUpdateCount
+ * @param showUserURL
+ * @param showProfileImageURL
+ * @throws SAXParseException
+ * @throws IOException
+ */
+ public void outputLogToCSV(String outputFilePath,
+ boolean showUsername, boolean showScreenName,
+ boolean showText,
+ boolean showUpdateTime, boolean showClient,
+ boolean showUserDescription,
+ boolean showFollowing, boolean showFollower,
+ boolean showUpdateCount, boolean showUserURL,
+ boolean showProfileImageURL) throws SAXParseException, IOException {
+ TwitterLogManager logManager = new TwitterLogManager();
+ List<Status> statuses = logManager.get();
+
+ logManager.outputCSVLog( outputFilePath, statuses, showUsername, showScreenName,
+ showText, showUpdateTime, showClient,
+ showUserDescription, showFollowing, showFollower,
+ showUpdateCount, showUserURL,showProfileImageURL);
+ }
+
+ /**
* 基本設定用ダイアログを取得
- *
+ *
* @return
*/
public ConfigurationDialog getConfigurationDialog() {
/**
* リストダイアログを取得
- *
+ *
* @param listUserName
* リストを保持しているユーザの名前
* @param selection
/**
* 自身のスクリーン名を取得
- *
+ *
* @return
*/
public String getScreenName() {
/**
* twitter全体からキーワード検索ダイアログを表示
- *
+ *
* @return
*/
public KeywordSearchDialog getKeywordSearchDialog() {
return keywordSearchDialog;
}
+ /**
+ * ユーザ検索ダイアログを表示
+ * @return
+ */
+ public UserSearchDialog getUserSearchDialog() {
+ if( this.userSearchDialog == null ) {
+ this.userSearchDialog = new UserSearchDialog(mainFrame, true, this);
+ }
+ return this.userSearchDialog;
+ }
+
+ /**
+ * CSVログ出力ダイアログを表示
+ * @return
+ */
+ public OutputCSVLogDialog getOutputCSVLogDialog() {
+ if( this.outputCSVLogDialog == null ) {
+ this.outputCSVLogDialog = new OutputCSVLogDialog(mainFrame, true, this);
+ }
+ return this.outputCSVLogDialog;
+ }
+
+ /**
+ * Following follower表示ダイアログ
+ * @return
+ */
+ public FollowingFollowerDialog getFollowingFollowerDialog() {
+ if( this.followingFollowerDialog == null ) {
+ this.followingFollowerDialog =
+ new FollowingFollowerDialog(mainFrame, true, this.tweetManager);
+ }
+ return this.followingFollowerDialog;
+ }
+
/**
* hashtag検索ダイアログ
- *
+ *
* @return
*/
public HashtagSearchDialog getHashtagSearchDialog() {
/**
* アカウント情報設定ダイアログを取得
- *
+ *
* @return
*/
public AccountDialog getAccountDialog() {
/**
* ダイレクトメッセージ送信用ダイアログを取得
- *
+ *
* @return
*/
public DirectMessageDialog getDirectMessageDialog() {
/**
* テーブルで選択したツイートを詳細情報としてセット
- *
+ *
* @param table
*/
public void setDetailInformationFromTable(JTable table) {
}
/**
- *
+ *
* @return
*/
public AboutDialog getAboutDialog() {
/**
* テーブルで選択した場所のTweet情報を取得
- *
+ *
* @return
*/
public Status getTweetTableInformation(JTable table, TableModel model) {
/**
* ステータスバーに情報を表示する
- *
+ *
* @param message
*/
public void information(String message) {
}
/**
+ * 前回タイムラインタブを開いていたか
+ * @return
+ */
+ public boolean isTempOpenedTimelineTab() {
+ return isTempOpenedTimelineTab;
+ }
+
+ /**
+ * 前回メンションタブを開いていたか
+ * @return
+ */
+ public boolean isTempOpenedMentionTab() {
+ return isTempOpenedMentionTab;
+ }
+
+ /**
+ * 前回DMタブを開いていたか
+ * @return
+ */
+ public boolean isTempOpenedDMTab() {
+ return isTempOpenedDMTab;
+ }
+
+ /**
+ * 前回SendDMタブを開いていたか
+ * @return
+ */
+ public boolean isTempOpenedSendDMTab() {
+ return isTempOpenedSendDMTab;
+ }
+
+ /**
* 設定ファイルを読み込む
- *
+ *
* @throws IOException
* @throws FileNotFoundException
*/
String nm = this.property.getProperty("notifyMention");
String ndm = this.property.getProperty("notifyDirectMessage");
+ //前回開いていたタブの情報
+ String ptl = this.property.getProperty("openTimelineTab");
+ String pm = this.property.getProperty("openMentionTab");
+ String podm = this.property.getProperty("openDirectMessageTab");
+ String posdmt = this.property.getProperty("openSendDirectMessageTab");
+
+ //ログ
+ String log = this.property.getProperty("saveLog");
+
+ //表示可能ツイート数
+ String nost = this.property.getProperty("numOfShowTweet");
+
try {
this.newTableColor = new Color(Integer.parseInt(ntrgb));
this.tlFontSize = Integer.parseInt(tfs);
// 通知関係
this.isNotifyMentionMessage = Boolean.parseBoolean(nm);
this.isNotifyDirectMessage = Boolean.parseBoolean(ndm);
+
+ //前回開いていたタブ情報
+ this.isTempOpenedTimelineTab = Boolean.parseBoolean(ptl);
+ this.isTempOpenedMentionTab = Boolean.parseBoolean(pm);
+ this.isTempOpenedDMTab = Boolean.parseBoolean(podm);
+ this.isTempOpenedSendDMTab = Boolean.parseBoolean(posdmt);
+
+ //ログ
+ this.saveLog = Boolean.parseBoolean(log);
+
+ //表示可能ツイート数
+ this.tableElementMaxSize = Integer.parseInt(nost);
} catch (NumberFormatException e) {
e.printStackTrace();
}
/**
* 設定ファイルを保存する
- *
+ *
* @throws IOException
*/
public void saveProperties() throws IOException {
this.property.setProperty("notifyDirectMessage",
this.isNotifyDirectMessage + "");
+ //タブの保存
+ this.property.setProperty("openTimelineTab", this.isExistTimelineTab() + "");
+ this.property.setProperty("openMentionTab", this.isExistMentionTab() + "");
+ this.property.setProperty("openDirectMessageTab", this.isExistDirectMessageTab() + "");
+ this.property.setProperty("openSendDirectMessageTab", this.isExistSendDirectMessageTab() + "");
+
+ //ログを保存するか
+ this.property.setProperty("saveLog", this.isSaveLog() + "");
+
+ //テーブルに表示可能なツイートの数
+ this.property.setProperty("numOfShowTweet", this.getTableElementMaxSize() + "");
+
// プロパティのリストを保存
property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
+ BASIC_SETTING_FILENAME), null);
/**
* newTableColorを取得します。
- *
+ *
* @return newTableColor
*/
public Color getNewTableColor() {
/**
* newTableColorを設定します。
- *
+ *
* @param newTableColor
* newTableColor
*/
/**
* tlFontNameを取得します。
- *
+ *
* @return tlFontName
*/
public String getTlFontName() {
/**
* tlFontNameを設定します。
- *
+ *
* @param tlFontName
* tlFontName
*/
/**
* tlFontSizeを取得します。
- *
+ *
* @return tlFontSize
*/
public int getTlFontSize() {
/**
* tlFontSizeを設定します。
- *
+ *
* @param tlFontSize
* tlFontSize
*/
/**
* detailFontNameを取得します。
- *
+ *
* @return detailFontName
*/
public String getDetailFontName() {
/**
* detailFontNameを設定します。
- *
+ *
* @param detailFontName
* detailFontName
*/
/**
* detailFontSizeを取得します。
- *
+ *
* @return detailFontSize
*/
public int getDetailFontSize() {
/**
* detailFontSizeを設定します。
- *
+ *
* @param detailFontSize
* detailFontSize
*/
/**
* tableElementHeightを取得します。
- *
+ *
* @return tableElementHeight
*/
public int getTableElementHeight() {
/**
* tableElementHeightを設定します。
- *
+ *
* @param tableElementHeight
* tableElementHeight
*/
}
/**
- *
+ *
* @param notify
*/
public void setNotifyMention(boolean notify) {
}
/**
- *
+ *
* @return
*/
public boolean getNotifyMention() {
}
/**
- *
+ *
* @param notify
* @return
*/
}
/**
- *
+ *
* @return
*/
public boolean getNotifyDirectMessage() {
}
/**
- *
+ *
* @return
*/
public Status getReplyStatus() {
}
/**
- *
+ *
* @param status
* @return
*/
public void setReplyStatus(Status status) {
this.replyStatus = status;
}
+
+ /**
+ * ログを保存するかどうか
+ * @return
+ */
+ public boolean isSaveLog() {
+ return this.saveLog;
+ }
+
+ /**
+ * ログを保存するかどうか設定
+ * @param check
+ */
+ public void setSaveLog(boolean check) {
+ this.saveLog = check;
+ }
+
+ /**
+ * テーブルに一度に表示できる数を設定
+ * @param size
+ */
+ public void setTableElementMaxSize(int size) {
+ if( size > 0 ) {
+ this.tableElementMaxSize = size;
+ }
+ }
+
+ /**
+ * テーブルに一度に表示できる数を取得
+ * @return
+ */
+ public int getTableElementMaxSize() {
+ return this.tableElementMaxSize;
+ }
}