📄 placelabstumblergui.java
字号:
qb.setButtons(new String[] { "Don't use GPS", "Use but don't save", "Use and save"}); Hashtable answers = (Hashtable)qb.open(); if(answers == null || qb.getButtonChosen() == 0) { return false; } else { Boolean b = (Boolean)answers.get(q1); if(b != null && b.booleanValue()) { PlacelabProperties.set("placelab.gps_device", "bluetooth"); } else { String port = (String)answers.get(q2); if(port == null) port = (String)answers.get(q3); PlacelabProperties.set("placelab.gps_device", port); } if(qb.getButtonChosen() == 2) PlacelabProperties.synchronize(); return true; } } private String basename(String path) { return path.substring(path.lastIndexOf(File.separatorChar) + 1, path.length()); } protected void doSaveAs() { String path = askUserForNewFile(); if(path == null) return; try { logWriter.setOutputFile(path); } catch (IOException e) { this.errorDialog("Couldn't save trace log", e); } shell.setText("Place Lab Stumbler - " + basename(path)); lastSavePath = path; } protected void doSubmitLog() { if(lastSavePath == null) { doSaveAs(); if(lastSavePath == null) return; } Vector questions = new Vector(); HTTPTransport transport = new HTTPTransport(lastSavePath, null); questions.addElement(new QuestionBox.QuestionPackage("Username", transport.username, 40, false)); questions.addElement(new QuestionBox.QuestionPackage("Password", transport.passwd, 40, true)); questions.addElement(new QuestionBox.QuestionPackage("Trace Description", "Submission from Place lab Stumbler", 400, false)); QuestionBox dialog = new QuestionBox(shell, questions, "Enter your placelab.org account info"); Hashtable results = (Hashtable)dialog.open(); if(results == null || dialog.getButtonChosen() == 0) return; transport.username = (String)results.get("Username"); transport.passwd = (String)results.get("Password"); transport.description = (String)results.get("Trace Description"); try { new ProgressMonitorDialog(shell).run(true, true, transport); } catch(InvocationTargetException e) { errorDialog("Your log was not accepted", e); } catch(InterruptedException e) { // user canceled it. } } public void run() { doEventLoop(); shutdown = true; funnel.shutdown(); System.exit(0); } protected volatile boolean shutdown = false; protected static long lastStumblerUpdate = 0; public void stumblerUpdated(Hashtable measurements) { long now = System.currentTimeMillis(); Logger.println("Time since last stumbler update " + (now - lastStumblerUpdate), Logger.MEDIUM); lastStumblerUpdate = now; //System.out.println("Got measurements: " + measurements); synchronized(eventQueue) { eventQueue.insertElementAt(measurements, eventQueue.size()); } if(display == null) return; synchronized(display) { display.wake(); } } protected static long lastUpdate = 0; protected void doEventLoop() { while(!shell.isDisposed()) { if(!display.readAndDispatch()) { boolean updateTable = false; synchronized(eventQueue) { if(eventQueue.size() > 0) { latestMeasurements = (Hashtable)eventQueue.elementAt(0); eventQueue.removeElementAt(0); // and anything else we want to do here //System.out.println("latest measurements: " + latestMeasurements.values()); if (boolStumbleOnOff){ updateTable = true; } } } if(gps != null && latestMeasurements.containsKey(gps)) { //System.out.println("got gps"); latestGPSMeasurement = (GPSMeasurement)latestMeasurements.get(gps); } updateTrackers(); if(updateTable) { long now = System.currentTimeMillis(); Logger.println("Time since last table update: " + (now - lastUpdate), Logger.HIGH); lastUpdate = now; updateUI(); } display.sleep(); } } } protected void updateTrackers() { if(latestMeasurements == null) return; Enumeration e = latestMeasurements.elements(); while(e.hasMoreElements()) { Measurement m = (Measurement)e.nextElement(); tracker.updateEstimate(m); } } // clever, but not used /*protected void updateFusionTracker() { if(latestMeasurements == null) return; int updateCount = 0; if(wifi != null) { Measurement m = (Measurement)latestMeasurements.get(wifi); if(m != null) placelabThinks.updateEstimate(m); updateCount++; } if(latestGPSMeasurement != null) { placelabThinks.updateEstimate(latestGPSMeasurement); updateCount++; } // TODO: if fusion tracker ever learns to track bt or gsm add that here too if(updateCount == 0) { placelabThinks.updateWithoutMeasurement(System.currentTimeMillis() - lastUpdate); } }*/ public void setShellSize(Shell s, Display d) { Rectangle screen= shell.getDisplay().getClientArea(); int w=screen.width; int h=screen.height; if (w>850) { w=850; } if (h>550) { h=750; } s.setSize(w,h); } /* (non-Javadoc) * @see org.placelab.client.tracker.EstimateListener#estimateUpdated(org.placelab.client.tracker.Tracker, org.placelab.client.tracker.Estimate) */ public void estimateUpdated(Tracker t, Estimate e, Measurement m) { if(t == placelabThinks) { TwoDCoordinate coord = (TwoDCoordinate) e.getCoord(); String lat,lon; lat = NumUtil.doubleToString(coord.getLatitude(),4); lon = NumUtil.doubleToString(coord.getLongitude(),4); //System.out.println("Place Lab thinks: " + lat + " " + lon); plEstimateText.setText("Place Lab Estimated Latitude: " + lat + " Estimated Longitude: " + lon); } // note: the gps estimate is handled in updateGPSText() } protected void updateUI() { if(wifi != null) wifiTableController.addMeasurement((BeaconMeasurement)latestMeasurements.get(wifi), (isGPSStale()) ? null : latestGPSMeasurement); if(bluetooth != null) { BeaconMeasurement btMeas = (BeaconMeasurement)latestMeasurements.get(bluetooth); //if(btMeas != null) System.out.println("Got bt: " + btMeas.toLogString()); bluetoothTableController.addMeasurement((BeaconMeasurement)latestMeasurements.get(bluetooth), (isGPSStale()) ? null : latestGPSMeasurement); }// if(bluetooth != null && (bluetooth instanceof BluetoothGSMSpotter)) {// BeaconMeasurement gsmMeas = (BeaconMeasurement)latestMeasurements.get(bluetooth);// gsmTableController.addMeasurement(gsmMeas, // (isGPSStale()) ? null : latestGPSMeasurement);// } if(gsm != null) { BeaconMeasurement gsmMeas = (BeaconMeasurement)latestMeasurements.get(gsm); gsmTableController.addMeasurement(gsmMeas, (isGPSStale()) ? null : latestGPSMeasurement); } updateGPSText(); //updateBeaconIcons(); updatePositionTracker(); item1Comp.layout(); } protected boolean isGPSStale() { return latestGPSMeasurement == null || (System.currentTimeMillis() - latestGPSMeasurement.getTimestamp()) > SpotterExtension.GPS_STALE_TIME; } protected void updatePositionTracker() { if(gpsThinks == null) return; GPSMeasurement gpsMeas; if(isGPSStale()) { gpsMeas = new GPSMeasurement(0L, TwoDCoordinate.NULL); } else { gpsMeas = latestGPSMeasurement; } gpsThinks.updateEstimate(gpsMeas); } protected void updateBeaconIcons() { // this is kind of a kludge, since the BeaconHistory objects are currently being collated // by the BeaconTableControllers, but thats probably ok. I just need to have a look at them here // XXX: this should be &&, i just have it changed temporarily while i work // on phantoms - fats if(mapView1 == null || mapView2 == null) { // then don't waste time return; } Hashtable temp = new Hashtable(); if(mapView1 != null) { mapView1.getHolder().freeze(); } if(mapView2 != null) { mapView2.getHolder().freeze(); } Enumeration i = wifiTableController.active.keys(); while(i.hasMoreElements()) { String id = (String)i.nextElement(); // if id is in beaconIcons, then poke the icon to reflect the latest data if(beaconIcons.containsKey(id)) { BeaconIcons bi = (BeaconIcons)beaconIcons.get(id); bi.updateAll(true); // remove it from lastActiveBeaconIcons, if it exists, and add it to temp // this indirection prevents me from doing any more computation than I absolutely have to // with regards to glyph drawing temp.put(id, bi); lastActiveBeaconIcons.remove(id); } else { // this is a new ap that doesn't have an icon yet. build it up, one for each // mapview. BeaconHistory bh = (BeaconHistory)wifiTableController.history.get(id); BeaconIcons bi = new BeaconIcons(); // isn't bp1 a great name for a variable? It rolls off the tongue // so nice ... if(mapView1 != null) { BeaconPlace bp1 = new BeaconPlace(mapView1, bh, mapper, true); bi.addBeaconPlace(bp1); } if(mapView2 != null) { BeaconPlace bp2 = new BeaconPlace(mapView2, bh, mapper, true); bi.addBeaconPlace(bp2); } beaconIcons.put(id, bi); temp.put(id, bi); } if(mapView1 != null) mapView1.getHolder().thaw(); if(mapView2 != null) mapView2.getHolder().thaw(); } // now for everthing that was in lastActiveBeaconIcons, go through and set it to // not active because it isn't active anymore Enumeration e = lastActiveBeaconIcons.elements(); while(e.hasMoreElements()) { BeaconIcons bi = (BeaconIcons)e.nextElement(); bi.updateAll(false); } // now the icons in temp are the ones that are active for this round // so lastActiveBeaconIcons to them lastActiveBeaconIcons = temp; } /** * When the map is changed for a mapview, all of the BeaconPlace glyphs * to be updated to move to their proper locations */ protected void updateAllBeaconIcons() { /*Enumeration e = beaconIcons.keys(); while(e.hasMoreElements()) { Object id = e.nextElement(); BeaconIcons bi = (BeaconIcons)beaconIcons.get(id); bi.updateAll(wifiTableController.active.containsKey(id)); }*/ } /** * When a mapview is first loaded, all beacons to date must be plotted on it. * They cannot be made in advance, because swt does not support making a widget * without a parent. */ protected void createBeaconIcons(MapView onView) { onView.getHolder().freeze(); Enumeration i = wifiTableController.history.elements(); while(i.hasMoreElements()) { BeaconHistory bh = (BeaconHistory)i.nextElement(); // check to see if there is already a BeaconIcons package // for this element // note that a BeaconHistory object hashes to the same place as // its bssid string does, so this works BeaconIcons bi = (BeaconIcons)beaconIcons.get(bh); if(bi == null) { bi = new BeaconIcons(); beaconIcons.put(bh, bi); } boolean isActive = wifiTableController.active.containsKey(bh); BeaconPlace bp = new BeaconPlace(onView, bh, mapper, isActive); bi.addBeaconPlace(bp); if(isActive) { lastActiveBeaconIcons.put(bh, bi); } } onView.getHolder().thaw(); } protected void updateGPSText() { String text = null; if(latestGPSMeasurement == null) { text = "GPS not connected"; } else if(isGPSStale()) { text = "No recent GPS Measurements (last one at " + BeaconTableController.humanReadableTime(latestGPSMeasurement.getTimestamp()) + ")"; } else { String latS = "unknown", lonS = "unknown"; if(!latestGPSMeasurement.getPosition().isNull()) { latS = NumUtil.doubleToString( ((TwoDCoordinate)latestGPSMeasurement.getPosition()).getLatitude(), 4); lonS = NumUtil.doubleToString( ((TwoDCoordinate)latestGPSMeasurement.getPosition()).getLongitude(), 4); } text = "GPS Estimated Latitude: " + latS + " Estimated Longitude: " + lonS + " " + (latestGPSMeasurement.isValid() ? "(fix obtained)" : "(fix not obtained)"); } if(gps != null && gps instanceof BluetoothGPSSpotter) { text += " (bluetooth gps state: " + ((BluetoothGPSSpotter)gps).getState() + ")"; } gpsEstimateText.setText(text); } protected void buildMenu() { // building menus by hand is a crime // but alas, this is how its done in swt int commandKey = SWT.CONTROL; if(BrowserControl.isMacPlatform()) commandKey = SWT.COMMAND; bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); // build file menu MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("File"); Menu fileMenu = new Menu(bar); MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH); saveItem.setText("Set log file ..."); saveItem.setAccelerator(commandKey | 'S'); saveItem.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { doSaveAs(); } public void widgetDefaultSelected(SelectionEvent e) { doSaveAs(); } }); // blank space new MenuItem(fileMenu, SWT.SEPARATOR); MenuItem submitItem = new MenuItem(fileMenu, SWT.PUSH); submitItem.setText("Submit log to placelab.org ..."); submitItem.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { doSubmitLog(); } public void widgetDefaultSelected(SelectionEvent e) { doSubmitLog(); } }); // blank space new MenuItem(fileMenu, SWT.SEPARATOR); MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH); openItem.setText("Open Mapwad..."); openItem.setAccelerator(commandKey | 'O'); openItem.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { loadWad(); } public void widgetDefaultSelected(SelectionEvent e) { loadWad(); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -