Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview DescriptionAttribute.java,1.4,1.
Status: Pre-Alpha
Brought to you by:
henryml
From: Nikolaj B. <nbr...@us...> - 2006-03-16 10:17:00
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8179/src/net/sourceforge/bprocessor/gui/attrview Modified Files: DescriptionAttribute.java StringAttribute.java LinkAttribute.java GenericPanel.java Log Message: Made the description scrollable and made some different code optimization Index: StringAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/StringAttribute.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** StringAttribute.java 13 Mar 2006 11:31:45 -0000 1.9 --- StringAttribute.java 16 Mar 2006 10:16:55 -0000 1.10 *************** *** 24,27 **** --- 24,28 ---- import net.sourceforge.bprocessor.model.Attribute; + import net.sourceforge.bprocessor.model.Entity; /** *************** *** 149,164 **** private JComponent createValueLabel(Object value) { String s = ""; ! if (value instanceof String) { ! s = (String)value; ! } else if (value instanceof Double) { ! double rounded = round(((Double) value).doubleValue()); ! s = Double.toString(rounded); ! } ! ! JLabel valueLabel = new JLabel(s); ! if (attribute.isEditable()) { ! valueLabel.setFont(AttributeView.FONT_PLAIN); ! } else { valueLabel.setFont(AttributeView.FONT_ITALIC); } return valueLabel; --- 150,171 ---- private JComponent createValueLabel(Object value) { String s = ""; ! JLabel valueLabel; ! if (value instanceof Entity) { ! s = ((Entity)value).getName(); ! valueLabel = new JLabel(s); valueLabel.setFont(AttributeView.FONT_ITALIC); + } else { + if (value instanceof String) { + s = (String)value; + } else if (value instanceof Double) { + double rounded = round(((Double) value).doubleValue()); + s = Double.toString(rounded); + } + valueLabel = new JLabel(s); + if (attribute.isEditable()) { + valueLabel.setFont(AttributeView.FONT_PLAIN); + } else { + valueLabel.setFont(AttributeView.FONT_ITALIC); + } } return valueLabel; *************** *** 180,186 **** JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; } ! /** * Return the attribute --- 187,195 ---- JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributeView.FONT_PLAIN); + return valueEditor; } ! ! /** * Return the attribute Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GenericPanel.java 13 Mar 2006 11:31:45 -0000 1.14 --- GenericPanel.java 16 Mar 2006 10:16:55 -0000 1.15 *************** *** 144,148 **** // Handles the links LinkAttribute la = new LinkAttribute(a); ! la.addLinkAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { obj.setAttributes(attributes); --- 144,148 ---- // Handles the links LinkAttribute la = new LinkAttribute(a); ! la.addStringAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { obj.setAttributes(attributes); Index: LinkAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/LinkAttribute.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LinkAttribute.java 10 Mar 2006 14:10:30 -0000 1.4 --- LinkAttribute.java 16 Mar 2006 10:16:55 -0000 1.5 *************** *** 8,246 **** 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.Entity; /** * The LinkAttributeView */ ! 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 LinkAttribute * @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.createHorizontalStrut(7)); ! header.add(label); ! header.add(Box.createHorizontalGlue()); ! column.add(Box.createRigidArea(new Dimension(70, 3))); ! column.add(header); ! column.add(Box.createRigidArea(new Dimension(70, 3))); ! column.setMaximumSize(new Dimension(60, Short.MAX_VALUE)); ! this.add(column); ! 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 LinkAttribute ! * @param mouseListener the mouselistener ! */ ! public void addMouseListener(MouseListener mouseListener) { ! label.addMouseListener(mouseListener); ! component.addMouseListener(mouseListener); ! } ! ! /** ! * Remove a mouselisterner to the active elements in the LinkAttribute ! * @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 = ((Entity)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) { } } --- 8,27 ---- package net.sourceforge.bprocessor.gui.attrview; import net.sourceforge.bprocessor.model.Attribute; ! /** * The LinkAttributeView */ ! public class LinkAttribute extends StringAttribute { /** ! * Constructor * @param attribute The attribute */ public LinkAttribute(Attribute attribute) { ! super(attribute); } } Index: DescriptionAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/DescriptionAttribute.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DescriptionAttribute.java 13 Mar 2006 11:31:45 -0000 1.4 --- DescriptionAttribute.java 16 Mar 2006 10:16:55 -0000 1.5 *************** *** 212,216 **** public void stopEditing() { if (descriptionEditor != null && attribute.isEditable()) { - Object val = attribute.getValue(); attribute.setValue(new Description(descriptionEditor.getText())); component.remove(descriptionArea); --- 212,215 ---- |