Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview GenericPanel.java, 1.38, 1.39 C
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-07-23 14:36:28
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17744/src/net/sourceforge/bprocessor/gui/attrview Modified Files: GenericPanel.java ClassificationTextAttribute.java ClassificationIdAttribute.java Log Message: Made a superclass to Classification and ClassificationType called Structure and made all uses reflect that... Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** GenericPanel.java 24 May 2007 21:43:07 -0000 1.38 --- GenericPanel.java 23 Jul 2007 13:57:39 -0000 1.39 *************** *** 36,39 **** --- 36,40 ---- import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selector; + import net.sourceforge.bprocessor.model.Structure; /** *************** *** 154,158 **** genAttributes.add(da); where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Parametric && !(a.getValue() instanceof Classification)) { // Handles the links LinkAttribute la = new LinkAttribute(a); --- 155,159 ---- genAttributes.add(da); where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Parametric && !(a.getValue() instanceof Structure)) { // Handles the links LinkAttribute la = new LinkAttribute(a); *************** *** 202,206 **** genAttributes.add(ba); where.add(new AttributeRow(ba)); ! } else if (a.getValue() instanceof Classification) { // Handles the text part classification ClassificationTextAttribute catext = new ClassificationTextAttribute(a); --- 203,207 ---- genAttributes.add(ba); where.add(new AttributeRow(ba)); ! } else if (a.getValue() instanceof Structure) { // Handles the text part classification ClassificationTextAttribute catext = new ClassificationTextAttribute(a); *************** *** 218,244 **** genAttributes.add(catext); where.add(new AttributeRow(catext)); ! if (a.getClassification() != null && ! !a.getClassification().getId().equalsIgnoreCase("-1") && ! !a.getName().equalsIgnoreCase("Type")) { ! // 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) { --- 219,246 ---- genAttributes.add(catext); where.add(new AttributeRow(catext)); ! if (a.getThe2ndValue() instanceof Classification) { ! Classification c = (Classification)a.getThe2ndValue(); ! 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) { Index: ClassificationTextAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/ClassificationTextAttribute.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ClassificationTextAttribute.java 8 May 2007 12:34:06 -0000 1.8 --- ClassificationTextAttribute.java 23 Jul 2007 13:57:39 -0000 1.9 *************** *** 40,43 **** --- 40,45 ---- import net.sourceforge.bprocessor.model.Classification; import net.sourceforge.bprocessor.model.Project; + import net.sourceforge.bprocessor.model.Space; + import net.sourceforge.bprocessor.model.Structure; /** *************** *** 45,49 **** */ public class ClassificationTextAttribute extends GenericAttribute ! implements ActionListener, MouseListener, KeyListener { /** The logger */ private static Logger log = Logger.getLogger(ClassificationTextAttribute.class); --- 47,51 ---- */ public class ClassificationTextAttribute extends GenericAttribute ! implements MouseListener, KeyListener { /** The logger */ private static Logger log = Logger.getLogger(ClassificationTextAttribute.class); *************** *** 65,70 **** /** The popup menu */ ! private JPopupMenu classification; ! /** The editor, when this EditableAttribute is being edited */ --- 67,71 ---- /** The popup menu */ ! private JPopupMenu popupChoices; /** The editor, when this EditableAttribute is being edited */ *************** *** 78,86 **** public ClassificationTextAttribute(Attribute attribute) { super(BoxLayout.X_AXIS); ! if (attribute.getName().equalsIgnoreCase("Classification")) { ! label = new JLabel("Classification: "); ! } else { ! label = new JLabel("Type: "); ! } label.setFont(AttributeView.FONT_BOLD); this.attribute = attribute; --- 79,83 ---- public ClassificationTextAttribute(Attribute attribute) { super(BoxLayout.X_AXIS); ! label = new JLabel(attribute.getName() + ": "); label.setFont(AttributeView.FONT_BOLD); this.attribute = attribute; *************** *** 88,93 **** Box column = Box.createVerticalBox(); component = Box.createHorizontalBox(); ! if (attribute.getClassification() != null) { ! JLabel cur = (JLabel) createValueLabel(attribute.getClassification()); cur.setFont(AttributeView.FONT_PLAIN); component.add(cur); --- 85,90 ---- Box column = Box.createVerticalBox(); component = Box.createHorizontalBox(); ! if (attribute.getThe2ndValue() != null) { ! JLabel cur = (JLabel) createValueLabel((Structure)attribute.getThe2ndValue()); cur.setFont(AttributeView.FONT_PLAIN); component.add(cur); *************** *** 97,101 **** component.add(cur); } ! createMenu(attribute.getValue()); Box header = Box.createHorizontalBox(); header.add(Box.createHorizontalStrut(7)); --- 94,98 ---- component.add(cur); } ! createMenu((Structure)attribute.getValue()); Box header = Box.createHorizontalBox(); header.add(Box.createHorizontalStrut(7)); *************** *** 166,202 **** * @param value The value */ ! private void createMenu(Object value) { ! classification = new JPopupMenu(); ! JMenu subMenu; ! MyMenuItem mi, submi; ! boolean hasChildren = false; ! Iterator it = ((Classification) value).getChildren().iterator(); ! while (it.hasNext()) { ! Classification current = (Classification) it.next(); ! if (current.getChildren() != null) { ! hasChildren = true; ! } ! if (hasChildren) { ! Iterator subit = current.getChildren().iterator(); ! subMenu = new JMenu(current.getName()); ! submi = new MyMenuItem(current); ! submi.addActionListener(this); ! if (!current.getId().equalsIgnoreCase("-99")) { ! subMenu.add(submi); ! } ! while (subit.hasNext()) { ! Classification subcur = (Classification) subit.next(); ! submi = new MyMenuItem(subcur); ! submi.addActionListener(this); subMenu.add(submi); } ! classification.add(subMenu); } else { ! mi = new MyMenuItem(current); ! mi.addActionListener(this); ! classification.add(mi); } } - } --- 163,189 ---- * @param value The value */ ! private void createMenu(Structure value) { ! popupChoices = new JPopupMenu(); ! MyMenuItem mi = new MyMenuItem(value); ! mi.addActionListener(new MyMenuItemListener()); ! popupChoices.add(mi); ! for (Structure s : (Vector<Structure>)value.getChildren()) { ! if (s.getChildren().size() > 0) { ! JMenu subMenu = new JMenu(s.getName()); ! mi = new MyMenuItem(s); ! mi.addActionListener(new MyMenuItemListener()); ! subMenu.add(mi); ! for (Structure child : (Vector<Structure>)s.getChildren()) { ! MyMenuItem submi = new MyMenuItem(child); ! submi.addActionListener(new MyMenuItemListener()); subMenu.add(submi); } ! popupChoices.add(subMenu); } else { ! mi = new MyMenuItem(s); ! mi.addActionListener(new MyMenuItemListener()); ! popupChoices.add(mi); } } } *************** *** 206,212 **** * @return The label */ ! private JComponent createValueLabel(Classification value) { ! JLabel valueLabel; ! if (attribute.getClassification().getId().equalsIgnoreCase("-1")) { valueLabel = new JLabel(value.getName()); } else { --- 193,200 ---- * @return The label */ ! private JComponent createValueLabel(Structure value) { ! JLabel valueLabel = new JLabel(value.getName()); ! valueLabel.setFont(AttributeView.FONT_PLAIN); ! /*if (attribute.getClassification().getId().equalsIgnoreCase("-1")) { valueLabel = new JLabel(value.getName()); } else { *************** *** 219,223 **** valueLabel = new JLabel(value.getName()); } ! } return valueLabel; } --- 207,211 ---- valueLabel = new JLabel(value.getName()); } ! }*/ return valueLabel; } *************** *** 225,238 **** /** * Create a value editor - * @param value The value * @param name the current name * @return The value editor */ ! private JComponent createValueEditor(String name, Classification value) { String s = ""; if (!name.equalsIgnoreCase("Classification")) { s = name; ! } ! AutoCompleteField valueEditor = new AutoCompleteField(s, (Classification) attribute.getValue()); valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; --- 213,225 ---- /** * Create a value editor * @param name the current name * @return The value editor */ ! private JComponent createValueEditor(String name) { String s = ""; if (!name.equalsIgnoreCase("Classification")) { s = name; ! } ! AutoCompleteField valueEditor = new AutoCompleteField(s, (Structure) attribute.getValue()); valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; *************** *** 246,262 **** return attribute; } - - /** - * Handles the event from the classification menu - * @param e is the action event - */ - public void actionPerformed(ActionEvent e) { - MyMenuItem source = (MyMenuItem)(e.getSource()); - attribute.setClassification(source.getClassification()); - component.remove(0); - component.add(createValueLabel(attribute.getClassification())); - component.revalidate(); - valueChanged(); - } /** --- 233,236 ---- *************** *** 264,297 **** */ class MyMenuItem extends JMenuItem { - /** the classification */ ! private Classification cla; /** * Constructor for a new MyMenuItem ! * @param classification the classification */ ! MyMenuItem(Classification classification) { ! super(classification.getName()); ! setClassification(classification); } /** ! * return the classification for the current menu item ! * @return the classification */ ! public Classification getClassification() { ! return cla; } /** * Sets the classification for a menu item ! * @param cla the classification */ ! public void setClassification(Classification cla) { ! this.cla = cla; } } ! /** * Start editing --- 238,290 ---- */ class MyMenuItem extends JMenuItem { /** the classification */ ! private Structure structure; /** * Constructor for a new MyMenuItem ! * @param struc the classification */ ! MyMenuItem(Structure struc) { ! super(struc.getName()); ! setClassification(struc); } /** ! * return the structure for the current menu item ! * @return the structure */ ! public Structure getClassification() { ! return this.structure; } /** * Sets the classification for a menu item ! * @param cla the structure */ ! public void setClassification(Structure cla) { ! this.structure = cla; } } ! ! /** ! * MenuItem action listener ! */ ! class MyMenuItemListener implements ActionListener { ! /** ! * Handles the event from the classification menu ! * @param e is the action event ! */ ! public void actionPerformed(ActionEvent e) { ! if (e.getSource() instanceof MyMenuItem) { ! MyMenuItem source = (MyMenuItem)(e.getSource()); ! attribute.setThe2ndValue(source.getClassification()); ! component.remove(0); ! component.add(createValueLabel((Structure)attribute.getThe2ndValue())); ! component.revalidate(); ! valueChanged(); ! } ! } ! } ! /** * Start editing *************** *** 299,304 **** public void startEditing() { if (editor == null) { ! editor = (AutoCompleteField) createValueEditor(((JLabel)component.getComponent(0)) ! .getText(), attribute.getClassification()); component.remove(0); editor.addKeyListener(this); --- 292,296 ---- public void startEditing() { if (editor == null) { ! editor = (AutoCompleteField)createValueEditor(((JLabel)component.getComponent(0)).getText()); component.remove(0); editor.addKeyListener(this); *************** *** 312,327 **** /** * Stop editing */ public void stopEditing() { if (editor != null && attribute.isEditable()) { ! Vector cur = ((Classification) attribute.getValue()).getChildren(); ! if (((Classification) attribute.getValue()).getType() == 0) { ! cur.addAll(Project.getInstance().getClassification("-99", 0).getChildren()); ! } ! if (((Classification) attribute.getValue()).getType() == 0) { ! cur.addAll(Project.getInstance().getClassification("-99", 1).getChildren()); } ! Classification current; ! Classification entered = null; StringTokenizer st = new StringTokenizer(editor.getText(), "."); while (st.hasMoreTokens()) { --- 304,327 ---- /** * Stop editing + * Should be able to handle two different strings + * 1. A . separated integer string + * 2. A */ public void stopEditing() { if (editor != null && attribute.isEditable()) { ! Vector cur = ((Structure) attribute.getValue()).getChildren(); ! if (attribute.getValue() instanceof Classification) { ! if (((Classification) attribute.getValue()).getType() == Space.CONSTRUCTION) { ! cur.addAll(Project.getInstance().getClassification("-99", ! Space.CONSTRUCTION).getChildren()); ! } else if (((Classification) attribute.getValue()).getType() == Space.FUNCTIONAL) { ! cur.addAll(Project.getInstance().getClassification("-99", ! Space.FUNCTIONAL).getChildren()); ! } else { ! log.warn(((Classification) attribute.getValue()).getType() + " is a unknown type"); ! } } ! Structure current; ! Structure entered = null; StringTokenizer st = new StringTokenizer(editor.getText(), "."); while (st.hasMoreTokens()) { *************** *** 329,333 **** Iterator it = cur.iterator(); while (it.hasNext()) { ! current = (Classification) it.next(); if (current.getName().equalsIgnoreCase(name)) { cur = current.getChildren(); --- 329,333 ---- Iterator it = cur.iterator(); while (it.hasNext()) { ! current = (Structure) it.next(); if (current.getName().equalsIgnoreCase(name)) { cur = current.getChildren(); *************** *** 337,342 **** } if (entered != null) { ! attribute.setClassification(entered); ! } else { Classification newclas, egne; if (((Classification) attribute.getValue()).getType() == 0) { --- 337,342 ---- } if (entered != null) { ! attribute.setThe2ndValue(entered); ! } /*else { Classification newclas, egne; if (((Classification) attribute.getValue()).getType() == 0) { *************** *** 353,362 **** } ! attribute.setClassification(newclas); ! } component.remove(editor); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel((Classification) attribute.getClassification())); component.revalidate(); valueChanged(); --- 353,362 ---- } ! attribute.setThe2ndValue(newclas); ! }*/ component.remove(editor); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel((Structure) attribute.getThe2ndValue())); component.revalidate(); valueChanged(); *************** *** 372,376 **** editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel((Classification) attribute.getValue())); component.revalidate(); } --- 372,376 ---- editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel((Structure) attribute.getValue())); component.revalidate(); } *************** *** 388,392 **** */ public void mousePressed(MouseEvent event) { ! classification.show(event.getComponent(), event.getX(), event.getY()); --- 388,392 ---- */ public void mousePressed(MouseEvent event) { ! popupChoices.show(event.getComponent(), event.getX(), event.getY()); *************** *** 444,450 **** */ public class AutoCompleteField extends JTextField { - /** The parent classification */ - private Classification parent; - /** * constructor of autocomplete field --- 444,447 ---- *************** *** 452,457 **** * @param parent the parent to the classification */ ! public AutoCompleteField(String string, Classification parent) { ! super(string); this.setDocument(new AutoCompleteDocument(this, parent)); this.setText(string); --- 449,454 ---- * @param parent the parent to the classification */ ! public AutoCompleteField(String string, Structure parent) { ! super(); this.setDocument(new AutoCompleteDocument(this, parent)); this.setText(string); *************** *** 465,474 **** /** The typed text */ private String typed; - /** The textfield */ private JTextField field; ! ! /** The parent classification */ ! private Classification parent; /** --- 462,469 ---- /** The typed text */ private String typed; /** The textfield */ private JTextField field; ! /** The possible strings */ ! private LinkedList<String> possibillities = new LinkedList<String>(); /** *************** *** 477,484 **** * @param parent the parent to the classification */ ! public AutoCompleteDocument(JTextField field, Classification parent) { this.field = field; - this.parent = parent; typed = ""; } --- 472,494 ---- * @param parent the parent to the classification */ ! public AutoCompleteDocument(JTextField field, Structure<? extends Structure> parent) { this.field = field; typed = ""; + findPossibillities("", parent, 1); + } + + private void findPossibillities(String prefix, Structure s, int lvl) { + String str = prefix + s.getName().toLowerCase(); + if (str.equalsIgnoreCase("constructional") || str.equalsIgnoreCase("functional")) { + str = ""; + } else { + possibillities.add(str); + str += "."; + } + if (lvl < 3) { + for (Structure struc : (Vector<Structure>)s.getChildren()) { + findPossibillities(str, struc, lvl + 1); + } + } } *************** *** 497,509 **** typed = typed.substring(0, offs) + str + typed.substring(offs, typed.length()); } else { ! typed = typed + str; } super.remove(0, super.getLength()); typed = autocomplete(typed); super.insertString(0, typed, a); ! field.setCaretPosition(offs + str.length()); ! field.setSelectionStart(offs + str.length()); ! field.setSelectionEnd(typed.length()); } --- 507,532 ---- typed = typed.substring(0, offs) + str + typed.substring(offs, typed.length()); } else { ! if (!str.equalsIgnoreCase(".")) { ! typed = typed + str; ! } } super.remove(0, super.getLength()); typed = autocomplete(typed); + if (str.equalsIgnoreCase(".")) { + offs = typed.length(); + typed = autocomplete(typed + "."); + } super.insertString(0, typed, a); ! try { ! field.setCaretPosition(offs + str.length()); ! field.setSelectionStart(offs + str.length()); ! field.setSelectionEnd(typed.length()); ! } catch (Exception e) { ! log.error("Catched thrown error" + e.getMessage()); ! field.setCaretPosition(0); ! field.setScrollOffset(0); ! field.setSelectionEnd(field.getText().length()); ! } } *************** *** 514,552 **** */ public String autocomplete(String string) { ! if (!string.equalsIgnoreCase("")) { ! Vector cl = parent.getChildren(); ! Vector sort = new Vector(); ! boolean children = false; ! Iterator it = cl.iterator(); ! while (it.hasNext()) { ! Classification current = (Classification) it.next(); ! if (!current.getId().equalsIgnoreCase("-99")) { ! sort.add(current.toString()); ! } ! if (current.getChildren() != null) { ! children = true; ! } ! if (children) { ! Iterator subit = current.getChildren().iterator(); ! while (subit.hasNext()) { ! String conc = ""; ! if (!current.getId().equalsIgnoreCase("-99")) { ! conc = current.toString() + "." + ((Classification) subit.next()).toString(); ! } else { ! conc = ((Classification) subit.next()).toString(); ! } ! sort.add(conc); ! } } } ! ! LinkedList matches = new LinkedList(); ! Iterator sortit = sort.iterator(); ! while (sortit.hasNext()) { ! String name = (String) sortit.next(); ! if (name.startsWith(string)) { ! matches.add(name); ! return name; ! } } } --- 537,552 ---- */ public String autocomplete(String string) { ! string = string.toLowerCase(); ! if (!string.equalsIgnoreCase("")) { ! LinkedList<String> matches = new LinkedList<String>(); ! for (String s : possibillities) { ! if (s.startsWith(string)) { ! matches.add(s); } } ! if (!matches.isEmpty()) { ! return matches.get(0); ! } else { ! return "Non existing"; } } Index: ClassificationIdAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/ClassificationIdAttribute.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ClassificationIdAttribute.java 24 Jan 2007 10:25:14 -0000 1.5 --- ClassificationIdAttribute.java 23 Jul 2007 13:57:39 -0000 1.6 *************** *** 63,70 **** label = createLabel("Code"); component = Box.createHorizontalBox(); ! if (!attribute.getClassification().getName().equalsIgnoreCase("Classification") && ! !attribute.getClassification().getId().equalsIgnoreCase("-1")) { ! component.add(createValueLabel(attribute.getClassification() ! .getFullId(attribute.getLevel()))); } Box header = Box.createHorizontalBox(); --- 63,70 ---- label = createLabel("Code"); component = Box.createHorizontalBox(); ! Classification c = (Classification)attribute.getThe2ndValue(); ! if (!c.getName().equalsIgnoreCase("Classification") && ! !c.getId().equalsIgnoreCase("-1")) { ! component.add(createValueLabel(c.getFullId(attribute.getLevel()))); } Box header = Box.createHorizontalBox(); *************** *** 189,196 **** if (editor == null) { component.remove(0); ! if (attribute.getClassification() != null ! && !attribute.getClassification().getName().equalsIgnoreCase("Classification")) { ! editor = (JTextField) createValueEditor(attribute.getClassification() ! .getFullId(attribute.getLevel())); } else { editor = (JTextField) createValueEditor(""); --- 189,196 ---- if (editor == null) { component.remove(0); ! Classification c = (Classification)attribute.getThe2ndValue(); ! if (c != null ! && !c.getName().equalsIgnoreCase("Classification")) { ! editor = (JTextField) createValueEditor(c.getFullId(attribute.getLevel())); } else { editor = (JTextField) createValueEditor(""); *************** *** 231,235 **** } } ! attribute.setClassification(clas); component.remove(editor); --- 231,235 ---- } } ! attribute.setThe2ndValue(clas); component.remove(editor); |