Class: Glimmer::SWT::ImageProxy
- Inherits:
-
Object
- Object
- Glimmer::SWT::ImageProxy
- Defined in:
- lib/glimmer/swt/image_proxy.rb
Overview
Proxy for org.eclipse.swt.graphics.Image
Invoking ‘#swt_image` returns the SWT Image object wrapped by this proxy
Follows the Proxy Design Pattern
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#image_data ⇒ Object
readonly
Returns the value of attribute image_data.
-
#jar_file_path ⇒ Object
readonly
Returns the value of attribute jar_file_path.
-
#swt_image ⇒ Object
readonly
Returns the value of attribute swt_image.
Instance Method Summary collapse
-
#initialize(*args) ⇒ ImageProxy
constructor
Initializes a proxy for an SWT Image object.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method, *args, &block) ⇒ Boolean
- #scale_to(width, height) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ImageProxy
Initializes a proxy for an SWT Image object
Takes the same args as the SWT Image class Alternatively, takes a file path string or a uri:classloader file path string (generated by JRuby when invoking ‘File.expand_path` inside a JAR file) and returns an image object.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/glimmer/swt/image_proxy.rb', line 18 def initialize(*args) @args = args @file_path = @args.first if @args.first.is_a?(String) && @args.size == 1 if @file_path if @file_path.start_with?('uri:classloader') @jar_file_path = @file_path @file_path = @jar_file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac object = java.lang.Object.new file_input_stream = object.java_class.resource_as_stream(file_path) buffered_file_input_stream = java.io.BufferedInputStream.new(file_input_stream) end @image_data = ImageData.new(buffered_file_input_stream || @file_path) @swt_image = Image.new(DisplayProxy.instance.swt_display, @image_data) else @swt_image = Image.new(*@args) @image_data = @swt_image.image_data end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/glimmer/swt/image_proxy.rb', line 44 def method_missing(method, *args, &block) swt_image.send(method, *args, &block) rescue => e Glimmer::Config.logger.debug {"Neither ImageProxy nor #{swt_image.class.name} can handle the method ##{method}"} super end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
11 12 13 |
# File 'lib/glimmer/swt/image_proxy.rb', line 11 def file_path @file_path end |
#image_data ⇒ Object (readonly)
Returns the value of attribute image_data.
11 12 13 |
# File 'lib/glimmer/swt/image_proxy.rb', line 11 def image_data @image_data end |
#jar_file_path ⇒ Object (readonly)
Returns the value of attribute jar_file_path.
11 12 13 |
# File 'lib/glimmer/swt/image_proxy.rb', line 11 def jar_file_path @jar_file_path end |
#swt_image ⇒ Object (readonly)
Returns the value of attribute swt_image.
11 12 13 |
# File 'lib/glimmer/swt/image_proxy.rb', line 11 def swt_image @swt_image end |
Instance Method Details
#respond_to?(method, *args, &block) ⇒ Boolean
51 52 53 |
# File 'lib/glimmer/swt/image_proxy.rb', line 51 def respond_to?(method, *args, &block) super || swt_image.respond_to?(method, *args, &block) end |
#scale_to(width, height) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/glimmer/swt/image_proxy.rb', line 37 def scale_to(width, height) scaled_image_data = image_data.scaledTo(width, height) device = swt_image.device swt_image.dispose @swt_image = Image.new(device, scaled_image_data) end |