Skip to content

Commit

Permalink
Added "Raw Data" button, which outputs all interview results in CSV f…
Browse files Browse the repository at this point in the history
…ormat, to the Interviewing and Analysis Tool.
  • Loading branch information
ericlavigne committed Mar 13, 2009
1 parent 06e42dd commit 997c208
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
<classpathentry kind="lib" path="lib/fest-swing-1.0b1/lib/MRJToolkitStubs-1.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/colt.jar"/>
<classpathentry kind="lib" path="lib/miglayout-3.7-swing.jar"/>
<classpathentry kind="lib" path="lib/opencsv-1.8.jar"/>
<classpathentry kind="lib" path="lib/functionalj.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
4 changes: 3 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
<zipfileset src="${dir.lib.Enet}/swing-layout-1.0.3.jar" />
<zipfileset src="${dir.lib.Enet}/swing-worker-1.1.jar" />
<zipfileset src="${dir.lib.Enet}/colt.jar" />

<zipfileset src="${dir.lib.Enet}/miglayout-3.7-swing.jar" />
<zipfileset src="${dir.lib.Enet}/opencsv-1.8.jar" />
<zipfileset src="${dir.lib.Enet}/functionalj.jar" />
</jar>
</target>

Expand Down
Binary file added lib/functionalj.jar
Binary file not shown.
Binary file added lib/miglayout-3.7-swing.jar
Binary file not shown.
Binary file added lib/opencsv-1.8.jar
Binary file not shown.
138 changes: 79 additions & 59 deletions src/com/endlessloopsoftware/ego/client/ClientPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,126 +19,129 @@
package com.endlessloopsoftware.ego.client;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.JFileChooser;

import net.miginfocom.swing.MigLayout;

import org.egonet.exceptions.CorruptedInterviewException;
import org.egonet.util.CatchingAction;
import org.egonet.util.ExtensionFileFilter;

import com.cim.dlgedit.loader.DialogResource;
import com.endlessloopsoftware.egonet.Interview;
import com.endlessloopsoftware.egonet.Study;

import org.egonet.io.RawDataCSVWriter;;

public class ClientPanel
extends JPanel
{
private JLabel titleLabel;
private JButton selectStudyButton;
private JButton statisticsButton;
private JButton rawDataButton;
private JButton viewInterviewButton;
private JButton startInterviewButton;

private JLabel studyNameLabel = new JLabel();

private final EgoClient egoClient;
public ClientPanel(EgoClient egoClient)
{
this.egoClient = egoClient;
// Load up the dialog contents.
java.io.InputStream is = this.getClass().getClassLoader().getResourceAsStream("com/endlessloopsoftware/ego/client/localSelect.gui_xml");
JPanel panel = DialogResource.load(is);
//JPanel panel = DialogResource.load("com/endlessloopsoftware/ego/client/localSelect.gui_xml");

// Attach beans to fields.
selectStudyButton = (JButton) DialogResource.getComponentByName(panel, "SelectStudy");
viewInterviewButton = (JButton) DialogResource.getComponentByName(panel, "ViewInterview");
statisticsButton = (JButton) DialogResource.getComponentByName(panel, "SummaryStatistics");
startInterviewButton = (JButton) DialogResource.getComponentByName(panel, "StartInterview");
titleLabel = (JLabel) DialogResource.getComponentByName(panel, "Title");
studyNameLabel = (JLabel) DialogResource.getComponentByName(panel, "StudyName");

jbInit();

this.setLayout(new GridLayout(1, 1));
this.add(panel);
initComponents();
}

//Component initialization
private void jbInit()
{

private void initComponents() {

// Create components

titleLabel = new JLabel("Egocentric Network Study");
titleLabel.setBackground(Color.lightGray);
titleLabel.setBorder(BorderFactory.createRaisedBevelBorder());
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

studyNameLabel.setBorder(BorderFactory.createLoweredBevelBorder());
studyNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
studyNameLabel.setText(" ");


selectStudyButton = new JButton("Select Study");
selectStudyButton.addActionListener(new CatchingAction("doSelectStudy") {
public void safeActionPerformed(ActionEvent e) throws Exception {
doSelectStudy(e);
}
});


viewInterviewButton = new JButton("View Interview");
viewInterviewButton.addActionListener(new CatchingAction("doViewInterview") {
public void safeActionPerformed(ActionEvent e) throws Exception {
doViewInterview(e);
}
});


rawDataButton = new JButton("Raw Data");
rawDataButton.addActionListener(new CatchingAction("saveRawDataAsCSV") {
public void safeActionPerformed(ActionEvent e) throws Exception {
saveRawDataAsCSV();
}
});

statisticsButton = new JButton("Summary Statistics");
statisticsButton.addActionListener(new CatchingAction("doSummaryStatistics") {
public void safeActionPerformed(ActionEvent e) throws Exception {
doSummaryStatistics(e);
}
});


startInterviewButton = new JButton("Start Interview");
startInterviewButton.addActionListener(new CatchingAction("doStartInterview") {
public void safeActionPerformed(ActionEvent e) throws Exception {
doStartInterview(e);
}
});

fillPanel();

// Layout components
this.setLayout(
new MigLayout(
"gapx 10, gapy 15",
"[grow]", "[grow]"));
this.add(this.titleLabel, "gaptop 10, span, growx");
this.add(this.selectStudyButton, "span, growx");
this.add(this.viewInterviewButton, "sg 1");
this.add(this.rawDataButton, "sg 1");
this.add(this.statisticsButton, "sg 1, wrap");
this.add(this.startInterviewButton, "span, growx");

// Part of building is a set of adjustments that need to be repeated when a study is selected.
adjustControlState();
}

void fillPanel()
void adjustControlState()
{
startInterviewButton.setEnabled(egoClient.getStorage().getStudyLoaded());
viewInterviewButton.setEnabled(egoClient.getStorage().getStudyLoaded());
statisticsButton.setEnabled(egoClient.getStorage().getStudyLoaded());

studyNameLabel.setText(egoClient.getStudy().getStudyName());
if (studyNameLabel.getText() == null)
{
studyNameLabel.setText(" ");
}

if (egoClient.getStorage().getStudyLoaded())
{

}
Boolean loaded = egoClient.getStorage().getStudyLoaded();
this.viewInterviewButton.setEnabled(loaded);
this.rawDataButton.setEnabled(loaded);
this.statisticsButton.setEnabled(loaded);
this.startInterviewButton.setEnabled(loaded);
this.selectStudyButton.setText(
loaded ? "Study: "+egoClient.getStudy().getStudyName() : "Select Study");
}

private void doSelectStudy(ActionEvent e) throws Exception
{
/* Clear out old data */
egoClient.setStudy(new Study());
egoClient.setStorage(new EgoStore(egoClient));
egoClient.setInterview(null);
egoClient.setStudy(new Study());
egoClient.setStorage(new EgoStore(egoClient));
egoClient.setInterview(null);

/* Read new study */
egoClient.getStorage().selectStudy();
egoClient.getStorage().readPackage();
studyNameLabel.setText(egoClient.getStudy().getStudyName());

fillPanel();
egoClient.getStorage().selectStudy();
egoClient.getStorage().readPackage();

/* Selecting a study enables some controls and changes the appearance of others. */
adjustControlState();
}

private void doStartInterview(ActionEvent e)
Expand Down Expand Up @@ -183,6 +186,23 @@ private void doViewInterview(ActionEvent e)
egoClient.setInterview(null);
egoClient.getStorage().selectInterview();
}

private void saveRawDataAsCSV() throws Exception {
File studyDirectory =
new File(egoClient.getStorage().getPackageFile().getParent());
JFileChooser fc = new JFileChooser(studyDirectory);
fc.addChoosableFileFilter(new ExtensionFileFilter("CSV Files","csv"));
fc.setDialogTitle("Save raw data as CSV file");
if(fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
File interviewDirectory =
new File(egoClient.getStorage().getPackageFile().getParent(),
"/Interviews/");
File outputCSV = fc.getSelectedFile();
new RawDataCSVWriter(egoClient.getStudy())
.writeFromInterviewDirectoryToFile(
interviewDirectory, outputCSV);
}
}

private void doSummaryStatistics(ActionEvent e)
{
Expand All @@ -195,4 +215,4 @@ private void doSummaryStatistics(ActionEvent e)
egoClient.getFrame().gotoSummaryPanel();
}
}
}
}
10 changes: 1 addition & 9 deletions src/com/endlessloopsoftware/egonet/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,7 @@ public Object clone() throws CloneNotSupportedException {
}

public String toString() {
String str = null;
if (string == null) {
Integer val = getValue();
str = val.toString();
;
} else {
str = string;
}
return str;
return string == null ? getValue()+"" : string;
}

public String getString() {
Expand Down
Loading

0 comments on commit 997c208

Please sign in to comment.