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));
}
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);
}
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;
}
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();
}
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);
}
}
Aggregations