r1384 - in jaxx/trunk: jaxx-example/src/main/java/jaxx/demo jaxx-runtime-swing-widget/src/main/java/jaxx/runtime/swing/editor
Author: sletellier Date: 2009-05-04 23:55:44 +0000 (Mon, 04 May 2009) New Revision: 1384 Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/NumberEditorDemo.jaxx jaxx/trunk/jaxx-runtime-swing-widget/src/main/java/jaxx/runtime/swing/editor/NumberEditorHandler.java Log: Determine si la propriete concernee est un float Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/NumberEditorDemo.jaxx =================================================================== --- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/NumberEditorDemo.jaxx 2009-05-04 23:09:13 UTC (rev 1383) +++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/NumberEditorDemo.jaxx 2009-05-04 23:55:44 UTC (rev 1384) @@ -95,8 +95,7 @@ model='{demoModel.getPositifFloat()}' autoPopup='false' showPopupButton='true' - showReset='true' - useFloat='true'/> + showReset='true'/> </cell> <cell> <NumberEditor id='positifFloatEditor2' @@ -106,8 +105,7 @@ model='{demoModel.getPositifFloat()}' autoPopup='true' showPopupButton='true' - showReset='true' - useFloat='true'/> + showReset='true'/> </cell> </row> <row> @@ -123,8 +121,7 @@ autoPopup='false' showPopupButton='true' showReset='true' - useSign='true' - useFloat='true'/> + useSign='true'/> </cell> <cell> <NumberEditor id='normalFloatEditor2' @@ -135,32 +132,9 @@ autoPopup='true' showPopupButton='true' showReset='true' - useSign='true' - useFloat='true'/> + useSign='true'/> </cell> </row> - <row> - <cell> - - </cell> - <cell> - - </cell> - <cell> - - </cell> - </row> - <row> - <cell> - - </cell> - <cell> - - </cell> - <cell> - - </cell> - </row> </Table> </DemoPanel> Modified: jaxx/trunk/jaxx-runtime-swing-widget/src/main/java/jaxx/runtime/swing/editor/NumberEditorHandler.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing-widget/src/main/java/jaxx/runtime/swing/editor/NumberEditorHandler.java 2009-05-04 23:09:13 UTC (rev 1383) +++ jaxx/trunk/jaxx-runtime-swing-widget/src/main/java/jaxx/runtime/swing/editor/NumberEditorHandler.java 2009-05-04 23:55:44 UTC (rev 1384) @@ -33,13 +33,15 @@ public static final String MODEL_PROPERTY = "model"; public static final String AUTO_POPUP_PROPERTY = "autoPopup"; public static final String POPUP_VISIBLE_PROPERTY = "popupVisible"; - public static final String USE_FLOAT_PROPERTY = "useFloat"; +// public static final String USE_FLOAT_PROPERTY = "useFloat"; public static final String USE_SIGN_PROPERTY = "useSign"; public static final String VALIDATE_PROPERTY = "validate"; /** editor ui */ protected NumberEditor editor; /** the mutator method on the property of boxed bean in the editor */ protected Method mutator; + /** the getter method on the property */ + protected Method getter; /** a flag to known if mutator accept null value */ protected Boolean acceptNull; @@ -72,6 +74,11 @@ } }); editor.getTextField().addMouseListener(new PopupListener()); + + // Determine si c'est un float + Class type = getGetter().getReturnType(); + editor.setUseFloat(!type.equals(Integer.class) && !type.equals(int.class)); + /*if (editor.getResetButton().getIcon() == null) { editor.getResetButton().setIcon(SwingUtil.createActionIcon("numbereditor-reset")); } @@ -141,8 +148,8 @@ } else if (s.endsWith(".")) { s += "0"; endWithDot = true; - } else if (s.length() == 1 && s.startsWith("-")) { - s += "0"; + } else if (editor.isUseSign() && s.length() == 1 && s.startsWith("-")) { + s = "0"; isLess = true; } @@ -186,10 +193,12 @@ if (log.isDebugEnabled()) { log.debug("can apply new model value : " + newValue); } - if (!isLess){ - // on peut mettre a jour le model - editor.setModel(newValue); + if (isLess){ + editor.setModelText("-"); + return; } + // on peut mettre a jour le model + editor.setModel(newValue); if (endWithDot) { editor.setModelText(s.substring(0, s.length() - 1)); field.setCaretPosition(oldPosition); @@ -208,7 +217,12 @@ oldPosition--; } field.setText(text); - field.setCaretPosition(oldPosition); + try { + field.setCaretPosition(oldPosition); + } + catch(IllegalArgumentException ex){ + log.debug("CaretPosition is invalid for position : " + oldPosition, ex); + } } /** @@ -383,6 +397,27 @@ return mutator; } + protected Method getGetter() { + if (getter == null) { + Object bean = editor.getBean(); + if (bean == null) { + throw new NullPointerException("could not find bean in " + editor); + } + String property = editor.getProperty(); + if (property == null) { + throw new NullPointerException("could not find property in " + editor); + } + + try { + PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, property); + getter = descriptor.getReadMethod(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + return getter; + } + public Boolean getAcceptNull() { if (acceptNull == null) { Method m = getMutator();
participants (1)
-
sletellier@users.labs.libre-entreprise.org