Skip to main content

[patch] jdnc

1 reply [Last post]
Anonymous

Username: grandinj, JCA submitted
Against current cvs.dev.java.net/cvs/jdnc HEAD.

Improve handling of numbers in ComponentMap.

Add clearBinding() methods to JForm.

NOTICE: Please note that this email, and the contents thereof,
are subject to the standard Peralex email disclaimer, which may
be found at: http://www.peralex.com/disclaimer.html

If you cannot access the disclaimer through the URL attached
and you wish to receive a copy thereof please send
an email to email@peralex.com
Index: swingx/src/java/org/jdesktop/swing/form/ComponentMap.java
===================================================================
RCS file: /cvs/jdnc/swingx/src/java/org/jdesktop/swing/form/ComponentMap.java,v
retrieving revision 1.6
diff -u -r1.6 ComponentMap.java
--- swingx/src/java/org/jdesktop/swing/form/ComponentMap.java 7 Mar 2005 15:27:02 -0000 1.6
+++ swingx/src/java/org/jdesktop/swing/form/ComponentMap.java 6 Apr 2005 12:17:38 -0000
@@ -30,11 +30,11 @@
import javax.swing.ListModel;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
+import javax.swing.JSpinner.NumberEditor;

import org.jdesktop.swing.JXDatePicker;
import org.jdesktop.swing.JXImagePanel;
import org.jdesktop.swing.JXListPanel;
-import org.jdesktop.swing.JXRadioGroup;
import org.jdesktop.swing.JXTable;
import org.jdesktop.swing.LinkHandler;
import org.jdesktop.swing.data.DataModel;
@@ -45,7 +45,6 @@
import org.jdesktop.swing.data.MetaData;
import org.jdesktop.swing.data.NumberMetaData;
import org.jdesktop.swing.data.StringMetaData;
-import org.jdesktop.swing.data.TabularDataModel;
import org.jdesktop.swing.data.TabularMetaData;

/**
@@ -77,7 +76,7 @@
private List assignables;

private static ComponentMap instance = new ComponentMap();
-
+
public static ComponentMap getInstance() {
return instance;
}
@@ -85,7 +84,8 @@
public static void setInstance(ComponentMap map) {
instance = map;
}
- /**
+
+ /**
* creates and returns a component based on the given MetaData.
*
* @param metaData
@@ -93,7 +93,13 @@
*/
public JComponent createComponent(MetaData metaData) {
ComponentCreator creator = getComponentCreator(metaData);
- return creator.createComponent(metaData);
+ JComponent comp = creator.createComponent(metaData);
+ if (comp==null) {
+ // default creator could not create it, so use fallback creator
+ creator = getFallBackComponentCreator();
+ comp = creator.createComponent(metaData);
+ }
+ return comp;
}

/**
@@ -343,21 +349,50 @@

public JComponent createComponent(MetaData metaData) {
if (!(metaData instanceof NumberMetaData)) {
- // Hack: prevents making static... where else to put?
- return getFallBackComponentCreator().createComponent(metaData);
+ // the fallback creator will get called
+ return null;
}
JComponent comp = createComponent((NumberMetaData) metaData);
+ if (comp==null) {
+ return null;
+ }
comp.setName(metaData.getName());
return comp;
}

- public JComponent createComponent(NumberMetaData numberMetaData) {
+ private JComponent createComponent(NumberMetaData numberMetaData) {
Class fieldClass = numberMetaData.getElementClass();
Number min = numberMetaData.getMinimum();
Number max = numberMetaData.getMaximum();
+
+ if (min == null) {
+ if (fieldClass == Integer.class) {
+ min = Integer.MIN_VALUE;
+ } else if (fieldClass == Long.class) {
+ min = Long.MIN_VALUE;
+ } else if (fieldClass == Short.class) {
+ min = Short.MIN_VALUE;
+ } else if (fieldClass == int.class) {
+ min = Integer.MIN_VALUE;
+ }
+ }
+
+ if (max == null) {
+ if (fieldClass == Integer.class) {
+ max = Integer.MAX_VALUE;
+ } else if (fieldClass == Long.class) {
+ max = Long.MAX_VALUE;
+ } else if (fieldClass == Short.class) {
+ max = Short.MAX_VALUE;
+ } else if (fieldClass == int.class) {
+ max = Integer.MAX_VALUE;
+ }
+ }
+
// JW: edit constraint - move to SpinnerBinding
+ SpinnerModel spinnerModel = null;
+ boolean fudgeFloatWidth = false;
if ((min != null) && (max != null)) {
- SpinnerModel spinnerModel = null;
if ((fieldClass == Integer.class) || (fieldClass == Long.class)
|| (fieldClass == Short.class)
|| (fieldClass == int.class)) {
@@ -368,26 +403,47 @@
|| (fieldClass == float.class)
|| (fieldClass == double.class)) {

- // **@todo aim: need to add precision to NumberMetaData */
+ /** @todo aim: need to add precision to NumberMetaData */
spinnerModel = new SpinnerNumberModel(min.doubleValue(),
min.doubleValue(), max.doubleValue(), .01);
+ } else if (min instanceof Comparable && max instanceof Comparable) {
+ spinnerModel = new SpinnerNumberModel(min,
+ (Comparable)min, (Comparable)max, new Integer(1));
}
- if (spinnerModel != null) {
- return new JSpinner(spinnerModel);
+ } else if (min==null && max==null
+ && (fieldClass == Float.class
+ || fieldClass == Double.class
+ || fieldClass == float.class
+ || fieldClass == double.class))
+ {
+ // if we default the min and max to the real min and max
+ // of the type, the JSpinner display will be unreasonably wide.
+ spinnerModel = new SpinnerNumberModel(new Integer(0),
+ null, null, new Integer(1));
+ fudgeFloatWidth = true;
+ } else {
+ // if we don't have min and max still do something useful
+ spinnerModel = new SpinnerNumberModel(new Integer(0),
+ (Comparable) min, (Comparable) max, new Integer(1));
+ }
+
+ if (spinnerModel!=null) {
+ JSpinner spinner = new JSpinner(spinnerModel);
+ if (fudgeFloatWidth) {
+ ((JSpinner.NumberEditor) spinner.getEditor()).getTextField().setColumns(10);
}
+ return spinner;
}
- // Hack: prevents making static... where else to put?
- return getFallBackComponentCreator()
- .createComponent(numberMetaData);
+
+ // the fallback creator will get called
+ return null;
}
}

/**
+ * creates and returns a JTextComponent.
*/
public static class TextCreator implements ComponentCreator {
- /**
- * creates and returns a JTextComponent.
- */

public JComponent createComponent(MetaData metaData) {
if (metaData instanceof StringMetaData) {
Index: swingx/src/java/org/jdesktop/swing/form/JForm.java
===================================================================
RCS file: /cvs/jdnc/swingx/src/java/org/jdesktop/swing/form/JForm.java,v
retrieving revision 1.5
diff -u -r1.5 JForm.java
--- swingx/src/java/org/jdesktop/swing/form/JForm.java 3 Feb 2005 13:33:06 -0000 1.5
+++ swingx/src/java/org/jdesktop/swing/form/JForm.java 31 Mar 2005 12:04:11 -0000
@@ -415,6 +415,15 @@
}

/**
+ * Removes all the bindings from the form.
+ */
+ public void clearBindings() {
+ if (bindings != null) {
+ bindings.clear();
+ }
+ }
+
+ /**
*
* @return array containing all Binding objects currently in this form
*/

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kleopatra

just committed your patch, thanks!

Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net