home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / AWT / menux / ViewFrame.java < prev   
Encoding:
Java Source  |  1996-10-15  |  8.0 KB  |  220 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import com.ms.awt.*;
  4. import com.ms.directX.*;
  5. import MessageBox;
  6.  
  7. //----------------------------------------------------------
  8. // class ViewFrame
  9. //----------------------------------------------------------
  10.  
  11. public class ViewFrame extends Frame implements  MenuXConstants
  12. {
  13.     public final int MENU_FILE_ABOUT            = 1 ;
  14.     public final int MENU_FILE_OPEN             = 2 ;
  15.     public final int MENU_FILE_OPEN_ANIMSET     = 3 ; 
  16.     public final int MENU_FILE_OPEN_FRAME       = 4 ;
  17.     public final int MENU_FILE_EXIT             = 5 ;
  18.     public final int MENU_EDIT_CUT              = 6 ;
  19.     public final int MENU_EDIT_COPY             = 7 ;
  20.     public final int MENU_EDIT_PASTE            = 8 ;
  21.     public final int MENU_EDIT_DELETE           = 9 ;
  22.     public final int MENU_EDIT_COLOR            = 10;
  23.     public final int MENU_EDIT_BOXES            = 11;
  24.     public final int MENU_QUALITY_LIGHTING      = 12; 
  25.     //separator
  26.     public final int MENU_QUALITY_POINTS        = 14;
  27.     public final int MENU_QUALITY_WIREFRAME     = 15;
  28.     public final int MENU_QUALITY_SOLID         = 16;
  29.     public final int MENU_QUALITY_FLAT          = 18;
  30.     public final int MENU_QUALITY_GOURAUD       = 19;
  31.     public final int MENU_QUALITY_PHONG         = 20;
  32.     public final int MENU_MODEL_MONO            = 22;
  33.     public final int MENU_MODEL_RGB             = 23;
  34.     public final int MENU_DITHER                = 25;
  35.     public final int MENU_TEXTURE_FILTERING     = 26;
  36.     public final int MENU_LIGHT_DIRECTIONAL     = 27; 
  37.     public final int MENU_LIGHT_PARALLEL_POINT  = 28;
  38.     public final int MENU_LIGHT_POINT           = 29;
  39.     public final int MENU_LIGHT_SPOT            = 30;
  40.     
  41.         MenuItemX items[] = 
  42.         {
  43.                 new MenuItemX("File" ,     0,                                              POPUP), 
  44.                 new MenuItemX("About" ,     MENU_FILE_ABOUT,            0), 
  45.                 new MenuItemX("Open" ,     MENU_FILE_OPEN,             0), 
  46.                 new MenuItemX("AnimSet" ,     MENU_FILE_OPEN_ANIMSET ,    0), 
  47.                 new MenuItemX("OpenFrame" ,     MENU_FILE_OPEN_FRAME  ,     SEPARATOR_NEXT),         
  48.                 new MenuItemX("Exit" ,     MENU_FILE_EXIT ,            ENDMENU),        
  49.                 new MenuItemX("Edit" ,     0,                                              POPUP), 
  50.                 new MenuItemX("Cut" ,     MENU_EDIT_CUT  ,            0),         
  51.                 new MenuItemX("Copy" ,     MENU_EDIT_COPY ,            0),         
  52.                 new MenuItemX("Paste" ,     MENU_EDIT_PASTE ,           0),         
  53.                 new MenuItemX("Delete" ,     MENU_EDIT_DELETE  ,         SEPARATOR_NEXT),         
  54.                 new MenuItemX("Color" ,     MENU_EDIT_COLOR,            SEPARATOR_NEXT),        
  55.                 new MenuItemX("Boxes" ,     MENU_EDIT_BOXES,            ENDMENU),     
  56.                 new MenuItemX("Quality" ,     0,                                              POPUP), 
  57.                 new MenuItemX("Lighting" ,     MENU_QUALITY_LIGHTING  ,    CHECKED + SEPARATOR_NEXT),         
  58.                 new MenuItemX("Points" ,     MENU_QUALITY_POINTS  ,      0), 
  59.                 new MenuItemX("Wireframe" ,     MENU_QUALITY_WIREFRAME  ,   0), 
  60.                 new MenuItemX("Solid" ,     MENU_QUALITY_SOLID  ,       CHECKED+SEPARATOR_NEXT), 
  61.                 new MenuItemX("Flat" ,     MENU_QUALITY_FLAT  ,        CHECKED), 
  62.                 new MenuItemX("Gouraud" ,     MENU_QUALITY_GOURAUD  ,     0), 
  63.                 new MenuItemX("Phong" ,     MENU_QUALITY_PHONG ,        SEPARATOR_NEXT), 
  64.                 new MenuItemX("Mono" ,     MENU_MODEL_MONO ,           CHECKED),         
  65.                 new MenuItemX("Rgb" ,     MENU_MODEL_RGB  ,           SEPARATOR_NEXT),         
  66.                 new MenuItemX("Dither" ,     MENU_DITHER ,               0), 
  67.                 new MenuItemX("Filtering" ,     MENU_TEXTURE_FILTERING  ,   ENDMENU),
  68.                 new MenuItemX("Light" ,     0,                                              POPUP), 
  69.                 new MenuItemX("Directional" ,     MENU_LIGHT_DIRECTIONAL  ,   0),         
  70.                 new MenuItemX("Parallel" ,     MENU_LIGHT_PARALLEL_POINT,      0),         
  71.                 new MenuItemX("Point" ,     MENU_LIGHT_POINT ,          0),        
  72.                 new MenuItemX("Spot" ,     MENU_LIGHT_SPOT,                    ENDMENU)
  73.         };
  74.     
  75.     int    m_menuItems = 30;      // Number of menu items
  76.     
  77.     ViewFrame(String s)
  78.     {
  79.         super(s);
  80.     }
  81.     
  82.     //////////////////////////////////////////////////////////////////////////
  83.  
  84.     //
  85.     // cant do anything in the constructor, no window created yet!
  86.     //
  87.     public void startWindow(Applet theApp, String menuSet[])
  88.     {
  89.         setBackground(Color.white);
  90.         
  91.         if( menuSet == null )
  92.             setMenuBar(new MenuBarX(items, m_menuItems, theApp, "menuString"));
  93.         else
  94.             setMenuBar(new MenuBarX(items, m_menuItems, menuSet));
  95.     }
  96.  
  97.     //////////////////////////////////////////////////////////////////////////
  98.  
  99.     MenuX GetAMenu(int m)
  100.     {
  101.          MenuBarX bar = (MenuBarX)getMenuBar();
  102.          return (MenuX)bar.getMenu(m);
  103.     }
  104.  
  105.  
  106.  
  107.     public void Paint(Graphics g)
  108.     {
  109.             g.drawString("MenuX demo sample", 10, 10);
  110.     }
  111.  
  112.     //////////////////////////////////////////////////////////////////////////
  113.  
  114.     public boolean action(Event e, Object o)
  115.     {
  116.  
  117.         if( o instanceof String )
  118.         {
  119.             MenuBarX menubar = (MenuBarX)getMenuBar();
  120.             int key = menubar.getItemID((String)o);
  121.             if( key != -1 )
  122.             {
  123.                 //
  124.                 // Checkbox is set on or off only for the Quality menu
  125.                 //
  126.  
  127.                 MenuX menu = (MenuX) menubar.getMenu(2); //Quality menu
  128.                 key = menu.getItemID((String)o);
  129.                 boolean checked = true;
  130.                 if (key != -1)
  131.                 {
  132.                     key -= 12; 
  133.                     //12 is index of Quality submenu start
  134.  
  135.                     // Implement groups
  136.                     // Only one in a group can be checked any time
  137.                     // Atleast one in each group has to be checked
  138.                     //
  139.  
  140.                     if (key == 2 || key == 3 || key == 4)
  141.                     {
  142.                         MenuItemX item1 = (MenuItemX) menu.getItem(key);
  143.                         item1 = (MenuItemX) menu.getItem(2);
  144.                         item1.Check(false);
  145.                         item1 = (MenuItemX) menu.getItem(3);
  146.                         item1.Check(false);
  147.                         item1 = (MenuItemX) menu.getItem(4);
  148.                         item1.Check(false);
  149.                     }
  150.  
  151.  
  152.                     if (key == 6 || key == 7 || key == 8)
  153.                     {
  154.                         MenuItemX item1 = (MenuItemX) menu.getItem(key);
  155.                         item1 = (MenuItemX) menu.getItem(6);
  156.                         item1.Check(false);
  157.                         item1 = (MenuItemX) menu.getItem(7);
  158.                         item1.Check(false);
  159.                         item1 = (MenuItemX) menu.getItem(8);
  160.                         item1.Check(false);
  161.                     }
  162.  
  163.                     if (key == 10 || key == 11)
  164.                     {
  165.                         MenuItemX item1 = (MenuItemX) menu.getItem(key);
  166.                         item1 = (MenuItemX) menu.getItem(10);
  167.                         item1.Check(false);
  168.                         item1 = (MenuItemX) menu.getItem(11);
  169.                         item1.Check(false);
  170.                     }
  171.  
  172.                     if (key == 13 || key == 14)
  173.                     {
  174.                         MenuItemX item1 = (MenuItemX) menu.getItem(key);
  175.                         item1 = (MenuItemX) menu.getItem(13);
  176.                         item1.Check(false);
  177.                         item1 = (MenuItemX) menu.getItem(14);
  178.                         item1.Check(false);
  179.                     }
  180.  
  181.                     MenuItemX item = (MenuItemX) menu.getItem(key);
  182.                     checked = item.isChecked();
  183.                     item.Check(!checked);  // true works as well 
  184.                                            // checked will always be false as we are turning
  185.                                            //  off the check marks except for key == 1 (LIGHTING)
  186.  
  187.                 }
  188.                 if ( o instanceof String )
  189.                 {
  190.                 //bring up a messagebox with the item name
  191.                         new MessageBox((Frame)this, 0, (String)o);
  192.                 }
  193.  
  194.             }
  195.         }
  196.         return true;
  197.     }
  198.  
  199.     //////////////////////////////////////////////////////////////////////////
  200.     // needed to allow window close
  201.     
  202.     public boolean handleEvent(Event e)
  203.     {
  204.         if (e.id == Event.WINDOW_DESTROY)
  205.         {
  206.             dispose();
  207.             return true;
  208.         }
  209.         
  210.        
  211.         // it's good form to let the super class look at any 
  212.         // unhandled events
  213.         return super.handleEvent(e);
  214.     }
  215.     
  216.     //////////////////////////////////////////////////////////////////////////
  217.  
  218. }
  219.  
  220.