Skip to content

Commit

Permalink
Added column export selection panel and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
shepdl committed Mar 2, 2013
1 parent fa52366 commit e8ecb3b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 40 deletions.
4 changes: 2 additions & 2 deletions manifest.mf
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: com.hypercities.exporttoearth
OpenIDE-Module: com.hypercities.exporttoearth/2
OpenIDE-Module-Localizing-Bundle: com/hypercities/exporttoearth/Bundle.properties
OpenIDE-Module-Specification-Version: 1.1
OpenIDE-Module-Specification-Version: 2

Expand Up @@ -105,6 +105,9 @@ public AttributeColumnSelectionPanel(AttributeColumn[] allColumns,
// TODO: set item responder
checkBoxesToColumns.put(checkbox, column);
checkbox.addItemListener(columnSelectorResponder);
if (column != longitudeColumn && column != latitudeColumn) {
checkbox.setSelected(true);
}
add(checkbox);

JRadioButton latButton = new JRadioButton();
Expand Down
5 changes: 0 additions & 5 deletions src/com/hypercities/exporttoearth/GeoAttributeFinder.java
Expand Up @@ -14,11 +14,6 @@ public class GeoAttributeFinder {
private AttributeColumn longitudeColumn;
private AttributeColumn latitudeColumn;

public GeoAttributeFinder(AttributeColumn lonAttributeColumn, AttributeColumn latAttributeColumn) {
this.longitudeColumn = lonAttributeColumn;
this.latitudeColumn = latAttributeColumn;
}

AttributeColumn[] findGeoFields(AttributeColumn[] columns) {
String[] latAttributes = {"latitude", "^lat$", "^y$", "(.*)lat(.*)"};
String[] lonAttributes = {"longitude", "lon", "lng", "^x$", "(.*)lon(.*)", "(.*)lng(.*)"};
Expand Down
20 changes: 5 additions & 15 deletions src/com/hypercities/exporttoearth/KMZExporter.java
Expand Up @@ -114,7 +114,7 @@ public boolean execute() {
Float maxSize = new Float(0.0);

if (longitudeColumn == null || latitudeColumn == null) {
GeoAttributeFinder gaf = new GeoAttributeFinder(longitudeColumn, latitudeColumn);
GeoAttributeFinder gaf = new GeoAttributeFinder();
gaf.findGeoFields(model.getNodeTable().getColumns());
setColumnsToUse(gaf.getLongitudeColumn(), gaf.getLatitudeColumn(), model.getNodeTable().getColumns());
}
Expand Down Expand Up @@ -186,7 +186,6 @@ public boolean execute() {
ticket.setDisplayName("Finding nodes");
ticket.start(validNodes.size());

HashMap<Integer, Color> modularityClassColors = new HashMap<Integer, Color>();
IconRenderer renderer = new IconRenderer();

double maxScale = 2.0;
Expand All @@ -198,18 +197,8 @@ public boolean execute() {
Float weight = (Float) ni.getData(NodeItem.SIZE);

String description = "";
for (AttributeColumn ac : model.getNodeTable().getColumns()) {
if ((ac == null ? latitudeColumn != null
: !(ac == latitudeColumn)
&& (ac.getTitle() == null ? longitudeColumn != null
: !(ac == longitudeColumn)))) {

description += ac.getTitle() + ": " + row.getValue(ac) + "\n";

if (ac.getTitle().equals("Modularity Class")) {
modularityClassColors.put((Integer) row.getValue(ac), (Color) ni.getData(NodeItem.COLOR));
}
}
for (AttributeColumn ac : columnsToExport) {
description += ac.getTitle() + ": " + row.getValue(ac) + "\n";
}
Placemark placemark = folder.createAndAddPlacemark().withName((String) row.getValue("Label")).withDescription(description);

Expand All @@ -230,11 +219,12 @@ public boolean execute() {
}

if (styleCounter == 0) {
JOptionPane.showMessageDialog(null, "Sorry, we could not locate the preivew.\n"
JOptionPane.showMessageDialog(null, "Sorry, the Preview has not been rendred correctly.\n"
+ " Please try switching to Preview mode and running the plugin again.");
return false;
}

ticket.setDisplayName("Exporting edges");
// 2b. produce edges
for (Item i : previewModel.getItems(Item.EDGE)) {
Edge e = (Edge) i.getSource();
Expand Down
5 changes: 1 addition & 4 deletions src/com/hypercities/exporttoearth/KMZExporterUI.java
@@ -1,12 +1,9 @@
package com.hypercities.exporttoearth;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JPanel;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeController;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.io.exporter.spi.Exporter;
import org.gephi.io.exporter.spi.ExporterUI;
import org.openide.util.Lookup;
Expand All @@ -32,7 +29,7 @@ public JPanel getPanel() {
AttributeColumn[] columns = model.getNodeTable().getColumns();

// get geocoordinate fields
GeoAttributeFinder gaf = new GeoAttributeFinder(longitudeColumn, latitudeColumn);
GeoAttributeFinder gaf = new GeoAttributeFinder();
gaf.findGeoFields(columns);
longitudeColumn = gaf.getLongitudeColumn();
latitudeColumn = gaf.getLatitudeColumn();
Expand Down
@@ -1,21 +1,19 @@
package com.hypercities.exporttoearth;

import javax.swing.JPanel;
import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.io.exporter.spi.Exporter;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Dave Shepard
*/
public class KMZExporterUITest {
public class GeoAttributeFinderTest {

public KMZExporterUITest() {
public GeoAttributeFinderTest() {
}

@BeforeClass
Expand All @@ -26,9 +24,6 @@ public static void setUpClass() {
public static void tearDownClass() {
}

/**
* Test of findGeoFields method, of class KMZExporterUI.
*/
@Test
public void testFindGeoFieldsWithLatitudeAndLongitude() {
AttributeColumn[] columns = {
Expand All @@ -37,7 +32,7 @@ public void testFindGeoFieldsWithLatitudeAndLongitude() {
new MockAttributeColumn("latitude", AttributeType.DOUBLE),
new MockAttributeColumn("longitude", AttributeType.DOUBLE)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
// TODO review the generated test code and remove the default call to fail.
assertNotNull("Longitude not found.", resultColumns[0]);
Expand All @@ -51,7 +46,7 @@ public void testFindGeoFieldsWithLatitudeAndLongitudePartialNames() {
new MockAttributeColumn("PlaceLatitudeInDegrees", AttributeType.DOUBLE),
new MockAttributeColumn("PlaceLongitudeInDegrees", AttributeType.DOUBLE)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
// TODO review the generated test code and remove the default call to fail.
assertNotNull("PlaceLongitudeInDegrees not found.", resultColumns[0]);
Expand All @@ -65,7 +60,7 @@ public void testFindGeoFieldsWithLatitudeAndLongitudeButWrongTypes() {
new MockAttributeColumn("latitude", AttributeType.STRING),
new MockAttributeColumn("longitude", AttributeType.STRING)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
assertNull("Longitude found even though it's a string.", resultColumns[0]);
assertNull("Latitude found even though it's a string.", resultColumns[1]);
Expand All @@ -78,7 +73,7 @@ public void testFindGeoFieldsWithLatAndLon() {
new MockAttributeColumn("lat", AttributeType.DOUBLE),
new MockAttributeColumn("lon", AttributeType.DOUBLE)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
assertNotNull("Lon not found", resultColumns[0]);
assertNotNull("Lat not found", resultColumns[1]);
Expand All @@ -91,7 +86,7 @@ public void testFindGeoFieldsWithLatAndLng() {
new MockAttributeColumn("lat", AttributeType.DOUBLE),
new MockAttributeColumn("lng", AttributeType.DOUBLE)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
assertNotNull("lng not found", resultColumns[0]);
assertNotNull("lat not found", resultColumns[1]);
Expand All @@ -104,7 +99,7 @@ public void testFindGeoFieldsWithXAndY() {
new MockAttributeColumn("x", AttributeType.DOUBLE),
new MockAttributeColumn("y", AttributeType.DOUBLE)
};
KMZExporterUI instance = new KMZExporterUI();
GeoAttributeFinder instance = new GeoAttributeFinder();
AttributeColumn[] resultColumns = instance.findGeoFields(columns);
assertNotNull("Y not found", resultColumns[0]);
assertNotNull("X not found", resultColumns[1]);
Expand Down

0 comments on commit e8ecb3b

Please sign in to comment.