📄 apviewer.java
字号:
package org.placelab.demo.apviewer;import java.io.IOException;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.TableColumn;import org.placelab.client.Placelab;import org.placelab.client.PlacelabWithProxy;import org.placelab.client.tracker.CentroidTracker;import org.placelab.client.tracker.Estimate;import org.placelab.client.tracker.EstimateListener;import org.placelab.client.tracker.Tracker;import org.placelab.client.tracker.TwoDPositionEstimate;import org.placelab.core.BeaconMeasurement;import org.placelab.core.Measurement;import org.placelab.core.TwoDCoordinate;import org.placelab.mapper.CompoundMapper;import org.placelab.mapper.Mapper;import org.placelab.spotter.LogSpotter;import org.placelab.spotter.WiFiSpotter;import org.placelab.util.Cmdline;/** * A sample graphical application that displays the currently viewable access points and an estimate of position */public class APViewer implements Runnable, EstimateListener{ private Shell shell; private Display display; private PlacelabWithProxy daemon; private Label text; //private Table data; private BeaconTableController data; private TableColumn cols[]; private Tracker tracker; private Mapper mapper; public static final int TIMER_INTERVAL_MILLIS=1000; public Measurement lastMeas = null; private Tracker createTracker() { mapper = CompoundMapper.createDefaultMapper(true, true); tracker = new CentroidTracker(mapper); return tracker; } /** * If this program is passed a file name it will be used as a log to be passed to a log spotter. If not a live WiFi spotter will be created. */ public static void main (String [] args) { try { int flag=SWT.SHELL_TRIM; if (System.getProperty("os.name").equalsIgnoreCase("Windows CE")) { flag=SWT.NO_TRIM; } Display display = new Display (); Cmdline.parse(args); APViewer accessPointViewer = new APViewer(display, new Shell(display, flag), (((args.length > 0) && (args[0].length() > 1)) ? args[0] : null)); accessPointViewer.runLoop(); } catch (Exception e) { System.err.println("Couldn't start the placelab daemon:\n"+ e.getClass().getName()+":\n"+e.getMessage()); e.printStackTrace(); } System.exit(0); } public APViewer(Display theDisplay, Shell shell, String logfile) throws IOException { createTracker(); if (logfile == null) { daemon=new PlacelabWithProxy(new WiFiSpotter(), tracker, mapper,-1); } else { daemon=new PlacelabWithProxy(LogSpotter.newSpotter(logfile),tracker,mapper,-1); } daemon.createProxy(); init(theDisplay,shell); } public APViewer(Display theDisplay, Shell shell, PlacelabWithProxy daemon) throws IOException { this.daemon = daemon; tracker = daemon.getTracker(); mapper = daemon.getMapper(); init(theDisplay,shell); } public APViewer(Display theDisplay, Shell shell, Placelab daemon) throws IOException { this.daemon = null; tracker = daemon.getTracker(); mapper = daemon.getMapper(); init(theDisplay,shell); } protected void init(Display theDisplay, Shell shell) { this.shell = shell; shell.setText("PlaceLab"); GridLayout layout = new GridLayout(); GridData gridData = null; layout.numColumns = 1; layout.marginWidth = layout.marginHeight = 0; shell.setLayout(layout); display=theDisplay; setShellSize(shell, theDisplay); int fontdec = 0; if (shell.getSize().x < 350) { fontdec = 2; } text = new Label(shell,0); Font f = new Font(shell.getDisplay(),shell.getFont().getFontData()[0].getName(),10-fontdec, shell.getFont().getFontData()[0].getStyle()); Font f2 = new Font(shell.getDisplay(),shell.getFont().getFontData()[0].getName(),9-fontdec, shell.getFont().getFontData()[0].getStyle()); text.setFont(f); text.setText("Estimated Latitude: ???\nEstimated Longitude: ???"); //text.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); text.setVisible(true); gridData = new GridData(GridData.FILL_HORIZONTAL); text.setLayoutData(gridData); data = new APViewerTableController("All", f2, f, shell, mapper, 10000); gridData = new GridData(GridData.FILL_BOTH); gridData.grabExcessVerticalSpace = true; gridData.grabExcessHorizontalSpace = true; data.body.setLayoutData(gridData); shell.layout(); /*data = new Table(this,0); cols = new TableColumn[5]; cols[0] = new TableColumn(data,0); cols[0].setText("Type"); cols[1] = new TableColumn(data,0); cols[1].setText("MAC Address"); cols[2] = new TableColumn(data,0); cols[2].setText("SSID"); cols[3] = new TableColumn(data,0); cols[3].setText("RSSI"); cols[4] = new TableColumn(data,0); cols[4].setText("Known?"); int w = this.getClientArea().width-2*gap; cols[0].setWidth(2*w/16+4); cols[1].setWidth(5*w/16); cols[2].setWidth(2*w/8-4); cols[3].setWidth(3*w/16); cols[4].setWidth(3*w/16+4); data.setBounds(gap,th+gap+2,w,this.getClientArea().height-3*gap-th); data.setVisible(true); data.setHeaderVisible(true); data.setFont(f2);*/ shell.open(); display.timerExec(TIMER_INTERVAL_MILLIS,this); } public void runLoop() { while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) { display.sleep (); } } if (daemon != null) { daemon.shutdown(); } display.dispose(); } public void setShellSize(Shell s, Display d) { Rectangle screen= shell.getDisplay().getClientArea(); int w=screen.width; int h=screen.height; if (w>450) { w=450; } if (h>550) { h=550; } s.setSize(w,h); } public void updated(BeaconMeasurement meas) { TwoDPositionEstimate estimate = (TwoDPositionEstimate) tracker.getEstimate(); TwoDCoordinate pos = (TwoDCoordinate)estimate.getCoord(); if (text.isDisposed()) return; text.setText("Estimated Latitude: " + pos.getLatitudeAsString() + "\nEstimated Longitude: " + pos.getLongitudeAsString()); // update the table if (meas == null) return; data.addMeasurement(meas, null); } public void estimateUpdated(Tracker t, Estimate e, Measurement m) { lastMeas = m; } public void run() { try { if (daemon == null) { if (lastMeas != null) { BeaconMeasurement bm = (BeaconMeasurement)lastMeas; lastMeas = null; updated(bm); } } else { Measurement meas = daemon.pulse(); if (meas != null) { updated((BeaconMeasurement)meas); } } } catch (Throwable t) { t.printStackTrace(); } finally { // schedule the timer display.timerExec(TIMER_INTERVAL_MILLIS, this); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -