use of org.geotoolkit.display2d.ext.text.DefaultTextTemplate in project geotoolkit by Geomatys.
the class DecorationXMLParser method parseDecoration.
private static void parseDecoration(final DecorationExtension deco, final Element decoNode) {
final String type = decoNode.getAttribute(ATT_NAME);
final Map<String, String> params = parseParameters(decoNode);
final BackgroundTemplate background = parseBackground(decoNode);
final Map<String, Object> parsed = new HashMap<>();
// offsets are the same for everyone
parsed.put(PARAM_OFFSET_X, parseInteger(params.get(PARAM_OFFSET_X), 0));
parsed.put(PARAM_OFFSET_Y, parseInteger(params.get(PARAM_OFFSET_Y), 0));
if (type.equalsIgnoreCase(TYPE_COMPAS)) {
final NorthArrowTemplate template = new DefaultNorthArrowTemplate(background, parseURL(params.get(PARAM_SOURCE), DecorationXMLParser.class.getResource("/org/geotoolkit/icon/boussole.svg")), new Dimension(parseInteger(params.get(PARAM_WIDTH), 100), parseInteger(params.get(PARAM_HEIGHT), 100)));
parsed.put(ATT_NAME, TYPE_COMPAS);
parsed.put(TYPE_COMPAS, template);
parsed.put(PARAM_POSITION, parsePosition(params.get(PARAM_POSITION), SwingConstants.NORTH_EAST));
} else if (type.equalsIgnoreCase(TYPE_GRID)) {
CoordinateReferenceSystem crs = null;
if (params.get(PARAM_CRS) != null) {
try {
crs = CRS.forCode(params.get(PARAM_CRS));
} catch (FactoryException ex) {
LOGGER.log(Level.WARNING, null, ex);
}
}
Stroke mainLineStroke = new BasicStroke(2);
Paint mainLinePaint = Color.DARK_GRAY;
Font mainLineFont = new Font("serial", Font.BOLD, 14);
Stroke secondLineStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, new float[] { 5, 5 }, 0);
Paint secondLinePaint = Color.GRAY;
Font secondLineFont = new Font("serial", Font.BOLD, 14);
NodeList nodes = decoNode.getElementsByTagName(TAG_MAIN);
for (int i = 0, n = nodes.getLength(); i < n; i++) {
final Element sub = (Element) nodes.item(i);
final Map<String, String> subParams = parseParameters(sub);
mainLineStroke = parseStroke(subParams.get(PARAM_STROKE_WIDTH), subParams.get(PARAM_STROKE_DASHES));
mainLinePaint = parseColor(subParams.get(PARAM_STROKE_COLOR), subParams.get(PARAM_STROKE_OPACITY), Color.DARK_GRAY);
mainLineFont = parseFont(subParams.get(PARAM_FONT));
}
nodes = decoNode.getElementsByTagName(TAG_SECOND);
for (int i = 0, n = nodes.getLength(); i < n; i++) {
final Element sub = (Element) nodes.item(i);
final Map<String, String> subParams = parseParameters(sub);
secondLineStroke = parseStroke(subParams.get(PARAM_STROKE_WIDTH), subParams.get(PARAM_STROKE_DASHES));
secondLinePaint = parseColor(subParams.get(PARAM_STROKE_COLOR), subParams.get(PARAM_STROKE_OPACITY), Color.DARK_GRAY);
secondLineFont = parseFont(subParams.get(PARAM_FONT));
}
final GridTemplate template = new DefaultGridTemplate(crs, mainLineStroke, mainLinePaint, secondLineStroke, secondLinePaint, mainLineFont, mainLinePaint, 0, new Color(0f, 0f, 0f, 0f), secondLineFont, secondLinePaint, 0, new Color(0f, 0f, 0f, 0f));
parsed.put(ATT_NAME, TYPE_GRID);
parsed.put(TYPE_GRID, template);
} else if (type.equalsIgnoreCase(TYPE_IMAGE)) {
final URL source = parseURL(params.get(PARAM_SOURCE), null);
BufferedImage buffer;
try {
buffer = ImageIO.read(source);
} catch (Exception ex) {
LOGGER.log(Level.WARNING, null, ex);
buffer = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
}
final ImageTemplate template = new DefaultImageTemplate(background, buffer);
parsed.put(ATT_NAME, TYPE_IMAGE);
parsed.put(TYPE_IMAGE, template);
parsed.put(PARAM_POSITION, parsePosition(params.get(PARAM_POSITION), SwingConstants.NORTH_WEST));
} else if (type.equalsIgnoreCase(TYPE_LEGEND)) {
final LegendTemplate template = new DefaultLegendTemplate(background, parseInteger(params.get(PARAM_GAP), 2), new Dimension(parseInteger(params.get(PARAM_GLYPH_WIDTH), 30), parseInteger(params.get(PARAM_GLYPH_HEIGHT), 20)), parseFont(params.get(PARAM_SECOND_FONT)), parseBoolean(params.get(PARAM_LAYER_NAME), true), parseFont(params.get(PARAM_MAIN_FONT)));
parsed.put(ATT_NAME, TYPE_LEGEND);
parsed.put(TYPE_LEGEND, template);
parsed.put(PARAM_POSITION, parsePosition(params.get(PARAM_POSITION), SwingConstants.EAST));
} else if (type.equalsIgnoreCase(TYPE_SCALE_GRAPHIC)) {
String unit = params.get(PARAM_UNIT);
if (unit == null || unit.isEmpty()) {
unit = "km";
}
final ScaleBarTemplate template = new DefaultScaleBarTemplate(background, new Dimension(parseInteger(params.get(PARAM_WIDTH), 250), parseInteger(params.get(PARAM_HEIGHT), 30)), 10, false, 5, NumberFormat.getNumberInstance(), Color.BLACK, Color.BLACK, Color.WHITE, 3, true, false, new Font("Serial", Font.PLAIN, 12), true, Units.valueOf(unit));
parsed.put(ATT_NAME, TYPE_SCALE_GRAPHIC);
parsed.put(TYPE_SCALE_GRAPHIC, template);
parsed.put(PARAM_POSITION, parsePosition(params.get(PARAM_POSITION), SwingConstants.SOUTH_WEST));
} else if (type.equalsIgnoreCase(TYPE_SCALE_NUMERIC)) {
// not handle yet
} else if (type.equalsIgnoreCase(TYPE_TEXT)) {
String txt = params.get(PARAM_TEXT);
if (txt == null) {
txt = "";
}
final TextTemplate template = new DefaultTextTemplate(background, txt);
parsed.put(ATT_NAME, TYPE_TEXT);
parsed.put(TYPE_TEXT, template);
parsed.put(PARAM_POSITION, parsePosition(params.get(PARAM_POSITION), SwingConstants.SOUTH_WEST));
}
deco.decorations.add(parsed);
}
Aggregations