[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview StringAttribute.java,1.1,1.2 Gen
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-02-03 20:11:53
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18258/src/net/sourceforge/bprocessor/gui/attrview Modified Files: StringAttribute.java GenericPanel.java Log Message: added stringattribute so that i also handle Doubles and added support for the attributes with value = null Index: StringAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/StringAttribute.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StringAttribute.java 3 Feb 2006 15:23:00 -0000 1.1 --- StringAttribute.java 3 Feb 2006 20:11:45 -0000 1.2 *************** *** 67,71 **** this.add(Box.createHorizontalStrut(7)); component = Box.createHorizontalBox(); ! component.add(createValueLabel((String)attribute.getValue())); this.add(component); this.add(Box.createHorizontalGlue()); --- 67,71 ---- this.add(Box.createHorizontalStrut(7)); component = Box.createHorizontalBox(); ! component.add(createValueLabel(attribute.getValue())); this.add(component); this.add(Box.createHorizontalGlue()); *************** *** 135,140 **** * @return The label */ ! private JComponent createValueLabel(String value) { ! JLabel valueLabel = new JLabel(value); valueLabel.setFont(AttributePanel.FONT_PLAIN); return valueLabel; --- 135,146 ---- * @return The label */ ! private JComponent createValueLabel(Object value) { ! String s = ""; ! if (value instanceof String) { ! s = (String)value; ! } else if (value instanceof Double) { ! s = ((Double) value).toString(); ! } ! JLabel valueLabel = new JLabel(s); valueLabel.setFont(AttributePanel.FONT_PLAIN); return valueLabel; *************** *** 146,151 **** * @return The editor */ ! private JComponent createValueEditor(String value) { ! JTextField valueEditor = new JTextField(value); valueEditor.setFont(AttributePanel.FONT_PLAIN); return valueEditor; --- 152,163 ---- * @return The editor */ ! private JComponent createValueEditor(Object value) { ! String s = ""; ! if (value instanceof String) { ! s = (String)value; ! } else if (value instanceof Double) { ! s = ((Double) value).toString(); ! } ! JTextField valueEditor = new JTextField(s); valueEditor.setFont(AttributePanel.FONT_PLAIN); return valueEditor; *************** *** 166,170 **** if (editor == null) { component.remove(0); ! editor = (JTextField) createValueEditor((String)attribute.getValue()); editor.addKeyListener(this); component.add(editor); --- 178,182 ---- if (editor == null) { component.remove(0); ! editor = (JTextField) createValueEditor(attribute.getValue()); editor.addKeyListener(this); component.add(editor); *************** *** 181,189 **** public void stopEditing() { if (editor != null) { component.remove(editor); - attribute.setValue(editor.getText()); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel((String)attribute.getValue())); component.revalidate(); valueChanged(); --- 193,206 ---- public void stopEditing() { if (editor != null) { + Object val = attribute.getValue(); + if (val instanceof String) { + attribute.setValue(editor.getText()); + } else if (val instanceof Double) { + attribute.setValue(Double.valueOf(editor.getText())); + } component.remove(editor); editor.removeKeyListener(this); editor = null; ! component.add(createValueLabel(attribute.getValue())); component.revalidate(); valueChanged(); Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenericPanel.java 3 Feb 2006 15:23:00 -0000 1.1 --- GenericPanel.java 3 Feb 2006 20:11:45 -0000 1.2 *************** *** 14,17 **** --- 14,18 ---- import javax.swing.Box; import javax.swing.BoxLayout; + import javax.swing.JLabel; import javax.swing.JPanel; *************** *** 57,61 **** while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); ! if (a.getValue() instanceof String) { StringAttribute sa = new StringAttribute(a); sa.addStringAttributeListener(new AttributeListener() { --- 58,62 ---- while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); ! if (a.getValue() instanceof String || a.getValue() instanceof Double) { StringAttribute sa = new StringAttribute(a); sa.addStringAttributeListener(new AttributeListener() { *************** *** 67,70 **** --- 68,74 ---- sa.addMouseListener(this); content.add(new AttributeRow(sa)); + } else if (a.getValue() == null) { + // Just a label + content.add(new JLabel(a.getName())); } } |