Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.event.MouseEvent;
- import java.io.*;
- import java.util.*;
- //import GUI.Move;
- public class Mapper extends GUI {
- List<Segment> outSegs = new ArrayList<Segment>();
- List<Segment> inSegs = new ArrayList<Segment>();
- List<Node> nodes = new ArrayList<Node>();
- List<Segment> segments = new ArrayList<Segment>();
- Map<Integer, Road> roads = new HashMap<>();
- Location origin = Location.newFromLatLon(Location.CENTRE_LAT, Location.CENTRE_LON-1);
- double lat_shift = 5;
- double long_shift = 5;
- double scale = 5;
- public Mapper() {
- // TODO Auto-generated constructor stub
- }
- @Override
- protected void redraw(Graphics g) {
- // draw nodes
- for (Node n : nodes) {
- Location loc = Location.newFromLatLon(n.latitude, n.longitude);
- Point point = loc.asPoint(origin, scale);
- g.fillOval(point.x, point.y, 1, 1);
- }
- }
- @Override
- protected void onClick(MouseEvent e) {
- System.out.println(e.getX());
- System.out.println(e.getY());
- System.out.println("onClick");
- }
- @Override
- protected void onSearch() {
- String search = getSearchBox().getText();
- System.out.print(search);
- }
- @Override
- protected void onMove(Move m) {
- if ( m == Move.EAST ) {
- Location neworigin = origin.moveBy(lat_shift, 0);
- origin = neworigin;
- getTextOutputArea().setText("MOVE EAST");
- } else if ( m == Move.WEST ) {
- Location neworigin = origin.moveBy(-lat_shift, 0);
- origin = neworigin;
- getTextOutputArea().setText("MOVE WEST");
- } else if ( m == Move.NORTH ) {
- Location neworigin = origin.moveBy(0, -long_shift);
- origin = neworigin;
- getTextOutputArea().setText("MOVE NORTH");
- } else if ( m == Move.SOUTH ) {
- Location neworigin = origin.moveBy(0, long_shift);
- origin = neworigin;
- getTextOutputArea().setText("MOVE SOUTH");
- } else if ( m == Move.ZOOM_IN ) {
- Dimension area = getDrawingAreaDimension();
- double oldscale = scale;
- scale += 0.5;
- // double midx = area.getWidth() / 2;
- // double midy = area.getHeight() / 2;
- // Location midpoint = new Location(midx, midy);
- // double distance = origin.distance(midpoint);
- double dx = ( area.getWidth() - ( area.getWidth() * ( oldscale / scale ) ) ) / 2;
- double dy = ( area.getHeight() - ( area.getHeight() * ( oldscale / scale ) ) ) / 2;
- System.out.println(dx);
- System.out.println(dy);
- // Point point = new Point(area.height, area.width);
- Location neworigin = origin.moveBy(origin.x + dx, origin.y + dy);
- origin = neworigin;
- getTextOutputArea().setText("ZOOM IN");
- } else if ( m == Move.ZOOM_OUT ) {
- scale--;
- Dimension area = getDrawingAreaDimension();
- double dx = ( area.width + ( area.width * scale ) ) / 2;
- double dy = ( area.height + ( area.height * scale ) ) / 2;
- Location neworigin = origin.moveBy(origin.x - dx, origin.y - dy);
- origin = neworigin;
- getTextOutputArea().setText("ZOOM OUT");
- }
- }
- @Override
- protected void onLoad(File nodesfile, File roadsfile, File segmentsfile, File polygonsfile) {
- BufferedReader nodesIn = null;
- //BufferedReader roadsIn = null;
- //BufferedReader segmentsIn = null;
- // Get nodes (intersections)
- try {
- nodesIn = new BufferedReader(new FileReader(nodesfile));
- String ln = nodesIn.readLine();
- int nodeID;
- double latitude, longitude;
- while (ln != null) {
- String[] splitln = ln.split("\\t"); // split line at tabs
- nodeID = Integer.parseInt(splitln[0]);
- latitude = Double.parseDouble(splitln[1]);
- longitude = Double.parseDouble(splitln[2]);
- Node n = new Node(nodeID, latitude, longitude);
- nodes.add(n);
- ln = nodesIn.readLine();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if ( nodesIn != null) {
- nodesIn.close();
- }
- } catch (IOException s) {
- System.out.print(s);
- }
- }
- // // Get roads
- // try {
- // roadsIn = new BufferedReader(new FileReader(roadsfile));
- // String ln = roadsIn.readLine();
- // int nodeID;
- // double latitude, longitude;
- // while (ln != null) {
- // String[] splitln = ln.split("\\t"); // split line at tabs
- // nodeID = Integer.parseInt(splitln[0]);
- // latitude = Double.parseDouble(splitln[1]);
- // longitude = Double.parseDouble(splitln[2]);
- // Node n = new Node(nodeID, latitude, longitude);
- // nodes.add(n);
- // ln = roadsIn.readLine();
- // }
- // } catch (IOException e) {
- // e.printStackTrace();
- // } finally {
- // try {
- // if ( roadsIn != null) {
- // roadsIn.close();
- // }
- // } catch (IOException s) {
- // System.out.print(s);
- // }
- // }
- //
- // Get segments
- // try {
- // segmentsIn = new BufferedReader(new FileReader(segmentsfile));
- // segmentsIn.readLine(); // headings line
- // String ln = segmentsIn.readLine();
- // int roadID, nodeID1, nodeID2;
- // double length;
- // double[][] coords;
- // while (ln != null) {
- // String[] splitln = ln.split("\\t"); // split line at tabs
- // roadID = Integer.parseInt(splitln[0]);
- // length = Double.parseDouble(splitln[1]);
- // nodeID1 = Integer.parseInt(splitln[2]);
- // nodeID2 = Integer.parseInt(splitln[3]);
- // for (int i=4; i<splitln.length; i+2){
- // double latitude = Double.parseDouble(splitln[4]);
- // double long
- // }
- // Node n = new Node(nodeID, latitude, longitude);
- // nodes.add(n);
- // ln = segmentsIn.readLine();
- // }
- // } catch (IOException e) {
- // e.printStackTrace();
- // } finally {
- // try {
- // if ( segmentsIn != null) {
- // segmentsIn.close();
- // }
- // } catch (IOException s) {
- // System.out.print(s);
- // }
- // }
- }
- public static void main(String[] args) {
- new Mapper();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement