Skip navigation links
Graphics2D Actor API

Package g2d.mwa

Provides classes and interfaces for the Multi-Window Application (MWA) framework.

See: Description

Package g2d.mwa Description

Provides classes and interfaces for the Multi-Window Application (MWA) framework.

The control of the application resides with the singleton instance of MWAControl. Users instantiate MWAFrame for each window that is to be controlled by the control application.

The following example shows the usage in jlambda. The example initially starts 3 windows. A new menu item "File -> New Window" allows to create more top-level windows (enumerated) on-the-fly. Another new menu item "File -> New Sub-Window" creates new windows as children of the current one.

(seq

; a global counter for new frames
(define counterI
  (object ("g2d.util.Box" (object ("java.lang.Integer" (int 1))))))

; a common routine to be applied to all new frames
(define makeFrame (frame)
  (let ((menuBar (object ("javax.swing.JMenuBar")))
        (fileM (object ("javax.swing.JMenu" "File")))
        (newMI (object ("javax.swing.JMenuItem" "New Window")))
        (newSubMI (object ("javax.swing.JMenuItem" "New Sub-Window")))
        ; closures to be activated by menu items
        (newClosure
         (lambda (self e)
           (let ((count (invoke counterI "getContents"))
                 (newframe (object ("g2d.mwa.MWAFrame"
                                    (concat "new frame " count)))))
             (seq
              ; update global counter
              (invoke counterI "setContents"
                      (object ("java.lang.Integer"
                               (+ (int 1) (invoke count "intValue")))))
              ; make new frame and show it
              (apply makeFrame newframe)
              )))) ;newClosure
        (newSubClosure
         (lambda (self e)
           (let ((count (invoke counterI "getContents"))
                 (newframe (object ("g2d.mwa.MWAFrame"
                                    (concat "new frame " count)
                                    frame)))) ; adding new frame as a child
             (seq
              ; update global counter
              (invoke counterI "setContents"
                      (object ("java.lang.Integer"
                               (+ (int 1) (invoke count "intValue")))))
              ; make new frame and show it
              (apply makeFrame newframe)
              )))) ;newClosure
        )
    (seq
     ; installing closures as ActionListener's
     (invoke newMI "addActionListener"
             (object ("g2d.closure.ClosureActionListener" newClosure)))
     (invoke newSubMI "addActionListener"
             (object ("g2d.closure.ClosureActionListener" newSubClosure)))
     ; fill file menu
     (invoke fileM "add" newMI)
     (invoke fileM "add" newSubMI)
     ; add file menu to menu bar and update menu bar in frame
     (invoke menuBar "add" fileM)
     (invoke frame "setJMenuBar" menuBar)
     ; make frame visible
     (invoke frame "setVisible" (boolean true))
     ))) ;makeFrame

; testing code
(let ((frame1 (object ("g2d.mwa.MWAFrame" "first")))
      (frame2 (object ("g2d.mwa.MWAFrame" "second")))
      (frame3 (object ("g2d.mwa.MWAFrame" "first")))) ;using a duplicate title
  (seq
   ; have every frame look the same by applying this function
   (apply makeFrame frame1)
   (apply makeFrame frame2)
   (apply makeFrame frame3)
   ))

) ;seq

Package Specification

(none)

Related Documentation

Since:
0.1
Skip navigation links
Graphics2D Actor API