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

📄 decluttermatrix.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************// // <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/DeclutterMatrix.java,v $// $RCSfile: DeclutterMatrix.java,v $// $Revision: 1.4.2.1 $// $Date: 2004/10/14 18:27:01 $// $Author: dietrick $// // **********************************************************************/* * ********************************************************************** *  *  A port to Java/Openmap of the MATT decluttering code. * *  Created on: Thu Aug 19 14:55:41 1999 * ********************************************************************** * *  Modification history: *  $Log: DeclutterMatrix.java,v $ *  Revision 1.4.2.1  2004/10/14 18:27:01  dietrick *  Copyright updates, removed extemporaneous import statements, cleaned up deprecations * *  Revision 1.5  2004/10/14 18:05:52  dietrick *  Copyright updates, removed extemporaneous import statements, cleaned up deprecations * *  Revision 1.4  2004/02/06 19:06:20  dietrick *  Fixed harmless lines in DeclutterMatrix, modified DemoLayer to create OMEllipse objects instead of hacking them up, added FullProjectionRenderPolicy which forces clipping area for layers to match the projection, and made RpfLayer call the RenderPolicy * *  Revision 1.3  2004/01/26 18:18:08  dietrick *  Untabified * *  Revision 1.2  2003/12/23 20:43:25  wjeuerle *  no code changes, updated javadoc comments to fix javadoc warnings * *  Revision 1.1  2003/02/14 21:35:48  dietrick *  Initial revision * *  Revision 1.14  2002/04/02 20:59:41  bmackiew *  Updated with revised copyright information. * *  Revision 1.13  2000/06/21 22:40:29  dietrick *  Fixed the runoff of some partial words on the right side when partials weren't allowed. * *  Added a main to RpfFrame to print out information about the frame file. * *  Added a string converter to Location.java to translate N340000 to 34.000, etc. * *  Revision 1.12  2000/05/08 14:22:19  wjeuerle *  BBNT Solutions LLC in copyright headers *  include Y2K in copyright years * *  Revision 1.11  2000/01/21 03:44:08  dietrick *  Added the capability to set whether you want to allow objects to be *  straddling the edge of the map. * *  Revision 1.10  1999/12/03 18:35:52  dietrick *  Changing System.out and System.error to Debug.output and Debug.error. * *  Revision 1.9  1999/12/02 21:07:35  dietrick *  Comments and tweaks. * *  Revision 1.8  1999/11/30 22:43:17  dietrick *  Updates and revamping. * *  Revision 1.7  1999/10/07 22:15:45  dietrick *  Took out the reset function I added, because it's unnecessary. * *  Revision 1.6  1999/10/07 16:08:51  dietrick *  Added a static getGraphics() call, which returns a fake graphics to *  use to figure out the demensions of font metrics at projection time, *  as opposed to render time. * *  Revision 1.5  1999/10/05 17:33:50  gkeith *  Cleaned up a bit, but not fully documented yet. *  Stay tuned... * *  Revision 1.4  1999/09/10 17:54:17  pmanghwa *  Removed unnecessary checks * *  Revision 1.3  1999/09/08 20:08:40  pmanghwa *  added methods to handle height. *  Slow but good looking * *  Revision 1.2  1999/09/07 21:26:43  pmanghwa *  Now its Readable * *  Revision 1.1  1999/08/24 19:02:35  gkeith *  JAVA-port of the old MATT decluttering code. * * **********************************************************************/package com.bbn.openmap.layer;import java.awt.*;import java.awt.image.*;import java.awt.Point;import com.bbn.openmap.util.Debug;/** * This class represents the screen divided up into sections, and * tracks the sections that are marked, for any reason. The * pix_intervals are the height and width of the sections. isClear() * returns 1 if the space is clear, and setTaken returns true if the * space was clear and the space is now marked taken. */public class DeclutterMatrix {    /**     * The height of the screen to be covered by the matrix, in     * pixels. The number of vertical matrix cell is the     * height/y_pix_interval.     */    protected int height = 0;    /**     * The width of the screen to be covered by the matrix, in pixels.     * The number of horizontal matrix cell is the     * width/x_pix_interval.     */    protected int width = 0;    /** The number of horizontal pixels per matrix cell */    protected int x_pix_interval = 1;    /** The number of vertical pixels per matrix cell */    protected int y_pix_interval = 1;    /** The matrix itself, width x height. */    protected boolean[][] matrix = new boolean[0][0];    /**     * The maximum index for the horizontal locations within the     * matrix.     */    protected int maxx;    /**     * The maximum index for the vertical locations within the matrix.     */    protected int maxy;    /**     * Whether or not objects are allowed to appear partially off the     * matrix. If true, cells off the matrix will be automatically     * counted as clear. The default is true.     */    protected boolean allowPartials = true;    /**     * A set of matrix indexes that get set for a particular object     * for a search. This is to limit the number of off matrix indexes     * used.     */    protected MatrixIndexes indexes = new MatrixIndexes();    /**     * A flag to force a recreation of the matrix if the dimensions     * change.     */    protected boolean needToRecreate = false;    /*     * These are all magic numbers that don't need to be anything in     * particular, apart from sequential. They are used to calculate     * where to next search for an opening in the matrix. The order     * reflects the pattern in which openings are searched for from     * the original position. In general, the original position is     * checked, and then alternatives are sought, checking the areas     * around the original in a search pattern. The search pattern is     * continued, but the distance from the original location is     * increased until a clear position is/is not found. As stated in     * the setNextOpen comments, the search pattern is a square, but     * the order of these notations let you control which     * sides/corners of the square are looked at first, in terms of     * finding an open space. The square expands outward until a place     * is found, or until no place is found, given some desired limit.     */    public final static int DCP_MIDDLE = 20875;    public final static int DCP_EAST = 20876;    public final static int DCP_NORTH = 20877;    public final static int DCP_SOUTH = 20878;    public final static int DCP_WEST = 20879;    public final static int DCP_NEAST = 20880;    public final static int DCP_SEAST = 20881;    public final static int DCP_SWEST = 20882;    public final static int DCP_NWEST = 20883;    /*     * The Declutter direction variables are general notations for the     * declutter positions. Within the search square, some positions,     * like along the side, present an opportunity to check in     * different places - for instance, if we are on the top part of     * the square, the search must travers East to West, hence, the     * direction is noted as DCD_EW. Corners have no search direction,     * and the left and right sides have North-South search traversal     * directions.     */    public final static int DCD_NS = 20884;    public final static int DCD_EW = 20885;    public final static int DCD_NONE = 20886;    /**     * This Denotes the parameters of one of the 8 possible positions     * around a decluttermatrix tile.     */    public static class PositionParameters {        public int position; // should be one of the DCP variables        public int ewindex;        public int nsindex;        public int direction; // should be one of the DCD_ variables        public PositionParameters(int pos, int ewindx, int nsindx, int direc) {            position = pos;            ewindex = ewindx;            nsindex = nsindx;            direction = direc;        }    }    /**     * This is an ordering of the possible positions around a matrix     * tile.     */    public final static PositionParameters dcPos[] = new PositionParameters[9];    static { // Now initialize it.        dcPos[0] = new PositionParameters(DCP_EAST, 1, 0, DCD_NS);        dcPos[1] = new PositionParameters(DCP_NORTH, 0, -1, DCD_EW);        dcPos[2] = new PositionParameters(DCP_SOUTH, 0, 1, DCD_EW);        dcPos[3] = new PositionParameters(DCP_WEST, -1, 0, DCD_NS);        dcPos[4] = new PositionParameters(DCP_NEAST, 1, -1, DCD_NONE);        dcPos[5] = new PositionParameters(DCP_SEAST, 1, 1, DCD_NONE);        dcPos[6] = new PositionParameters(DCP_SWEST, -1, 1, DCD_NONE);        dcPos[7] = new PositionParameters(DCP_NWEST, -1, -1, DCD_NONE);        dcPos[8] = new PositionParameters(DCP_MIDDLE, 0, 0, DCD_NONE);    }    public class MatrixIndexes {        public boolean withinMatrix = false;        public boolean partial = false;        public int xStart = 0;        public int yStart = 0;        public int xEnd = 0;        public int yEnd = 0;        public int origXIndex = -1;        public int origYIndex = -1;        public int origIndexLength = 1;        public int origIndexHeight = 1;        public MatrixIndexes() {}        public boolean setFromPixels(int pixelXLocation, int pixelYLocation,                                     int pixelLength, int pixelHeight) {            int objXIndex = pixelXLocation / x_pix_interval;            int objYIndex = pixelYLocation / y_pix_interval;            int objLength = (int) Math.ceil((double) pixelLength                    / (double) x_pix_interval);            int objHeight = (int) Math.ceil((double) pixelHeight                    / (double) y_pix_interval);            return set(objXIndex, objYIndex, objLength, objHeight);        }        public boolean setFromPixels(int pixelXLocation, int pixelYLocation) {            int objXIndex = pixelXLocation / x_pix_interval;            int objYIndex = pixelYLocation / y_pix_interval;            return set(objXIndex, objYIndex, origIndexLength, origIndexHeight);        }        public boolean set(int objXIndex, int objYIndex) {            return set(objXIndex, objYIndex, origIndexLength, origIndexHeight);        }        public boolean set(int objXIndex, int objYIndex, int objIndexLength,                           int objIndexHeight) {            // Save as reference            origXIndex = objXIndex;            origYIndex = objYIndex;            // This may be redundant, but so what. It's too hard to            // tell...            origIndexLength = objIndexLength;            origIndexHeight = objIndexHeight;            withinMatrix = objOnMatrix(objXIndex,                    objYIndex,                    objIndexLength,                    objIndexHeight);            if (!withinMatrix) {                return false;            }            // End variables refer to an end index            partial = false;            // Set the end of the check - if the end sticks out past            // the            // matrix, just check the part that's on the matrix. If            // it's            // left of the matrix, don't bother going into the loop by            // setting the end point to 0.            if ((objXIndex + objIndexLength) <= maxx) {                xEnd = objXIndex + objIndexLength;            } else {                xEnd = maxx;                partial = true;            }            if (xEnd < 0)                xEnd = 0;            // Now do the vertical version of the same thing...            if ((objYIndex + objIndexHeight) <= maxy) {                yEnd = objYIndex + objIndexHeight;            } else {                yEnd = maxy;                partial = true;            }            if (yEnd < 0)                yEnd = 0;            // And, figure out what the good starting index point is            // to            // check for vertical conflicts - This is all to make the            // checkMatrixLocation methods run as efficiently as            // possible.            if (objYIndex >= 0) {                yStart = objYIndex;            } else {                objYIndex = 0;                partial = true;            }            // And horizontal starting index            if (objXIndex >= 0) {                xStart = objXIndex;            } else {                xStart = 0;                partial = true;

⌨️ 快捷键说明

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