NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.*;
import java.util.List;

/**
* Created by Sean on 7/03/17.
*/
public class main extends GUI {
private Map<Integer, Road> roadMap = new HashMap<Integer, Road>();
private Map<Integer, Node> nodeMap = new HashMap<Integer, Node>();
private Set<Segment> segmentSet = new HashSet<Segment>();
public static Location origin = new Location(0,0);
public static double scale = 100;

@Override
protected void redraw(Graphics g) {
for (Node no : nodeMap.values()) {
no.draw(g);
}
for (Segment seg : segmentSet) {
seg.draw(g);
}

}

@Override
protected void onClick(MouseEvent e) {
Point p = new Point(e.getX(), e.getY());
Location loc = newFromPoint(p, this.origin, this.scale);
double xM = loc.x;
double yM = (loc.y+1.1);

for(Node n : nodeMap.values()){
Location lo = n.getLoc();

double mod = 0.07;

if (xM > n.getLoc().x - mod && xM < n.getLoc().x + mod &&
yM > n.getLoc().y - mod && yM < n.getLoc().y + mod) {
System.out.println("swag");
n.setFe(10);
n.setColor(Color.yellow);
return;
}
}
}

@Override
protected void onSearch() {
String search = getSearchBox().getText();
for(Road ro : roadMap.values()) {
if(search.equals(ro.getLabel())){
getTextOutputArea().setText(null);
for(Segment seg : ro.getSegments()){
//write code to set colour back to original
seg.setColor(Color.magenta);
System.out.println("yM ");
}
getTextOutputArea().setText(ro.info());
}
}

}
// for(Segment seg : segmentSet){
// if(seg.getSegID() == ro.getID()){
//
// }
// }


@Override
protected void onMove(Move m) {
switch (m) {
case NORTH:
origin = origin.moveBy(0, 0.3);
break;
case SOUTH:
origin = origin.moveBy(0, -0.3);
break;
case EAST:
origin = origin.moveBy(0.3, 0);
break;
case WEST:
origin = origin.moveBy(-0.3, 0);
break;
case ZOOM_IN:
scale = scale*1.15;
origin = origin.moveBy(0.1*1.15, -0.1*1.15);
break;
case ZOOM_OUT:
scale = scale*0.85;
origin = origin.moveBy(-0.1*0.85, 0.1*0.85);
break;
}

}

@Override
protected void onLoad(File nodes, File roads, File segments, File polygons) {
try {
BufferedReader data = new BufferedReader(new FileReader(roads));
data.readLine();
String line = data.readLine();
while (line != null){
String[] values = line.split("t");
int roadID = Integer.parseInt(values[0]);
int type = Integer.parseInt(values[1]);
String label = values[2];
String city = values[3];
boolean oneway = Integer.parseInt(values[4]) == 1;
int speed = Integer.parseInt(values[5]);
int rClass = Integer.parseInt(values[5]);
boolean nfc = Integer.parseInt(values[7]) == 1;
boolean nfp = Integer.parseInt(values[8]) == 1;
boolean nfb = Integer.parseInt(values[9]) == 1;
Road road = new Road(roadID, type, label, city, oneway, speed, rClass, nfc, nfp, nfb);
roadMap.put(roadID, road);
line = data.readLine();
}
}
catch(Exception e) {
System.out.println(e);
}

try {
BufferedReader data = new BufferedReader(new FileReader(nodes));
String line = data.readLine();
while (line != null){
String[] values = line.split("t");
int nodeID = Integer.parseInt(values[0]);
double lat = Double.parseDouble(values[1]);
double lon = Double.parseDouble(values[2]);
//Location loca = new Location(lat, lon);
Location loca = Location.newFromLatLon(lat, lon);
Node node = new Node(nodeID, loca);
nodeMap.put(nodeID, node);
line = data.readLine();
}
}
catch(Exception e) {
System.out.println(e);
}
try {
BufferedReader data = new BufferedReader(new FileReader(segments));
data.readLine();
String line = data.readLine();
while (line != null) {
String[] values = line.split("t");
int segID = Integer.parseInt(values[0]);
double length = Double.parseDouble(values[1]);
int nodeID1 = Integer.parseInt(values[2]);
int nodeID2 = Integer.parseInt(values[3]);
ArrayList<Location> coord = new ArrayList<Location>();
for (int i = 5; i < values.length; i+=2) {
if (values[i] != null) {
Location loca = new Location(0,0);

loca = loca.newFromLatLon(Double.parseDouble(values[i-1]), Double.parseDouble(values[i]));
coord.add(loca);
}
}
Road segRoad = roadMap.get(segID);
Node segNode1 = nodeMap.get(nodeID1);
Node segNode2 = nodeMap.get(nodeID2);
Color color = Color.black;

switch(segRoad.getRClass()) {
case 0:
color = Color.yellow;
break;
case 1:
color = Color.green;
break;
case 2:
color = Color.black;
break;
case 3:
color = Color.blue;
break;
case 4:
color = Color.red;
break;
}
Segment seg = new Segment(segID, segRoad, segNode1, segNode2, coord, color);
segNode1.addInSeg(seg);
segNode2.addOutSeg(seg);
segRoad.addSeg(seg);
segmentSet.add(seg);
line = data.readLine();
}
}
catch(Exception e) {
System.out.println(e);
}
}

public static void main(String[] arguments) {
new main();
}

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.