Search in sources :

Example 1 with ColorMapEntry

use of org.geotools.styling.ColorMapEntry 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)

Example 2 with ColorMapEntry

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

the class RasterReader method createRGBImageSymbol.

/**
 * Creates the rgb image symbol.
 *
 * @param sym the sym
 * @param cov the cov
 * @param raster the raster
 */
private void createRGBImageSymbol(RasterSymbolizer sym, GridCoverage2D cov, WritableRaster raster) {
    double dest;
    List<Double> valueList = new ArrayList<Double>();
    GridEnvelope2D gridRange2D = cov.getGridGeometry().getGridRange2D();
    for (int x = 0; x < gridRange2D.getWidth(); x++) {
        for (int y = 0; y < gridRange2D.getHeight(); y++) {
            try {
                dest = raster.getSampleDouble(x, y, 0);
                if (!valueList.contains(dest)) {
                    valueList.add(dest);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    ColorMapImpl colourMap = new ColorMapImpl();
    // Sort the unique sample values in ascending order
    Collections.sort(valueList);
    // Create colour amp entries in the colour map for all the sample values
    for (Double value : valueList) {
        ColorMapEntry entry = new ColorMapEntryImpl();
        Literal colourExpression = ff.literal(ColourUtils.fromColour(ColourUtils.createRandomColour()));
        entry.setColor(colourExpression);
        entry.setQuantity(ff.literal(value.doubleValue()));
        colourMap.addColorMapEntry(entry);
    }
    colourMap.setType(ColorMap.TYPE_VALUES);
    sym.setColorMap(colourMap);
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Literal(org.opengis.filter.expression.Literal) ArrayList(java.util.ArrayList) ColorMapEntry(org.geotools.styling.ColorMapEntry) IOException(java.io.IOException)

Example 3 with ColorMapEntry

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

the class ColourMapModel method getColourMap.

/**
 * Gets the colour map.
 *
 * @return the colour map
 */
public ColorMap getColourMap() {
    ColorMap colourMap = new ColorMapImpl();
    for (ColourMapData data : colourMapList) {
        ColorMapEntry entry = createColourMapEntry(data);
        colourMap.addColorMapEntry(entry);
    }
    return colourMap;
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMap(org.geotools.styling.ColorMap) ColorMapEntry(org.geotools.styling.ColorMapEntry)

Example 4 with ColorMapEntry

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

the class EncodeColourMap method encode.

/**
 * Encode colour map entries into a string.
 *
 * @param colourMap the colour map
 * @return the string
 */
public static String encode(ColorMap colourMap) {
    StringBuilder sb = new StringBuilder();
    for (ColorMapEntry entry : colourMap.getColorMapEntries()) {
        sb.append((entry.getLabel() == null) ? "" : entry.getLabel());
        sb.append(SEPARATOR);
        sb.append(entry.getColor());
        sb.append(SEPARATOR);
        sb.append(Double.valueOf(entry.getOpacity().toString()));
        sb.append(SEPARATOR);
        sb.append(entry.getQuantity());
        sb.append(ENTRY_SEPARATOR);
    }
    return sb.toString();
}
Also used : ColorMapEntry(org.geotools.styling.ColorMapEntry)

Example 5 with ColorMapEntry

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

the class FieldConfigColourMap method createUI.

/**
 * Creates the ui.
 */
@Override
public void createUI() {
    if (colourRampConfig == null) {
        int xPos = getXPos();
        int maxNoOfConfigRows = 7;
        int maxNoOfTableRows = 12;
        int totalRows = maxNoOfConfigRows + maxNoOfTableRows + ColourMapEntryPanel.getNoOfRows();
        FieldPanel fieldPanel = createFieldPanel(xPos, getRowY(totalRows), getLabel());
        colourRampConfig = new ColourRampConfigPanel(this, model);
        colourRampConfig.setBounds(xPos, 0, BasePanel.FIELD_PANEL_WIDTH, getRowY(maxNoOfConfigRows));
        fieldPanel.add(colourRampConfig);
        table = new JTable(model);
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setBounds(xPos, getRowY(maxNoOfConfigRows), BasePanel.FIELD_PANEL_WIDTH, getRowY(totalRows - 2));
        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    removeButton.setEnabled(true);
                    List<ColorMapEntry> entries;
                    if (table.getSelectedRowCount() == 1) {
                        ColorMapEntry entry = model.getColourMapEntry(table.getSelectedRow());
                        entries = new ArrayList<ColorMapEntry>();
                        entries.add(entry);
                    } else {
                        entries = model.getColourMapEntries(table.getSelectedRows());
                    }
                    colourMapEntryPanel.setSelectedEntry(entries);
                }
            }
        });
        model.setCellRenderer(table);
        JScrollPane scrollPanel = new JScrollPane(table);
        int endOfTableRow = maxNoOfConfigRows + maxNoOfTableRows - 2;
        scrollPanel.setBounds(xPos, getRowY(maxNoOfConfigRows), BasePanel.FIELD_PANEL_WIDTH, getRowY(endOfTableRow) - getRowY(maxNoOfConfigRows));
        fieldPanel.add(scrollPanel);
        int buttonY = getRowY(endOfTableRow);
        // 
        // Add button
        // 
        addButton = new JButton(Localisation.getString(FieldConfigBase.class, "FieldConfigColourMap.add"));
        addButton.setBounds(xPos + BasePanel.WIDGET_X_START, buttonY, BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT);
        addButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addEntry();
            }
        });
        fieldPanel.add(addButton);
        // 
        // Remove button
        // 
        removeButton = new JButton(Localisation.getString(FieldConfigBase.class, "FieldConfigColourMap.remove"));
        removeButton.setBounds(xPos + BasePanel.WIDGET_BUTTON_WIDTH + BasePanel.WIDGET_X_START + 10, buttonY, BasePanel.WIDGET_BUTTON_WIDTH, BasePanel.WIDGET_HEIGHT);
        removeButton.setEnabled(false);
        removeButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                removeEntry();
            }
        });
        fieldPanel.add(removeButton);
        colourMapEntryPanel = new ColourMapEntryPanel(getPanelId(), this);
        colourMapEntryPanel.setBounds(xPos, getRowY(maxNoOfConfigRows + maxNoOfTableRows - 1), BasePanel.FIELD_PANEL_WIDTH, colourMapEntryPanel.getPanelHeight());
        fieldPanel.add(colourMapEntryPanel);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) ColorMapEntry(org.geotools.styling.ColorMapEntry) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ArrayList(java.util.ArrayList) List(java.util.List) FieldPanel(com.sldeditor.ui.widgets.FieldPanel) ColourRampConfigPanel(com.sldeditor.colourramp.ColourRampConfigPanel)

Aggregations

ColorMapEntry (org.geotools.styling.ColorMapEntry)11 ColorMapEntryImpl (org.geotools.styling.ColorMapEntryImpl)5 ArrayList (java.util.ArrayList)3 ColorMapImpl (org.geotools.styling.ColorMapImpl)3 ColorMap (org.geotools.styling.ColorMap)2 Test (org.junit.Test)2 ColourRampConfigPanel (com.sldeditor.colourramp.ColourRampConfigPanel)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)1 FieldConfigColourMap (com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap)1 MultipleColourMapEntry (com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry)1 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1