-
Notifications
You must be signed in to change notification settings - Fork 94
A File Chooser for Ruby Processing
Martin Prout edited this page Aug 25, 2013
·
13 revisions
Rather than trying to implement the vanilla processing convenience function "selectInput", which relies on dodgy java reflection nonsense, we provide a more ruby like file chooser (built on JFileChooser). Like the control_panel library, the file_chooser takes a block ( instead of a string reflection method ). On linux using openjdk the default look and feel might be preferred.
load_library :file_chooser
attr_reader :img
###########
# Example file chooser (in this case image file chooser),
# the image loading and resizing is encapsulated in the block.
# Borrows heavily from control_panel.
###########
def setup
size 600, 600
file_chooser do |fc|
fc.look_feel "Nimbus"
fc.set_filter "Image Files", [".png", ".jpg"]
my_file = fc.display
@img = load_image(my_file)
img.resize(width, height)
end
end
def draw
image img, 0, 0
end