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

📄 cspeclayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/corba/com/bbn/openmap/layer/specialist/CSpecLayer.java,v $// $RCSfile: CSpecLayer.java,v $// $Revision: 1.6.2.2 $// $Date: 2005/08/09 21:17:53 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.specialist;/*  Java Core  */import java.awt.Component;import java.awt.event.MouseEvent;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import org.omg.CORBA.BooleanHolder;import org.omg.CORBA.ShortHolder;import org.omg.CORBA.StringHolder;import com.bbn.openmap.Environment;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.CSpecialist.CProjection;import com.bbn.openmap.CSpecialist.GraphicChange;import com.bbn.openmap.CSpecialist.LLPoint;import com.bbn.openmap.CSpecialist.Server;import com.bbn.openmap.CSpecialist.ServerHelper;import com.bbn.openmap.CSpecialist.UGraphic;import com.bbn.openmap.CSpecialist.UWidget;import com.bbn.openmap.CSpecialist.GraphicPackage.GraphicType;import com.bbn.openmap.event.InfoDisplayEvent;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * CSpecLayer is a Layer which communicates to CORBA Specialists. * <P> * Properties: * <P> *  * <pre> *  *  # If you have an ior for the server: *  cspeclayermarker.ior= URL to ior *  # If you are using the Naming Service: *  cspeclayermarker.name= SERVER NAME *  # Static Arguments for the server, to be sent on every map request: *  cspeclayermarker.staticArgs= space separated arguments *  # If the network setup allows the server to contact the client (no firewall) *  cspeclayermarker.allowServerUpdates=true/false (false is default) *   * </pre> */public class CSpecLayer extends OMGraphicHandlerLayer implements        MapMouseListener {//    private final static String[] debugTokens = { "debug.cspec" };    /** The property specifying the IOR URL. */    public static final String iorUrlProperty = "ior";    public static final String namingProperty = "name";    /** The property specifying the static arguments. */    public static final String staticArgsProperty = "staticArgs";    /**     * The property to use for specifying whether the GraphicChange     * object should be sent to the server. The server can use the     * GraphicChange object to contact the client to notify it that     * updates are available. This should only be true if the network     * setup allows it to be. Running the client behind a firewall,     * taking with the server through a Gatekeeper, will not allow the     * GraphicChange object to be set. You get a BOA instantiation     * error.     */    public static final String serverUpdateProperty = "allowServerUpdates";    /** IOR URL for the server. */    protected URL iorURL = null;    /** Name of the server. */    protected String naming = null;    /** Arguments passed in from the OverlayTable/properties file. */    protected String staticArgs = null;    /**     * Arguments modified by the Layer, or set by the Bean, at     * runtime. Historical, should use Properties instead.     */    protected String dynamicArgs = null;    protected String clientID = Environment.generateUniqueString();    protected UWidget[] widgets = null;    protected transient CSpecPalette gui = null;    protected transient Server specialist = null;    protected ShortHolder selectDist = new ShortHolder();    protected BooleanHolder wantAreaEvents = new BooleanHolder();    protected GraphicChange notifyOnChange = null;    protected MapGesture mapGesture = new MapGesture();    /**     * Used for the MapMouseListener interface, to track whether to     * listen to mouse events, or not.     */    protected boolean acceptingEvents = false;    /**     * Used to track if a info line was sent, so that a clearing     * message can be sent when it is no longer relevant.     */    protected boolean sentInfoLine = false;    // all the dirty bits    protected int dirtybits = 0;    public final transient static int PALETTE_DIRTY = 0x1;    public final transient static int PREMATURE_FINISH = 0x4;    public final transient static int EXCEPTION = 0x8;    public final transient static int DIRTYMASK = 0xFFFFFFFF;    // new slots    protected boolean showDialogs = Environment.getBoolean("com.bbn.openmap.ShowLayerMessages");    /**     * Default constructor, that sets the MapMouseListener for this     * layer to itself.     */    public CSpecLayer() {        handleGraphicChangeRequests(false);        setProjectionChangePolicy(new com.bbn.openmap.layer.policy.ListResetPCPolicy(this));    }    /**     * Sets whether the notifyOnChange object will actually be set to     * anything. This object can be used to tell the CSpecLayer to go     * to the specialist with a getRectangle. The Layer handles the     * creation of the object if this is set to true. If you are     * working through a firewall, this might not be allowed,     * especially if the client is behind the firewall.     *      * @param setting if the object should be created or not.     */    public void handleGraphicChangeRequests(boolean setting) {        if (setting) {            if (notifyOnChange == null) {                notifyOnChange = new JGraphicChange(this);            }        } else {            notifyOnChange = null;        }    }    /**     *       */    public void finalize() {        if (Debug.debugging("cspec")) {            Debug.output(getName() + "|CSpecLayer.finalize(): calling shutdown");        }        try {            if (specialist != null)                specialist.signoff(clientID);            specialist = null;        } catch (org.omg.CORBA.SystemException e) {            System.err.println(getName() + "|CSpecLayer.finalize(): " + e);        } catch (Throwable t) {            System.err.println(getName() + "|CSpecLayer.finalize(): " + t);        }    }    /**     * Set the properties for the CSpecLayer.     */    public void setProperties(String prefix, java.util.Properties props) {        super.setProperties(prefix, props);        prefix = PropUtils.getScopedPropertyPrefix(prefix);        String url = props.getProperty(prefix + iorUrlProperty);        if (url != null) {            try {                setIorUrl(PropUtils.getResourceOrFileOrURL(null, url));            } catch (MalformedURLException e) {                throw new IllegalArgumentException("\"" + url                        + "\" is malformed.");            }        }        // Get the naming context to get        naming = props.getProperty(prefix + namingProperty);        String staticArgValue = props.getProperty(prefix + staticArgsProperty);        setStaticArgs(staticArgValue);        handleGraphicChangeRequests(PropUtils.booleanFromProperties(props,                prefix + serverUpdateProperty,                notifyOnChange != null));    }    /**     * Gets the argv for the layer from the pseudo-overlay-table.     * Expecting <URL>&rest args.     */    public void setArgs(String argv[]) {        int argc = argv.length;        if (argc == 0) {            // Do nothing.            return;        }        String url = argv[0];        StringBuffer argBuf = new StringBuffer();        if (argc > 1) {            // More arguments, append them into one string and            // pass it off to setArgs.            argBuf.append(argv[1]);            for (int i = 2; i < argc; i++) {                argBuf.append(" ").append(argv[i]);            }        }        //dbg        // Debug.output("----------------------------------------------");        //dbg Debug.output("CSpecLayer " + getName() + ":");        //dbg Debug.output("\tURL: " + url);        //dbg Debug.output("\targs: " + argBuf);        try {            setIorUrl(new URL(url));            if (Debug.debugging("cspec")) {                Debug.output(getName() + "(CSpecLayer) using ior from " + url);            }        } catch (MalformedURLException e) {            throw new IllegalArgumentException("\"" + url + "\""                    + " is not a well formed URL");        }        setStaticArgs(argBuf.toString());    }    /**     * get the specialist proxy.     *      * @return Server specialist server or null if error.     */    public Server getSpecialist() {        if (specialist == null) {            initSpecialist();        }        return specialist;    }    /**     * Bind to the specialist server.     */    private void initSpecialist() {        String ior = null;        org.omg.CORBA.Object object = null;        com.bbn.openmap.util.corba.CORBASupport cs = new com.bbn.openmap.util.corba.CORBASupport();        try {            object = cs.readIOR(iorURL);            specialist = ServerHelper.narrow(object);        } catch (IOException ioe) {            if (Debug.debugging("cspec")) {                Debug.output(getName()                        + "(CSpecLayer).initSpecialist() IO Exception with ior: "                        + iorURL);            }            specialist = null;            return;        }        if (specialist == null) {            object = cs.resolveName(naming);            if (object != null) {                specialist = ServerHelper.narrow(object);                if (Debug.debugging("cspec")) {                    Debug.output("Have a specialist:");                    Debug.output("*** Specialist Server: is a "                            + specialist.getClass().getName() + "\n"                            + specialist);                }            }        }        if (specialist == null) {            if (Debug.debugging("cspec")) {                System.err.println("CSpecLayer.initSpecialist: null specialist!\n  IOR="                        + ior + "\n  Name = " + naming);            }        }    }    /**     * Set the server, if you've taken special steps to create on, or     * want to null out the current one to reset the connection.     */    public void setSpecialist(Server aSpecialist) {        specialist = aSpecialist;        if (specialist == null) {            widgets = null;            gui = null;            setList(null);        }    }    /**     * Interface Layer method to get the dynamic args.     *      * @return String args     */    public String getArgs() {        return dynamicArgs;    }    /**     * Method to set the dynamic args.     *      * @param args String     */    public void setArgs(String args) {        dynamicArgs = args;    }    /**     * Interface Layer method to get the static args, which are     * usually set via the openmap.properties file, or     * setProperties().     */    public String getStaticArgs() {        return staticArgs;    }    /**     * Interface Layer method to set the static args, which are     * usually set via the openmap.properties file.     */    public void setStaticArgs(String args) {        staticArgs = args;    }    public URL getIorUrl() {        return iorURL;    }    public void setIorUrl(URL url) {        iorURL = url;    }    /**     * Perform the getRectangle() call on the specialist.     *      * @param p Projection     * @return UGraphic[] graphic list or null if error     */    protected UGraphic[] getSpecGraphics(Projection p) {        CProjection cproj;        LLPoint ll1, ll2;        StringHolder dynamicArgsHolder;        UGraphic[] graphics = null;        Server spec = getSpecialist();        if (Debug.debugging("cspec"))            Debug.output(getName() + "|CSpecLayer.getSpecGraphics()");        cproj = new CProjection((short) (p.getProjectionType()), new LLPoint(p.getCenter()                .getLatitude(), p.getCenter().getLongitude()), (short) p.getHeight(), (short) p.getWidth(), (int) p.getScale());        // lat-lon "box", (depends on the projection)        LatLonPoint ul = p.getUpperLeft();        LatLonPoint lr = p.getLowerRight();        ll1 = new LLPoint(ul.getLatitude(), ul.getLongitude());        ll2 = new LLPoint(lr.getLatitude(), lr.getLongitude());        // check for cancellation        if (isCancelled()) {            dirtybits |= PREMATURE_FINISH;            if (Debug.debugging("cspec"))                Debug.output(getName()                        + "|CSpecLayer.getSpecGraphics(): aborted.");            return null;        }        // check for null specialist        if (spec == null) {            if (Debug.debugging("cspec")) {                System.err.println(getName()                        + "|CSpecLayer.getSpecGraphics(): null specialist!");            }            return null;        }        try {            // Keep the gestures up-to-date            mapGesture.setProjection(p);

⌨️ 快捷键说明

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