Sha256: 0b19b2b24a1714f2ee86259445820502b4ef01a358eeee7e962fbfbdf8a4c899

Contents?: true

Size: 1.46 KB

Versions: 33

Compression:

Stored size: 1.46 KB

Contents

---
layout: page
title:  "File Chooser"
permalink:   /classes/chooser/
---

A native file chooser for propane, bases around vanilla processing `selectInput`.

### Usage ###

First load the `chooser` library, this creates the interface:-

`public void file_selected(java.io.File selected);`

which you need to define in your sketch, to make use the `selected` file. This sketch makes use of the propane method `resizable` (vanilla processing `surface.setResizable(true)`) so that we can change sketch size to match our `image`. Note we need to guard against `img` being `nil` or sketch will crash. You may change the the prompt `select an image` in `select_input` but you cannot change `file_selected` which is hard-wired to cope with java reflection.

### example sketch ###
```ruby
load_library :chooser

attr_reader :img

def settings
  size(400, 200)
end

def setup
  sketch_title 'Chooser'
  resizable
  fill 0, 0, 200
  text('Click Window to Load Image', 10, 100)
end

def draw
  image(img, 0, 0) unless img.nil?
end

def file_selected(selection)
  if selection.nil?
    puts 'Nothing Chosen'
  else
    @img = load_image(selection.get_absolute_path)
    surface.set_size(img.width, img.height)
  end
end

def mouse_clicked
  @img = nil
  # java_signature 'void selectInput(String, String)'
  select_input('select an image', 'file_selected')
end
```

See more [examples here][examples]

[examples]:https://github.com/ruby-processing/picrate-examples/tree/processing_app/library/file_chooser

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
picrate-2.5.2-java docs/_classes/chooser/chooser.md
picrate-2.5.1-java docs/_classes/chooser/chooser.md
picrate-2.5.0-java docs/_classes/chooser/chooser.md
picrate-2.4.2-java docs/_classes/chooser/chooser.md
picrate-2.4.1-java docs/_classes/chooser/chooser.md
picrate-2.4.0-java docs/_classes/chooser/chooser.md
picrate-2.3.0-java docs/_classes/chooser/chooser.md
picrate-2.2.0-java docs/_classes/chooser/chooser.md
picrate-2.1.2-java docs/_classes/chooser/chooser.md
picrate-2.1.1-java docs/_classes/chooser/chooser.md
picrate-2.1.0-java docs/_classes/chooser/chooser.md
picrate-2.0.1-java docs/_classes/chooser/chooser.md
picrate-1.3.0-java docs/_classes/chooser/chooser.md
picrate-2.0.0.pre-java docs/_classes/chooser/chooser.md
picrate-1.2.4-java docs/_classes/chooser/chooser.md
picrate-1.2.3-java docs/_classes/chooser/chooser.md
picrate-1.2.2-java docs/_classes/chooser/chooser.md
picrate-1.2.1-java docs/_classes/chooser/chooser.md
picrate-1.2.0-java docs/_classes/chooser/chooser.md
picrate-1.1.0-java docs/_classes/chooser/chooser.md