org.geotools.styling.StyleBuilder Java Examples

The following examples show how to use org.geotools.styling.StyleBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphicViewer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * TODO summary sentence for createControl ...
 *
 * @param parent
 * @param klisten
 * @param build
 * @return Generated composite
 */
public Composite createControl(final Composite parent, final KeyListener klisten, final StyleBuilder build) {
	final Composite part = SimpleConfigurator.subpart(parent, "Point");

	this.on = new Button(part, SWT.CHECK);

	this.size = new Combo(part, SWT.DROP_DOWN);
	this.size.setItems(new String[] { "1", "2", "3", "5", "10", "15" });
	this.size.setTextLimit(2);
	this.size.addKeyListener(klisten);
	this.size.setToolTipText("Graphic size");

	this.name = new Combo(part, SWT.DROP_DOWN);
	this.name.setItems(build.getWellKnownMarkNames());
	this.name.setTextLimit(9);
	this.name.addKeyListener(klisten);
	this.name.setToolTipText("Shape type");
	return part;
}
 
Example #2
Source File: FieldConfigFilenameTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigFilename field =
            new FieldConfigFilename(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertTrue(field.accept(externalGraphic));

    Mark marker = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker));
}
 
Example #3
Source File: FieldConfigWindBarbsTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigWindBarbs field =
            new FieldConfigWindBarbs(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));

    Mark marker1 = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker1));

    Mark marker2 = styleBuilder.createMark("windbarbs://default(15)[kts]");
    assertTrue(field.accept(marker2));
}
 
Example #4
Source File: FieldConfigArrowTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigArrow field =
            new FieldConfigArrow(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();

    Mark marker1 = styleBuilder.createMark("star");
    assertFalse(field.accept(marker1));

    Mark marker2 = styleBuilder.createMark("extshape://arrow?hr=1.2&t=0.34&ab=0.56");
    assertTrue(field.accept(marker2));
}
 
Example #5
Source File: FieldConfigTTFTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.ttf.FieldConfigTTF#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigTTF field =
            new FieldConfigTTF(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));

    Mark marker1 = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker1));

    Mark marker2 = styleBuilder.createMark("ttf://Arial");
    assertTrue(field.accept(marker2));
}
 
Example #6
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#populateColourField(com.sldeditor.ui.detail.config.FieldId,
 * org.opengis.filter.expression.Expression, org.opengis.filter.expression.Expression)}.
 */
@Test
public void testColour() {

    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;

    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);

    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(Geometry.class, fieldId, "label", true, false));
    colourField.createUI();
    colourField.createUI();
    fieldConfigManager.add(fieldId, colourField);

    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);

    StyleBuilder styleBuilder = new StyleBuilder();
    Expression colour = styleBuilder.colorExpression(Color.red);

    obj.populateColourField(fieldId, colour);
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateColourField(wrongFieldEnum, colour);
}
 
Example #7
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#populateFontField(com.sldeditor.common.xml.ui.FieldIdEnum,
 * org.geotools.styling.Font)}.
 */
@Test
public void testFont() {

    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;

    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);

    FieldConfigFont fontField =
            new FieldConfigFont(
                    new FieldConfigCommonData(Geometry.class, fieldId, "label", true, false));
    fontField.createUI();
    fieldConfigManager.add(fieldId, fontField);

    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);

    StyleBuilder styleBuilder = new StyleBuilder();

    Font expectedValue = styleBuilder.createFont(java.awt.Font.decode(null));
    obj.populateFontField(fieldId, expectedValue);

    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateFontField(wrongFieldEnum, expectedValue);
}
 
Example #8
Source File: TextSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Constructor. */
public TextSymbolizerDetails() {
    super(TextSymbolizerDetails.class);

    // Cache the default point placement anchor point values
    StyleBuilder styleBuilder = new StyleBuilder();
    PointPlacement defaultPointPlacement = styleBuilder.createPointPlacement();
    defaultPointPlacementAnchorPointX =
            defaultPointPlacement.getAnchorPoint().getAnchorPointX();
    defaultPointPlacementAnchorPointY =
            defaultPointPlacement.getAnchorPoint().getAnchorPointY();

    createUI();
}
 
Example #9
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private ApplyingStyleVisitor() {
    StyleBuilder sb = new StyleBuilder();
    final double layerOpacity = 1.0 - getTransparency();
    polyFillExp = sb.literalExpression(polyFillOpacity * layerOpacity);
    polyStrokeExp = sb.literalExpression(polyStrokeOpacity * layerOpacity);
    textExp = sb.literalExpression(textOpacity * layerOpacity);
    defaultTextFill = sb.createFill(Color.BLACK, textOpacity * layerOpacity);
}
 
Example #10
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Execute
public void displayMaps() throws Exception {
    sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
    ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    sb = new StyleBuilder(sf, ff);

    final MapContent map = new MapContent();
    map.setTitle("Maps Viewer");

    addImageMosaic(map);

    addCoverages(map);

    addFeatureCollections(map);

    map.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);

    // Create a JMapFrame with a menu to choose the display style for the
    final JMapFrame frame = new JMapFrame(map);
    frame.setSize(1800, 1200);
    frame.enableStatusBar(true);
    frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET);
    frame.enableToolBar(true);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter(){
        public void windowClosing( WindowEvent e ) {
            frame.setVisible(false);
        }
    });

    while( frame.isVisible() ) {
        Thread.sleep(300);
    }
}
 
Example #11
Source File: GraphicViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setGraphic ...
 *
 * @param graphic
 * @param mode
 * @param enabled
 */
public void setGraphic(final Graphic g, final Mode mode, final Color defaultColor) {
	Graphic graphic = g;
	boolean enabled = true;
	if (graphic == null) {
		final StyleBuilder builder = new StyleBuilder();
		graphic = builder.createGraphic(null, builder.createMark(StyleBuilder.MARK_SQUARE, defaultColor), null);
		enabled = true;
	}
	this.width = SLDs.size(graphic);
	final String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
	if (text != null) {
		this.size.setText(text);
		this.size.select(this.size.indexOf(text));
	}

	boolean marked = false;
	if (graphic != null && graphic.graphicalSymbols() != null && !graphic.graphicalSymbols().isEmpty()) {

		for (final GraphicalSymbol symbol : graphic.graphicalSymbols()) {
			if (symbol instanceof Mark) {
				final Mark mark = (Mark) symbol;
				setMark(mark, mode);
				marked = true;
				break;
			}
		}
	}
	if (!marked) {
		setMark(null, mode);
	}
	this.enabled = this.enabled && enabled;
}
 
Example #12
Source File: StrokeViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setStroke ...
 *
 * @param line
 * @param mode
 * @param defaultColor
 */
public void setStroke(final Stroke aLine, final Mode mode, final Color defaultColor) {
	listen(false);
	try {
		boolean enabled = true;
		Stroke line = aLine;

		if (line == null) {
			final StyleBuilder builder = new StyleBuilder();
			line = builder.createStroke(defaultColor);
			enabled = false;
		}
		this.enabled = enabled && mode != Mode.NONE && line != null;
		this.color = SLD.color(line);
		this.width = SLD.width(line);
		this.opacity = SLD.opacity(line);

		// Stroke is used in line, point and polygon
		this.on.setEnabled(mode != Mode.NONE);
		this.chooser.setColor(this.color);

		String text = MessageFormat.format("{0,number,#0}", this.width); //$NON-NLS-1$
		this.size.setText(text);
		this.size.select(this.size.indexOf(text));

		text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
		this.percent.setText(text);
		this.percent.select(this.percent.indexOf(text));

		this.on.setSelection(this.enabled);
		this.chooser.setEnabled(this.enabled);
		this.size.setEnabled(this.enabled);
		this.percent.setEnabled(this.enabled);
	} finally {
		listen(true); // listen to user now
	}
}
 
Example #13
Source File: FillViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO summary sentence for setFill ...
 *
 * @param fill
 * @param mode
 * @param enabled
 */
public void setFill(final Fill fill2, final Mode mode, final Color defaultColor) {
	listen(false);
	try {

		boolean enabled = true;
		Fill fill = fill2;
		if (fill == null) {
			final StyleBuilder builder = new StyleBuilder();
			fill = builder.createFill(defaultColor, 0.5);
			enabled = false;
		}

		this.enabled = enabled && mode != Mode.NONE && mode != Mode.LINE && fill != null;
		this.color = SLD.color(fill);
		this.opacity = SLD.opacity(fill);

		// Fill is used in point and polygon
		this.on.setEnabled(mode != Mode.NONE && mode != Mode.LINE);
		this.chooser.setColor(this.color);

		final String text = MessageFormat.format("{0,number,#0%}", this.opacity); //$NON-NLS-1$
		this.percent.setText(text);
		this.percent.select(this.percent.indexOf(text));

		this.on.setSelection(this.enabled);
		this.chooser.setEnabled(this.enabled);
		this.percent.setEnabled(this.enabled);
	} finally {
		listen(true);
	}
}
 
Example #14
Source File: FieldConfigWKTTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigWKT field =
            new FieldConfigWKT(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));

    Mark marker1 = styleBuilder.createMark("star");
    assertFalse(field.accept(marker1));

    // CHECKSTYLE:OFF
    Mark marker2 =
            styleBuilder.createMark(
                    "wkt://MULTILINESTRING((-0.25 -0.25, -0.125 -0.25), (0.125 -0.25, 0.25 -0.25), (-0.25 0.25, -0.125 0.25), (0.125 0.25, 0.25 0.25))");
    // CHECKSTYLE:ON
    assertTrue(field.accept(marker2));
}
 
Example #15
Source File: FieldConfigFontTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#generateExpression()}. Test method for
 * {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#populateField(org.geotools.styling.Font)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#getFont()}. Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFont#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigFont field =
            new FieldConfigFont(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false));

    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateField((Font) null);
    field.populateExpression((Font) null);

    String expectedValue = fontFamilies[0];
    field.createUI();
    field.populateField(expectedValue);
    String actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);

    field.populateExpression(Integer.valueOf(1));
    field.populateExpression(expectedValue);
    actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);

    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);

    StyleBuilder styleBuilder = new StyleBuilder();

    Font f1 = styleBuilder.createFont(expectedValue, false, true, 24.0);
    field.populateField(f1);
    actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);
}
 
Example #16
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#populateColourMapField(com.sldeditor.common.xml.ui.FieldIdEnum,
 * org.geotools.styling.ColorMap)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#getColourMap(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#getColourMap(com.sldeditor.ui.detail.config.FieldId)}.
 */
@Test
public void testColourMap() {

    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;

    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);

    FieldConfigColourMap colourMapField =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(Geometry.class, fieldId, "label", true, false));
    colourMapField.createUI();
    fieldConfigManager.add(fieldId, colourMapField);

    ColorMap expectedValue = new ColorMapImpl();
    ColorMapEntry entry = new ColorMapEntryImpl();
    StyleBuilder styleBuilder = new StyleBuilder();

    entry.setColor(styleBuilder.colorExpression(Color.PINK));
    entry.setQuantity(styleBuilder.literalExpression(2.3));
    expectedValue.addColorMapEntry(entry);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    obj.populateColourMapField(fieldId, expectedValue);
    assertEquals(
            expectedValue.getColorMapEntries().length,
            obj.getColourMap(fieldId).getColorMapEntries().length);

    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateColourMapField(wrongFieldEnum, expectedValue);
    assertNull(obj.getColourMap(wrongFieldEnum));
}
 
Example #17
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle(final SimpleFeatureCollection features) {
    // get name based rule names
    final List<Rule> ruleList = new ArrayList<>();
    final Set<String> nameSet = new HashSet<>();

    // setup custom rules for polygons
    final SimpleFeatureIterator featureIterator = features.features();
    while (featureIterator.hasNext()) {
        final SimpleFeature feature = featureIterator.next();
        if (nameSet.add((String) feature.getAttribute(ATTRIBUTE))) {
            ruleList.add(makeFillRule(feature));
        }
    }

    // create a partially opaque outline stroke
    final Rule defaultRule = makeFillRule();
    defaultRule.setElseFilter(true);
    defaultRule.setName("Default Rule");
    ruleList.add(defaultRule);

    // Create rule defined style
    final Rule[] rules = ruleList.toArray(new Rule[ruleList.size()]);
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FeatureTypeStyle featureTypeStyle = styleFactory.createFeatureTypeStyle(rules);

    final StyleBuilder builder = new StyleBuilder();
    final Style style = builder.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(featureTypeStyle);

    return style;
}
 
Example #18
Source File: FieldConfigFont.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate string field, overridden if necessary.
 *
 * @param value the value
 */
@Override
public void populateField(String value) {
    StyleBuilder styleBuilder = new StyleBuilder();

    Font font = styleBuilder.createFont(defaultValue, DEFAULT_FONT_SIZE);

    populateField(font);
}
 
Example #19
Source File: FieldConfigFontPreview.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate string field, overridden if necessary.
 *
 * @param value the value
 */
@Override
public void populateField(String value) {
    StyleBuilder styleBuilder = new StyleBuilder();

    Font font = styleBuilder.createFont(defaultValue, DEFAULT_FONT_SIZE);

    populateField(font);
}
 
Example #20
Source File: FieldConfigFontPreviewTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#generateExpression()}. Test method
 * for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#populateField(org.geotools.styling.Font)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigFontPreview field =
            new FieldConfigFontPreview(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false));

    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateField((Font) null);
    field.populateExpression((Font) null);

    String expectedValue = fontFamilies[0];
    field.createUI();
    field.populateField((Font) null);
    field.populateField(expectedValue);
    String actualValue = field.getStringValue();
    assertNotNull(actualValue);

    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualValue = field.getStringValue();
    assertNotNull(actualValue);

    StyleBuilder styleBuilder = new StyleBuilder();

    Font f1 = styleBuilder.createFont(expectedValue, false, true, 24.0);
    field.populateField(f1);
    assertNotNull(field.getStringValue());

    Font f2 = styleBuilder.createFont(expectedValue, true, true, 24.0);
    field.populateField(f2);
    assertNotNull(field.getStringValue());

    Font f3 = styleBuilder.createFont(expectedValue, true, false, 24.0);
    field.populateField(f3);
    assertNotNull(field.getStringValue());

    Font f4 = styleBuilder.createFont(expectedValue, false, false, 24.0);
    field.populateField(f4);
    assertNotNull(field.getStringValue());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font f5 = styleBuilder.createFont(expectedValue, false, false, 24.0);
    f5.setWeight(null);
    field.populateField(f5);
    assertEquals(field.getStringValue(), "");

    Font f6 = styleBuilder.createFont(expectedValue, false, false, 24.0);
    f6.setSize(ff.literal("24"));
    field.populateField(f6);
    assertNotNull(field.getStringValue());

    Font f7 = styleBuilder.createFont(expectedValue, false, false, 24.0);
    f7.setSize(ff.property("property"));
    field.populateField(f7);
    assertNotNull(field.getStringValue());
}
 
Example #21
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Finish service initialization.
 */
@PostConstruct
protected void postConstruct() {
	styleBuilder = new StyleBuilder(filterService.getFilterFactory());
}
 
Example #22
Source File: OmsCoverageViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void viewCoverage() throws Exception {
    StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
    // RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
    // Style rasterStyle = SLD.wrapSymbolizers(sym);

    StyleBuilder sB = new StyleBuilder(sf);
    RasterSymbolizer rasterSym = sf.createRasterSymbolizer();

    ColorMap colorMap = sf.createColorMap();

    RenderedImage renderedImage = raster.getRenderedImage();
    double max = Double.NEGATIVE_INFINITY;
    double min = Double.POSITIVE_INFINITY;
    RectIter iter = RectIterFactory.create(renderedImage, null);
    do {
        do {
            double value = iter.getSampleDouble();
            if (value > max) {
                max = value;
            }
            if (value < min) {
                min = value;
            }
        } while( !iter.nextPixelDone() );
        iter.startPixels();
    } while( !iter.nextLineDone() );

    // red to blue
    Color fromColor = Color.blue;
    Color toColor = Color.red;
    Expression fromColorExpr = sB
            .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255));
    Expression toColorExpr = sB
            .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255));
    Expression fromExpr = sB.literalExpression(min);
    Expression toExpr = sB.literalExpression(max);

    ColorMapEntry entry = sf.createColorMapEntry();
    entry.setQuantity(fromExpr);
    entry.setColor(fromColorExpr);
    colorMap.addColorMapEntry(entry);

    entry = sf.createColorMapEntry();
    entry.setQuantity(toExpr);
    entry.setColor(toColorExpr);
    colorMap.addColorMapEntry(entry);

    rasterSym.setColorMap(colorMap);

    Style rasterStyle = SLD.wrapSymbolizers(rasterSym);

    // Set up a MapContext with the two layers
    final MapContent map = new MapContent();
    map.setTitle("Coverage Viewer");
    map.addLayer(new GridCoverageLayer(raster, rasterStyle));

    // Create a JMapFrame with a menu to choose the display style for the
    final JMapFrame frame = new JMapFrame(map);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);
    frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET);
    frame.enableToolBar(true);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter(){
        public void windowClosing( WindowEvent e ) {
            frame.setVisible(false);
        }
    });

    while( frame.isVisible() ) {
        Thread.sleep(300);
    }
}
 
Example #23
Source File: FieldConfigFilenameTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename#getFill(org.opengis.style.GraphicFill,
 * com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testGetFill() {
    boolean valueOnly = true;
    FieldConfigFilename field =
            new FieldConfigFilename(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    GraphicFill graphicFill = null;
    GraphicPanelFieldManager fieldConfigManager = null;
    assertNull(field.getFill(graphicFill, fieldConfigManager));

    Class<?> panelId = PointFillDetails.class;
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(FieldIdEnum.UNKNOWN, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField =
            new FieldConfigSlider(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField =
            new FieldConfigSymbolType(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    symbolSelectionField.createUI();

    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);

    field.createUI();
    StyleBuilder styleBuilder = new StyleBuilder();
    graphicFill = styleBuilder.createGraphic();

    Fill actualValue = field.getFill(graphicFill, fieldConfigManager);

    assertTrue(
            actualValue.getOpacity().toString().compareTo(String.valueOf(expectedOpacityValue))
                    == 0);
}
 
Example #24
Source File: FieldConfigMarkerTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#getFill(org.opengis.style.GraphicFill,
 * com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testGetFill() {
    // Test it with null values
    boolean valueOnly = true;
    ColourFieldConfig fillConfig =
            new ColourFieldConfig(
                    GroupIdEnum.FILL,
                    FieldIdEnum.FILL_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_WIDTH);
    ColourFieldConfig strokeConfig =
            new ColourFieldConfig(
                    GroupIdEnum.STROKE,
                    FieldIdEnum.STROKE_STROKE_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_FILL_WIDTH);
    FieldConfigMarker field =
            new FieldConfigMarker(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    fillConfig,
                    strokeConfig,
                    null);

    assertNull(field.getStringValue());

    GraphicFill graphicFill = null;
    GraphicPanelFieldManager fieldConfigManager = null;
    Fill actualValue = field.getFill(graphicFill, fieldConfigManager);

    assertNull(actualValue);

    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    actualValue = field.getFill(graphicFill, fieldConfigManager);
    assertNotNull(actualValue);
    assertNull(actualValue.getColor());
    assertNull(actualValue.getGraphicFill());
    assertNull(actualValue.getOpacity());

    // Test it with non null values
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;

    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField =
            new FieldConfigSlider(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField =
            new FieldConfigSymbolType(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    symbolSelectionField.createUI();

    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);

    FieldConfigMarker field2 =
            new FieldConfigMarker(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    fillConfig,
                    strokeConfig,
                    symbolSelectionFieldId);
    actualValue = field2.getFill(graphicFill, fieldConfigManager);
    assertNotNull(actualValue);
    LiteralExpressionImpl literalExpressionImpl =
            (LiteralExpressionImpl) actualValue.getColor();
    String actualColourString = literalExpressionImpl.toString();
    assertTrue(actualColourString.compareTo(expectedColourValue) == 0);

    StyleBuilder styleBuilder = new StyleBuilder();

    graphicFill = styleBuilder.createGraphic();
    actualValue = field2.getFill(graphicFill, fieldConfigManager);
    assertNull(actualValue.getColor());
    assertNull(actualValue.getOpacity());
}
 
Example #25
Source File: FieldConfigMarkerTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigMarker field =
            new FieldConfigMarker(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);

    assertFalse(field.accept(null));

    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic =
            (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));

    Mark marker = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker));

    List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();

    dataList.add(new ValueComboBoxData("star", "Star", this.getClass()));
    dataList.add(new ValueComboBoxData("square", "Square", this.getClass()));
    dataList.add(new ValueComboBoxData("triangle", "Triangle", this.getClass()));

    List<ValueComboBoxDataGroup> groupList = new ArrayList<ValueComboBoxDataGroup>();
    groupList.add(new ValueComboBoxDataGroup(dataList));

    field.populateSymbolList(String.class, groupList);
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));
    field.populateSymbolList(PointFillDetails.class, groupList);
    assertTrue(field.accept(marker));

    // Try some invalid values
    StyleFactory sf = CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    marker = sf.createMark();
    marker.setWellKnownName(ff.property("testproperty"));
    assertFalse(field.accept(marker));

    marker = sf.createMark();
    marker.setWellKnownName(ff.literal(12));
    assertFalse(field.accept(marker));
}
 
Example #26
Source File: FieldConfigMarkerTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#setValue(com.sldeditor.ui.detail.GraphicPanelFieldManager,
 * com.sldeditor.ui.detail.config.FieldConfigSymbolType, org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testSetValue() {

    GraphicPanelFieldManager fieldConfigManager = null;

    Class<?> panelId = PointSymbolizer.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);

    // Test it with non null values
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField =
            new FieldConfigSlider(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField =
            new FieldConfigSymbolType(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    symbolSelectionField.createUI();

    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);

    boolean valueOnly = true;

    ColourFieldConfig fillConfig =
            new ColourFieldConfig(
                    GroupIdEnum.FILL,
                    FieldIdEnum.FILL_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_WIDTH);
    ColourFieldConfig strokeConfig =
            new ColourFieldConfig(
                    GroupIdEnum.STROKE,
                    FieldIdEnum.STROKE_STROKE_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_FILL_WIDTH);

    FieldConfigMarker field2 =
            new FieldConfigMarker(
                    new FieldConfigCommonData(
                            PointSymbolizer.class,
                            FieldIdEnum.NAME,
                            "test label",
                            valueOnly,
                            false),
                    fillConfig,
                    strokeConfig,
                    null);

    field2.setValue(null, null, null, null, null);
    field2.setValue(null, fieldConfigManager, null, null, null);

    StyleBuilder styleBuilder = new StyleBuilder();
    Mark marker = styleBuilder.createMark("shape://plus");
    field2.setValue(null, null, null, null, marker);
    field2.setValue(PointSymbolizer.class, fieldConfigManager, null, null, marker);

    GroupConfig strokeGroup = new GroupConfig();
    strokeGroup.setId(strokeConfig.getGroup());
    fieldConfigManager.addGroup(strokeGroup);

    GroupConfig fillGroup = new GroupConfig();
    fillGroup.setId(fillConfig.getGroup());
    fieldConfigManager.addGroup(fillGroup);

    field2.setValue(PointSymbolizer.class, fieldConfigManager, null, null, marker);
}
 
Example #27
Source File: FieldConfigWindBarbsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager,
 * org.opengis.filter.expression.Expression, boolean, boolean)}.
 */
@Test
public void testGetValue() {
    // Test it with null values
    boolean valueOnly = true;
    FieldConfigWindBarbs field =
            new FieldConfigWindBarbs(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    null,
                    null,
                    null);
    field.createUI();
    assertNull(field.getStringValue());

    GraphicPanelFieldManager fieldConfigManager = null;
    Expression symbolType = null;
    List<GraphicalSymbol> actualValue =
            field.getValue(fieldConfigManager, symbolType, false, false);

    assertTrue(actualValue.isEmpty());

    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    String actualMarkerSymbol = "solid";
    StyleBuilder styleBuilder = new StyleBuilder();
    symbolType = styleBuilder.literalExpression(actualMarkerSymbol);

    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField =
            new FieldConfigSlider(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField =
            new FieldConfigSymbolType(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    symbolSelectionField.createUI();

    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);

    // Try without setting any fields
    actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
    assertNotNull(actualValue);
    assertEquals(1, actualValue.size());
    Mark actualSymbol = (Mark) actualValue.get(0);
    assertTrue(
            actualSymbol.getWellKnownName().toString().compareTo("windbarbs://default(0)[m/s]")
                    == 0);
}
 
Example #28
Source File: FieldConfigTTFTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.symboltype.ttf.FieldConfigTTF#setValue(com.sldeditor.ui.detail.GraphicPanelFieldManager,
 * com.sldeditor.ui.detail.config.FieldConfigSymbolType, org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testSetValue() {

    GraphicPanelFieldManager fieldConfigManager = null;

    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField =
            new FieldConfigColour(
                    new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    fieldConfigManager.add(colourFieldId, colourField);

    ColourFieldConfig fillConfig =
            new ColourFieldConfig(
                    GroupIdEnum.FILL,
                    FieldIdEnum.FILL_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_WIDTH);
    ColourFieldConfig strokeConfig =
            new ColourFieldConfig(
                    GroupIdEnum.STROKE,
                    FieldIdEnum.STROKE_STROKE_COLOUR,
                    FieldIdEnum.OVERALL_OPACITY,
                    FieldIdEnum.STROKE_FILL_WIDTH);
    boolean valueOnly = true;
    FieldConfigTTF field =
            new FieldConfigTTF(
                    new FieldConfigCommonData(
                            String.class, FieldIdEnum.NAME, "test label", valueOnly, false),
                    fillConfig,
                    strokeConfig,
                    null);

    field.setValue(null, null, null, null, null);
    field.setValue(null, fieldConfigManager, null, null, null);

    field.createUI();
    StyleBuilder styleBuilder = new StyleBuilder();
    Mark marker = styleBuilder.createMark("star", Color.green, Color.black, 2.0);

    field.setValue(null, null, null, null, marker);
    field.setValue(null, fieldConfigManager, null, null, marker);
}
 
Example #29
Source File: StrokeViewer.java    From gama with GNU General Public License v3.0 3 votes vote down vote up
/**
 * TODO summary sentence for getStroke ...
 *
 * @param build
 *
 * @return Stroke defined by this model
 */
public Stroke getStroke(final StyleBuilder build) {
	if (!this.enabled) { return null; }
	if (!Double.isNaN(this.opacity)) { return build.createStroke(this.color, this.width, this.opacity); }
	if (!Double.isNaN(this.width)) { return build.createStroke(this.color, this.width); }
	return build.createStroke(this.color);
}
 
Example #30
Source File: SLDExternalImagesTest.java    From sldeditor with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates the test point.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPoint(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();

    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    Rule rule = styleFactory.createRule();

    fts.rules().add(rule);

    PointSymbolizer point = styleFactory.createPointSymbolizer();

    rule.symbolizers().add(point);

    Graphic graphic = createGraphic(url, styleFactory);

    point.setGraphic(graphic);

    return sld;
}