📄 uicontroller.java
字号:
/*
* Copyright 2001, 2002, 2003 Sun Microsystems, Inc. All Rights Reserved.
* Except for any files in PNG format (which are marked with the filename
* extension ".png"), GIF format (which are marked with the filename
* extension ".gif"), or JPEG format (which are marked with the filename
* extension ".jpg"), redistribution and use in source and binary forms,
* with or without modification, are permitted provided that the
* following conditions are met:
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* You may compile, use, perform and display the following files with
* original Java Smart Ticket Sample Application code obtained from Sun
* Microsystems, Inc. only:
* - files in PNG format and having the ".png" extension
* - files in GIF format and having the ".gif" extension
* - files in JPEG format and having the ".jpg" extension
* You may not modify or redistribute .png, .gif, or .jpg files in any
* form, in whole or in part, by any means without prior written
* authorization from Sun Microsystems, Inc. and its licensors, if any.
* Neither the name of Sun Microsystems, Inc., the 'Java Smart Ticket
* Sample Application', 'Java', 'Java'-based names, or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
* ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance
* of any nuclear facility.
*/
/*
* $Id: UIController.java 291 2008-10-06 09:03:15Z khanh.lnq $
* $URL: https://jvnmobilegis.googlecode.com/svn/trunk/src/org/javavietnam/gis/client/midp/ui/UIController.java $
* $Author: khanh.lnq $
* $Revision: 291 $
* $Date: 2008-10-06 16:03:15 +0700 (Mon, 06 Oct 2008) $
*
* ====================================================================
*
* Copyright (C) 2006-2007 by JVNGIS
*
* All copyright notices regarding JVNMobileGIS MUST remain
* intact in the Java codes and resource files.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Support can be obtained from project homepage at:
* http://code.google.com/p/jvnmobilegis/
*
* Correspondence and Marketing Questions can be sent to:
* khanh.lnq AT gmail.com
*
* @version: 1.0
* @author: Khanh Le
* @Date Created: 22 Jun 2007
*/
package org.javavietnam.gis.client.midp.ui;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import org.bouncycastle.util.encoders.Base64;
import org.javavietnam.gis.client.midp.JVNMobileGISMIDlet;
import org.javavietnam.gis.client.midp.model.MessageCodes;
import org.javavietnam.gis.client.midp.model.ModelFacade;
import org.javavietnam.gis.client.midp.model.Preferences;
import org.javavietnam.gis.client.midp.util.GpsBt;
import org.javavietnam.gis.shared.midp.ApplicationException;
import org.javavietnam.gis.shared.midp.IndexedResourceBundle;
import org.javavietnam.gis.shared.midp.VietSign;
import org.javavietnam.gis.shared.midp.model.Credentials;
import org.javavietnam.gis.shared.midp.model.LayerInformation;
import org.javavietnam.gis.shared.midp.model.MapFeature;
import org.javavietnam.gis.shared.midp.model.SearchFeatureParameter;
import org.javavietnam.gis.shared.midp.model.WMSRequestParameter;
/**
* @author khanhlnq
*/
public class UIController {
private static final String BASE_NAME_UI_RESOURCES = "UIResources2";
private static final String BASE_NAME_MESSAGE_RESOURCES = "MessageResources";
public static class EventIds {
public static final byte EVENT_ID_GETMAPWMS = 1;
public static final byte EVENT_ID_GETCAPABILITIESWMS = 2;
public static final byte EVENT_ID_UPDATEMAPWMS = 3;
// public static final byte EVENT_ID_FINDPATHWMS = 4;
// public static final byte EVENT_ID_VIEWPATHWMS = 5;
public static final byte EVENT_ID_GETFEATUREINFO = 6;
public static final byte EVENT_ID_SEARCHFEATURE = 7;
public static final byte EVENT_ID_VIEWFEATURE = 8;
public static final byte EVENT_ID_CHECKUPDATE = 9;
public static final byte EVENT_ID_SAVEMAPTOFILE = 10;
public static final byte EVENT_ID_SAVETOFILE = 11;
public static final byte EVENT_ID_SHOWDIR = 12;
public static final byte EVENT_ID_CHECKEXISTING = 13;
public static final byte EVENT_ID_GPSSEARCHING = 14;
public static final byte EVENT_ID_GPSREADING = 15;
}
private static final String[] iconPaths = { "/icons/JVNMobileGIS_icon.png",
"/icons/map_server_icon.png", "/icons/preferences_icon.png",
"/icons/check_update_icon.png", "/icons/flags/en.png",
"/icons/flags/vn.png", "/icons/flags/nl.png",
"/icons/error_alert_icon.png", "/icons/info_alert_icon.png",
"/icons/dir.png", "/icons/file.png" };
private final MIDlet midlet;
/**
* @uml.property name="display"
*/
private final Display display;
private IndexedResourceBundle resourceBundle;
private IndexedResourceBundle messageBundle;
private final ModelFacade model;
public VietSign vietSign;
public MapServersCmd mapServersCmd;
private final Image[] icons = new Image[iconPaths.length];
private FileConnection fileConnection;
private OutputStream out = null;
private Command mainMenuCommand;
private Command exitCommand;
private Command aboutCommand;
// private Alert alert;
private MainMenuUI mainMenuUI;
private PreferencesUI preferencesUI;
private MapServerUI mapServerUI;
private MapViewUI mapViewUI;
// private FindPathUI findPathUI;
private LBSMainUI lbsMainUI;
private GpsUI gpsUI;
private SearchFeatureUI searchFeatureUI;
private SearchFeatureResultUI searchFeatureResultUI;
private LayerSelectUI layerSelectUI;
private FeatureInfoUI featureInfoUI;
private HelpUI helpUI;
private LayerListUI layerListUI;
private SortLayerListUI sortLayerListUI;
private ProgressObserverUI progressObserverUI;
private PromptDialog promptDialog;
private ConfirmDialogUI confirmDialogUI;
private FileSystemBrowserUI fileSystemBrowserUI;
private FileSystemCreatorUI fileSystemCreatorUI;
private final Credentials credentials;
private Displayable currentFallBackUI;
// private EventDispatcher currentThread;
public UIController(MIDlet midlet, ModelFacade model) {
this.credentials = new Credentials();
this.midlet = midlet;
this.display = Display.getDisplay(midlet);
this.model = model;
vietSign = new VietSign(midlet);
}
/**
* @return Returns the display.
* @uml.property name="display"
*/
public Display getDisplay() {
return display;
}
public String getString(int uiConstant) {
return resourceBundle.getString(uiConstant);
}
public String getMessage(int messageId) {
return messageBundle.getString(messageId);
}
public MIDlet getMIDlet() {
return midlet;
}
/**
* @return the model
* @uml.property name="model"
*/
public ModelFacade getModel() {
return model;
}
public void init() throws ApplicationException {
deinitialize(true);
resourceBundle = model.getResourceBundle(BASE_NAME_UI_RESOURCES);
messageBundle = model.getResourceBundle(BASE_NAME_MESSAGE_RESOURCES);
createCommands();
// setCommands(mapViewUI);
// setCommands(preferencesUI);
// setCommands(layerListUI);
// setCommands(mapServerUI);
model.setProgressObserver(getProgressObserverUI());
mapServersCmd = new MapServersCmd(this);
for (int i = 0; i < iconPaths.length; i++) {
try {
icons[i] = Image.createImage(iconPaths[i]);
} catch (IOException ioe) {
System.out.println("can not get image " + iconPaths[i]);
}
}
Alert alert = new Alert(
null,
getString(UIConstants.MOBILEGIS_CLIENT)
+ " version "
+ (null == midlet
.getAppProperty(JVNMobileGISMIDlet.PROPERTY_MIDLET_VERSION) ? ""
: midlet
.getAppProperty(JVNMobileGISMIDlet.PROPERTY_MIDLET_VERSION))
+ " \n" + getString(UIConstants.COPYRIGHT),
icons[UIConstants.ICON_IDX_SPLASH], null);
alert.setTimeout(UIConstants.SPLASH_TIMEOUT);
display.setCurrent(alert, getMainMenuUI());
}
public void destroy() {
}
public MainMenuUI getMainMenuUI() {
if (mainMenuUI == null) {
mainMenuUI = new MainMenuUI(this);
}
return mainMenuUI;
}
private Displayable getCurrentFallBackUI() {
if (currentFallBackUI == null) {
currentFallBackUI = getMainMenuUI();
}
return currentFallBackUI;
}
public PreferencesUI getPreferencesUI() {
if (preferencesUI == null) {
preferencesUI = new PreferencesUI(this);
}
return preferencesUI;
}
public MapServerUI getMapServerUI() {
if (mapServerUI == null) {
try {
mapServerUI = new MapServerUI(this, model.getPreferences()
.getWmsServerURL());
} catch (ApplicationException ae) {
ae.printStackTrace();
showErrorAlert(ae, getMainMenuUI());
}
}
return mapServerUI;
}
public MapViewUI getMapViewUI() {
if (mapViewUI == null) {
mapViewUI = new MapViewUI(this, false);
}
return mapViewUI;
}
private LBSMainUI getLBSMainForm() {
if (lbsMainUI == null) {
lbsMainUI = new LBSMainUI(this);
}
return lbsMainUI;
}
private GpsUI getGpsUI() {
if (gpsUI == null) {
gpsUI = new GpsUI(this);
}
return gpsUI;
}
public SearchFeatureUI getSearchFeatureUI() {
if (searchFeatureUI == null) {
searchFeatureUI = new SearchFeatureUI(this);
}
return searchFeatureUI;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -