Skip to content

A File Chooser for Ruby Processing

Martin Prout edited this page Aug 23, 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 string reflection method)

load_library :file_chooser
attr_reader :img

###########
# example file chooser (in this case image file chooser) you could
# the image loading and resizing is encapsulated in the block.
# borrows heavily off 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

chooser sketch