📄 locationlayer.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/location/LocationLayer.java,v $// $RCSfile: LocationLayer.java,v $// $Revision: 1.6.2.2 $// $Date: 2006/01/18 17:51:02 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.location;/* Java Core */import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.util.Enumeration;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import javax.swing.Box;import javax.swing.JCheckBox;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.ScrollPaneConstants;import javax.swing.SwingUtilities;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.Layer;import com.bbn.openmap.MapBean;import com.bbn.openmap.event.InfoDisplayEvent;import com.bbn.openmap.event.LayerStatusEvent;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.ProjectionEvent;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.gui.WindowSupport;import com.bbn.openmap.layer.DeclutterMatrix;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.SwingWorker;/** * The LocationLayer is a layer that displays graphics supplied by * LocationHandlers. When the layer receives a new projection, it goes to each * LocationHandler and asks it for additions to the layer's graphic list. The * LocationHandlers maintain the graphics, and the layer maintains the overall * list. * * The whole idea behind locations is that there are geographic places that are * to be marked with a graphic, and/or a text label. The location handler * handles the interface with the source and type of location to be displayed, * and the LocationLayer deals with all the locations in a generic way. The * LocationLayer is capable of using more than one LocationHandler. * <P> * * As a side note, a Link is nothing more than a connection between Locations, * and is an extension of the Location Class. They have a graphic representing * the link, an optional label, and an extra set of location coordinates. * <P> * * The layer responds to gestures with pop-up menus. Which menu appears depends * if the gesture affects a graphic. * <P> * * The properties for this layer are: * <P> * * <pre> * * #################################### * # Properties for LocationLayer * # Use the DeclutterMatrix to declutter the labels. * locationlayer.useDeclutter=false * # Which declutter matrix class to use. * locationlayer.declutterMatrix=com.bbn.openmap.layer.DeclutterMatrix * # Let the DeclutterMatrix have labels that run off the edge of the map. * locationlayer.allowPartials=true * # The list of location handler prefixes - each prefix should then * # be used to further define the location handler properties. * locationlayer.locationHandlers=handler1 handler2 * # Then come the handler properties... * # At the least, each handler should have a .class property * handler1.class=<handler classname> * # plus any other properties handler1 needs - check the handler1 documentation. * #################################### * * </pre> */public class LocationLayer extends Layer implements MapMouseListener { /** The declutter matrix to use, if desired. */ protected DeclutterMatrix declutterMatrix = null; /** Flag to use declutter matrix or not. */ protected boolean useDeclutterMatrix = false; /** * Flag to let objects appear partially off the edges of the map, when * decluttering through the decluterr matrix. */ protected boolean allowPartials = true; /** The graphic list of objects to draw. */ protected Vector omGraphics; /** Handlers load the data, and manage it for the layer. */ protected LocationHandler[] dataHandlers; /** Pretty names for the handlers, for GUIs and such. */ protected String[] dataHandlerNames; // /////////////////// // Variables to manage the gesturing mechanisms /** Used for recentering commands off the pop-up menu. */ protected MapBean map; /** * What pops up if someone clicks on the background. The handler is * responsible for suppling the pop-up menu when one of its objects is * selected. */ protected LocationPopupMenu backgroundMenu; /** What pops up if someone clicks on a location. */ protected LocationPopupMenu locMenu; static final public String recenter = "Re-center map"; static final public String cancel = "Cancel"; public static final String UseDeclutterMatrixProperty = "useDeclutter"; public static final String DeclutterMatrixClassProperty = "declutterMatrix"; public static final String AllowPartialsProperty = "allowPartials"; public static final String LocationHandlerListProperty = "locationHandlers"; /** * The swing worker that goes off in it's own thread to get graphics. */ protected LocationWorker currentWorker; /** * Set when the projection has changed while a swing worker is gathering * graphics, and we want him to stop early. */ protected boolean cancelled = false; /** * Since we can't have the main thread taking up the time to create images, * we use this worker thread to do it. */ class LocationWorker extends SwingWorker { /** Constructor used to create a worker thread. */ public LocationWorker() { super(); } /** * Compute the value to be returned by the <code>get</code> method. */ public Object construct() { if (Debug.debugging("location")) { Debug.output(getName() + "|LocationWorker.construct()"); } fireStatusUpdate(LayerStatusEvent.START_WORKING); try { return prepare(); } catch (OutOfMemoryError e) { String msg = getName() + "|LocationLayer.LocationWorker.construct(): " + e; Debug.error(msg); e.printStackTrace(); fireRequestMessage(new InfoDisplayEvent(this, msg)); fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); return null; } } /** * Called on the event dispatching thread (not on the worker thread) * after the <code>construct</code> method has returned. */ public void finished() { workerComplete(this); fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); } } /** * The default constructor for the Layer. All of the attributes are set to * their default values. */ public LocationLayer() {} /** * The properties and prefix are managed and decoded here, for the standard * uses of the LocationLayer. * * @param prefix string prefix used in the properties file for this layer. * @param properties the properties set in the properties file. */ public void setProperties(String prefix, Properties properties) { super.setProperties(prefix, properties); String realPrefix = ""; if (prefix != null) { realPrefix = prefix + "."; } setLocationHandlers(realPrefix, properties); declutterMatrix = (DeclutterMatrix) PropUtils.objectFromProperties(properties, realPrefix + DeclutterMatrixClassProperty); allowPartials = PropUtils.booleanFromProperties(properties, realPrefix + AllowPartialsProperty, true); if (declutterMatrix != null) { useDeclutterMatrix = PropUtils.booleanFromProperties(properties, realPrefix + UseDeclutterMatrixProperty, useDeclutterMatrix); declutterMatrix.setAllowPartials(allowPartials); Debug.message("location", "LocationLayer: Found DeclutterMatrix to use"); // declutterMatrix.setXInterval(3); // declutterMatrix.setYInterval(3); } else { useDeclutterMatrix = false; } } /** * Sets the current graphics list to the given list. * * @param aList a vector of OMGraphics */ public synchronized void setGraphicList(Vector aList) { omGraphics = aList; } /** * Retrieves a vector of the current graphics list. * * @return vector of OMGraphics. */ public synchronized Vector getGraphicList() { return omGraphics; } public void setDeclutterMatrix(DeclutterMatrix dm) { declutterMatrix = dm; } public DeclutterMatrix getDeclutterMatrix() { return declutterMatrix; } public void setUseDeclutterMatrix(boolean set) { useDeclutterMatrix = set; } public boolean getUseDeclutterMatrix() { return useDeclutterMatrix; } /** * Used to set the cancelled flag in the layer. The swing worker checks this * once in a while to see if the projection has changed since it started * working. If this is set to true, the swing worker quits when it is safe. */ public synchronized void setCancelled(boolean set) { cancelled = set; } /** Check to see if the cancelled flag has been set. */ public synchronized boolean isCancelled() { return cancelled; } public synchronized MapMouseListener getMapMouseListener() { return this; } /** * Tell the location handlers to reload their data from their sources. If * you want these changes to appear on the map, you should call doPrepare() * after this call. */ public void reloadData() { if (dataHandlers != null) { for (int i = 0; i < dataHandlers.length; i++) { dataHandlers[i].reloadData(); } } } /** * Implementing the ProjectionPainter interface. */ public synchronized void renderDataForProjection(Projection proj, java.awt.Graphics g) { if (proj == null) { Debug.error("LocationLayer.renderDataForProjection: null projection!"); return; } else if (!proj.equals(getProjection())) { setProjection(proj.makeClone()); setGraphicList(prepare()); } paint(g); } /** * The projectionListener interface method that lets the Layer know when the * projection has changes, and therefore new graphics have to created * /supplied for the screen. * * @param e The projection event, most likely fired from a map bean. */ public void projectionChanged(ProjectionEvent e) { if (Debug.debugging("basic")) { Debug.output(getName() + "|LocationLayer.projectionChanged()"); } if (setProjection(e) == null) { // Nothing to do, already have it and have acted on it... repaint(); return; } setGraphicList(null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -