File: filechooser.rb

package info (click to toggle)
ruby-rjb 1.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 704 kB
  • sloc: ansic: 3,859; ruby: 2,604; java: 247; makefile: 35; sh: 3
file content (35 lines) | stat: -rw-r--r-- 590 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/local/bin/ruby -Ks
#coding: cp932

require 'rjb'

Rjb::load

unless RUBY_VERSION =~ /^1\.9/
  class String
    def encode(s)
      self
    end
  end
end

class FileChooser
  @@klass = Rjb::import('javax.swing.JFileChooser')
  def initialize(ext = '*', desc = 'any files')
    @selected = nil
  end

  def show()
    chooser = @@klass.new
    if chooser.showOpenDialog(nil) == @@klass.APPROVE_OPTION 
      @selected = chooser.getSelectedFile
    end
  end
  attr_reader :selected
end

f = FileChooser.new
if f.show  
  puts f.selected.getAbsolutePath.encode('cp932')
end
puts 'bye'