[Bprocessor-commit] facade/src/net/sourceforge/bprocessor/facade/modellor NetFacadeModellor.java,
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-04-16 15:54:45
|
Update of /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15177/src/net/sourceforge/bprocessor/facade/modellor Modified Files: NetFacadeModellor.java FacadeModellor.java Log Message: made abstract methods for getting and setting attributes and content to make extending modellors fool proof alongside with more generics Index: NetFacadeModellor.java =================================================================== RCS file: /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor/NetFacadeModellor.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** NetFacadeModellor.java 15 Apr 2007 11:05:54 -0000 1.28 --- NetFacadeModellor.java 16 Apr 2007 15:54:36 -0000 1.29 *************** *** 16,19 **** --- 16,20 ---- import java.util.Set; + import net.sourceforge.bprocessor.gui.GUI; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Classification; *************** *** 87,111 **** /** ! * Get content of the modellor for persistence ! * @return a map for persistence */ ! public Map getContent() { ! Map content = new HashMap(); ! content.put("space", space); ! content.put("net", net); ! content.put("depth", new Double(depth)); ! content.put("frameWidth", new Double(frameWidth)); ! content.put("front", front); ! content.put("single", Boolean.valueOf(single)); ! content.put("frame", frame); ! content.putAll(super.getContent()); ! return content; } /** ! * Set the content of the modellor from a map, for persistence ! * @param m persistence map */ ! public void setContent(Map m) { space = (Space)m.get("space"); net = (Net)m.get("net"); --- 88,107 ---- /** ! * {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { ! m.put("space", space); ! m.put("net", net); ! m.put("depth", new Double(depth)); ! m.put("frameWidth", new Double(frameWidth)); ! m.put("front", front); ! m.put("single", Boolean.valueOf(single)); ! m.put("frame", frame); } /** ! * {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { space = (Space)m.get("space"); net = (Net)m.get("net"); *************** *** 115,119 **** single = ((Boolean)m.get("single")).booleanValue(); frame = (Space)m.get("frame"); - super.setContent(m); Project.getInstance().addObserver(this); } --- 111,114 ---- *************** *** 199,251 **** space.setModellor(null); } ! space = null; ! net = null; ! frame = null; ! front = null; } /** ! * Get the attributes of this modellor ! * @return the attributes */ ! public List getAttributes() { ! List attributes = new LinkedList(); ! attributes.add(new Attribute("Net", net, true)); ! attributes.add(new Attribute("Front", front, true)); ! attributes.add(new Attribute("Framewidth", new Double(frameWidth), true)); ! attributes.add(new Attribute("Depth", new Double(depth), true)); ! attributes.add(new Attribute("Single", Boolean.valueOf(single), true)); ! attributes.addAll(super.getAttributes()); ! return attributes; } /** ! * 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 att = (Attribute)it.next(); ! if (att.getName().equals("Net")) { ! setNet((Space)att.getValue()); ! } else if (att.getName().equals("Framewidth")) { ! setFrameWidth(((Double)att.getValue()).doubleValue()); ! } else if (att.getName().equals("Depth")) { ! setDepth(((Double)att.getValue()).doubleValue()); ! } else if (att.getName().equals("Single")) { ! setSingle(((Boolean)att.getValue()).booleanValue()); ! } else if (att.getName().equals("Front")) { ! Iterator sit = Project.getInstance().getActiveSpace().getSurfaces().iterator(); ! while (sit.hasNext()) { ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(att.getValue()) && front != s) { ! this.setFront(s); ! this.setNet(createNet(front)); ! } } } } - super.setAttributes(attributes); } --- 194,254 ---- space.setModellor(null); } ! //space = null; ! //net = null; ! //frame = null; ! //front = null; } /** ! * {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Net", net, true)); ! l.add(new Attribute("Front", front, true)); ! l.add(new Attribute("Framewidth", new Double(frameWidth), true)); ! l.add(new Attribute("Depth", new Double(depth), true)); ! l.add(new Attribute("Single", Boolean.valueOf(single), true)); } /** ! * {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { ! Attribute a = attributes.get("Net"); ! if (a != null) { ! setNet((Space)a.getValue()); ! } ! a = attributes.get("Framewidth"); ! if (a != null) { ! setFrameWidth(((Double)a.getValue()).doubleValue()); ! } ! a = attributes.get("Framewidth"); ! if (a != null) { ! setFrameWidth(((Double)a.getValue()).doubleValue()); ! } ! a = attributes.get("Depth"); ! if (a != null) { ! setDepth(((Double)a.getValue()).doubleValue()); ! } ! a = attributes.get("Single"); ! if (a != null) { ! setSingle(((Boolean)a.getValue()).booleanValue()); ! } ! a = attributes.get("Front"); ! if (a != null) { ! Iterator sit = space.getOwner().getSurfaces().iterator(); ! boolean legalSurface = false; ! while (sit.hasNext()) { ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(a.getValue()) && front != s) { ! legalSurface = true; ! this.setFront(s); ! this.setNet(createNet(front)); } } + if (!legalSurface) { + GUI.getInstance().alert(a.getValue() + " weren't a useable surface"); + } } } Index: FacadeModellor.java =================================================================== RCS file: /cvsroot/bprocessor/facade/src/net/sourceforge/bprocessor/facade/modellor/FacadeModellor.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** FacadeModellor.java 15 Apr 2007 10:40:18 -0000 1.32 --- FacadeModellor.java 16 Apr 2007 15:54:36 -0000 1.33 *************** *** 16,19 **** --- 16,20 ---- import java.util.Iterator; + import net.sourceforge.bprocessor.gui.GUI; import net.sourceforge.bprocessor.model.modellor.Modellor; import net.sourceforge.bprocessor.model.Space; *************** *** 225,300 **** } /** ! * Set the attributes of the object to the values in the list ! * @param attributes The attributes to set */ ! public void setAttributes(List attributes) { ! Iterator it = attributes.iterator(); boolean changeFacade = false; boolean changeCons = false; ! while (it.hasNext()) { ! Attribute a = (Attribute)it.next(); ! if (a.getName().equals("Name")) { ! name = (String)a.getValue(); ! } else if (a.getName().equals("Front")) { ! Iterator sit = Project.getInstance().getActiveSpace().getSurfaces().iterator(); ! while (sit.hasNext()) { ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(a.getValue())) { ! if (front != s) { ! front = s; ! changeFacade = true; ! changeCons = true; ! } } - } - } else if (a.getName().equals("V-posts")) { - int n = ((Double)a.getValue()).intValue(); - if (n != vertPosts) { - changeFacade = true; - changeCons = true; - vertPosts = n; } ! } else if (a.getName().equals("H-posts")) { ! int n = ((Double)a.getValue()).intValue(); ! if (n != horPosts) { ! changeFacade = true; ! changeCons = true; ! horPosts = n; ! } ! } else if (a.getName().equals("V-postwidth")) { ! double d = ((Double)a.getValue()).doubleValue(); ! setVertPostWidth(d); changeFacade = true; ! } else if (a.getName().equals("H-postwidth")) { ! double d = ((Double)a.getValue()).doubleValue(); ! setHorPostWidth(d); changeFacade = true; ! } else if (a.getName().equals("Frame thickness")) { ! double n = ((Double)a.getValue()).doubleValue(); ! if (n != frameWidth) { ! frameWidth = n; ! changeCons = true; ! changeFacade = true; ! } ! } else if (a.getName().equals("Depth")) { ! double n = ((Double)a.getValue()).doubleValue(); ! if (n != depth) { ! depth = n; ! changeFacade = true; ! } ! } else if (a.getName().equals("Single posted")) { ! boolean b = ((Boolean)a.getValue()).booleanValue(); ! if (b && type != SINGLE_BAR) { ! type = SINGLE_BAR; ! changeFacade = true; ! changeCons = true; ! } ! if (!b && type == SINGLE_BAR) { ! type = DOUBLE_BAR; ! changeFacade = true; ! changeCons = true; ! } } } if (changeCons || (horCons.isEmpty() && vertCons.isEmpty())) { createPostConstructors(); --- 226,319 ---- } /** ! * {@inheritDoc} */ ! public void setAttributes(Map<String, Attribute> attributes) { boolean changeFacade = false; boolean changeCons = false; ! Attribute a = attributes.get("Name"); ! if (a != null) { ! name = (String)a.getValue(); ! } ! a = attributes.get("Front"); ! if (a != null) { ! Iterator sit = space.getOwner().getSurfaces().iterator(); ! boolean legalSurface = false; ! while (sit.hasNext()) { ! Surface s = (Surface)sit.next(); ! if (s.getName().equals(a.getValue())) { ! if (front != s) { ! legalSurface = true; ! front = s; ! changeFacade = true; ! changeCons = true; } } ! } ! if (!legalSurface) { ! GUI.getInstance().alert(a.getValue() + " weren't a useable surface"); ! } ! } ! a = attributes.get("V-posts"); ! if (a != null) { ! int n = ((Double)a.getValue()).intValue(); ! if (n != vertPosts) { changeFacade = true; ! changeCons = true; ! vertPosts = n; ! } ! } ! a = attributes.get("H-posts"); ! if (a != null) { ! int n = ((Double)a.getValue()).intValue(); ! if (n != horPosts) { changeFacade = true; ! changeCons = true; ! horPosts = n; ! } ! } ! a = attributes.get("V-postwidth"); ! if (a != null) { ! double d = ((Double)a.getValue()).doubleValue(); ! setVertPostWidth(d); ! changeFacade = true; ! } ! a = attributes.get("H-postwidth"); ! if (a != null) { ! double d = ((Double)a.getValue()).doubleValue(); ! setHorPostWidth(d); ! changeFacade = true; ! } ! a = attributes.get("Frame thickness"); ! if (a != null) { ! double n = ((Double)a.getValue()).doubleValue(); ! if (n != frameWidth) { ! frameWidth = n; ! changeCons = true; ! changeFacade = true; ! } ! } ! a = attributes.get("Depth"); ! if (a != null) { ! double n = ((Double)a.getValue()).doubleValue(); ! if (n != depth) { ! depth = n; ! changeFacade = true; ! } ! } ! a = attributes.get("Single posted"); ! if (a != null) { ! boolean b = ((Boolean)a.getValue()).booleanValue(); ! if (b && type != SINGLE_BAR) { ! type = SINGLE_BAR; ! changeFacade = true; ! changeCons = true; ! } ! if (!b && type == SINGLE_BAR) { ! type = DOUBLE_BAR; ! changeFacade = true; ! changeCons = true; } } + if (changeCons || (horCons.isEmpty() && vertCons.isEmpty())) { createPostConstructors(); *************** *** 307,329 **** } /** ! * Retrn a list of the attributes in the object ! * @return the list of attributes for the object */ ! public List getAttributes() { ! LinkedList attributes = new LinkedList(); ! attributes.add(new Attribute("Name", name)); ! attributes.add(new Attribute("Front", front, true)); ! attributes.add(new Attribute("V-posts", new Double(vertPosts))); ! attributes.add(new Attribute("H-posts", new Double(horPosts))); boolean bars = (type == SINGLE_BAR); if (bars) { ! attributes.add(new Attribute("V-postwidth", new Double(vertPostWidth), bars)); ! attributes.add(new Attribute("H-postwidth", new Double(horPostWidth), bars)); ! attributes.add(new Attribute("Frame thickness", new Double(frameWidth), bars)); } ! attributes.add(new Attribute("Depth", new Double(depth))); ! attributes.add(new Attribute("Single posted", Boolean.valueOf(bars))); ! return attributes; } /** * Get the name --- 326,346 ---- } /** ! * {@inheritDoc} */ ! public void getAttributes(List<Attribute> l) { ! l.add(new Attribute("Name", name)); ! l.add(new Attribute("Front", front, true)); ! l.add(new Attribute("V-posts", new Double(vertPosts))); ! l.add(new Attribute("H-posts", new Double(horPosts))); boolean bars = (type == SINGLE_BAR); if (bars) { ! l.add(new Attribute("V-postwidth", new Double(vertPostWidth), bars)); ! l.add(new Attribute("H-postwidth", new Double(horPostWidth), bars)); ! l.add(new Attribute("Frame thickness", new Double(frameWidth), bars)); } ! l.add(new Attribute("Depth", new Double(depth))); ! l.add(new Attribute("Single posted", Boolean.valueOf(bars))); } + /** * Get the name *************** *** 776,780 **** /** {@inheritDoc} */ ! public void setContent(Map m) { bottomBound = (Line)m.get("bottomBound"); rightBound = (Line)m.get("rightBound"); --- 793,797 ---- /** {@inheritDoc} */ ! public void setSubContent(Map<String, Object> m) { bottomBound = (Line)m.get("bottomBound"); rightBound = (Line)m.get("rightBound"); *************** *** 794,799 **** /** {@inheritDoc} */ ! public Map getContent() { ! Map m = new HashMap(); m.put("bottomBound", bottomBound); m.put("rightBound", rightBound); --- 811,815 ---- /** {@inheritDoc} */ ! public void getSubContent(Map<String, Object> m) { m.put("bottomBound", bottomBound); m.put("rightBound", rightBound); *************** *** 810,814 **** m.put("name", name); m.put("Space", space); - return m; } --- 826,829 ---- |