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

📄 mapdemo.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				public void widgetDefaultSelected(SelectionEvent e) {					shutdown();				}			});		}		fileItem.setMenu(fileMenu);				// cut out early and don't have View, Hashtable or Place menus if there isn't anything		// loaded yet		if(data == null || mapView == null || mapView.getMapData() == null) return;				// build view menu		MenuItem viewItem = new MenuItem(bar, SWT.CASCADE);		viewItem.setText("View");		viewItem.setAccelerator(commandKey | 'V');		Menu viewMenu = new Menu(bar);		//		MenuItem beaconShowItem = new MenuItem(viewMenu, SWT.CHECK);		beaconShowItem.setText("Show Beacons");		beaconShowItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				toggleBeacons();			}			public void widgetDefaultSelected(SelectionEvent e) {				toggleBeacons();			}		});		beaconShowItem.setSelection(mapView.getShowBeacons());		//		MenuItem particlesShowItem = new MenuItem(viewMenu, SWT.CHECK);		particlesShowItem.setText("Show Particles");		particlesShowItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				toggleParticles();			}			public void widgetDefaultSelected(SelectionEvent e) {				toggleParticles();			}		});		particlesShowItem.setSelection(mapView.getShowParticles());		//				MenuItem autoScrollItem = new MenuItem(viewMenu, SWT.CHECK);		autoScrollItem.setText("Auto Scroll Map " + mapView.getAutoScroll());		autoScrollItem.setSelection(mapView.getAutoScroll());		autoScrollItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				toggleAutoScroll();			}			public void widgetDefaultSelected(SelectionEvent e) {				toggleAutoScroll();			}		});				//		MenuItem autoZoomItem = new MenuItem(viewMenu, SWT.CHECK);		autoZoomItem.setText("Auto Zoom Map");		autoZoomItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				toggleAutoZoom();			}			public void widgetDefaultSelected(SelectionEvent e) {				toggleAutoZoom();			}		});		autoZoomItem.setSelection(mapView.getAutoZoom());		//		MenuItem zoomInItem = new MenuItem(viewMenu, SWT.PUSH);		zoomInItem.setText("Zoom In");		zoomInItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				mapView.zoomIn();			}			public void widgetDefaultSelected(SelectionEvent e) {				mapView.zoomIn();			}		});		//		MenuItem zoomOutItem = new MenuItem(viewMenu, SWT.PUSH);		zoomOutItem.setText("Zoom Out");		zoomOutItem.addSelectionListener(new SelectionListener() {			public void widgetSelected(SelectionEvent e) {				mapView.zoomOut();			}			public void widgetDefaultSelected(SelectionEvent e) {				mapView.zoomOut();			}		});		viewItem.setMenu(viewMenu);				// build map menu		MenuItem mapItem = new MenuItem(bar, SWT.CASCADE);		mapItem.setText("Maps");		Menu mapMenu = new Menu(bar);		Enumeration e = data.getMaps().keys();		String selected = mapView.getMapData().getName();		MenuItem select = null;		while(e.hasMoreElements()) {			String name = (String) e.nextElement();			MenuItem item = new MenuItem(mapMenu, SWT.RADIO);			if(select == null && name.equals(selected)) {				select = item;				item.setSelection(true);			}			item.setText(name);			item.addSelectionListener(new SelectionListener() {				public void widgetSelected(SelectionEvent e) {					mapAction(e);				}				public void widgetDefaultSelected(SelectionEvent e) {					mapAction(e);				}			});		}		if(select != null) mapMenu.setDefaultItem(select);		MenuItem placeItem = new MenuItem(bar, SWT.CASCADE);		placeItem.setText("Places");		Menu placeMenu = new Menu(bar);		placeItems = new Vector();		Hashtable defaultPlaceSets = data.getDefaultPlaceSets();		e = data.getPlaceSetNames();		while(e.hasMoreElements()) {			String name = (String)e.nextElement();			MenuItem item = new MenuItem(placeMenu, SWT.CHECK);			if(defaultPlaceSets != null && defaultPlaceSets.containsKey(name)) item.setSelection(true);			item.setText(name);			item.addSelectionListener(new SelectionListener() {				public void widgetSelected(SelectionEvent e) {					placeAction(e);				}				public void widgetDefaultSelected(SelectionEvent e) {					placeAction(e);				}			});			placeItems.add(item);		}		mapItem.setMenu(mapMenu);		placeItem.setMenu(placeMenu);	}	protected void mapAction(SelectionEvent e) {		MenuItem item = (MenuItem)e.getSource();		String mapName = item.getText();		MapBacking map = data.getMap(mapName);		if(mapName != null) {			shell.setText(mapName);			mapView.setMapData(map);		}	}	protected void saveWad() {		if(data != null) {			try {				data.saveWad();			} catch (Exception e) {				this.errorDialog("Save failed", e);			}		}	}	protected void saveAsWad() {		if(data != null) {			FileDialog fd = new FileDialog(shell, SWT.SAVE);			String path = fd.open();			try {				data.saveWad(new FileOutputStream(path));			} catch (Exception e) {				this.errorDialog("Save failed", e);			}		}	}	protected void placeAction(SelectionEvent e) {		// XXX: This is lame		Hashtable selectedPlaces = new Hashtable();		Enumeration i = placeItems.elements();		while(i.hasMoreElements()) {			MenuItem mi = (MenuItem)i.nextElement();			if(mi.getSelection()) {				Hashtable placeSet = data.getPlaceSet(mi.getText());				selectedPlaces.put(mi.getText(), placeSet);			}		}		mapView.setPlaceSets(selectedPlaces);	}		protected void toggleBeacons() {		mapView.setShowBeacons(!mapView.getShowBeacons());	}	protected void toggleAutoScroll() {		mapView.setAutoScroll(!mapView.getAutoScroll());		buildMenu();	}	protected void toggleAutoZoom() {		mapView.setAutoZoom(!mapView.getAutoZoom());		buildMenu();	}	protected void toggleParticles() {		mapView.setShowParticles(!mapView.getShowParticles());	}		protected void shutdown() {		// XXX: Should do cleanup here		System.exit(0);	}		protected void resize() {		Rectangle r = display.getClientArea();		r.height = (int)(0.95 * r.height);		/*System.out.println("bounds: ("+r.x+","+r.y+"):"+r.width+"x"+		  r.height);*/		Point mapSize = mapView.getMapSize();		Rectangle trim = mapView.computeTrim(0, 0, mapSize.x, mapSize.y);		trim = shell.computeTrim(0, 0, trim.width, trim.height);/*		System.out.println("image: "+mapSize.x+				   "x"+mapSize.y);		System.out.println("trim: ("+trim.x+","+trim.y+"):"+trim.width+				   "x"+trim.height);*/		if (trim.width  < r.width ) r.width  = trim.width;		if (trim.height < r.height) r.height = trim.height;		shell.setBounds(r);	}	public void run() throws SpotterException {		doEventLoop();	}		protected void doEventLoop() {		try {			if(sp != null) sp.open();			SWTEventSystem evs = new SWTEventSystem(this.display, this.shell);			if(sp != null) sp.startScanning(evs);			evs.run();		} catch (SpotterException se) {			// still allow the maps to be viewed if it fails to open			se.printStackTrace();			System.err.println("Spotter Open failed, but allowing viewing of maps anway ...");			SWTEventSystem evs = new SWTEventSystem(this.display, this.shell);			evs.run();		}	}	public PlacelabWithProxy getDaemon() {		return daemon;	}	/**	 * Passing in a file will cause a log spotter to be created. If no file name is passed, a wifi spotter will be created	 */	public static void main (String [] args) {		Cmdline.parse(args);		String inputLog = Cmdline.getArg("log");		//System.out.println(inputLog);		String mapArchive = Cmdline.getArg("maps");		String mapName = Cmdline.getArg("mapname");		if (Cmdline.getArg("demo") != null) {		 	inputLog = "seattle.log";		 	mapArchive = "seattlemaps.zip";		 	mapName = "University District";					}		if (Cmdline.getArg("demolive") != null) {		 	inputLog = null;		 	mapArchive = "seattlemaps.zip";		 	mapName = "University District";					}		//if(mapArchive == null) {		//	System.err.println("Usage: java XMapDemo --maps <map archive> --mapname <map name> [--log <logfile>]");		//	System.exit(1);		//}		try {			MapDemo hello = new MapDemo(inputLog, mapArchive, mapName, null);			hello.run();		} catch (Exception e) {			System.err.println("Error:\n"+					e.getClass().getName()+":\n"+e.getMessage());			e.printStackTrace();		}	}}

⌨️ 快捷键说明

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