From 08132c27bf13ae56f17149832a1dda0f36096495 Mon Sep 17 00:00:00 2001 From: Suraj Waghulde Date: Mon, 10 Jan 2011 11:42:56 -0800 Subject: [PATCH 1/5] Adding UI to Twitter Topic Count example --- twittertopiccount/TwitterUI.java | 159 +++++++++++++ twittertopiccount/s4.png | 0 .../twittertopiccount/ui/TwitterUI.java | 218 ++++++++++++++++++ twittertopiccount/twitter_topic_count.sh | 1 + 4 files changed, 378 insertions(+) create mode 100644 twittertopiccount/TwitterUI.java create mode 100644 twittertopiccount/s4.png create mode 100644 twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java create mode 100755 twittertopiccount/twitter_topic_count.sh diff --git a/twittertopiccount/TwitterUI.java b/twittertopiccount/TwitterUI.java new file mode 100644 index 0000000..94dc52b --- /dev/null +++ b/twittertopiccount/TwitterUI.java @@ -0,0 +1,159 @@ +package io.s4.example.twittertopiccount.ui; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import javax.swing.JLabel; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class TwitterUI4 extends javax.swing.JFrame { + + /** Creates new form TwitterUI4 */ + public TwitterUI4() { + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + getContentPane().setLayout(null); + this.setSize(605, 580); + this.setBackground(Color.white); + jLabel1.setText("S4 Twitter top N tweets"); + getContentPane().add(jLabel1); + jLabel1.setFont(new Font("Times New Roman", Font.BOLD, 18)); + // readTopNTweets(); + + getContentPane().setVisible(true); + }// + + public void drawComponents(Object [][] tweets, long maxCount) { + + int y = 110; + int x1 = 90; + int x2 = 290; + + getContentPane().removeAll(); + + jLabel1.setText("S4 Twitter top N tweets"); + getContentPane().add(jLabel1); + jLabel1.setBounds(200, 40, 400, 25); + + for(int i = 0; i < 10; i++) { + javax.swing.JLabel jLabelTweet = new javax.swing.JLabel(); + javax.swing.JLabel jLabelFrequency = new javax.swing.JLabel(); + jLabelTweet.setText((String) tweets[i][0]); + long count = ((Long)tweets[i][1]); + jLabelFrequency.setText(Long.toString((Long)tweets[i][1])); + jLabelTweet.setBounds(x1, y+(i*40), 200, 13); + getContentPane().add(jLabelTweet); + jLabelFrequency.setBounds(x2, y+(i*40), (int)((200/maxCount)*count), 13); + jLabelFrequency.setBackground(new java.awt.Color(246, 232, 252)); + jLabelFrequency.setForeground(new java.awt.Color(51, 0, 51)); + jLabelFrequency.setOpaque(true); + getContentPane().add(jLabelFrequency); + } + getContentPane().repaint(); + getContentPane().setVisible(true); + } + + public Object[][] readTopNTweets() { + Object[][] tweets = new Object[10][2]; + long maxCount = 0; + BufferedReader reader = null; + try { + System.out.println("fileName " + fileName); + reader = new BufferedReader(new FileReader(new File( + fileName))); + String line = reader.readLine(); + JSONObject jsonObject = new JSONObject(line); + System.out.println(line); + System.out.println(jsonObject.get("topN")); + JSONArray jsonArray = jsonObject.getJSONArray("topN"); + int numberOfTweets = jsonArray.length(); + for (int i = 0; i < numberOfTweets; i++) { + JSONObject record = (JSONObject) jsonArray.get(i); + System.out.println(record); + tweets[i][0] = record.getString("topic"); + long count = record.getLong("count"); + if (count > maxCount) { + maxCount = count; + } + String countString = Long.toString(record.getLong("count")); + JLabel countLabel = new JLabel(countString); + countLabel.setSize((int)((400/maxCount) * count), 40); + countLabel.setBackground(new java.awt.Color(183, 123, 213)); + tweets[i][1] = record.getLong("count"); + } + for (int j = 0; j < numberOfTweets; j++) { + System.out.println("Tweet " + tweets[j][0] + " frequency " + + tweets[j][1]); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + finally { + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + drawComponents(tweets, maxCount); + return tweets; + } + + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + final TwitterUI4 twitterUI = new TwitterUI4(); + twitterUI.fileName = args[0]; + + while (true) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + twitterUI.readTopNTweets(); + twitterUI.setVisible(true); + } + }); + try { + Thread.sleep(400); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + // Variables declaration - do not modify + private javax.swing.JLabel jLabel1; + private String fileName; + // End of variables declaration + +} diff --git a/twittertopiccount/s4.png b/twittertopiccount/s4.png new file mode 100644 index 0000000..e69de29 diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java new file mode 100644 index 0000000..83a227e --- /dev/null +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java @@ -0,0 +1,218 @@ +package io.s4.example.twittertopiccount.ui; + +import java.awt.Color; +import java.awt.Desktop; +import java.awt.Dimension; +import java.awt.Font; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.URI; +import java.net.URLEncoder; + +import javax.swing.JLabel; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class TwitterUI extends javax.swing.JFrame { + + /** Creates new form TwitterUI */ + public TwitterUI() { + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JButton(); + jLabel3 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + getContentPane().setLayout(null); + this.setSize(569, 580); + this.setBackground(Color.white); + // readTopNTweets(); + + getContentPane().setVisible(true); + }// + + public void drawComponents(Object [][] tweets, long maxCount) { + + int y = 110; + int x1 = 90; + int x2 = 290; + + getContentPane().removeAll(); + + jLabel1.setText("Top Twitter Topics"); + jLabel1.setFont(new Font("Times New Roman", Font.BOLD, 18)); + getContentPane().add(jLabel1); + jLabel1.setBounds(193, 40, 400, 25); + jLabel2.setIcon(new javax.swing.ImageIcon("/mnt/home/s4.png")); + if (Desktop.isDesktopSupported()) { + jLabel2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + if(evt.getClickCount() > 0){ + try { + Desktop desktop = Desktop.getDesktop(); + desktop.browse(new URI("http://s4.io/")); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + getContentPane().add(jLabel2); + jLabel2.setBounds(164, 529, 124, 19); + jLabel3.setText("Get Started"); + jLabel3.setFont(new Font("Times New Roman", Font.ITALIC, 11)); + jLabel3.setBounds(299, 529, 124, 19); + if (Desktop.isDesktopSupported()) { + jLabel3.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + if(evt.getClickCount() > 0){ + try { + Desktop desktop = Desktop.getDesktop(); + desktop.browse(new URI("http://wiki.s4.io/Tutorials/GettingStarted")); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + getContentPane().add(jLabel3); + + for(int i = 0; i < 10; i++) { + javax.swing.JLabel jLabelTweet = new javax.swing.JLabel(); + javax.swing.JLabel jLabelFrequency = new javax.swing.JLabel(); + final String tweet = (String) tweets[i][0]; + jLabelTweet.setText("" + tweet + ""); + long count = ((Long)tweets[i][1]); + jLabelFrequency.setText(Long.toString((Long)tweets[i][1])); + jLabelTweet.setBounds(x1, y+(i*40), 200, 13); + if (Desktop.isDesktopSupported()) { + jLabelTweet.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + if(evt.getClickCount() > 0){ + try { + Desktop desktop = Desktop.getDesktop(); + URLEncoder.encode(tweet, "UTF-8"); + desktop.browse(new URI("http://twitter.com/search?q=" + tweet)); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } + getContentPane().add(jLabelTweet); + jLabelFrequency.setBounds(x2, y+(i*40), (int)((200/maxCount)*count), 13); + jLabelFrequency.setBackground(new java.awt.Color(246, 232, 252)); + jLabelFrequency.setForeground(new java.awt.Color(51, 0, 51)); + jLabelFrequency.setOpaque(true); + getContentPane().add(jLabelFrequency); + } + getContentPane().repaint(); + getContentPane().setVisible(true); + } + + public Object[][] readTopNTweets() { + Object[][] tweets = new Object[10][2]; + long maxCount = 0; + BufferedReader reader = null; + try { + System.out.println("fileName " + fileName); + reader = new BufferedReader(new FileReader(new File( + fileName))); + String line = reader.readLine(); + JSONObject jsonObject = new JSONObject(line); + System.out.println(line); + System.out.println(jsonObject.get("topN")); + JSONArray jsonArray = jsonObject.getJSONArray("topN"); + int numberOfTweets = jsonArray.length(); + for (int i = 0; i < numberOfTweets; i++) { + JSONObject record = (JSONObject) jsonArray.get(i); + System.out.println(record); + tweets[i][0] = record.getString("topic"); + long count = record.getLong("count"); + if (count > maxCount) { + maxCount = count; + } + String countString = Long.toString(record.getLong("count")); + JLabel countLabel = new JLabel(countString); + countLabel.setSize((int)((400/maxCount) * count), 40); + countLabel.setBackground(new java.awt.Color(183, 123, 213)); + tweets[i][1] = record.getLong("count"); + } + for (int j = 0; j < numberOfTweets; j++) { + System.out.println("Tweet " + tweets[j][0] + " frequency " + + tweets[j][1]); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + finally { + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + drawComponents(tweets, maxCount); + return tweets; + } + + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + final TwitterUI twitterUI = new TwitterUI(); + twitterUI.fileName = args[0]; + + while (true) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + twitterUI.readTopNTweets(); + twitterUI.setVisible(true); + } + }); + try { + Thread.sleep(400); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + // Variables declaration - do not modify + private javax.swing.JLabel jLabel1; + private javax.swing.JButton jLabel2; + private javax.swing.JLabel jLabel3; + private String fileName; + // End of variables declaration + +} diff --git a/twittertopiccount/twitter_topic_count.sh b/twittertopiccount/twitter_topic_count.sh new file mode 100755 index 0000000..83be76a --- /dev/null +++ b/twittertopiccount/twitter_topic_count.sh @@ -0,0 +1 @@ +java -cp /mnt/home/.m2/repository/org/json/json/20090211/json-20090211.jar:. io.s4.example.twittertopiccount.ui.TwitterUI From 659d44d88fbb92875ee3871a32c2fde4be376210 Mon Sep 17 00:00:00 2001 From: Suraj Waghulde Date: Tue, 1 Mar 2011 14:49:43 -0800 Subject: [PATCH 2/5] Adding image to resources and adding scripts and paths to execute the TwitterUI from example application. Also added the count to the desktop for opening the browser window only once when clikced on the same links again and again. --- twittertopiccount/assembly.xml | 14 ++ twittertopiccount/pom.xml | 5 + twittertopiccount/s4.png | Bin 0 -> 4288 bytes .../DirectToFilePersister.java | 4 + .../TopicCountAndReportPE.java | 3 - .../twittertopiccount/ui/TwitterUI.java | 143 +++++++++--------- .../src/main/resources/adapter_conf.xml | 5 +- twittertopiccount/twitter_topic_count.sh | 2 +- 8 files changed, 94 insertions(+), 82 deletions(-) diff --git a/twittertopiccount/assembly.xml b/twittertopiccount/assembly.xml index c9ed2ca..17220a9 100644 --- a/twittertopiccount/assembly.xml +++ b/twittertopiccount/assembly.xml @@ -25,6 +25,20 @@ *.jar + + ${project.basedir} + bin + + *.sh + + + + ${project.basedir} + resources + + *.png + + ${project.basedir}/src/main/resources diff --git a/twittertopiccount/pom.xml b/twittertopiccount/pom.xml index b52dac0..831f521 100644 --- a/twittertopiccount/pom.xml +++ b/twittertopiccount/pom.xml @@ -31,6 +31,11 @@ + + org.json + json + 20090211 + io.s4 s4_core diff --git a/twittertopiccount/s4.png b/twittertopiccount/s4.png index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bec4a2dccdc65784cf80e34dff885dad7131f984 100644 GIT binary patch literal 4288 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 NOpPqj6$XU+{|5%+>CylI literal 0 HcmV?d00001 diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/DirectToFilePersister.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/DirectToFilePersister.java index 02dc809..99c5ec7 100644 --- a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/DirectToFilePersister.java +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/DirectToFilePersister.java @@ -33,6 +33,10 @@ public class DirectToFilePersister implements Persister { public void setOutputFilename(String outputFilename) { this.outputFilename = outputFilename; } + + public String getOutputFilename() { + return outputFilename; + } @Override public int cleanOutGarbage() throws InterruptedException { diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TopicCountAndReportPE.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TopicCountAndReportPE.java index 1263ff9..8c06561 100644 --- a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TopicCountAndReportPE.java +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TopicCountAndReportPE.java @@ -59,9 +59,6 @@ public void processEvent(TopicSeen topicSeen) { @Override public void output() { - if (count < threshold) { - return; - } TopicSeen topicSeen = new TopicSeen((String) this.getKeyValue().get(0), count); topicSeen.setReportKey("1"); diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java index 83a227e..f3774bb 100644 --- a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java @@ -2,7 +2,6 @@ import java.awt.Color; import java.awt.Desktop; -import java.awt.Dimension; import java.awt.Font; import java.io.BufferedReader; import java.io.File; @@ -25,13 +24,15 @@ public TwitterUI() { initComponents(); } - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. + int count = 0; + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // + private void initComponents() { jLabel1 = new javax.swing.JLabel(); @@ -42,87 +43,94 @@ private void initComponents() { getContentPane().setLayout(null); this.setSize(569, 580); this.setBackground(Color.white); - // readTopNTweets(); getContentPane().setVisible(true); - }// + } + + public void drawComponents(Object[][] tweets, long maxCount) { - public void drawComponents(Object [][] tweets, long maxCount) { - int y = 110; int x1 = 90; int x2 = 290; - + getContentPane().removeAll(); - + jLabel1.setText("Top Twitter Topics"); jLabel1.setFont(new Font("Times New Roman", Font.BOLD, 18)); getContentPane().add(jLabel1); jLabel1.setBounds(193, 40, 400, 25); - jLabel2.setIcon(new javax.swing.ImageIcon("/mnt/home/s4.png")); + String path = System.getProperty("user.dir"); + String[] splitPath; + splitPath = path.split("/bin"); + jLabel2.setIcon(new javax.swing.ImageIcon(splitPath[0] + + "/resources/s4.png")); + jLabel2.setBounds(164, 529, 124, 19); if (Desktop.isDesktopSupported()) { jLabel2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { - if(evt.getClickCount() > 0){ - try { - Desktop desktop = Desktop.getDesktop(); - desktop.browse(new URI("http://s4.io/")); - } - catch (Exception e) { - e.printStackTrace(); - } + if (evt.getClickCount() > count) { + try { + Desktop desktop = Desktop.getDesktop(); + desktop.browse(new URI("http://s4.io/")); + count++; + } catch (Exception e) { + e.printStackTrace(); + } } - } - }); + } + }); + count = 0; } getContentPane().add(jLabel2); - jLabel2.setBounds(164, 529, 124, 19); jLabel3.setText("Get Started"); jLabel3.setFont(new Font("Times New Roman", Font.ITALIC, 11)); jLabel3.setBounds(299, 529, 124, 19); if (Desktop.isDesktopSupported()) { jLabel3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { - if(evt.getClickCount() > 0){ - try { - Desktop desktop = Desktop.getDesktop(); - desktop.browse(new URI("http://wiki.s4.io/Tutorials/GettingStarted")); - } - catch (Exception e) { - e.printStackTrace(); - } + if (evt.getClickCount() > count) { + try { + Desktop desktop = Desktop.getDesktop(); + desktop.browse(new URI( + "http://wiki.s4.io/Tutorials/GettingStarted")); + count++; + } catch (Exception e) { + e.printStackTrace(); + } } - } - }); + } + }); + count = 0; } getContentPane().add(jLabel3); - - for(int i = 0; i < 10; i++) { + + for (int i = 0; i < 10; i++) { javax.swing.JLabel jLabelTweet = new javax.swing.JLabel(); javax.swing.JLabel jLabelFrequency = new javax.swing.JLabel(); final String tweet = (String) tweets[i][0]; jLabelTweet.setText("" + tweet + ""); - long count = ((Long)tweets[i][1]); - jLabelFrequency.setText(Long.toString((Long)tweets[i][1])); - jLabelTweet.setBounds(x1, y+(i*40), 200, 13); + long count = ((Long) tweets[i][1]); + jLabelFrequency.setText(Long.toString((Long) tweets[i][1])); + jLabelTweet.setBounds(x1, y + (i * 40), 200, 13); if (Desktop.isDesktopSupported()) { jLabelTweet.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { - if(evt.getClickCount() > 0){ - try { - Desktop desktop = Desktop.getDesktop(); - URLEncoder.encode(tweet, "UTF-8"); - desktop.browse(new URI("http://twitter.com/search?q=" + tweet)); - } - catch (Exception e) { - e.printStackTrace(); - } + if (evt.getClickCount() > 0) { + try { + Desktop desktop = Desktop.getDesktop(); + URLEncoder.encode(tweet, "UTF-8"); + desktop.browse(new URI( + "http://twitter.com/search?q=" + tweet)); + } catch (Exception e) { + e.printStackTrace(); + } } - } - }); + } + }); } getContentPane().add(jLabelTweet); - jLabelFrequency.setBounds(x2, y+(i*40), (int)((200/maxCount)*count), 13); + jLabelFrequency.setBounds(x2, y + (i * 40), + (int) ((200 / maxCount) * count), 13); jLabelFrequency.setBackground(new java.awt.Color(246, 232, 252)); jLabelFrequency.setForeground(new java.awt.Color(51, 0, 51)); jLabelFrequency.setOpaque(true); @@ -131,24 +139,19 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { getContentPane().repaint(); getContentPane().setVisible(true); } - + public Object[][] readTopNTweets() { Object[][] tweets = new Object[10][2]; long maxCount = 0; BufferedReader reader = null; try { - System.out.println("fileName " + fileName); - reader = new BufferedReader(new FileReader(new File( - fileName))); + reader = new BufferedReader(new FileReader(new File(fileName))); String line = reader.readLine(); JSONObject jsonObject = new JSONObject(line); - System.out.println(line); - System.out.println(jsonObject.get("topN")); JSONArray jsonArray = jsonObject.getJSONArray("topN"); int numberOfTweets = jsonArray.length(); for (int i = 0; i < numberOfTweets; i++) { JSONObject record = (JSONObject) jsonArray.get(i); - System.out.println(record); tweets[i][0] = record.getString("topic"); long count = record.getLong("count"); if (count > maxCount) { @@ -156,42 +159,35 @@ public Object[][] readTopNTweets() { } String countString = Long.toString(record.getLong("count")); JLabel countLabel = new JLabel(countString); - countLabel.setSize((int)((400/maxCount) * count), 40); + countLabel.setSize((int) ((400 / maxCount) * count), 40); countLabel.setBackground(new java.awt.Color(183, 123, 213)); tweets[i][1] = record.getLong("count"); } - for (int j = 0; j < numberOfTweets; j++) { - System.out.println("Tweet " + tweets[j][0] + " frequency " - + tweets[j][1]); - } } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); - } - finally { + } finally { try { reader.close(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } drawComponents(tweets, maxCount); return tweets; } - - + /** - * @param args the command line arguments - */ + * @param args + * the command line arguments + */ public static void main(String args[]) { final TwitterUI twitterUI = new TwitterUI(); twitterUI.fileName = args[0]; - + while (true) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { @@ -202,17 +198,14 @@ public void run() { try { Thread.sleep(400); } catch (InterruptedException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } } - // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JButton jLabel2; private javax.swing.JLabel jLabel3; private String fileName; - // End of variables declaration } diff --git a/twittertopiccount/src/main/resources/adapter_conf.xml b/twittertopiccount/src/main/resources/adapter_conf.xml index c8b8219..befe115 100644 --- a/twittertopiccount/src/main/resources/adapter_conf.xml +++ b/twittertopiccount/src/main/resources/adapter_conf.xml @@ -5,11 +5,10 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> - - - + + diff --git a/twittertopiccount/twitter_topic_count.sh b/twittertopiccount/twitter_topic_count.sh index 83be76a..c99c8ed 100755 --- a/twittertopiccount/twitter_topic_count.sh +++ b/twittertopiccount/twitter_topic_count.sh @@ -1 +1 @@ -java -cp /mnt/home/.m2/repository/org/json/json/20090211/json-20090211.jar:. io.s4.example.twittertopiccount.ui.TwitterUI +java -cp ../lib/twittertopiccount-0.0.0.1.jar:../lib/json-20090211.jar io.s4.example.twittertopiccount.ui.TwitterUI /mnt/home/tmp/top_n_hashtags From 9bf4c14f26c437f433999e60f6fae789f6991fa5 Mon Sep 17 00:00:00 2001 From: Suraj Waghulde Date: Tue, 1 Mar 2011 15:13:26 -0800 Subject: [PATCH 3/5] Removing the duplicate UI class. --- twittertopiccount/TwitterUI.java | 159 ------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 twittertopiccount/TwitterUI.java diff --git a/twittertopiccount/TwitterUI.java b/twittertopiccount/TwitterUI.java deleted file mode 100644 index 94dc52b..0000000 --- a/twittertopiccount/TwitterUI.java +++ /dev/null @@ -1,159 +0,0 @@ -package io.s4.example.twittertopiccount.ui; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; - -import javax.swing.JLabel; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -public class TwitterUI4 extends javax.swing.JFrame { - - /** Creates new form TwitterUI4 */ - public TwitterUI4() { - initComponents(); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - getContentPane().setLayout(null); - this.setSize(605, 580); - this.setBackground(Color.white); - jLabel1.setText("S4 Twitter top N tweets"); - getContentPane().add(jLabel1); - jLabel1.setFont(new Font("Times New Roman", Font.BOLD, 18)); - // readTopNTweets(); - - getContentPane().setVisible(true); - }// - - public void drawComponents(Object [][] tweets, long maxCount) { - - int y = 110; - int x1 = 90; - int x2 = 290; - - getContentPane().removeAll(); - - jLabel1.setText("S4 Twitter top N tweets"); - getContentPane().add(jLabel1); - jLabel1.setBounds(200, 40, 400, 25); - - for(int i = 0; i < 10; i++) { - javax.swing.JLabel jLabelTweet = new javax.swing.JLabel(); - javax.swing.JLabel jLabelFrequency = new javax.swing.JLabel(); - jLabelTweet.setText((String) tweets[i][0]); - long count = ((Long)tweets[i][1]); - jLabelFrequency.setText(Long.toString((Long)tweets[i][1])); - jLabelTweet.setBounds(x1, y+(i*40), 200, 13); - getContentPane().add(jLabelTweet); - jLabelFrequency.setBounds(x2, y+(i*40), (int)((200/maxCount)*count), 13); - jLabelFrequency.setBackground(new java.awt.Color(246, 232, 252)); - jLabelFrequency.setForeground(new java.awt.Color(51, 0, 51)); - jLabelFrequency.setOpaque(true); - getContentPane().add(jLabelFrequency); - } - getContentPane().repaint(); - getContentPane().setVisible(true); - } - - public Object[][] readTopNTweets() { - Object[][] tweets = new Object[10][2]; - long maxCount = 0; - BufferedReader reader = null; - try { - System.out.println("fileName " + fileName); - reader = new BufferedReader(new FileReader(new File( - fileName))); - String line = reader.readLine(); - JSONObject jsonObject = new JSONObject(line); - System.out.println(line); - System.out.println(jsonObject.get("topN")); - JSONArray jsonArray = jsonObject.getJSONArray("topN"); - int numberOfTweets = jsonArray.length(); - for (int i = 0; i < numberOfTweets; i++) { - JSONObject record = (JSONObject) jsonArray.get(i); - System.out.println(record); - tweets[i][0] = record.getString("topic"); - long count = record.getLong("count"); - if (count > maxCount) { - maxCount = count; - } - String countString = Long.toString(record.getLong("count")); - JLabel countLabel = new JLabel(countString); - countLabel.setSize((int)((400/maxCount) * count), 40); - countLabel.setBackground(new java.awt.Color(183, 123, 213)); - tweets[i][1] = record.getLong("count"); - } - for (int j = 0; j < numberOfTweets; j++) { - System.out.println("Tweet " + tweets[j][0] + " frequency " - + tweets[j][1]); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - finally { - try { - reader.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - drawComponents(tweets, maxCount); - return tweets; - } - - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - final TwitterUI4 twitterUI = new TwitterUI4(); - twitterUI.fileName = args[0]; - - while (true) { - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - twitterUI.readTopNTweets(); - twitterUI.setVisible(true); - } - }); - try { - Thread.sleep(400); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - // Variables declaration - do not modify - private javax.swing.JLabel jLabel1; - private String fileName; - // End of variables declaration - -} From 661c00f394406a5a99923e3c42ca5f245f46eb9b Mon Sep 17 00:00:00 2001 From: Suraj Waghulde Date: Mon, 14 Mar 2011 22:02:55 -0700 Subject: [PATCH 4/5] Adding single script to run Twitter topic count application from anywhere. Removed errors for fork dispatcher and EventListener from the twitter application. Enhanced Twitter UI display. --- twittertopiccount/NOTICE.txt | 11 ++++++ .../launch_twittertopiccount_application.sh | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 twittertopiccount/NOTICE.txt create mode 100755 twittertopiccount/launch_twittertopiccount_application.sh diff --git a/twittertopiccount/NOTICE.txt b/twittertopiccount/NOTICE.txt new file mode 100644 index 0000000..d31a1d2 --- /dev/null +++ b/twittertopiccount/NOTICE.txt @@ -0,0 +1,11 @@ +======================================================================= +NOTICE file for use with, and corresponding to Section 4 of, +the Apache License, Version 2.0, in this case for the S4 project. +========================================================================= + + This product includes software developed by + Yahoo! Inc. (www.yahoo.com) + Copyright (c) 2010 Yahoo! Inc. All rights reserved. + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). diff --git a/twittertopiccount/launch_twittertopiccount_application.sh b/twittertopiccount/launch_twittertopiccount_application.sh new file mode 100755 index 0000000..cbf0024 --- /dev/null +++ b/twittertopiccount/launch_twittertopiccount_application.sh @@ -0,0 +1,35 @@ +#! /bin/bash + +osx=false +case "`uname`" in +Darwin*) osx=true;; +esac + +if $osx; then + READLINK="stat" +else + READLINK="readlink" +fi + +export S4_APPS=$IMAGE_BASE/s4_apps + +BASE_DIR=`dirname $($READLINK -f $0)` +echo $BASE_DIR + +rm $S4_APPS/twittertopiccount-*.tar.gz +rm -r $S4_APPS/twittertopiccount +cp $BASE_DIR/../../twittertopiccount-*.tar.gz $S4_APPS +cd $S4_APPS +pwd +tar zxf $S4_APPS/twittertopiccount-*.tar.gz +cd twittertopiccount +cd bin +chmod 755 twitter_topic_count.sh +cd $IMAGE_BASE/bin +./s4_start.sh & +./run_adapter.sh -x -u $S4_APPS/twittertopiccount/lib/twittertopiccount-*.jar -d $S4_APPS/twittertopiccount/adapter_conf.xml & +cd /tmp +touch top_n_hashtags +cd $S4_APPS/twittertopiccount/bin +sleep 4 +./twitter_topic_count.sh From fd682fceaaa92a40cbec27fac0376b6f860fa8b5 Mon Sep 17 00:00:00 2001 From: Suraj Waghulde Date: Mon, 14 Mar 2011 22:17:03 -0700 Subject: [PATCH 5/5] Commiting the changes to add the scripts and giving run priviledges to those in assembly. Enhanced the twitter UI. --- twittertopiccount/assembly.xml | 8 ++ twittertopiccount/pom.xml | 4 +- .../TwitterFeedListener.java | 4 +- .../twittertopiccount/ui/TwitterUI.java | 102 ++++++++++++------ twittertopiccount/twitter_topic_count.sh | 26 ++++- 5 files changed, 109 insertions(+), 35 deletions(-) diff --git a/twittertopiccount/assembly.xml b/twittertopiccount/assembly.xml index 17220a9..c636a88 100644 --- a/twittertopiccount/assembly.xml +++ b/twittertopiccount/assembly.xml @@ -17,6 +17,13 @@ + + + ${project.basedir}/NOTICE.txt + + NOTICE.txt + + ${project.basedir}/target @@ -27,6 +34,7 @@ ${project.basedir} + 0755 bin *.sh diff --git a/twittertopiccount/pom.xml b/twittertopiccount/pom.xml index 831f521..39b6559 100644 --- a/twittertopiccount/pom.xml +++ b/twittertopiccount/pom.xml @@ -4,7 +4,7 @@ io.s4.examples.twittertopiccount twittertopiccount jar - 0.0.0.1 + 0.0.0.3 twittertopiccount http://maven.apache.org @@ -39,7 +39,7 @@ io.s4 s4_core - 0.2.0.0 + 0.3.0.0 provided diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TwitterFeedListener.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TwitterFeedListener.java index 7881365..3c59291 100644 --- a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TwitterFeedListener.java +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/TwitterFeedListener.java @@ -31,9 +31,9 @@ import io.s4.collector.EventWrapper; import io.s4.listener.EventHandler; -import io.s4.listener.EventListener; +import io.s4.listener.EventProducer; -public class TwitterFeedListener implements EventListener, Runnable { +public class TwitterFeedListener implements EventProducer, Runnable { private String userid; private String password; private String urlString; diff --git a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java index f3774bb..4b7d5eb 100644 --- a/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java +++ b/twittertopiccount/src/main/java/io/s4/example/twittertopiccount/ui/TwitterUI.java @@ -10,6 +10,10 @@ import java.io.IOException; import java.net.URI; import java.net.URLEncoder; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Scanner; import javax.swing.JLabel; @@ -25,6 +29,7 @@ public TwitterUI() { } int count = 0; + long timestamp = 1L; /** * This method is called from within the constructor to initialize the form. @@ -38,6 +43,7 @@ private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); @@ -50,7 +56,7 @@ private void initComponents() { public void drawComponents(Object[][] tweets, long maxCount) { int y = 110; - int x1 = 90; + int x1 = 74; int x2 = 290; getContentPane().removeAll(); @@ -58,7 +64,11 @@ public void drawComponents(Object[][] tweets, long maxCount) { jLabel1.setText("Top Twitter Topics"); jLabel1.setFont(new Font("Times New Roman", Font.BOLD, 18)); getContentPane().add(jLabel1); - jLabel1.setBounds(193, 40, 400, 25); + jLabel1.setBounds(193, 40, 200, 25); + jLabel4.setText("Timestamp: " + Long.toString(timestamp)); + jLabel4.setFont(new Font("Times New Roman", Font.ITALIC, 9)); + getContentPane().add(jLabel4); + jLabel4.setBounds(427,40,139,13); String path = System.getProperty("user.dir"); String[] splitPath; splitPath = path.split("/bin"); @@ -129,8 +139,21 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { }); } getContentPane().add(jLabelTweet); - jLabelFrequency.setBounds(x2, y + (i * 40), - (int) ((200 / maxCount) * count), 13); + if (maxCount != 0) { + int size = (int) ((250 / maxCount) * count); + if (size > countDigits(count) * 18) { + jLabelFrequency.setBounds(x2, y + (i * 40), + size, 13); + } + else { + jLabelFrequency.setBounds(x2, y + (i * 40), + countDigits(count) * 18, 13); + } + } + else { + jLabelFrequency.setBounds(x2, y + (i * 40), + 20, 13); + } jLabelFrequency.setBackground(new java.awt.Color(246, 232, 252)); jLabelFrequency.setForeground(new java.awt.Color(51, 0, 51)); jLabelFrequency.setOpaque(true); @@ -139,42 +162,60 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { getContentPane().repaint(); getContentPane().setVisible(true); } + + public int countDigits(long count) { + int width = 0; + while (count > 1) { + count /= 10; + width++; + } + return width; + } public Object[][] readTopNTweets() { - Object[][] tweets = new Object[10][2]; + Object[][] tweets = new Object [][] {{"", 0L}, {"", 0L},{"", 0L}, {"", 0L},{"", 0L}, {"", 0L},{"", 0L}, {"", 0L},{"", 0L}, {"", 0L},{"", 0L}, {"", 0L}}; long maxCount = 0; - BufferedReader reader = null; + int size = 0; + Scanner scanner = null; try { - reader = new BufferedReader(new FileReader(new File(fileName))); - String line = reader.readLine(); - JSONObject jsonObject = new JSONObject(line); - JSONArray jsonArray = jsonObject.getJSONArray("topN"); - int numberOfTweets = jsonArray.length(); - for (int i = 0; i < numberOfTweets; i++) { - JSONObject record = (JSONObject) jsonArray.get(i); - tweets[i][0] = record.getString("topic"); - long count = record.getLong("count"); - if (count > maxCount) { - maxCount = count; + File file = new File(fileName); + if (timestamp < file.lastModified()/1000) { + timestamp = file.lastModified()/1000; + } + scanner = new Scanner(file); + if (scanner.hasNext()) { + String line = scanner.nextLine(); + if ((line != null) && (line != "")) { + JSONObject jsonObject = new JSONObject(line); + JSONArray jsonArray = jsonObject.getJSONArray("topN"); + int numberOfTweets = jsonArray.length(); + for (int i = 0; i < numberOfTweets; i++) { + JSONObject record = (JSONObject) jsonArray.get(i); + tweets[i][0] = record.getString("topic"); + long count = record.getLong("count"); + if (count > maxCount) { + maxCount = count; + } + String countString = Long.toString(record.getLong("count")); + JLabel countLabel = new JLabel(countString); + if (maxCount == 0) { + size =400; + } + else { + size = (int) ((400 / maxCount) * count); + } + countLabel.setSize(size, 29); + countLabel.setBackground(new java.awt.Color(183, 123, 213)); + tweets[i][1] = record.getLong("count"); + } } - String countString = Long.toString(record.getLong("count")); - JLabel countLabel = new JLabel(countString); - countLabel.setSize((int) ((400 / maxCount) * count), 40); - countLabel.setBackground(new java.awt.Color(183, 123, 213)); - tweets[i][1] = record.getLong("count"); } } catch (FileNotFoundException e) { e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } finally { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } + scanner.close(); } drawComponents(tweets, maxCount); return tweets; @@ -196,7 +237,7 @@ public void run() { } }); try { - Thread.sleep(400); + Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } @@ -206,6 +247,7 @@ public void run() { private javax.swing.JLabel jLabel1; private javax.swing.JButton jLabel2; private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; private String fileName; } diff --git a/twittertopiccount/twitter_topic_count.sh b/twittertopiccount/twitter_topic_count.sh index c99c8ed..2bbbad2 100755 --- a/twittertopiccount/twitter_topic_count.sh +++ b/twittertopiccount/twitter_topic_count.sh @@ -1 +1,25 @@ -java -cp ../lib/twittertopiccount-0.0.0.1.jar:../lib/json-20090211.jar io.s4.example.twittertopiccount.ui.TwitterUI /mnt/home/tmp/top_n_hashtags +#! /bin/bash + +osx=false +case "`uname`" in +Darwin*) osx=true;; +esac + +if $osx; then + READLINK="stat" +else + READLINK="readlink" +fi + +CP_SEP=":" + +BASE_DIR=`dirname $($READLINK -f $0)` +echo $BASE_DIR + +CLASSPATH=$CLASSPATH$CP_SEP`find $BASE_DIR/../lib -name "*.jar" | awk '{p=$0"'$CP_SEP'"p;} END {print p}'` +echo $CLASSPATH + +CMD="java -classpath $CLASSPATH io.s4.example.twittertopiccount.ui.TwitterUI /tmp/top_n_hashtags" +echo "RUNNING $CMD" + +exec ${CMD}