use of com.sldeditor.common.xml.ui.FieldIdEnum 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 com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class FieldConfigPopulationTest method testIsTreeDataUpdated.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#isTreeDataUpdated()}. Test method
* for {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#resetTreeDataUpdated()}.
*/
@Test
public void testIsTreeDataUpdated() {
FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
FieldConfigString stringField = new FieldConfigString(new FieldConfigCommonData(Geometry.class, fieldId, "label", true), "button text");
stringField.createUI();
fieldConfigManager.add(fieldId, stringField);
FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
assertFalse(obj.isTreeDataUpdated());
// Set data
String expectedValue = "test string";
obj.populateTextField(fieldId, expectedValue);
assertTrue(expectedValue.compareTo(obj.getText(fieldId)) == 0);
assertFalse(obj.isTreeDataUpdated());
// Simulate a key being pressed
expectedValue = "test string1";
stringField.populateField(expectedValue);
// Data is different so flag should have changed
assertTrue(expectedValue.compareTo(obj.getText(fieldId)) == 0);
assertTrue(obj.isTreeDataUpdated());
obj.resetTreeDataUpdated();
assertFalse(obj.isTreeDataUpdated());
// Populate the same data again and the flag should not have changed
obj.populateTextField(fieldId, expectedValue);
assertTrue(expectedValue.compareTo(obj.getText(fieldId)) == 0);
assertFalse(obj.isTreeDataUpdated());
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class FieldConfigPopulationTest method testFont.
/**
* 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));
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);
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class ExpressionSubPanel method displayExpression.
/**
* Display expression.
*
* @param node the node
*/
private void displayExpression(ExpressionNode node) {
if (panelLiteral.getComponentCount() == 2) {
panelLiteral.remove(1);
}
if (node == null) {
return;
}
fieldConfig = PanelField.getField(ExpressionPanelv2.class, "ExpressionSubPanel.value", node.getType());
if (fieldConfig != null) {
fieldConfig.createUI();
fieldConfig.addDataChangedListener(new UpdateSymbolInterface() {
@Override
public void dataChanged(FieldIdEnum changedField) {
buttonGroup.setSelected(rdbtnLiteral.getModel(), true);
updateButtonState(true);
}
});
panelLiteral.add(fieldConfig.getPanel());
// Reset the fields
dataSourceAttributePanel.setAttribute(null);
functionPanel.setFunction(null);
dataSourceAttributePanel.setDataType(node.getType());
Expression expression = node.getExpression();
if (expression instanceof AttributeExpressionImpl) {
dataSourceAttributePanel.setAttribute(expression);
buttonGroup.setSelected(rdbtnAttribute.getModel(), true);
} else if (expression instanceof EnvFunction) {
envVarField.setEnvironmentVariable(expression);
buttonGroup.setSelected(rdbtnEnvVar.getModel(), true);
} else if (expression instanceof FunctionExpressionImpl) {
functionPanel.setFunction(expression);
buttonGroup.setSelected(rdbtnFunction.getModel(), true);
} else {
fieldConfig.populate(expression);
buttonGroup.setSelected(rdbtnLiteral.getModel(), true);
}
}
Dimension boxSize = box.getPreferredSize();
setPreferredSize(boxSize);
revalidate();
}
use of com.sldeditor.common.xml.ui.FieldIdEnum in project sldeditor by robward-scisys.
the class BasePanel method handleFieldState.
/**
* Handle field state for a specific combo box field.
*
* @param fieldId the field id
*/
protected void handleFieldState(FieldIdEnum fieldId) {
FieldConfigBase fieldConfig = fieldConfigManager.get(fieldId);
if (fieldConfig != null) {
if (fieldConfig instanceof FieldConfigEnum) {
FieldConfigEnum fieldEnum = (FieldConfigEnum) fieldConfig;
Map<FieldIdEnum, Boolean> stateMap = fieldEnum.getFieldEnableState();
if (stateMap != null) {
for (FieldIdEnum fieldKey : stateMap.keySet()) {
enableField(fieldKey, stateMap.get(fieldKey));
}
}
}
} else {
ConsoleManager.getInstance().error(this, String.format("handleFieldState - %s : %s", Localisation.getString(StandardPanel.class, "StandardPanel.unknownField"), fieldId));
}
}
Aggregations