pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Fwd: Menus??
Date Thu, 30 Jul 2009 06:57:04 GMT
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 <niclas@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<niclas@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<niclas@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

Mime
View raw message