Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull from master #4

Merged
merged 15 commits into from
Nov 19, 2016
4 changes: 2 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="GO_Sync/src"/>
<classpathentry kind="src" path="GO_Sync/src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="GO_Sync/swingx-ws-1.0-bin/swingx-ws-1.0.jar"/>
<classpathentry kind="lib" path="/usr/share/java/swingx.jar"/>
<classpathentry kind="lib" path="/usr/share/java/AbsoluteLayout.jar"/>

<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion GO_Sync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>edu.usf.cutr.osm</groupId>
<artifactId>gtfs-osm-sync</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<name>GO_Sync</name>
<url>https://github.com/CUTR-at-USF/gtfs-osm-sync/</url>
<dependencies>
Expand Down
7 changes: 6 additions & 1 deletion GO_Sync/src/main/java/edu/usf/cutr/go_sync/gui/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public MainForm() {
setMinimumSize(new Dimension(660, 460));

DefaultOperatorReader reader = new DefaultOperatorReader(); //create a new reader
ops = reader.readOperators(new File("operators.csv").getAbsolutePath()); //read a file with operator info for autocompletion
try {
ops = reader.readOperators(getClass().getResourceAsStream("/operators.csv")); //read a file with operator info for autocompletion
}
catch (Exception e) {
ops = reader.readOperators(new File("operators.csv").getAbsolutePath()); //read a file with operator info for autocompletion
}

//TODO Fix textfield with ops is null (operators.csv doesn't exist)

Expand Down
78 changes: 56 additions & 22 deletions GO_Sync/src/main/java/edu/usf/cutr/go_sync/gui/ReportViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
Expand Down Expand Up @@ -70,6 +71,7 @@
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.GroupLayout;
import javax.swing.JPanel;
Expand Down Expand Up @@ -149,12 +151,32 @@ public class ReportViewer extends javax.swing.JFrame implements TableModelListen
private JProgressBar progressBar;

private boolean generateStopsToUploadFlag = false;

protected ImageIcon busIcon;

protected static Color matchColor, selectedOSMColor, selectedGTFSColor;


/** Creates new form ReportViewer */




public ReportViewer(List<Stop> aData, Hashtable<Stop, ArrayList<Stop>> r, HashSet<Stop>u, HashSet<Stop>m, HashSet<Stop>d, Hashtable routes, Hashtable nRoutes, Hashtable eRoutes, JTextArea to) {
super("GO-Sync: Report");
super.setResizable(true); //false);

try {
busIcon = new javax.swing.ImageIcon(this.getClass().getClassLoader().getResource("bus_icon.png"));
}
catch (Exception e) {
busIcon = new javax.swing.ImageIcon(this.getClass().getResource("bus_icon.png"));
}

matchColor = new Color(255,255,0,150);
selectedOSMColor = new Color(0,127,0,150);
selectedGTFSColor = new Color(0,0,127,150);

// set tooltip time for 10 seconds
javax.swing.ToolTipManager.sharedInstance().setDismissDelay(10000);

Expand Down Expand Up @@ -631,27 +653,20 @@ private void addNewBusStopToMap(ArrayList<Stop> newStops){
//crate a WaypointPainter to draw the points
stopsPainter.setWaypoints(waypoints);

stopsPainter.setRenderer(new DefaultWaypointRenderer() {
public boolean paintWaypoint(Graphics2D g, JXMapViewer map, JXMapViewer v, Waypoint wp) {
Image busIcon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/edu/usf/cutr/go_sync/gui/bus_icon.png")); //Toolkit.getDefaultToolkit().getImage("bus_icon.png");
g.drawImage(busIcon, -5, -5, map);
return true;
}
stopsPainter.setRenderer(new WaypointRenderer<Waypoint>() {
// public boolean paintWaypoint(Graphics2D g, JXMapViewer map, JXMapViewer v, Waypoint wp) {
// g.drawImage(busIcon.getImage(), -5, -5, map);
// return true;
// }
public void paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint wp) {
Image busIcon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/edu/usf/cutr/go_sync/gui/bus_icon.png")); //Toolkit.getDefaultToolkit().getImage("bus_icon.png");
Point2D point = map.getTileFactory().geoToPixel(wp.getPosition(), map.getZoom());

int x = (int)point.getX() -16/ 2;
int y = (int)point.getY() -16;

g.drawImage(busIcon,x, y, map);
return;
g.drawImage(busIcon.getImage(),x, y, map);
return ;
}
// public void paintWaypoint(Graphics2D g, JXMapViewer map,Object waypoint) {
// Image busIcon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/edu/usf/cutr/go_sync/gui/bus_icon.png")); //Toolkit.getDefaultToolkit().getImage("bus_icon.png");
// g.drawImage(busIcon, -5, -5, map);
// System.out.println(busIcon.g);
// }
});

mainMap.setZoom(1);
Expand Down Expand Up @@ -734,7 +749,7 @@ public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
JXMapViewer mainMap = mapJXMapKit.getMainMap();
Iterator it = matchStop.iterator();
while(it.hasNext()){
g.setColor(new Color(255,255,0,150));
g.setColor(matchColor);
Stop st = (Stop)it.next();
GeoPosition st_gp = new GeoPosition(Double.parseDouble(st.getLat()), Double.parseDouble(st.getLon()));
//convert to pixel
Expand Down Expand Up @@ -772,7 +787,7 @@ public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
Rectangle rect = map.getViewportBounds();
// g.translate(-rect.x, -rect.y);

g.setColor(new Color(0,0,127,150));
g.setColor(selectedGTFSColor);

JXMapViewer mainMap = mapJXMapKit.getMainMap();

Expand Down Expand Up @@ -802,7 +817,7 @@ public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
Rectangle rect = map.getViewportBounds();
// g.translate(-rect.x, -rect.y);

g.setColor(new Color(0,127,0,150));
g.setColor(selectedOSMColor);

JXMapViewer mainMap = mapJXMapKit.getMainMap();

Expand Down Expand Up @@ -1142,6 +1157,25 @@ public String GetGeneralInformationToRouteTextArea(){
public void SetGeneralInformationToRouteTextArea(String s){
generalInformationRouteTextArea.setText(s);
}

protected ImageIcon generateImageIcon (Color c)
{
int w = 20;
int h =20;

BufferedImage img = new BufferedImage( w,h, BufferedImage.TYPE_INT_ARGB );
// Get a Graphics object
Graphics2D g = img.createGraphics();

// Create white background
g.setColor( Color.WHITE );
g.fillRect( 0, 0, w,h);
g.setColor( Color.BLACK );
g.drawRect( 0, 0, w-1,h-1);
g.setColor(c);
g.fillRect( 1, 1, w-2,h-2 );
return new ImageIcon(img);
}

/** This method is called from within the constructor to
* initialize the form.
Expand Down Expand Up @@ -1586,7 +1620,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
busStopPanel.add(donotUploadButton, gbc_donotUploadButton);
jLabel18 = new javax.swing.JLabel();

jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/usf/cutr/go_sync/gui/bus_icon.png"))); // NOI18N
jLabel18.setIcon(busIcon); // NOI18N
jLabel18.setText("New Stop");
jLabel18.setName("jLabel18"); // NOI18N
GridBagConstraints gbc_jLabel18 = new GridBagConstraints();
Expand All @@ -1607,8 +1641,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
gbc_tableStopButton.gridy = 5;
busStopPanel.add(tableStopButton, gbc_tableStopButton);
jLabel15 = new javax.swing.JLabel();

jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/usf/cutr/go_sync/gui/yellow.png"))); // NOI18N
jLabel15.setIcon(generateImageIcon(matchColor)); // NOI18N
jLabel15.setText("Potential Match Stops");
jLabel15.setName("jLabel15"); // NOI18N
jLabel15.setOpaque(true);
Expand Down Expand Up @@ -1649,7 +1682,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
busStopPanel.add(jLabel3, gbc_jLabel3);
jLabel16 = new javax.swing.JLabel();

jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/usf/cutr/go_sync/gui/green.png"))); // NOI18N
jLabel16.setIcon(generateImageIcon(selectedOSMColor)); // NOI18N
jLabel16.setText("Selected Osm Stop");
jLabel16.setName("jLabel16"); // NOI18N
jLabel16.setOpaque(true);
Expand All @@ -1662,7 +1695,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
busStopPanel.add(jLabel16, gbc_jLabel16);
jLabel17 = new javax.swing.JLabel();

jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/usf/cutr/go_sync/gui/blue.png"))); // NOI18N

jLabel17.setIcon(generateImageIcon(selectedGTFSColor)); // NOI18N
jLabel17.setText("Selected Gtfs Stop");
jLabel17.setName("jLabel17"); // NOI18N
jLabel17.setOpaque(true);
Expand Down
Binary file removed GO_Sync/src/main/java/edu/usf/cutr/go_sync/gui/blue.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import edu.usf.cutr.go_sync.object.DefaultOperator;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,76 +21,103 @@
*/
public class DefaultOperatorReader {

public List<DefaultOperator> readOperators(String fName){


private List<DefaultOperator> readOperatorsInternal (BufferedReader br) throws IOException
{
String thisLine;
String [] elements;
List<DefaultOperator> ops = new ArrayList<DefaultOperator>();
try {
BufferedReader br = new BufferedReader(new FileReader(fName));
boolean isFirstLine = true;
while ((thisLine = br.readLine()) != null) {
if (isFirstLine) {
isFirstLine = false;
}

boolean isFirstLine = true;
while ((thisLine = br.readLine()) != null) {
if (isFirstLine) {
isFirstLine = false;
}
else {
thisLine = thisLine.trim();

if(thisLine.contains("\"")) {
String[] temp = thisLine.split("\"");
ArrayList<String> l = new ArrayList<String>();
l.add(temp[1].toString());
int commas = temp[1].replaceAll("[^,]", "").length();

elements = thisLine.split(",");

for(int i = 0; i < elements.length; i++) {
if(i > commas) {
l.add(elements[i].toString());
}
}
elements = (String[]) l.toArray(new String[0]);
}
else {
thisLine = thisLine.trim();
elements = thisLine.split(",");
}


DefaultOperator op = new DefaultOperator(elements[0]);

System.out.print(":: ");
for(int i = 0; i < elements.length; i++) {
System.out.print(elements[i] + " : ");

if(thisLine.contains("\"")) {
String[] temp = thisLine.split("\"");
ArrayList l = new ArrayList();
l.add(temp[1].toString());
int commas = temp[1].replaceAll("[^,]", "").length();

elements = thisLine.split(",");

for(int i = 0; i < elements.length; i++) {
if(i > commas) {
l.add(elements[i].toString());
}
}
elements = (String[]) l.toArray(new String[0]);
}
else {
elements = thisLine.split(",");
if(i == 1 && elements[1] != null) {
op.setOperatorAbbreviation(elements[1]);
}


DefaultOperator op = new DefaultOperator(elements[0]);

System.out.print(":: ");
for(int i = 0; i < elements.length; i++) {
System.out.print(elements[i] + " : ");

if(i == 1 && elements[1] != null) {
op.setOperatorAbbreviation(elements[1]);
}

if(i == 2 && elements[2] != null) {
try{
op.setNtdID(Integer.parseInt(elements[2]));
} catch(NumberFormatException ex) {
System.err.println("Error parsing NTD ID " + elements[2] + " - " + ex.getLocalizedMessage());
}
}

if(i == 3 && elements[3] != null) {
op.setGtfsURL(elements[3]);
}

if(i == 4 && elements[4] != null) {
try{
op.setStopDigits(Integer.parseInt(elements[4]));
} catch(NumberFormatException ex) {
System.err.println("Error parsing stop digits " + elements[4] + " - " + ex.getLocalizedMessage());
}
if(i == 2 && elements[2] != null) {
try{
op.setNtdID(Integer.parseInt(elements[2]));
} catch(NumberFormatException ex) {
System.err.println("Error parsing NTD ID " + elements[2] + " - " + ex.getLocalizedMessage());
}
}
System.out.println(" :: ");

ops.add(op);
if(i == 3 && elements[3] != null) {
op.setGtfsURL(elements[3]);
}

if(i == 4 && elements[4] != null) {
try{
op.setStopDigits(Integer.parseInt(elements[4]));
} catch(NumberFormatException ex) {
System.err.println("Error parsing stop digits " + elements[4] + " - " + ex.getLocalizedMessage());
}
}
}
}
System.out.println(" :: ");

ops.add(op);
}
}
return ops;
}


// BufferedReader txtReader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/resources/mytextfile.txt")));
public List<DefaultOperator> readOperators(InputStream fName){


try {
BufferedReader br = new BufferedReader(new InputStreamReader(fName));
List<DefaultOperator> ops = readOperatorsInternal(br);
br.close();
return ops;
}
catch (IOException e) {
System.err.println("Error reading in default operators: " + e.getLocalizedMessage());
return null;
}
}

public List<DefaultOperator> readOperators(String fName){


try {
BufferedReader br = new BufferedReader(new FileReader(fName));
List<DefaultOperator> ops = readOperatorsInternal(br);
br.close();
return ops;
}
catch (IOException e) {
Expand Down
Loading