use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class FieldConfigDoubleTest method testCreateCopy.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDouble#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
*/
@Test
public void testCreateCopy() {
boolean valueOnly = true;
class TestFieldConfigDouble extends FieldConfigDouble {
public TestFieldConfigDouble(FieldConfigCommonData commonData) {
super(commonData);
}
public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
return createCopy(fieldConfigBase);
}
}
TestFieldConfigDouble field = new TestFieldConfigDouble(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly));
FieldConfigDouble copy = (FieldConfigDouble) field.callCreateCopy(null);
assertNull(copy);
copy = (FieldConfigDouble) field.callCreateCopy(field);
assertEquals(field.getFieldId(), copy.getFieldId());
assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
assertEquals(field.isValueOnly(), copy.isValueOnly());
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class FieldConfigDoubleTest method testGenerateExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDouble#generateExpression()}. Test method
* for
* {@link com.sldeditor.ui.detail.config.FieldConfigDouble#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDouble#populateField(java.lang.Double)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigDouble#setTestValue(com.sldeditor.ui.detail.config.FieldId, double)}.
* Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDouble#getDoubleValue()}.
*/
@Test
public void testGenerateExpression() {
boolean valueOnly = true;
FieldConfigDouble field = new FieldConfigDouble(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly));
double expectedValue = 1.0;
field.populateField(expectedValue);
double actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.001);
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.001);
field.populateExpression(null);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.001);
field.createUI();
field.populateField(expectedValue);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue) < 0.001);
double expectedValue2 = 0.134;
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue2) < 0.001);
Integer expectedValue3a = Integer.valueOf(42);
field.populateExpression(expectedValue3a);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue3a) < 0.001);
Long expectedValue3b = Long.valueOf(4567);
field.populateExpression(expectedValue3b);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue3b) < 0.001);
Double expectedValue3c = Double.valueOf(42.12);
field.populateExpression(expectedValue3c);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue3c) < 0.001);
double expectedValue3d = 698.7;
String expectedValue3dString = String.valueOf(expectedValue3d);
field.populateExpression(expectedValue3dString);
actualValue = field.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedValue3d) < 0.001);
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class ColourMapEntryPanel method createUI.
/**
* Creates the UI.
*
* @param panelId the panel id
*/
private void createUI(Class<?> panelId) {
TitledBorder title = BorderFactory.createTitledBorder(Localisation.getString(FieldConfigBase.class, "ColourMapEntryPanel.title"));
setBorder(title);
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
label = new FieldConfigString(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_LABEL, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.label"), true, true, true), null);
label.createUI();
label.addDataChangedListener(this);
fieldList.add(label);
add(label.getPanel());
colour = new FieldConfigColour(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_COLOUR, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.colour"), false, true, true));
colour.createUI();
colour.addDataChangedListener(this);
fieldList.add(colour);
add(colour.getPanel());
opacity = new FieldConfigSlider(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_OPACITY, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.opacity"), false, true, true));
opacity.createUI();
opacity.addDataChangedListener(this);
fieldList.add(opacity);
add(opacity.getPanel());
quantity = new FieldConfigDouble(new FieldConfigCommonData(panelId, FieldIdEnum.RASTER_COLOURMAP_ENTRY_QUANTITY, Localisation.getField(FieldConfigBase.class, "ColourMapEntryPanel.quantity"), false, true, true));
quantity.createUI();
quantity.addDataChangedListener(this);
fieldList.add(quantity);
add(quantity.getPanel());
JPanel buttonPanel = new JPanel();
//
// Apply button
//
applyButton = new JButton(Localisation.getString(FieldConfigBase.class, "common.apply"));
applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (parentObj != null) {
ColourMapData data = new ColourMapData();
data.setLabel(label.getStringValue());
data.setColour(colour.getColourExpression());
data.setOpacity(opacity.getExpression());
data.setQuantity(quantity.getExpression());
parentObj.colourMapEntryUpdated(data);
}
}
});
buttonPanel.add(applyButton);
//
// Cancel button
//
cancelButton = new JButton(Localisation.getString(FieldConfigBase.class, "common.cancel"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
buttonPanel.add(cancelButton);
add(buttonPanel);
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class VOGeoServerLabelling method includeValue.
/**
* Find out whether to include value based on the value of another field.
*
* @param field the field
* @return true, if successful
*/
private boolean includeValue(FieldIdEnum field) {
DefaultOverride override = overrideMap.get(field);
if (override != null) {
String value = null;
FieldConfigBase fieldConfig = fieldConfigManager.get(override.getField());
if (fieldConfig instanceof FieldConfigBoolean) {
value = String.valueOf(fieldConfigVisitor.getBoolean(override.getField()));
} else if (fieldConfig instanceof FieldConfigInteger) {
value = String.valueOf(fieldConfigVisitor.getInteger(override.getField()));
} else if (fieldConfig instanceof FieldConfigDouble) {
value = String.valueOf(fieldConfigVisitor.getDouble(override.getField()));
} else if (fieldConfig instanceof FieldConfigEnum) {
value = String.valueOf(fieldConfigVisitor.getComboBox(override.getField()));
} else {
ConsoleManager.getInstance().error(this, "Unsupported field type : " + field + " " + fieldConfig.getClass().getName());
}
if (value != null) {
for (String legalValue : override.getLegalValues()) {
if (value.compareToIgnoreCase(legalValue) == 0) {
return true;
}
}
}
}
return false;
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class FilterManager method convertParameters.
/**
* Convert function parameters to ui components.
*
* @param panelId the panel id
* @param functionName the function name
* @return the list of ui components to display
*/
@Override
public List<GroupConfigInterface> convertParameters(Class<?> panelId, FunctionName functionName) {
List<GroupConfigInterface> groupConfigList = new ArrayList<GroupConfigInterface>();
if (functionName != null) {
GroupConfig groupConfig = new GroupConfig();
StringBuilder funcPrototypeStringBuilder = new StringBuilder();
funcPrototypeStringBuilder.append(functionName.getName());
funcPrototypeStringBuilder.append("(");
int argCount = functionName.getArgumentCount();
if (functionName.getArgumentCount() < 0) {
argCount *= -1;
}
for (int index = 0; index < argCount; index++) {
int argIndex = index;
if (argIndex >= functionName.getArguments().size()) {
argIndex = functionName.getArguments().size() - 1;
}
String label = functionName.getArgumentNames().get(argIndex);
Parameter<?> parameterType = functionName.getArguments().get(argIndex);
boolean valueOnly = false;
FieldIdEnum id = FieldIdEnum.UNKNOWN;
if (index > 0) {
funcPrototypeStringBuilder.append(", ");
}
Class<?> type = parameterType.getType();
funcPrototypeStringBuilder.append(type.getSimpleName());
FieldConfigBase fieldConfig = null;
FieldConfigCommonData commonData = new FieldConfigCommonData(panelId, id, label, valueOnly);
if (type == java.lang.Number.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Double.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Float.class) {
fieldConfig = new FieldConfigDouble(commonData);
} else if (type == Integer.class) {
fieldConfig = new FieldConfigInteger(commonData);
} else if (type == Long.class) {
fieldConfig = new FieldConfigInteger(commonData);
} else if (type == String.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Object.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Boolean.class) {
fieldConfig = new FieldConfigBoolean(commonData);
} else if (type == Geometry.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == org.opengis.geometry.Geometry.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == LineString.class) {
fieldConfig = new FieldConfigGeometry(commonData, null);
} else if (type == Date.class) {
fieldConfig = new FieldConfigDate(commonData);
} else if (type == Class.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Classifier.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Unit.class) {
fieldConfig = new FieldConfigMapUnits(commonData);
} else if (type == Comparable.class) {
fieldConfig = new FieldConfigString(commonData, null);
} else if (type == Color.class) {
fieldConfig = new FieldConfigColour(commonData);
} else {
ConsoleManager.getInstance().error(this, Localisation.getField(ExpressionPanelv2.class, "FilterManager.error1") + type.getName());
}
groupConfig.addField(fieldConfig);
}
funcPrototypeStringBuilder.append(")");
groupConfig.setLabel(funcPrototypeStringBuilder.toString());
groupConfigList.add(groupConfig);
}
return groupConfigList;
}
Aggregations