Class: Clevic::SearchDialog
- Includes:
- AcceptReject, QtFlags
- Defined in:
- lib/clevic/qt/search_dialog.rb,
lib/clevic/swing/search_dialog.rb
Instance Attribute Summary collapse
-
#backwards ⇒ Object
readonly
Returns the value of attribute backwards.
-
#cancel_button ⇒ Object
readonly
Returns the value of attribute cancel_button.
-
#forwards ⇒ Object
readonly
Returns the value of attribute forwards.
-
#from_start ⇒ Object
Returns the value of attribute from_start.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#match_flags ⇒ Object
readonly
Returns the value of attribute match_flags.
-
#ok_button ⇒ Object
readonly
Returns the value of attribute ok_button.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#result ⇒ Object
Returns the value of attribute result.
-
#search_combo ⇒ Object
readonly
Returns the value of attribute search_combo.
-
#search_label ⇒ Object
readonly
Returns the value of attribute search_label.
-
#status ⇒ Object
readonly
after the dialog, this will be either accepted or rejected.
-
#whole_words ⇒ Object
readonly
Returns the value of attribute whole_words.
Instance Method Summary collapse
- #accept! ⇒ Object
- #accepted? ⇒ Boolean
- #backwards? ⇒ Boolean
-
#direction ⇒ Object
return either :backwards or :forwards.
-
#exec(text = '') ⇒ Object
show the dialog, wait for close, return an object that understands rejected? and accepted?.
- #forwards? ⇒ Boolean
- #from_start? ⇒ Boolean
- #init_controls ⇒ Object
-
#init_layout ⇒ Object
this was originally Java from NetBeans, so it’s really ugly.
-
#initialize(parent = nil, modal = true) ⇒ SearchDialog
constructor
A new instance of SearchDialog.
- #regex? ⇒ Boolean
- #reject! ⇒ Object
- #rejected? ⇒ Boolean
- #search_text ⇒ Object
- #search_text=(value) ⇒ Object
- #whole_words? ⇒ Boolean
Constructor Details
#initialize(parent = nil, modal = true) ⇒ SearchDialog
Returns a new instance of SearchDialog.
15 16 17 18 19 |
# File 'lib/clevic/qt/search_dialog.rb', line 15 def initialize( parent ) @layout = Ui_SearchDialog.new @dialog = Qt::Dialog.new @layout.setupUi( @dialog ) end |
Instance Attribute Details
#backwards ⇒ Object (readonly)
Returns the value of attribute backwards.
108 109 110 |
# File 'lib/clevic/swing/search_dialog.rb', line 108 def backwards @backwards end |
#cancel_button ⇒ Object (readonly)
Returns the value of attribute cancel_button.
109 110 111 |
# File 'lib/clevic/swing/search_dialog.rb', line 109 def @cancel_button end |
#forwards ⇒ Object (readonly)
Returns the value of attribute forwards.
108 109 110 |
# File 'lib/clevic/swing/search_dialog.rb', line 108 def forwards @forwards end |
#from_start ⇒ Object
Returns the value of attribute from_start.
107 108 109 |
# File 'lib/clevic/swing/search_dialog.rb', line 107 def from_start @from_start end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
12 13 14 |
# File 'lib/clevic/qt/search_dialog.rb', line 12 def layout @layout end |
#match_flags ⇒ Object (readonly)
Returns the value of attribute match_flags.
12 13 14 |
# File 'lib/clevic/qt/search_dialog.rb', line 12 def match_flags @match_flags end |
#ok_button ⇒ Object (readonly)
Returns the value of attribute ok_button.
109 110 111 |
# File 'lib/clevic/swing/search_dialog.rb', line 109 def @ok_button end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
107 108 109 |
# File 'lib/clevic/swing/search_dialog.rb', line 107 def regex @regex end |
#result ⇒ Object
Returns the value of attribute result.
13 14 15 |
# File 'lib/clevic/qt/search_dialog.rb', line 13 def result @result end |
#search_combo ⇒ Object (readonly)
Returns the value of attribute search_combo.
37 38 39 |
# File 'lib/clevic/qt/search_dialog.rb', line 37 def search_combo layout.search_combo end |
#search_label ⇒ Object (readonly)
Returns the value of attribute search_label.
106 107 108 |
# File 'lib/clevic/swing/search_dialog.rb', line 106 def search_label @search_label end |
#status ⇒ Object (readonly)
after the dialog, this will be either accepted or rejected
31 32 33 |
# File 'lib/clevic/swing/search_dialog.rb', line 31 def status @status end |
#whole_words ⇒ Object (readonly)
Returns the value of attribute whole_words.
107 108 109 |
# File 'lib/clevic/swing/search_dialog.rb', line 107 def whole_words @whole_words end |
Instance Method Details
#accept! ⇒ Object
94 95 96 |
# File 'lib/clevic/swing/search_dialog.rb', line 94 def accept! @status = :accept end |
#accepted? ⇒ Boolean
90 91 92 |
# File 'lib/clevic/swing/search_dialog.rb', line 90 def accepted? status == :accept end |
#backwards? ⇒ Boolean
45 46 47 |
# File 'lib/clevic/qt/search_dialog.rb', line 45 def backwards? layout.backwards.checked? end |
#direction ⇒ Object
return either :backwards or :forwards
50 51 52 53 54 |
# File 'lib/clevic/qt/search_dialog.rb', line 50 def direction return :forwards if forwards? return :backwards if backwards? raise "direction not known" end |
#exec(text = '') ⇒ Object
show the dialog, wait for close, return an object that understands rejected? and accepted?
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/clevic/swing/search_dialog.rb', line 66 def exec( text = '' ) search_combo.edit_text = text.to_s search_combo.set_focus self.result = @dialog.exec # remember previous searches if search_combo.find_text( search_combo.current_text ) == -1 search_combo.add_item( search_combo.current_text ) end self end |
#forwards? ⇒ Boolean
41 42 43 |
# File 'lib/clevic/qt/search_dialog.rb', line 41 def forwards? layout.forwards.checked? end |
#from_start? ⇒ Boolean
21 22 23 |
# File 'lib/clevic/qt/search_dialog.rb', line 21 def from_start? layout.from_start.value end |
#init_controls ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/clevic/swing/search_dialog.rb', line 111 def init_controls @search_label = javax.swing.JLabel.new( "Search" ).tap do |search_label| search_label.text = "Search" search_label.name = "search_label" end @search_combo = javax.swing.JComboBox.new.tap do |search_combo| search_combo.editable = true search_combo.name = "search_combo" end @from_start = javax.swing.JCheckBox.new.tap do |from_start| from_start.mnemonic = 'S' from_start.text = "From Start" from_start.name = "from_start" end @regex = javax.swing.JCheckBox.new.tap do |regex| regex.mnemonic = 'R' regex.text = "Regular Expression" regex.name = "regex" end @whole_words = javax.swing.JCheckBox.new.tap do |whole_words| whole_words.mnemonic = 'W' whole_words.text = "Whole words" whole_words.name = "whole_words" end @forwards = javax.swing.JRadioButton.new.tap do |forwards| forwards.mnemonic = 'F' forwards.text = "Forwards" forwards.name = "forwards" forwards.selected = true end @backwards = javax.swing.JRadioButton.new.tap do |backwards| backwards.mnemonic = 'B' backwards.text = "Backwards" backwards.name = "backwards" end @ok_button = javax.swing.JButton.new.tap do || .mnemonic = 'O' .text = "Ok" .name = "ok_button" .add_action_listener do |event| hide accept! end end @cancel_button = javax.swing.JButton.new.tap do || .mnemonic = 'C' .text = "Cancel" .name = "cancel_button" .add_action_listener do |event| hide reject! end end end |
#init_layout ⇒ Object
this was originally Java from NetBeans, so it’s really ugly. Note that for 1.5 compatibility, we have to use org.jdesktop.layout.GroupLayout and include swing-layout-1.0.3.jar
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/clevic/swing/search_dialog.rb', line 177 def init_layout content_pane.layout = org.jdesktop.layout.GroupLayout.new( content_pane ).tap do |layout| getContentPane().setLayout(layout); layout.setHorizontalGroup( \ layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \ .add(layout.createSequentialGroup() \ .addContainerGap() \ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \ .add(layout.createSequentialGroup() \ .add(21, 21, 21) \ .add(search_label) \ .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING, false) \ .add(search_combo, 0, 192, java.lang.Short::MAX_VALUE) \ .add(from_start, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, java.lang.Short::MAX_VALUE) \ .add(regex, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, java.lang.Short::MAX_VALUE) \ .add(whole_words, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, java.lang.Short::MAX_VALUE) \ .add(forwards, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, java.lang.Short::MAX_VALUE) \ .add(backwards))) \ .add(layout.createSequentialGroup() \ .add() \ .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED, 160, java.lang.Short::MAX_VALUE) \ .add())) \ .add(16, 16, 16)) \ ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout::LEADING) \ .add(org.jdesktop.layout.GroupLayout::TRAILING, layout.createSequentialGroup() \ .addContainerGap(23, java.lang.Short::MAX_VALUE) \ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::BASELINE) \ .add(search_combo, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE, org.jdesktop.layout.GroupLayout::DEFAULT_SIZE, org.jdesktop.layout.GroupLayout::PREFERRED_SIZE) \ .add(search_label)) \ .add(18, 18, 18) \ .add(from_start) \ .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \ .add(regex) \ .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \ .add(whole_words) \ .add(18, 18, 18) \ .add(forwards) \ .addPreferredGap(org.jdesktop.layout.LayoutStyle::RELATED) \ .add(backwards) \ .add(18, 18, 18) \ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout::BASELINE) \ .add() \ .add()) \ .add(20, 20, 20)) \ ); end pack end |
#regex? ⇒ Boolean
29 30 31 |
# File 'lib/clevic/qt/search_dialog.rb', line 29 def regex? layout.regex.value end |
#reject! ⇒ Object
102 103 104 |
# File 'lib/clevic/swing/search_dialog.rb', line 102 def reject! @status = :reject end |
#rejected? ⇒ Boolean
98 99 100 |
# File 'lib/clevic/swing/search_dialog.rb', line 98 def rejected? status == :reject end |
#search_text ⇒ Object
69 70 71 |
# File 'lib/clevic/qt/search_dialog.rb', line 69 def search_text search_combo.current_text end |
#search_text=(value) ⇒ Object
82 83 84 |
# File 'lib/clevic/swing/search_dialog.rb', line 82 def search_text=( value ) search_combo.editor.item = value.to_s end |
#whole_words? ⇒ Boolean
33 34 35 |
# File 'lib/clevic/qt/search_dialog.rb', line 33 def whole_words? layout.whole_words.value end |