📄 placelabstumblergui.java
字号:
package org.placelab.stumbler.gui;import gnu.io.CommPortIdentifier;import java.io.File;import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.dialogs.ProgressMonitorDialog;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.SashForm;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.graphics.Color;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.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.swt.widgets.Group;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.MenuItem;import org.eclipse.swt.widgets.Scale;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.TabFolder;import org.eclipse.swt.widgets.TabItem;import org.placelab.client.tracker.CentroidTracker;import org.placelab.client.tracker.CompoundTracker;import org.placelab.client.tracker.Estimate;import org.placelab.client.tracker.EstimateListener;import org.placelab.client.tracker.FilteredEstimateListener;import org.placelab.client.tracker.PositionTracker;import org.placelab.client.tracker.Tracker;import org.placelab.core.BeaconMeasurement;import org.placelab.core.GPSMeasurement;import org.placelab.core.Measurement;import org.placelab.core.PlacelabProperties;import org.placelab.core.TwoDCoordinate;import org.placelab.demo.apviewer.BeaconTableController;import org.placelab.demo.mapview.BrowserControl;import org.placelab.demo.mapview.MapBacking;import org.placelab.demo.mapview.MapView;import org.placelab.demo.mapview.TrackedMapView;import org.placelab.demo.mapview.WadData;import org.placelab.mapper.CompoundMapper;import org.placelab.mapper.Mapper;import org.placelab.spotter.BluetoothGPSSpotter;import org.placelab.spotter.BluetoothSpotter;import org.placelab.spotter.ListenerBluetoothGPSSpotter;import org.placelab.spotter.NMEAGPSSpotter;import org.placelab.spotter.RemoteGSMSpotter;import org.placelab.spotter.SerialGPSSpotter;import org.placelab.spotter.SpotterException;import org.placelab.spotter.WiFiSpotter;import org.placelab.stumbler.AudioNotifier;import org.placelab.stumbler.LogWriter;import org.placelab.stumbler.SpotterExtension;import org.placelab.stumbler.StumblerFunnel;import org.placelab.stumbler.StumblerFunnelUpdateListener;import org.placelab.util.Cmdline;import org.placelab.util.Logger;import org.placelab.util.NumUtil;import org.placelab.util.swt.PhantomView;import org.placelab.util.swt.QuestionBox;/** * The gui for the PlacelabStumbler application. This gui is only intended for * laptops or other devices with a standard sized display and a full swt and jface * implementation. The pocket pc will have to use the text based version or a scaled * down ui. * */public class PlacelabStumblerGUI implements StumblerFunnelUpdateListener, EstimateListener{ protected CompoundTracker tracker; protected Tracker placelabThinks; protected PositionTracker gpsThinks; protected Display display; protected Shell shell; protected PhantomView phantom; protected Composite phantomHolder; protected TrackedMapView mapView1, mapView2; protected WadData wad1, wad2; protected Vector placeItems; protected Menu bar; protected TabFolder mainTabFolder; protected TabItem item1, item2; protected Composite mainComposite, item1Comp, item2Comp; protected Scale tmvZoomScale; protected Group tmvGroup, mapHolderGroup; protected Label tmvLabel, tmvBigLabel; protected Label plEstimateText, gpsEstimateText; protected SashForm sash; protected WiFiTableController wifiTableController; protected BluetoothTableController bluetoothTableController; protected GSMTableController gsmTableController; protected Hashtable beaconIcons; protected Hashtable lastActiveBeaconIcons; protected int tableCount; protected StumblerFunnel funnel; protected NMEAGPSSpotter gps; protected WiFiSpotter wifi; protected BluetoothSpotter bluetooth; protected RemoteGSMSpotter gsm; protected SpotterExtension gpsExtension, wifiExtension, bluetoothExtension, gsmExtension; protected LogWriter logWriter; protected Vector eventQueue; protected Hashtable latestMeasurements; protected GPSMeasurement latestGPSMeasurement; protected Button tmvBtnPosition, tmvBtnTrack, tmvBtnBigMap, tmvBtnScroll; protected int gap; protected boolean boolStumbleOnOff, boolAutoScroll; protected String lastSavePath = null; protected Mapper mapper; protected static String sp = "\t"; public PlacelabStumblerGUI(String mapArchive, String mapName, Mapper m) throws IOException { if(m == null) m = CompoundMapper.createDefaultMapper(true, true); mapper = m; lastActiveBeaconIcons = new Hashtable(); beaconIcons = new Hashtable(); latestMeasurements = new Hashtable(); beginStumbling(); if(wifi == null && bluetooth == null && gps == null) { System.err.println("I was unable to get a WiFiSpotter nor a BluetoothSpotter nor an NMEAGPSSpotter."); System.err.println("If you have any of that hardware, you need to set up your classpath and native libraries" + " appropriately"); System.err.println("If you don't have any of that hardware, this program can't work for you."); System.exit(1); } tracker = new CompoundTracker(); //placelabThinks = new BeaconAndGPSParticleFilterTracker(m); placelabThinks = new CentroidTracker(m); placelabThinks.addEstimateListener(new FilteredEstimateListener(this, 200, FilteredEstimateListener.FILTER_BY_TIME)); tracker.addTracker(placelabThinks); if(gps != null) { gpsThinks = new PositionTracker(); gpsThinks.addEstimateListener(this); tracker.addTracker(gpsThinks); } boolStumbleOnOff = true; buildShell(); shell.open(); } public static void main(String args[]) { Cmdline.parse(args); try { PlacelabStumblerGUI gui = new PlacelabStumblerGUI(null, null, null); gui.run(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } protected void buildShell() { /** TODO: The GUI in Windows is rather bland; it looks better with the WinXP look and feel but * this seems to be something that you set with a manifest for all of Eclipse. I need to find out * how to make the manifest application-specific. --tabert */ int flag = SWT.SHELL_TRIM; Display.setAppName("PlacelabStumbler"); display = Display.getCurrent(); if(display == null) display = new Display(); shell = new Shell(display, flag); shell.setText("Place Lab Stumbler"); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginWidth = layout.marginHeight = 0; shell.setLayout(layout); // create the main tab folder mainTabFolder = new TabFolder(shell,SWT.NONE); mainTabFolder.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { buildMenu(); } public void widgetDefaultSelected(SelectionEvent e) { } }); GridData gridData = new GridData(GridData.FILL_BOTH); mainTabFolder.setLayoutData(gridData); // create the tabs and their composite containers item1 = new TabItem(mainTabFolder, SWT.NONE); item1.setText("Stumbler"); item2 = new TabItem(mainTabFolder,SWT.NONE); item2.setText("Map"); item1Comp = new Composite(mainTabFolder, SWT.NONE); item2Comp = new Composite(mainTabFolder, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; item1Comp.setLayout(gridLayout); //set the size of the shell setShellSize(shell,display); int fontdec = 0; if (shell.getSize().x < 350) { fontdec = 2; } /* * STUMBLER TAB GUI SETUP */ Font f = new Font(getDisplay(),shell.getFont().getFontData()[0].getName(),10-fontdec, shell.getFont().getFontData()[0].getStyle()); Font f2 = new Font(getDisplay(),shell.getFont().getFontData()[0].getName(),9-fontdec, shell.getFont().getFontData()[0].getStyle()); Font f3 = new Font(getDisplay(),shell.getFont().getFontData()[0].getName(),10-fontdec, SWT.BOLD); plEstimateText = new Label(item1Comp,SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 1; plEstimateText.setLayoutData(gridData); gpsEstimateText = new Label(item1Comp,SWT.NONE); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 1; gpsEstimateText.setLayoutData(gridData); //set the text for the label at the top showing lat/lon plEstimateText.setFont(f); plEstimateText.setText("Place Lab Estimated Latitude: Unknown\tEstimated Longitude: Unknown\tNearby Access Points: Unknown"); gpsEstimateText.setFont(f); gpsEstimateText.setText("GPS Estimated Latitude: Unknown\tEstimated Longitude: Unknown"); int th = plEstimateText.getBounds().height; Label seperatorLabel = new Label(item1Comp, SWT.SEPARATOR | SWT.HORIZONTAL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.heightHint = 2; seperatorLabel.setLayoutData(gridData); // apparently vertical means horizontal in the world of SashForms sash = new SashForm(item1Comp, SWT.VERTICAL); sash.setLayout(layout); gridData = new GridData(GridData.FILL_BOTH); gridData.heightHint = item1Comp.getClientArea().height; gridData.widthHint = item1Comp.getClientArea().width; sash.setLayoutData(gridData); tableCount = 0; if(wifi != null) { wifiTableController = new WiFiTableController(f3, f, sash, mapper, SpotterExtension.GPS_STALE_TIME); tableCount++; } if(bluetooth != null) { bluetoothTableController = new BluetoothTableController(f3, f, sash, mapper, 20000); tableCount++; } if(gsm != null) { gsmTableController = new GSMTableController(f3, f, sash, mapper, 20000); tableCount++; } if(tableCount == 0) { System.err.println("don't have wifi, bt, or gsm. Exiting ..."); System.exit(1); } int[] weights = new int[tableCount]; for(int i = 0; i < tableCount; i++) { weights[i] = 100 / tableCount; } sash.setWeights(weights); sash.setVisible(true); // placeholder label for the tmv String loadMessage = "Choose Load MapWad from the File menu to load a map"; tmvBigLabel = new Label(item2Comp,SWT.NONE); tmvBigLabel.setBounds(gap,gap,shell.getClientArea().width-gap*5,shell.getClientArea().height-gap*8); tmvBigLabel.setBackground(new Color(display,242,255,179)); tmvBigLabel.setText(loadMessage); tmvBigLabel.setVisible(true); // set the Composite containers to their respective tabs item1.setControl(item1Comp); item2.setControl(item2Comp); //set the tab folder size mainTabFolder.setBounds(shell.getClientArea()); buildMenu(); // resize display to fit Rectangle r1 = display.getClientArea(); Rectangle r2 = shell.getBounds(); if(r2.height > r1.height) r2.height = r1.height; if(r2.width > r2.width) r2.width = r1.width; shell.setBounds(r2); } protected String askUserForFile() { FileDialog fd = new FileDialog(shell, SWT.OPEN); String path = fd.open(); return path; } protected String askUserForNewFile() { FileDialog fd = new FileDialog(shell, SWT.SAVE); String path = fd.open(); return path; } protected void errorDialog(String msg) { errorDialog(msg, null); } protected void errorDialog(String msg, Throwable e) { MessageDialog d = new MessageDialog(shell, e == null ? "Error" : msg, null, e == null ? msg : e.toString(), MessageDialog.ERROR, new String[]{"OK"}, 0); d.open(); } public Display getDisplay() { return display; } public void checkZoomLevel() { int selection = tmvZoomScale.getSelection(); if (selection < 20){ mapView1.setZoom(0.5); }else if(selection < 40){ mapView1.setZoom(0.75); }else if(selection < 80){ mapView1.setZoom(1.0); }else if(selection < 100){ mapView1.setZoom(1.5); }else if(selection < 120){ mapView1.setZoom(2.0); } fixZoomSlider(); } protected void fixZoomSlider() { double zoom = mapView1.getZoom(); if(zoom <= 0.5) { tmvZoomScale.setSelection(20); } else if(zoom <= 0.75) { tmvZoomScale.setSelection(40); } else if(zoom <= 1.0) { tmvZoomScale.setSelection(60); } else if(zoom <= 1.5) { tmvZoomScale.setSelection(80); } else { tmvZoomScale.setSelection(100); } } protected void doMapZoomIn() { // check which map to zoom if(this.mainTabFolder.getSelectionIndex() == 0) { mapView1.zoomIn(); fixZoomSlider(); } else { mapView2.zoomIn(); } } protected void doMapZoomOut() { // check which map to zoom if(this.mainTabFolder.getSelectionIndex() == 0) { mapView1.zoomOut();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -