Hi Gene,

ULCPercentDataType, the way it is implemented at present, does not allow
character 'E' and by default allows only 2 fraction digits. It converts the
entered number into a Double. So when you enter a large value, a double
number appears in exponential form and since 'E' is not a valid character
the formatter rejects it and shows nothing.

When 10000010 is entered it is formatted as 1.00 % because the max fraction
digits by default is 2 and the converted number is 1.000001E7 with chopped
off fraction is 1.00.

When 10000000 is entered, the formatted number is 1.0E7 and since 'E' is not
a valid character the string is rejected.

Given the present implementation you cannot prevent the number from being
converted to exponential form.

At the end of this mail I have attached snippet which extends
ULCPercentDataType to allow exponential format to be displayed.

Moreover you can implement your own datatype. For instance, please see the
following links
http://lists.canoo.com/mailman/private/ulc-developer/2005/001919.html
http://lists.canoo.com/mailman/private/ulc-developer/2004/001037.html

I have created an issue https://www.canoo.com/jira/browse/UBA-6918 in our
database.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Eugene Coelho
Sent: Tuesday, May 02, 2006 12:09 PM
To: UlC Devleoper list
Subject: [ULC-developer] problem with ULCPercentDataType


Hi,

i  have the following problem,

If i set the datatype of a text feild to ULCPercentDataType and  if a user
enters a very large value in this text feild it gets converted to
exponential no (like 1.0E ) .... can this  be avoided  but still the
formatting should be  with % sign at the end.

In ULCtables if i use
Cell Editor as following

DecimalFormatSymbols symbols = new DecimalFormatSymbols();
ULCNumberDataType fnumber = new ULCNumberDataType("#.##",symbols);
fnumber.setFormattingPolicy(ULCNumberDataType.JAVA_TEXT_FORMATTING);
fnumber.setMinFractionDigits(1);
fnumber.setMaxFractionDigits(2);
ULCTextField editorTextField = new ULCTextField();
editorTextField.setDataType(fnumber);
DefaultCellEditor editor = new DefaultCellEditor(editorTextField);

And set the Table Cell Renderer  like the following

ForecastTableCellRenderer tmpCR =
(ForecastTableCellRenderer)column.getCellRenderer();

 DecimalFormatSymbols symbols = new DecimalFormatSymbols();
 ULCPercentDataType fnumber = new ULCPercentDataType(2);
 tmpCR.setDataType(fnumber);

if a  user  enters a value like

10000010 in a table cell,  when users  leaves the cell, value gets displayed
as
1.00%  which is not desirable

enter 10000000  in table cell , when u come out of cell, cell  contains
nothing
move back into cell the value 10000000 appears again .

values till 9000000 are displayed correctly that is u  change the value in
table cell  to  9000000, come  out of cell it displays as 9000000

Any suggestions would be greatly appreciated
Thanks and Regards,
Gene

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Eugene Coelho
Sent: Monday, May 15, 2006 9:42 AM
To: UlC Devleoper list
Subject: [ULC-developer] Prevent percent data type getting formatted as
XXXX.XE %


Hi,
I  need to achieve  following  behaviour in a textfeild and in a cell of  a
table
When i set the textfeild with  a percentage data type and if  a user  enters
a very large value its getting formatted into exponential format say like
1.0E %
on tab out of the textfeild or the  cell  of table
i need to avoid this formatting into exponential number  and show the same
number
when the user  was editing the number
and on tab out it should be appended  with % at the end

Do i have  to extend  the textfeild or the datatype in this case  ?

Thanks and sorry for the repost,  any suggestions  help will be greatly
appreciated

Regards ,
Gene

-----------------------------------

import com.ulcjava.base.application.AbstractAction;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.IAction;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.datatype.ULCPercentDataType;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.client.datatype.UIPercentDataType;
import com.ulcjava.base.development.DevelopmentRunner;

public class PercentDataTypeSnippet extends AbstractApplication {
        public void start() {
                final ULCTextField textField = new ULCTextField(20);
                ULCEPercentDataType dataType = new ULCEPercentDataType();

                textField.setDataType(dataType);
        ULCBoxPane content = new ULCBoxPane(true);
        content.add(textField);
        content.add(new ULCButton(new ShowValueAction(textField)));

        ULCFrame frame = new ULCFrame("PercentDatTypeSnippet");
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
        frame.add(content);
        frame.setVisible(true);
    }

    private static class ShowValueAction extends AbstractAction {
        private ULCTextField fTextField;

        public ShowValueAction(ULCTextField textField) {
            fTextField = textField;
            putValue(IAction.NAME, "Show Value");
        }

        public void actionPerformed(ActionEvent event) {
            Object value = fTextField.getValue();

            System.out.println("value = " + value);
            System.out.println("value.getClass() = " + (value == null ? null
: value.getClass().getName()));
        }
    }

    public static void main(String[] args) {
        DevelopmentRunner.setApplicationClass(PercentDataTypeSnippet.class);
        DevelopmentRunner.main(args);
    }

    public static class ULCEPercentDataType extends ULCPercentDataType {
                protected String typeString() {
                        return UIEPercentDataType.class.getName();
                }
    }

    public static class UIEPercentDataType extends UIPercentDataType {
                public String limitFractionDigits(String s) {
                        return s;
                }

                public boolean hasValidCharacters(String s) {
            for (int i = 0; i < s.length(); i++)
                if (validChars.indexOf(s.charAt(i)) < 0 && s.charAt(i) !=
'E' && s.charAt(i) != '-') {
                    return false;
                }
            return true;
        }
    }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to