📄 layer.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.java,v $// $RCSfile: Layer.java,v $// $Revision: 1.18.2.9 $// $Date: 2005/09/13 14:34:02 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap;import java.awt.Component;import java.awt.Container;import java.awt.Frame;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import java.beans.beancontext.BeanContext;import java.beans.beancontext.BeanContextChild;import java.beans.beancontext.BeanContextChildSupport;import java.beans.beancontext.BeanContextMembershipEvent;import java.beans.beancontext.BeanContextMembershipListener;import java.io.IOException;import java.io.ObjectInputStream;import java.util.Iterator;import java.util.Properties;import javax.swing.Icon;import javax.swing.JComponent;import com.bbn.openmap.I18n;import com.bbn.openmap.ProjectionPainter;import com.bbn.openmap.event.InfoDisplayEvent;import com.bbn.openmap.event.InfoDisplayListener;import com.bbn.openmap.event.LayerStatusEvent;import com.bbn.openmap.event.LayerStatusListener;import com.bbn.openmap.event.ListenerSupport;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.ProjectionEvent;import com.bbn.openmap.event.ProjectionListener;import com.bbn.openmap.gui.ScrollPaneWindowSupport;import com.bbn.openmap.gui.WindowSupport;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.propertyEditor.Inspector;/** * Layer objects are components which can be added to the MapBean to * make a map. * <p> * * Layers implement the ProjectionListener interface to listen for * ProjectionEvents. When the projection changes, they may need to * refetch, regenerate their graphics, and then repaint themselves * into the new view. * <p> * * When the Layer is added to the MapBean, it will start receiving * ProjectionEvents via the ProjectionListener.projectionChanged() * method it has to implement. There is a * setProjection(ProjectionEvent) methods that should be called from * there if you want to save the projection for later use (handling * MouseEvents, etc). If you call getProjection() before calling * setProjection(), getProjection() will return null, and your * OMGraphics will complain and probably freak out at some point. * * <pre> * //// SAMPLE handling of the ProjectionListener interface. * * public void projectionChanged(com.bbn.openmap.event.ProjectionEvent pe) { * Projection proj = setProjection(pe); * if (proj != null) { * // Use the projection to gather OMGraphics in the layer, * // and prepare the layer so that in the paint() method, * // the OMGraphics get rendered. * * // Call any methods that kick off work to build graphics * // here... * * // You get the paint() methods called by calling * // repaint(): * repaint(); * } * * fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); * } * </pre> * * @see com.bbn.openmap.event.ProjectionListener * @see com.bbn.openmap.event.ProjectionEvent * @see com.bbn.openmap.PropertyConsumer */public abstract class Layer extends JComponent implements ProjectionListener, ProjectionPainter, BeanContextChild, BeanContextMembershipListener, PropertyConsumer, ActionListener { /** * Precaches the swing package. Computed based on the package of * <code>JComponent</code>. */ protected static final String SWING_PACKAGE = getPackage(JComponent.class); /** * The String to use for a key lookup in a Properties object to * find the name to use in a GUI relating to this layer. */ public static final String PrettyNameProperty = "prettyName"; /** * The property to set to add the layer to the BeanContext * "addToBeanContext". This probably needs be set by the layer * itself, because it knows whether it needs other components or * not. However, this property is defined in case an option can be * given to the user. If a Layer doesn't want this option given, * it should reset the addToBeanContext variable after * setProperties() is called. The Layer.setProperties() methods * maintain the current state of the variable if undefined, which * is true by default. */ public static final String AddToBeanContextProperty = "addToBeanContext"; /** * Property 'background' to designate this layer as a background * layer, which will cause extra buffering to occur if the * application can handle it. False by default. */ public static final String AddAsBackgroundProperty = "background"; /** * Property 'removable' to designate this layer as removable from * the application, or able to be deleted. True by default. */ public static final String RemovableProperty = "removable"; /** * Misspelled property 'removeable' to designate this layer as * removable from the application, or able to be deleted. True by * default. Going away. Really. * * @deprecated use RemovableProperty */ public static final String RemoveableProperty = "removeable"; /** * The property for designating the minimum projection scale value * that the layer will respond to. This Layer class doesn't limit * how subclasses will react to projections with scale values * smaller than the specified value. */ public static final String MinScaleProperty = "minScale"; /** * The property for designating the maximum projection scale value * that the layer will respond to. This Layer class doesn't limit * how subclasses will react to projections with scale values * greater than the specified value. */ public static final String MaxScaleProperty = "maxScale"; /** * The property to show the palette when the layer is created - * or, more accurately, when the properties are set. */ public static final String AutoPaletteProperty = "autoPalette"; /** Layer-defined action event command to display the palette. */ public static final String DisplayPaletteCmd = "displayPaletteCmd"; /** Layer-defined action event command to hide the palette. */ public static final String HidePaletteCmd = "hidePaletteCmd"; /** * Layer-defined action event command to display the properties * using an Inspector. */ public static final String DisplayPropertiesCmd = "displayPropertiesCmd"; /** * Layer-defined action event command to force a redraw on the * layer. The Layer class does not respond to this command, it's * provided as a convenience. */ public static final String RedrawCmd = "redrawCmd"; /** * The listeners to the Layer that respond to requests for * information displays, like messages, requests for URL displays, * etc. */ protected ListenerSupport IDListeners = null; /** * List of LayerStatusListeners. */ protected ListenerSupport lsListeners = null; /** * Token uniquely identifying this layer in the application * properties. */ protected String propertyPrefix = null; /** * Used by the LayerHandler to check if the layer should be added * to the MapHandler BeanContext. See the comments under the * AddToBeanContextProperty. True by default. */ protected boolean addToBeanContext = true; /** * Flag used by the layer to indicate that it should be treated as * a background layer, indicating that any cache mechanism * available can enable extra buffering. This may prevent mouse * events from being received by the layer. */ protected boolean addAsBackground = false; /** * Flag to designate the layer as removable or not. */ protected boolean removable = true; /** * A flag to have the layer display it's palette when the * properties are set. If you are creating a layer manually, just * call showPalette() instead. */ protected boolean autoPalette = false; /** * A minimum projection scale value that the layer will respond * to. Using this value for reacting to the projection depends on * the Layer implementation, the Layer class doesn't limit * subclasses from doing their own thing in response to the scale * setting on a projection. */ protected float minScale = Float.MIN_VALUE; /** * A maximum projection scale value that the layer will respond * to. Using this value for reacting to the projection depends on * the Layer implementation, the Layer class doesn't limit * subclasses from doing their own thing in response to the scale * setting on a projection. */ protected float maxScale = Float.MAX_VALUE; /** * This is a convenience copy of the latest projection received * from the MapBean, when the Layer is added to the map. If you * need it, use the accessor!. */ private Projection projection = null; /** * Support class that now handles palette windows. */ protected transient WindowSupport windowSupport; /** * A helper component listener that is paying attention to the * visibility of the palette. */ protected transient ComponentListener paletteListener; /** * A pointer to the JDialog or JInternalFrame. May be used by the * layer's ComponentListeners to figure out if a component event * is for the layer or for the palette. */ protected transient Container palette; /** * The BeanContext allows Layers to find other components, and * other components to find the layer, if the layer is added to * it. */ protected transient BeanContextChildSupport beanContextChildSupport = new BeanContextChildSupport(this); /** * All layers have access to an I18n object, which is provided by * the Environment. */ protected transient I18n i18n = Environment.getI18n(); /** * Icon associated with layer. */ private Icon icon = null; /** * Returns the package of the given class as a string. * * @param c a class */ protected static String getPackage(Class c) { String className = c.getName(); int lastDot = className.lastIndexOf('.'); return className.substring(0, lastDot); } /** * Override to only allow swing package listeners. If Listeners * get added to the Layers, the mouse events don't make it to the * map. Ever. * <p> * Swing popup menus, like <code>JPopupMenu</code> grab the * JComponent by adding themselves as <code>MouseListener</code> * s. So this method allows instances of classes in the xxx.swing * package to be added as <code>MouseListener</code>s, and no * one else. * * @param l a mouse listener. */ public final void addMouseListener(MouseListener l) { String pkg = getPackage(l.getClass()); if (java.beans.Beans.isDesignTime() || pkg.equals(SWING_PACKAGE) || pkg.startsWith(SWING_PACKAGE) || pkg.startsWith("com.sun.java.accessibility.util")) { // Used to do nothing for the equals and startsWith // comparison, but that breaks the menus from being // recinded when something else is clicked on. Thanks to // Tom Peel for pointing this out, 11/29/00. super.addMouseListener(l); } else { throw new IllegalArgumentException("This operation is disallowed because the package \"" + getPackage(l.getClass()) + "\" is not in the swing package (\"" + SWING_PACKAGE + "\")."); } } /** * Sets the properties for the <code>Layer</code>. This * particular method assumes that the marker name is not needed, * because all of the contents of this Properties object are to be * used for this layer, and scoping the properties with a prefix * is unnecessary. * * @param props the <code>Properties</code> object. */ public void setProperties(Properties props) { setProperties(getPropertyPrefix(), props); } /** * Sets the properties for the <code>Layer</code>. Part of the * PropertyConsumer interface. Layers which override this method * should do something like: * * <code><pre> * public void setProperties(String prefix, Properties props) { * super.setProperties(prefix, props); * // do local stuff * } * </pre></code> * * If the addToBeanContext property is not defined, it maintains * the same state. * * @param prefix the token to prefix the property names * @param props the <code>Properties</code> object */ public void setProperties(String prefix, Properties props) { String prettyName = PrettyNameProperty; setPropertyPrefix(prefix); String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); prettyName = realPrefix + PrettyNameProperty; String defaultName = getName(); if (defaultName == null) { defaultName = "Anonymous"; } setName(props.getProperty(prettyName, defaultName)); setAddToBeanContext(PropUtils.booleanFromProperties(props, realPrefix + AddToBeanContextProperty, addToBeanContext)); setAddAsBackground(PropUtils.booleanFromProperties(props, realPrefix + AddAsBackgroundProperty, addAsBackground)); setRemovable(PropUtils.booleanFromProperties(props, realPrefix + RemovableProperty, removable)); // Remove this for 4.7, just covering for misspelled original // version.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -