Class: Clevic::ConfirmDialog
- Defined in:
- lib/clevic/swing/confirm_dialog.rb
Overview
keeps a list of names => results mappings and returns
Instance Attribute Summary collapse
-
#dialog_result ⇒ Object
Returns the value of attribute dialog_result.
-
#names ⇒ Object
Returns the value of attribute names.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#question ⇒ Object
Returns the value of attribute question.
-
#results ⇒ Object
Returns the value of attribute results.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#[]=(name, *args) ⇒ Object
To create a an Ok button that has the focus, and causes the class to return true from accepted? dialog = :accept, true.
- #accepted? ⇒ Boolean
- #canonical_results ⇒ Object
-
#initialize {|_self| ... } ⇒ ConfirmDialog
constructor
A new instance of ConfirmDialog.
- #rejected? ⇒ Boolean
- #show ⇒ Object
- #to_java(arg) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ ConfirmDialog
Returns a new instance of ConfirmDialog.
5 6 7 8 9 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 5 def initialize @names = [] @results = [] yield self if block_given? end |
Instance Attribute Details
#dialog_result ⇒ Object
Returns the value of attribute dialog_result.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def dialog_result @dialog_result end |
#names ⇒ Object
Returns the value of attribute names.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def names @names end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def parent @parent end |
#question ⇒ Object
Returns the value of attribute question.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def question @question end |
#results ⇒ Object
Returns the value of attribute results.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def results @results end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 11 def title @title end |
Instance Method Details
#[]=(name, *args) ⇒ Object
To create a an Ok button that has the focus, and causes the class to return true from accepted?
dialog['Ok'] = :accept, true
To create a Cancel button that returns true from rejected?
dialog['Cancel'] = :reject
27 28 29 30 31 32 33 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 27 def []=( name, *args ) result, default = *args.flatten raise "Result is not in #{@canonical_results.inspect}" unless canonical_results.include?( result.to_sym ) names << name.to_s results << result.to_sym @default = name.to_s if default end |
#accepted? ⇒ Boolean
35 36 37 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 35 def accepted? results[dialog_result] == :accept end |
#canonical_results ⇒ Object
17 18 19 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 17 def canonical_results @canonical_results ||= [:accept, :reject] end |
#rejected? ⇒ Boolean
39 40 41 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 39 def rejected? results[dialog_result] == :reject end |
#show ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 43 def show self.dialog_result = javax.swing.JOptionPane.showOptionDialog( parent, question, title, javax.swing.JOptionPane::DEFAULT_OPTION, javax.swing.JOptionPane::QUESTION_MESSAGE, nil, # icon. Not used here names.to_java( :object ), @default ) self end |
#to_java(arg) ⇒ Object
13 14 15 |
# File 'lib/clevic/swing/confirm_dialog.rb', line 13 def to_java( arg ) .keys.to_java( arg ) end |