Search in sources :

Example 1 with TextStyle

use of com.revolsys.swing.map.layer.record.style.TextStyle in project com.revolsys.open by revolsys.

the class ArcGisRestServerRecordLayer method addTextRenderer.

private void addTextRenderer(final AbstractMultipleRenderer renderers, final MapEx labelProperties) {
    final TextStyle textStyle = new TextStyle();
    final String alignment = labelProperties.getString("labelPlacement");
    if (alignment.endsWith("Left")) {
        textStyle.setTextHorizontalAlignment("right");
    } else if (alignment.endsWith("Right")) {
        textStyle.setTextHorizontalAlignment("left");
    } else if (alignment.endsWith("Before")) {
        textStyle.setTextHorizontalAlignment("right");
        textStyle.setTextPlacementType("vertex(0)");
    } else if (alignment.endsWith("Start")) {
        textStyle.setTextHorizontalAlignment("left");
        textStyle.setTextPlacementType("vertex(0)");
    } else if (alignment.endsWith("After")) {
        textStyle.setTextHorizontalAlignment("left");
        textStyle.setTextPlacementType("vertex(n)");
    } else if (alignment.endsWith("End")) {
        textStyle.setTextHorizontalAlignment("right");
        textStyle.setTextPlacementType("vertex(n)");
    } else if (alignment.endsWith("Along")) {
        textStyle.setTextHorizontalAlignment("center");
        textStyle.setTextPlacementType("auto");
    } else {
        textStyle.setTextHorizontalAlignment("center");
    }
    if (alignment.contains("Above")) {
        textStyle.setTextVerticalAlignment("bottom");
    } else if (alignment.endsWith("Below")) {
        textStyle.setTextVerticalAlignment("top");
    } else {
        textStyle.setTextVerticalAlignment("center");
    }
    String textName = labelProperties.getString("labelExpression");
    textName = textName.replace(" CONCAT ", "");
    textName = textName.replaceAll("\"([^\"]+)\"", "$1");
    textStyle.setTextName(textName);
    final MapEx symbol = labelProperties.getValue("symbol");
    if ("esriTS".equals(symbol.getString("type"))) {
        final Color textFill = getColor(symbol);
        textStyle.setTextFill(textFill);
        final Color backgroundColor = getColor(symbol, "backgroundColor");
        textStyle.setTextBoxColor(backgroundColor);
        // "useCodedValues": false,
        // "borderLineColor": null,
        // "verticalAlignment": "bottom",
        // "horizontalAlignment": "left",
        // "rightToLeft": false,
        // "kerning": true,
        final double angle = symbol.getDouble("angle", 0);
        textStyle.setTextOrientation(angle);
        final Quantity<Length> textDx = Quantities.getQuantity(symbol.getDouble("xoffset", 0), CustomUnits.PIXEL);
        textStyle.setTextDx(textDx);
        final Quantity<Length> textDy = Quantities.getQuantity(symbol.getDouble("yoffset", 0), CustomUnits.PIXEL);
        textStyle.setTextDx(textDy);
        final MapEx font = symbol.getValue("font");
        if (font != null) {
            final String faceName = font.getString("family", "Arial");
            textStyle.setTextFaceName(faceName);
            final Quantity<Length> size = Quantities.getQuantity(font.getDouble("size", 10), CustomUnits.PIXEL);
            textStyle.setTextSize(size);
        }
    // "font": {
    // "style": "normal",
    // "weight": "bold",
    // "decoration": "none"
    }
    final TextStyleRenderer textRenderer = new TextStyleRenderer(this, textStyle);
    textRenderer.setName(textName.replace("[", "").replace("]", ""));
    long minimumScale = labelProperties.getLong("minScale", Long.MAX_VALUE);
    if (minimumScale == 0) {
        minimumScale = Long.MAX_VALUE;
    }
    textRenderer.setMinimumScale(minimumScale);
    final long maximumScale = labelProperties.getLong("maxScale", 0);
    textRenderer.setMaximumScale(maximumScale);
    final String where = labelProperties.getString("where");
    textRenderer.setQueryFilter(where);
    renderers.addRenderer(textRenderer);
}
Also used : TextStyle(com.revolsys.swing.map.layer.record.style.TextStyle) MapEx(com.revolsys.collection.map.MapEx) Length(javax.measure.quantity.Length) Color(java.awt.Color) TextStyleRenderer(com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer)

Example 2 with TextStyle

use of com.revolsys.swing.map.layer.record.style.TextStyle in project com.revolsys.open by revolsys.

the class MeasureOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    if (!this.measureGeometry.isEmpty()) {
        final GeometryFactory geometryFactory = getGeometryFactory2d();
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            MEASURE_RENDERER.paintSelected(viewport, graphics, geometryFactory, this.measureGeometry);
            if (this.measureGeometry instanceof Polygon) {
                final Polygon polygon = (Polygon) this.measureGeometry;
                GeometryStyleRenderer.renderPolygon(viewport, graphics, polygon, POLYGON_STYLE);
            }
        }
        if (!(this.measureGeometry instanceof Punctual)) {
            final TextStyle measureTextStyle = new TextStyle();
            measureTextStyle.setTextBoxColor(WebColors.Violet);
            measureTextStyle.setTextSize(Quantities.getQuantity(14, CustomUnits.PIXEL));
            measureTextStyle.setTextFaceName(Font.MONOSPACED);
            Point textPoint;
            measureTextStyle.setTextHorizontalAlignment("right");
            if (this.measureDataType == DataTypes.POLYGON && this.measureGeometry instanceof Polygon) {
                measureTextStyle.setTextDx(Quantities.getQuantity(-5, CustomUnits.PIXEL));
                measureTextStyle.setTextPlacementType("vertex(n-1)");
                measureTextStyle.setTextVerticalAlignment("middle");
                textPoint = this.measureGeometry.getToVertex(0, 1);
            } else {
                measureTextStyle.setTextDx(Quantities.getQuantity(-7, CustomUnits.PIXEL));
                measureTextStyle.setTextDy(Quantities.getQuantity(-2, CustomUnits.PIXEL));
                measureTextStyle.setTextPlacementType("vertex(n)");
                measureTextStyle.setTextVerticalAlignment("top");
                textPoint = this.measureGeometry.getToVertex(0);
            }
            TextStyleRenderer.renderText(viewport, graphics, this.measureLabel, textPoint, measureTextStyle);
        }
    }
    drawXorGeometry(graphics);
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Punctual(com.revolsys.geometry.model.Punctual) TextStyle(com.revolsys.swing.map.layer.record.style.TextStyle) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Aggregations

TextStyle (com.revolsys.swing.map.layer.record.style.TextStyle)2 MapEx (com.revolsys.collection.map.MapEx)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 Polygon (com.revolsys.geometry.model.Polygon)1 Punctual (com.revolsys.geometry.model.Punctual)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 TextStyleRenderer (com.revolsys.swing.map.layer.record.renderer.TextStyleRenderer)1 Color (java.awt.Color)1 Length (javax.measure.quantity.Length)1