BBjWrappedJComponent Example

use javax.swing.event.ChangeEvent
use javax.swing.event.ChangeListener
use javax.swing.JComponent
use javax.swing.JPanel
use javax.swing.JSplitPane
use javax.swing.JLabel
use java.awt.Container
use java.awt.Dimension
use java.awt.GridBagLayout
use java.awt.GridBagConstraints
use java.awt.Insets
declare BBjSysGui sysgui!
declare BBjWindow window!
declare BBjButton button!
declare BBjCEdit cedit!
declare BBjCheckBox checkbox!
declare BBjEditBox editbox!
declare BBjImageCtrl imagectrl!
declare BBjInputE inpute!
declare BBjInputN inputn!
declare BBjInputD inputd!
declare BBjListBox listbox!
declare BBjListButton listbutton!
declare BBjListEdit listedit!
declare BBjNavigator navigator!
declare BBjProgressBar progressbar!
declare BBjScrollBar scrollbar!
declare BBjStaticText statictext!
declare BBjToolButton toolbutton!
declare BBjTree tree!
declare BBjStandardGrid grid!
declare Container container!
declare Dimension@ dimension!
declare JComponent component!
declare JPanel@ clientPanel!
declare GridBagLayout@ layout!
declare GridBagConstraints@ c!
open (unt)"X0"
sysgui! = BBjAPI().getSysGui()
window! = sysgui!.addWindow(100,100,800,600,"BBjWindow",$00010013$)
layout! = new GridBagLayout@()
clientPanel! = new  JPanel@()
clientpanel!.setLayout(layout!)

rem ' Helper function to force sizes
sizer! = new Sizer(clientPanel!)

rem ' GridBagLayout is formatted according to the grid shown here
rem ' GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,fill,insets,ipadx,ipady)
rem '
rem ' gridx,gridy specify the upper left corner of the control based on the grid below
rem ' gridwidth,gridheight specify how many grid cells the control uses
rem ' weightx indicates whether the control stretches as the screen width changes
rem ' weighty indicates whether the control stretches as the screen height changes
rem ' anchor specifies where the control is anchored in the cell based on compass coordinates
rem ' fill specifies whether the control should be resized (horizontal, vertical, both, neither)
rem ' insets specifies a border of empty space around the control
rem ' ipadx,ipady specify how much to add to the preferred size width and height
rem '
rem '    0          1          2          3          4          5
rem '
rem ' 0  "EDIT"     editbox    "LISTBOX"  listbox    "CEDIT"    cedit
rem '
rem ' 1  "INPUTE"   inpute                listbox               cedit
rem '
rem ' 2  "INPUTN"   inputn    "LISTBUTTON"listbutton "TREE"     tree
rem '
rem ' 3  "INPUTD"   inputd    "LISTEDIT"  listedit              tree
rem '
rem ' 4  "CHECK1"   checkbox1 "CHECK2"    checkbox2             tree
rem '
rem ' 5  "RADIO1"   radio1    "RADIO2"    radio2     "GRID"     grid
rem '
rem ' 6  "PROGRESS" progressbar=====================            grid
rem '
rem ' 7  "NAVIGATOR"navigator=======================            grid
rem '
rem ' 8  "SCROLLBAR"scrollbar======================= "IMAGE"    image
rem '
rem ' 9  "BUTTON"   button    "TBUTTON"  tbutton                image
rem '
rem ' GridBag constants
declare Insets@ i!
i! = new Insets@(3,3,3,3)
declare BBjNumber EAST
declare BBjNumber NORTHEAST
declare BBjNumber NORTHWEST
declare BBjNumber NONE
declare BBjNumber HORZ
declare BBjNumber VERT
declare BBjNumber BOTH
EAST = java.awt.GridBagConstraints.EAST
NORTHEAST = java.awt.GridBagConstraints.NORTHEAST
NORTHWEST = java.awt.GridBagConstraints.NORTHWEST
NONE = java.awt.GridBagConstraints.NONE
HORZ = java.awt.GridBagConstraints.HORIZONTAL
VERT = java.awt.GridBagConstraints.VERTICAL
BOTH = java.awt.GridBagConstraints.BOTH
ListSample$ = "A"+$0A$+"B"+$0A$+"C"+$0A$+"D"+$0A$+"E"+$0A$+"F"+$0A$

rem ' ============================== Row 0 ==============================
rem ' BBjEditBox
text! = new JLabel@("BBjEditBox")
c! = new GridBagConstraints@(0,0,1,1,1,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem ' 0
editbox! = window!.addEditBox(101,10,10,90,30,"BBjEditBox")
c! = new GridBagConstraints@(1,0,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(editbox!,c!); rem ' 1
sizer!.setSize(1,90,30)

rem ' BBjListBox
text! = new JLabel@("BBjListBox")
c! = new GridBagConstraints@(2,0,1,1,1,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 2
listbox! = window!.addListBox(102,10,10,90,30,ListSample$)
c! = new GridBagConstraints@(3,0,1,2,1,1,NORTHWEST,BOTH,i!,0,0)
clientPanel!.add(listbox!,c!); rem 3

rem ' BBjCEdit
text! = new JLabel@("BBjCEdit")
c! = new GridBagConstraints@(4,0,1,1,1,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 4
gosub gettysburg
cedit! = window!.addCEdit(103,10,10,200,100,gettysburg$,$0182$)
c! = new GridBagConstraints@(5,0,1,2,3,0,NORTHWEST,BOTH,i!,0,0)
clientPanel!.add(cedit!,c!); rem 5
sizer!.setSize(5,200,80)

rem ' ============================== Row 1 ==============================
rem ' BBjInputE
text! = new JLabel@("BBjInputE")
c! = new GridBagConstraints@(0,1,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 6
inpute! = window!.addInputE(104,10,10,90,30)
c! = new GridBagConstraints@(1,1,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(inpute!,c!); rem 7
sizer!.setSize(7,90,30)

rem ' ============================== Row 2 ==============================
rem ' BBjInputN
text! = new JLabel@("BBjInputN")
c! = new GridBagConstraints@(0,2,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 8
inputn! = window!.addInputN(105,10,10,90,30)
c! = new GridBagConstraints@(1,2,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(inputn!,c!); rem 9
sizer!.setSize(9,90,30)

rem ' BBjListButton
text! = new JLabel@("BBjListButton")
c! = new GridBagConstraints@(2,2,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 10
listbutton! = window!.addListButton(106,10,10,90,90,ListSample$)
c! = new GridBagConstraints@(3,2,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(listbutton!,c!); rem 11
sizer!.setSize(11,90,30)

rem ' BBjTree
text! = new JLabel@("BBjTree")
c! = new GridBagConstraints@(4,2,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 12
tree! = window!.addTree(107,10,10,200,100)
dim music$[2,4]
music$[0,0]="The Beatles"
music$[0,1]="Hey Jude",MUSIC$[0,2]="Let It Be",MUSIC$[0,3]="Twist and Shout",MUSIC$[0,4]="Yesterday"
music$[1,0]="Paul Simon"
music$[1,1]="Bridge Over Troubled Waters",MUSIC$[1,2]="Hearts and Bones",MUSIC$[1,3]="Kathy's Song",MUSIC$[1,4]="The Sound of Silence"
music$[2,0]="Willie Nelson"
music$[2,1]="Always On My Mind",MUSIC$[2,2]="Getting Over You",MUSIC$[2,3]="Old Fords and Natural Stone",MUSIC$[2,4]="This Morning"
parent=0,node=1
tree!.setRoot(parent,"Music Tree")
for artist=0 to 2
    node=node+1
    tree!.addExpandableNode(node,parent,music$[artist,0])
    song_parent=node
    for song=1 TO 4
        node=node+1
        tree!.addNode(node,song_parent,music$[artist,song])
    next song
next artist
c! = new GridBagConstraints@(5,2,1,3,3,1,NORTHWEST,BOTH,i!,0,0)
clientPanel!.add(tree!,c!); rem 13
sizer!.setSize(13,200,100)

rem ' ============================== Row 3 ==============================
rem ' BBjInputD
text! = new JLabel@("BBjInputD")
c! = new GridBagConstraints@(0,3,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 14
inputd! = window!.addInputD(108,10,10,90,30)
c! = new GridBagConstraints@(1,3,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(inputd!,c!); rem 15
sizer!.setSize(15,90,30)

rem ' BBjListEdit
text! = new JLabel@("BBjListEdit")
c! = new GridBagConstraints@(2,3,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 16
listedit! = window!.addListEdit(109,10,10,90,90,ListSample$)
c! = new GridBagConstraints@(3,3,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(listedit!,c!); rem 17
sizer!.setSize(17,90,30)

rem ' ============================== Row 4 ==============================
rem ' BBjCheckBox (1)
text! = new JLabel@("BBjCheckBox")
c! = new GridBagConstraints@(0,4,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 18
declare BBjCheckBox check1!
check1! = window!.addCheckBox(110,10,10,90,30,"Check1")
c! = new GridBagConstraints@(1,4,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(check1!,c!); rem 19
sizer!.setSize(19,90,30)

rem ' BBjCheckBox (2)
text! = new JLabel@("BBjCheckBox")
c! = new GridBagConstraints@(2,4,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 20
declare BBjCheckBox check2!
check2! = window!.addCheckBox(111,10,10,90,30,"Check2")
c! = new GridBagConstraints@(3,4,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(check2!,c!); rem 21
sizer!.setSize(21,90,30)

rem ' ============================== Row 5 ==============================
rem ' BBjRadioButton (1)
text! = new JLabel@("BBjRadioButton")
c! = new GridBagConstraints@(0,5,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 22
declare BBjRadioButton radio1!
radio1! = window!.addRadioButton(112,10,10,90,30,"Radio1",$0020$)
c! = new GridBagConstraints@(1,5,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(radio1!,c!); rem 23
sizer!.setSize(23,90,30)

rem ' BBjRadioButton (2)
text! = new JLabel@("BBjRadioButton")
c! = new GridBagConstraints@(2,5,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 24
declare BBjRadioButton radio2!
radio2! = window!.addRadioButton(113,10,10,90,30,"Radio2",$0020$)
c! = new GridBagConstraints@(3,5,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(radio2!,c!); rem 25
sizer!.setSize(25,90,30)

rem ' Radio buttons are a group
radiogroup! = window!.addRadioGroup()
radioGroup!.add(radio1!)
radioGroup!.add(radio2!)

rem ' BBjStandardGrid
text! = new JLabel@("BBjGrid")
c! = new GridBagConstraints@(4,5,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 26
grid! = window!.addGrid(114,10,10,300,100)
grid!.setNumRows(10)
grid!.setNumColumns(10)
grid!.setDefaultColumnWidth(30)
grid!.setHorizontalScrollable(sysgui!.TRUE)
grid!.setVerticalScrollable(sysgui!.TRUE)
grid!.setScrollUpdate(sysgui!.TRUE)
grid!.setDefaultAlignment(sysgui!.GRID_ALIGN_LEFT)
grid!.setHasColumnHeader(sysgui!.TRUE)
grid!.setDefaultAlignment(sysgui!.GRID_ALIGN_LEFT)
grid!.setEditable(sysgui!.TRUE)
c! = new GridBagConstraints@(5,5,1,3,3,1,NORTHWEST,BOTH,i!,0,0)
clientPanel!.add(grid!,c!); rem 27
sizer!.setSize(27,200,100)

rem ' ============================== Row 6 ==============================
rem ' BBjProgressBar
text! = new JLabel@("BBjProgressBar")
c! = new GridBagConstraints@(0,6,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 28
declare BBjProgressBar progress!
progress! = window!.addProgressBar(115,10,10,90,30)
c! = new GridBagConstraints@(1,6,3,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(progress!,c!); rem 29
sizer!.setSize(29,90,30)

rem ' ============================== Row 7 ==============================
rem ' BBjNavigator
text! = new JLabel@("BBjNavigator")
c! = new GridBagConstraints@(0,7,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 30
navigator! = window!.addNavigator(116,10,10,150,30,"BBjNavigator")
c! = new GridBagConstraints@(1,7,3,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(navigator!,c!); rem 31
sizer!.setSize(31,150,30)

rem ' ============================== Row 8 ==============================
rem ' BBjScrollBar
text! = new JLabel@("BBjScrollBar")
c! = new GridBagConstraints@(0,8,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 32
scrollbar! = window!.addHorizontalScrollBar(1116,10,10,90,30)
c! = new GridBagConstraints@(1,8,3,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(scrollbar!,c!); rem 33
sizer!.setSize(33,90,30)

rem ' BBjImage & BBjImageCtrl
text! = new JLabel@("BBjImage")
c! = new GridBagConstraints@(4,8,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 34
declare BBjImage image!
image! = BBjAPI().getSysGui().getImageManager().loadImageFromFile("chilelogo.bmp")
imagectrl! = window!.addImageCtrl(117,10,10,90,30,image!)
c! = new GridBagConstraints@(5,8,1,3,3,1,NORTHWEST,BOTH,i!,0,0)
clientPanel!.add(imagectrl!,c!); rem 35

rem ' ============================== Row 9 ==============================
rem ' BBjButton
text! = new JLabel@("BBjButton")
c! = new GridBagConstraints@(0,9,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 36
button! = window!.addButton(1110,10,10,90,30,"Button")
c! = new GridBagConstraints@(1,9,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(button!,c!); rem 37
sizer!.setSize(37,90,30)

rem ' BBjToolButton
declare JLabel@ text!
text! = new JLabel@("BBjToolButton")
c! = new GridBagConstraints@(2,9,1,1,0,0,NORTHEAST,NONE,i!,0,0)
clientPanel!.add(text!,c!); rem 38
toolbutton! = window!.addToolButton(1111,10,10,90,30,"Tool Button")
c! = new GridBagConstraints@(3,9,1,1,1,0,NORTHWEST,HORIZONTAL,i!,0,0)
clientPanel!.add(toolbutton!,c!); rem 39
sizer!.setSize(39,90,30)

rem ' ============================== Ready ==============================
dimension! = new Dimension@(cast(BBjNumber,window!.getWidth()),cast(BBjNumber, window!.getHeight()))
clientPanel!.setPreferredSize(dimension!)

rem 'panel!.add(clientPanel!)
rem 'panel!.validate()
window!.addWrappedJComponent(2222, 0, 0, window!.getWidth(), window!.getY(), clientPanel!)
clientPanel!.setPreferredSize(dimension!)
window!.setVisible(1)
listener! = new Listener()
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")
button!.setCallback(button!.ON_BUTTON_PUSH,listener!,"buttonPush")
toolbutton!.setCallback(toolbutton!.ON_TOOL_BUTTON_PUSH,listener!,"toolButtonPush")
process_events

eoj:
release

resize:
    event!=BBjAPI().getSysGui().getLastEvent()
    dimension! = new Dimension@(cast(BBjNumber,event!.getWidth()),cast(BBjNumber,event!.getHeight()))
    clientPanel!.setPreferredSize(dimension!)
return

class public Sizer
    field private JPanel@ panel!
    method public Sizer(JPanel@ panel!)
        #panel! = panel!
    methodend
    method public void setSize(BBjNumber i, BBjNumber w, BBjNumber h)
        dimension! = new Dimension@(w,h)
        component! = #panel!.getComponent(i)
        component!.setMinimumSize(dimension!)
    methodend
classend
class public Listener

    method public void stateChanged(ChangeEvent p_event!)
        print " ===============    in listener ================="
        print p_event!
        target! = p_event!.getSource()
        ? target!.getValue()
    methodend
    method public void buttonPush(BBjButtonPushEvent event!)
        print "button pushed"
    methodend
    method public void toolButtonPush(BBjToolButtonPushEvent event!)
        print "tool button pushed"
    methodend
classend

gettysburg:
    gettysburg$ =
    :   "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal."+$0a$+$0a$+
    :  "Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this."+$0a$+$0a$+
    :  "But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth."+$0a$
return