Skip to content

Commit

Permalink
Add preset for twitt categories
Browse files Browse the repository at this point in the history
  • Loading branch information
jjroman committed Jan 31, 2013
1 parent af1e131 commit 137b9f6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target
UserTweets.txt
PlikDoNauki.BLA.dict
nicks_outpur.tab
target
UserTweets.txt
PlikDoNauki.BLA.dict
nicks_outpur.tab
CategoriesUsers.txt
45 changes: 34 additions & 11 deletions src/main/java/sem2/iwi/gui/TwellowCateryModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package sem2.iwi.gui;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import javax.swing.table.DefaultTableModel;
Expand All @@ -16,33 +18,54 @@
*/
class TwellowCateryModel extends DefaultTableModel {



public TwellowCateryModel(Object[][] data, String[] columnNames) {
super(data,columnNames);
super(data, columnNames);
}

public static String[] getColumnNames(){
public static String[] getColumnNames() {
return new String[]{"Nazwa", "Liczba użytkowników", "URL"};
}
public static Object[][] getData(){

public static Object[][] getData() {
HashSet<TwellowCategory> hstc = MainTwellowCrawler.getMainCategoryList();
HashMap<String, TwellowCategory> hmstc = new HashMap<>();

Object[][] data = new Object[hstc.size()][3];
int i = 0;

for (Iterator<TwellowCategory> it = hstc.iterator(); it.hasNext(); i++) {
TwellowCategory tc = it.next();
data[i][0] = tc.getName();
data[i][1] = tc.getUsers();
data[i][2] = tc.getUrl();
hmstc.put(tc.getName(), tc);
}
HashSet<String> setOfChoosen = new HashSet<>();
Collections.addAll(setOfChoosen, "Education", "Games",
"Movies & Filmmaking", "Sports", "Pets", "Travel", "Politics",
"Fashion", "Actors & Actresses", "Fitness");
int i2 = 0;
for (String mainCat : setOfChoosen) {
data[i2][0] = mainCat;
data[i2][1] = hmstc.get(mainCat).getUsers();
data[i2++][2] = hmstc.get(mainCat).getUrl();
}

for (Iterator<TwellowCategory> it = hstc.iterator(); it.hasNext(); ) {
TwellowCategory tc = it.next();
if (setOfChoosen.contains(tc.getName())) {
continue;
}
data[i2][0] = tc.getName();
data[i2][1] = tc.getUsers();
data[i2++][2] = tc.getUrl();
}

return data;
}

@Override
public boolean isCellEditable(int y, int x){
public boolean isCellEditable(int y, int x) {
return false;
}

@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 1) {
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/sem2/iwi/gui/TwellowCrawler.form
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jButton1" max="32767" attributes="0"/>
</Group>
<Component id="jButton2" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jButton2" min="-2" pref="337" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton3" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand All @@ -38,7 +42,10 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="31" max="-2" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton3" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="213" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -121,5 +128,13 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton3">
<Properties>
<Property name="text" type="java.lang.String" value="Preset 10"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton3ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
26 changes: 22 additions & 4 deletions src/main/java/sem2/iwi/gui/TwellowCrawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package sem2.iwi.gui;

import java.util.ArrayList;
import java.util.Locale;
import javax.swing.ListSelectionModel;
import sem2.iwi.crawler.MainTwellowCrawler;

Expand Down Expand Up @@ -42,6 +41,7 @@ private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
Expand Down Expand Up @@ -78,6 +78,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

jButton3.setText("Preset 10");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -93,14 +100,19 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jButton2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
Expand Down Expand Up @@ -133,9 +145,15 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
jTextArea1.setText(MainTwellowCrawler.getNicksForCategoryNames(retVal));
sem2.iwi.tweets.GettingTweets.writeToFileTwellowCategories(MainTwellowCrawler.getNicksForCategoryNames(retVal));
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
jTable1.setRowSelectionInterval(0, 9);
}//GEN-LAST:event_jButton3ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
Expand All @@ -147,4 +165,4 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
private void loadMainCategories() {
jTable1.setModel(new TwellowCateryModel(TwellowCateryModel.getData(), TwellowCateryModel.getColumnNames()));
}
}
}

0 comments on commit 137b9f6

Please sign in to comment.