Sha256: 7242feca2ec53584f62168dba89d9bdd465f9f2305842756159467b7680a0138

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

module Redcar
  class SplashScreen
    class << self
      attr_reader :splash_screen
    end
    
    def self.create_splash_screen(maximum)
      @splash_screen = SplashScreen.new(maximum)
      splash_screen.show
    end

    attr_reader :max
    
    def initialize(max)
      @max = max
      @current = 0
    end
    
    def show
      @image = Swt::Graphics::Image.new(Swt.display, Redcar.icons_directory + "/redcar-splash.png")
      @splash = Swt::Widgets::Shell.new(Swt::SWT::NONE)
      @bar = Swt::Widgets::ProgressBar.new(@splash, Swt::SWT::NONE)
      @bar.setMaximum(max)
      label = Swt::Widgets::Label.new(@splash, Swt::SWT::NONE)
      label.setImage(@image)
      layout = Swt::Layout::FormLayout.new
      @splash.setLayout(layout)
      labelData = Swt::Layout::FormData.new
      labelData.right  = Swt::Layout::FormAttachment.new(100, 0)
      labelData.bottom = Swt::Layout::FormAttachment.new(100, 0)
      label.setLayoutData(labelData)
      progressData = Swt::Layout::FormData.new
      progressData.left   = Swt::Layout::FormAttachment.new(0, 5)
      progressData.right  = Swt::Layout::FormAttachment.new(100, -5)
      progressData.bottom = Swt::Layout::FormAttachment.new(100, -5)
      @bar.setLayoutData(progressData)
      @splash.pack
      
      primary = Swt.display.getPrimaryMonitor
      bounds = primary.getBounds
      rect = @splash.getBounds
      x = bounds.x + (bounds.width - rect.width) / 2;
      y = bounds.y + (bounds.height - rect.height) / 2;
    
      @splash.setLocation(x, y)
      @splash.open
      Redcar.log.debug("opened splash")
    end
    
    def inc(val = 1)
      @current += val
      @bar.setSelection([@current, @max].min)
    end
    
    def close
      @splash.close
      @image.dispose
      Swt.instance_variable_set(:@splashscreen, nil)
      Redcar.log.debug("closed splash")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redcar-dev-0.12.11dev-java plugins/splash_screen/splash_screen.rb
redcar-dev-0.12.10dev-java plugins/splash_screen/splash_screen.rb
redcar-dev-0.12.9dev-java plugins/splash_screen/splash_screen.rb