/* GridBagTest: a GridBagLayout test.                                 */
/* ------------------------------------------------------------------ */
/* This is a sample stand-alone Java application with frame and a     */
/* custom component that shows how to use gridbag layout.             */
/* ------------------------------------------------------------------ */
/* Martin Lafaix -- July 1996                                         */

options binary                     -- optional, for speed

import ViewerComponent

/* ------------------------------------------------------------------ */
/* GridBagTest -- an applet or stand-alone application                */
/* ------------------------------------------------------------------ */
class GridBagTest extends Applet

 method makebutton(name=String, gridbag=GridBagLayout, c=GridBagConstraints)
   button = Button(name)
   gridbag.setConstraints(button, c)
   add(button)

 method init
   gridbag = GridBagLayout()
   c = GridBagConstraints()
   setFont(Font("Helvetica", Font.PLAIN, 14))
   setLayout(gridbag)
   c.fill = GridBagConstraints.BOTH
   c.weightx = 1.0
   makebutton("Button1", gridbag, c)
   makebutton("Button2", gridbag, c)
   makebutton("Button3", gridbag, c)
   c.gridwidth = GridBagConstraints.REMAINDER   -- end row
   makebutton("Button4", gridbag, c)
   c.weightx = 0.0                              -- reset to the default
   makebutton("Button5", gridbag, c)            -- another row
   c.gridwidth = GridBagConstraints.RELATIVE    -- next to last in row
   makebutton("Button6", gridbag, c)
   c.gridwidth = GridBagConstraints.REMAINDER   -- end row
   makebutton("Button7", gridbag, c)
   c.gridwidth = 1                              -- reset to the default
   c.gridheight = 2
   c.weighty = 1.0
   bitmap = Button('test')
-- a test
   bitmap = ViewerComponent('mfc.gif')
   gridbag.setConstraints(bitmap, c)
   add(bitmap)
--   makebutton("Button8", gridbag, c)
   c.weighty = 0.0                              -- reset to the default
   c.gridwidth = GridBagConstraints.REMAINDER   -- end row
   c.gridheight = 1                             -- reset to the default
   makebutton("Button9", gridbag, c)
   makebutton("Button10", gridbag, c)
   resize(300, 100)

class GridBagMain extends Frame

 /* The 'main' method is called when this class is started as an application */
 method main(s=String[]) static
   GridBagMain("GridBag Layout Example")

 method GridBagMain(s=String)
   super(s)

   ex1 = GridBagTest()
   ex1.init
   add("Center", ex1)
   this.pack
   resize(preferredSize())
   this.show

 /* Method for handling events */
 method handleEvent(e=Event) returns boolean
   if e.id=Event.WINDOW_DESTROY then exit    -- exit on close
   return super.handleEvent(e)               -- otherwise take default action