From 3c4d4a40e73f610d6a409aa8f6bd0e188f9419f6 Mon Sep 17 00:00:00 2001 From: kubeusz Date: Thu, 31 Jan 2013 13:44:31 +0100 Subject: [PATCH] gettingTweetPanel - added Twitter4j.Paging param --- .../java/sem2/iwi/gui/GettingTweetsPanel.form | 55 +++++++++++++------ .../java/sem2/iwi/gui/GettingTweetsPanel.java | 55 ++++++++++++++----- .../java/sem2/iwi/tweets/GettingTweets.java | 14 +++-- 3 files changed, 87 insertions(+), 37 deletions(-) diff --git a/src/main/java/sem2/iwi/gui/GettingTweetsPanel.form b/src/main/java/sem2/iwi/gui/GettingTweetsPanel.form index 4a1739f..25e443e 100644 --- a/src/main/java/sem2/iwi/gui/GettingTweetsPanel.form +++ b/src/main/java/sem2/iwi/gui/GettingTweetsPanel.form @@ -23,32 +23,37 @@ + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - @@ -63,14 +68,19 @@ - + + + + + + - + - + @@ -141,5 +151,18 @@ + + + + + + + + + + + + + diff --git a/src/main/java/sem2/iwi/gui/GettingTweetsPanel.java b/src/main/java/sem2/iwi/gui/GettingTweetsPanel.java index 4a63f20..0357927 100644 --- a/src/main/java/sem2/iwi/gui/GettingTweetsPanel.java +++ b/src/main/java/sem2/iwi/gui/GettingTweetsPanel.java @@ -42,6 +42,8 @@ private void initComponents() { jButton2 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); + jLabel3 = new javax.swing.JLabel(); + jTextField2 = new javax.swing.JTextField(); jLabel1.setText("Pobierz tweety"); @@ -76,6 +78,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jTextArea2.setRows(5); jScrollPane2.setViewportView(jTextArea2); + jLabel3.setText("Nr strony z tweetami"); + + jTextField2.setText("1"); + jTextField2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField2ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -85,17 +96,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(jButton1)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(26, 26, 26)) + .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(jButton2) @@ -104,7 +105,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1)) - .addContainerGap()))) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jButton1)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(26, 26, 26)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -115,14 +130,18 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jButton1) .addGap(18, 18, 18) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane2) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) .addContainerGap()) ); }// //GEN-END:initComponents @@ -138,7 +157,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS twitterUsers = sem2.iwi.tweets.GettingTweets.readFromFileTwellowCategories(); //for(String s:twitterUsers)System.out.println("category z userem: "+s); - jTextArea1.setText(sem2.iwi.tweets.GettingTweets.gettingTweets(twitterUsers, jTextField1.getText())); + jTextArea1.setText(sem2.iwi.tweets.GettingTweets.gettingTweets(twitterUsers, jTextField1.getText(),jTextField2.getText())); }//GEN-LAST:event_jButton1ActionPerformed @@ -161,16 +180,22 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS jTextArea2.setText(sb.toString()); }//GEN-LAST:event_jButton2ActionPerformed + private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField2ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; // End of variables declaration//GEN-END:variables diff --git a/src/main/java/sem2/iwi/tweets/GettingTweets.java b/src/main/java/sem2/iwi/tweets/GettingTweets.java index 8ca5b71..6af4785 100644 --- a/src/main/java/sem2/iwi/tweets/GettingTweets.java +++ b/src/main/java/sem2/iwi/tweets/GettingTweets.java @@ -126,7 +126,7 @@ public static Map readCategoriesDictionary(){ return categoryMappings; } private static HashMap> forBOW = null; - public static String gettingTweets(List users, String noOfTweets){ + public static String gettingTweets(List users, String noOfTweets, String noOfPage){ Twitter twitter = getTwitterInstance(); @@ -159,18 +159,20 @@ public static String gettingTweets(List users, String noOfTweets){ if(exists!=false){ - List statuses = twitter.getUserTimeline(result[1], new Paging(1,Integer.parseInt(noOfTweets) )); + List statuses = twitter.getUserTimeline(result[1], new Paging(Integer.parseInt(noOfPage),Integer.parseInt(noOfTweets) )); for (Status status : statuses) { + String s = status.getText(); + s.replace("\n\r", " "); if(forBOW.containsKey(result[0])){ - forBOW.get(result[0]).add(status.getText()); + forBOW.get(result[0]).add(s); }else{ ArrayList altmp = new ArrayList<>(); - altmp.add(status.getText()); + altmp.add(s); forBOW.put(result[0], altmp); } - bw.write(result[0] + " || " + status.getText() +"\n"); - content+=result[0] + " || " + status.getText() +"\n"; + bw.write(result[0] + " || " + s +"\n"); + content+=result[0] + " || " + s +"\n"; } }