⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omgraphiclist.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *         found.     */    protected synchronized OMGeometry _getContains(int x, int y) {        ListIterator iterator;        OMGeometry graphic, ret = null;        OMGraphicList tomgl = null;        if (size() != 0) {            if (traverseMode == FIRST_ADDED_ON_TOP) {                iterator = graphics.listIterator();                while (iterator.hasNext()) {                    graphic = (OMGraphic) iterator.next();                    // cannot select a graphic which isn't visible                    if (!shouldProcess(graphic))                        continue;                    if (graphic instanceof OMGraphicList) {                        tomgl = (OMGraphicList) graphic;                        ret = tomgl._getContains(x, y);                        if (ret != null) {                            if (tomgl.isVague()) {                                ret = graphic;                            }                            break;                        }                    } else if (graphic.contains(x, y)) {                        ret = graphic;                        break;                    }                }            } else {                iterator = graphics.listIterator(graphics.size());                while (iterator.hasPrevious()) {                    graphic = (OMGraphic) iterator.previous();                    // cannot select a graphic which isn't visible                    if (!shouldProcess(graphic))                        continue;                    if (graphic instanceof OMGraphicList) {                        tomgl = (OMGraphicList) graphic;                        ret = tomgl._getContains(x, y);                        if (ret != null) {                            if (tomgl.isVague()) {                                ret = graphic;                            }                            break;                        }                    } else if (graphic.contains(x, y)) {                        ret = graphic;                        break;                    }                }            }        }        if (ret != null && this.isVague()) {            ret = this;        }        return ret;    }    /**     * If you call deselect() on an OMGraphicList, it deselects all the graphics     * it contains. This is really an OMGraphic method, but it makes     * OMGraphicLists embedded in other OMGraphicLists act correctly.     */    public void deselect() {        deselectAll();        super.deselect();    }    /**     * Deselects all the items on the graphic list.     */    public synchronized void deselectAll() {        for (Iterator it = iterator(); it.hasNext();) {            ((OMGeometry) it.next()).deselect();        }    }    /**     * Selects all the items on the graphic list.     */    public synchronized void selectAll() {        for (Iterator it = iterator(); it.hasNext();) {            ((OMGeometry) it.next()).select();        }    }    /**     * Perform an action on the provided graphic. If the graphic is not     * currently on the list, it is added (if the action doesn't say to delete     * it). If the graphic is null, the list checks for an action to take on the     * list (deselectAll).     */    public void doAction(OMGraphic graphic, OMAction action) {        _doAction((OMGeometry) graphic, action);    }    /**     * Perform an action on the provided geometry. If the geometry is not     * currently on the list, it is added (if the action doesn't say to delete     * it). If the geometry is null, the list checks for an action to take on     * the list (deselectAll).     */    protected void _doAction(OMGeometry graphic, OMAction action) {        Debug.message("omgl", "OMGraphicList.doAction()");        if (graphic == null) {            return;        }        int i = _indexOf(graphic);        boolean alreadyOnList = (i != -1);        if (action == null || action.getValue() == 0 && !alreadyOnList) {            Debug.message("omgl",                    "OMGraphicList.doAction: adding graphic with null action");            _add(graphic);            return;        }        if (action.isMask(ADD_GRAPHIC_MASK)                || action.isMask(UPDATE_GRAPHIC_MASK) && !alreadyOnList) {            Debug.message("omgl", "OMGraphicList.doAction: adding graphic");            _add(graphic);        }        if (action.isMask(DELETE_GRAPHIC_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: removing graphic");            _remove(graphic);        }        if (action.isMask(RAISE_GRAPHIC_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: raising graphic");            moveIndexedOneToTop(i);        }        if (action.isMask(RAISE_TO_TOP_GRAPHIC_MASK)) {            Debug.message("omgl",                    "OMGraphicList.doAction: raising graphic to top");            moveIndexedToTop(i);        }        if (action.isMask(LOWER_GRAPHIC_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: lowering graphic");            moveIndexedOneToBottom(i);        }        if (action.isMask(LOWER_TO_BOTTOM_GRAPHIC_MASK)) {            Debug.message("omgl",                    "OMGraphicList.doAction: lowering graphic to bottom");            moveIndexedOneToBottom(i);        }        if (action.isMask(DESELECTALL_GRAPHIC_MASK)) {            Debug.message("omgl",                    "OMGraphicList.doAction: deselecting all graphics.");            deselectAll();        }        if (action.isMask(SELECT_GRAPHIC_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: selecting graphic");            graphic.select();        }        if (action.isMask(DESELECT_GRAPHIC_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: deselecting graphic");            graphic.deselect();        }        if (action.isMask(SORT_GRAPHICS_MASK)) {            Debug.message("omgl", "OMGraphicList.doAction: sorting the list");            sort();        }    }    /**     * Set the visibility variable. NOTE: <br>     * This is checked by the OMGeometryList when it iterates through its list     * for render and gesturing. It is not checked by the internal OMGeometry     * methods, although maybe it should be...     *      * @param visible boolean     */    public synchronized void setVisible(boolean visible) {        for (Iterator it = iterator(); it.hasNext();) {            ((OMGeometry) it.next()).setVisible(visible);        }    }    /**     * Get the visibility variable. For the OMGeometryList, if any part of it is     * visible, then it is considered visible.     *      * @return boolean     */    public synchronized boolean isVisible() {        for (Iterator it = iterator(); it.hasNext();) {            if (((OMGeometry) it.next()).isVisible()) {                return true;            }        }        return false;    }    /**     * Set whether the list will allow duplicate entries added. If not, then the     * copy will be added, and the previous version removed.     */    public void setAllowDuplicates(boolean set) {        allowDuplicates = set;    }    /**     * Get whether the list will allow duplicate entries added. If not, then the     * copy will be added, and the previous version removed.     */    public boolean getAllowDuplicates() {        return allowDuplicates;    }    /**     * Convenience function for methods that may add a OMGeometry. Method checks     * to see if duplicates are allowed, and if they are not, it will remove the     * OMGeometry from the list. The calling method can be confident that it     * will be adding a unqiue OMGeometry. Internal methods that call this     * method should be synchronized on the graphics list.     */    protected synchronized void checkForDuplicate(OMGeometry g) {        if (!allowDuplicates) {            // Why check first, just remove it if it's found?!            // if (graphics.contains(g)) {            graphics.remove(g);            // }        }    }    /**     * Checks if an OMGeometry is on this list. Checks sublists, too.     */    public synchronized boolean contains(OMGeometry g) {        boolean ret = false;        if (g != null) {            for (Iterator it = iterator(); it.hasNext();) {                OMGeometry itg = (OMGeometry) it.next();                if (g == itg                        || (itg instanceof OMGraphicList && ((OMGraphicList) itg).contains(g))) {                    ret = true;                    break;                }            }        }        return ret;    }    /**     * Goes through the list, finds the OMGrid objects, and sets the generator     * for all of them. If a projection is passed in, the generator will be used     * to create a displayable graphic within the grid.     *      * @param generator an OMGridGenerator to create a renderable graphic from     *        the OMGrid.     * @param proj a projection to use to generate the graphic. If null, the     *        generator will create a renderable graphic the next time a     *        projection is handed to the list.     */    public synchronized void setGridGenerator(OMGridGenerator generator,                                              Projection proj) {        OMGraphic graphic;        for (Iterator it = iterator(); it.hasNext();) {            graphic = (OMGraphic) it.next();            if (graphic instanceof OMGrid) {                ((OMGrid) graphic).setGenerator(generator);                if (proj != null) {                    graphic.generate(proj);                }            }        }    }    /**     * Get a reference to the graphics vector. This method is meant for use by     * methods that need to iterate over the graphics vector, or make at least     * two invocations on the graphics vector.     * <p>     * HACK this method should either return a clone of the graphics list or a     * quick reference. Currently it returns the latter for simplicity and minor     * speed improvement. We should allow a way for the user to set the desired     * behavior, depending on whether they want responsibility for list     * synchronization. Right now, the user is responsible for synchronizing the     * OMGeometryList if it's being used in two or more threads...     *      * @return a reference of the graphics List.     */    public synchronized java.util.List getTargets() {        if (graphics == null) {            // make sure that the graphics vector is not null,            // since all of the internal methods rely on it.            graphics = new ArrayList();        }        return graphics;    }    /**     * Set the List used to hold the OMGraphics. The OMGraphicList assumes that     * this list contains OMGraphics. Make *SURE* this is the case. The     * OMGraphicList will behave badly if there are non-OMGraphics on the list.     */    public synchronized void setTargets(java.util.List list) {        graphics = list;    }    /**     * Get an Iterator containing the OMGeometrys.     */    public synchronized Iterator iterator() {        return graphics.iterator();    }    /**     * Read a cache of OMGeometrys, given an URL.     *      * @param cacheURL URL of serialized graphic list.     */    public void readGraphics(URL cacheURL) throws IOException {        try {            ObjectInputStream objstream = new ObjectInputStream(cacheURL.openStream());            if (Debug.debugging("omgraphics")) {                Debug.output("OMGeomtryList: Opened " + cacheURL.toString());            }            readGraphics(objstream);            objstream.close();            if (Debug.debugging("omgraphics")) {                Debug.output("OMGeometryList: closed " + cacheURL.toString());            }        } catch (ArrayIndexOutOfBoundsException aioobe) {            throw new com.bbn.openmap.util.HandleError(aioobe);        } catch (ClassCastException cce) {            cce.printStackTrace();        }    }    /**     * Read a cache of OMGraphics, given a ObjectInputStream.     *      * @param objstream ObjectInputStream of graphic list.     */    public synchronized void readGraphics(ObjectInputStream objstream)            throws IOException {        Debug.message("omgraphics", "OMGraphicList: Reading cached graphics");        try {            w

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -