BBjTree::getImageWidth

Description

In BBj 20.00 and higher, this BBjTree method returns the image width specified in BBjTree::setImageSize, or 0 if setImageSize has never been called.

Syntax

Return Value Method
int getImageWidth()

Parameters

None.

Return Value

None.

Example

rem ' BBjTree::getImageWidth

sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()

window! = sysgui!.addWindow(50,50,450,650,title$,$20090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.setCallback(window!.ON_RESIZE,"resize")
window!.setCallback(window!.ON_KEYPRESS,"keypress")

rem ' Define tree data
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 Water"
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"

dim image$[2,4]

rem ' fill in filenames here to set node-specific icons
image$[0,0]=""; rem "The Beatles"
image$[0,1]=""; rem "Hey Jude"
image$[0,2]=""; rem "Let It Be"
image$[0,3]=""; rem "Twist and Shout"
image$[0,4]=""; rem "Yesterday"
image$[1,0]=""; rem "Paul Simon"
image$[1,1]=""; rem "Bridge Over Troubled Water"
image$[1,2]=""; rem "Hearts and Bones"
image$[1,3]=""; rem "Kathy's Song"
image$[1,4]=""; rem "The Sound of Silence"
image$[2,0]=""; rem "Willie Nelson"
image$[2,1]=""; rem "Always On My Mind"
image$[2,2]=""; rem "Getting Over You"
image$[2,3]=""; rem "Old Fords and Natural Stone"
image$[2,4]=""; rem "This Morning"

rem ' Create and populate tree
tree! = window!.addTree(101,25,25,400,400)

color! = tree!.getSelectedBackColor()
tree!.setSelectedBackColor(BBjColor.RED)
print "selected background color changed from ",color!," to ",
print tree!.getSelectedBackColor()
color! = tree!.getSelectedForeColor()
tree!.setSelectedForeColor(BBjColor.YELLOW)
print "selected foreground color changed from ",color!," to ",
print tree!.getSelectedForeColor()

tree!.putClientProperty("JTree.lineStyle","None")
tree!.setSelectionMode(tree!.CONTIGUOUS_TREE_SELECTION)
tree!.setCollapsedIcon("collapsed.gif",err=*next)
tree!.setExpandedIcon("expanded.gif",err=*next)
tree!.setLeafIcon("leaf.png",err=*next)
tree!.setSelectedIcon("selected.png",err=*next)

root = 0
node = 0
root$ = "Musical Tree"
root$ = "<html><h2>" + root$ + " " + str(root) + "</h2></html>"
tree!.setRoot(root,root$)
tree!.setToolTipText(root,root$)
color! = sysgui!.makeColor(rnd(255),rnd(255),rnd(255))
tree!.setNodeForeColor(root,color!)
for artist = 0 to 2
    node = node + 1
    artist$ = "<html><h3>"+music$[artist,0]+" "+str(node)+"</h3></html>"
    tree!.addExpandableNode(node,root,artist$)
    tree!.expandNode(node)
    tree!.setToolTipText(node,artist$)
    color! = sysgui!.makeColor(rnd(255),rnd(255),rnd(255))
    tree!.setNodeForeColor(node,color!)
    if (len(image$[artist,0])) then
        tree!.setNodeIcon(node,image$[artist,0])
    endif
    parent = node
    for song = 1 to 4
        node = node + 1
        song$ = music$[artist,song]+" "+str(node)
        tree!.addNode(node,parent,song$)
        tree!.setToolTipText(node,song$)
        color! = sysgui!.makeColor(rnd(255),rnd(255),rnd(255))
        tree!.setNodeForeColor(node,color!)
        if (len(image$[artist,song])) then
            tree!.setNodeIcon(node,image$[artist,song])
        endif
    next song
next artist

rem 'tree!.expandTreeFromNode(0)

tree!.setCallback(tree!.ON_TREE_SELECT,"event")
tree!.setCallback(tree!.ON_TREE_DESELECT,"event")
tree!.setCallback(tree!.ON_TREE_EXPAND,"event")
tree!.setCallback(tree!.ON_TREE_COLLAPSE,"event")
tree!.setCallback(tree!.ON_TREE_EDIT_STOP,"event")
tree!.setCallback(tree!.ON_TREE_MOUSE_UP,"event")
tree!.setCallback(tree!.ON_TREE_MOUSE_DOWN,"event")
tree!.setCallback(tree!.ON_TREE_DOUBLE_CLICK,"event")
tree!.setCallback(tree!.ON_TREE_RIGHT_MOUSE_UP,"event")
tree!.setCallback(tree!.ON_TREE_RIGHT_MOUSE_DOWN,"event")
tree!.setCallback(tree!.ON_CONTROL_SCROLL,"scroll")
tree!.setCallback(tree!.ON_POPUP_REQUEST,"popup")

allNodes! = window!.addMenuButton(1,25,450,100,25,"All Nodes",$$)
allNodes!.setCallback(allNodes!.ON_BUTTON_PUSH,"allNodes")
expNodes! = window!.addMenuButton(2,125,450,100,25,"Expanded",$$)
expNodes!.setCallback(expNodes!.ON_BUTTON_PUSH,"expNodes")

backColor! = window!.addMenuButton(3,125,500,100,25,"backColor",$$)
backColor!.setCallback(backColor!.ON_BUTTON_PUSH,"backColor")

flags$ = iff(tree!.isEnabled(),$0004$,$0000$)
enabled! = window!.addCheckBox(201,25,500,100,25,"Enabled",flags$)
enabled!.setCallback(enabled!.ON_CHECK_OFF,"enabled0")
enabled!.setCallback(enabled!.ON_CHECK_ON,"enabled1")

flags$ = iff(tree!.isEditable(),$0004$,$0000$)
editable! = window!.addCheckBox(202,25,550,100,25,"Editable",flags$)
editable!.setCallback(editable!.ON_CHECK_OFF,"editable0")
editable!.setCallback(editable!.ON_CHECK_ON,"editable1")

flags$ = iff(tree!.isOpaque(),$0004$,$0000$)
opaque! = window!.addCheckBox(203,125,550,100,25,"Opaque",flags$)
opaque!.setCallback(opaque!.ON_CHECK_OFF,"opaque0")
opaque!.setCallback(opaque!.ON_CHECK_ON,"opaque1")

setImageSize! = window!.addCheckBox(204,25,600,200,25,"setImageSize",$0000$)
setImageSize!.setCallback(setImageSize!.ON_CHECK_ON,"setImageSize")
setImageSize!.setCallback(setImageSize!.ON_CHECK_OFF,"clearImageSize")

width = 16
height = 16
width! = window!.addInputN(205,125,600,75,25,$$,"###0",$$,width,height)
width!.setToolTipText("Width")
height! = window!.addInputN(206,225,600,75,25,$$,"###0",$$,width,height)
height!.setToolTipText("Height")

event = 0

dim event$:tmpl(sysgui),generic$:noticetpl(0,0)

process_events

eoj:
release

backColor:
    color! = bbjapi().makeColor(rnd(255),rnd(255),rnd(255))
    print "setBackColor ",color!
    tree!.setBackColor(color!)
return

default:
    color! = null()
    print "setBackColor ",color!
    tree!.setBackColor(color!)
return

scrollable:
    print "Scrollable values:"
    print "isHorizontalScrollBarVisible=",tree!.isHorizontalScrollBarVisible()
    print "getHorizontalScrollBarWidth=",tree!.getHorizontalScrollBarWidth()
    print "getHorizontalScrollBarHeight=",tree!.getHorizontalScrollBarHeight()
    print "getHorizontalScrollBarPosition=",tree!.getHorizontalScrollBarPosition()
    print "isVerticalScrollBarVisible=",tree!.isVerticalScrollBarVisible()
    print "getVerticalScrollBarWidth=",tree!.getVerticalScrollBarWidth()
    print "getVerticalScrollBarHeight=",tree!.getVerticalScrollBarHeight()
    print "getVerticalScrollBarPosition=",tree!.getVerticalScrollBarPosition()
return

event:
    event = event + 1
    event! = sysgui!.getLastEvent()
    event$ = sysgui!.getLastEventString()
    print event!.getEventName(),event,":",
    if (event.code$ = "N") then
        generic$ = notice(sysgui,event.x)
        dim notice$:noticetpl(generic.objtype,event.flags)
        notice$ = generic$
        fields = pos($0a$ = fattr(notice$,""),1,0)
        dim field$:"name["+str(fields)+"]:c(1*)"
        let field$ = fattr(notice$,"")
        for field = 1 to fields
            name$ = field.name$[field]
            info$ = fattr(notice$,name$,$$)
            print " ",name$,"=",
            if (asc(info$) = 1) then
                print field(notice$,name$),
            else
                print str(nfield(notice$,name$)),
            endif
        next field
    endif
    event! = sysgui!.getLastEvent()
    print " isDown=",event!.isDown(err=*next),
    print ""
    print "Selected node:",tree!.getSelectedNode()
    print ""
return

scroll:
    event = event + 1
    event! = sysgui!.getLastEvent()
    print event!.getEventName(),event,": orientation=",str(event!.getOrientation()),
    print " position=",str(event!.getPosition())," adjusting=",str(event!.isAdjusting())
return

popup:
    event! = sysgui!.getLastEvent()
    event$ = sysgui!.getLastEventString()
    print event!.getEventName()," X=",str(event.x)," Y=",str(event.y)
    print ""
return

resize:
    event! = sysgui!.getLastEvent()
    print "Resized; width=",str(event!.getWidth()),", height=",str(event!.getHeight())
return

allNodes:
    node = tree!.getSelectedNode()
    if node < 0 then i = msgbox("No selected node"); return
    count = tree!.getNumChildren(node)
    if count = 0 then i = msgbox("Node "+str(node)+" has no children"); return
    vector! = bbjapi().makeVector()
    for i = 0 to count - 1
        child = tree!.getChildAt(node,i)
        vector!.add(child)
    next i
    i = msgbox(vector!.toString(),0,"All child nodes of "+str(node))
return

expNodes:
    node = tree!.getSelectedNode()
    if node < 0 then i = msgbox("No selected node"); return
    count = tree!.getNumChildren(node)
    if count = 0 then i = msgbox("Node "+str(node)+" has no children"); return
    vector! = bbjapi().makeVector()
    expanded! = tree!.getExpandedNodes()
    for i = 0 to count - 1
        child = tree!.getChildAt(node,i)
        if expanded!.contains(child) then vector!.add(child)
    next i
    i = msgbox(vector!.toString(),0,"Expanded child nodes of "+str(node))
return

enabled0:
    tree!.setEnabled(0)
return

enabled1:
    tree!.setEnabled(1)
return

editable0:
    tree!.setEditable(0)
return

editable1:
    tree!.setEditable(1)
return

opaque0:
    tree!.setOpaque(0)
return

opaque1:
    tree!.setOpaque(1)
return

setImageSize:
    width = width!.getValue()
    height = height!.getValue()
    print "setImageSize",width,height
    tree!.setImageSize(width,height)
    print "getImageWidth",tree!.getImageWidth()
    print "getImageHeight",tree!.getImageHeight()
return

clearImageSize:
    print "clearImageSize"
    tree!.clearImageSize()
    print "getImageWidth ",tree!.getImageWidth()
    print "getImageHeight ",tree!.getImageHeight()
return

keypress:
    print fill(72,"=")
    event$ = sysgui!.getLastEventString()
    key = event.id,flags$ = event.flags$
    print "Window Keypress: ",hta(event.id$)," Flags: ",
    print hta(event.flags$)+": """+cvs(event.id$,16)+"""",
    if key>255 then print "" else gosub key
    event! = sysgui!.getLastEvent()
    print "getOriginalControl(): ",event!.getOriginalControl()
    print "getKeyChar():",num(event!.getKeyChar())
    print "getKeyCode():",num(event!.getKeyCode()),": ",
    keycode = event!.getKeyCode()
    gosub keycode
    print "isShiftDown(): ",event!.isShiftDown()
    print "isControlDown(): ",event!.isControlDown()
    print "isAltDown(): ",event!.isAltDown()
    print "isCmdDown(): ",event!.isCmdDown()
    print fill(72,"=")
return

key:
    print ": ",
    if asc(and(flags$,$01$)) then print "SHIFT+",
    if asc(and(flags$,$02$)) then print "CTRL+",;key = key+64
    if asc(and(flags$,$04$)) then print "ALT+",
    if asc(and(flags$,$08$)) then print "CMD+",
    print cvs(chr(key),16)
return

keycode:
    keycode$ = bin(keycode,2)
    if asc(and(keycode$,$1000$)) then print "SHIFT+",
    if asc(and(keycode$,$2000$)) then print "CTRL+",
    if asc(and(keycode$,$4000$)) then print "ALT+",
    if asc(and(keycode$,$8000$)) then print "CMD+",
    switch dec(and(keycode$,$0fff$))
        case dec($0009$); print "Tab"; break
        case dec($001b$); print "Escape"; break
        case dec($007f$); print "Delete"; break
        case dec($012d$); print "Up arrow"; break
        case dec($012e$); print "Down arrow"; break
        case dec($012f$); print "Right arrow"; break
        case dec($0130$); print "Left arrow"; break
        case dec($0131$); print "Page up"; break
        case dec($0132$); print "Page down"; break
        case dec($0133$); print "Home"; break
        case dec($0134$); print "End"; break
        case dec($0135$); print "Ctrl-Home"; break
        case dec($0136$); print "Ctrl-End"; break
        case dec($0138$); print "Insert"; break
        case dec($0139$); print "Ctrl-Right arrow"; break
        case dec($013a$); print "Ctrl-Left arrow"; break
        case dec($013b$); print "Backtab"; break
        case dec($013e$); print "Keypad 0"; break
        case dec($013f$); print "Keypad 1"; break
        case dec($0140$); print "Keypad 2"; break
        case dec($0141$); print "Keypad 3"; break
        case dec($0142$); print "Keypad 4"; break
        case dec($0143$); print "Keypad 5"; break
        case dec($0144$); print "Keypad 6"; break
        case dec($0145$); print "Keypad 7"; break
        case dec($0146$); print "Keypad 8"; break
        case dec($0147$); print "Keypad 9"; break
        case dec($014b$); print "F1"; break
        case dec($014c$); print "F2"; break
        case dec($014d$); print "F3"; break
        case dec($014e$); print "F4"; break
        case dec($014f$); print "F5"; break
        case dec($0150$); print "F6"; break
        case dec($0151$); print "F7"; break
        case dec($0152$); print "F8"; break
        case dec($0153$); print "F9"; break
        case dec($0154$); print "F10"; break
        case dec($0155$); print "F11"; break
        case dec($0156$); print "F12"; break
        case dec($0174$); print "Keypad *"; break
        case dec($0175$); print "Keypad -"; break
        case dec($0176$); print "Keypad +"; break
        case dec($0177$); print "Keypad /"; break
        case default; print """",chr(dec(and(keycode$,$00ff$))),""" ",keycode; break
    swend
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.