home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-15 | 8.0 KB | 220 lines |
- import java.awt.*;
- import java.applet.*;
- import com.ms.awt.*;
- import com.ms.directX.*;
- import MessageBox;
-
- //----------------------------------------------------------
- // class ViewFrame
- //----------------------------------------------------------
-
- public class ViewFrame extends Frame implements MenuXConstants
- {
- public final int MENU_FILE_ABOUT = 1 ;
- public final int MENU_FILE_OPEN = 2 ;
- public final int MENU_FILE_OPEN_ANIMSET = 3 ;
- public final int MENU_FILE_OPEN_FRAME = 4 ;
- public final int MENU_FILE_EXIT = 5 ;
- public final int MENU_EDIT_CUT = 6 ;
- public final int MENU_EDIT_COPY = 7 ;
- public final int MENU_EDIT_PASTE = 8 ;
- public final int MENU_EDIT_DELETE = 9 ;
- public final int MENU_EDIT_COLOR = 10;
- public final int MENU_EDIT_BOXES = 11;
- public final int MENU_QUALITY_LIGHTING = 12;
- //separator
- public final int MENU_QUALITY_POINTS = 14;
- public final int MENU_QUALITY_WIREFRAME = 15;
- public final int MENU_QUALITY_SOLID = 16;
- public final int MENU_QUALITY_FLAT = 18;
- public final int MENU_QUALITY_GOURAUD = 19;
- public final int MENU_QUALITY_PHONG = 20;
- public final int MENU_MODEL_MONO = 22;
- public final int MENU_MODEL_RGB = 23;
- public final int MENU_DITHER = 25;
- public final int MENU_TEXTURE_FILTERING = 26;
- public final int MENU_LIGHT_DIRECTIONAL = 27;
- public final int MENU_LIGHT_PARALLEL_POINT = 28;
- public final int MENU_LIGHT_POINT = 29;
- public final int MENU_LIGHT_SPOT = 30;
-
- MenuItemX items[] =
- {
- new MenuItemX("File" , 0, POPUP),
- new MenuItemX("About" , MENU_FILE_ABOUT, 0),
- new MenuItemX("Open" , MENU_FILE_OPEN, 0),
- new MenuItemX("AnimSet" , MENU_FILE_OPEN_ANIMSET , 0),
- new MenuItemX("OpenFrame" , MENU_FILE_OPEN_FRAME , SEPARATOR_NEXT),
- new MenuItemX("Exit" , MENU_FILE_EXIT , ENDMENU),
- new MenuItemX("Edit" , 0, POPUP),
- new MenuItemX("Cut" , MENU_EDIT_CUT , 0),
- new MenuItemX("Copy" , MENU_EDIT_COPY , 0),
- new MenuItemX("Paste" , MENU_EDIT_PASTE , 0),
- new MenuItemX("Delete" , MENU_EDIT_DELETE , SEPARATOR_NEXT),
- new MenuItemX("Color" , MENU_EDIT_COLOR, SEPARATOR_NEXT),
- new MenuItemX("Boxes" , MENU_EDIT_BOXES, ENDMENU),
- new MenuItemX("Quality" , 0, POPUP),
- new MenuItemX("Lighting" , MENU_QUALITY_LIGHTING , CHECKED + SEPARATOR_NEXT),
- new MenuItemX("Points" , MENU_QUALITY_POINTS , 0),
- new MenuItemX("Wireframe" , MENU_QUALITY_WIREFRAME , 0),
- new MenuItemX("Solid" , MENU_QUALITY_SOLID , CHECKED+SEPARATOR_NEXT),
- new MenuItemX("Flat" , MENU_QUALITY_FLAT , CHECKED),
- new MenuItemX("Gouraud" , MENU_QUALITY_GOURAUD , 0),
- new MenuItemX("Phong" , MENU_QUALITY_PHONG , SEPARATOR_NEXT),
- new MenuItemX("Mono" , MENU_MODEL_MONO , CHECKED),
- new MenuItemX("Rgb" , MENU_MODEL_RGB , SEPARATOR_NEXT),
- new MenuItemX("Dither" , MENU_DITHER , 0),
- new MenuItemX("Filtering" , MENU_TEXTURE_FILTERING , ENDMENU),
- new MenuItemX("Light" , 0, POPUP),
- new MenuItemX("Directional" , MENU_LIGHT_DIRECTIONAL , 0),
- new MenuItemX("Parallel" , MENU_LIGHT_PARALLEL_POINT, 0),
- new MenuItemX("Point" , MENU_LIGHT_POINT , 0),
- new MenuItemX("Spot" , MENU_LIGHT_SPOT, ENDMENU)
- };
-
- int m_menuItems = 30; // Number of menu items
-
- ViewFrame(String s)
- {
- super(s);
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- //
- // cant do anything in the constructor, no window created yet!
- //
- public void startWindow(Applet theApp, String menuSet[])
- {
- setBackground(Color.white);
-
- if( menuSet == null )
- setMenuBar(new MenuBarX(items, m_menuItems, theApp, "menuString"));
- else
- setMenuBar(new MenuBarX(items, m_menuItems, menuSet));
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- MenuX GetAMenu(int m)
- {
- MenuBarX bar = (MenuBarX)getMenuBar();
- return (MenuX)bar.getMenu(m);
- }
-
-
-
- public void Paint(Graphics g)
- {
- g.drawString("MenuX demo sample", 10, 10);
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- public boolean action(Event e, Object o)
- {
-
- if( o instanceof String )
- {
- MenuBarX menubar = (MenuBarX)getMenuBar();
- int key = menubar.getItemID((String)o);
- if( key != -1 )
- {
- //
- // Checkbox is set on or off only for the Quality menu
- //
-
- MenuX menu = (MenuX) menubar.getMenu(2); //Quality menu
- key = menu.getItemID((String)o);
- boolean checked = true;
- if (key != -1)
- {
- key -= 12;
- //12 is index of Quality submenu start
-
- // Implement groups
- // Only one in a group can be checked any time
- // Atleast one in each group has to be checked
- //
-
- if (key == 2 || key == 3 || key == 4)
- {
- MenuItemX item1 = (MenuItemX) menu.getItem(key);
- item1 = (MenuItemX) menu.getItem(2);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(3);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(4);
- item1.Check(false);
- }
-
-
- if (key == 6 || key == 7 || key == 8)
- {
- MenuItemX item1 = (MenuItemX) menu.getItem(key);
- item1 = (MenuItemX) menu.getItem(6);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(7);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(8);
- item1.Check(false);
- }
-
- if (key == 10 || key == 11)
- {
- MenuItemX item1 = (MenuItemX) menu.getItem(key);
- item1 = (MenuItemX) menu.getItem(10);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(11);
- item1.Check(false);
- }
-
- if (key == 13 || key == 14)
- {
- MenuItemX item1 = (MenuItemX) menu.getItem(key);
- item1 = (MenuItemX) menu.getItem(13);
- item1.Check(false);
- item1 = (MenuItemX) menu.getItem(14);
- item1.Check(false);
- }
-
- MenuItemX item = (MenuItemX) menu.getItem(key);
- checked = item.isChecked();
- item.Check(!checked); // true works as well
- // checked will always be false as we are turning
- // off the check marks except for key == 1 (LIGHTING)
-
- }
- if ( o instanceof String )
- {
- //bring up a messagebox with the item name
- new MessageBox((Frame)this, 0, (String)o);
- }
-
- }
- }
- return true;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // needed to allow window close
-
- public boolean handleEvent(Event e)
- {
- if (e.id == Event.WINDOW_DESTROY)
- {
- dispose();
- return true;
- }
-
-
- // it's good form to let the super class look at any
- // unhandled events
- return super.handleEvent(e);
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- }
-
-