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.DirectMessageDialog;
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のアクション部分
// 自分宛のメッセージを通知バーに表示するか
private boolean isNotifyMentionMessage = true;
private boolean isNotifyDirectMessage = true;
+ //前回開いていたタブの情報を復活する際に利用する(最初の一回だけ利用)
+ private boolean isTempOpenedTimelineTab = true;
+ private boolean isTempOpenedMentionTab = true;
+ private boolean isTempOpenedDMTab = true;
+ private boolean isTempOpenedSendDMTab = true;
// Tweetの詳細情報を表示する部分
private JLabel userImageLabel = null;
// リストダイアログ
private UserListDialog userListDialog = null;
+ //ユーザサーチダイアログ
+ private UserSearchDialog userSearchDialog = null;
+ //CSVログ出力ダイアログ
+ private OutputCSVLogDialog outputCSVLogDialog = null;
// 情報更新間隔[sec]
private int getTimelinePeriod = 60;
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();
}
}
*
* @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);
// checkboxの状態更新
this.updateCheckboxInformation();
+ //設定保存
+ try {
+ saveProperties();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
// checkboxの状態更新
this.updateCheckboxInformation();
+ //設定保存
+ try {
+ saveProperties();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
Matcher matcher = convURLLinkPtn.matcher(message);
return matcher.replaceAll("<a href=\"$0\">$0</a>");
}
+
+ /**
+ * メッセージ内にある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.replaceAll( source , conv );
+ }
+ return result;
+ }
+
+ /**
+ * つぶやきボックス内のURLをbitlyに変換
+ */
+ public void actionConvertTweetBoxURLToBitly() {
+ String message = this.tweetBoxPane.getText();
+ String conv = actionConvertURLToBitly(message);
+ this.tweetBoxPane.setText( conv );
+ }
/**
* @ユーザ名の部分をa hrefリンクに変換
status = this.getCurrentStatus();
}
String username = status.getUser().getScreenName();
- long userID = status.getUser().getId();
// ユーザ
- actionAddUserTimelineTab(username, userID, this.getGetTimelinePeriod());
+ actionAddUserTimelineTab(username, this.getGetTimelinePeriod());
}
/**
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);
+ }
+
/**
* ハッシュタグ検索ダイアログを表示
*/
* tweetBoxPaneに書かれた文字をつぶやく
*/
public void actionTweet() {
- if (this.replyStatus != null) {
- tweetManager.replyTweet(tweetBoxPane.getText(), this.replyStatus
- .getId());
- } else {
- tweetManager.tweet(tweetBoxPane.getText());
+ boolean isTweet = false;
+ try {
+ if (this.replyStatus != null) {
+ tweetManager.replyTweet(tweetBoxPane.getText(),
+ this.replyStatus.getId());
+ } else {
+ tweetManager.tweet(tweetBoxPane.getText());
+ }
+ isTweet = true;
+ } catch (Exception e) {
+ e.printStackTrace();
}
- // ツイートした旨を表示
- this.information("メッセージをつぶやきました. 発言:" + tweetBoxPane.getText());
- tweetBoxPane.setText(""); // テキストをクリア
+ if (isTweet) {
+ // ツイートした旨を表示
+ this.information("メッセージをつぶやきました. 発言:" + tweetBoxPane.getText());
+ tweetBoxPane.setText(""); // テキストをクリア
+ } else {
+ this.information("つぶやきに失敗しました");
+ JOptionPane.showMessageDialog(null,
+ "つぶやきに失敗しました。文字数がオーバーしているか、ツイッターに接続ができませんでした。",
+ "Tweet Error", JOptionPane.ERROR_MESSAGE);
+ }
}
*/
public void actionUpdateTweetMessageCount() {
int len = 140 - (tweetBoxPane.getText().length());
+ boolean over = false;
if (len < 0) {
- len = 0;
+ // len = 0;
+ over = true;
+ }
+
+ if (over) {
+ tweetMessageCountLabel.setForeground(Color.RED);
+ // オーバーしたことを伝える
+ tweetMessageCountLabel.setText("Over(" + len + ")");
+ } else {
+ tweetMessageCountLabel.setForeground(Color.BLACK);
+ // 残り文字数
+ tweetMessageCountLabel.setText(len + "");
}
- tweetMessageCountLabel.setText(len + "");
// 残りつぶやき数140の場合,reply状態も解除する
if (len == 140) {
this.setReplyStatus(null);
}
}
+
+ /**
+ * デバッグ用
+ */
+ public void debug() {
+/* String message = "こんにちは http://densan-labs.net/でした。 http://google.com/ あいうえお";
+ System.out.println( this.actionConvertURLToBitly( message ));*/
+ //this.actionConvertTweetBoxURLToBitly();
+ for(int i=0; i < 5; i++) {
+ List<User> lists = this.tweetManager.getFollowingUser("nishio_dens", i);
+ if( lists != null) {
+ for(User u : lists) {
+ System.out.println( u );
+ }
+ }
+ }
+// String url = "http://google.com";
+// System.out.println( URLBitlyConverter.convertUrlToBitly(url));
+ }
+
+ /**
+ * ログデータを保存
+ * @param logFilePath
+ * @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 logFilePath, 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(logFilePath);
+ logManager.outputCSVLog( outputFilePath, statuses, showUsername, showScreenName,
+ showText, showUpdateTime, showClient,
+ showUserDescription, showFollowing, showFollower,
+ showUpdateCount, showUserURL,showProfileImageURL);
+ }
/**
* 基本設定用ダイアログを取得
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;
+ }
+
/**
* hashtag検索ダイアログ
*
// 詳細情報にテーブルで選択した人のツイート情報を表示
tweetMessageBox.setText(infoMessage);
// user icon
- //アイコンをキャッシュから取得
- ImageIcon icon = TwitterImageCache.getInstance().getProfileImage( st.getUser().getProfileImageURL().toString() );
- userImageLabel.setIcon( icon );
+ // アイコンをキャッシュから取得
+ ImageIcon icon = TwitterImageCache.getInstance().getProfileImage(
+ st.getUser().getProfileImageURL().toString());
+ userImageLabel.setIcon(icon);
// user name and id
userNameLabel.setText(st.getUser().getName() + " / "
+ st.getUser().getScreenName());
}
/**
+ * 前回タイムラインタブを開いていたか
+ * @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
String mfh = this.property.getProperty("mainFrameHeight");
// メッセージ通知を行うか
- String nm = this.property.getProperty("notifyMessage");
+ 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");
try {
this.newTableColor = new Color(Integer.parseInt(ntrgb));
// 通知関係
this.isNotifyMentionMessage = Boolean.parseBoolean(nm);
- this.isNotifyMentionMessage = Boolean.parseBoolean(ndm);
+ 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);
} catch (NumberFormatException e) {
e.printStackTrace();
}
+ "");
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() + "");
// プロパティのリストを保存
property.store(new FileOutputStream("./" + PROPERTIES_DIRECTORY + "/"
}
/**
+ *
+ * @param notify
+ */
+ public void setNotifyMention(boolean notify) {
+ this.isNotifyMentionMessage = notify;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean getNotifyMention() {
+ return this.isNotifyMentionMessage;
+ }
+
+ /**
+ *
+ * @param notify
+ * @return
+ */
+ public void setNotifyDirectMessage(boolean notify) {
+ this.isNotifyDirectMessage = notify;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean getNotifyDirectMessage() {
+ return this.isNotifyDirectMessage;
+ }
+
+ /**
* @param getTimelinePeriod
* the getTimelinePeriod to set
*/