Adding Data into a Spinner from JAVA code?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding Data into a Spinner from JAVA code?

Ripgiblet

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [mailto:[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [mailto:[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding Data into a Spinner from JAVA code?

Roger and Beth Whitcomb
Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Adding Data into a Spinner from JAVA code?

Ripgiblet

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [mailto:[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Adding Data into a Spinner from JAVA code?

Ripgiblet

Hi All,

 

Need to change to:

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()-1));

And maybe a check to make sure not empty…

Regards,

Mark.

 

From: Mark R. Chambers [mailto:[hidden email]]
Sent: Tuesday, 18 February 2014 2:36 PM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [mailto:[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Adding Data into a Spinner from JAVA code?

Roger Whitcomb-2
In reply to this post by Ripgiblet

Hi Mark,

                You can make a custom SpinnerItemRenderer, and call spinner.setItemRenderer(myCustomRenderer).  I guess my question would be:  how are you going to tell (from the data) what color to make it? 

 

~Roger

 

From: Mark R. Chambers [mailto:[hidden email]]
Sent: Monday, February 17, 2014 11:36 PM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Adding Data into a Spinner from JAVA code?

Ripgiblet

Hi Roger,

 

Ideally I would just make the Data another component and add a label.

But if that is difficult and it has to be text then I will just add a HEX colour in the start with a delimiter. (In my code I already have Status broken down into standard Warning,Info,Fine,Finer etc… )

 

Regards,

Mark.

From: Roger Whitcomb [mailto:[hidden email]]
Sent: Wednesday, 19 February 2014 1:29 AM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Mark,

                You can make a custom SpinnerItemRenderer, and call spinner.setItemRenderer(myCustomRenderer).  I guess my question would be:  how are you going to tell (from the data) what color to make it? 

 

~Roger

 

From: Mark R. Chambers [mailto:[hidden email]]
Sent: Monday, February 17, 2014 11:36 PM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding Data into a Spinner from JAVA code?

Roger and Beth Whitcomb
Hi Mark,
    Well, the job of the renderer is to basically "translate" the data into a visual representation.  So, if you write a custom renderer to take your data which is a component with a Label and render that, then great!  But note that the usual way to write a renderer is to have it setup its own internal components, set their data values based on the data in the list and let them render themselves to the graphics object.
    So, no your data doesn't have to be just text, but I think I would just make a small custom Java object that contains the text you want to display, along with something you can use to decide the color and make that your data object.  Then the renderer would just contain a Label component for which you set the text and the foreground color based on your list data and just have this single Label render itself.  In fact, if you look at the default renderer for a Spinner (SpinnerItemRenderer.java) it is just subclassed from a Label with the additional methods needed to implement the Spinner.ItemRenderer interface.  You could easily duplicate this logic with just a few changes and (I think) achieve the effect you want.

Let us know how you get on with this.

HTH,
~Roger

On 2/18/14 5:04 PM, Mark R. Chambers wrote:

Hi Roger,

 

Ideally I would just make the Data another component and add a label.

But if that is difficult and it has to be text then I will just add a HEX colour in the start with a delimiter. (In my code I already have Status broken down into standard Warning,Info,Fine,Finer etc… )

 

Regards,

Mark.

From: Roger Whitcomb [[hidden email]]
Sent: Wednesday, 19 February 2014 1:29 AM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Mark,

                You can make a custom SpinnerItemRenderer, and call spinner.setItemRenderer(myCustomRenderer).  I guess my question would be:  how are you going to tell (from the data) what color to make it? 

 

~Roger

 

From: Mark R. Chambers [[hidden email]]
Sent: Monday, February 17, 2014 11:36 PM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Adding Data into a Spinner from JAVA code?

Ripgiblet

Hi Roger,

 

Yeah thanks will do, I will probably parse in the Text, StyleName and the Style. Should make it pretty intuitive for people to use if they want to insert objects from the bxml as well…

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [mailto:[hidden email]]
Sent: Wednesday, 19 February 2014 12:17 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    Well, the job of the renderer is to basically "translate" the data into a visual representation.  So, if you write a custom renderer to take your data which is a component with a Label and render that, then great!  But note that the usual way to write a renderer is to have it setup its own internal components, set their data values based on the data in the list and let them render themselves to the graphics object.
    So, no your data doesn't have to be just text, but I think I would just make a small custom Java object that contains the text you want to display, along with something you can use to decide the color and make that your data object.  Then the renderer would just contain a Label component for which you set the text and the foreground color based on your list data and just have this single Label render itself.  In fact, if you look at the default renderer for a Spinner (SpinnerItemRenderer.java) it is just subclassed from a Label with the additional methods needed to implement the Spinner.ItemRenderer interface.  You could easily duplicate this logic with just a few changes and (I think) achieve the effect you want.

Let us know how you get on with this.

HTH,
~Roger

On 2/18/14 5:04 PM, Mark R. Chambers wrote:

Hi Roger,

 

Ideally I would just make the Data another component and add a label.

But if that is difficult and it has to be text then I will just add a HEX colour in the start with a delimiter. (In my code I already have Status broken down into standard Warning,Info,Fine,Finer etc… )

 

Regards,

Mark.

From: Roger Whitcomb [[hidden email]]
Sent: Wednesday, 19 February 2014 1:29 AM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Mark,

                You can make a custom SpinnerItemRenderer, and call spinner.setItemRenderer(myCustomRenderer).  I guess my question would be:  how are you going to tell (from the data) what color to make it? 

 

~Roger

 

From: Mark R. Chambers [[hidden email]]
Sent: Monday, February 17, 2014 11:36 PM
To: [hidden email]
Subject: RE: Adding Data into a Spinner from JAVA code?

 

Hi Roger,

 

Thanks for your reply… to enable me to change the colour of the text in the list any ideas?

I had a look at modifying the numericspinnerdata object but it does only seem to get the String…

I could rewrite a component Spinner? Based off the Spinner code… but seems like a fair bit of work;

 

Anyway for other code to add to a spinner is (Still can’t get SetSelectedItem to work…):

    ArrayList<String> mMessages = new ArrayList<String>();

 

    public boolean addStatusMessage(String vStatus)

    {

        mMessages.add(vStatus);

        ApplicationContext.queueCallback(new TaskAddSpinnerMessage(mTRNGUIWindow.mStatusSpinner, mMessages), true);

        return true;

    }

 

    /** */

    private class TaskAddSpinnerMessage implements Runnable

    {

        Spinner mSpinner;

        ArrayList<String> mMessage;

        public TaskAddSpinnerMessage (Spinner vSpinner,ArrayList<String> vMessage)

        {

            mMessage = vMessage;

            mSpinner = vSpinner;

        }

 

        public void run ()

        {

            mSpinner.setSpinnerData(mMessage);

            mSpinner.setSelectedItem(mMessage.get(mMessage.getLength()));

        }

    }

 

Regards,

Mark.

 

From: Roger and Beth Whitcomb [[hidden email]]
Sent: Tuesday, 18 February 2014 12:22 PM
To: [hidden email]
Subject: Re: Adding Data into a Spinner from JAVA code?

 

Hi Mark,
    The data for a Spinner should be a org.apache.pivot.collections.List of something (and it could be an unknown or List<?>).  The default list for a Spinner is an immutable list, so trying to add to it won't work.  And adding a Label component won't be necessary either because the skin just wants to call the "toString()" method of the list element in order to render it.
    So, the right thing would be to keep your List<String> spinnerData = new ArrayList<String>(); separately, then add the string data to it as you get more text.  Just call "setSpinnerData(spinnerData)" once, and the spinner itself will update its display as you add data to the data list (that's why it has to be a Pivot List, so the component gets notified of changes to the data itself.

HTH,
~Roger

P.S. It would be better create a new email thread than replying to an earlier, unrelated posting.  Thanks.

On 2/16/14 10:53 PM, Mark R. Chambers wrote:

Hi All,

 

Anybody know how to set values into a spinner from JAVA code? (Should be easy just having problems…bit vague of how to use <?> wildcards… and assume there is an easier way)

I need to add Lines of Text? (Using is for my apps logging interface, to keep a history of logged actions…) (Also being able to change the colour would be good too;])

//For example…

String vMessage = “Hello!”;

mSpinner.getSpinnerData().add(vMessage);

//Or

Label vMessage = new Label(“Hello”);

mSpinner.getSpinnerData().add(vMessage);

 

Regards,

Mark.

 

From: Roger Whitcomb [[hidden email]]
Sent: Saturday, 15 February 2014 2:21 AM
To: [hidden email]
Subject: RE: Alerts loosing Focus When using Context Menu Items

 

Hi,

   We had similar problems in our application.  The issue is that the process of closing the context menu puts focus back on the window it was invoked from, which takes focus away from the alert or popup or any other dialog, for that matter.  We have a workaround, which involves a custom skin for the menu popups. 

   Maybe you could open up a JIRA issue for your case and we can work on getting a better fix into the next release.  But, probably we can put the workaround into that issue so you can try it (at least for now).

 

Thanks,

~Roger

 

From: V SANTOSH PAVAN RAJU Bs [[hidden email]]
Sent: Tuesday, January 28, 2014 10:13 PM
To: [hidden email]
Subject: Alerts loosing Focus When using Context Menu Items

 

Hi,

I am popping up one Alert message using Context Menu Items. Alert is coming fine, But Once Alert message popped up, it is loosing its Focus. Can Any help me in how to make sure Alert should not loose focus when they are opened from Context Menu Items. Code that i have used for this functionality is as follows:

Action.getNamedActions().put("openAction", new Action() {
            @Override
            public void perform(Component source) {
                Alert.alert("Opening.", MyClass.this.getWindow());
            }
});

Here MyClass is the Class Name in which iam using this code and this MyClass extends BoxPane and "openAction" is a Menu.Item .



--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

 

 

Loading...