📄 cityguidemidlet.java
字号:
} catch (LocationException e) { e.printStackTrace(); destroyApp(false); notifyDestroyed(); return; } } else { cityMap.setCategories(selectedCategories); } if (mapCanvas == null) { mapCanvas = new MapCanvas(cityMap); mapCanvas.addCommand(exitCommand); mapCanvas.addCommand(detailsCommand); mapCanvas.addCommand(settingsCommand); mapCanvas.setCommandListener(this); } display.setCurrent(mapCanvas); } /** * Initializes map display and sets listener for location updates * use LocationProvider defaults */ public void showMapCanvas(boolean updateLandmarks) { if (updateLandmarks || (mapCanvas == null)) { Form progressForm = new Form(null); progressForm.append(new StringItem("Generating map...", null)); display.setCurrent(progressForm); Thread mapGeneratorThread = new Thread() { public void run() { generateAndDisplayMap(); } }; mapGeneratorThread.start(); } else { display.setCurrent(mapCanvas); } } /** * Show error screen with last error */ public void showErrorForm(String message) { if (errorAlert == null) { errorAlert = new Alert("Error", message, null, AlertType.ERROR); errorAlert.addCommand(closeCommand); errorAlert.setCommandListener(this); } errorAlert.setString(message); display.setCurrent(errorAlert); } /** * Progress screen while loading landmarks * Especially while creating new landmark store from * text resource file */ public void showProgressScreen(String title, int size) { if (progressGauge == null) { progressGauge = new Gauge(title, false, size, 0); progressGauge.setLayout(Item.LAYOUT_CENTER | Item.LAYOUT_EXPAND | Item.LAYOUT_VCENTER); } progressGauge.setValue(0); if (progressScreen == null) { progressScreen = new Form(null); progressScreen.append(progressGauge); progressScreen.addCommand(exitCommand); ProgressScreen_nextCommand = new Command("Next", Command.SCREEN, 1); progressScreen.setCommandListener(this); } display.setCurrent(progressScreen); } /** * Settings screen let user select categories * of points of interest he/she is interested in. * Only those will be displayed on the map. * Contains choice group of categories */ public void showSettingsScreen(boolean show) { if (settingsScreen == null) { String[] categories = Util.asArray(landmarkStore.getCategories()); Image[] images = new Image[categories.length]; for (int i = 0; i < categories.length; i++) images[i] = imageManager.getImage(categories[i]); Item[] items = new Item[] { new StringItem(null, SETTINGS_TEXT), new ChoiceGroup(CHOICEGRP_TEXT, ChoiceGroup.MULTIPLE, categories, images) }; settingsScreen = new Form("Settings", items); boolean[] flags = new boolean[categories.length]; for (int i = 0; i < flags.length; i++) { flags[i] = true; } ((ChoiceGroup)settingsScreen.get(1)).setSelectedFlags(flags); SettingsScreen_backCommand = new Command("Back", Command.SCREEN, 1); settingsScreen.addCommand(SettingsScreen_backCommand); settingsScreen.setCommandListener(this); } if (show) { display.setCurrent(settingsScreen); } } /** * Details screen contains detailed info about * landmarks. It's used for landmarks which * appear in proximity radius. */ public void showDetailsScreen() { MapLandmark[] mapLandmarks = cityMap.getMapLandmarks(); int numActive = 0; for (int i = 0; i < mapLandmarks.length; ++i) { if (mapLandmarks[i].isActive()) { ++numActive; } } Item[] items = null; if (numActive == 0) { items = new Item[] { new StringItem(null, NOLANDMARK_TEXT) }; } else { int NUMBER_OF_ITEMS = 7; items = new Item[numActive * NUMBER_OF_ITEMS]; Landmark l = null; AddressInfo address = null; int i = 0; for (int j = 0; j < mapLandmarks.length; ++j) { if (mapLandmarks[j].isActive()) { l = (Landmark)mapLandmarks[j].getLandmark(); address = l.getAddressInfo(); items[i] = new StringItem("Name:", l.getName()); items[i + 1] = new StringItem("Description:", l.getDescription()); items[i + 2] = new StringItem("Street:", address.getField(AddressInfo.STREET)); items[i + 3] = new StringItem("Postal Code:", address.getField(AddressInfo.POSTAL_CODE)); items[i + 4] = new StringItem("City:", address.getField(AddressInfo.CITY)); items[i + 5] = new StringItem("Phone No:", address.getField(AddressInfo.PHONE_NUMBER)); items[i + 6] = new StringItem(" ", " "); i += NUMBER_OF_ITEMS; } } } detailsScreen = new Form("Details", items); DetailsScreen_backCommand = new Command("Back", Command.SCREEN, 1); detailsScreen.addCommand(DetailsScreen_backCommand); detailsScreen.setCommandListener(this); display.setCurrent(detailsScreen); } /** * Simple welcome screen */ public void showWelcomeScreen() { if (welcomeScreen == null) { Item[] items = new Item[] { new StringItem(null, WELCOME_TEXT), new ImageItem(null, imageManager.getImage("logo"), Item.LAYOUT_CENTER, "logo"), }; welcomeScreen = new Form("City Guide", items); WelcomeScreen_nextCommand = new Command("Next", Command.SCREEN, 2); welcomeScreen.addCommand(exitCommand); welcomeScreen.addCommand(WelcomeScreen_nextCommand); welcomeScreen.setCommandListener(this); } display.setCurrent(welcomeScreen); } /** is map display on */ public boolean isMapDisplayed() { return (display.getCurrent() == mapCanvas); } /** which categories are selected */ public Vector getSelectedCategories() { return selectedCategories; } /** * Update map display - categories have changed */ public void selectedCategoriesChanged() { selectedCategories = new Vector(); ChoiceGroup cg = (ChoiceGroup)settingsScreen.get(1); for (int i = 0; i < cg.size(); i++) { if (cg.isSelected(i)) { selectedCategories.addElement(cg.getString(i)); } } } /** * Get landmarks of the categories in given extent */ public Vector getLandmarks(String[] categories, double minLat, double minLon, double maxLat, double maxLon) { Vector landmarks = new Vector(); for (int i = 0; i < categories.length; i++) { Enumeration l = null; try { l = landmarkStore.getLandmarks(categories[i], minLat, minLon, maxLat, maxLon); } catch (IOException ioe) { ioe.printStackTrace(); } for (; l.hasMoreElements();) { landmarks.addElement(l.nextElement()); } } return landmarks; } /** * Load all images */ private void loadImages() { try { String name = null; while (!landmarksLoaded) { synchronized (this) { wait(); } } imageManager.loadImagesCache(landmarkStore.getCategories()); imageManager.loadImagesCache(PRELOAD_IMAGES); commandAction(ProgressScreen_nextCommand, null); } catch (Exception ioe) { ioe.printStackTrace(); } } /** * Load landmarks from text resources */ private void loadLandmarks() { final InputStream is = getClass().getResourceAsStream("/waypoints.txt"); try { landmarkStore = LandmarkStore.getInstance(LANDMARKSTORE_NAME); if (null == landmarkStore) { LandmarkStore.createLandmarkStore(LANDMARKSTORE_NAME); landmarkStore = LandmarkStore.getInstance(LANDMARKSTORE_NAME); Util.readLandmarksFromStream(landmarkStore, is, progressGauge); } landmarksLoaded = true; synchronized (this) { notify(); } } catch (Exception ioe) { ioe.printStackTrace(); lastError = "Cannot read landmarks.\n Landmark store wasn't created." + ioe.getMessage(); try { LandmarkStore.deleteLandmarkStore(LANDMARKSTORE_NAME); commandAction(showErrorCommand, null); } catch (Exception e) { //do nothing } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -