Java源码示例:org.geotools.styling.StyleBuilder

示例1
/**
 * 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));
}
 
示例2
/**
 * 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));
}
 
示例3
/**
 * 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);
}
 
示例4
/**
 * 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);
}
 
示例5
/**
 * 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));
}
 
示例6
/**
 * 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));
}
 
示例7
/**
 * 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;
}
 
示例8
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;
}
 
示例9
/** 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();
}
 
示例10
/**
 * 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);
}
 
示例11
/**
 * 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);
}
 
示例12
/**
 * 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));
}
 
示例13
/**
 * 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);
}
 
示例14
/**
 * 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));
}
 
示例15
/**
 * 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);
	}
}
 
示例16
/**
 * 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
	}
}
 
示例17
/**
 * 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;
}
 
示例18
@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);
    }
}
 
示例19
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);
}
 
示例20
/**
 * 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);
}
 
示例21
/**
 * 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());
}
 
示例22
/**
 * 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));
}
 
示例23
/**
 * 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);
}
 
示例24
/**
 * 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);
}
 
示例25
/**
 * 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());
}
 
示例26
/**
 * 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);
}
 
示例27
@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);
    }
}
 
示例28
/**
 * Finish service initialization.
 */
@PostConstruct
protected void postConstruct() {
	styleBuilder = new StyleBuilder(filterService.getFilterFactory());
}
 
示例29
/**
 * Creates the test line.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestLine(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);

    LineSymbolizer line = styleFactory.createLineSymbolizer();

    rule.symbolizers().add(line);

    Graphic graphicFill = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);

    Stroke stroke =
            styleFactory.createStroke(
                    null, null, null, null, null, null, null, graphicFill, graphicStroke);
    line.setStroke(stroke);

    return sld;
}
 
示例30
/**
 * 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;
}