Sha256: a954efd2e041ce59259b8810bff4bbb3edd0d2db89c1c4d970dcf71d15658b07

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

module Glimmer
  module SWT
    # Proxy for org.eclipse.swt.widgets.Display
    #
    # Maintains a singleton instance since SWT only supports
    # a single active display at a time.
    #
    # Supports SWT Display's very useful asyncExec and syncExec methods
    # to support proper multi-threaded manipulation of SWT UI objects
    #
    # Invoking `#swt_display` returns the SWT Display object wrapped by this proxy
    #
    # Follows the Proxy Design Pattern
    class DisplayProxy
      include_package 'org.eclipse.swt.widgets'

      class << self
        # Returns singleton instance
        def instance(*args)
          if @instance.nil? || @instance.swt_display.isDisposed
            @instance = new(*args)
          end
          @instance
        end
      end

      # SWT Display object wrapped
      attr_reader :swt_display

      def initialize(*args)
        @swt_display = Display.new(*args)
      end

      def dispose
        @swt_display.dispose
      end

      # Executes code block asynchronously with respect to SWT UI thread
      def async_exec(&block)
        @swt_display.asyncExec(&block)
      end

      # Executes code block synchronously with respect to SWT UI thread
      def sync_exec(&block)
        @swt_display.syncExec(&block)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
glimmer-0.5.8 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.7 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.6 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.5 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.4 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.3 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.2 lib/glimmer/swt/display_proxy.rb
glimmer-0.5.0 lib/glimmer/swt/display_proxy.rb