From 08d5f7b0a0b24c042aa5976f66bf3a1b5b754478 Mon Sep 17 00:00:00 2001 From: Richard Zahoransky Date: Mon, 7 Nov 2011 16:29:56 +0100 Subject: Localization Code. How-To will follow... --- gui/ShowMapStrength.java | 309 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100644 gui/ShowMapStrength.java (limited to 'gui/ShowMapStrength.java') diff --git a/gui/ShowMapStrength.java b/gui/ShowMapStrength.java new file mode 100644 index 0000000..a74e064 --- /dev/null +++ b/gui/ShowMapStrength.java @@ -0,0 +1,309 @@ +package gui; + +import helper.ListBTS; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Label; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.awt.geom.Point2D; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.ObjectInputStream; + +import javax.swing.JFrame; + +import org.jdesktop.swingx.JXMapKit; +import org.jdesktop.swingx.JXMapKit.DefaultProviders; +import org.jdesktop.swingx.JXMapViewer; +import org.jdesktop.swingx.mapviewer.DefaultTileFactory; +import org.jdesktop.swingx.mapviewer.GeoPosition; +import org.jdesktop.swingx.mapviewer.TileFactoryInfo; +import org.jdesktop.swingx.painter.Painter; + +import DataStructure.GSMMap; +import DataStructure.GSMMap.PaintEnum; +import DataStructure.Interpolator; +import DataStructure.SingleBTS; + +public class ShowMapStrength { + // private static blub overlay; + private static int index = 0; + private GSMMap.PaintEnum whatToPaint = GSMMap.PaintEnum.DL; + static int paintindex = 0; + + /** + * @param args + * @throws IOException + * @throws FileNotFoundException + * @throws ClassNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException, + IOException, ClassNotFoundException { + JFrame frame = new JFrame(); + // JFrame control = new JFrame(); + frame.addWindowListener(new closeWindow()); + + frame.setSize(400, 400); + final JXMapKit mapViewer = new JXMapKit(); + // JXMapViewer + // Painter + mapViewer.setDefaultProvider(DefaultProviders.OpenStreetMaps); + mapViewer.setDataProviderCreditShown(true); + frame.add(mapViewer, BorderLayout.CENTER); + Button knopf1 = new Button("change ARFCN"); + Button knopf2 = new Button("Map -"); + Button knopf3 = new Button("Map +"); + frame.add(knopf1, BorderLayout.SOUTH); + frame.add(knopf2, BorderLayout.WEST); + frame.add(knopf3, BorderLayout.EAST); + final Label label1 = new Label(); + frame.add(label1, BorderLayout.NORTH); + + frame.setVisible(true); + System.out.println("da"); + // ObjectInputStream ois = new ObjectInputStream(new FileInputStream( + // "parallel.obj")); + ObjectInputStream ois = new ObjectInputStream(new FileInputStream( + "parallel-strictdB-BER.obj")); + // ObjectInputStream ois = new ObjectInputStream(new FileInputStream( + // "D:/parallel-strictdB-BER.obj")); + final Interpolator map = (Interpolator) ois.readObject(); + + System.out.println("GSMMap eingelesen"); + + mapViewer.setAddressLocation(new GeoPosition((map.minY + map.maxY) / 2, + (map.minX + map.maxX) / 2)); + mapViewer.setZoom(1); + mapViewer.setAddressLocationShown(true); + + mapViewer.setDefaultProvider(DefaultProviders.Custom); + + TileFactoryInfo ownTileFactory = new TileFactoryInfo(0, 18, 18, 256, + false, false, "http://b.tile.openstreetmap.org", "/", "/", "/") { + public String getTileUrl(int x, int y, int zoom) { + return this.baseURL + "/" + (18 - zoom) + "/" + x + "/" + y + + ".png"; + } + }; + mapViewer.setTileFactory(new DefaultTileFactory(ownTileFactory)); + + mapViewer.setAddressLocation(new GeoPosition((map.minY + map.maxY) / 3, + (map.minX + map.maxX) / 3)); + mapViewer.setAddressLocationShown(true); + mapViewer.setZoom(1); + mapViewer.setCenterPosition(new GeoPosition((map.minY + map.maxY) / 2, + (map.minX + map.maxX) / 2)); + + // overlay = new blub(map, map.content()[index]); + map.whatToPaint = GSMMap.PaintEnum.DL; + map.indexToPaint = 0; + + mapViewer.getMainMap().setOverlayPainter(map); + + knopf1.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + index++; + if (index > map.content().length - 1) { + index = 0; + } + map.indexToPaint = index; + mapViewer.getMainMap().setOverlayPainter(map); + // overlay = new blub(map, map.content()[index]); + // mapViewer.getMainMap().setOverlayPainter( + // (org.jdesktop.swingx.painter.Painter) overlay); + label1.setText("ARFCN:" + map.content()[index].ARFCN); + // label1.setAlignment(2); + + } + }); + + knopf2.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // map.whatToPaint = GSMMap.PaintEnum.DL; + paintindex++; + if (paintindex > PaintEnum.values().length - 1) { + paintindex = 0; + } + map.whatToPaint = PaintEnum.values()[paintindex]; + mapViewer.getMainMap().setOverlayPainter(map); + } + }); + knopf3.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // map.whatToPaint = GSMMap.PaintEnum.variance; + // mapViewer.getMainMap().setOverlayPainter(map); + paintindex--; + if (paintindex < 0) { + paintindex = PaintEnum.values().length - 1; + } + map.whatToPaint = PaintEnum.values()[paintindex]; + mapViewer.getMainMap().setOverlayPainter(map); + + } + }); + + } +} + +class blub implements Painter { + private GSMMap gsmmap; + private SingleBTS what; + + public blub(GSMMap map, SingleBTS what) { + this.gsmmap = map; + this.what = what; + } + + public void paint(Graphics2D g, JXMapViewer map, int w, int h) { + g = (Graphics2D) g.create(); + // convert from viewport to world bitmap + Rectangle rect = ((org.jdesktop.swingx.JXMapViewer) map) + .getViewportBounds(); + g.translate(-rect.x, -rect.y); + + // draw each rectangle + for (int x = 0; x < gsmmap.Xcoords.length; x++) { + for (int y = 0; y < gsmmap.Ycoords.length; y++) { + SingleBTS current = ListBTS.getARFCN(gsmmap.map[x][y], what); + if (current != null) { + // draw it + double coordX = gsmmap.Xcoords[x]; + double coordY = gsmmap.Ycoords[y]; + double accuracy = gsmmap.accuracy; + Polygon tile = new Polygon(); + + GeoPosition pos1 = new GeoPosition(coordY - accuracy / 2, + coordX + accuracy / 2); + GeoPosition pos2 = new GeoPosition(coordY + accuracy / 2, + coordX + accuracy / 2); + GeoPosition pos3 = new GeoPosition(coordY + accuracy / 2, + coordX - accuracy / 2); + GeoPosition pos4 = new GeoPosition(coordY - accuracy, + coordX - accuracy); + Point2D pt1 = map.getTileFactory().geoToPixel(pos1, + map.getZoom()); + Point2D pt2 = map.getTileFactory().geoToPixel(pos2, + map.getZoom()); + Point2D pt3 = map.getTileFactory().geoToPixel(pos3, + map.getZoom()); + Point2D pt4 = map.getTileFactory().geoToPixel(pos4, + map.getZoom()); + + // finally, draw it! + Color color = getColor((int) current.getDldB()); + g.setColor(color); + tile.addPoint((int) pt1.getX(), (int) pt1.getY()); + tile.addPoint((int) pt2.getX(), (int) pt2.getY()); + tile.addPoint((int) pt3.getX(), (int) pt3.getY()); + tile.addPoint((int) pt4.getX(), (int) pt4.getY()); + g.fill(tile); + g.draw(tile); + + } + } + } + g.dispose(); + } + + private Color getColor(int strength) { + int green = 0; + int red = 0; + // yellow at -75 + if (strength > -75) { + green = 255; + red = 256 - Math.abs((256 / 45) * (-75 - strength)); + + } else { + // transient green from now on + red = 255; + green = Math.abs((256 / 45) * (-120 - strength)); + } + // int green = 256 - Math.abs((256 / 90) * (-120 - strength)); + // int red = Math.abs((256 / 90) * (-120 - strength)); + // int result = red << 24 | green + if ((green > 255) || (red > 255)) + System.out.println("Zu groß bei strength= " + strength + ",Rot: " + + red + "Grün: " + green); + if (green > 255) + green = 255; + if (red > 255) + red = 255; + // return ("7f00" + Integer.toHexString(red) + + // Integer.toHexString(green)); + // return ("ff00" + Integer.toHexString(red) + + // Integer.toHexString(green)); + // return ("ff00" + Integer.toHexString(red) + + // Integer.toHexString(green)); + + Color result = new Color(red, green, 0, 100); + + // return ("ff00" + Integer.toHexString(green) + + // Integer.toHexString(red)); + return result; + + } + +} + +class closeWindow implements WindowListener { + + @Override + public void windowActivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosed(WindowEvent e) { + // TODO Auto-generated method stub + ((JFrame) e.getSource()).dispose(); + } + + @Override + public void windowClosing(WindowEvent e) { + // TODO Auto-generated method stub + ((JFrame) e.getSource()).dispose(); + System.exit(0); + + } + + @Override + public void windowDeactivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowDeiconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowIconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowOpened(WindowEvent e) { + // TODO Auto-generated method stub + + } + +} -- cgit v1.2.3-55-g7522