?? omgraphiclist.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/omGraphics/OMGraphicList.java,v $// $RCSfile: OMGraphicList.java,v $// $Revision: 1.13.2.6 $// $Date: 2006/01/03 15:40:20 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Graphics;import java.awt.Paint;import java.awt.TexturePaint;import java.io.EOFException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.OptionalDataException;import java.io.Serializable;import java.net.URL;import java.util.ArrayList;import java.util.Iterator;import java.util.ListIterator;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.GraphicList;import com.bbn.openmap.omGraphics.grid.OMGridGenerator;import com.bbn.openmap.util.Debug;/** * This class encapsulates a List of OMGraphics. * <p> * There are several things that this list does that make it better that any ol' * List. You can make several common OMGraphic modification calls on the list, * and the list handles the iteration and changing of all the graphics while * taking into account a travese order. * <p> * An additional benefit is that because the OMGraphicList extends OMGraphic it * can contain other instances of OMGraphicList. This way you can manage * groupings of graphics, (for instance, an OMGraphicList of OMGraphicLists * which each have an OMRaster and OMText). * <p> * Many methods, such as generate() and findClosest() traverse the items in the * GraphicsList recursively. The direction that the list is traversed is * controlled by then traverseMode variable. The traverseMode mode lets you set * whether the first or last object added to the list (FIRST_ADDED_ON_TOP or * LAST_ADDED_ON_TOP) is drawn on top of the list and considered first for * searches. */public class OMGraphicList extends OMGraphic implements GraphicList, Serializable { /** * Used to set the order in which the list is traversed to draw or search * the objects. This means that the last things on the list will be on top * of the map because they are drawn last, on top of everything else. For * searches, objects added last to the list will be considered first for a * search match. */ public final transient static int LAST_ADDED_ON_TOP = 0; /** * Used to set the order in which the list is traversed to draw or search * the objects. This means that the first things on the list will appear on * top because they are drawn last, on top of everything else. For searches, * objects added first to the list will be considered first for a search * match. This is the default mode for the list. */ public final transient static int FIRST_ADDED_ON_TOP = 1; /** * Used for searches, when OMDist doesn't have a graphic. The index of a * null graphic is NONE. If you try to remove or insert a graphic at NONE, * an exception will be thrown. If you try to get a graphic at NONE, you'll * get null; */ public final static int NONE = -1; /** * List traversal mode. The default is FIRST_ADDED_ON_TOP. */ protected int traverseMode = FIRST_ADDED_ON_TOP; /** * Flag to adjust behavior of OMGraphicList for certain queries. If * OMGraphicList should act as OMGraphic, the entire list will be treated as * one object. Otherwise, the list will act as a pass-through container, and * internal OMGraphics will be returned. This applies to distance(), * selectClosest(), findClosest(), getOMGraphicThatContains(), etc. This * flag becomes really helpful for embedded OMGraphicLists, not so much for * top-level OMGraphicLists. */ protected boolean vague = false; /** * The list of graphics. Once an OMGraphicList is constructed, this variable * should never be null. */ protected java.util.List graphics = null; /** * Flag used to allow duplicates in the OMGraphicList. True by default - * this prevents the list from doing the extra work for checking for * duplicates at addition time. */ protected boolean allowDuplicates = true; /** * Construct an OMGraphicList. */ public OMGraphicList() { this(10); }; /** * Construct an OMGraphicList with an initial capacity. * * @param initialCapacity the initial capacity of the list */ public OMGraphicList(int initialCapacity) { graphics = new ArrayList(initialCapacity); }; /** * Construct an OMGraphicList with an initial capacity and a standard * increment value. * * @param initialCapacity the initial capacity of the list * @param capacityIncrement the capacityIncrement for resizing * @deprecated capacityIncrement no longer used. */ public OMGraphicList(int initialCapacity, int capacityIncrement) { this(initialCapacity); }; /** * Construct an OMGraphicList around a List of OMGraphics. The OMGraphicList * assumes that all the objects on the list are OMGraphics, and never does * checking. Live with the consequences if you put other stuff in there. * * @param list List of OMGraphics. */ public OMGraphicList(java.util.List list) { graphics = list; } /** * OMGraphic method for returning a simple description of the list. This is * really a debugging method. */ public String getDescription() { return getDescription(0); } /** * OMGraphic method, for returning a simple description if the contents of * the list. This method handles the spacing of sub-member descriptions. * This is really a debugging method. * * @return String that represents the structure of the OMGraphicList. */ public String getDescription(int level) { StringBuffer sb = new StringBuffer(); if (level > 0) { sb.append("|--> "); } sb.append("OMGraphicList with " + size() + " OMGraphic" + (size() == 1 ? "\n" : "s\n")); synchronized (this) { StringBuffer sb1 = new StringBuffer(); for (int i = 0; i < level; i++) { sb1.append(" "); } String spacer = sb1.toString(); for (Iterator it = iterator(); it.hasNext();) { sb.append(spacer + ((OMGraphic) it.next()).getDescription(level + 1) + "\n"); } } return sb.toString(); } /** * Set whether the list returns the specific OMGraphic in response to a * query, or itself. */ public void setVague(boolean value) { vague = value; } /** * Get whether the list returns the specific OMGraphic in response to a * query, or itself. */ public boolean isVague() { return vague; } /** * Add an OMGraphic to the GraphicList. The OMGraphic must not be null. * * @param g the non-null OMGraphic to add * @exception IllegalArgumentException if OMGraphic is null */ public void addOMGraphic(OMGraphic g) { _add(g); } /** * Add an OMGraphic to the list. */ public void add(OMGraphic g) { _add(g); } /** * Add an OMGeometry to the list. */ protected synchronized void _add(OMGeometry g) { checkForDuplicate(g); graphics.add(g); } /** * Set the order in which the list is traversed to draw or search the * objects. The possible modes for the list are FIRST_ADDED_ON_TOP or * LAST_ADDED_ON_TOP. * * @param mode traversal mode */ public void setTraverseMode(int mode) { traverseMode = mode; } /** * Get the order in which the list is traversed to draw or search the * objects. The possible modes for the list are FIRST_ADDED_ON_TOP or * LAST_ADDED_ON_TOP. * * @return int traversal mode */ public int getTraverseMode() { return traverseMode; } /** * Remove all elements from the graphic list. */ public synchronized void clear() { graphics.clear(); } /** * Find out if the list is empty. * * @return boolean true if the list is empty, false if not */ public synchronized boolean isEmpty() { return graphics.isEmpty(); } /** * Find out the number of graphics in the list. * * @return int the number of graphics on the list. */ public synchronized int size() { return graphics.size(); } /** * Set the graphic at the specified location. The OMGraphic must not be * null. * * @param graphic OMGraphic * @param index index of the OMGraphic to return * @exception ArrayIndexOutOfBoundsException if index is out-of-bounds */ public synchronized void setOMGraphicAt(OMGraphic graphic, int index) { graphics.set(index, graphic); } /** * Get the graphic at the location number on the list. * * @param location the location of the OMGraphic to return * @return OMGraphic or null if location > list size * @exception ArrayIndexOutOfBoundsException if <code>location < 0</code> * or <code>location >= * this.size()</code> */ public OMGraphic getOMGraphicAt(int location) { return (OMGraphic) _getAt(location); } /** * Get the geometry at the location number on the list. * * @param location the location of the OMGeometry to return * @return OMGraphic or null if location > list size * @exception ArrayIndexOutOfBoundsException if <code>location < 0</code> * or <code>location >= * this.size()</code> */ protected synchronized OMGeometry _getAt(int location) { if (location < 0 || location >= graphics.size()) { return null; } return (OMGeometry) graphics.get(location); } /** * Set the geometry at the specified location. The OMGeometry must not be * null. * * @param graphic OMGeometry * @param index index of the OMGeometry to return * @exception ArrayIndexOutOfBoundsException if index is out-of-bounds */ protected synchronized void _setAt(OMGeometry graphic, int index) { graphics.set(index, graphic); } /** * Get the graphic with the appObject. Traverse mode doesn't matter. Tests * object identity first, then tries equality. * * @param appObj appObject of the wanted graphic. * @return OMGraphic or null if not found * @see Object#equals * @see OMGeometry#setAppObject * @see OMGeometry#getAppObject */ public OMGraphic getOMGraphicWithAppObject(Object appObj) { return (OMGraphic) _getWithAppObject(appObj); } /** * Get the graphic with the appObject. Traverse mode doesn't matter. Tests * object identity first, then tries equality. * <p> * * If this list contains OMGraphicLists that are not vague, and the those * lists' appObject doesn't match, the object will be passed to those lists * as well for a check, with their OMGraphic being passed back with a * successful search. * * @param appObj appObject of the wanted graphic. * @return OMGraphic or null if not found * @see Object#equals
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -