summaryrefslogtreecommitdiffstats
path: root/gui/ShowMapStrength.java
blob: a74e064450cf73d99bfbf4bb53933697149d5b8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
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<JXMapViewer> {
	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

	}

}