Path: blob/master/SLICK_HOME/src/org/newdawn/slick/svg/Diagram.java
1462 views
package org.newdawn.slick.svg;12import java.util.ArrayList;3import java.util.HashMap;45/**6* A diagram read from SVG containing multiple figures7*8* @author kevin9*/10public class Diagram {11/** The figures in the diagram */12private ArrayList figures = new ArrayList();13/** The pattern definitions */14private HashMap patterns = new HashMap();15/** The linear gradients defined within the diagram */16private HashMap gradients = new HashMap();17/** The figures mapping */18private HashMap figureMap = new HashMap();1920/** The width of the diagram */21private float width;22/** The height of the diagram */23private float height;2425/**26* Create a new empty diagram27*28* @param width The width of the diagram29* @param height The height of the diagram30*/31public Diagram(float width, float height) {32this.width = width;33this.height = height;34}3536/**37* Get the width of the diagram38*39* @return The width of the diagram40*/41public float getWidth() {42return width;43}4445/**46* Get the height of the diagram47*48* @return The height of the diagram49*/50public float getHeight() {51return height;52}5354/**55* Add a pattern definition basd on a image56*57* @param name The name of the pattern58* @param href The href to the image specified in the doc59*/60public void addPatternDef(String name, String href) {61patterns.put(name, href);62}6364/**65* Add gradient to the diagram66*67* @param name The name of the gradient68* @param gradient The gradient to be added69*/70public void addGradient(String name, Gradient gradient) {71gradients.put(name, gradient);72}7374/**75* Get a pattern definition from the diagram76*77* @param name The name of the pattern78* @return The href to the image that was specified for the given pattern79*/80public String getPatternDef(String name) {81return (String) patterns.get(name);82}8384/**85* Get the gradient defined in this document86*87* @param name The name of the gradient88* @return The gradient definition89*/90public Gradient getGradient(String name) {91return (Gradient) gradients.get(name);92}9394/**95* Get the names of the patterns defined96*97* @return The names of the pattern98*/99public String[] getPatternDefNames() {100return (String[]) patterns.keySet().toArray(new String[0]);101}102103/**104* Get a figure by a given ID105*106* @param id The ID of the figure107* @return The figure with the given ID108*/109public Figure getFigureByID(String id) {110return (Figure) figureMap.get(id);111}112113/**114* Add a figure to the diagram115*116* @param figure The figure to add117*/118public void addFigure(Figure figure) {119figures.add(figure);120figureMap.put(figure.getData().getAttribute(NonGeometricData.ID), figure);121122String fillRef = figure.getData().getAsReference(NonGeometricData.FILL);123Gradient gradient = getGradient(fillRef);124if (gradient != null) {125if (gradient.isRadial()) {126for (int i=0;i<InkscapeLoader.RADIAL_TRIANGULATION_LEVEL;i++) {127figure.getShape().increaseTriangulation();128}129}130}131}132133/**134* Get the number of figures in the diagram135*136* @return The number of figures in the diagram137*/138public int getFigureCount() {139return figures.size();140}141142/**143* Get the figure at a given index144*145* @param index The index of the figure to retrieve146* @return The figure at the given index147*/148public Figure getFigure(int index) {149return (Figure) figures.get(index);150}151152/**153* Remove a figure from the diagram154*155* @param figure The figure to be removed156*/157public void removeFigure(Figure figure) {158figures.remove(figure);159figureMap.remove(figure.getData().getAttribute("id"));160}161}162163164