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

📄 omtext.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * Set the y location. Applies to XY and OFFSET text objects.     *      * @param newY the vertical pixel location of the window to place the     *        string.     */    public void setY(int newY) {        if (point == null && getRenderType() == RENDERTYPE_LATLON) {            point = new Point();            setRenderType(RENDERTYPE_OFFSET);        }        point.y = newY;        setNeedToRegenerate(true);    }    /**     * Get the latitude location of the string. Applies to LATLON and OFFSET     * text objects.     *      * @return the latitude, in decimal degrees.     */    public float getLat() {        return lat;    }    /**     * Set the latitude. Applies to LATLON and OFFSET text objects.     *      * @param l latitude for new location, in decimal degrees.     */    public void setLat(float l) {        lat = l;        setNeedToRegenerate(true);    }    /**     * Return the longitude. Applies to LATLON and OFFSET text objects.     *      * @return the longitude location of the string, in decimal degrees.     */    public float getLon() {        return lon;    }    /**     * Set the longitude. Applies to LATLON and OFFSET text objects.     *      * @param l the longitude location for the string, in decimal degrees.     */    public void setLon(float l) {        lon = l;        setNeedToRegenerate(true);    }    /**     * Not for the faint hearted. Used by the DeclutterMatrix to replace text on     * the map after it has been projected. This method lets the declutter     * matrix find out where the text should go.     *      * @return Point on the map where the text has been projected to go.     */    public Point getMapLocation() {        return pt;    }    /**     * Not for the faint hearted. Used by the DeclutterMatrix to replace text on     * the map after it has been projected. This method lets the declutter     * matrix put the text in an uncluttered place.     *      * @param point the point on the map where the text being placed.     */    public void setMapLocation(Point point) {        pt = point;        polyBounds = null;    }    /**     * Returns the color used to matte the actuall text of this class.     *      * @return the text matte color, null if not used     */    public Color getTextMatteColor() {        return textMatteColor;    }    /**     * Sets the color used to paint the outline of the characters in this text.     * The thickness of the outline is decided by the textMatteStroke. If the     * color is null, the outline will not be painted.     *      * The default value is null.     *      * @param textMatteColor     */    public void setTextMatteColor(Color textMatteColor) {        this.textMatteColor = textMatteColor;    }    /**     * Returns the stroke used to paint the outline of the characters in this     * text.     *      * @return the stroke used to paint the outline     */    public Stroke getTextMatteStroke() {        return textMatteStroke;    }    /**     * Sets the stroke used to paint the outline of the characters in this text     * For best effect the stroke thickness should be larger than 1 and it     * should be continuous.     *      * The default thickness is 2.     *      * @param textMatteStroke the new stroke     */    public void setTextMatteStroke(Stroke textMatteStroke) {        this.textMatteStroke = textMatteStroke;    }    /**     * Return the string.     *      * @return the string     */    public java.lang.String getData() {        return data;    }    /**     * Sets the string contents that are presented. Flushes the cache fields     * <code>parsedData</code>,<code>widths</code>, and     * <code>polyBounds</code>. HACK synchronized so that it doesn't     * interfere with other methods that are using parsedData.     *      * @param d the text to be displayed     *      * @see #parsedData     * @see #widths     * @see #polyBounds     */    public synchronized void setData(java.lang.String d) {        data = d;        // now flush the cached information about the old text        parsedData = null; // flush existing parsed line table.        widths = null; // flush existing width table.        polyBounds = null; // flush existing bounds.    }    /**     * Gets the justification of this OMText.     *      * @return one of JUSTIFY_LEFT, JUSTIFY_CENTER, JUSTIFY_RIGHT     */    public int getJustify() {        return justify;    }    /**     * Sets the justification of this OMText. Flushes the cache fields     * <code>fm</code>,<code>widths</code>, and <code>polyBounds</code>.     *      * @param j one of JUSTIFY_LEFT, JUSTIFY_CENTER, JUSTIFY_RIGHT     * @see #polyBounds     */    public void setJustify(int j) {        justify = j;        // now flush cached information        polyBounds = null; // flush existing bounds.    }    /**     * Gets the baseline location of this OMText.     *      * @return one of BASELINE_BOTTOM, BASELINE_MIDDLE or BASELINE_TOP.     */    public int getBaseline() {        return baseline;    }    /**     * Sets the location of the baseline of this OMText. Flushes the cache     * fields <code>fm</code>,<code>widths</code>, and     * <code>polyBounds</code>.     *      * @param b one of BASELINE_BOTTOM, BASELINE_MIDDLE or BASELINE_TOP.     * @see #polyBounds     */    public void setBaseline(int b) {        baseline = b;        // now flush cached information        polyBounds = null; // flush existing bounds.    }    /**     * Gets the show bounds field.     *      * @deprecated use isMatted() instead.     * @return true if bounds are shown, false if hidden.     */    public boolean getShowBounds() {        return isMatted();    }    /**     * Sets the show bounds field. When <code>true</code>, the bounding box     * of this text is displayed.     *      * @deprecated use setMatted(boolean) instead.     * @param show true to show, false to hide.     * @see #setFillColor     */    public void setShowBounds(boolean show) {        setMatted(show);    }    /**     * Set flag to specify that the bounds, if displayed, should be rectangular.     * Only really affects mult-line text.     *      * @param value if true, bounds for multi-line text will be retangular     *        instead of closely following text.     */    public void setUseMaxWidthForBounds(boolean value) {        useMaxWidthForBounds = value;    }    /**     * Get flag to specify that the bounds, if displayed, should be rectangular.     * Only really affects mult-line text.     *      * @return true if bounds for multi-line text will be retangular instead of     *         closely following text.     */    public boolean getUseMaxWidthForBounds() {        return useMaxWidthForBounds;    }    /**     * Get the text bounds.     *      * @return Polygon or null if bounds not calculated yet     */    public Polygon getPolyBounds() {        if (polyBounds == null) {            computeBounds();        }        return polyBounds;    }    /**     * Set the fmHeight to use for the footprint.     *      * @param fmh the setting for fmHeight, out of the parameters stated above.     */    public void setFMHeight(int fmh) {        fmHeight = fmh;    }    /**     * Get the fmHeight used for the footprint.     *      * @return the setting for fmHeight, out of the parameters stated above.     */    public int getFMHeight() {        return fmHeight;    }    /**     * Set the angle by which the text is to rotated.     *      * @param theta the number of radians the text is to be rotated. Measured     *        clockwise from horizontal.     * @deprecated use setRotationAngle instead.     */    public void setTheta(double theta) {        setRotationAngle(theta);        setNeedToRegenerate(true);    }    /**     * Get the current rotation of the text.     *      * @return the text rotation.     * @deprecated use getRotationAngle instead.     */    public double getTheta() {        return getRotationAngle();    }    /**     * Set the angle by which the text is to rotated.     *      * @param angle the number of radians the text is to be rotated. Measured     *        clockwise from horizontal. Positive numbers move the positive x     *        axis toward the positive y axis.     */    public void setRotationAngle(double angle) {        this.rotationAngle = angle;        setNeedToRegenerate(true);    }    /**     * Get the current rotation of the text.     *      * @return the text rotation.     */    public double getRotationAngle() {        return rotationAngle;    }    /**     * Prepares the text for rendering. Determines the location based on the     * renderType and possibly the projection. Sets the field <code>pt</code>.     * Flushes the cache field <code>polyBounds</code>.     *      * @param proj the projection of the window.     * @return true if the placement of the string on the window is valid.     *      * @see #pt     */    public synchronized boolean generate(Projection proj) {        // HACK synchronized because of various race conditions that        // need to        // be sorted out.        if (proj == null) {            Debug.message("omgraphic", "OMText: null projection in generate!");            return false;        }        // flush the cached information about the bounding box.        polyBounds = null;        // Although it most definately has bounds, OMText is        // considered a        // point object by the projection code. We need to check to        // make        // sure the point is plot-able: if not then don't display it.        // This        // might occur, for instance, if we're using the Orthographic        // and the        // point is on the other side of the world.        switch (renderType) {        case RENDERTYPE_XY:            pt = point;            break;        case RENDERTYPE_OFFSET:            if (!proj.isPlotable(lat, lon)) {                if (Debug.debugging("omgraphic"))                    System.err.println("OMText.generate(): offset point is not plotable!");                setNeedToRegenerate(true);// so we don't render it!                return false;            }            pt = proj.forward(lat, lon);            pt.translate(point.x, point.y);            break;        case RENDERTYPE_LATLON:            if (!proj.isPlotable(lat, lon)) {                if (Debug.debugging("omgraphic"))                    System.err.println("OMText.generate(): llpoint is not plotable!");                setNeedToRegenerate(true);// so we don't render it!                return false;            }            pt = proj.forward(lat, lon);            break;        case RENDERTYPE_UNKNOWN:            System.err.println("OMText.render.generate(): invalid RenderType");            return false;        }        setFont(proj.getScale());        // Compliance with Shape additions to OMGeometry/OMGraphic.        // If font metrics are set, we can take care of this now. If        // this is the first time this OMText is drawn, then we have        // to put this off until render. There will be a        // one-projection lag for font metrics to catch up with any        // change.        computeBounds();        setNeedToRegenerate(false);        return true;    }    protected Projection hackProj = null;    /**     * Build a font out of an X Font description string. This function take this     * common string format, and pulls the font type, style, and size out of it.     *      * @param fontString the X font description.     */    public static Font rebuildFont(String fontString) {        if (fontString.equals(""))            return DEFAULT_FONT;        int fontStyle = Font.PLAIN;        int fontSize = 12;        // Taking the X Font-type string and converting the        // essential parts to a java Font object.        int start = fontString.indexOf("-", 1) + 1; // skipping first        // field        int end = fontString.indexOf("-", start + 1);        String name = fontString.substring(start, end);        // System.out.println("rebuildFont: Name is " + name);        if (fontString.indexOf("-bold-") >= 0)            fontStyle = Font.BOLD;        if (fontString.indexOf("-i-") >= 0)            fontStyle += Font.ITALIC;        // System.out.println("rebuildFont: Style is " + fontStyle);        start = fontString.indexOf("--") + 2;        end = fontString.indexOf("-", start + 1);        String tmpFontSize = fontString.substring(start, end);        if (tmpFontSize.indexOf("*") < 0)            fontSize = Integer.parseInt(tmpFontSize);        // System.out.println("rebuildFont: Size is " + fontSize);        return new Font(name, fontStyle, fontSize);    }    /**     * In some applications, fonts are represented by a string. Traditionally,     * with MATT, the font was a X representation of a font. That's what is     * being done here - we're taking the Font structure, and then going to     * XFont type text structure. Dashes need to be included, line feeds are     * not. They are here only for readability. The rebuildFont method brings     * this back to a java Font.     *      * @param font the Java font to convert to an XFont string.     * @return the font as a string.     */    public static String fontToXFont(java.awt.Font font) {        // -foundry(who made it)        StringBuffer ret = new StringBuffer("-*");        // -font family(name)        ret.append("-" + font.getName());        // -weight(bold, medium)        if (font.isBold())            ret.append("-bold");        else            ret.append("-normal");        // -slant(o,i)        if (font.isItalic())            ret.append("-i");        else            ret.append("-o");        // -set width(normal, condensed, narrow, double width)        ret.append("-normal");        // --pixels(height)        ret.append("--" + font.getSize());        // -points(in tenths of a point, related to screen)        ret.append("-*");        // -horizontal resolution in dpi        ret.append("-*");        // -vertical resolution in dpi        ret.append("-*");        // -spacing(m-monospace or p-proportional)

⌨️ 快捷键说明

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