package vnsim.gui; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Vector; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCanvas; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; import javax.swing.JPanel; import com.sun.opengl.util.Animator; import com.sun.opengl.util.GLUT; import vnsim.applications.adaptiveTL.IntersectionCarRecord; import vnsim.applications.adaptiveTL.WirelessTrafficLight; import vnsim.applications.trafficview.SimulatedCarInfo; import vnsim.core.CarInfo; import vnsim.map.object.Globals; import vnsim.map.object.Point; import vnsim.map.object.Road; import vnsim.map.utils.GPSutil; import vnsim.vehicular.simulator.CarInstance; import vnsim.vehicular.simulator.RouteSegment; import vnsim.vehicular.simulator.intersections.DirectedRoadSegment; import vnsim.vehicular.simulator.intersections.IntersectionWithTrafficLights; /** * @author Simion Liviu Mihai * */ public abstract class MapViewPanel extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener { /** * */ private static final long serialVersionUID = 1L; public GLCanvas canvas; /** Camera position */ public float xCamera, yCamera, zCamera; /** display lists */ public int mapList, carList, accCar, hAccCar, hDecCar, signalCar, decCar, stoppedCar, whiteCar, pinkCar, traceCar, carListOut, neighbor, endOfQueue, arrows, prioritySign, noPrioritySign, stopSign, DSRCapp; public int[] mapLevel; /** Clicks on the map */ public Vector zones; public HashMap carPositions = new HashMap(); public float high; /** Car currently selected */ public SimulatedCarInfo currentCar = null; public WirelessTrafficLight currentIntersection = null; public float reposCameraX = 0, reposCameraY = 0, reposCameraZ = 0; double maxX = 0, maxY = 0; int pressX, pressY, releaseX, releaseY; ArrayList ci; public Animator anim; public float maxlonglat = 0; public boolean printRoute = false; /** * * @param s * @param w * Latimea ferestrei. * @param h * Inaltimea ferestrei. */ public MapViewPanel(Statistics s, int w, int h) { super(); GLCapabilities capabilities = new GLCapabilities(); capabilities.setHardwareAccelerated(true); // and sets it's properties // Se creeaza un nou canvas canvas = new GLCanvas(); // Se adauga listeneri canvas.addGLEventListener(this); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); canvas.addKeyListener(this); canvas.addMouseWheelListener(this); // Se seteaza dimensiunea canvas.setSize(w, h); // Se face vizibil canvas.setVisible(true); // Se face un Animator pentru animarea canvasului anim = new Animator(canvas); // needed for constant displying // Se adauga canvasul pe panel si se seteaza dimensiunea panel-ului. this.add(canvas); this.setSize(w, h); // Se ruleaza animatorul anim.setRunAsFastAsPossible(true); anim.start(); this.zones = new Vector();// vector of mouse clicks } /** * Face initializarea OpenGL. */ public void init(GLAutoDrawable glDrawable) { GL myGL = glDrawable.getGL(); GLU myGLU = new GLU(); double width = this.getSize().getWidth(); double height = this.getSize().getHeight(); this.high = (float) Math.sqrt((double) ((((width * width) + (height * height))) / 4)); buildList(glDrawable); // builds all display lists // Culoarea atmosferei myGL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); myGL.glShadeModel(GL.GL_FASTEST); myGL.glMatrixMode(GL.GL_PROJECTION); // Incarca matricea identitate. myGL.glLoadIdentity(); myGLU.gluPerspective(60.0f, (double) width / height, 0.1f, 50000.0f); myGL.glMatrixMode(GL.GL_MODELVIEW); myGL.glLoadIdentity(); // Regleaza camera. myGLU.gluLookAt(xCamera, yCamera, zCamera, xCamera, yCamera, 0.0, 0.0, 1.0, 0.0); float maxlong = (float) Math.abs(Globals.maxPoint.getLongitude() - Globals.minPoint.getLongitude()); float maxlat = (float) Math.abs(Globals.maxPoint.getLatitude() - Globals.minPoint.getLatitude()); maxlonglat = maxlong > maxlat ? maxlong : maxlat; } /** * Deseneaza ruta masinii curente. * * @param glDrawable * Obiectul pe care se deseneaza */ public void drawRoute(GL myGL) { RouteSegment[] tp = null; // Daca masina curenta este null se revine. if (currentCar == null) { return; } // Se ia ruta masinii. synchronized (currentCar) { tp = currentCar.getRealPos().route; } // Daca exista o ruta o vom afisa. if (tp != null) { // Primul punct din segment, al doilea punct din segment. int p1, p2, r; // Pentru fiecare segment din ruta. for (int i = 0; i < tp.length; i++) { // Se preiau datele segmentului. r = tp[i].roadIndex; p1 = tp[i].pt1; p2 = tp[i].pt2; float x, y, x2, y2; Point currentPoint; // Se calculeaza coordonatele pe ecran ale primului punct. currentPoint = Globals.map.roads.get(r).points.get(p1); y = (float) GPSutil.getMetersLatitude(Globals.minPoint, currentPoint); x = (float) GPSutil.getMetersLongitude(Globals.minPoint, currentPoint); // Se calculeaza cordonatele pe ecran ale celui de-al doilea // punct currentPoint = Globals.map.roads.get(r).points.get(p2); y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, currentPoint); x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, currentPoint); // Se salveaza configuratia OpenGL curenta. myGL.glPushMatrix(); // Se seteaza culoarea de desenare. myGL.glColor3f(1.0f, 0.5f, 0.0f); // Se seteaza dimensiunea liniei. myGL.glLineWidth(2.0f); // Se deseneaza o linie intre cele 2 puncte de pe ecrn. myGL.glBegin(GL.GL_LINES); { myGL.glVertex3f(x, y, 1.0f); myGL.glVertex3f(x2, y2, 1.0f); } myGL.glEnd(); // Se revine la configuratia matricii. myGL.glPopMatrix(); } } } public void display_Semaphores(GL myGL) { Road currentRoad; Point currentPoint = null; float x = 0.0f, y = 0.0f, x2, y2, sinAlfa, cosAlfa, dx, dy; int laneNr; int i; ci = Globals.engine.cars; currentRoad = null; // Afiseaza semafoarele Integer idx; IntersectionWithTrafficLights tpI; DirectedRoadSegment drS; int tempPointIdx; // Pentru fiecare intersectie cu semafor for (i = 0; i < Globals.map.lightsIndices.size(); i++) { // Se preia intersectia respectiva idx = Globals.map.lightsIndices.get(i); tpI = (IntersectionWithTrafficLights) Globals.map.allIntersections.get(idx.intValue()); // Pentru fiecare segment care intra in intersectie for (int j = 0; j < tpI.segments.size(); j++) { // drS - Segmentul curent drS = tpI.segments.get(j); // Daca este doar iesire se trece la urmatorul segment. if (drS.isExitOnly()) continue; currentRoad = (Road) Globals.map.roads.get(drS.roadIndex); laneNr = currentRoad.laneNo; if (drS.direction) { tempPointIdx = drS.pointIndex + 2; while (currentRoad.points.size() <= tempPointIdx) { tempPointIdx--; } currentPoint = (Point) currentRoad.points.get(tempPointIdx); } else { tempPointIdx = drS.pointIndex - 2; while (tempPointIdx < 0) { tempPointIdx++; } currentPoint = (Point) currentRoad.points.get(tempPointIdx); } // Se salveaza coordonatele punctelor intre care va fi desenat. // segmentul. y = (float) GPSutil.getMetersLatitude(Globals.minPoint, currentPoint); x = (float) GPSutil.getMetersLongitude(Globals.minPoint, currentPoint); currentPoint = (Point) currentRoad.points.get(drS.pointIndex); y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, currentPoint); x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, currentPoint); // Daca punctele nu se suprapun if ((x2 != x) || (y2 != y)) { // Semaforul va fi perpendicular pe drum. sinAlfa = (float) ((y2 - y) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); cosAlfa = (float) ((x2 - x) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); // Latimea depinde de numarul de benzi. dx = (float) (laneNr * 2 * sinAlfa); dy = (float) (laneNr * 2 * cosAlfa); x2 = dx + x; y2 = y - dy; x = x - dx; y = y + dy; // myGL.glPushMatrix(); // TODO trebuie introdusa tpI.isYellow(int) // Se regleaza culoarea de desenare. if (tpI.isGreen(j)) { myGL.glColor3f(MyColor.color_SemaphoreGreen.getRed(), MyColor.color_SemaphoreGreen.getGreen(), MyColor.color_SemaphoreGreen.getBlue()); } else if (tpI.isRed(j)) { myGL.glColor3f(MyColor.color_SemaphoreRed.getRed(), MyColor.color_SemaphoreRed.getGreen(), MyColor.color_SemaphoreRed.getBlue()); } else { myGL.glColor3f(MyColor.color_SemaphoreYellow.getRed(), MyColor.color_SemaphoreYellow.getGreen(), MyColor.color_SemaphoreYellow.getBlue()); } myGL.glPushMatrix(); myGL.glLineWidth(2.0f); // Se deseneaza o linie reprezentand semaforul. myGL.glBegin(GL.GL_LINES); { myGL.glVertex3f(x, y, 1.0f); myGL.glVertex3f(x2, y2, 1.0f); } myGL.glEnd(); myGL.glPopMatrix(); } } } } public void display_Cars(GL myGL) { CarInfo elem; double offset; // Daca trebuie sa afseza rutele si este o masina selectata afiseaza // ruta. if (printRoute && currentCar != null) { drawRoute(myGL); } Road currentRoad; Point p, p2; float x = 0.0f, y = 0.0f, auxx, auxy, x2, y2, sinAlfa, cosAlfa, dx, dy; int dir, laneNr, ln; int i, pt; carPositions.clear(); synchronized (ci) { Iterator it = Globals.engine.cars.iterator(); // Se ia fiecare masina in parte. while (it.hasNext()) { elem = (SimulatedCarInfo) (it.next()); currentRoad = (Road) Globals.map.roads.get(elem.getRoadIdx()); pt = elem.getPointIdx(); offset = elem.getOffset(); p = (Point) currentRoad.points.get(pt); y = (float) GPSutil.getMetersLatitude(Globals.minPoint, p); x = (float) GPSutil.getMetersLongitude(Globals.minPoint, p); y2 = y; x2 = x; pt++; dir = (int) elem.getDirection(); try { p2 = (Point) currentRoad.points.get(pt); y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, p2); x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, p2); // Se inverseaza valorile if (dir == 0) { auxx = x; auxy = y; x = x2; y = y2; x2 = auxx; y2 = auxy; offset = p2.getDistance() - p.getDistance() - offset; } offset = offset * 1000; laneNr = currentRoad.laneNo; ln = elem.getLane(); if ((x2 != x) || (y2 != y)) { sinAlfa = (float) ((y2 - y) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); cosAlfa = (float) ((x2 - x) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); x = x + (float) (cosAlfa * offset); y = y + (float) (sinAlfa * offset); dx = (float) (((laneNr + 1 - ln) * 2 - 1) * sinAlfa); dy = (float) (((laneNr + 1 - ln) * 2 - 1) * cosAlfa); x = x + dx; y = y - dy; //System.out.println("1Car "+elem.getVehicleId()+":"+elem // +"road:"+currentRoad+"; point "+pt+ // " gets printed at: x="+x+"y="+y); // rd++; } } catch (Exception e) { } carPositions.put(elem, new MyPoint(x, y)); // Desenez masina in functie de ce tip este. // System.out.println(elem.getVehicleId()+" : "+x+" : "+y); myGL.glPushMatrix(); myGL.glTranslatef(x, y, 0.0f); myGL.glScalef(0.1f, 0.1f, 0.1f); if (currentCar != null && currentCar.equals(((SimulatedCarInfo) elem))) myGL.glCallList(pinkCar); else { if (Globals.monitoredCars.indexOf((SimulatedCarInfo) elem) != -1) myGL.glCallList(traceCar); else { CarInstance ci = ((SimulatedCarInfo) elem).getRealPos(); if (!Globals.comView) { if (ci.getSpeed() < 0.5) myGL.glCallList(stoppedCar); else { double acc = ci.accel / (3.6 * 3600); if (acc >= 2) myGL.glCallList(hAccCar); else if (acc >= 0) myGL.glCallList(accCar); else if (acc <= -3) myGL.glCallList(hDecCar); else myGL.glCallList(decCar); } int aux = Globals.engine.crtTime / Globals.SECOND; if (((SimulatedCarInfo) elem).getSignal() == 1 && ci.canSignal && aux % 2 == 0) { myGL.glCallList(signalCar); } } else { if (!((SimulatedCarInfo) elem).pulseMessage) myGL.glCallList(carList); else if (((SimulatedCarInfo) elem).isPromiscuousMode()) myGL.glCallList(pinkCar); else myGL.glCallList(whiteCar); } } } myGL.glPopMatrix(); if (currentCar != null && currentCar.trafficDB != null && currentCar.trafficDB.contains((SimulatedCarInfo) elem)) { myGL.glPushMatrix(); myGL.glTranslatef(x, y, 0.0f); myGL.glScalef(0.1f, 0.1f, 0.1f); myGL.glCallList(neighbor); myGL.glPopMatrix(); } if (currentIntersection != null) { boolean end = false; for (int j = 0; j < currentIntersection.segments.size(); j++) { DirectedRoadSegment seg = currentIntersection.segments.get(j); synchronized (currentIntersection.DBmutex) { // Daca nu exista masini trec mai departe. if (seg.cars == null) { continue; } ArrayList neighbors = seg.cars; for (i = 0; i < neighbors.size(); i++) { IntersectionCarRecord icr = (IntersectionCarRecord) neighbors.get(i); SimulatedCarInfo elem1 = icr.getCar(); if (elem1.equals(elem)) { boolean endCar = false; if (seg.endOfQueue[elem.getLane()].getCar() != null && seg.endOfQueue[elem.getLane()].equals(icr)) { endCar = true; } myGL.glPushMatrix(); myGL.glTranslatef(x, y, 0.0f); myGL.glScalef(0.1f, 0.1f, 0.1f); if (endCar) { myGL.glCallList(endOfQueue); } else { myGL.glCallList(neighbor); } myGL.glPopMatrix(); end = true; break; } } } if (end) break; } } } // } // S-au terminat de desenat masinile } } public void display_Arrows(GL myGL) { myGL.glPushMatrix(); myGL.glTranslatef(xCamera, yCamera, (float) (zCamera - this.high)); myGL.glCallList(arrows); myGL.glPopMatrix(); } public void display_Legend(GL myGL) { float raport, len, scale; String legend; raport = (float) (this.high / zCamera); myGL.glPushMatrix(); float x2 = (float) (xCamera - (((this.getSize().getWidth() * zCamera) / this.high) / 2)); x2 = x2 + (float) ((((this.getSize().getWidth() - 100) * zCamera) / this.high)); float y2 = (float) (yCamera - (((this.getSize().getHeight() * zCamera) / this.high) / 2)); y2 = y2 + (float) ((100 * zCamera) / this.high); myGL.glTranslatef(x2, y2, 2.0f); myGL.glColor3f(1.0f, 0.0f, 0.0f); myGL.glLineWidth(4.0f); len = 0.0f; legend = null; if ((10000 * raport) < (this.getSize().width / 3)) { len = 10000.0f; legend = new String("10 Km"); } else { if ((1000 * raport) < (this.getSize().width / 3)) { len = 1000.0f; legend = new String("1 Km"); } else { if ((100 * raport) < (this.getSize().width / 3)) { len = 100.0f; legend = new String("100 m"); } else { if ((10 * raport) < (this.getSize().width / 3)) { len = 10.0f; legend = new String("10 m"); } else { len = 1.0f; legend = new String("1 m"); } } } } // Afisez legenda GLUT myGLUT = new GLUT(); scale = myGLUT.glutStrokeLengthf(GLUT.STROKE_ROMAN, legend); scale = (float) ((50.0f) / (raport * scale)); myGL.glBegin(GL.GL_LINES); { myGL.glVertex3f(0.0f, 0.0f, 0.0f); myGL.glVertex3f(0.0f - len, 0.0f, 0.0f); } myGL.glEnd(); myGL.glPushMatrix(); myGL.glScalef(scale, scale, scale); myGLUT.glutStrokeString(GLUT.STROKE_ROMAN, legend); myGL.glPopMatrix(); myGL.glPopMatrix(); } /** * Metoda principala de desenare. */ public abstract void display(GLAutoDrawable glDrawable); public void reshape(GLAutoDrawable glDrawable, int i, int i1, int i2, int i3) { } /** * * @param glDrawable */ public abstract void buildList(GLAutoDrawable glDrawable); /** * */ public void displayChanged(GLAutoDrawable glDrawable, boolean b, boolean b1) { } /** * */ public void zoomIn() { if (zCamera > 50) { zCamera = (zCamera * 9) / 10; } canvas.repaint(); } /** * */ public void zoomOut() { if (zCamera < 100000.0f * maxlonglat) { zCamera = (zCamera * 12) / 10; }else{ zCamera = 100000.0f * (float) maxlonglat; } canvas.repaint(); } /** * */ public void goLeft() { xCamera = xCamera - zCamera / 10; canvas.repaint(); } /** * */ public void goRight() { xCamera = xCamera + zCamera / 10; canvas.repaint(); } /** * */ public void goUp() { yCamera = yCamera + zCamera / 10; canvas.repaint(); } /** * */ public void goDown() { yCamera = yCamera - zCamera / 10; canvas.repaint(); } /** * Se face zoom modificand coordonata z a camerei corespunzator. * * @param p1 * @param p2 */ void doZoom(Point2D.Float p1, Point2D.Float p2) { double worldX1, worldY1, worldX2, worldY2, temp; boolean zoomout = true; float w, h; float winX = p1.x; float winY = (float) this.getSize().height - (float) p1.y; w = (float) (this.getSize().width * zCamera) / high; h = (float) (this.getSize().height * zCamera) / high; worldX1 = xCamera - (float) (w / 2) + (winX * zCamera) / high; worldY1 = yCamera - (float) (h / 2) + (winY * zCamera) / high; winX = p2.x; winY = (float) this.getSize().height - (float) p2.y; worldX2 = xCamera - (float) (w / 2) + (winX * zCamera) / high; worldY2 = yCamera - (float) (h / 2) + (winY * zCamera) / high; if (worldX1 > worldX2) { temp = worldX1; worldX1 = worldX2; worldX2 = temp; } if (worldY1 > worldY2) { zoomout = false; temp = worldY1; worldY1 = worldY2; worldY2 = temp; } xCamera = (float) (((worldX2 - worldX1) / 2) + worldX1); yCamera = (float) (((worldY2 - worldY1) / 2) + worldY1); float wM, hM, diffW, diffH; wM = (float) (worldX2 - worldX1); hM = (float) (worldY2 - worldY1); diffW = ((this.getSize().width * zCamera) / high) - wM; diffH = ((this.getSize().height * zCamera) / high) - hM; if (!zoomout) { if (diffW < diffH) { zCamera = (high * wM) / this.getSize().width; } else { zCamera = (high * hM) / this.getSize().height; } } else { if (diffW < diffH) { zCamera = zCamera + 15 * (zCamera * (diffH)) / this.getSize().height; } else { zCamera = zCamera + 15 * (zCamera * (diffW)) / this.getSize().width; } } if (zCamera < 50.0f) { zCamera = 50.0f; } if (zCamera > 100000.0f * maxlonglat) { zCamera = 100000.0f * (float) maxlonglat; } } /** * */ public void mouseEntered(MouseEvent e) { } /** * */ public void mouseExited(MouseEvent e) { } /** * Cand este apasat un buton de mouse. */ public void mousePressed(MouseEvent e) { this.pressX = e.getX(); this.pressY = e.getY(); } /** * Cand este eliberat butonul de mouse. */ public void mouseReleased(MouseEvent e) { this.releaseX = e.getX(); this.releaseY = e.getY(); if ((this.pressX != this.releaseX) || (this.pressY != this.releaseY)) { if ((this.releaseX > 30) && (this.releaseX < (this.getSize().getWidth() - 30)) && (this.releaseY > 60) && (this.releaseY < (this.getSize().getHeight() - 60))) { doZoom(new Point2D.Float(pressX, pressY), new Point2D.Float(releaseX, releaseY)); } } } public void selection(MouseEvent e) { } /** * */ public void mouseClicked(MouseEvent e) { // isDragged = true; float x = e.getX(); float y = e.getY(); if ((x < 30) && (y < 60)) { goUp(); goLeft(); return; } if ((this.getSize().getWidth() - 30 < x) && (y < 60)) { goRight(); goUp(); return; } if ((x < 30) && (y > this.getSize().getHeight() - 60)) { goLeft(); goDown(); return; } if ((this.getSize().getWidth() - 30 < x) && (y > this.getSize().getHeight() - 60)) { goDown(); goRight(); return; } if (this.getSize().getWidth() - 30 < x) { goRight(); return; } if (x < 30) { goLeft(); return; } if (y < 60) { goUp(); return; } if (y > this.getSize().getHeight() - 60) { goDown(); return; } selection(e); } /** * * @param e */ public void mouseDragged(MouseEvent e) { } /** * * @param e */ public void mouseMoved(MouseEvent e) { } /** * Petroaca * * @param elem * @param myGL */ public void drawDSRCCar(CarInfo elem, GL myGL) { Road currentRoad; Point p, p2; float x = 0.0f, y = 0.0f, auxx, auxy, x2, y2, sinAlfa, cosAlfa, dx, dy; int dir, laneNr, ln; int pt; double offset; currentRoad = (Road) Globals.map.roads.get(elem.getRoadIdx()); pt = elem.getPointIdx(); offset = elem.getOffset(); p = (Point) currentRoad.points.get(pt); y = (float) GPSutil.getMetersLatitude(Globals.minPoint, p); x = (float) GPSutil.getMetersLongitude(Globals.minPoint, p); y2 = y; x2 = x; pt++; dir = (int) elem.getDirection(); try { p2 = (Point) currentRoad.points.get(pt); y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, p2); x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, p2); if (dir == 0) { auxx = x; auxy = y; x = x2; y = y2; x2 = auxx; y2 = auxy; offset = p2.getDistance() - p.getDistance() - offset; } offset = offset * 1000; laneNr = currentRoad.laneNo; ln = elem.getLane(); if ((x2 != x) || (y2 != y)) { sinAlfa = (float) ((y2 - y) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); cosAlfa = (float) ((x2 - x) / (Math.sqrt((y2 - y) * (y2 - y) + (x2 - x) * (x2 - x)))); x = x + (float) (cosAlfa * offset); y = y + (float) (sinAlfa * offset); dx = (float) (((laneNr + 1 - ln) * 2 - 1) * sinAlfa); dy = (float) (((laneNr + 1 - ln) * 2 - 1) * cosAlfa); x = x + dx; y = y - dy; } } catch (Exception e) { } myGL.glPushMatrix(); { myGL.glTranslatef(x, y, 0.0f); myGL.glScalef(0.1f, 0.1f, 0.1f); myGL.glCallList(DSRCapp); } myGL.glPopMatrix(); } public Point recoverRoad(float x, float y) { float y2 = (float) GPSutil.getMetersLatitude(Globals.minPoint, Globals.maxPoint); float x2 = (float) GPSutil.getMetersLongitude(Globals.minPoint, Globals.maxPoint); maxX = x2; maxY = y2; Point currentPoint; double l, L; l = Globals.map.maxPoint.getLongitude() - Globals.map.minPoint.getLongitude(); l = (double) l / maxX; l = (double) (x * l + Globals.map.minPoint.getLongitude()); L = Globals.map.maxPoint.getLatitude() - Globals.map.minPoint.getLatitude(); L = (double) L / maxY; L = (double) (y * L + Globals.map.minPoint.getLatitude()); currentPoint = new Point(l, L); return currentPoint; } public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == KeyEvent.VK_UP) { goUp(); } if (e.getKeyCode() == KeyEvent.VK_DOWN) { goDown(); } if (e.getKeyCode() == KeyEvent.VK_LEFT) { goLeft(); } if (e.getKeyCode() == KeyEvent.VK_RIGHT) { goRight(); } if (e.getKeyCode() == KeyEvent.VK_EQUALS) { zoomIn(); } if (e.getKeyCode() == KeyEvent.VK_MINUS) { zoomOut(); } } public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } public void mouseWheelMoved(MouseWheelEvent e) { // TODO Auto-generated method stub if (e.getWheelRotation()>0){ zoomIn(); } if (e.getWheelRotation()<0){ zoomOut(); } } }