Skip to content

Commit

Permalink
Adding more obvious file saving for the graphs, figuring out the stru…
Browse files Browse the repository at this point in the history
…cture of the graph stuff
  • Loading branch information
martinb3 committed May 20, 2008
1 parent e019d16 commit 01c306c
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 103 deletions.
Binary file added EgoNet Graphing Structure.odg
Binary file not shown.
74 changes: 36 additions & 38 deletions src/com/endlessloopsoftware/ego/client/ClientFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
import javax.swing.JPanel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.endlessloopsoftware.elsutils.files.ExtensionFileFilter;
import com.endlessloopsoftware.elsutils.files.FileCreateException;

Expand Down Expand Up @@ -53,48 +65,37 @@ public class ClientFrame extends JFrame {

private final JMenu jMenuGraph = new JMenu("Graph");

private final JMenuItem graphProperties = new JMenuItem(
"Graph Properties");
private final JMenuItem graphProperties = new JMenuItem("Graph Properties");

private final JMenuItem nodeProperties = new JMenuItem(
"Node Properties");
private final JMenuItem nodeProperties = new JMenuItem("Node Properties");

private final JMenuItem edgeProperties = new JMenuItem(
"Edge Properties");
private final JMenuItem edgeProperties = new JMenuItem("Edge Properties");

private final JMenuItem jMenuHelpAbout = new JMenuItem("About");

private final JMenuItem saveStudySummary = new JMenuItem(
"Save Study Summary");
private final JMenuItem saveStudySummary = new JMenuItem("Save Study Summary");

private final JMenuItem exit = new JMenuItem("Exit");

public final JMenuItem saveAlterSummary = new JMenuItem(
"Save Alter Summary");
public final JMenuItem saveAlterSummary = new JMenuItem("Save Alter Summary");

public final JMenuItem saveTextSummary = new JMenuItem(
"Save Text Answer Summary");
public final JMenuItem saveTextSummary = new JMenuItem("Save Text Answer Summary");

public final JMenuItem saveAdjacencyMatrix = new JMenuItem(
"Save Adjacency Matrix");
public final JMenuItem saveAdjacencyMatrix = new JMenuItem("Save Adjacency Matrix");

public final JMenuItem saveWeightedAdjacencyMatrix = new JMenuItem(
"Save Weighted Adjacency Matrix");
public final JMenuItem saveWeightedAdjacencyMatrix = new JMenuItem("Save Weighted Adjacency Matrix");

public final JMenuItem saveGraph = new JMenuItem("Save Graph as JPEG image");

public final JMenuItem saveGraphSettings = new JMenuItem(
"Save graph settings");
public final JMenuItem saveGraphSettings = new JMenuItem("Save graph settings");

public final JMenuItem saveInterview = new JMenuItem("Save Interview");

public final JMenuItem recalculateStatistics = new JMenuItem(
"Recalculate Statistics");
public final JMenuItem recalculateStatistics = new JMenuItem("Recalculate Statistics");

public final JMenuItem close = new JMenuItem("Return to Main Menu");

public final JMenuItem saveInterviewStatistics = new JMenuItem(
"Save Interview Statistics");
public final JMenuItem saveInterviewStatistics = new JMenuItem("Save Interview Statistics");

// Construct the frame
public ClientFrame() {
Expand Down Expand Up @@ -229,7 +230,7 @@ public void createMenuBar(int mode) {
jMenuFile.add(saveAdjacencyMatrix);
jMenuFile.add(saveWeightedAdjacencyMatrix);
jMenuFile.add(saveGraph);
// jMenuFile.add(saveGraphSettings);
jMenuFile.add(saveGraphSettings);
jMenuFile.add(saveInterview);
jMenuFile.add(recalculateStatistics);
jMenuFile.addSeparator();
Expand Down Expand Up @@ -296,32 +297,29 @@ void saveGraph_actionPerformed(ActionEvent e) {
}

void saveGraphSettings_actionPerformed(ActionEvent e) {
String fileName;
fileName = EgoClient.interview.getName() + "_graphSettings";
File currentDirectory = new File(EgoClient.storage.getPackageFile()
.getParent()
+ "/Graphs");
currentDirectory.mkdir();

String[] name = EgoClient.interview.getName();
String fileName = "/" + name[0] + "_" + name[1] + ".xml";

final File currentDirectory = new File(EgoClient.storage.getPackageFile().getParent(), "Graphs");
currentDirectory.mkdir();
File file = new File(currentDirectory.getAbsolutePath() + fileName);

JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(currentDirectory);
fileChooser.setSelectedFile(new File(fileName + ".settings"));
fileChooser.setDialogTitle("Save Graph Settings");
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setSelectedFile(file);

// ExtensionFileFilter jpegFilter = new ExtensionFileFilter("JPEG
// Files",".jpeg");
ExtensionFileFilter filter = new ExtensionFileFilter("Graph Settings",
"settings");
ExtensionFileFilter filter = new ExtensionFileFilter("Graph Settings", "settings");
fileChooser.addChoosableFileFilter(filter);

int returnValue = fileChooser.showSaveDialog(this);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File settingsFile = fileChooser.getSelectedFile();
System.out.println(settingsFile.getName());
// obtain the iterator for QA settings
Iterator iterator;


GraphRenderer.getGraphSettings().saveSettingsFile(settingsFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class EdgeColorPanel extends JPanel {

private GraphRenderer graphRenderer;

private GraphData graphData;

private JButton applyButton;

public static boolean[][] edgesSelected;
Expand All @@ -51,7 +49,6 @@ public EdgeColorPanel(GraphRenderer renderer) {
this.setLayout(layout);
layout.setAutocreateGaps(true);
layout.setAutocreateContainerGaps(true);
graphData = new GraphData();
createComponents();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class EdgeShapePanel extends JPanel {

private GraphRenderer graphRenderer;

private GraphData graphData;

private JButton applyButton;

List<Selection> selectionList = new ArrayList<Selection>();
Expand All @@ -51,7 +49,6 @@ public EdgeShapePanel(GraphRenderer renderer) {
this.setLayout(layout);
layout.setAutocreateGaps(true);
layout.setAutocreateContainerGaps(true);
graphData = new GraphData();
createComponents();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class EdgeSizePanel extends JPanel {

private GraphRenderer graphRenderer;

private GraphData graphData;

private JButton applyButton;


Expand All @@ -54,7 +52,6 @@ public EdgeSizePanel(GraphRenderer renderer) {
this.setLayout(layout);
layout.setAutocreateGaps(true);
layout.setAutocreateContainerGaps(true);
graphData = new GraphData();
createComponents();
}

Expand Down
13 changes: 12 additions & 1 deletion src/com/endlessloopsoftware/ego/client/graph/GraphRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.endlessloopsoftware.ego.client.graph;

import com.endlessloopsoftware.ego.client.graph.GraphSettingsEntry.GraphSettingType;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.List;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class GraphRenderer extends PluggableRenderer implements
EdgePaintFunction, EdgeStringer, VertexStringer, EdgeStrokeFunction,
ToolTipFunction {

private GraphSettings graphSettings;
private static GraphSettings graphSettings;

private static VisualizationViewer visualizationViewer;

Expand Down Expand Up @@ -770,4 +771,14 @@ public String getToolTipText(MouseEvent event) {
public Iterator getSettingsIterator() {
return graphSettings.getQAsettingsIterator();
}

public static GraphSettings getGraphSettings()
{
return graphSettings;
}

public static VisualizationViewer getVisualizationViewer()
{
return visualizationViewer;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package com.endlessloopsoftware.ego.client.graph;

public enum GraphSettingType {
Node, Edge
}

61 changes: 15 additions & 46 deletions src/com/endlessloopsoftware/ego/client/graph/GraphSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.endlessloopsoftware.ego.client.graph;

import com.endlessloopsoftware.ego.client.graph.GraphSettingsEntry.GraphSettingType;
import edu.uci.ics.jung.graph.ArchetypeVertex;
import edu.uci.ics.jung.graph.Edge;
import edu.uci.ics.jung.graph.impl.UndirectedSparseEdge;
Expand Down Expand Up @@ -79,12 +80,9 @@ private void init() throws Exception {
}
}
}

createSettingsFile();

}

private void createSettingsFile() {
public void saveSettingsFile(File file) {
try {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Expand All @@ -95,25 +93,21 @@ private void createSettingsFile() {
studyElement.setAttribute("StudyId", studyID);
doc.appendChild(studyElement);

for(GraphSettingsEntry entry : QAsettings)
entry.writeEntryElement(doc, studyElement);

TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();

final File currentDirectory = new File(EgoClient.storage
.getPackageFile().getParent(), "Graphs");
currentDirectory.mkdir();

String[] name = EgoClient.interview.getName();
String fileName = "/" + name[0] + "_" + name[1] + ".xml";
File file = new File(currentDirectory.getAbsolutePath() + fileName);
aTransformer.setOutputProperty("indent", "yes");
aTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

Source src = new DOMSource(doc);
Result dest = new StreamResult(file);
aTransformer.transform(src, dest);

} catch (Exception ex) {
ex.printStackTrace();
} catch (Throwable ex) {
throw new RuntimeException(ex);
}

}

public int getNodeSize(ArchetypeVertex node) {
Expand Down Expand Up @@ -217,7 +211,7 @@ public void addQAsetting(GraphQuestion graphQuestion,
GraphSettingsEntry entry = new GraphSettingsEntry(graphQuestion,
nodeProperty, GraphSettingType.Node);
QAsettings.add(entry);
updateSettingsFile(entry);
//updateSettingsFile(entry);
displaySettings();
}

Expand All @@ -226,35 +220,10 @@ public void addQAsetting(GraphQuestion graphQuestion,
GraphSettingsEntry entry = new GraphSettingsEntry(graphQuestion,
edgeProperty, GraphSettingType.Edge);
QAsettings.add(entry);
updateSettingsFile(entry);
//updateSettingsFile(entry);
displaySettings();
}

private void updateSettingsFile(GraphSettingsEntry entry) {
try {
final File currentDirectory = new File(EgoClient.storage
.getPackageFile().getParent(), "Graphs");
String[] name = EgoClient.interview.getName();
String fileName = "/" + name[0] + "_" + name[1] + ".xml";
File file = new File(currentDirectory.getAbsolutePath() + fileName);

DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.parse(file);
Element rootElement = doc.getDocumentElement();
entry.writeEntryElement(doc, rootElement);

TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
Source src = new DOMSource(doc);
Result dest = new StreamResult(file);
aTransformer.transform(src, dest);

} catch (Exception ex) {
ex.printStackTrace();
}
}

private void displaySettings() {

System.out
Expand All @@ -268,7 +237,7 @@ private void displaySettings() {
.println("\n-------------------------------------------------------");
}

public Iterator getQAsettingsIterator() {
public Iterator<GraphSettingsEntry> getQAsettingsIterator() {
return QAsettings.iterator();
}

Expand Down Expand Up @@ -298,7 +267,7 @@ private String getAlterInfo(int alterIndex) {
return alterToolTip[alterIndex];
}

public Iterator getEdgeIterator() {
public Iterator<Edge> getEdgeIterator() {
return edgeSettingsMap.keySet().iterator();
}

Expand All @@ -311,10 +280,10 @@ public void emptyEdgeSettingsMap() {
}

public void printEdgeMap() {
Iterator iterator = getEdgeIterator();
Iterator<Edge> iterator = getEdgeIterator();
System.out.println("***********Edge Map************");
while (iterator.hasNext()) {
Edge e = (Edge) iterator.next();
Edge e = iterator.next();
System.out.println(e.toString() + ":"
+ edgeSettingsMap.get(e).toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

public class GraphSettingsEntry {

public enum GraphSettingType {
Node, Edge
}

GraphQuestion graphQuestion = null;

GraphProperty property = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class NodeLabelPanel extends JPanel {

private GraphRenderer graphRenderer;

private GraphData graphData;

List<Selection> selectionList = new ArrayList<Selection>();

public NodeLabelPanel(GraphRenderer renderer) {
Expand All @@ -47,7 +45,6 @@ public NodeLabelPanel(GraphRenderer renderer) {
this.setLayout(layout);
layout.setAutocreateGaps(true);
layout.setAutocreateContainerGaps(true);
graphData = new GraphData();
createComponents();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class StructuralMeasuresPanel extends JPanel {

private GraphRenderer graphRenderer;

private GraphData graphData;

public static enum StructuralMeasures {
DegreeCentrality, BetweennessCentrality
};
Expand All @@ -40,7 +38,6 @@ public StructuralMeasuresPanel(GraphRenderer renderer) {
this.setLayout(layout);
layout.setAutocreateGaps(true);
layout.setAutocreateContainerGaps(true);
graphData = new GraphData();
createComponents();
}

Expand Down

0 comments on commit 01c306c

Please sign in to comment.