class Alert

  def initialize(msg, target_display = nil, &block)
    target_display = Swt::Widgets::Display.get_current unless target_display
    @shell = Swt::Widgets::Shell.new(target_display, Swt::SWT::DIALOG_TRIM)
    @shell.setText("Fire.app")
    @shell.setBackgroundMode(Swt::SWT::INHERIT_DEFAULT)
    @shell.setSize(800,480)
    layout = Swt::Layout::GridLayout.new(7, false)
    layout.numColumns = 2;
    @shell.layout = layout

    gridData = Swt::Layout::GridData.new
    gridData.horizontalAlignment = Swt::SWT::LEFT;
    gridData.verticalAlignment = Swt::SWT::TOP;
    gridData.verticalSpan=1
    if defined? App
      @label = Swt::Widgets::Label.new(@shell, Swt::SWT::LEFT)
      @label.setImage( App.create_image('icon/32.png') )
      @label.setLayoutData(gridData)
    end 
    gridData = Swt::Layout::GridData.new
    @label = Swt::Widgets::Label.new(@shell, Swt::SWT::LEFT)
    @label.setText(msg)
    @label.setLayoutData(gridData)


    gridData = Swt::Layout::GridData.new
    gridData.horizontalAlignment = Swt::SWT::RIGHT;
    gridData.verticalAlignment = Swt::SWT::BOTTOM;
    gridData.grabExcessHorizontalSpace = false;
    gridData.grabExcessVerticalSpace = false;
    gridData.horizontalSpan=2
    btn = Swt::Widgets::Button.new(@shell, Swt::SWT::PUSH | Swt::SWT::CENTER)
    btn.setText('OK')
    btn.setLayoutData(gridData)
    btn.addListener(Swt::SWT::Selection,Swt::Widgets::Listener.impl do |method, evt|   
      block.call if block_given?
      evt.widget.shell.dispose();
    end)
    @shell.pack
    @monior=target_display.getPrimaryMonitor().getBounds();
    rect = @shell.getClientArea();
    @shell.setLocation((@monior.width-rect.width) /2, (@monior.height-rect.height) /2) 
    @shell.open
    @shell.forceActive
  end

  def replace(msg)
    @label.text = msg
    @label.update
    @shell.pack
    rect = @shell.getClientArea();
    @shell.setLocation((@monior.width-rect.width) /2, (@monior.height-rect.height) /2) 
  end
end
