Skip to main content

Adding commands to custom Dialog

5 replies [Last post]
Anonymous

Hi,

I have developped a custom dialog componenet that is in charge of
displaying a progress bar (using Shai's examples availablein the LWUIT
blog).
Everything works great except that I have some trouble managing Commands
that are added to the Dialog.

The command I added is triggered corerctly when the user presses the soft
button and the Dialog is "disposed" and the main thread continues it's life
normally. The only problem is I have no Idea which Command was triggered by
the user. This is fine if I only have one "Cancel" Command in my dialog
but I'm going to have trouble if I have more than one Command as I am unable
to determine which one is triggered by the user.

My dialog is not contructed using static methods. Rather I build the
dialog's UI in the contructor of my class (add the progress bar, labels
etc... ) and then call show() from the calling method. So basically my
question is : is there a way to call show() on a dialog and having the
Command object that was triggered by the user (if any) returned by show().
I'm talking about a non static call to show()"

I hope I'm clear enough.

Here's a litle piece of my code so that you better understand what I mean :

//here is the class
class ImageDownloadDialog extends Dialog {

public ImageDownloadDialog(String url, boolean addCancelCommand) {
//add components here (Label and progress bar)
addCommand(new Command("CANCEL") );
}

public void startDownload(){

//download the image here using a BackgroundTask and update the
progress bar as the download is progressing
}

}

public Image getImageFromServer(String url){

ImageDownloadDialog dlg = new ImageDownloadDialog(url);
dlg.startDownload();
dlg.show(); // thread is frozen here until the download completed or
the user has clicked "cancel"

//the idea would be to have a method such as
//Command cmd = dlg.show(); //this would allow me to know which command
was triggered.

if(!dlg.isCompleted()){ //if isCompleted is still false here the user
pressed the Cancel command
dlg.killDownload();
}

Image img = dlg.getImage();
dlg.dispose();
return img;
}

Thansk for helping !

Cheers

Alex.
[att1.html]

Reply viewing options

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

Hi Alex,
currently you can do this by overriding:
protected void actionCommand(Command cmd) {
super.actionCommand(cmd);
}

And keeping the last action that occurred this would indeed be a
useful feature I will add if for the next drop.

Thanks,
Shai.

> Hi,
>
> I have developped a custom dialog componenet that is in charge of
> displaying a progress bar (using Shai's examples availablein the
> LWUIT blog).
> Everything works great except that I have some trouble managing
> Commands that are added to the Dialog.
>
> The command I added is triggered corerctly when the user presses
> the soft button and the Dialog is "disposed" and the main thread
> continues it's life normally. The only problem is I have no Idea
> which Command was triggered by the user. This is fine if I only
> have one "Cancel" Command in my dialog but I'm going to have
> trouble if I have more than one Command as I am unable to determine
> which one is triggered by the user.
>
> My dialog is not contructed using static methods. Rather I build
> the dialog's UI in the contructor of my class (add the progress
> bar, labels etc... ) and then call show() from the calling method.
> So basically my question is : is there a way to call show() on a
> dialog and having the Command object that was triggered by the user
> (if any) returned by show(). I'm talking about a non static call to
> show()"
>
> I hope I'm clear enough.
>
> Here's a litle piece of my code so that you better understand what
> I mean :
>
> //here is the class
> class ImageDownloadDialog extends Dialog {
>
> public ImageDownloadDialog(String url, boolean
> addCancelCommand) {
> //add components here (Label and progress bar)
> addCommand(new Command("CANCEL") );
> }
>
> public void startDownload(){
>
> //download the image here using a BackgroundTask and update
> the progress bar as the download is progressing
> }
>
>
> }
>
>
> public Image getImageFromServer(String url){
>
> ImageDownloadDialog dlg = new ImageDownloadDialog(url);
> dlg.startDownload();
> dlg.show(); // thread is frozen here until the download
> completed or the user has clicked "cancel"
>
> //the idea would be to have a method such as
> //Command cmd = dlg.show(); //this would allow me to know which
> command was triggered.
>
>
> if(!dlg.isCompleted()){ //if isCompleted is still false here
> the user pressed the Cancel command
> dlg.killDownload();
> }
>
> Image img = dlg.getImage();
> dlg.dispose();
> return img;
> }
>
>
>
> Thansk for helping !
>
> Cheers
>
> Alex.
>

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

Alex

Hi !

I'm not sure I understand what you mean.

When is actionCommand supposed to be called ? What is it supposed to do ?

Thanks

On Fri, Jul 11, 2008 at 8:26 PM, Shai Almog wrote:

> Hi Alex,
> currently you can do this by overriding:
> protected void actionCommand(Command cmd) {
> super.actionCommand(cmd);
> }
>
> And keeping the last action that occurred this would indeed be a useful
> feature I will add if for the next drop.
>
> Thanks,
> Shai.
>
>
> Hi,
>>
>> I have developped a custom dialog componenet that is in charge of
>> displaying a progress bar (using Shai's examples availablein the LWUIT
>> blog).
>> Everything works great except that I have some trouble managing Commands
>> that are added to the Dialog.
>>
>> The command I added is triggered corerctly when the user presses the soft
>> button and the Dialog is "disposed" and the main thread continues it's life
>> normally. The only problem is I have no Idea which Command was triggered by
>> the user. This is fine if I only have one "Cancel" Command in my dialog
>> but I'm going to have trouble if I have more than one Command as I am unable
>> to determine which one is triggered by the user.
>>
>> My dialog is not contructed using static methods. Rather I build the
>> dialog's UI in the contructor of my class (add the progress bar, labels
>> etc... ) and then call show() from the calling method. So basically my
>> question is : is there a way to call show() on a dialog and having the
>> Command object that was triggered by the user (if any) returned by show().
>> I'm talking about a non static call to show()"
>>
>> I hope I'm clear enough.
>>
>> Here's a litle piece of my code so that you better understand what I mean
>> :
>>
>> //here is the class
>> class ImageDownloadDialog extends Dialog {
>>
>> public ImageDownloadDialog(String url, boolean addCancelCommand) {
>> //add components here (Label and progress bar)
>> addCommand(new Command("CANCEL") );
>> }
>>
>> public void startDownload(){
>>
>> //download the image here using a BackgroundTask and update the
>> progress bar as the download is progressing
>> }
>>
>>
>> }
>>
>>
>> public Image getImageFromServer(String url){
>>
>> ImageDownloadDialog dlg = new ImageDownloadDialog(url);
>> dlg.startDownload();
>> dlg.show(); // thread is frozen here until the download completed or
>> the user has clicked "cancel"
>>
>> //the idea would be to have a method such as
>> //Command cmd = dlg.show(); //this would allow me to know which command
>> was triggered.
>>
>>
>> if(!dlg.isCompleted()){ //if isCompleted is still false here the
>> user pressed the Cancel command
>> dlg.killDownload();
>> }
>>
>> Image img = dlg.getImage();
>> dlg.dispose();
>> return img;
>> }
>>
>>
>>
>> Thansk for helping !
>>
>> Cheers
>>
>> Alex.
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
[att1.html]

Shai Almog

Hi,
action command is called when a command is pressed e.g. if you want
to do something like this do:

class CDialog extends Dialog {
public Command lastCommand;
public void actionCommand(Command c) {
lastCommand = c;
super.actionCommand(c);
}
}

CDialog dlg = ...;
dlg.show();

if(dlg.lastCommand == ...) {
...
}

Thanks,
Shai.

> Hi !
>
>
> I'm not sure I understand what you mean.
>
> When is actionCommand supposed to be called ? What is it supposed
> to do ?
>
> Thanks

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

Alex

Oh ok !

Great !

Many thanks for responding so fast ! (Do you ever take a break ? ) :)

Cheers

Alex

On Sat, Jul 12, 2008 at 1:42 PM, Shai Almog wrote:

> Hi,
> action command is called when a command is pressed e.g. if you want to do
> something like this do:
>
> class CDialog extends Dialog {
> public Command lastCommand;
> public void actionCommand(Command c) {
> lastCommand = c;
> super.actionCommand(c);
> }
> }
>
> CDialog dlg = ...;
> dlg.show();
>
> if(dlg.lastCommand == ...) {
> ...
> }
>
> Thanks,
> Shai.
>
> Hi !
>>
>>
>> I'm not sure I understand what you mean.
>>
>> When is actionCommand supposed to be called ? What is it supposed to do ?
>>
>> Thanks
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
[att1.html]

Shai Almog

> Many thanks for responding so fast ! (Do you ever take a break ? ) :)

No ;-)

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