// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.objects.structures; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Properties; import xaal.draw.StructureDraw; import xaal.objects.AddCoordinate; import xaal.objects.AddGraphicalPrimitive; import xaal.objects.StyledObject; import xaal.objects.Xaal; import xaal.objects.XaalObject; import xaal.objects.graphical.Coordinate; import xaal.objects.graphical.GraphicalPrimitive; import xaal.objects.graphical.Style; import xaal.util.EmptyIterator; /** * @author vkaravir * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class Structure extends XaalObject implements AddGraphicalPrimitive, StyledObject, AddCoordinate { private Properties props; private List graphics; // private String id; private String narrative; private String ref; private Coordinate coord; private Style style; public boolean visible; private Rectangle bounds; private List markers; /** * */ public Structure(Xaal xaalDoc) { super(xaalDoc); markers = new LinkedList(); visible = true; props = new Properties(); } /** * @param name * @param value */ public void addProperty(String name, String value) { props.setProperty(name, value); } /** * @param hotspotenabled * @param b */ public void addProperty(String name, boolean value) { addProperty(name, "" + value); } public boolean hasProperty(String name) { return props.containsKey(name); } public String getProperty(String name) { return props.getProperty(name, null); } public Enumeration getProperties() { return props.propertyNames(); } /** * @return Returns the narrative. */ public String getNarrative() { return narrative; } /** * @param n The narrative to set. */ public void setNarrative(String n) { narrative = n; } /** * @return Returns the graphics. */ public Iterator getGraphicals() { if (graphics == null) return new EmptyIterator(); return graphics.iterator(); } /** * @param graphical The graphics to set. */ public void setGraphical(List graphical) { this.graphics = graphical; } public void addGraphical(GraphicalPrimitive gp) { addGraphicalToList(gp); } /* public void addGraphical(GraphicalOperation go) { addGraphicalToList(go); }*/ private void addGraphicalToList(Object o) { if (graphics == null) graphics = new ArrayList(); graphics.add(o); } /** * @return Returns the id. */ /*public String getId() { return id; }*/ /** * @param id The id to set. */ /*public void setId(String id) { this.id = id; getXaal().addStructure(id, this); }*/ /** * @return Returns the ref. */ public String getRef() { return ref; } /** * @param ref The ref to set. */ public void setRef(String ref) { this.ref = ref; } /** * @return Returns the coord. */ public Coordinate getCoordinate() { return coord; } /** * @param coord The coord to set. */ public void setCoordinate(Coordinate coord) { this.coord = coord; } public void setCoordinate(int x, int y) { this.coord = new Coordinate(getXaal(), x, y); } public Style getStyle() { return style; } public void setStyle(Style style) { if (style.getId() != null) { getXaal().getDefs().addStyle(style); } this.style = style; } public void setVisible(boolean b) { visible = b; } public boolean isVisible() { return visible; } public void addCoordinate(Coordinate c) { this.setCoordinate(c); } public Rectangle getBounds() { if (this.bounds == null) { this.bounds = this.calculateBounds(); } return this.bounds; } private Rectangle calculateBounds() { if (this.graphics != null && this.graphics.size() > 0) { Rectangle r = null; for (Iterator iterator = graphics.iterator(); iterator.hasNext();) { GraphicalPrimitive next = (GraphicalPrimitive) iterator.next(); if (r == null) { r = new Rectangle(next.getBounds()); } else { r.add(next.getBounds()); } } return r; } else { Rectangle r = StructureDraw.drawStructure((DataStructure) this, getXaal()); return r; } } public void addMarker(Marker m) { markers.add(m); } public void removeMarker(Marker m) { markers.remove(m); } public Iterator getMarkers() { return markers.iterator(); } public List getGraphicalsList() { return new ArrayList(graphics); } }