Skip to main content

Command button + List selected item

14 replies [Last post]
francisdb
Offline
Joined: 2006-06-16

Hi,

My application has a list visible and a few commands that trigger things for the selected item in the list. In the command's actionperformed i'm getting the selected item for the list and do my thing.

The problem is that when the user is fast and triggers the command, after that quickly picks an other item in the list using the up/down keys the wrong item (the newly selected one) is selected in the actionperformed.

Is this a known problem? Is the edt free between the command being triggered and it's actionperformed method being called?

Reply viewing options

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

Hi,
the EDT is not free between invocations of actionPerformed and a
selection so they should be completely serial and while an event can
enter the queue in that time (since it arrives in the MIDP thread) it
will not be known to the List yet which receives it in the EDT as well.
If you have a reproducible test case I will be happy to take a look.

Thanks,
Shai.

> Hi,
>
> My application has a list visible and a few commands that trigger
> things for the selected item in the list. In the command's
> actionperformed i'm getting the selected item for the list and do
> my thing.
>
> The problem is that when the user is fast and triggers the command,
> after that quickly picks an other item in the list using the up/
> down keys the wrong item (the newly selected one) is selected in
> the actionperformed.
>
> Is this a known problem? Is the edt free between the command being
> triggered and it's actionperformed method being called?
> [Message sent by forum member 'francisdb' (francisdb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=285088
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

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

francisdb
Offline
Joined: 2006-06-16

Is there a way to disable animation + transparency for the command menu? I'll have a look for a test case later this week.

Shai Almog

Yes,
you can set a renderer to the menu to disable transparency for
selection (Form.setMenuCellRenderer) and you can disable transition
to the menu by calling setMenuTransitions(null, null) on Form.

Shai.

> Is there a way to disable animation + transparency for the command
> menu? I'll have a look for a test case later this week.
> [Message sent by forum member 'francisdb' (francisdb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=285118
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

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

Francis De Brabandere

Well by using setMenuTransitions(null, null) my issue disappears.
Is the actionPerformd called immediately after the user hits the
command or only after the menu transition animation is done? And is
there a way for the user to interact while the menu is getting
animated for the transition?

On Tue, Jul 8, 2008 at 6:40 PM, Shai Almog wrote:
> Yes,
> you can set a renderer to the menu to disable transparency for selection
> (Form.setMenuCellRenderer) and you can disable transition to the menu by
> calling setMenuTransitions(null, null) on Form.
>
> Shai.
>
>> Is there a way to disable animation + transparency for the command menu?
>> I'll have a look for a test case later this week.
>> [Message sent by forum member 'francisdb' (francisdb)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=285118
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

Hi Francis,
I'm still not clear exactly on what the issue you are experiencing is.
If I understand correctly:
1. You open a menu.
2. Press fire immediately followed by down.
3. The menu is still visible (because of the transition) but the down
press reaches the list.

That would make sense and seems like the right behavior.

LWUIT internally has the EDT loop which is just a big while(true)
loop of sort... MIDP events get called on the MIDP thread and added
into a queue which we read within this loop and deliver to the
application. During transition a key press might be delivered to the
next screen or the previous screen, this depends on when the EDT
actually gets to the queue and extracts the key press/release. This
is further augmented by the fact that we "commandeer" the CPU for the
purpose of transitions to draw as fast as possible on the device and
so the MIDP thread might have issues delivering key events to us.

Thanks,
Shai.

> Well by using setMenuTransitions(null, null) my issue disappears.
> Is the actionPerformd called immediately after the user hits the
> command or only after the menu transition animation is done? And is
> there a way for the user to interact while the menu is getting
> animated for the transition?
>
> On Tue, Jul 8, 2008 at 6:40 PM, Shai Almog wrote:
>> Yes,
>> you can set a renderer to the menu to disable transparency for
>> selection
>> (Form.setMenuCellRenderer) and you can disable transition to the
>> menu by
>> calling setMenuTransitions(null, null) on Form.
>>
>> Shai.
>>
>>> Is there a way to disable animation + transparency for the
>>> command menu?
>>> I'll have a look for a test case later this week.
>>> [Message sent by forum member 'francisdb' (francisdb)]
>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=285118
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
>
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

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

Francis De Brabandere

Hi Shai, thanks for the follow up

The problem is that the actionPerformed of the command seems to be
triggered somewhere between/after the command menu transition
completes. And while the command menu transition is going the user can
change the state of the form. So the form state when the command's
actionPerformed is called is not the same one as when the user
triggered the command which is unexpected.

form state 1
user triggers soft button
menu transition (in)
*user triggers item in command menu*
command menu transition (out)
*user changes form state to state 2*
command menu transition continues (out)
*actionPerformed for the command is called *
(maybe command menu transition continues (out)?)

This is the behavior I'm seeing, and I'm not spawning any threads in
the actionPerformed method

On Wed, Jul 9, 2008 at 10:24 AM, Shai Almog wrote:
> Hi Francis,
> I'm still not clear exactly on what the issue you are experiencing is.
> If I understand correctly:
> 1. You open a menu.
> 2. Press fire immediately followed by down.
> 3. The menu is still visible (because of the transition) but the down press
> reaches the list.
>
> That would make sense and seems like the right behavior.
>
> LWUIT internally has the EDT loop which is just a big while(true) loop of
> sort... MIDP events get called on the MIDP thread and added into a queue
> which we read within this loop and deliver to the application. During
> transition a key press might be delivered to the next screen or the previous
> screen, this depends on when the EDT actually gets to the queue and extracts
> the key press/release. This is further augmented by the fact that we
> "commandeer" the CPU for the purpose of transitions to draw as fast as
> possible on the device and so the MIDP thread might have issues delivering
> key events to us.
>
> Thanks,
> Shai.
>
>> Well by using setMenuTransitions(null, null) my issue disappears.
>> Is the actionPerformd called immediately after the user hits the
>> command or only after the menu transition animation is done? And is
>> there a way for the user to interact while the menu is getting
>> animated for the transition?
>>
>> On Tue, Jul 8, 2008 at 6:40 PM, Shai Almog wrote:
>>>
>>> Yes,
>>> you can set a renderer to the menu to disable transparency for selection
>>> (Form.setMenuCellRenderer) and you can disable transition to the menu by
>>> calling setMenuTransitions(null, null) on Form.
>>>
>>> Shai.
>>>
>>>> Is there a way to disable animation + transparency for the command menu?
>>>> I'll have a look for a test case later this week.
>>>> [Message sent by forum member 'francisdb' (francisdb)]
>>>>
>>>> http://forums.java.net/jive/thread.jspa?messageID=285118
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>>
>>
>>
>>
>> --
>> http://www.somatik.be
>> Microsoft gives you windows, Linux gives you the whole house.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

Hi Francis,
this seems to be correct behavior. Once the user pressed fire/select
all following key presses should be delivered to the next form even
if the transition is taking effect (please correct me if this is not
the case).

This allows the user to press buttons rapidly without being delayed
by transitions which allows the user to navigate an application very
fast.
The transition blocks all input while its in effect so all input is
queued and would be received by the upcoming form.

There is currently no way I can think of to block this that would not
pose a performance penalty on the transition and the behavior seems
to make sense. From your description I'm not exactly clear on what is
the problem with this behavior?
When the user presses a stream of buttons they shouldn't be ignored,
maybe if you can give me the concrete details of the problem it would
be clearer.

Thanks,
Shai.

> form state 1
> user triggers soft button
> menu transition (in)
> *user triggers item in command menu*
> command menu transition (out)
> *user changes form state to state 2*
> command menu transition continues (out)
> *actionPerformed for the command is called *
> (maybe command menu transition continues (out)?)
>

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

Francis De Brabandere

concrete example

we have a list with videos
the form only contains this list
the form has a few commands that act on this list (more than 2 causing
the command menu). One of them being to queue this item for playback,
which will be indicated by the cell renderer.

now if the user decides to queue the current selected item he presses
the soft button, the menu pops up and he chooses queue. Now he scrolls
down the list to see if there are more items he wants to queue.

*There is a big chance one of the next items down is being queued
instead of the one that was selected when he triggered queue*

On Wed, Jul 9, 2008 at 12:23 PM, Shai Almog wrote:
> Hi Francis,
> this seems to be correct behavior. Once the user pressed fire/select all
> following key presses should be delivered to the next form even if the
> transition is taking effect (please correct me if this is not the case).

>
> This allows the user to press buttons rapidly without being delayed by
> transitions which allows the user to navigate an application very fast.
> The transition blocks all input while its in effect so all input is queued
> and would be received by the upcoming form.
>
> There is currently no way I can think of to block this that would not pose a
> performance penalty on the transition and the behavior seems to make sense.
> From your description I'm not exactly clear on what is the problem with this
> behavior?
> When the user presses a stream of buttons they shouldn't be ignored, maybe
> if you can give me the concrete details of the problem it would be clearer.
>
> Thanks,
> Shai.
>
>> form state 1
>> user triggers soft button
>> menu transition (in)
>> *user triggers item in command menu*
>> command menu transition (out)
>> *user changes form state to state 2*
>> command menu transition continues (out)
>> *actionPerformed for the command is called *
>> (maybe command menu transition continues (out)?)
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

Hi Francis,
I think there is a miscommunication here:
> *There is a big chance one of the next items down is being queued
> instead of the one that was selected when he triggered queue*

Why would that happen???

I think what you have is the complete opposite of what I understood...
You make a selection in your application list in the form but moving
the list selection in the smooth animation hasn't completed.
In the meantime, the menu button is pressed and shows the list with
the previous selection?

Is that the case?

Does disabling the smooth animation on the list help?
You can speed up the smooth animation by reducing the time of
transition too.

Did I understand the problem correctly?

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

Francis De Brabandere

I don't think there is a miscommunication, I'm starting from a list
that has no animation going (wait 5 sec between selection change and
softbutton)

the one and only problem is that the actionPerformed of the queue
command gets triggered to late (after/while command menu hiding), it
should be called immediately when the user triggers the command.

My code:
in the Form constructor:

Command queueCommand = new Command("Queue") {
public void actionPerformed(ActionEvent event) {
doQueue();
}
};
this.addCommand(queueCommand);

in a form private method:

private void doQueue() {
Video video = (Video) list.getSelectedItem();
videoQueue.queue(video);
list.repaint();
}

Sorry for not being clear.

On Wed, Jul 9, 2008 at 12:49 PM, Shai Almog wrote:
> Hi Francis,
> I think there is a miscommunication here:
>>
>> *There is a big chance one of the next items down is being queued
>> instead of the one that was selected when he triggered queue*
>
> Why would that happen???
>
> I think what you have is the complete opposite of what I understood...
> You make a selection in your application list in the form but moving the
> list selection in the smooth animation hasn't completed.
> In the meantime, the menu button is pressed and shows the list with the
> previous selection?
>
> Is that the case?
>
> Does disabling the smooth animation on the list help?
> You can speed up the smooth animation by reducing the time of transition
> too.
>
> Did I understand the problem correctly?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

Sorry I just don't see the problem and I don't understand what is it
that you wait 5 seconds for.

Please provide a reproducible test case.

Thanks,
Shai.

> I don't think there is a miscommunication, I'm starting from a list
> that has no animation going (wait 5 sec between selection change and
> softbutton)
>
> the one and only problem is that the actionPerformed of the queue
> command gets triggered to late (after/while command menu hiding), it
> should be called immediately when the user triggers the command.
>
> My code:
> in the Form constructor:
>
> Command queueCommand = new Command("Queue") {
> public void actionPerformed(ActionEvent event) {
> doQueue();
> }
> };
> this.addCommand(queueCommand);
>
> in a form private method:
>
> private void doQueue() {
> Video video = (Video) list.getSelectedItem();
> videoQueue.queue(video);
> list.repaint();
> }
>
>
> Sorry for not being clear.
>
>
> On Wed, Jul 9, 2008 at 12:49 PM, Shai Almog
> wrote:
>> Hi Francis,
>> I think there is a miscommunication here:
>>>
>>> *There is a big chance one of the next items down is being queued
>>> instead of the one that was selected when he triggered queue*
>>
>> Why would that happen???
>>
>> I think what you have is the complete opposite of what I
>> understood...
>> You make a selection in your application list in the form but
>> moving the
>> list selection in the smooth animation hasn't completed.
>> In the meantime, the menu button is pressed and shows the list
>> with the
>> previous selection?
>>
>> Is that the case?
>>
>> Does disabling the smooth animation on the list help?
>> You can speed up the smooth animation by reducing the time of
>> transition
>> too.
>>
>> Did I understand the problem correctly?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
>
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

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

Francis De Brabandere

test case below
how to reproduce:

just run in the wtk emulator
select an item in the list (memorize/write down number)
click menu
-- fast from here
select queue
press action button
press down button a few times
-- stop fast mode :-)

behavior: you will see a dialog showing one of the items below the
item you selected queue for (memorized nr)

expected behavior: the item shown in the dialog should be the item you
requested queue for (memorized nr)

import com.sun.lwuit.Command;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Form;
import com.sun.lwuit.List;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;

/**
*
* @author francisdb
*/
public class TestForm extends Form{

private List list;

public TestForm() {
super(null);
this.setScrollable(false);
this.list = new List();
list.setBorderPainted(false);
list.setSmoothScrolling(false);
list.getStyle().setBgTransparency(0);
for(int i = 0;i<100;i++){
list.addItem("Video "+(i+1));
}
this.setLayout(new BorderLayout());
this.addComponent(BorderLayout.CENTER, list);
Command queueCommand = new Command("Queue") {
public void actionPerformed(ActionEvent event) {
doQueue();
}
};
this.addCommand(new Command("nothing"));
this.addCommand(new Command("nothing2"));
this.addCommand(queueCommand);
this.addCommand(new Command("nothing3"));

}

private void doQueue() {
Object video = (Object) list.getSelectedItem();
Dialog.show("Test", video.toString(), "Ok", null);
}

}

On Wed, Jul 9, 2008 at 1:36 PM, Shai Almog wrote:
> Sorry I just don't see the problem and I don't understand what is it that
> you wait 5 seconds for.
>
> Please provide a reproducible test case.
>
> Thanks,
> Shai.
>
>> I don't think there is a miscommunication, I'm starting from a list
>> that has no animation going (wait 5 sec between selection change and
>> softbutton)
>>
>> the one and only problem is that the actionPerformed of the queue
>> command gets triggered to late (after/while command menu hiding), it
>> should be called immediately when the user triggers the command.
>>
>> My code:
>> in the Form constructor:
>>
>> Command queueCommand = new Command("Queue") {
>> public void actionPerformed(ActionEvent event) {
>> doQueue();
>> }
>> };
>> this.addCommand(queueCommand);
>>
>> in a form private method:
>>
>> private void doQueue() {
>> Video video = (Video) list.getSelectedItem();
>> videoQueue.queue(video);
>> list.repaint();
>> }
>>
>>
>> Sorry for not being clear.
>>
>>
>> On Wed, Jul 9, 2008 at 12:49 PM, Shai Almog wrote:
>>>
>>> Hi Francis,
>>> I think there is a miscommunication here:
>>>>
>>>> *There is a big chance one of the next items down is being queued
>>>> instead of the one that was selected when he triggered queue*
>>>
>>> Why would that happen???
>>>
>>> I think what you have is the complete opposite of what I understood...
>>> You make a selection in your application list in the form but moving the
>>> list selection in the smooth animation hasn't completed.
>>> In the meantime, the menu button is pressed and shows the list with the
>>> previous selection?
>>>
>>> Is that the case?
>>>
>>> Does disabling the smooth animation on the list help?
>>> You can speed up the smooth animation by reducing the time of transition
>>> too.
>>>
>>> Did I understand the problem correctly?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>>
>>
>>
>>
>> --
>> http://www.somatik.be
>> Microsoft gives you windows, Linux gives you the whole house.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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

Shai Almog

> test case below
>

Thanks.
I had to go to an old version of LWUIT to see the problem occurring
though. It seems the form gets input focus for a while between
transition which it generally shouldn't get but this is rather
"difficult".
Anyway, this is apparently already fixed for the next drop since I
changed many things in this particular area of the code... The next
drop will hopefully be at some point next week.

Thanks,
Shai.

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

Francis De Brabandere

Ok great, I'll start with the test case next time ;-)

On Wed, Jul 9, 2008 at 2:12 PM, Shai Almog wrote:
>
>> test case below
>>
>
>
> Thanks.
> I had to go to an old version of LWUIT to see the problem occurring though.
> It seems the form gets input focus for a while between transition which it
> generally shouldn't get but this is rather "difficult".
> Anyway, this is apparently already fixed for the next drop since I changed
> many things in this particular area of the code... The next drop will
> hopefully be at some point next week.
>
> Thanks,
> Shai.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

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