Class: RSwing::Components::Dialog
- 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
-
.option_type_for(option_type) ⇒ Object
Returns a JOptionPane-specific option_type for a given rswing-option_type.
-
.show(message, options = {}) ⇒ Object
Creates a MessageDialog.
-
.show_option(message, options = {}) ⇒ Object
Creates a OptionsDialog (Dialog with selection for different Options).
Instance Method Summary collapse
-
#initialize(title, options = {}, &block) ⇒ Dialog
constructor
A new instance of Dialog.
Methods included from Window
Methods included from Events::WindowFocus
Methods included from Container
#[], #add, add_if_requested, #add_with_name, #components, #remove
Methods included from Events::ContainerEvents
Methods included from Events::FocusEvents
Methods included from Events::InputMethodEvents
Methods included from Events::HierarchyBoundsEvents
Methods included from Events::KeyEvents
Methods included from Events::MouseMotionEvents
Methods included from Events::MouseEvents
Methods included from Events::ComponentEvents
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, = {}, &block) super(Options.value_for( => :belongs_to), title, Options.value_for( => :modal)) Window.init(self, ) if(name = Options.value_for( => :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:
-
:yes_no
=>JOptionPane::YES_NO_OPTION
-
: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:
-
:dialog_type => (:error | :question | :plain | :warning | :info)
(default: :info) -
:title => "my title"
(defailt:""
) -
:modal => false
(default: true) -
: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(, = {}) = case Options.value_for( => :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( => :belongs_to), , Options.value_for( => :title), ) 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:
-
:option_type => (:yes_no | :yes_no_cancel)
(default::yes_no
) -
:option_values => ["OK", "Cancel", "Quit"]
(default:["Yes", "No"]
) -
:title => "my title"
(default:""
) -
:modal => false
(default:true
) -
:icon => nil
(default: nil) -
: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(, = {}) title = [:title].nil? ? Options.[:option_default_title] : [:title] icon = Options.value_for( => :icon) option_type = option_type_for(Options.value_for( => :option_type)) option_values = Options.value_for( => :option_values) selected_option_index = JOptionPane.showOptionDialog(Options.value_for( => :belongs_to), , title, option_type, JOptionPane::QUESTION_MESSAGE, icon, option_values.to_java(:Object), nil); option_values[selected_option_index] end |