📄 linklayer.java
字号:
// **********************************************************************// // <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/openmap/com/bbn/openmap/layer/link/LinkLayer.java,v $// $RCSfile: LinkLayer.java,v $// $Revision: 1.12.2.2 $// $Date: 2005/08/09 18:10:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;/* Java Core */import java.awt.Container;import java.awt.event.MouseEvent;import java.io.IOException;import java.net.URL;import java.net.UnknownHostException;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;/* OpenMap */import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MapBean;import com.bbn.openmap.MapHandler;import com.bbn.openmap.MoreMath;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.grid.OMGridGenerator;import com.bbn.openmap.proj.GreatCircle;import com.bbn.openmap.proj.Mercator;import com.bbn.openmap.proj.Proj;import com.bbn.openmap.proj.ProjMath;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.ProjectionFactory;import com.bbn.openmap.tools.drawing.DrawingToolRequestor;/** * The LinkLayer is a Swing component, and an OpenMap layer, that * communicates with a server via the Link protocol. It transmits * graphics requests and gesture information, and handles the * responses to those queries. The entry in the openmap.properties * file looks like this: * <P> * * <pre> * * * * * # port number of server * link.port=3031 * * # host name of server * link.host=host.com * * # URL of properties file for server attributes. Properties * # contained in this file are passed directly to the server to provide * # additional information to the server about how to provide the * # graphics. Some standard properties are listed in the * # LinkPropertiesConstants file, but any property can be passed to the * # server. How the server handles the property depends on the server, * # but non-applicable properties are ignored. * link.propertiesURL=http://location.of.properties.file.com * * * * * </pre> * * You have to call setProperties() on this layer to set its * parameters, and to start the thread that listens to updates from * the server. */public class LinkLayer extends OMGraphicHandlerLayer implements MapMouseListener, LinkPropertiesConstants, LinkActionConstants, DrawingToolRequestor { /** * The thread listener used to communicate asynchronously. The * LinkLayer sends out requsts and notifications to the server, * and the LinkListener reads any input from the server, making * calls on the LinkLayer as appropriate. */ protected LinkListener listener; /** * A masked integer describing which gestures should be sent to * the server. */ protected int gestureDescriptor = 0; /** The port to connect to the server on. */ protected int port; /** The host where the server is running. */ protected String host; /** * The special parameters (attributes) transmitted to the server * with every query. */ protected LinkProperties args; /** * The object that provides a link to the layer (and its various * threads) on a coordinateed basis. */ protected LinkManager linkManager = null; /** The flag to supress pop-up messages. */ protected boolean quiet = false; /** The generator to use with LinkGrid objects. */ protected OMGridGenerator currentGenerator = null; /** * The property name to specify what port the server is running * on. "port" */ public final static String PortProperty = "port"; /** * The property name to specify the hostname the server is running * on. "host" */ public final static String HostProperty = "host"; /** * The property name to specify a URL of a properties file * containing properties that will be sent to the server within * requests to it. The contents of this file depends on the * server. "propertiesURL" */ public final static String ArgsProperty = "propertiesURL"; public final static String ServerLocationProperty = "isl"; /** * The property to make the layer quiet. "quiet" */ public final static String QuietProperty = "quiet"; /** * The property to specify which grid generator to use for grid * objects. "gridGenerator" */ public final static String GridGeneratorProperty = "gridGenerator"; /** * The property to set a pixel distance limit for gestures. * "distanceLimit" */ public final static String DistanceLimitProperty = "distanceLimit"; public final static int DEFAULT_DISTANCE_LIMIT = 4; /** * The maximum distance away a mouse event can happen away from a * graphic in order for it to be considered to have touched. */ protected int distanceLimit = DEFAULT_DISTANCE_LIMIT; /** * The property to set to true if the server should be able to * decide when to kill the client, the overall application. False * by default, only modified in setProperties. "exitOnCommand" */ public final static String ExitOnCommandProperty = "exitOnCommand"; /** * The default constructor for the Layer. All of the attributes * are set to their default values. */ public LinkLayer() { // We don't want to reset the OMGraphicsList automatically // when the projection changes, now. With ansynchronous // behavior, the current list should be reprojected and the // server notified, and the server will update itself if // needed. setProjectionChangePolicy(new com.bbn.openmap.layer.policy.ListResetPCPolicy( this) { // Modified so it doesn't reset the OMGraphicList when // the SwingWorker thread returns. The list has // already been nulled out, will be reset when the // asynchronous thread decides it is. public void workerComplete(OMGraphicList list) {} }); } /** * Constructor to use when LinkLayer is not being used with * OpenMap application. * * @param host the hostname of the server's computer. * @param port the port number of the server. * @param propertiesURL the URL of a properties file that contains * parameters for the server. */ public LinkLayer(String host, int port, String propertiesURL) { this(); this.host = host; this.port = port; linkManager = new LinkManager(host, port); args = new LinkProperties(); if (propertiesURL != null) { try { URL propertiesFile = new URL(propertiesURL); args.load(propertiesFile.openStream()); } catch (java.net.MalformedURLException mue) { System.err.println("LinkLayer: Properties URL isn't valid: " + propertiesURL); System.err.println(mue); } catch (IOException ioe) { System.err.println("LinkLayer: IOException reading properties file:"); System.err.println(ioe); } } } /** * Sets the current graphics list to the given list. * * @param aList a list of OMGraphics */ public synchronized void setGraphicList(LinkOMGraphicList aList) { super.setList(aList); } /** * Retrieves the current graphics list. */ public synchronized LinkOMGraphicList getGraphicList() { return (LinkOMGraphicList) getList(); } /** * Called when the layer is no longer part of the map. In this * case, we should disconnect from the server if we have a link. */ public void removed(Container cont) { linkManager.resetLink(); } /** * Sets the masked integer which indicates what types of events * get sent to the server. * * @param descriptor masked int * @see LinkActionRequest */ public synchronized void setGestureDescriptor(int descriptor) { gestureDescriptor = descriptor; } /** * Gets the masked integer which indicates what types of events * get sent to the server. * * @return descriptor masked int * @see LinkActionRequest */ public synchronized int getGestureDescriptor() { return gestureDescriptor; } /** * Set all the Link properties from a properties object. * * @param prefix the prefix to the properties tha might * individualize it to a particular layer. * @param properties the properties for the layer. */ public void setProperties(String prefix, Properties properties) { super.setProperties(prefix, properties); String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); String quietString = properties.getProperty(realPrefix + QuietProperty); if (quietString != null && quietString.intern() == "true") { quiet = true; } host = properties.getProperty(realPrefix + HostProperty); port = PropUtils.intFromProperties(properties, realPrefix + PortProperty, LinkServerStarter.DEFAULT_PORT); linkManager = new LinkManager(host, port); linkManager.setObeyCommandToExit(PropUtils.booleanFromProperties(properties, realPrefix + ExitOnCommandProperty, false)); String propertiesURL = properties.getProperty(realPrefix + ArgsProperty); args = new LinkProperties(); // Empty if not filled. if (propertiesURL != null) { try { URL propertiesFile = new URL(propertiesURL); args.load(propertiesFile.openStream()); } catch (java.net.MalformedURLException mue) { System.err.println("LinkLayer: Properties URL isn't valid: " + realPrefix + ArgsProperty); System.err.println(mue); } catch (IOException ioe) { System.err.println("LinkLayer: IOException reading properties file:"); System.err.println(ioe); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -