use of org.opengis.style.GraphicFill in project sldeditor by robward-scisys.
the class TextSymbol method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.symbols.EsriTextSymbolInterface#convert(org.geotools.styling.TextSymbolizer, com.google.gson.JsonElement, int)
*/
@SuppressWarnings("unused")
@Override
public void convert(TextSymbolizer textSymbolizer, JsonElement element, int transparency) {
if ((element != null) && (textSymbolizer != null)) {
JsonObject obj = element.getAsJsonObject();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
int breakCharacter = getInt(obj, TextSymbolKeys.BREAK_CHARACTER);
int textCase = getInt(obj, TextSymbolKeys.CASE);
double characterSpacing = getDouble(obj, TextSymbolKeys.CHARACTER_SPACING);
double characterWidth = getDouble(obj, TextSymbolKeys.CHARACTER_WIDTH);
double size = getDouble(obj, CommonSymbolKeys.SIZE);
size += MXDOptions.getInstance().getFontSizeFactor();
int direction = getInt(obj, TextSymbolKeys.DIRECTION);
double flipAngle = getDouble(obj, TextSymbolKeys.FLIP_ANGLE);
int horizontalAlignment = getInt(obj, TextSymbolKeys.HORIZONTAL_ALIGNMENT);
int verticalAlignment = getInt(obj, TextSymbolKeys.VERTICAL_ALIGNMENT);
double leading = getDouble(obj, TextSymbolKeys.LEADING);
double margin = getDouble(obj, TextSymbolKeys.MARGIN);
double maskSize = getDouble(obj, TextSymbolKeys.MASK_SIZE);
int maskStyle = getInt(obj, TextSymbolKeys.MASK_STYLE);
int position = getInt(obj, TextSymbolKeys.POSITION);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
double shadowXOffset = getDouble(obj, TextSymbolKeys.SHADOW_X_OFFSET);
double shadowYOffset = getDouble(obj, TextSymbolKeys.SHADOW_Y_OFFSET);
double wordSpacing = getDouble(obj, TextSymbolKeys.WORD_SPACING);
boolean CJKCharactersRotation = getBoolean(obj, TextSymbolKeys.CJK_CHARACTERS_ROTATION);
boolean clip = getBoolean(obj, TextSymbolKeys.CLIP);
boolean kerning = getBoolean(obj, TextSymbolKeys.KERNING);
boolean rightToLeft = getBoolean(obj, TextSymbolKeys.RIGHT_TO_LEFT);
boolean rotateWithTransform = getBoolean(obj, TextSymbolKeys.ROTATE_WITH_TRANSFORM);
boolean typeSetting = getBoolean(obj, TextSymbolKeys.TYPE_SETTING);
//
// Point placement
//
AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0), ff.literal(0));
Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
Expression rotationExpression = ff.literal(angle);
styleFactory.pointPlacement(anchorPoint, displacement, rotationExpression);
//
// Font
//
JsonElement fontElement = obj.get(TextSymbolKeys.FONT);
if (fontElement != null) {
JsonObject fontObj = fontElement.getAsJsonObject();
String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
boolean bold = getBoolean(fontObj, FontSymbolKeys.BOLD);
boolean italic = getBoolean(fontObj, FontSymbolKeys.ITALIC);
boolean strikeThrough = getBoolean(fontObj, FontSymbolKeys.STRIKE_THROUGH);
boolean underline = getBoolean(fontObj, FontSymbolKeys.UNDERLINE);
int weight = getInt(fontObj, FontSymbolKeys.FONT_WEIGHT);
int charset = getInt(fontObj, FontSymbolKeys.CHARSET);
int fontSize = getInt(obj, FontSymbolKeys.FONT_SIZE);
Expression fontFamilyExpression = ff.literal(fontName);
Expression fontSizeExpression = ff.literal(size);
String fontStyle = "normal";
if (italic) {
fontStyle = "italic";
}
Expression fontStyleExpression = ff.literal(fontStyle);
String fontWeight = "normal";
if (bold) {
fontWeight = "bold";
}
Expression fontWeightExpression = ff.literal(fontWeight);
Font font = styleFactory.createFont(fontFamilyExpression, fontStyleExpression, fontWeightExpression, fontSizeExpression);
textSymbolizer.setFont(font);
}
GraphicFill graphicFill = null;
Expression textColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression opacity = null;
if (transparency != 0) {
opacity = ff.literal(transparency / 255);
}
Fill fill = styleFactory.fill(graphicFill, textColour, opacity);
textSymbolizer.setFill(fill);
String geometryPropertyName = null;
textSymbolizer.setGeometryPropertyName(geometryPropertyName);
Expression shadowColour = getColour(obj.get(TextSymbolKeys.SHADOW_COLOUR));
}
}
use of org.opengis.style.GraphicFill in project sldeditor by robward-scisys.
the class SymbolTypeFactory method getFill.
/**
* Gets the fill for the selected value.
*
* @param graphicFill the graphic fill
* @param fieldConfigManager the field config manager
* @return the fill
*/
public Fill getFill(GraphicFill graphicFill, GraphicPanelFieldManager fieldConfigManager) {
Fill fill = null;
ValueComboBoxData obj = symbolTypeField.getSelectedValueObj();
if (obj != null) {
if (!isNone(obj.getKey())) {
FieldState panel = classMap.get(obj.getPanelId());
if (panel != null) {
fill = panel.getFill(graphicFill, fieldConfigManager);
}
}
}
return fill;
}
use of org.opengis.style.GraphicFill in project sldeditor by robward-scisys.
the class FieldConfigFilename method getFill.
/**
* Gets the fill.
*
* @param graphicFill the graphic fill
* @param fieldConfigManager the field config manager
* @return the fill
*/
@Override
public Fill getFill(GraphicFill graphicFill, GraphicPanelFieldManager fieldConfigManager) {
if (fieldConfigManager == null) {
return null;
}
Fill fill = null;
FieldConfigBase fieldConfig = fieldConfigManager.get(FieldIdEnum.OVERALL_OPACITY);
if (fieldConfig != null) {
Expression fillColour = null;
Expression fillColourOpacity = null;
if (fieldConfig instanceof FieldConfigColour) {
fillColourOpacity = ((FieldConfigColour) fieldConfig).getColourOpacityExpression();
} else {
fillColourOpacity = fieldConfig.getExpression();
}
fill = getStyleFactory().fill(graphicFill, fillColour, fillColourOpacity);
}
return fill;
}
use of org.opengis.style.GraphicFill in project sldeditor by robward-scisys.
the class FieldConfigMarkerTest method testGetFill.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#getFill(org.opengis.style.GraphicFill, com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
*/
@Test
public void testGetFill() {
// Test it with null values
boolean valueOnly = true;
ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILL, FieldIdEnum.FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_WIDTH);
ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKE, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
FieldConfigMarker field = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, null);
assertNull(field.getStringValue());
GraphicFill graphicFill = null;
GraphicPanelFieldManager fieldConfigManager = null;
Fill actualValue = field.getFill(graphicFill, fieldConfigManager);
assertNull(actualValue);
Class<?> panelId = PointFillDetails.class;
fieldConfigManager = new GraphicPanelFieldManager(panelId);
actualValue = field.getFill(graphicFill, fieldConfigManager);
assertNotNull(actualValue);
assertNull(actualValue.getColor());
assertNull(actualValue.getGraphicFill());
assertNull(actualValue.getOpacity());
// Test it with non null values
FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false));
colourField.createUI();
String expectedColourValue = "#012345";
colourField.setTestValue(null, expectedColourValue);
double expectedOpacityValue = 0.72;
FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false));
opacityField.createUI();
opacityField.populateField(expectedOpacityValue);
FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false));
symbolSelectionField.createUI();
fieldConfigManager.add(colourFieldId, colourField);
FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
fieldConfigManager.add(opacityFieldId, opacityField);
FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
FieldConfigMarker field2 = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, symbolSelectionFieldId);
actualValue = field2.getFill(graphicFill, fieldConfigManager);
assertNotNull(actualValue);
LiteralExpressionImpl literalExpressionImpl = (LiteralExpressionImpl) actualValue.getColor();
String actualColourString = literalExpressionImpl.toString();
assertTrue(actualColourString.compareTo(expectedColourValue) == 0);
StyleBuilder styleBuilder = new StyleBuilder();
graphicFill = styleBuilder.createGraphic();
actualValue = field2.getFill(graphicFill, fieldConfigManager);
assertNull(actualValue.getColor());
assertNull(actualValue.getOpacity());
}
use of org.opengis.style.GraphicFill in project sldeditor by robward-scisys.
the class FieldConfigFilenameTest method testGetFill.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename#getFill(org.opengis.style.GraphicFill, com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
*/
@Test
public void testGetFill() {
boolean valueOnly = true;
FieldConfigFilename field = new FieldConfigFilename(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
GraphicFill graphicFill = null;
GraphicPanelFieldManager fieldConfigManager = null;
assertNull(field.getFill(graphicFill, fieldConfigManager));
Class<?> panelId = PointFillDetails.class;
FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false));
colourField.createUI();
String expectedColourValue = "#012345";
colourField.setTestValue(FieldIdEnum.UNKNOWN, expectedColourValue);
double expectedOpacityValue = 0.72;
FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false));
opacityField.createUI();
opacityField.populateField(expectedOpacityValue);
FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false));
symbolSelectionField.createUI();
fieldConfigManager = new GraphicPanelFieldManager(panelId);
fieldConfigManager.add(colourFieldId, colourField);
FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
fieldConfigManager.add(opacityFieldId, opacityField);
FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
field.createUI();
StyleBuilder styleBuilder = new StyleBuilder();
graphicFill = styleBuilder.createGraphic();
Fill actualValue = field.getFill(graphicFill, fieldConfigManager);
assertTrue(actualValue.getOpacity().toString().compareTo(String.valueOf(expectedOpacityValue)) == 0);
}
Aggregations