📄 layerspanel.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/gui/LayersPanel.java,v $// $RCSfile: LayersPanel.java,v $// $Revision: 1.9.2.5 $// $Date: 2006/01/13 22:48:58 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.gui;import java.awt.BorderLayout;import java.awt.Container;import java.awt.Dimension;import java.awt.Frame;import java.awt.Insets;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.Serializable;import java.util.Hashtable;import java.util.Iterator;import java.util.LinkedList;import java.util.Properties;import javax.swing.BoxLayout;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JInternalFrame;import javax.swing.JPanel;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.ScrollPaneConstants;import com.bbn.openmap.BufferedLayerMapBean;import com.bbn.openmap.I18n;import com.bbn.openmap.Layer;import com.bbn.openmap.LayerHandler;import com.bbn.openmap.LightMapHandlerChild;import com.bbn.openmap.MapHandler;import com.bbn.openmap.event.LayerEvent;import com.bbn.openmap.event.LayerListener;import com.bbn.openmap.util.ComponentFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * The LayersPanel displays the list of layers that OpenMap can display. The * layer name is displayed accompanied by an on/off button and a tool palette * button. Pressing the on/off button will cause the the map to display/remove * the layer. Pressing the tool palette button will cause a window to be * displayed containing widgets specific to that layer. * <p> * * The order of the layers in the list reflects the order that the layers are * displayed on the map, with the bottom-most layer listed on the panel * underneath all the the other layers displayed on the map. The order of the * layers is determined by their order in the Layer[] passed in the setLayers * method. * <p> * * The order of the layers can be changed by sending the LayersPanel an * ActionEvent with one of the string commands in the class, or by sending a * PropertyChangeEvent with a command and a Layer as the new value. * <P> * * In the standard GUI, the order can be changed by selecting a layer by * clicking on the layer's name (or on either of buttons), then clicking on one * of the four buttons on the left side of the panel. The four buttons signify, * from top to bottom: Move the selected layer to the top; Move the selected * layer up one position; Move the selected layer down one position; Move the * selected layer to the bottom. * <P> * * The LayersPanel can be used within a BeanContext. If it is added to a * BeanConext, it will look for a LayerHandler to add itself to as a * LayerListener. The LayersPanel can only listen to one LayerHandler, so if * more than one is found, only the last one found will be used. If another * LayerHandler is added to the BeanContext later, the new LayerHandler will be * used. The LayersPanel is also considered to be a Tool, which will cause a * button that will bring up the LayersPanel to be automatically added to the * ToolPanel if a ToolPanel is part of the BeanContext. * <P> * * When the LayersPanel discovers a BufferedLayerMapBean is being used, it adds * a special LayerPane to its LayerPane list that shows which layers are being * buffered in the MapBean. This special LayerPane shows up as a line in the * list, and all layers below that line are being specially buffered by the * BufferedLayerMapBean. * <P> * * The properties that can be set for the LayersPanel: * * <pre> * * * * # Use LayerStatusPanes for the layers if true, otherwise * # LayerPanes. LayerStatusPanes turn the on/off bulbs to green/red * # bulbs when the layer is resting/working. LayerPanes just show * # yellow bulbs when the layer is part of the map. * showStatus=true * # When the BufferedLayerMapBean is used, a divider will be * # displayed in the list of layers showing which layers are in the * # MapBean buffer (below the line). Commands to move layers, by * # default, respect this divider, requiring more commands to have * # layers cross it. * boundary=true * # Add control buttons - use "none" for no button. If undefined, * # the LayerControlButtonPanel will be created automatically. * controls=com.bbn.openmap.gui.LayerControlButtonPanel * # Any control properties added here, prepended by "controls"... * controls.configuration=WEST * * * * </pre> */public class LayersPanel extends OMToolComponent implements Serializable, ActionListener, LayerListener, PropertyChangeListener { /** Action command for the layer order buttons. */ public final static String LayerTopCmd = "LayerTopCmd"; /** Action command for the layer order buttons. */ public final static String LayerBottomCmd = "LayerBottomCmd"; /** Action command for the layer order buttons. */ public final static String LayerUpCmd = "LayerUpCmd"; /** Action command for the layer order buttons. */ public final static String LayerDownCmd = "LayerDownCmd"; /** Action command removing a layer. */ public final static String LayerRemoveCmd = "LayerRemoveCmd"; /** Action command adding a layer. */ public final static String LayerAddCmd = "LayerAddCmd"; /** Action command for notification that a layer has been selected. */ public final static String LayerSelectedCmd = "LayerSelected"; /** * Action command for notification that a layer has been deselected. Not so * reliable. Usually a selection notification means that others are * deselected. */ public final static String LayerDeselectedCmd = "LayerDeselected"; /** * A property to set the class to create for layer order controls. If * undefined, a LayerControlButtonPanel in its default configuration will be * created. For no controls added, use (none) for this property. */ public final static String ControlButtonsProperty = "controls"; /** * A property that can be used for controlling how the to top and to bottom * cammands will be interpreted when a BufferedLayerMapBean is used. See the * definition of bufferedBoundary. */ public final static String BufferedBoundaryProperty = "boundary"; /** * A property that can be used for controlling what type of LayerPanes are * used. If true (default) a LayerStatusPane will be created for each layer. * Otherwise, a LayerPane will be used. */ public final static String ShowStatusProperty = "showStatus"; /** * A value for the (controls) property to not include control buttons in the * interface. */ public final static String NO_CONTROLS = "none"; /** Default key for the LayersPanel Tool. */ public final static String defaultKey = "layerspanel"; /** * The LayerHandler to listen to for LayerEvents, and also to notify if the * layer order should change. */ protected transient LayerHandler layerHandler = null; /** * Panel that lets you dynamically add and configure layers. */ protected transient LayerAddPanel layerAddPanel = null; /** * The components holding the layer name label, the on/off indicator and on * button, and the palette on/off indicator and palette on button. */ protected transient LinkedList panes; /** The internal component that holds the panes. */ protected transient JPanel panesPanel; /** The scroll pane to use for panes. */ protected transient JScrollPane scrollPane; /** The Layer order adjustment button group. */ protected transient ButtonGroup bg; /** The ActionListener that will bring up the LayersPanel. */ protected ActionListener actionListener; /** * The frame used when the LayersPanel is used in an application and the * actionListener is called. */ protected transient JFrame layersWindowFrame; /** * The frame used when the LayersPanel is used in an applet and the * actionListener is called. */ protected transient JInternalFrame layersWindow; /** The set of buttons that control the layers. */ protected LayerControlButtonPanel controls = null; /** * Hashtable that tracks LayerPanes for layers, with the layer as the key * and LayerPane as the value. */ protected Hashtable paneLookUp = new Hashtable(); /** * A special LayerPane used when the LayersPanel senses that a * BufferedLayerMapBean is being used. This LayersPanel is a separating line * showing which layers are part of the MapBean's buffer, and which are not. */ protected LayerPane backgroundLayerSeparator = null; /** * Behavior flag so that if there is a background buffered layer on the * MapBean, and a buffered layer divider in the LayersPanel, whether * commands instructing a layer to the top or bottom of the list should * honor the virtual boundary between buffered and unbuffered layers. That * is, if a layer is on the bottom of the buffered list and is instructed to * go to the top of the overal list, it will only first travel to the top of * the buffered layers. On a subsequent top command, it will go to the top * of the list. The same behavior applies for going down. True is default. * If set to false, these commands will just send the selected layer to the * top and bottom of the entire list. */ protected boolean bufferedBoundary = true; /** * Behavior flag that determines what kind of LayerPane is used for the * layers. If true (default) the LayerStatusPane will be used. Otherwise, * the LayerPane will be used instead. */ protected boolean showStatus = true; /** * Construct the LayersPanel. */ public LayersPanel() { super(); setKey(defaultKey); setLayout(new BorderLayout()); // setWindowSupport(new WindowSupport(this, "Layers")); setWindowSupport(new WindowSupport(this, i18n.get(LayersPanel.class, "title", "Layers"))); } /** * Construct the LayersPanel. * * @param lHandler the LayerHandler controlling the layers. */ public LayersPanel(LayerHandler lHandler) { this(); setLayerHandler(lHandler); } /** * Set the LayerHandler that the LayersPanel listens to. If the LayerHandler * passed in is not null, the LayersMenu will be added to the LayerHandler * LayerListener list, and the LayersMenu will receive a LayerEvent with the * current layers. * <P> * * If there is a LayerHandler that is already being listened to, then the * LayersPanel will remove itself from current LayerHandler as a * LayerListener, before adding itself to the new LayerHandler. * <P> * * Lastly, if the LayerHandler passed in is null, the LayersPanel will * disconnect itself from any LayerHandler currently held, and reset itself * with no layers. * * @param lh LayerHandler to listen to, and to use to reorder the layers. */ public void setLayerHandler(LayerHandler lh) { if (layerHandler != null) { layerHandler.removeLayerListener(this); } layerHandler = lh; if (layerHandler != null) { layerHandler.addLayerListener(this); } else { setLayers(new Layer[0]); } updateLayerPanes(layerHandler); } /** * Get the LayerHandler that the LayersPanel listens to and uses to reorder * layers. * * @return LayerHandler. */ public LayerHandler getLayerHandler() { return layerHandler; } /** * Set the layerpanes with the given layerhandler * * @param layerHandler The LayerHandler controlling the layers */ protected void updateLayerPanes(LayerHandler layerHandler) { Iterator it = getPanes().iterator(); while (it.hasNext()) { ((LayerPane) it.next()).setLayerHandler(layerHandler); } } /** * LayerListener interface method. A list of layers will be added, removed, * or replaced based on on the type of LayerEvent. The LayersPanel only * reacts to LayerEvent.ALL events, to reset the components in the * LayersPanel. * * @param evt a LayerEvent. */ public void setLayers(LayerEvent evt) { Layer[] layers = evt.getLayers(); int type = evt.getType(); if (type == LayerEvent.ALL) { Debug.message("layerspanel", "LayersPanel received layers update"); setLayers(layers); } } /** * Tool interface method. The retrieval tool's interface. This method * creates a button that will bring up the LayersPanel. * * @return String The key for this tool. */ public Container getFace() { JButton layerButton = null; if (getUseAsTool()) { layerButton = new JButton(new ImageIcon(OMToolSet.class.getResource("layers.gif"), "Layer Controls"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -