|
Commentary TBD
TODO: Needs some work to make setting tab colors/icons easier.
|
require 'jrbuilder'
ctx = JRBuilder.new_swing_context
ctx.enter {
attr_reader :my_frame
attr_accessor :my_table
# this one is just too much of a pain to type, even in our shortened form
add_class_alias('tree_node', javax.swing.tree.DefaultMutableTreeNode)
Font = java.awt.Font
Color = java.awt.Color
JOptionPane = javax.swing.JOptionPane
bgcolor = color(240,238,220)
popup = nil # custom dialog (see end of file)
bg1 = nil # radio button group
bg2 = nil # radio button group
text = nil # text area
column_headings = ['SKU','Product Name','Quantity','Unit Price','Total Price']
data = [
['123-456-789','Foo',3,2.75,3*2.75],
['123-456-790','Foo Plus',5,3.75,5*3.75],
['555-867-5309','Super Foo',2,9.27,2*9.27],
['987-654-321','Foo for Bars',4,7.99,4*7.99]
]
tree_nodes =
tree_node('Home',true) {
0.upto(2) do |i|
tree_node('Foo ' + i.to_s,true) {
0.upto(2) do |j|
tree_node('Bar ' + i.to_s + '.' + j.to_s,true) {
0.upto(1) do |k|
tree_node('Baz ' + i.to_s + '.' + j.to_s + '.' + k.to_s,true)
end
}
end
}
end
}
my_tree = tree(tree_nodes)
@my_frame = frame('Tabs Demo 1') { size 500, 500
content_pane { background bgcolor; layout :box, _parent, :Y_AXIS
border :bevel, :RAISED }
on_window_closing { my_frame.dispose }
menu_bar { background bgcolor
menu("File") { mnemonic :VK_F; background :WHITE
menu_item("Exit") { mnemonic :VK_X; background :WHITE
on_click { my_frame.dispose }
}
} }
tabbed_pane { background bgcolor
panel {name 'Table'; background bgcolor; layout :box, _parent, :Y_AXIS
border :compound, border(:titled, 'Current Order Items') {
border :etched,:LOWERED }, border(:empty,7,7,7,7)
scroll_pane(
@my_table = table(data,column_headings) {
get_table_header {
background :BLUE; foreground :WHITE;
font('Dialog',:BOLD,12)
}
}) {
get_viewport { background :WHITE }
}
}
panel { name 'Tree'; background bgcolor; layout :box, _parent, :Y_AXIS
border :empty,7,7,7,7
scroll_pane(my_tree)
}
panel { name 'Widgets'; background bgcolor; layout :box, _parent, :Y_AXIS; align :LEFT
border :empty,0,4,4,4
x_box { align :LEFT
button('Custom Dialog') { align :LEFT; on_click { _center(popup,my_frame).show }}
x_strut 8
button('Message Dialog') { align :LEFT
on_click {JOptionPane.showMessageDialog(
my_frame,'Thanks for visiting!','SwingBuilder Sez',JOptionPane::PLAIN_MESSAGE)}
}
x_strut 8
button('Confirm Dialog') { align :LEFT
on_click {JOptionPane.showConfirmDialog(my_frame, 'Are we having fun yet?')}
}
x_glue
}
y_strut 5
x_box { align :LEFT
y_box { align :LEFT,:TOP
panel { border(:titled,'Text Style') { border :etched, :LOWERED }
layout :box, _parent, :Y_AXIS ; background bgcolor; align :LEFT,:TOP
check_box('Bold') { background bgcolor; align :LEFT
on_click { |event,box|
if box.selected
text.font = font(text.font.name,text.font.style|Font::BOLD,text.font.size)
else
text.font = font(text.font.name,text.font.style^Font::BOLD,text.font.size)
end
}
}
check_box('Italic') { background bgcolor; align :LEFT
on_click { |event,box|
if box.selected
text.font = font(text.font.name,text.font.style|Font::ITALIC,text.font.size)
else
text.font = font(text.font.name,text.font.style^Font::ITALIC,text.font.size)
end
}
}
check_box('Mono-spaced') { background bgcolor; align :LEFT
on_click { |event,box|
if box.selected
text.font = font('Monospaced',text.font.style,text.font.size)
else
text.font = font('Dialog',text.font.style,text.font.size)
end
}
}
x_spacer(120) { align :LEFT }
}
panel { background bgcolor; layout :box, _parent, :Y_AXIS; align :LEFT,:TOP
border(:titled,'Color') { border :etched, :LOWERED }
r1 = radio_button('Black',true) { background bgcolor; align :LEFT
on_click { text.foreground = Color::BLACK }
}
r2 = radio_button('Blue') { background bgcolor; align :LEFT
on_click { text.foreground = Color::BLUE }
}
r3 = radio_button('Red') { background bgcolor; align :LEFT
on_click { text.foreground = Color::RED }
}
bg1 = button_group { add r1; add r2; add r3 }
x_spacer(120) { align :LEFT }
}
panel { background bgcolor; layout :box, _parent, :Y_AXIS; align :LEFT,:TOP
border(:titled,'Size') { border :etched, :LOWERED }
s1 = radio_button('Large') { background bgcolor; align :LEFT
on_click { text.font = font(text.font.name,text.font.style, 20) }
}
s2 = radio_button('Medium',true) { background bgcolor; align :LEFT
on_click { text.font = font(text.font.name,text.font.style, 12) }
}
s3 = radio_button('Small') { background bgcolor; align :LEFT
on_click { text.font = font(text.font.name,text.font.style, 8) }
}
bg2 = button_group { add s1; add s2; add s3 }
x_spacer(120) { align :LEFT }
}
}
x_glue
panel { background bgcolor; layout :box, _parent, :Y_AXIS; align :LEFT,:TOP
scroll_pane(
text = text_area(20,25){border :bevel, :LOWERED; text 'Welcome to SwingBuilder!'
align :LEFT,:TOP
}) {
align :LEFT,:TOP
}
y_glue
}
}
y_glue
}
}
}
popup = dialog(my_frame,'Hello',true) { size 240, 180
content_pane { layout :box,_parent,:Y_AXIS; background bgcolor; align :CENTER }
y_glue
label('Howdy Doody') { align :CENTER }
y_spacer(15)
button("Click to close") { on_click { popup.visible = false }; align :CENTER }
y_glue
}
}
ctx.my_frame.show
|
|