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

📄 omgraphiclist.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Find all of the OMGraphics on this list that are located within the pixel     * limit of the x, y pixel location.     *      * @param x the x coordinate on the component the graphics are displayed on.     * @param y the y coordinate on the component the graphics are displayed on.     * @param limit the max distance that a graphic has to be within to be     *        returned, in pixels.     * @param resetSelect call deselect on OMGraphics not within limit.     * @param addTo OMGraphicList to add found OMGraphics to, if null a list     *        will be created.     * @return OMGraphicList containing all of the OMGraphics within the limit,     *         empty if none are found.     */    protected synchronized OMGraphicList findAll(int x, int y, float limit,                                                 boolean resetSelect,                                                 OMGraphicList addTo) {        if (addTo == null) {            addTo = new OMGraphicList();        }        OMDist omd = new OMDist();        ListIterator iterator;        if (size() != 0) {            if (traverseMode == FIRST_ADDED_ON_TOP) {                iterator = graphics.listIterator();                while (iterator.hasNext()) {                    if (!findAllTest(x,                            y,                            limit,                            resetSelect,                            addTo,                            (OMGeometry) iterator.next(),                            omd)) {                        break;                    }                }            } else {                iterator = graphics.listIterator(graphics.size());                while (iterator.hasPrevious()) {                    if (!findAllTest(x,                            y,                            limit,                            resetSelect,                            addTo,                            (OMGeometry) iterator.previous(),                            omd)) {                        break;                    }                }            }        }        if (Debug.debugging("omgraphics")) {            Debug.output(this.getClass().getName() + "(" + size()                    + ") detecting hits and vagueness, returning list with "                    + addTo.size() + " graphics.");        }        return addTo;    }    /**     * Test to find out if an OMGeometry is located within the pixel limit of     * the x, y pixel location.     *      * @param x the x coordinate on the component the graphics are displayed on.     * @param y the y coordinate on the component the graphics are displayed on.     * @param limit the max distance that a graphic has to be within to be     *        returned, in pixels.     * @param resetSelect call deselect on OMGeometry not within limit.     * @param addTo OMGraphicList to add found OMGeometries to, if null a list     *        will be created.     * @param omg OMGeometry to test.     * @param omd OMDist to use for test, provided to avoid recurring memory     *        allocations for loops.     * @return true of this method should still be called again in a loop, false     *         of this list is vague and we have a hit.     */    protected boolean findAllTest(int x, int y, float limit,                                  boolean resetSelect, OMGraphicList addTo,                                  OMGeometry omg, OMDist omd) {        if (omg instanceof OMGraphicList) {            int oldSize = addTo.size();            ((OMGraphicList) omg).findAll(x, y, limit, resetSelect, addTo);            int newSize = addTo.size();            if (isVague() && oldSize != newSize) {                addTo.clear();                addTo.add(this);                return false;            }        } else {            omd = findClosestTest(omd,                    0 /* doesn't matter */,                    omg,                    x,                    y,                    limit,                    resetSelect);                        if (omd.omg == null) {                // no hit, but continue testing...                return true;            }            // Measurements passed, add OMGraphic to addTo list and            // continue            if (isVague()) {                addTo.add(this);                return false;            }            addTo.graphics.add(omd.omg);            omd.d = Float.MAX_VALUE; // reset for next OMGraphic            omd.omg = null;        }        return true;    }    /**     * Finds the object located the closest to the point, regardless of how far     * away it is. This method returns null if the list is not valid. The search     * starts at the first-added graphic. <br>     * This is the same as calling     * <code>findClosest(x, y, Float.MAX_VALUE)</code>.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @return the closest graphic to the xy window point.     * @see #findClosest(int, int, float)     */    public OMGraphic findClosest(int x, int y) {        return findClosest(x, y, Float.MAX_VALUE);    }    /**     * Finds the object located the closest to the point, if the object distance     * away is within the limit. The search is always conducted from the topmost     * graphic to the bottommost, depending on the traverseMode. Any graphics     * where <code>isVisible()</code> returns false are not considered.     *      * @param x the x coordinate on the component the graphics are displayed on.     * @param y the y coordinate on the component the graphics are displayed on.     * @param limit the max distance that a graphic has to be within to be     *        returned, in pixels.     * @return index of the closest on the list within the limit, or     *         OMGeometryList.NONE if not found.     */    public int findIndexOfClosest(int x, int y, float limit) {        return _findClosest(x, y, limit, false).index;    }    /**     * Finds the object located the closest to the point, regardless of how far     * away it is. This method returns null if the list is not valid. The search     * starts at the first-added graphic. <br>     * This is the same as calling     * <code>findClosest(x, y, Float.MAX_VALUE)</code>.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @return index of the closest graphic to the xy window point, or     *         OMGeometryList.NONE if not found.     * @see #findIndexOfClosest(int, int, float)     */    public int findIndexOfClosest(int x, int y) {        return _findClosest(x, y, Float.MAX_VALUE, false).index;    }    /**     * Calls _findClosest(x, y, limit, false);     */    protected OMDist _findClosest(int x, int y, float limit) {        return _findClosest(x, y, limit, false);    }    /**     * Finds the object located the closest to the coordinates, regardless of     * how far away it is. Sets the select paint of that object, and resets the     * paint of all the other objects. The search starts at the first-added     * graphic.     *      * @param x the x coordinate on the component the graphics are displayed on.     * @param y the y coordinate on the component the graphics are displayed on.     * @return the closest OMGraphic on the list, with selected having been     *         called on that OMGraphics. This OMGraphic will be within the     *         limit or null if none found. Will return this list if this list     *         is set to be vague.     */    public OMGraphic selectClosest(int x, int y) {        return (OMGraphic) _selectClosest(x, y, Float.MAX_VALUE);    }    /**     * Finds the object located the closest to the point, if the object distance     * away is within the limit, and sets the paint of that graphic to its     * select paint. It sets the paints to all the other objects to the regular     * paint. The search starts at the first-added graphic. Any graphics where     * <code>isVisible()</code> returns false are not considered.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @param limit the max distance that a graphic has to be within to be     *        returned, in pixels.     * @return the closest OMGraphic on the list, with selected having been     *         called on that OMGraphics. This OMGraphic will be within the     *         limit or null if none found. Will return this list if this list     *         is set to be vague.     */    public OMGraphic selectClosest(int x, int y, float limit) {        return (OMGraphic) _selectClosest(x, y, limit);    }    /**     * Finds the object located the closest to the point, if the object distance     * away is within the limit, and sets the paint of that graphic to its     * select paint. It sets the paints to all the other objects to the regular     * paint. The search starts at the first-added graphic. Any graphics where     * <code>isVisible()</code> returns false are not considered.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @param limit the max distance that a graphic has to be within to be     *        returned, in pixels.     * @return the closest OMGraphic on the list, with selected having been     *         called on that OMGraphics. This OMGraphic will be within the     *         limit or null if none found. Will return this list if this list     *         is set to be vague.     */    protected synchronized OMGeometry _selectClosest(int x, int y, float limit) {        OMDist omd = null;        OMDist tomd;        ListIterator iterator;        OMGeometry ret = null;        // Handle vagueness.        if (isVague()) {            omd = _findClosest(x, y, limit, true);            if (omd != null) {                selectAll();                return this;            }        }        if (size() != 0) {            if (traverseMode == FIRST_ADDED_ON_TOP) {                iterator = graphics.listIterator();                while (iterator.hasNext()) {                    tomd = selectClosestTest(omd,                            0,                            (OMGeometry) iterator.next(),                            x,                            y,                            limit);                    if (tomd == null)                        continue;                    omd = tomd; // for style                    if (omd.d == 0)                        break;                }            } else {                iterator = graphics.listIterator(graphics.size());                while (iterator.hasPrevious()) {                    tomd = selectClosestTest(omd,                            0,                            (OMGeometry) iterator.previous(),                            x,                            y,                            limit);                    if (tomd == null)                        continue;                    omd = tomd; // for style                    if (omd.d == 0)                        break;                }            }        }        if (omd != null) {            ret = omd.omg;        }        return ret;    }    /**     * A variation on findClosestTest, manages select() and deselect().     *      * @param current the OMDist that contains the current best result of a     *        search.     * @param index the index in the graphic list of the provied OMGeometry     * @param graphic the OMGeometry to test     * @param x the window horiontal pixel value.     * @param y the window vertical pixel value.     * @return OMDist if the graphic passed in is the current closest.     *         OMGeometry will be set in OMDist and selected(). OMGeometry will     *         be deselected if not the closest, and the OMDist will be null.     *         This method will return this list if it is set to be vague and     *         one of its children meet the criteria.     */    protected OMDist selectClosestTest(OMDist current, int index,                                       OMGeometry graphic, int x, int y,                                       float limit) {        if (current == null) {            current = new OMDist();        }        OMGeometry oldGraphic = current.omg;        OMDist ret = findClosestTest(current, index, graphic, x, y, limit, true);        // Test for the OMDist still holding the same OMGraphicList,        // which will be the case if this list is vague. The distance        // will be updated, though.        if (ret != null && oldGraphic != ret.omg) {            if (oldGraphic != null) {                oldGraphic.deselect();            }            ret.omg.select();        }        return ret;    }    /**     * If you call select() on an OMGraphicList, it selects all the graphics it     * contains. This is really an OMGraphic method, but it makes OMGraphicLists     * embedded in other OMGraphicLists act correctly.     */    public void select() {        selectAll();        super.select();    }    /**     * Finds the first OMGraphic (the one on top) that is under this pixel.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @return the graphic that contains the pixel, NONE (null) if none are     *         found.     */    public OMGraphic getOMGraphicThatContains(int x, int y) {        return (OMGraphic) _getContains(x, y);    }    /**     * Finds the first OMGeometry (the one on top) that is under this pixel. If     * an OMGeometry is an OMGraphicList, its contents will be checked. If that     * check is successful and OMGraphicList is not vague, its OMGeometry will     * be returned - otherwise the list will be returned.     *      * @param x the horizontal pixel position of the window, from the left of     *        the window.     * @param y the vertical pixel position of the window, from the top of the     *        window.     * @return the graphic that contains the pixel, NONE (null) if none are

⌨️ 快捷键说明

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