Class: RSwing::Components::Dialog

Inherits:
JDialog
  • Object
show all
Includes:
Window
Defined in:
lib/rswing/components/dialog.rb

Overview

Dialog-Class. Has static methods to create Message-Dialogs. (show() and show_option). Can also be used to create custom dialogs by extending from this class.

Constant Summary

Constants included from Events::WindowFocus

Events::WindowFocus::WindowFocusListener

Constants included from Events::WindowState

Events::WindowState::WindowStateListener

Constants included from Events::PropertyChanged

Events::PropertyChanged::PropertyChangeListener

Constants included from Events::ContainerEvents

Events::ContainerEvents::ContainerListener

Constants included from Events::FocusEvents

Events::FocusEvents::FocusListener

Constants included from Events::InputMethodEvents

Events::InputMethodEvents::InputMethodListener

Constants included from Events::HierarchyBoundsEvents

Events::HierarchyBoundsEvents::HierarchyBoundsListener

Constants included from Events::KeyEvents

Events::KeyEvents::KeyListener

Constants included from Events::MouseWheelEvents

Events::MouseWheelEvents::MouseWheelListener

Constants included from Events::MouseMotionEvents

Events::MouseMotionEvents::MouseMotionListener

Constants included from Events::MouseEvents

Events::MouseEvents::MouseListener

Constants included from Events::ComponentEvents

Events::ComponentEvents::ComponentListener

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Window

init, #location=, #size=

Methods included from Events::WindowFocus

event_mappings

Methods included from Container

#[], #add, add_if_requested, #add_with_name, #components, #remove

Methods included from Events::ContainerEvents

event_mappings

Methods included from Events::FocusEvents

event_mappings

Methods included from Events::InputMethodEvents

event_mappings

Methods included from Events::HierarchyBoundsEvents

event_mappings

Methods included from Events::KeyEvents

event_mappings

Methods included from Events::MouseMotionEvents

event_mappings

Methods included from Events::MouseEvents

event_mappings

Methods included from Events::ComponentEvents

event_mappings

Constructor Details

#initialize(title, options = {}, &block) ⇒ Dialog

Returns a new instance of Dialog.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rswing/components/dialog.rb', line 32

def initialize(title, options = {}, &block)
  super(Options.value_for(options => :belongs_to), title, Options.value_for(options => :modal))
  
  Window.init(self, options)
  
  if(name = Options.value_for(options => :name) && owner.class.include?(Container))
    owner.add_with_name(self, name)
  end
  
  # call block with current object, if given
  if block_given?
    yield self
  end
end

Class Method Details

.option_type_for(option_type) ⇒ Object

Returns a JOptionPane-specific option_type for a given rswing-option_type. For example:

  1. :yes_no => JOptionPane::YES_NO_OPTION

  2. :yes_no_cancel => JOptionPane::YES_NO_CANCEL_OPTION



99
100
101
102
103
104
105
106
# File 'lib/rswing/components/dialog.rb', line 99

def self.option_type_for(option_type)
  case option_type
  when :yes_no
    JOptionPane::YES_NO_OPTION
  else
    JOptionPane::YES_NO_CANCEL_OPTION
  end
end

.show(message, options = {}) ⇒ Object

Creates a MessageDialog.

  • message: Message, to be displayed in this dialog.

  • options: Options-Hash with the following valid values:

  1. :dialog_type => (:error | :question | :plain | :warning | :info) (default: :info)

  2. :title => "my title" (defailt: "")

  3. :modal => false (default: true)

  4. :belongs_to => parent Parent-Container for this dialog (default: nil)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rswing/components/dialog.rb', line 54

def self.show(message, options = {})
  message_type =
    case Options.value_for(options => :dialog_type)
    when :error
      JOptionPane::ERROR_MESSAGE
    when :question
      JOptionPane::QUESTION_MESSAGE
    when :plain
      JOptionPane::PLAIN_MESSAGE
    when :warning
      JOptionPane::WARNING_MESSAGE
    else
      JOptionPane::INFORMATION_MESSAGE
    end
  
  JOptionPane.showMessageDialog(Options.value_for(options => :belongs_to), message, 
    Options.value_for(options => :title), message_type)
end

.show_option(message, options = {}) ⇒ Object

Creates a OptionsDialog (Dialog with selection for different Options).

  • message: Message, to be displayed in the dialog.

  • options: Options-Hash with the following valid values:

  1. :option_type => (:yes_no | :yes_no_cancel) (default: :yes_no)

  2. :option_values => ["OK", "Cancel", "Quit"] (default: ["Yes", "No"])

  3. :title => "my title" (default: "")

  4. :modal => false (default: true)

  5. :icon => nil (default: nil)

  6. :belongs_to => parent Parent-Container for this dialog (default: nil)



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rswing/components/dialog.rb', line 82

def self.show_option(message, options = {})
  title = options[:title].nil? ? Options.gui_options[:option_default_title] : options[:title]
  icon = Options.value_for(options => :icon) 
  
  option_type = option_type_for(Options.value_for(options => :option_type))
  option_values = Options.value_for(options => :option_values)
    
  selected_option_index = JOptionPane.showOptionDialog(Options.value_for(options => :belongs_to), message, 
    title, option_type, JOptionPane::QUESTION_MESSAGE, icon, option_values.to_java(:Object), nil);
                        
  option_values[selected_option_index]
end