class Canis::Listbox
A scrollable, selectable array of strings. Delegates display to ListRenderer
Delegates selection to Defaultlistselection (/include/listselectionmodel.rb) Due to extending Defaultlistselection, methods are not visible here. Selection methods are (the first three are what programmers will use the most):
- `selected_values` : returns values selecteda (multiple selection) - `selected_value` : returns value of row selected (single selection) - `selected_rows` : same as selected_indices, indices of selected items - `toggle_row_selection` : toggles current row, called by key $row_selector - `select` : select given or current row - `unselect` : unselects given or current row - `is_row_selected?` : determine if given row is selected - `is_selection_empty?` : has anything been selected - `clear_selection` : clear selection - `select_all` : select all rows
Listbox
also fires a ListSelectionEvent
whose type can be:
- :INSERT , a row or rows added to selection - :DELETE , a row or rows removed from selection - :CLEAR , all selection cleared
Examples¶ ↑
mylist = %w[john tim matz shougo _why sean aaron] l = Listbox.new @form, :row => 5, :col => 4, :height => 10, :width => 20, :list => mylist
Inside a Flow:
lb = listbox :list => mylist, :title => 'Contacts', :width_pc => 50, :selection_mode => :single
Public Class Methods
# File lib/canis/core/widgets/listbox.rb, line 85 def initialize form = nil, config={}, &block @left_margin = 0 @should_show_focus = true register_events([:LEAVE_ROW, :LIST_SELECTION_EVENT]) self.extend DefaultListSelection super # textpad takes care of enter_row and press #@_events.push(*[:LEAVE_ROW, :LIST_SELECTION_EVENT]) bind_key(?f, 'next row starting with char'){ set_selection_for_char(nil) } # if user has not specified a selection model, install default unless @selection_mode == :none unless @list_selection_model create_default_selection_model end end # if user has not specified a renderer, install default unless @renderer create_default_renderer end end
Public Instance Methods
www.opensource.apple.com/source/gcc/gcc-5483/libjava/javax/swing/table/DefaultTableColumnModel.java
clear the list completely of data, including selections
# File lib/canis/core/widgets/listbox.rb, line 131 def clear @selected_indices.clear super end
create a default renderer since user has not specified Widgets inheriting this with a differernt rendering such as tree can overrider this.
# File lib/canis/core/widgets/listbox.rb, line 111 def create_default_renderer r = ListRenderer.new self renderer(r) end
create a default selection model Widgets inheriting this may override this
# File lib/canis/core/widgets/listbox.rb, line 123 def create_default_selection_model list_selection_model(Canis::DefaultListSelectionModel.new self) end
Find the next row that contains given string @return row and col offset of match, or nil @param String
to find
# File lib/canis/core/widgets/listbox.rb, line 195 def next_regex str first = nil ## content can be string or Chunkline, so we had to write <tt>index</tt> for this. ## =~ does not give an error, but it does not work. @list.each_with_index do |line, ix| col = line =~ /#{str}/ if col first ||= [ ix, col ] if ix > @current_index return [ix, col] end end end return first end
This is called whenever user enters a row
# File lib/canis/core/widgets/listbox.rb, line 147 def on_enter_row arow super # TODO check if user wants focus to be showed ## this results in the row being entered and left being evaluated and repainted # which means that the focussed row can be bolded. The renderer's +render+ method will be triggered if @should_show_focus fire_row_changed @oldindex fire_row_changed arow end end
This is called whenever user leaves a row Fires handler for leave_row
# File lib/canis/core/widgets/listbox.rb, line 139 def on_leave_row arow # leave this out, since we are not painting on exit of widget 2014-07-02 - 17:51 #if @should_show_focus #fire_row_changed arow #end fire_handler :LEAVE_ROW, self end
# File lib/canis/core/widgets/listbox.rb, line 115 def renderer *val if val.empty? return @renderer end @renderer = val[0] end
sets the selection to the next row starting with char Trying to return unhandled is having no effect right now. if only we could pop it into a stack or unget it.
# File lib/canis/core/widgets/listbox.rb, line 177 def set_selection_for_char char=nil char = _ask_a_char unless char return :UNHANDLED if char == :UNHANDLED #alert "got #{char}" @oldrow = @current_index @last_regex = /^#{char}/i ix = next_regex @last_regex return unless ix @current_index = ix[0] #alert "curr ind #{@current_index} " @search_found_ix = @current_index @curpos = ix[1] ensure_visible return @current_index end
Private Instance Methods
def on_leave super on_leave_row
@current_index if @current_index end
get a char ensure it is a char or number In this state, it could accept control and other chars.
# File lib/canis/core/widgets/listbox.rb, line 164 def _ask_a_char ch = @graphic.getch #message "achar is #{ch}" if ch < 26 || ch > 255 @graphic.ungetch ch return :UNHANDLED end return ch.chr end