summaryrefslogtreecommitdiffstats
path: root/DataStructure/PhoneContainer.java
diff options
context:
space:
mode:
Diffstat (limited to 'DataStructure/PhoneContainer.java')
-rw-r--r--DataStructure/PhoneContainer.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/DataStructure/PhoneContainer.java b/DataStructure/PhoneContainer.java
new file mode 100644
index 0000000..efcc24c
--- /dev/null
+++ b/DataStructure/PhoneContainer.java
@@ -0,0 +1,106 @@
+package DataStructure;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.util.ArrayList;
+import java.util.Random;
+
+import org.jdesktop.swingx.JXMapViewer;
+import org.jdesktop.swingx.painter.Painter;
+
+public class PhoneContainer implements Painter<JXMapViewer> {
+
+ private ArrayList<MobilePhone> phones = new ArrayList<MobilePhone>();
+ private ArrayList<ImsiColor> colors = new ArrayList<ImsiColor>();
+
+ public PhoneContainer() {
+
+ }
+
+ /**
+ * Adds the phone to the JXMAP-Painter. Assigns a random Color if phone is
+ * new. Make sure phone is already initialized. That means, locate method is
+ * already called. This container takes MobilEPhone Objects and draws them
+ * all!
+ *
+ * @param phone
+ */
+ public void add(MobilePhone phone) {
+ // look if Phone is already inside
+ int index = findIMSI(phone);
+ if (index > -1) {
+ // phone is there at position index
+ Color intermediate = phones.get(index).color;
+ phone.color = intermediate;
+ phones.set(index, phone);
+ } else {
+
+ Random r = new Random();
+ phone.color = new Color(r.nextInt(256), r.nextInt(256),
+ r.nextInt(256));
+ phones.add(phone);
+ }
+
+ // oder Farbe durch einen Hash auf die IMSI machen...
+
+ }
+
+ private int findIMSI(MobilePhone phone) {
+ for (int i = 0; i < phones.size(); i++) {
+ if (phones.get(i).IMSI == phone.IMSI) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Removes all Phones from Painter list. Colors for each phone (IMSI) is
+ * remembered
+ */
+ public void removeAll() {
+ phones.clear();
+ }
+
+ @Override
+ /**
+ * HACK: Outputs only two phones now! For Journal. Remove test for IMSI afterwards
+ */
+ public void paint(Graphics2D g, JXMapViewer map, int w, int h) {
+ for (MobilePhone phone : phones) {
+ if (phone.IMSI == 262230000000003L
+ || phone.IMSI == 262230000000013L) {
+ // g.setColor(phone.color);
+ g.setColor(getColor(phone));
+
+ phone.paint(g, map, w, h);
+ }
+ }
+ g.dispose();
+
+ }
+
+ private Color getColor(MobilePhone phone) {
+ // search if IMSI already in list
+ for (int i = 0; i < colors.size(); i++) {
+ if (colors.get(i).IMSI == phone.IMSI) {
+ return colors.get(i).c;
+ }
+ }
+ Random r = new Random();
+ Color result = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
+ colors.add(new ImsiColor(phone.IMSI, result));
+ return result;
+ }
+
+}
+
+class ImsiColor {
+ public long IMSI;
+ public Color c;
+
+ public ImsiColor(long IMSI, Color c) {
+ this.IMSI = IMSI;
+ this.c = c;
+ }
+}