Sha256: 395d62a3bf4b2e46c2c64669a716e18a4e789b2c0d55c29ecf37c706f43539ff

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require_relative 'g_widget'
require_relative 'g_display'

module Glimmer
  class GShell < GWidget
    WIDTH_MIN = 130
    HEIGHT_MIN = 0

    include_package 'org.eclipse.swt.layout'
    include_package 'org.eclipse.swt.widgets'

    attr_reader :display

    # Instantiates shell with same arguments expected by SWT Shell 
    def initialize(*args)
      if !args.first.is_a?(Display) && !args.first.is_a?(Shell)
        @display = GDisplay.instance.display
        args = [@display] + args
      end
      args = GSWT.constantify_args(args)
      @widget = Shell.new(*args)
      @display ||= @widget.getDisplay
      @widget.setLayout(FillLayout.new)
      @widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
    end

    # Centers shell within screen
    def center
      primary_monitor = @display.getPrimaryMonitor()
      monitor_bounds = primary_monitor.getBounds()
      shell_bounds = @widget.getBounds()
      location_x = monitor_bounds.x + (monitor_bounds.width - shell_bounds.width) / 2
      location_y = monitor_bounds.y + (monitor_bounds.height - shell_bounds.height) / 2
      @widget.setLocation(location_x, location_y)
    end

    # Opens shell and starts SWT's UI thread event loop
    def open
      @widget.pack
      center
      @widget.open
      until @widget.isDisposed
        @display.sleep unless @display.readAndDispatch
      end
      @display.dispose
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glimmer-0.4.2 lib/glimmer/command_handlers/models/g_shell.rb