[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/modellor TileModellor.java, 1.5, 1.
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15187/src/net/sourceforge/bprocessor/model/modellor Modified Files: TileModellor.java WindowModellor.java Modellor.java Cylinder.java ModelBathModellor.java LayerModellor.java Log Message: made abstract methods for getting and setting attributes and content to make extending modellors fool proof alongside with more generics Index: ModelBathModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/ModelBathModellor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ModelBathModellor.java 10 Apr 2007 20:59:01 -0000 1.1 --- ModelBathModellor.java 16 Apr 2007 15:54:42 -0000 1.2 *************** *** 8,12 **** import java.util.Collection; - import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; --- 8,11 ---- *************** *** 197,213 **** /** {@inheritDoc} */ ! public void setAttributes(List attributes) { update(space); } /** {@inheritDoc} */ ! public List getAttributes() { ! List res = new LinkedList(); ! res.add(new Attribute("Name", getName(), false)); ! res.add(new Attribute("Length", length, true)); ! res.add(new Attribute("Width", width, true)); ! res.add(new Attribute("Height", height, true)); ! res.add(new Attribute("Shaft-offset", shaftOffset, true)); ! return res; } --- 196,225 ---- /** {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Length"); ! if (a != null) { ! length = (Double)a.getValue(); ! } ! a = attributes.get("Width"); ! if (a != null) { ! width = (Double)a.getValue(); ! } ! a = attributes.get("Height"); ! if (a != null) { ! height = (Double)a.getValue(); ! } ! a = attributes.get("Shaft-offset"); ! if (a != null) { ! shaftOffset = (Double)a.getValue(); ! } update(space); } /** {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Length", length, true)); ! l.add(new Attribute("Width", width, true)); ! l.add(new Attribute("Height", height, true)); ! l.add(new Attribute("Shaft-offset", shaftOffset, true)); } *************** *** 223,235 **** /** {@inheritDoc} */ ! public void setContent(Map m) { space = (Space)m.get("Space"); } /** {@inheritDoc} */ ! public Map getContent() { ! Map what = new HashMap(); ! what.put("Space", space); ! return what; } --- 235,245 ---- /** {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { space = (Space)m.get("Space"); } /** {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { ! m.put("Space", space); } Index: WindowModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/WindowModellor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WindowModellor.java 10 Apr 2007 20:59:01 -0000 1.1 --- WindowModellor.java 16 Apr 2007 15:54:42 -0000 1.2 *************** *** 9,15 **** import java.util.ArrayList; import java.util.Collection; - import java.util.HashMap; import java.util.HashSet; - import java.util.LinkedList; import java.util.List; import java.util.Iterator; --- 9,13 ---- *************** *** 191,205 **** /** {@inheritDoc} */ ! public void setAttributes(List attributes) { ! framewidth = ((Double)((Attribute)attributes.get(1)).getValue()).doubleValue(); ! framedepth = ((Double)((Attribute)attributes.get(2)).getValue()).doubleValue(); ! offset = ((Double)((Attribute)attributes.get(3)).getValue()).doubleValue(); ! Iterator sit = Project.getInstance().getActiveSpace().getSurfaces().iterator(); ! Object value = ((Attribute)attributes.get(4)).getValue(); ! while (sit.hasNext()) { ! Project.getInstance().checkpoint(); ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(value)) { ! surface = s; } } --- 189,215 ---- /** {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Framewidth"); ! if (a != null) { ! framewidth = (Double)a.getValue(); ! } ! a = attributes.get("Framedepth"); ! if (a != null) { ! framedepth = (Double)a.getValue(); ! } ! a = attributes.get("Offset"); ! if (a != null) { ! offset = (Double)a.getValue(); ! } ! a = attributes.get("Surface"); ! if (a != null) { ! Iterator sit = Project.getInstance().getActiveSpace().getSurfaces().iterator(); ! Object value = a.getValue(); ! while (sit.hasNext()) { ! Project.getInstance().checkpoint(); ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(value)) { ! surface = s; ! } } } *************** *** 208,219 **** /** {@inheritDoc} */ ! public List getAttributes() { ! List res = new LinkedList(); ! res.add(new Attribute("Name", getName(), false)); ! res.add(new Attribute("Framewidth", new Double(framewidth))); ! res.add(new Attribute("Framedepth", new Double(framedepth))); ! res.add(new Attribute("Offset", new Double(offset))); ! res.add(new Attribute("Surface", surface)); ! return res; } --- 218,227 ---- /** {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Name", getName(), false)); ! l.add(new Attribute("Framewidth", new Double(framewidth))); ! l.add(new Attribute("Framedepth", new Double(framedepth))); ! l.add(new Attribute("Offset", new Double(offset))); ! l.add(new Attribute("Surface", surface)); } *************** *** 229,233 **** /** {@inheritDoc} */ ! public void setContent(Map m) { framewidth = ((Double)m.get("Framewidth")).doubleValue(); framedepth = ((Double)m.get("Framedepth")).doubleValue(); --- 237,241 ---- /** {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { framewidth = ((Double)m.get("Framewidth")).doubleValue(); framedepth = ((Double)m.get("Framedepth")).doubleValue(); *************** *** 239,251 **** /** {@inheritDoc} */ ! public Map getContent() { ! Map what = new HashMap(); ! what.put("Framewidth", new Double(framewidth)); ! what.put("Framedepth", new Double(framedepth)); ! what.put("Offset", new Double(offset)); ! what.put("Sign", new Integer(sign)); ! what.put("Space", space); ! what.put("Surface", surface); ! return what; } --- 247,257 ---- /** {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { ! m.put("Framewidth", new Double(framewidth)); ! m.put("Framedepth", new Double(framedepth)); ! m.put("Offset", new Double(offset)); ! m.put("Sign", new Integer(sign)); ! m.put("Space", space); ! m.put("Surface", surface); } Index: TileModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/TileModellor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TileModellor.java 16 Apr 2007 11:13:29 -0000 1.5 --- TileModellor.java 16 Apr 2007 15:54:42 -0000 1.6 *************** *** 11,14 **** --- 11,15 ---- import java.util.LinkedList; import java.util.List; + import java.util.Map; import org.apache.log4j.Logger; *************** *** 37,41 **** /** The width of the joint between tiles in mm*/ ! private static int jointSize = 3; private int height = 0; --- 38,42 ---- /** The width of the joint between tiles in mm*/ ! private int jointSize = 3; private int height = 0; *************** *** 50,54 **** /** tile thickness in mm */ ! private static int tileThickness = 8; /** --- 51,55 ---- /** tile thickness in mm */ ! private int tileThickness = 8; /** *************** *** 107,116 **** List<Surface> tiles = new LinkedList<Surface>(); CoordinateSystem insertPoint = cs.copy(); ! insertPoint.setOrigin(cs.unTranslate(new Vertex(minX + jointSize / 2000, ! minY + jointSize / 2000, 0))); Vertex orig = insertPoint.center(); if (height > 0) { ! maxY = height / 1000; } Vertex localHori = new Vertex(tileSize.getWidth() / 1000.0 + jointSize / 2000.0, 0, 0); --- 108,117 ---- List<Surface> tiles = new LinkedList<Surface>(); CoordinateSystem insertPoint = cs.copy(); ! insertPoint.setOrigin(cs.unTranslate(new Vertex(minX + jointSize / 2000.0, ! minY + jointSize / 2000.0, 0))); Vertex orig = insertPoint.center(); if (height > 0) { ! maxY = height / 1000.0; } Vertex localHori = new Vertex(tileSize.getWidth() / 1000.0 + jointSize / 2000.0, 0, 0); *************** *** 168,192 **** /** {@inheritDoc} */ @Override ! public List<Attribute> getAttributes() { ! List<Attribute> atrib = super.getAttributes(); ! ! atrib.add(new Attribute("Tilewidth", new Double(tileSize.width))); ! atrib.add(new Attribute("Tileheight", new Double(tileSize.height))); ! atrib.add(new Attribute("Joint width", new Double(jointSize))); ! atrib.add(new Attribute("Material", tileColor)); ! atrib.add(new Attribute("Surface", surface)); ! atrib.add(new Attribute("Setting height", new Double(height))); ! return atrib; } /** {@inheritDoc} */ @Override ! public void setAttributes(List<Attribute> attributes) { ! super.setAttributes(attributes); ! for (Attribute a : attributes) { ! if (a.getName().equals("Setting height")) { ! height = ((Double)a.getValue()).intValue(); ! update(null); ! } } } --- 169,266 ---- /** {@inheritDoc} */ @Override ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Tilewidth", new Double(tileSize.width))); ! l.add(new Attribute("Tileheight", new Double(tileSize.height))); ! l.add(new Attribute("Joint width", new Double(jointSize))); ! l.add(new Attribute("Material", tileColor)); ! l.add(new Attribute("Surface", surface)); ! l.add(new Attribute("Setting height", new Double(height))); } /** {@inheritDoc} */ @Override ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Tilewidth"); ! if (a != null) { ! tileSize.width = ((Double)a.getValue()).intValue(); ! } ! a = attributes.get("Tileheight"); ! if (a != null) { ! tileSize.height = ((Double)a.getValue()).intValue(); ! } ! a = attributes.get("Joint width"); ! if (a != null) { ! jointSize = ((Double)a.getValue()).intValue(); ! } ! a = attributes.get("Material"); ! if (a != null) { ! tileColor = (Material)a.getValue(); ! } ! a = attributes.get("Surface"); ! if (a != null) { ! surface = (Surface)a.getValue(); ! } ! a = attributes.get("Setting height"); ! if (a != null) { ! surface = (Surface)a.getValue(); ! } ! } ! ! /** ! * {@inheritDoc} ! */ ! @Override ! public void getSubContent(Map<String, Object> m) { ! m.put("Space", space); ! m.put("Surface", surface); ! m.put("startPoint", startPoint); ! m.put("tileColor", tileColor); ! m.put("jointSize", jointSize); ! m.put("tileWidth", tileSize.width); ! m.put("tileHeight", tileSize.height); ! m.put("tileThickness", tileThickness); ! m.put("height", height); ! } ! ! /** ! * {@inheritDoc} ! */ ! @Override ! public void setSubContent(Map<String, Object> m) { ! Object o = m.get("Space"); ! if (o != null) { ! space = (Space)o; ! } ! o = m.get("Surface"); ! if (o != null) { ! surface = (Surface)o; ! } ! o = m.get("startPoint"); ! if (o != null) { ! startPoint = (CoordinateSystem)o; ! } ! o = m.get("tileColor"); ! if (o != null) { ! tileColor = (Material)o; ! } ! o = m.get("jointSize"); ! if (o != null) { ! jointSize = (Integer)o; ! } ! o = m.get("tileWidth"); ! if (o != null) { ! tileSize.width = (Integer)o; ! } ! o = m.get("tileHeight"); ! if (o != null) { ! tileSize.height = (Integer)o; ! } ! o = m.get("tileThickness"); ! if (o != null) { ! tileThickness = (Integer)o; ! } ! o = m.get("height"); ! if (o != null) { ! height = (Integer)o; } } Index: Modellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/Modellor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Modellor.java 16 Apr 2007 09:08:46 -0000 1.9 --- Modellor.java 16 Apr 2007 15:54:42 -0000 1.10 *************** *** 10,14 **** import java.util.Collection; import java.util.HashMap; - import java.util.Iterator; import java.util.LinkedList; import java.util.List; --- 10,13 ---- *************** *** 79,82 **** --- 78,94 ---- return modellors.remove(m); } + + /** + * Static method for generating a map of attributes to lookup in + * @param attributes the list of attributes + * @return a map from name to attribute + */ + public static Map<String, Attribute> generateAttributeMap(List<Attribute> attributes) { + Map<String, Attribute> attr = new HashMap<String, Attribute>(); + for (Attribute a : attributes) { + attr.put(a.getName(), a); + } + return attr; + } /** *************** *** 91,94 **** --- 103,125 ---- */ public abstract int getUseableLevel(); + + /** + * method to fill in all the attributes, in the wished order + * @param l the list to fill in the attributes + */ + public abstract void getAttributes(List<Attribute> l); + + /** + * Set attributes in the modellor + * @param m a map of attribute name to attributes for quick lookup + */ + public abstract void setAttributes(Map<String, Attribute> m); + + /** + * Create a new instance of the modellor, based on a space + * @param s The space the modellor should reside in + * @return The created modellor object for the given space + */ + public abstract Modellor newInstance(Space s); /** *************** *** 114,131 **** return "Modellor"; } ! ! /** ! * Create a new instance of the modellor, based on a space ! * @param s The space the modellor should reside in ! * @return The created modellor object for the given space ! */ ! public abstract Modellor newInstance(Space s); ! /** * Set the entire content of the modellor to the given map key to value pairs * @param m the map containing the values; */ ! public void setContent(Map m) { active = ((Boolean)m.get("active")).booleanValue(); } --- 145,156 ---- return "Modellor"; } ! /** * Set the entire content of the modellor to the given map key to value pairs * @param m the map containing the values; */ ! public void setContent(Map<String, Object> m) { active = ((Boolean)m.get("active")).booleanValue(); + setSubContent(m); } *************** *** 134,142 **** * @return A map of key to value pairs of the content */ ! public Map getContent() { ! Map content = new HashMap(); content.put("active", Boolean.valueOf(active)); return content; } /** --- 159,180 ---- * @return A map of key to value pairs of the content */ ! public Map<String, Object> getContent() { ! Map<String, Object> content = new HashMap<String, Object>(); content.put("active", Boolean.valueOf(active)); + this.getSubContent(content); return content; } + + /** + * Abstract method for getting the implementing modellors content + * @param c the map to put the content in + */ + public abstract void getSubContent(Map<String, Object> c); + + /** + * Abstact method for setting the content in extending classes + * @param c The map containing the object setting + */ + public abstract void setSubContent(Map<String, Object> c); /** *************** *** 158,181 **** /** * Get the attributes of this modellor * @return the attributes */ public List<Attribute> getAttributes() { List<Attribute> l = new LinkedList<Attribute>(); l.add(new Attribute("Active", Boolean.valueOf(active), true)); return l; } ! /** * Set the attributes of the modellor * @param attributes the new attributes */ public void setAttributes(List<Attribute> attributes) { ! Iterator it = attributes.iterator(); ! while (it.hasNext()) { ! Attribute a = (Attribute)it.next(); ! if (a.getName().equals("Active")) { ! setActive((Boolean)a.getValue()); ! } } } } --- 196,221 ---- /** * Get the attributes of this modellor + * DO NOT OVERRIDE * @return the attributes */ public List<Attribute> getAttributes() { List<Attribute> l = new LinkedList<Attribute>(); + this.getAttributes(l); l.add(new Attribute("Active", Boolean.valueOf(active), true)); return l; } ! /** * Set the attributes of the modellor + * DO NOT OVERRIDE * @param attributes the new attributes */ public void setAttributes(List<Attribute> attributes) { ! Map<String, Attribute> map = generateAttributeMap(attributes); ! Attribute a = map.get("Active"); ! if (a != null) { ! setActive((Boolean)a.getValue()); } + setAttributes(map); } } Index: LayerModellor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/LayerModellor.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** LayerModellor.java 10 Apr 2007 20:59:01 -0000 1.11 --- LayerModellor.java 16 Apr 2007 15:54:42 -0000 1.12 *************** *** 9,13 **** import java.util.Collection; - import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; --- 9,12 ---- *************** *** 131,170 **** /** ! * Set attributes ! * @param attributes The attributes */ ! public void setAttributes(List attributes) { ! Iterator iter = attributes.iterator(); ! while (iter.hasNext()) { ! Attribute current = (Attribute) iter.next(); ! if (current.getName().equals("Thickness")) { ! Double thickness = (Double) current.getValue(); ! distance = thickness.doubleValue(); ! space.changed(); ! } else if (current.getName().equals("Surface")) { ! Iterator it = space.getEnvelope().iterator(); ! Surface chosen = null; ! while (it.hasNext()) { ! Surface cur = (Surface)it.next(); ! if (cur.getName().equalsIgnoreCase((String)current.getValue())) { ! chosen = cur; ! } ! } ! if (chosen != null) { ! surface = chosen; } } } } /** ! * Get attributes ! * @return The attributes */ ! public List getAttributes() { ! LinkedList attributes = new LinkedList(); ! attributes.add(new Attribute("Surface", surface.getName())); ! attributes.add(new Attribute("Thickness", new Double(distance))); ! return attributes; } --- 130,164 ---- /** ! * {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Thickness"); ! if (a != null) { ! Double thickness = (Double) a.getValue(); ! distance = thickness.doubleValue(); ! space.changed(); ! } ! a = attributes.get("Surface"); ! if (a != null) { ! Iterator it = space.getEnvelope().iterator(); ! Surface chosen = null; ! while (it.hasNext()) { ! Surface cur = (Surface)it.next(); ! if (cur.getName().equalsIgnoreCase((String)a.getValue())) { ! chosen = cur; } } + if (chosen != null) { + surface = chosen; + } } } /** ! * {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Surface", surface.getName())); ! l.add(new Attribute("Thickness", new Double(distance))); } *************** *** 196,200 **** * @param attributes Attributes */ ! public void setAttributes(List attributes) { } --- 190,194 ---- * @param attributes Attributes */ ! public void setAttributes(List<Attribute> attributes) { } *************** *** 203,208 **** * @return List of attributes */ ! public List getAttributes() { ! LinkedList attributes = new LinkedList(); attributes.add(new Attribute("Depth", new Double(0.3))); attributes.add(new Attribute("Top offset", new Double(0.0))); --- 197,202 ---- * @return List of attributes */ ! public List<Attribute> getAttributes() { ! LinkedList<Attribute> attributes = new LinkedList<Attribute>(); attributes.add(new Attribute("Depth", new Double(0.3))); attributes.add(new Attribute("Top offset", new Double(0.0))); *************** *** 224,228 **** /** {@inheritDoc} */ ! public void setContent(Map m) { space = (Space)m.get("Space"); surface = (Surface)m.get("Surface"); --- 218,222 ---- /** {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { space = (Space)m.get("Space"); surface = (Surface)m.get("Surface"); *************** *** 231,240 **** /** {@inheritDoc} */ ! public Map getContent() { ! Map m = new HashMap(); m.put("Space", space); m.put("Surface", surface); m.put("Distance", new Double(distance)); - return null; } --- 225,232 ---- /** {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { m.put("Space", space); m.put("Surface", surface); m.put("Distance", new Double(distance)); } Index: Cylinder.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/modellor/Cylinder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Cylinder.java 10 Apr 2007 20:59:01 -0000 1.1 --- Cylinder.java 16 Apr 2007 15:54:42 -0000 1.2 *************** *** 8,16 **** import java.util.Arrays; - import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Project; --- 8,16 ---- import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Map; + import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Project; *************** *** 124,135 **** /** {@inheritDoc} */ ! public void setAttributes(List attributes) { ! // TODO Auto-generated method stub } /** {@inheritDoc} */ ! public List getAttributes() { ! // TODO Auto-generated method stub ! return null; } --- 124,147 ---- /** {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Radius"); ! if (a != null) { ! radius = (Double)a.getValue(); ! } ! a = attributes.get("Height"); ! if (a != null) { ! height = (Double)a.getValue(); ! } ! a = attributes.get("Axis devisions"); ! if (a != null) { ! axisDivisions = ((Double)a.getValue()).intValue(); ! } } /** {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Radius", new Double(radius))); ! l.add(new Attribute("Height", new Double(height))); ! l.add(new Attribute("Axis devisions", new Double(axisDivisions))); } *************** *** 141,145 **** /** {@inheritDoc} */ ! public void setContent(Map m) { axisDivisions = ((Integer)m.get("Axis")).intValue(); height = ((Double)m.get("Height")).doubleValue(); --- 153,157 ---- /** {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { axisDivisions = ((Integer)m.get("Axis")).intValue(); height = ((Double)m.get("Height")).doubleValue(); *************** *** 148,157 **** /** {@inheritDoc} */ ! public Map getContent() { ! Map m = new HashMap(); m.put("Axis", new Integer(axisDivisions)); m.put("Height", new Double(height)); m.put("Radius", new Double(radius)); - return m; } --- 160,167 ---- /** {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { m.put("Axis", new Integer(axisDivisions)); m.put("Height", new Double(height)); m.put("Radius", new Double(radius)); } |