Java Code Examples for org.geotools.factory.CommonFactoryFinder#getFilterFactory()

The following examples show how to use org.geotools.factory.CommonFactoryFinder#getFilterFactory() . 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: SelectedSymbolTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.data.SelectedSymbol#getSymbolList(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testGetSymbolList() {

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Stroke stroke = null;
    Fill fill = styleFactory.createFill(ff.literal(DefaultSymbols.defaultColour()));
    GraphicalSymbol symbolToAdd = styleFactory.mark(ff.literal("circle"), fill, stroke);

    List<GraphicalSymbol> symbolList = SelectedSymbol.getInstance().getSymbolList(symbolToAdd);

    assertEquals(1, symbolList.size());

    assertEquals(symbolToAdd, symbolList.get(0));
}
 
Example 2
Source File: VOGeoServerTextSymbolizer2Test.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.text.VOGeoServerTextSymbolizer2#getMinimumVersion(java.lang.Object,
 * java.lang.Object, java.util.List)}.
 */
@Test
public void testGetMinimumVersion() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();
    VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
    TextSymbolizer2 symbolizer = null;
    testObj.updateSymbol(symbolizer);

    symbolizer = (TextSymbolizer2) DefaultSymbols.createDefaultTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    symbolizer.setSnippet(ff.literal("Test snippet"));

    List<VendorOptionPresent> vendorOptionsPresentList = null;
    testObj.getMinimumVersion(symbolizer, "", vendorOptionsPresentList);

    vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(symbolizer, "", vendorOptionsPresentList);
}
 
Example 3
Source File: ExpressionPanelv2Test.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.expression.ExpressionPanelv2#ExpressionPanelv2(java.util.List)}.
 */
@Test
public void testExpressionPanelv2Property() {

    TestExpressionPanelv2 testObj = new TestExpressionPanelv2(null);

    assertNull(testObj.getVendorOptionList());
    testObj.dataSourceAboutToUnloaded(null);
    testObj.populate((String) null);
    testObj.configure("title", String.class, false);

    testObj.testShowExpressionDialog(null, null);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression expectedExpression = ff.add(ff.property("field"), ff.literal(42));

    testObj.populate(expectedExpression);
    testObj.testShowExpressionDialog(Integer.class, expectedExpression);

    assertEquals(testObj.getExpression().toString(), testObj.getExpressionString());

    testObj.dataSourceLoaded(GeometryTypeEnum.POLYGON, true);
    testObj.dataApplied();
    testObj.testSelection();
}
 
Example 4
Source File: VOGeoServerContrastEnhancementNormalizeGreenTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the channel selection object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelection(
        StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement =
            (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1"));
    options.put("maxValue", ff.literal("5"));

    SelectedChannelType channelType =
            styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
 
Example 5
Source File: VOGeoServerContrastEnhancementNormalizeBlueTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the channel selection error object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelectionError(
        StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement =
            (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("TestStretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1.0"));
    options.put("maxValue", ff.literal("5.0"));

    SelectedChannelType channelType =
            styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
 
Example 6
Source File: DetailsUtilitiesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.DetailsUtilities#isSame(org.geotools.styling.AnchorPoint,
 * org.geotools.styling.AnchorPoint)}.
 */
@Test
public void testIsSameAnchorPointAnchorPoint() {
    assertFalse(DetailsUtilities.isSame((AnchorPoint) null, (AnchorPoint) null));

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    // Try values that are the same
    AnchorPoint anchorPoint1 = new AnchorPointImpl();
    anchorPoint1.setAnchorPointX(ff.literal(0.58));
    anchorPoint1.setAnchorPointY(ff.literal(0.1));

    AnchorPoint anchorPoint2 = new AnchorPointImpl();
    anchorPoint2.setAnchorPointX(ff.literal(0.58));
    anchorPoint2.setAnchorPointY(ff.literal("0.1"));

    assertTrue(DetailsUtilities.isSame(anchorPoint1, anchorPoint2));

    // Try values that are not the same
    AnchorPoint anchorPoint3 = new AnchorPointImpl();
    anchorPoint3.setAnchorPointX(ff.literal(1.0));
    anchorPoint3.setAnchorPointY(ff.literal(0.1));
    assertFalse(DetailsUtilities.isSame(anchorPoint1, anchorPoint3));
    assertFalse(DetailsUtilities.isSame(anchorPoint2, anchorPoint3));
}
 
Example 7
Source File: VOGeoServerContrastEnhancementNormalizeOverallTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the channel selection object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelection(
        StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement =
            (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1"));
    options.put("maxValue", ff.literal("5"));

    SelectedChannelType channelType =
            styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
 
Example 8
Source File: VOGeoServerContrastEnhancementNormalizeGreyTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the channel selection object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelection(
        StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement =
            (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1"));
    options.put("maxValue", ff.literal("5"));

    SelectedChannelType channelType =
            styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
 
Example 9
Source File: ColourUtilsTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.utils.ColourUtils#getIntColour(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testGetIntColour() {

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Expression colourExpression = ff.literal("#FF00FF");
    int colourValue = ColourUtils.getIntColour(colourExpression);
    assertEquals(0xff00ff, colourValue);

    colourValue = ColourUtils.getIntColour(null);
}
 
Example 10
Source File: EncodeColourMapTest.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.colourmap.EncodeColourMap#encode(org.geotools.styling.ColorMap)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.EncodeColourMap#encode(java.util.List)}.
 */
@Test
public void testEncodeColorMap() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMapEntryImpl entry1 = new ColorMapEntryImpl();
    entry1.setColor(ff.literal(COLOUR_1));
    entry1.setOpacity(ff.literal(OPACITY_1));
    entry1.setQuantity(ff.literal(QUANTITY_1));
    ColorMap expectedValue = new ColorMapImpl();
    expectedValue.addColorMapEntry(entry1);
    ColorMapEntryImpl entry2 = new ColorMapEntryImpl();
    entry2.setColor(ff.literal(COLOUR_2));
    entry2.setLabel(LABEL_2);
    entry2.setOpacity(ff.literal(OPACITY_2));
    entry2.setQuantity(ff.literal(QUANTITY_2));
    expectedValue.addColorMapEntry(entry2);

    XMLColourMapEntry xml1 = new XMLColourMapEntry();
    xml1.setColour(COLOUR_1);
    xml1.setOpacity(OPACITY_1);
    xml1.setQuantity(42);
    List<XMLColourMapEntry> xmlList = new ArrayList<XMLColourMapEntry>();
    xmlList.add(xml1);

    XMLColourMapEntry xml2 = new XMLColourMapEntry();
    xml2.setColour(COLOUR_2);
    xml2.setLabel(LABEL_2);
    xml2.setOpacity(OPACITY_2);
    xml2.setQuantity(QUANTITY_2);
    xmlList.add(xml2);

    String actualValue1 = EncodeColourMap.encode(expectedValue);
    String actualValue2 = EncodeColourMap.encode(xmlList);

    assertTrue(actualValue1.compareTo(actualValue2) == 0);
}
 
Example 11
Source File: MathsExpressionPanelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.expression.MathsExpressionPanel#MathsExpressionPanel(com.sldeditor.ui.attribute.SubPanelUpdatedInterface)}.
 */
@Test
void testMathsExpressionPanel() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    MathsExpressionPanel testObj =
            new MathsExpressionPanel(
                    new SubPanelUpdatedInterface() {

                        @Override
                        public void updateSymbol() {}

                        @Override
                        public void parameterAdded() {}
                    });

    // Invalid
    testObj.setExpression(null);
    assertEquals(null, testObj.getExpression());

    // Add
    testObj.setExpression(ff.add(null, null));
    assertEquals(AddImpl.class, testObj.getExpression().getClass());
    assertEquals("Add", testObj.getSelectedItem());

    // Subtract
    testObj.setExpression(ff.subtract(null, null));
    assertEquals(SubtractImpl.class, testObj.getExpression().getClass());

    // Multiply
    testObj.setExpression(ff.multiply(null, null));
    assertEquals(MultiplyImpl.class, testObj.getExpression().getClass());

    // Divide
    testObj.setExpression(ff.divide(null, null));
    assertEquals(DivideImpl.class, testObj.getExpression().getClass());

    testObj.setPanelEnabled(true);
}
 
Example 12
Source File: IFeatureShape.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Modify the attributes of this feature.
 * 
 * @param names the names of the attributes to modify.
 * @param values the values to set.
 * @return the new feature if the editing has been successful.
 */
default public SimpleFeature modifyFeatureAttribute( String[] names, Object[] values ) {
    FeatureStoreInfo featureStoreInfo = getFeatureStoreInfo();
    SimpleFeatureStore featureStore = featureStoreInfo.getFeatureStore();
    if (featureStore != null) {
        Transaction transaction = new DefaultTransaction("modify");
        featureStore.setTransaction(transaction);

        FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
        Filter filter = ff.id(Collections.singleton(ff.featureId(getFeature().getID())));

        try {
            featureStore.modifyFeatures(names, values, filter);
            transaction.commit();

            SimpleFeature modifiedFeature = featureStore.getFeatures(filter).features().next();
            return modifiedFeature;
        } catch (Exception eek) {
            try {
                transaction.rollback();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
 
Example 13
Source File: ExpressionPanelv2Test.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.expression.ExpressionPanelv2#ExpressionPanelv2(java.util.List)}.
 */
@Test
public void testExpressionPanelv2Concatenate() {

    TestExpressionPanelv2 testObj = new TestExpressionPanelv2(null);

    assertNull(testObj.getVendorOptionList());
    testObj.dataSourceAboutToUnloaded(null);
    testObj.populate((String) null);
    testObj.configure("title", String.class, false);

    testObj.testShowExpressionDialog(null, null);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    FunctionImpl expectedExpression = new ConcatenateFunction();
    List<Expression> params = new ArrayList<Expression>();
    params.add(ff.literal("world"));
    params.add(ff.literal("dog"));
    expectedExpression.setParameters(params);

    testObj.populate(expectedExpression);
    testObj.testShowExpressionDialog(String.class, expectedExpression);

    assertEquals(testObj.getExpression().toString(), testObj.getExpressionString());

    testObj.dataApplied();
    testObj.testSelection();
}
 
Example 14
Source File: EnvironmentVariablePanelTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.envvar.EnvironmentVariablePanel#EnvironmentVariablePanel(com.sldeditor.filter.v2.expression.ExpressionFilterInterface)}.
 */
@Test
void testEnvironmentVariablePanel() {
    TestEnvironmentVariablePanel testObj = new TestEnvironmentVariablePanel(null);

    // Nothing selected
    testObj.revertButton();
    testObj.applyButton();
    testObj.dataSourceLoaded(null);

    TestExpressionFilterInterface receiver = new TestExpressionFilterInterface();
    testObj = new TestEnvironmentVariablePanel(receiver);
    TestDataSourceInterface dataSource = new TestDataSourceInterface();
    testObj.dataSourceLoaded(dataSource);

    assertFalse(receiver.dataAppliedFlag);
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ExpressionNode node = new ExpressionNode();

    Expression property = ff.property("Field2");
    node.setExpression(property);

    testObj.setAttribute(property);
    testObj.applyButton();
    assertTrue(receiver.dataAppliedFlag);
    receiver.dataAppliedFlag = false;
    testObj.setSelectedNode(node);
    testObj.applyButton();
    assertTrue(receiver.dataAppliedFlag);
}
 
Example 15
Source File: ExpressionPanelv2Test.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.expression.ExpressionPanelv2#ExpressionPanelv2(java.util.List)}.
 */
@Test
public void testExpressionPanelv2FunctionExpression() {

    TestExpressionPanelv2 testObj = new TestExpressionPanelv2(null);

    assertNull(testObj.getVendorOptionList());
    testObj.dataSourceAboutToUnloaded(null);
    testObj.populate((String) null);
    testObj.configure("title", String.class, false);

    testObj.testShowExpressionDialog(null, null);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    FunctionExpression expectedExpression = new Collection_AverageFunction();
    List<Expression> params = new ArrayList<Expression>();
    params.add(ff.literal(1));
    expectedExpression.setParameters(params);

    testObj.populate(expectedExpression);
    testObj.testShowExpressionDialog(Integer.class, expectedExpression);

    assertEquals(testObj.getExpression().toString(), testObj.getExpressionString());

    testObj.dataApplied();
    testObj.testSelection();
}
 
Example 16
Source File: VOGeoServerTextSymbolizer2Test.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.text.VOGeoServerTextSymbolizer2#VOGeoServerTextSymbolizer2(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSymbolizer2() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example 17
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 18
Source File: FieldConfigBaseTest.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.FieldConfigBase#populate(org.opengis.filter.expression.Expression)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression,
 * org.opengis.filter.expression.Expression)}.
 */
@Test
public void testPopulateExpressionExpression() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field =
            new TestFieldConfigBase(
                    new FieldConfigCommonData(
                            String.class, expectedFieldId, expectedLabel, false, false));

    AttributeSelection attributeSelectionPanel =
            AttributeSelection.createAttributes(String.class, field, false);
    field.testAttributeSelectionPanel(attributeSelectionPanel);

    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);

    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    // Test function
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    FunctionName functionName = null;

    for (FunctionName func : functionFactory.getFunctionNames()) {
        if (func.getName() == "greaterThan") {
            functionName = func;
            break;
        }
    }

    assertNotNull(functionName);

    Expression testExpression =
            ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
    field.populate(testExpression);
    // Updated because the attribute pulldown changed
    assertTrue(listener.hasBeenCalled());

    assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression.toString().startsWith(functionName.getName()));

    // Attribute expression wrapped in a literal expression
    String testAttributeName = "test attribute";
    NameImpl name = new NameImpl(testAttributeName);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl(name);

    Expression literalExpression = ff.literal(attributeExpression);
    field.populate(literalExpression);
    assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());

    // Process Function
    // ProcessFunctionFactory factory = new ProcessFunctionFactory();
    // FunctionTableModel functionParameterTableModel = new FunctionTableModel();
    // ProcessFunction processFunction = functionParameterTableModel.getExpression(factory);
    // field.populate(processFunction);
    // assertEquals(ExpressionTypeEnum.E_VALUE, field.getExpressionType());
}
 
Example 19
Source File: ColourRampTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Test method for {@link com.sldeditor.colourramp.ColourRamp#ColourRamp()}. */
@Test
public void testColourRamp() {
    ColourRamp ramp = new ColourRamp();

    assertEquals(Color.BLACK, ramp.getStartColour());
    assertEquals(Color.WHITE, ramp.getEndColour());

    Color expectedStart = Color.red;
    Color expectedEnd = Color.pink;

    ramp.setColourRamp(expectedStart, expectedEnd);
    assertEquals(expectedStart, ramp.getStartColour());
    assertEquals(expectedEnd, ramp.getEndColour());

    Color expectedEnd2 = Color.cyan;
    ramp.addColour(expectedEnd2);
    assertEquals(expectedStart, ramp.getStartColour());
    assertEquals(expectedEnd2, ramp.getEndColour());
    assertEquals(3, ramp.getColourList().size());

    ImageIcon icon1 = ramp.getImageIcon(false);
    assertNotNull(icon1);
    ImageIcon icon2 = ramp.getImageIcon(true);
    assertNotNull(icon2);

    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
    ColourRampData data = new ColourRampData();
    Expression expectedMinValue = ff.literal(1);
    Expression expectedMaxValue = ff.literal(10);
    data.setColourRamp(ramp);
    data.setMinValue(1);
    data.setMaxValue(10);

    Expression actualStart = ramp.getColour(data, expectedMinValue, false);
    @SuppressWarnings("unused")
    Expression actualEnd = ramp.getColour(data, expectedMaxValue, false);

    assertEquals(ColourUtils.toColour(actualStart.toString()), expectedStart);

    // Can't test end value
    // assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedEnd2);

    // Reverse colours
    actualStart = ramp.getColour(data, expectedMinValue, true);
    actualEnd = ramp.getColour(data, expectedMaxValue, true);

    assertEquals(ColourUtils.toColour(actualStart.toString()), expectedEnd2);
    // Can't test end value
    //        assertEquals(ColourUtils.toColour(actualEnd.toString()), expectedStart);
}
 
Example 20
Source File: SLDUtilsTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font =
            styleFactory.createFont(
                    ff.literal("abc"),
                    ff.literal("normal"),
                    ff.literal("normal"),
                    ff.literal(10));
    symbolizer.setFont(font);

    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();

    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);

    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());

    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);

    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}