Skip to content

Commit

Permalink
Crawler GUI almost working
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Jaszewski authored and jjroman committed Jan 30, 2013
1 parent 95a18fd commit 2fb4289
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 53 deletions.
6 changes: 3 additions & 3 deletions nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath sem2.iwi.crawler.MainTwellowCrawler</exec.args>
<exec.args>-classpath %classpath sem2.iwi.App</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
</properties>
Expand All @@ -19,7 +19,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath sem2.iwi.crawler.MainTwellowCrawler</exec.args>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath sem2.iwi.App</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
<jpda.listen>true</jpda.listen>
Expand All @@ -32,7 +32,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>${profiler.args} -classpath %classpath sem2.iwi.crawler.MainTwellowCrawler</exec.args>
<exec.args>${profiler.args} -classpath %classpath sem2.iwi.App</exec.args>
<exec.executable>${profiler.java}</exec.executable>
</properties>
</action>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/sem2/iwi/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sem2.iwi.bayes.NBAttributeValue;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JFrame;
import sem2.iwi.gui.MainWindow;

/**
* Hello world!
Expand All @@ -15,6 +17,10 @@
public class App {

public static void main(String[] args) {
JFrame f = new MainWindow();
f.setVisible(true);
}
public static void testRun(){
try {

HashMap<String, String> hm = InOut.getInputStreamAsOutputDictionary(Thread.currentThread().getContextClassLoader().getResourceAsStream("input2_test.dict"));
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/sem2/iwi/crawler/MainTwellowCrawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,35 @@ public static void main(String[] args) {
}
}

ArrayList<String> nicks = getNicksForCategory(atc.iterator().next());

/*for (String nick : nicks) {
System.out.println(nick);
}*/

}

public static String getNicksForCategoryNames(ArrayList<String> categories) {

HashSet<TwellowCategory> atc = getMainCategoryList();
StringBuilder output = new StringBuilder();

for (TwellowCategory tc : atc) {
if (!categories.contains(tc.getName())) {
continue;
}
//System.out.println(String.format("%s\t%d\t http://twellow.com%s ", tc.getName(), tc.getUsers(), tc.getUrl()));

ArrayList<String> nicks = getNicksForCategory(tc);
for (String nick : nicks) {
output.append(tc.getName())
.append('\t')
.append(nick)
.append('\n');
}
}
return output.toString();
}

private static String getUrlForCategory(TwellowCategory tc) {
return TWELLOW_BASE + tc.getUrl();
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/sem2/iwi/gui/MainPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
<Component id="jTextField3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton3" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Component id="jScrollPane1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="91" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
Expand All @@ -106,6 +106,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="przegl&#x105;daj"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
Expand All @@ -118,6 +121,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="przegl&#x105;daj"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/sem2/iwi/gui/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package sem2.iwi.gui;

import javax.swing.JFileChooser;

/**
*
* @author jjroman
Expand Down Expand Up @@ -42,10 +44,20 @@ private void initComponents() {
jLabel1.setText("Zbiór uczący");

jButton1.setText("przeglądaj");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel2.setText("Zbiór testujacy");

jButton2.setText("przeglądaj");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
Expand Down Expand Up @@ -115,11 +127,31 @@ private void initComponents() {
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButton3))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION){
jTextField1.setText(fc.getSelectedFile().getAbsolutePath());
}

}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION){
jTextField2.setText(fc.getSelectedFile().getAbsolutePath());
}
}//GEN-LAST:event_jButton2ActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/sem2/iwi/gui/MainWindow.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jTabbedPane1" pref="380" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jTabbedPane1" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1">

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Component class="sem2.iwi.gui.MainPanel" name="mainPanel1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Klasyfikator">
<Property name="tabTitle" type="java.lang.String" value="Klasyfikator"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
</Component>
<Component class="sem2.iwi.gui.TwellowCrawler" name="twellowCrawler1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Kategorie Twitt&#xf3;w">
<Property name="tabTitle" type="java.lang.String" value="Kategorie Twitt&#xf3;w"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
97 changes: 97 additions & 0 deletions src/main/java/sem2/iwi/gui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sem2.iwi.gui;

/**
*
* @author jjroman
*/
public class MainWindow extends javax.swing.JFrame {

/**
* Creates new form MainWindow
*/
public MainWindow() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jTabbedPane1 = new javax.swing.JTabbedPane();
mainPanel1 = new sem2.iwi.gui.MainPanel();
twellowCrawler1 = new sem2.iwi.gui.TwellowCrawler();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jTabbedPane1.addTab("Klasyfikator", mainPanel1);
jTabbedPane1.addTab("Kategorie Twittów", twellowCrawler1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTabbedPane1)
.addContainerGap())
);

pack();
}// </editor-fold>//GEN-END:initComponents

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTabbedPane jTabbedPane1;
private sem2.iwi.gui.MainPanel mainPanel1;
private sem2.iwi.gui.TwellowCrawler twellowCrawler1;
// End of variables declaration//GEN-END:variables
}
53 changes: 53 additions & 0 deletions src/main/java/sem2/iwi/gui/TwellowCateryModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sem2.iwi.gui;

import java.util.HashSet;
import java.util.Iterator;
import javax.swing.table.DefaultTableModel;
import sem2.iwi.crawler.MainTwellowCrawler;
import sem2.iwi.crawler.TwellowCategory;

/**
*
* @author jjroman
*/
class TwellowCateryModel extends DefaultTableModel {



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

public static String[] getColumnNames(){
return new String[]{"Nazwa", "Liczba użytkowników", "URL"};
}
public static Object[][] getData(){
HashSet<TwellowCategory> hstc = MainTwellowCrawler.getMainCategoryList();
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();
}
return data;
}

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

@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 1) {
return Integer.class;
}
return String.class;
}
}
Loading

0 comments on commit 2fb4289

Please sign in to comment.