[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview DescriptionAttribute.java,NONE,1
Status: Pre-Alpha
Brought to you by:
henryml
From: Nikolaj B. <nbr...@us...> - 2006-02-28 02:32:45
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16886/src/net/sourceforge/bprocessor/gui/attrview Modified Files: AttributePanel.java StringAttribute.java GenericPanel.java Added Files: DescriptionAttribute.java LinkAttribute.java Log Message: All that is displayed in the attribute view should now be parametric Index: StringAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/StringAttribute.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** StringAttribute.java 15 Feb 2006 11:12:51 -0000 1.6 --- StringAttribute.java 28 Feb 2006 02:25:48 -0000 1.7 *************** *** 45,48 **** --- 45,51 ---- private JTextField editor; + + + /** * Constructor for StringAttribute *************** *** 72,79 **** this.add(component); this.add(Box.createHorizontalGlue()); - if (attribute.isEditable()) { - label.addMouseListener(this); - component.addMouseListener(this); - } } --- 75,78 ---- *************** *** 156,160 **** double rounded = round(((Double) value).doubleValue()); s = Double.toString(rounded); ! } JLabel valueLabel = new JLabel(s); if (attribute.isEditable()) { --- 155,160 ---- double rounded = round(((Double) value).doubleValue()); s = Double.toString(rounded); ! } ! JLabel valueLabel = new JLabel(s); if (attribute.isEditable()) { *************** *** 163,167 **** valueLabel.setFont(AttributeView.FONT_ITALIC); } ! return valueLabel; } --- 163,167 ---- valueLabel.setFont(AttributeView.FONT_ITALIC); } ! return valueLabel; } *************** *** 178,182 **** double rounded = round(((Double) value).doubleValue()); s = Double.toString(rounded); ! } JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributeView.FONT_PLAIN); --- 178,182 ---- double rounded = round(((Double) value).doubleValue()); s = Double.toString(rounded); ! } JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributeView.FONT_PLAIN); Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericPanel.java 15 Feb 2006 11:12:51 -0000 1.7 --- GenericPanel.java 28 Feb 2006 02:25:49 -0000 1.8 *************** *** 26,32 **** --- 26,35 ---- import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; + import net.sourceforge.bprocessor.model.Description; import net.sourceforge.bprocessor.model.Entity; import net.sourceforge.bprocessor.model.Parametric; import net.sourceforge.bprocessor.model.Project; + import net.sourceforge.bprocessor.model.Selection; + import net.sourceforge.bprocessor.model.Surface; /** *************** *** 49,52 **** --- 52,59 ---- private GenericAttribute current; + + /** The kludge */ + protected boolean simpleUpdate = false; + /** * The constructor *************** *** 90,93 **** --- 97,101 ---- obj.setAttributes(attributes); if (obj instanceof Entity) { + simpleUpdate = true; ((Entity)obj).changed(); } else if (obj instanceof Camera) { *************** *** 96,102 **** log.info("Were not a Entity object " + obj); } ! } }); ! sa.addMouseListener(this); where.add(new AttributeRow(sa)); } else if (a.getValue() instanceof List) { --- 104,110 ---- log.info("Were not a Entity object " + obj); } ! } }); ! //sa.addMouseListener(this); where.add(new AttributeRow(sa)); } else if (a.getValue() instanceof List) { *************** *** 114,118 **** } where.add(more); ! } else { log.info("[GenericPanel] Something were not implemented"); } --- 122,162 ---- } 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); ! if (obj instanceof Entity) { ! simpleUpdate = true; ! ((Entity)obj).changed(); ! } else if (obj instanceof Camera) { ! Project.getInstance().changed((Camera)obj); ! } else { ! log.info("Were not a Entity object " + obj); ! } ! } ! }); ! //da.addMouseListener(this); ! where.add(new AttributeRow(da)); ! } else if (a.getValue() instanceof Surface) { ! // Handles the description field ! LinkAttribute la = new LinkAttribute(a); ! la.addLinkAttributeListener(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); ! } else { ! log.info("Were not a Entity object " + obj); ! } ! } ! }); ! //da.addMouseListener(this); ! where.add(new AttributeRow(la)); ! } else { log.info("[GenericPanel] Something were not implemented"); } *************** *** 126,135 **** */ public void startEditing(GenericAttribute ga) { ! if (current != null) { ! current.stopEditing(); ! } current = ga; ! if (current != null) { ! ga.startEditing(); } } --- 170,182 ---- */ public void startEditing(GenericAttribute ga) { ! stopEditing(); current = ga; ! if (ga instanceof LinkAttribute) { ! Selection.primary().set(ga.attribute().getValue()); ! //Selection.primary().changed(); ! } else { ! if (current != null) { ! current.startEditing(); ! } } } *************** *** 189,193 **** this.ga = ga; this.add(ga); ! ga.addMouseListener(this); } --- 236,242 ---- this.ga = ga; this.add(ga); ! if (ga.attribute().isEditable() || ga instanceof LinkAttribute) { ! ga.addMouseListener(this); ! } } *************** *** 234,241 **** */ public void update() { //FIXME need to delay call to a reasonable time content.removeAll(); ! generateContent(obj.getAttributes(), content); revalidate(); } } --- 283,309 ---- */ public void update() { + if (simpleUpdate) { + simpleUpdate(); + simpleUpdate = false; + } else { + complexUpdate(); + } + } + /** + * + * + */ + public void complexUpdate() { //FIXME need to delay call to a reasonable time content.removeAll(); ! attributes = obj.getAttributes(); ! generateContent(attributes, content); revalidate(); } + + /** + * + * + */ + public void simpleUpdate() { } } Index: AttributePanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributePanel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AttributePanel.java 9 Feb 2006 13:55:12 -0000 1.5 --- AttributePanel.java 28 Feb 2006 02:25:48 -0000 1.6 *************** *** 97,101 **** nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); ! JTextArea descriptionEditor = new JTextArea(o.getDescription()); descriptionEditor.setLineWrap(true); descriptionEditor.setWrapStyleWord(true); --- 97,101 ---- nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); ! JTextArea descriptionEditor = new JTextArea(o.getDescription().toString()); descriptionEditor.setLineWrap(true); descriptionEditor.setWrapStyleWord(true); --- NEW FILE: LinkAttribute.java --- //--------------------------------------------------------------------------------- // $Id: LinkAttribute.java,v 1.1 2006/02/28 02:25:49 nbramsen Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.attrview; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JTextField; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Surface; /** * The StringAttributeView */ public class LinkAttribute extends GenericAttribute { /** The listeners */ private List listeners; /** The attribute this gui represents */ private Attribute attribute; /** The component */ private JComponent component; /** The Label */ private JLabel label; /** The editor, when this EditableAttribute is being edited */ private JTextField editor; /** * Constructor for StringAttribute * @param attribute The attribute */ public LinkAttribute(Attribute attribute) { super(BoxLayout.X_AXIS); this.attribute = attribute; this.listeners = new LinkedList(); label = createLabel(attribute.getName()); Box header = Box.createHorizontalBox(); Box column = Box.createVerticalBox(); header.add(Box.createHorizontalGlue()); header.add(label); //column.add(Box.createHorizontalStrut(60)); column.add(Box.createRigidArea(new Dimension(70, 3))); column.add(header); column.add(Box.createRigidArea(new Dimension(70, 3))); //column.add(Box.createHorizontalStrut(60)); column.setMaximumSize(new Dimension(60, Short.MAX_VALUE)); this.add(column); this.add(Box.createHorizontalStrut(7)); component = Box.createHorizontalBox(); component.add(createValueLabel(attribute.getValue())); this.add(component); this.add(Box.createHorizontalGlue()); } /** * Create a label for the * @param key The key * @return A JLabel */ private JLabel createLabel(String key) { JLabel keyLabel = new JLabel(key + " :"); keyLabel.setFont(AttributeView.FONT_BOLD); return keyLabel; } /** * Add a mouselisterner to the active elements in the StringAttribute * @param mouseListener the mouselistener */ public void addMouseListener(MouseListener mouseListener) { label.addMouseListener(mouseListener); component.addMouseListener(mouseListener); } /** * Remove a mouselisterner to the active elements in the StringAttribute * @param mouseListener the mouselistener */ public void removeMouseListener(MouseListener mouseListener) { label.removeMouseListener(mouseListener); component.removeMouseListener(mouseListener); } /** * Add a listener that are notified when the value is changed * @param listener The listener */ public void addLinkAttributeListener(AttributeListener listener) { listeners.add(listener); } /** * Remove a listener * @param listener The listener */ public void removeLinkAttributeListener(AttributeListener listener) { listeners.remove(listener); } /** * Send valueChanged to all listeners */ protected void valueChanged() { Iterator iter = listeners.iterator(); while (iter.hasNext()) { AttributeListener current = (AttributeListener) iter.next(); current.valueChanged(attribute); } } /** * Create a value label * @param value The value * @return The label */ private JComponent createValueLabel(Object value) { String s = ""; s = ((Surface)value).getName(); JLabel valueLabel = new JLabel(s); if (attribute.isEditable()) { valueLabel.setFont(AttributeView.FONT_PLAIN); } else { valueLabel.setFont(AttributeView.FONT_ITALIC); } return valueLabel; } /** * Create a value editor * @param value The value * @return The editor */ private JComponent createValueEditor(Object value) { String s = ""; if (value instanceof String) { s = (String)value; } JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; } /** * Return the attribute * @return The attribute */ public Attribute attribute() { return attribute; } /** * Start editing the value by replacing the label with an editor */ public void startEditing() { if (attribute.isEditable()) { if (editor == null) { component.remove(0); editor = (JTextField) createValueEditor(attribute.getValue()); component.add(editor); component.revalidate(); } editor.requestFocus(); editor.selectAll(); } } /** * Stop editing the value by replacing the editor with an label, * and sending valueChanged to all listeners. */ public void stopEditing() { if (editor != null && attribute.isEditable()) { Object val = attribute.getValue(); if (val instanceof String) { attribute.setValue(editor.getText()); } component.remove(editor); editor = null; component.add(createValueLabel(attribute.getValue())); component.revalidate(); valueChanged(); } } /** * Cancels editing the value by replacing the editor with an label, * without sending any events to listeners. */ public void cancelEditing() { if (editor != null) { component.remove(editor); editor = null; component.add(createValueLabel(attribute.getValue())); component.revalidate(); } } /** * Start editing on the view * @param event The event */ public void mouseClicked(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mousePressed(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseReleased(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseEntered(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseExited(MouseEvent event) { } } --- NEW FILE: DescriptionAttribute.java --- //--------------------------------------------------------------------------------- // $Id: DescriptionAttribute.java,v 1.1 2006/02/28 02:25:48 nbramsen Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.attrview; import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JTextArea; import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Description; /** * The StringAttributeView */ public class DescriptionAttribute extends GenericAttribute implements MouseListener { /** The listeners */ private List listeners; /** The attribute this gui represents */ private Attribute attribute; /** The component */ private JComponent component; /** The Label */ private JLabel label; /** The editor, when this Description Attribute is being edited */ private JTextArea descriptionEditor; /** * Constructor for StringAttribute * @param attribute The attribute */ public DescriptionAttribute(Attribute attribute) { super(BoxLayout.X_AXIS); this.attribute = attribute; this.listeners = new LinkedList(); label = createLabel(attribute.getName()); Box header = Box.createHorizontalBox(); Box column = Box.createVerticalBox(); header.add(Box.createHorizontalGlue()); header.add(label); header.add(Box.createHorizontalGlue()); //column.add(Box.createHorizontalStrut(60)); column.add(Box.createRigidArea(new Dimension(70, 3))); column.add(header); column.add(Box.createRigidArea(new Dimension(70, 3))); //column.add(Box.createHorizontalStrut(60)); //column.setMaximumSize(new Dimension(60, Short.MAX_VALUE)); //this.add(Box.createHorizontalStrut(7)); component = Box.createVerticalBox(); component.add(createValueLabel(attribute.getValue())); column.add(component); this.add(column); } /** * Create a label for the * @param key The key * @return A JLabel */ private JLabel createLabel(String key) { JLabel keyLabel = new JLabel(key + " :"); keyLabel.setFont(AttributeView.FONT_BOLD); return keyLabel; } /** * Add a mouselisterner to the active elements in the StringAttribute * @param mouseListener the mouselistener */ public void addMouseListener(MouseListener mouseListener) { label.addMouseListener(mouseListener); component.addMouseListener(mouseListener); } /** * Remove a mouselisterner to the active elements in the StringAttribute * @param mouseListener the mouselistener */ public void removeMouseListener(MouseListener mouseListener) { label.removeMouseListener(mouseListener); component.removeMouseListener(mouseListener); } /** * Add a listener that are notified when the value is changed * @param listener The listener */ public void addDescriptionAttributeListener(AttributeListener listener) { listeners.add(listener); } /** * Remove a listener * @param listener The listener */ public void removeDescriptionAttributeListener(AttributeListener listener) { listeners.remove(listener); } /** * Send valueChanged to all listeners */ protected void valueChanged() { Iterator iter = listeners.iterator(); while (iter.hasNext()) { AttributeListener current = (AttributeListener) iter.next(); current.valueChanged(attribute); } } /** * Create a value label * @param value The value * @return The label */ private JComponent createValueLabel(Object value) { String s = ""; s = value.toString(); JTextArea valueLabel = new JTextArea(s); valueLabel.setBackground(new Color(204, 204, 204)); valueLabel.setLineWrap(true); valueLabel.setWrapStyleWord(true); valueLabel.setEditable(false); if (attribute.isEditable()) { valueLabel.setFont(AttributeView.FONT_PLAIN); } else { valueLabel.setFont(AttributeView.FONT_ITALIC); } return valueLabel; } /** * Create a value editor * @param value The value * @return The editor */ private JComponent createValueEditor(Object value) { String s = ""; s = value.toString(); JTextArea valueEditor = new JTextArea(s); valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; } /** * Return the attribute * @return The attribute */ public Attribute attribute() { return attribute; } /** * Start editing the value by replacing the label with an editor */ public void startEditing() { if (attribute.isEditable()) { if (descriptionEditor == null) { component.remove(0); descriptionEditor = (JTextArea) createValueEditor(attribute.getValue()); descriptionEditor.setLineWrap(true); descriptionEditor.setWrapStyleWord(true); component.add(descriptionEditor); component.revalidate(); } descriptionEditor.requestFocus(); descriptionEditor.selectAll(); } } /** * Stop editing the value by replacing the editor with an label, * and sending valueChanged to all listeners. */ public void stopEditing() { if (descriptionEditor != null && attribute.isEditable()) { Object val = attribute.getValue(); attribute.setValue(new Description(descriptionEditor.getText())); component.remove(descriptionEditor); descriptionEditor = null; component.add(createValueLabel(attribute.getValue())); component.revalidate(); valueChanged(); } } /** * Cancels editing the value by replacing the editor with an label, * without sending any events to listeners. */ public void cancelEditing() { if (descriptionEditor != null) { component.remove(descriptionEditor); descriptionEditor = null; component.add(createValueLabel(attribute.getValue())); component.revalidate(); } } /** * Start editing on the view * @param event The event */ public void mouseClicked(MouseEvent event) { startEditing(); } /** * Not in use * @param event The MouseEvent */ public void mousePressed(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseReleased(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseEntered(MouseEvent event) { } /** * Not in use * @param event The MouseEvent */ public void mouseExited(MouseEvent event) { } } |