com.googlecode.blaisemath.svg.reader.SvgGroupReader Maven / Gradle / Ivy
package com.googlecode.blaisemath.svg.reader;
/*-
* #%L
* blaise-svg
* --
* Copyright (C) 2014 - 2020 Elisha Peterson
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import com.googlecode.blaisemath.graphics.Graphic;
import com.googlecode.blaisemath.graphics.GraphicComposite;
import com.googlecode.blaisemath.style.AttributeSet;
import com.googlecode.blaisemath.svg.xml.*;
import java.awt.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Reads group of SVG content as Blaise graphics content. Supported SVG types include:
*
* - {@link SvgRect}, {@link SvgEllipse}, {@link SvgCircle}, {@link SvgPolygon}
* - {@link SvgLine}, {@link SvgPolyline}
* - {@link SvgPath}
* - {@link SvgImage}
* - {@link SvgText}
* - {@link SvgGroup}
*
* @author Elisha Peterson
*/
public final class SvgGroupReader extends SvgReader> {
private static final Logger LOG = Logger.getLogger(SvgGroupReader.class.getName());
@Override
protected List createPrimitive(SvgGroup el) {
if (el == null) {
throw new SvgReadException("Null SVG element");
}
return el.elements;
}
@Override
protected Graphic createGraphic(List prims, AttributeSet style) {
GraphicComposite res = new GraphicComposite<>();
res.setStyle(style);
for (SvgElement p : prims) {
try {
Graphic g = readGraphic(p);
g.setDefaultTooltip(p.id);
res.addGraphic(g);
} catch (SvgReadException e) {
LOG.log(Level.SEVERE, "Graphic read error", e);
}
}
return res;
}
public static Graphic readGraphic(SvgElement el) throws SvgReadException {
for (SvgReader r : SvgReader.readers()) {
if (r.canRead(el)) {
return r.read(el);
}
}
throw new SvgReadException("Unsupported: "+el);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy