Class: SimpleGuiCreator::DropDownSelector

Inherits:
JDialog
  • Object
show all
Defined in:
lib/simple_gui_creator/swing_helpers.rb

Overview

JDialog is blocking…

Instance Method Summary collapse

Constructor Details

#initialize(parent, options_array, prompt_for_top_entry) ⇒ DropDownSelector

Returns a new instance of DropDownSelector.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/simple_gui_creator/swing_helpers.rb', line 193

def initialize parent, options_array, prompt_for_top_entry
  super parent, true
  set_title prompt_for_top_entry
  @drop_down_elements = options_array
  @selected_idx = nil
  box = JComboBox.new
  box.add_action_listener do |e|
    idx = box.get_selected_index
    if idx != 0
      # don't count choosing the first as a real entry
      @selected_idx = box.get_selected_index - 1
      dispose
    end
  end

  box.add_item @prompt = prompt_for_top_entry # put something in index 0
  options_array.each{|option|
    box.add_item option
  }
  add box
  pack # how do you get this arbitrary size? what the...
  
end

Instance Method Details

#go_selected_indexObject

returns index from initial array that they selected, or raises if they hit the x on it



218
219
220
221
222
223
# File 'lib/simple_gui_creator/swing_helpers.rb', line 218

def go_selected_index
  puts 'select from dropdown window' if $simple_creator_show_console_prompts
  show # blocks...
  raise 'did not select, exited early ' + @prompt unless @selected_idx
  @selected_idx
end

#go_selected_valueObject



225
226
227
228
229
230
# File 'lib/simple_gui_creator/swing_helpers.rb', line 225

def go_selected_value
  puts 'select from dropdown window ' + @drop_down_elements[-1] + ' ...' if $simple_creator_show_console_prompts
  show # blocks...
  raise 'did not select, exited early ' + @prompt unless @selected_idx
  @drop_down_elements[@selected_idx]
end