[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview ClassificationIdAttribute.java,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-10-18 11:54:34
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4454/src/net/sourceforge/bprocessor/gui/attrview Modified Files: ClassificationIdAttribute.java GenericPanel.java Log Message: refactor Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** GenericPanel.java 18 Oct 2007 08:46:34 -0000 1.42 --- GenericPanel.java 18 Oct 2007 11:54:36 -0000 1.43 *************** *** 49,53 **** /** The list of attributes */ ! private List attributes; /** The list of generic attributes */ --- 49,53 ---- /** The list of attributes */ ! private List<Attribute> attributes; /** The list of generic attributes */ *************** *** 102,148 **** } ! /** ! * local method for generating the content ! * @param what The list of attributes ! * @param where The place to put all the generated content; ! */ ! private void generateContent(List what, JComponent where) { ! Iterator iter = what.iterator(); ! while (iter.hasNext()) { ! Attribute a = (Attribute)iter.next(); ! if (a.getValue() instanceof String || a.getValue() instanceof Double) { ! // All the simple types in a field just for editing ! StringAttribute sa = new StringAttribute(a); ! sa.addStringAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(sa); ! where.add(new AttributeRow(sa)); ! } else if (a.getValue() instanceof List) { ! // Take care of all list attributes ! List elems = (List)a.getValue(); ! Iterator iterElems = elems.iterator(); ! Box more = Box.createVerticalBox(); ! TitledBorder b = BorderFactory.createTitledBorder( ! BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), ! a.getName()); ! b.setTitleJustification(TitledBorder.CENTER); ! more.setBorder(b); ! if (iterElems.next() instanceof Attribute) { ! generateContent(elems, more); ! } ! where.add(more); ! } else if (a.getValue() instanceof Description) { ! // Handles the description field ! DescriptionAttribute da = new DescriptionAttribute(a); ! da.addDescriptionAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { obj.setAttributes(attributes); --- 102,210 ---- } ! private void handleString(Attribute attribute, JComponent where) { ! StringAttribute sa = new StringAttribute(attribute); ! sa.addStringAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(sa); ! where.add(new AttributeRow(sa)); ! } ! ! private void handleList(Attribute attribute, JComponent where) { ! List elems = (List) attribute.getValue(); ! Iterator iterElems = elems.iterator(); ! Box more = Box.createVerticalBox(); ! TitledBorder b = BorderFactory.createTitledBorder( ! BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), ! attribute.getName()); ! b.setTitleJustification(TitledBorder.CENTER); ! more.setBorder(b); ! if (iterElems.next() instanceof Attribute) { ! generateContent(elems, more); ! } ! where.add(more); ! } ! ! private void handleDescription(Attribute attribute, JComponent where) { ! DescriptionAttribute da = new DescriptionAttribute(attribute); ! da.addDescriptionAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(da); ! where.add(new AttributeRow(da)); ! } ! ! private void handleMaterial(Attribute attribute, JComponent where) { ! MaterialAttribute ma = new MaterialAttribute(attribute); ! ma.addMaterialAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(ma); ! where.add(new AttributeRow(ma)); ! } ! ! private void handleBoolean(Attribute attribute, JComponent where) { ! BooleanAttribute ba = new BooleanAttribute(attribute); ! ba.addBooleanAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(ba); ! where.add(new AttributeRow(ba)); ! } ! ! private void handleClassification(Attribute attribute, JComponent where) { ! ClassificationTextAttribute catext = new ClassificationTextAttribute(attribute); ! catext.addClassificationAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(catext); ! where.add(new AttributeRow(catext)); ! if (attribute.getValue() instanceof Classification) { ! Classification c = (Classification)attribute.getValue(); ! if (c != null && !c.getId().equalsIgnoreCase("-1") && ! attribute.getName().equalsIgnoreCase("Classification")) { ! // Handles the id part of classification ! ClassificationIdAttribute caid = new ClassificationIdAttribute(attribute); ! caid.addClassificationAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { obj.setAttributes(attributes); *************** *** 155,265 **** } }); ! genAttributes.add(da); ! where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Material) { ! // Handles the materials ! MaterialAttribute ma = new MaterialAttribute(a); ! ma.addMaterialAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } } ! }); ! genAttributes.add(ma); ! where.add(new AttributeRow(ma)); } else if (a.getValue() instanceof Boolean) { ! // Handles the booleans ! BooleanAttribute ba = new BooleanAttribute(a); ! ba.addBooleanAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(ba); ! where.add(new AttributeRow(ba)); } else if (a.getThe2ndValue() instanceof Structure) { ! // Handles the text part classification ! ClassificationTextAttribute catext = new ClassificationTextAttribute(a); ! catext.addClassificationAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(catext); ! where.add(new AttributeRow(catext)); ! if (a.getValue() instanceof Classification) { ! Classification c = (Classification)a.getValue(); ! if (c != null && !c.getId().equalsIgnoreCase("-1") && ! a.getName().equalsIgnoreCase("Classification")) { ! // Handles the id part of classification ! ClassificationIdAttribute caid = new ClassificationIdAttribute(a); ! caid.addClassificationAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(caid); ! where.add(new AttributeRow(caid)); ! } ! } } else if (a.getValue() instanceof Selector) { ! Selector s = (Selector)a.getValue(); ! SelectorAttribute satt = new SelectorAttribute(a); ! satt.addItemListener(new SelectorListener(s) { ! public void itemStateChanged(ItemEvent e) { ! if (e.getStateChange() == e.SELECTED) { ! getSelector().setCurrentValue(e.getItem()); ! if (obj instanceof Entity) { ! obj.setAttributes(attributes); ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! } ! }); ! genAttributes.add(satt); ! where.add(new AttributeRow(satt)); } else if (a.getValue() instanceof Parametric) { ! // Handles the links ! LinkAttribute la = new LinkAttribute(a); ! la.addStringAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(la); ! where.add(new AttributeRow(la)); ! } else { ! log.info("[GenericPanel] Something were not implemented"); } } --- 217,283 ---- } }); ! genAttributes.add(caid); ! where.add(new AttributeRow(caid)); ! } ! } ! } ! ! private void handleSelector(Attribute attribute, JComponent where) { ! Selector s = (Selector)attribute.getValue(); ! SelectorAttribute satt = new SelectorAttribute(attribute); ! satt.addItemListener(new SelectorListener(s) { ! public void itemStateChanged(ItemEvent e) { ! if (e.getStateChange() == ItemEvent.SELECTED) { ! getSelector().setCurrentValue(e.getItem()); ! if (obj instanceof Entity) { obj.setAttributes(attributes); ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); } ! } ! } ! }); ! genAttributes.add(satt); ! where.add(new AttributeRow(satt)); ! } ! ! private void handleLink(Attribute attribute, JComponent where) { ! LinkAttribute la = new LinkAttribute(attribute); ! la.addStringAttributeListener(new AttributeListener() { ! public void valueChanged(Attribute a) { ! obj.setAttributes(attributes); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } ! } ! }); ! genAttributes.add(la); ! where.add(new AttributeRow(la)); ! } ! ! private void generateContent(List what, JComponent where) { ! Iterator iter = what.iterator(); ! while (iter.hasNext()) { ! Attribute a = (Attribute)iter.next(); ! if (a.getValue() instanceof String || a.getValue() instanceof Double) { ! handleString(a, where); ! } else if (a.getValue() instanceof List) { ! handleList(a, where); ! } else if (a.getValue() instanceof Description) { ! handleDescription(a, where); ! } else if (a.getValue() instanceof Material) { ! handleMaterial(a, where); } else if (a.getValue() instanceof Boolean) { ! handleBoolean(a, where); } else if (a.getThe2ndValue() instanceof Structure) { ! handleClassification(a, where); } else if (a.getValue() instanceof Selector) { ! handleSelector(a, where); } else if (a.getValue() instanceof Parametric) { ! handleLink(a, where); } } Index: ClassificationIdAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/ClassificationIdAttribute.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ClassificationIdAttribute.java 10 Aug 2007 09:26:57 -0000 1.7 --- ClassificationIdAttribute.java 18 Oct 2007 11:54:36 -0000 1.8 *************** *** 211,240 **** public void stopEditing() { if (editor != null) { - //Object val = attribute.getValue(); String id = editor.getText(); StringTokenizer st = new StringTokenizer(id, "."); ! Classification clas; if (((Classification) attribute.getValue()).getType() == 0) { ! clas = Project.getInstance().getConstructionClas(); } else { ! clas = Project.getInstance().getFunctionalClas(); } String curid; while (st.hasMoreTokens()) { curid = st.nextToken(); ! Iterator it = clas.getChildren().iterator(); while (it.hasNext()) { Classification current = (Classification) it.next(); if (curid.equalsIgnoreCase(current.getId())) { ! clas = current; } } } ! attribute.setThe2ndValue(clas); component.remove(editor); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel(clas.getFullId(attribute.getLevel()))); component.revalidate(); valueChanged(); --- 211,239 ---- public void stopEditing() { if (editor != null) { String id = editor.getText(); StringTokenizer st = new StringTokenizer(id, "."); ! Classification classification; if (((Classification) attribute.getValue()).getType() == 0) { ! classification = Project.getConstructionClas(); } else { ! classification = Project.getFunctionalClas(); } String curid; while (st.hasMoreTokens()) { curid = st.nextToken(); ! Iterator it = classification.getChildren().iterator(); while (it.hasNext()) { Classification current = (Classification) it.next(); if (curid.equalsIgnoreCase(current.getId())) { ! classification = current; } } } ! attribute.setThe2ndValue(classification); component.remove(editor); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel(classification.getFullId(attribute.getLevel()))); component.revalidate(); valueChanged(); |