use of com.sldeditor.ui.detail.config.font.FieldConfigFont in project sldeditor by robward-scisys.
the class FieldConfigFontTest method testSetEnabled.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#internal_setEnabled(boolean)}.
* Test method for {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#isEnabled()}.
*/
@Test
public void testSetEnabled() {
// Value only, no attribute/expression dropdown
boolean valueOnly = true;
FieldConfigFont field = new FieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
// Text field will not have been created
boolean expectedValue = true;
field.internal_setEnabled(expectedValue);
assertFalse(field.isEnabled());
// Create text field
field.createUI();
field.createUI();
assertEquals(expectedValue, field.isEnabled());
expectedValue = false;
field.internal_setEnabled(expectedValue);
assertEquals(expectedValue, field.isEnabled());
// Has attribute/expression dropdown
valueOnly = false;
FieldConfigFont field2 = new FieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
// Text field will not have been created
expectedValue = true;
field.internal_setEnabled(expectedValue);
assertFalse(field2.isEnabled());
// Create text field
field2.createUI();
assertEquals(expectedValue, field2.isEnabled());
expectedValue = false;
field.internal_setEnabled(expectedValue);
// Actual value is coming from the attribute panel, not the text field
assertEquals(!expectedValue, field2.isEnabled());
}
use of com.sldeditor.ui.detail.config.font.FieldConfigFont in project sldeditor by robward-scisys.
the class FieldConfigFontTest method testRevertToDefaultValue.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#revertToDefaultValue()}. Test
* method for
* {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#setDefaultValue(java.lang.String)}.
*/
@Test
public void testRevertToDefaultValue() {
boolean valueOnly = true;
FieldConfigFont field = new FieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
field.revertToDefaultValue();
String actualValue = field.getStringValue();
assertNull(actualValue);
field.createUI();
String expectedDefaultValue = fontFamilies[2];
field.setDefaultValue(expectedDefaultValue);
field.revertToDefaultValue();
actualValue = field.getStringValue();
assertTrue(expectedDefaultValue.compareTo(actualValue) == 0);
}
use of com.sldeditor.ui.detail.config.font.FieldConfigFont 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.ui.detail.config.font.FieldConfigFont in project sldeditor by robward-scisys.
the class ReadPanelConfig method addField.
/**
* Adds the field.
*
* @param localisationClass the localisation class
* @param panelId the panel id
* @param groupConfig the group config
* @param xmlFieldConfig the xml field config
*/
private void addField(Class<?> localisationClass, Class<?> panelId, GroupConfig groupConfig, XMLFieldConfigData xmlFieldConfig) {
FieldIdEnum id = xmlFieldConfig.getId();
String label = getLocalisedText(localisationClass, xmlFieldConfig.getLabel());
boolean valueOnly = xmlFieldConfig.getValueOnly();
String defaultValue = xmlFieldConfig.getDefault();
boolean multipleValues = xmlFieldConfig.getMultipleValues();
FieldConfigCommonData commonData = new FieldConfigCommonData(panelId, id, label, valueOnly, isRasterSymbol, multipleValues);
if (xmlFieldConfig instanceof XMLFieldConfigString) {
XMLFieldConfigString xmlStringFieldConfig = (XMLFieldConfigString) xmlFieldConfig;
FieldConfigString stringConfig = new FieldConfigString(commonData, getLocalisedText(localisationClass, xmlStringFieldConfig.getButtonText()));
stringConfig.setSuppressUpdatesOnSet(xmlStringFieldConfig.getSuppressUpdateOnSet());
groupConfig.addField(stringConfig);
String defaultValueObj = ConfigDefaultFactory.getString(defaultValue);
if (defaultValueObj != null) {
stringConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigColourMap) {
commonData.setValueOnly(true);
FieldConfigColourMap colourMapConfig = new FieldConfigColourMap(commonData);
groupConfig.addField(colourMapConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigFeatureTypeConstraint) {
FieldConfigFeatureTypeConstraint stringConfig = new FieldConfigFeatureTypeConstraint(commonData);
groupConfig.addField(stringConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigSortBy) {
FieldConfigSortBy sortByConfig = new FieldConfigSortBy(commonData);
groupConfig.addField(sortByConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigDSProperties) {
FieldConfigDSProperties dsPropertiesConfig = new FieldConfigDSProperties(commonData);
groupConfig.addField(dsPropertiesConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigGeometryField) {
FieldConfigGeometryField geometryFieldConfig = new FieldConfigGeometryField(commonData);
DataSourceInterface dataSource = DataSourceFactory.getDataSource();
if (dataSource != null) {
dataSource.addListener(geometryFieldConfig);
}
groupConfig.addField(geometryFieldConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigFont) {
FieldConfigFont fontConfig = new FieldConfigFont(commonData);
groupConfig.addField(fontConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigInlineFeature) {
FieldConfigInlineFeature inlineFeatureConfig = new FieldConfigInlineFeature(commonData);
groupConfig.addField(inlineFeatureConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigFontPreview) {
FieldConfigFontPreview fontPreviewConfig = new FieldConfigFontPreview(commonData);
groupConfig.addField(fontPreviewConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigTransformation) {
XMLFieldConfigTransformation xmlTransformationFieldConfig = (XMLFieldConfigTransformation) xmlFieldConfig;
FieldConfigTransformation transformationConfig = new FieldConfigTransformation(commonData, getLocalisedText(localisationClass, xmlTransformationFieldConfig.getEditButtonText()), getLocalisedText(localisationClass, xmlTransformationFieldConfig.getClearButtonText()));
groupConfig.addField(transformationConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigGeometry) {
XMLFieldConfigGeometry xmlGeometryFieldConfig = (XMLFieldConfigGeometry) xmlFieldConfig;
FieldConfigGeometry geometryConfig = new FieldConfigGeometry(commonData, getLocalisedText(localisationClass, xmlGeometryFieldConfig.getButtonText()));
groupConfig.addField(geometryConfig);
String defaultValueObj = ConfigDefaultFactory.getString(defaultValue);
if (defaultValueObj != null) {
geometryConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigBoolean) {
FieldConfigBoolean boolConfig = new FieldConfigBoolean(commonData);
groupConfig.addField(boolConfig);
Boolean defaultValueObj = ConfigDefaultFactory.getBoolean(defaultValue);
if (defaultValueObj != null) {
boolConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigDouble) {
FieldConfigDouble doubleConfig = new FieldConfigDouble(commonData);
XMLFieldConfigDouble xmlDouble = (XMLFieldConfigDouble) xmlFieldConfig;
doubleConfig.setDefaultValue(xmlDouble.getDefaultValue());
doubleConfig.setConfig((xmlDouble.getMinValue() == null) ? Double.NEGATIVE_INFINITY : xmlDouble.getMinValue().doubleValue(), (xmlDouble.getMaxValue() == null) ? Double.POSITIVE_INFINITY : xmlDouble.getMaxValue().doubleValue(), xmlDouble.getStepSize(), xmlDouble.getNoOfDecimalPlaces());
groupConfig.addField(doubleConfig);
Double defaultValueObj = ConfigDefaultFactory.getDouble(defaultValue);
if (defaultValueObj != null) {
doubleConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigInteger) {
XMLFieldConfigInteger xmlInteger = (XMLFieldConfigInteger) xmlFieldConfig;
FieldConfigInteger integerConfig = new FieldConfigInteger(commonData);
integerConfig.setDefaultValue(xmlInteger.getDefaultValue());
integerConfig.setConfig(xmlInteger.getMinValue(), xmlInteger.getMaxValue(), xmlInteger.getStepSize());
groupConfig.addField(integerConfig);
Integer defaultValueObj = ConfigDefaultFactory.getInteger(defaultValue);
if (defaultValueObj != null) {
integerConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigColour) {
FieldConfigColour colourConfig = new FieldConfigColour(commonData);
groupConfig.addField(colourConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigSlider) {
XMLFieldConfigSlider xmlSlider = (XMLFieldConfigSlider) xmlFieldConfig;
FieldConfigSlider sliderConfig = new FieldConfigSlider(commonData);
sliderConfig.setDefaultValue(xmlSlider.getDefaultValue());
groupConfig.addField(sliderConfig);
Double defaultValueObj = ConfigDefaultFactory.getDouble(defaultValue);
if (defaultValueObj != null) {
sliderConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
} else if (xmlFieldConfig instanceof XMLFieldConfigSymbolType) {
FieldConfigSymbolType fillSymbolConfig = new FieldConfigSymbolType(commonData);
groupConfig.addField(fillSymbolConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigEnum) {
FieldConfigEnum valueConfig = new FieldConfigEnum(commonData);
XMLFieldConfigEnumValueList valueList = ((XMLFieldConfigEnum) xmlFieldConfig).getValueList();
List<SymbolTypeConfig> configList = readValueListConfig(localisationClass, panelId, valueList);
valueConfig.addConfig(configList);
String defaultValueObj = ConfigDefaultFactory.getString(defaultValue);
if (defaultValueObj != null) {
valueConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
groupConfig.addField(valueConfig);
} else if (xmlFieldConfig instanceof XMLFieldConfigMapUnit) {
FieldConfigMapUnits valueConfig = new FieldConfigMapUnits(commonData);
String defaultValueObj = ConfigDefaultFactory.getString(defaultValue);
if (defaultValueObj != null) {
valueConfig.setDefaultValue(defaultValueObj);
defaultFieldMap.put(id, defaultValueObj);
}
groupConfig.addField(valueConfig);
}
}
use of com.sldeditor.ui.detail.config.font.FieldConfigFont in project sldeditor by robward-scisys.
the class FieldConfigFontTest method testCreateCopy.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
*/
@Test
public void testCreateCopy() {
boolean valueOnly = true;
class TestFieldConfigFont extends FieldConfigFont {
public TestFieldConfigFont(FieldConfigCommonData commonData) {
super(commonData);
}
public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
return createCopy(fieldConfigBase);
}
}
TestFieldConfigFont field = new TestFieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
FieldConfigFont copy = (FieldConfigFont) field.callCreateCopy(null);
assertNull(copy);
copy = (FieldConfigFont) field.callCreateCopy(field);
assertEquals(field.getFieldId(), copy.getFieldId());
assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Aggregations