Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4418/src/net/sourceforge/bprocessor/gui/attrview
Modified Files:
StringAttribute.java GenericPanel.java
Log Message:
rounding of numbers
Index: StringAttribute.java
===================================================================
RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/StringAttribute.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** StringAttribute.java 26 Nov 2007 10:51:04 -0000 1.19
--- StringAttribute.java 9 Sep 2009 12:51:35 -0000 1.20
***************
*** 15,18 ****
--- 15,19 ----
import java.io.Reader;
import java.io.StringReader;
+ import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;
***************
*** 170,173 ****
--- 171,187 ----
}
+ protected String valueOf(Object value) {
+ String s = "";
+ if (value instanceof String) {
+ s = (String)value;
+ } else if (value instanceof Double) {
+ DecimalFormat format = new DecimalFormat("0.000");
+ s = format.format(((Double) value).doubleValue());
+ } else if (value instanceof Integer) {
+ s = String.valueOf((Integer) value);
+ }
+ return s;
+ }
+
/**
* Create a value label
***************
*** 176,187 ****
*/
private JComponent createValueLabel(Object value) {
! String s = "";
JLabel valueLabel;
- 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()) {
--- 190,195 ----
*/
private JComponent createValueLabel(Object value) {
! String s = valueOf(value);
JLabel valueLabel;
valueLabel = new JLabel(s);
if (attribute.isEditable()) {
***************
*** 199,209 ****
*/
private JComponent createValueEditor(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);
! }
JTextField valueEditor = new JTextField(s);
valueEditor.setFont(AttributeView.FONT_PLAIN);
--- 207,211 ----
*/
private JComponent createValueEditor(Object value) {
! String s = valueOf(value);
JTextField valueEditor = new JTextField(s);
valueEditor.setFont(AttributeView.FONT_PLAIN);
***************
*** 253,257 ****
try {
Object val = attribute.getValue();
! if (val instanceof String) {
attribute.setValue(editor.getText());
} else if (val instanceof Double) {
--- 255,261 ----
try {
Object val = attribute.getValue();
! if (val instanceof Integer) {
! attribute.setValue(Integer.valueOf(editor.getText()));
! } else if (val instanceof String) {
attribute.setValue(editor.getText());
} else if (val instanceof Double) {
Index: GenericPanel.java
===================================================================
RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** GenericPanel.java 28 Dec 2007 11:17:09 -0000 1.53
--- GenericPanel.java 9 Sep 2009 12:51:35 -0000 1.54
***************
*** 217,221 ****
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) {
--- 217,223 ----
while (iter.hasNext()) {
Attribute a = (Attribute)iter.next();
! if (a.getValue() instanceof String
! || a.getValue() instanceof Double
! || a.getValue() instanceof Integer) {
handleString(a, where);
} else if (a.getValue() instanceof List) {
|