Class Limelight::FileChooser
In: lib/limelight/file_chooser.rb
Parent: Object

An object that manages the selection of a file on the file system. When invoked, a file chooser window will pop up and allow the user to select a file.

Methods

choose_file   new  

Attributes

chooser  [R] 
chosen_file  [R] 

Public Class methods

Creates a new FileChooser. Options may include:

  • :description => a string describing the desired file
  • :parent => (required) the parent window
  • :directory => starting directory
  • :title => title of the window
  • :directories_only => boolean, true if the user must select a directory
  • :files_only => boolean, true if the user must select a file

[Source]

    # File lib/limelight/file_chooser.rb, line 23
23:     def initialize(options = {}, &filter)
24:       @options = options
25:       @parent = options[:parent]
26:       create_chooser
27:       @chooser.setFileFilter(FileFilter.new(@options[:description], &filter)) if filter
28:     end

Public Instance methods

Opens the windows and returns the chosen file.

[Source]

    # File lib/limelight/file_chooser.rb, line 32
32:     def choose_file
33:       returnVal = @chooser.showOpenDialog(@parent);
34:       
35:       if(returnVal == javax.swing.JFileChooser::APPROVE_OPTION)
36:         @chosen_file = @chooser.getSelectedFile().absolute_path
37:       else
38:         @chosen_file = nil
39:       end
40:       
41:       return @chosen_file
42:     end

[Validate]