Search in sources :

Example 1 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class EncodeColourMapTest method testEncodeColorMap.

/**
 * 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);
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMap(org.geotools.styling.ColorMap) XMLColourMapEntry(com.sldeditor.common.xml.ui.XMLColourMapEntry) ArrayList(java.util.ArrayList) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 2 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class FieldConfigColourMapTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#generateExpression()}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#populateField(org.geotools.styling.ColorMap)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#setTestValue(com.sldeditor.ui.detail.config.FieldId, org.geotools.styling.ColorMap)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#getColourMap()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigColourMap field = new FieldConfigColourMap(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
    ColorMap testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);
    field.createUI();
    ColorMap expectedValue1 = new ColorMapImpl();
    field.populateField(expectedValue1);
    assertEquals(expectedValue1, field.getColourMap());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ColorMap expectedValue2 = new ColorMapImpl();
    ColorMapEntryImpl entry = new ColorMapEntryImpl();
    entry.setColor(ff.literal("#001122"));
    expectedValue2.addColorMapEntry(entry);
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
    assertEquals(expectedValue2.getColorMapEntries().length, field.getColourMap().getColorMapEntries().length);
    field.populateExpression((String) null);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ColorMapImpl(org.geotools.styling.ColorMapImpl) FieldConfigColourMap(com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMap(org.geotools.styling.ColorMap) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 3 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class FieldConfigColourMapTest method testGetStringValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#getStringValue()}.
 */
@Test
public void testGetStringValue() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ColorMapEntryImpl entry1 = new ColorMapEntryImpl();
    entry1.setColor(ff.literal("#001122"));
    entry1.setLabel("testlabel");
    entry1.setOpacity(ff.literal(0.42));
    entry1.setQuantity(ff.literal(42));
    ColorMap expectedValue = new ColorMapImpl();
    expectedValue.addColorMapEntry(entry1);
    ColorMapEntryImpl entry2 = new ColorMapEntryImpl();
    entry2.setColor(ff.literal("#551122"));
    entry2.setLabel("testlabel2");
    entry2.setOpacity(ff.literal(0.22));
    entry2.setQuantity(ff.literal(12));
    expectedValue.addColorMapEntry(entry2);
    FieldConfigColourMap field = new FieldConfigColourMap(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
    field.populateField(expectedValue);
    assertTrue(field.getStringValue().compareTo(EncodeColourMap.encode(expectedValue)) == 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) FieldConfigColourMap(com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap) ColorMap(org.geotools.styling.ColorMap) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 4 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class FieldConfigColourMapTest method testUndoAction.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigColourMap field = new FieldConfigColourMap(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();
    ColorMap expectedValue1 = new ColorMapImpl();
    field.populateField(expectedValue1);
    assertEquals(expectedValue1, field.getColourMap());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ColorMap expectedValue2 = new ColorMapImpl();
    ColorMapEntryImpl entry = new ColorMapEntryImpl();
    entry.setColor(ff.literal("#001122"));
    expectedValue2.addColorMapEntry(entry);
    field.populateField(expectedValue2);
    UndoManager.getInstance().undo();
    assertEquals(expectedValue1.getColorMapEntries().length, field.getColourMap().getColorMapEntries().length);
    UndoManager.getInstance().redo();
    assertEquals(expectedValue2.getColorMapEntries().length, field.getColourMap().getColorMapEntries().length);
    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) UndoEvent(com.sldeditor.common.undo.UndoEvent) ColorMapImpl(org.geotools.styling.ColorMapImpl) FieldConfigColourMap(com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMap(org.geotools.styling.ColorMap) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 5 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testColourMap.

/**
 * 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));
    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));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) ColorMapImpl(org.geotools.styling.ColorMapImpl) FieldConfigColourMap(com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMap(org.geotools.styling.ColorMap) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) ColorMapEntry(org.geotools.styling.ColorMapEntry) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Aggregations

ColorMapEntryImpl (org.geotools.styling.ColorMapEntryImpl)9 ColorMapImpl (org.geotools.styling.ColorMapImpl)6 Test (org.junit.Test)6 ColorMap (org.geotools.styling.ColorMap)5 ColorMapEntry (org.geotools.styling.ColorMapEntry)5 FilterFactory (org.opengis.filter.FilterFactory)5 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)4 FieldConfigColourMap (com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap)4 Geometry (com.vividsolutions.jts.geom.Geometry)4 ArrayList (java.util.ArrayList)3 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 XMLColourMapEntry (com.sldeditor.common.xml.ui.XMLColourMapEntry)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 MultipleColourMapEntry (com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry)1 IOException (java.io.IOException)1 GridEnvelope2D (org.geotools.coverage.grid.GridEnvelope2D)1 StyleBuilder (org.geotools.styling.StyleBuilder)1 Literal (org.opengis.filter.expression.Literal)1