⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.placelab.stumbler.smallgui;import java.io.File;import java.io.IOException;import java.util.Enumeration;import java.util.Hashtable;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.layout.RowLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.MenuItem;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.TableItem;import org.placelab.core.GPSMeasurement;import org.placelab.spotter.BluetoothSpotter;import org.placelab.spotter.NMEAGPSSpotter;import org.placelab.spotter.WiFiSpotter;import org.placelab.stumbler.SpotterExtension;public class View extends Composite {		public static Display display;	public static Shell shell;		private static int PLATFORM;	private static int PLATFORM_PPC = 1;	private static int PLATFORM_OTHER = 2;		static {		display = new Display();				// get platform		if (System.getProperty("os.name").equalsIgnoreCase("Windows CE")) {			PLATFORM = PLATFORM_PPC;			//System.out.println("PocketPC Platform");		} else { 			//System.out.println("Non-PocketPC Platform = " + System.getProperty("os.name"));			PLATFORM = PLATFORM_OTHER;		}		if (PLATFORM == PLATFORM_PPC) {			shell = new Shell(display, SWT.NO_TRIM | SWT.RESIZE);			shell.setLocation(0,26);						// take up the whole screen.			Rectangle screen = display.getClientArea();			shell.setSize(screen.width, screen.height);		} else {			shell = new Shell(display, SWT.SHELL_TRIM);		}		{			RowLayout rl = new RowLayout(SWT.VERTICAL);			rl.marginTop = 0;			rl.marginLeft = 0;			rl.marginRight = 0;			rl.marginBottom = 0;			shell.setLayout(rl);		}				shell.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));		shell.setText("PlaceLab Stumbler");		Display.setAppName("Stumbler");			}		private Composite beaconTable;	private Composite status;	private Menu menuBar;	public View () {		super(shell, SWT.NONE);						GridLayout l = new GridLayout();		l.numColumns = 1;		l.marginHeight = 0;		l.marginWidth = 0;		setLayout(l);								beaconTable = new BeaconTable(this);		beaconTable.setVisible(true);								status = new Status(this);		status.setVisible(true);				loadMenus();				shell.open();	}		private void loadMenus () {				menuBar = new Menu(shell, SWT.BAR);		shell.setMenuBar(menuBar);				// FILE		{			MenuItem item = new MenuItem(menuBar, SWT.CASCADE);			item.setText("File");						Menu sub = new Menu(shell, SWT.DROP_DOWN);			item.setMenu(sub);						MenuItem newLog = new MenuItem(sub, SWT.PUSH);			newLog.setText("New");			newLog.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					try {					Stumbler.getStumbler().newLog();					} catch (IOException ioe) {						reportError(ioe.toString());					}				}			});						MenuItem open = new MenuItem(sub, SWT.PUSH);			open.setText("Open...");			open.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					FileDialog fd = new FileDialog(View.shell, SWT.OPEN);					fd.setFilterExtensions(new String[]{".log"});					String file = fd.open();					if (file != null) {						try {							Stumbler.getStumbler().openLog(file);						} catch (IOException ioe) {							reportError(ioe.toString());						}					}				}			});						MenuItem save = new MenuItem(sub, SWT.PUSH);			save.setText("Save");			save.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					FileDialog fd = new FileDialog(View.shell, SWT.SAVE);					fd.setFilterExtensions(new String[]{".log"});					String file = fd.open();					if (file != null) {						try {							Stumbler.getStumbler().saveLog(file);						} catch (IOException ioe) {							reportError(ioe.toString());						}					}				}			});						MenuItem saveAs = new MenuItem(sub, SWT.PUSH);			saveAs.setText("Save As...");			saveAs.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					FileDialog fd = new FileDialog(View.shell, SWT.SAVE);					fd.setFilterExtensions(new String[]{".log"});					String file = fd.open();					if (file != null) {						try {							Stumbler.getStumbler().saveLogAs(file);						} catch (IOException ioe) {							reportError(ioe.toString());						}					}				}			});						MenuItem upload = new MenuItem(sub, SWT.PUSH);			upload.setText("Upload...");			upload.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					MessageBox mb = new MessageBox(View.shell, SWT.ICON_INFORMATION | SWT.OK );					mb.setMessage("Not yet implemented.");					mb.open();				}			});						new MenuItem(sub, SWT.SEPARATOR);						MenuItem enable = new MenuItem(sub, SWT.CHECK);			enable.setText("Stumble");			enable.setSelection(Stumbler.getStumbler().isStumbling() ? true : false);			enable.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					if (((MenuItem) e.widget).getSelection()) {												Stumbler.getStumbler().startStumbling();					} else {						Stumbler.getStumbler().stopStumbling();					}				}			});						new MenuItem(sub, SWT.SEPARATOR);						MenuItem quit = new MenuItem(sub, SWT.CHECK);			quit.setText("Quit");			quit.addListener(SWT.Selection, new Listener(){				public void handleEvent(Event e) {					Stumbler.getStumbler().stopStumbling();					View.display.dispose();					System.exit(1);				}			});								}				// SPOTTER		{			MenuItem item = new MenuItem(menuBar, SWT.CASCADE);			item.setText("Devices");						Menu sub = new Menu(shell, SWT.DROP_DOWN);			item.setMenu(sub);						for (Enumeration e = Stumbler.getStumbler().getReceivers(); e.hasMoreElements(); ) {				Receiver r = (Receiver) e.nextElement();				//System.out.println("r: " + r.getType());								// don't show GPS on this menu.				if (r instanceof GPSReceiver) 					continue;								MenuItem mi = new MenuItem(sub, SWT.CHECK);				mi.setText(r.getType());				mi.setSelection(false);								Class[] supSpotter = r.getSupportedSpotters();								for (int i = 0;i<supSpotter.length;i++) {					SpotterExtension s = (SpotterExtension) Stumbler.getStumbler().getSpotter(supSpotter[i]);					if (s == null)						continue;										if (s.isScanning()) {						mi.setSelection(true);						break;					}				}								mi.addListener(SWT.Selection, new Listener(){					public void handleEvent (Event e) {						MenuItem mi = (MenuItem) e.widget;						for (Enumeration re = Stumbler.getStumbler().getReceivers(); re.hasMoreElements(); ) {							Receiver r = (Receiver) re.nextElement();														if (!r.getType().equals(mi.getText()))								continue;														Class[] supSpotter = r.getSupportedSpotters();														for (int i = 0;i<supSpotter.length;i++) {								SpotterExtension s = (SpotterExtension) Stumbler.getStumbler().getSpotter(supSpotter[i]);								if (s == null)									continue;																if (mi.getSelection()) {									s.startScanning();								} else {									s.stopScanning();								}							}						}											}				});											}					}						/**		 * This code will eventually provide a quick on/off toggle button

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -