You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Niclas Hedhman <ni...@hedhman.org> on 2009/07/30 07:52:04 UTC

Menus??

No tutorial on menus, no demo code, and a dumb developer who can't
figure out how to get a standard MenuBar in a Frame....


TIA
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

Re: Menus??

Posted by Niclas Hedhman <ni...@hedhman.org>.
And I forgot to mention; Programmatically only needed.

On Thu, Jul 30, 2009 at 1:52 PM, Niclas Hedhman<ni...@hedhman.org> wrote:
> No tutorial on menus, no demo code, and a dumb developer who can't
> figure out how to get a standard MenuBar in a Frame....
>
>
> TIA
> --
> Niclas Hedhman, Software Developer
> http://www.qi4j.org - New Energy for Java
>
> I  live here; http://tinyurl.com/2qq9er
> I  work here; http://tinyurl.com/2ymelc
> I relax here; http://tinyurl.com/2cgsug
>



-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

Re: Menus??

Posted by Greg Brown <gk...@mac.com>.
Unfortunately, the tutorial is still missing a lot of information,  
including menu docs. However, it looks like you managed to figure it  
out.

Until we are able to find time to improve the tutorials (and, believe  
me, this is consistently at the top of my to-do list), you may find  
the WTKX Primer useful. It explains exactly how WTKX maps to Java, so,  
when you see an example that is written in WTKX (e.g. Kitchen Sink  
app), you will be able to tell what the corresponding Java should look  
like.

The primer is in the tutorials/www directory. If you run the deploy  
target, it will be in the root of pivot_tutorials.war as  
wtkx_primer.html.


On Jul 30, 2009, at 2:28 AM, Niclas Hedhman wrote:

> On Thu, Jul 30, 2009 at 1:52 PM, Niclas Hedhman<ni...@hedhman.org>  
> wrote:
>> No tutorial on menus, no demo code, and a dumb developer who can't
>> figure out how to get a standard MenuBar in a Frame....
>
> Ok, I finally figured it out by going thru heaps of code, so if
> someone else comes across this later;
>
> 1. Create a MenuBar
>
> 2. Create a MenuBar.Item (mbItem), which may either take a String,
> Image or ButtonData instance in the constructor.
>
> 3. Create a Menu (menu).
>
> 4. call mbItem.setMenu( menu );
>
> 5. Create a Menu.Section and give it a name (probably optional).
>
> 6. Add the section to the menu.getSections() sequence.
>
> 7. Create a Menu.Item (mItem), which again can take a String, Image or
> ButtonData/MenuItemData instance.
>
> 8. Add the mItem to the Section.
>
> 9. Place the MenuBar in the Frame or Layout where needed.
>
>
> The following code snippet is my working test copy;
>
>        MenuBar bar = new MenuBar();
>        MenuBar.Item mbItem = new MenuBar.Item( "File" );
>        Menu menu = new Menu();
>        mbItem.setMenu( menu );
>        Menu.Item item = new Menu.Item( "Open...");
>        Menu.SectionSequence sections = menu.getSections();
>        Menu.Section section = new Menu.Section();
>        section.setName( "default" );
>        sections.add( section );
>        section.add( item );
>        bar.getItems().add( mbItem );
>        Frame frame = new Frame("Menus", bar);
>        frame.open( display );
>
>
> Cheers
> -- 
> Niclas Hedhman, Software Developer
> http://www.qi4j.org - New Energy for Java
>
> I  live here; http://tinyurl.com/2qq9er
> I  work here; http://tinyurl.com/2ymelc
> I relax here; http://tinyurl.com/2cgsug


Re: Menus??

Posted by Greg Brown <gk...@mac.com>.
I general, we try to avoid "convenience" methods, since, for many  
cases, WTKX is meant to fill this role. However, since menus are often  
dynamically constructed and manipulated, it may make sense to define  
some here.

On Aug 2, 2009, at 4:01 PM, Noel Grandin wrote:

> Hi
>
> Surely we can improve the common experience by adding some utility
> methods to the API?
>
> We should be able to shrink the code snippet to:
>       MenuBar bar = new MenuBar();
>       Menu.Section section = bar.getSections().add("default");
>       section.addItem("Open...");
>       Frame frame = new Frame("Menus", bar);
>       frame.open( display );
>
> or just
>       MenuBar bar = new MenuBar();
>       bar.addItem("Open...");
>       Frame frame = new Frame("Menus", bar);
>       frame.open( display );
> for the common case where there is only one section (i.e. one would be
> auto-created).
>
> What is the general feeling about adding these kinds of utility  
> methods?
>
> Too many of them can create clutter, but a small handful can provide a
> very valuable helping hand to people beginning to use Pivot.
>
> Regards,
>   Noel Grandin.


Re: Menus??

Posted by Sandro Martini <sa...@gmail.com>.
Hi Noel,

> Too many of them can create clutter, but a small handful can provide a
> very valuable helping hand to people beginning to use Pivot.
I agree with you, at least for most common cases.

Then, if someone needs more complicated solutions, it will be possible
to have a specialized Menu-related utility class ... like a factory.

Bye,
Sandro

Re: Menus??

Posted by Noel Grandin <no...@gmail.com>.
Hi

Surely we can improve the common experience by adding some utility
methods to the API?

We should be able to shrink the code snippet to:
       MenuBar bar = new MenuBar();
       Menu.Section section = bar.getSections().add("default");
       section.addItem("Open...");
       Frame frame = new Frame("Menus", bar);
       frame.open( display );

or just
       MenuBar bar = new MenuBar();
       bar.addItem("Open...");
       Frame frame = new Frame("Menus", bar);
       frame.open( display );
for the common case where there is only one section (i.e. one would be
auto-created).

What is the general feeling about adding these kinds of utility methods?

Too many of them can create clutter, but a small handful can provide a
very valuable helping hand to people beginning to use Pivot.

Regards,
   Noel Grandin.

Re: Menus??

Posted by Niclas Hedhman <ni...@hedhman.org>.
On Thu, Jul 30, 2009 at 1:52 PM, Niclas Hedhman<ni...@hedhman.org> wrote:
> No tutorial on menus, no demo code, and a dumb developer who can't
> figure out how to get a standard MenuBar in a Frame....

Ok, I finally figured it out by going thru heaps of code, so if
someone else comes across this later;

1. Create a MenuBar

2. Create a MenuBar.Item (mbItem), which may either take a String,
Image or ButtonData instance in the constructor.

3. Create a Menu (menu).

4. call mbItem.setMenu( menu );

5. Create a Menu.Section and give it a name (probably optional).

6. Add the section to the menu.getSections() sequence.

7. Create a Menu.Item (mItem), which again can take a String, Image or
ButtonData/MenuItemData instance.

8. Add the mItem to the Section.

9. Place the MenuBar in the Frame or Layout where needed.


The following code snippet is my working test copy;

        MenuBar bar = new MenuBar();
        MenuBar.Item mbItem = new MenuBar.Item( "File" );
        Menu menu = new Menu();
        mbItem.setMenu( menu );
        Menu.Item item = new Menu.Item( "Open...");
        Menu.SectionSequence sections = menu.getSections();
        Menu.Section section = new Menu.Section();
        section.setName( "default" );
        sections.add( section );
        section.add( item );
        bar.getItems().add( mbItem );
        Frame frame = new Frame("Menus", bar);
        frame.open( display );


Cheers
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

Fwd: Menus??

Posted by Niclas Hedhman <ni...@hedhman.org>.
Yikes, pivot-user has no moderator?? My post bounced. So I can't
post... Sorry, guys, not really your problem that ezmlm (mailing lists
manager) is brain-dead when it comes to dealing with GMail clients...
Phew... I have been battling this with infra@ for quite a while, to no
prevail...


---------- Forwarded message ----------
From: Niclas Hedhman <ni...@hedhman.org>
Date: Thu, Jul 30, 2009 at 2:53 PM
Subject: Re: Menus??
To: pivot-user@incubator.apache.org


Ooops, I realized that this should have been posted to pivot-user@ list...

I have also expanded the trial to be more elaborate... see below.

On Thu, Jul 30, 2009 at 1:52 PM, Niclas Hedhman<ni...@hedhman.org> wrote:
> No tutorial on menus, no demo code, and a dumb developer who can't
> figure out how to get a standard MenuBar in a Frame....

On Thu, Jul 30, 2009 at 2:28 PM, Niclas Hedhman<ni...@hedhman.org> wrote:
> Ok, I finally figured it out by going thru heaps of code, so if
> someone else comes across this later;
>
> 1. Create a MenuBar
>
> 2. Create a MenuBar.Item (mbItem), which may either take a String,
> Image or ButtonData instance in the constructor.
>
> 3. Create a Menu (menu).
>
> 4. call mbItem.setMenu( menu );
>
> 5. Create a Menu.Section and give it a name (probably optional).
>
> 6. Add the section to the menu.getSections() sequence.
>
> 7. Create a Menu.Item (mItem), which again can take a String, Image or
> ButtonData/MenuItemData instance.
>
> 8. Add the mItem to the Section.
>
> 9. Place the MenuBar in the Frame or Layout where needed.
>
>
> The following code snippet is my working test copy;
>
>        MenuBar bar = new MenuBar();
>        MenuBar.Item mbItem = new MenuBar.Item( "File" );
>        Menu menu = new Menu();
>        mbItem.setMenu( menu );
>        Menu.Item item = new Menu.Item( "Open...");
>        Menu.SectionSequence sections = menu.getSections();
>        Menu.Section section = new Menu.Section();
>        section.setName( "default" );
>        sections.add( section );
>        section.add( item );
>        bar.getItems().add( mbItem );
>        Frame frame = new Frame("Menus", bar);
>        frame.open( display );


And here is a larger sample with cascading menus;

public class MenuTest
   implements Application
{
   public void startup( Display display, Map<String, String> properties )
       throws Exception
   {
       MenuBar bar = new MenuBar();

       createFileMenu( bar );
       createWindowMenu( bar );

       BoxPane pane = new BoxPane( Orientation.VERTICAL );
       FlowPane contentPane = new FlowPane();
       Label statusBar = new Label( "Status Bar" );
       pane.add( bar );
       pane.add( contentPane );
       pane.add( statusBar );
       Frame frame = new Frame( "Menus", pane );
       frame.open( display );
   }

   private void createWindowMenu( MenuBar bar )
   {
       MenuBar.Item mbiWindow = new MenuBar.Item( "Window" );
       Menu windowMenu = new Menu();
       mbiWindow.setMenu( windowMenu );
       Menu.Item toolsItem = new Menu.Item( "Tool Windows" );
       Menu.SectionSequence windowSections = windowMenu.getSections();
       Menu.Section windowSection = new Menu.Section();
       windowSection.setName( "default" );
       windowSections.add( windowSection );
       windowSection.add( toolsItem );


       Menu toolsMenu = new Menu();
       toolsItem.setMenu( toolsMenu );
       Menu.SectionSequence toolsSections = toolsMenu.getSections();
       Menu.Section toolsSection = new Menu.Section();
       toolsSection.setName( "tools" );
       toolsSections.add( toolsSection );

       Menu.Item componentToolItem = new Menu.Item( "Component Tool" );
       toolsSection.add( componentToolItem );

       bar.getItems().add( mbiWindow );

   }

   private void createFileMenu( MenuBar bar )
   {
       MenuBar.Item mbiFile = new MenuBar.Item( "File" );
       Menu fileMenu = new Menu();
       mbiFile.setMenu( fileMenu );
       Menu.Item openItem = new Menu.Item( "Open..." );
       Menu.Item newItem = new Menu.Item( "New..." );
       Menu.Item closeItem = new Menu.Item( "Close" );
       Menu.Item printItem = new Menu.Item( "Print..." );
       Menu.Item previewItem = new Menu.Item( "Preview..." );
       Menu.SectionSequence fileSections = fileMenu.getSections();
       Menu.Section fileSection = new Menu.Section();
       Menu.Section printSection = new Menu.Section();
       fileSection.setName( "default" );
       printSection.setName( "print" );
       fileSections.add( fileSection );
       fileSections.add( printSection );
       fileSection.add( newItem );
       fileSection.add( openItem );
       fileSection.add( closeItem );
       printSection.add( printItem );
       printSection.add( previewItem );
       bar.getItems().add( mbiFile );
   }

   public boolean shutdown( boolean optional ) throws Exception
   {
       return false;  //To change body of implemented methods use
File | Settings | File Templates.
   }

   public void suspend() throws Exception
   {
       //To change body of implemented methods use File | Settings |
File Templates.
   }

   public void resume() throws Exception
   {
       //To change body of implemented methods use File | Settings |
File Templates.
   }

   public static void main( String[] args )
   {
       DesktopApplicationContext.main( MenuTest.class, args );
   }
}


Cheers
--
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug



-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug