linkproperties.java

来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 454 行 · 第 1/2 页

JAVA
454
字号
        }    }    /**     * New, static method for more efficient property handling.     *      * @param dis     * @param props     * @return if there are no properties, the EMPTY_PROPERTIES object is     *         returned. If there are properties and props == null, then a new     *         LinkProperties object is allocated and returned, otherwise, props     *         is returned.     * @throws IOException     */    public static LinkProperties read(DataInput dis, LinkProperties props)            throws IOException {        int numArgs = dis.readInt();        if (numArgs == 0) {            return EMPTY_PROPERTIES;        }        if (props == null) {            props = new LinkProperties();        }        props.readArgs(numArgs, dis);        return props;    }    /**     * New, static method for more efficient property handling and loading the     * properties into the OMGraphic.     *      * @param dis     * @param omg     * @return if there are no properties, the EMPTY_PROPERTIES object is     *         returned. If there are properties and props == null, then a new     *         LinkProperties object is allocated and returned, otherwise, props     *         is returned. The OMGraphic appObject is set with the read     *         properties.     */    public static LinkProperties loadPropertiesIntoOMGraphic(                                                             DataInput dis,                                                             OMGraphic omg,                                                             LinkProperties propertiesBuffer)            throws IOException {        LinkProperties readProperties = (LinkProperties) read(dis,                propertiesBuffer).clone();        readProperties.setProperties(omg); // load them into OMGraphic..        return readProperties;    }    /**     * Method to call on the LinkProperties object to set the DrawingAttributes     * properties on an OMGraphic. Will set the line and select colors, fill     * paints (including patterns) and stroke based on the properties contained     * in this LinkProperties object. Will set default values in the OMGraphic     * if the applicable properties aren't defined, and will set the     * LinkProperties in the AppObject of the OMGraphic.     */    public void setProperties(OMGraphic omg) {        if (omg == null)            return;        omg.setLinePaint(getPaint(LPC_LINECOLOR, BLACK_COLOR_STRING));        omg.setFillPaint(getFillPaint());        omg.setSelectPaint(getPaint(LPC_HIGHLIGHTCOLOR, BLACK_COLOR_STRING));        omg.setStroke(getStroke());        if (this != EMPTY_PROPERTIES) {            omg.setAppObject(this);        }    }    protected Hashtable renderAttributesCache = new Hashtable();    public Stroke getStroke() {        int lineWidth = PropUtils.intFromProperties(this, LPC_LINEWIDTH, 1);        String strokeString = getProperty(LPC_LINESTYLE);        int cap = BasicStroke.CAP_SQUARE;        int join = BasicStroke.JOIN_MITER;        float miterLimit = 10f;        float dashPhase = 0f;        Stroke stroke = null;        float[] dash = null;        String strokeCode = "stroke" + lineWidth + strokeString;        stroke = (Stroke) renderAttributesCache.get(strokeCode);        if (stroke != null) {            return stroke;        }        if (strokeString != null) {            if (strokeString.equalsIgnoreCase(LPC_LONG_DASH)) {                dash = new float[] { 10f, 10f };            } else if (strokeString.equalsIgnoreCase(LPC_DASH)) {                dash = new float[] { 6f, 6f };            } else if (strokeString.equalsIgnoreCase(LPC_DOT)) {                dash = new float[] { 3f, 6f };            } else if (strokeString.equalsIgnoreCase(LPC_DASH_DOT)) {                dash = new float[] { 6f, 6f, 3f, 6f };            } else if (strokeString.equalsIgnoreCase(LPC_DASH_DOT_DOT)) {                dash = new float[] { 6f, 6f, 3f, 6f, 3f, 6f };            }            if (dash != null) {                stroke = new BasicStroke(lineWidth, cap, join, miterLimit, dash, dashPhase);            }        }        if (stroke == null) {            stroke = new BasicStroke(lineWidth);        }        renderAttributesCache.put(strokeCode, stroke);        return stroke;    }    public Paint getPaint(String paintProperty, String defaultPaintString) {        Paint paint = null;        String paintKey = "paint" + getProperty(paintProperty);        if (paintProperty != null) {            paint = (Paint) renderAttributesCache.get(paintKey);            if (paint == null) {                paint = (Paint) renderAttributesCache.get("paint"                        + defaultPaintString);            }            if (paint != null) {                return paint;            }        }        paint = ColorFactory.parseColorFromProperties(this,                paintProperty,                defaultPaintString,                true);        renderAttributesCache.put(paintKey, paint);        return paint;    }    public Paint getFillPaint() {        Paint fillPaint = getPaint(LPC_FILLCOLOR, CLEAR_COLOR_STRING);        String fillPatternString = getProperty(LPC_FILLPATTERN);        if (fillPatternString == null                || fillPatternString.equalsIgnoreCase(LPC_SOLID_PATTERN)) {            return fillPaint;        } else {            String fillPaintString = getProperty(LPC_FILLCOLOR);            String texturePaintKey = "fill" + fillPaintString + fillPatternString;            if (fillPaintString == null) {                fillPaint = Color.black;                TexturePaint ret = (TexturePaint) renderAttributesCache.get("fill" + fillPaint + fillPatternString);                if (ret != null) {                    return ret;                } else {                    ret = (TexturePaint) renderAttributesCache.get(texturePaintKey);                    if (ret != null) {                        return ret;                    }                }            }            BufferedImage bi = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB);            Graphics2D big = bi.createGraphics();            big.setColor(new Color(0, true)); // clear            big.fillRect(0, 0, 8, 8);            big.setPaint(fillPaint);            if (fillPatternString.equalsIgnoreCase(LPC_HORIZONTAL_PATTERN)) {                big.draw(new Line2D.Double(0, 0, 7, 0));                big.draw(new Line2D.Double(0, 4, 7, 4));            } else if (fillPatternString.equalsIgnoreCase(LPC_VERTICAL_PATTERN)) {                big.draw(new Line2D.Double(0, 0, 0, 7));                big.draw(new Line2D.Double(4, 0, 4, 7));            } else if (fillPatternString.equalsIgnoreCase(LPC_CROSS_PATTERN)) {                big.draw(new Line2D.Double(0, 0, 7, 0));                big.draw(new Line2D.Double(0, 4, 7, 4));                big.draw(new Line2D.Double(0, 0, 0, 7));                big.draw(new Line2D.Double(4, 0, 4, 7));            } else if (fillPatternString.equalsIgnoreCase(LPC_DIAG_CROSS_PATTERN)) {                big.draw(new Line2D.Double(0, 0, 7, 7));                big.draw(new Line2D.Double(0, 4, 3, 7));                big.draw(new Line2D.Double(4, 0, 7, 3));                big.draw(new Line2D.Double(0, 7, 7, 0));                big.draw(new Line2D.Double(0, 3, 3, 0));                big.draw(new Line2D.Double(4, 7, 7, 4));            } else if (fillPatternString.equalsIgnoreCase(LPC_BACKWARD_DIAG_PATTERN)) {                big.draw(new Line2D.Double(0, 0, 7, 7));                big.draw(new Line2D.Double(0, 4, 3, 7));                big.draw(new Line2D.Double(4, 0, 7, 3));            } else if (fillPatternString.equalsIgnoreCase(LPC_FORWARD_DIAG_PATTERN)) {                big.draw(new Line2D.Double(0, 7, 7, 0));                big.draw(new Line2D.Double(0, 3, 3, 0));                big.draw(new Line2D.Double(4, 7, 7, 4));            } else {                // default to solid                big.fillRect(0, 0, 8, 8);            }            Rectangle r = new Rectangle(0, 0, 8, 8);            TexturePaint texturePaint = new TexturePaint(bi, r);            renderAttributesCache.put(texturePaintKey, texturePaint);            return texturePaint;        }    }}

⌨️ 快捷键说明

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