Class: RubyCurses::ListDataModel

Inherits:
Object
  • Object
show all
Includes:
Enumerable, EventHandler
Defined in:
lib/rbcurse/rlistbox.rb

Overview

www.java2s.com/Code/JavaAPI/javax.swing.event/ListDataEventCONTENTSCHANGED.htm should we extend array of will that open us to misuse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(anarray) ⇒ ListDataModel

Returns a new instance of ListDataModel.



49
50
51
# File 'lib/rbcurse/rlistbox.rb', line 49

def initialize anarray
  @list = anarray.dup
end

Instance Attribute Details

#last_regexObject (readonly)

should i really keep here as public or maintain in listbox



47
48
49
# File 'lib/rbcurse/rlistbox.rb', line 47

def last_regex
  @last_regex
end

#selected_indexObject

Returns the value of attribute selected_index.



46
47
48
# File 'lib/rbcurse/rlistbox.rb', line 46

def selected_index
  @selected_index
end

Instance Method Details

#[](off0) ⇒ Object



88
89
90
# File 'lib/rbcurse/rlistbox.rb', line 88

def [](off0)
  @list[off0]
end

#[]=(off0, data) ⇒ Object



85
86
87
# File 'lib/rbcurse/rlistbox.rb', line 85

def []=(off0, data)
  update off0, data
end

#append(data) ⇒ Object



75
76
77
78
79
# File 'lib/rbcurse/rlistbox.rb', line 75

def append data
  @list << data
  lde = ListDataEvent.new(@list.length-1, @list.length-1, self, :INTERVAL_ADDED)
  fire_handler :LIST_DATA_EVENT, lde
end

#delete(obj) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/rbcurse/rlistbox.rb', line 102

def delete obj
  off0 = @list.index obj
  return nil if off0.nil?
  ret=@list.delete_at off0
  lde = ListDataEvent.new(off0, off0, self, :INTERVAL_REMOVED)
  fire_handler :LIST_DATA_EVENT, lde
  return ret
end

#delete_at(off0) ⇒ Object



91
92
93
94
95
96
# File 'lib/rbcurse/rlistbox.rb', line 91

def delete_at off0
  ret=@list.delete_at off0
  lde = ListDataEvent.new(off0, off0, self, :INTERVAL_REMOVED)
  fire_handler :LIST_DATA_EVENT, lde
  return ret
end

#each(&blk) ⇒ Object

changd on 2009-01-14 12:28 based on .. www.ruby-forum.com/topic/175637#769030



54
55
56
# File 'lib/rbcurse/rlistbox.rb', line 54

def each(&blk)
  @list.each(&blk)
end

#find_match(regex, ix0 = 0, ix1 = length()) ⇒ Object

## added 2009-01-14 01:00 searches between given range of rows (def 0 and end) returns row index of first match of given regex (or nil if not found)



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rbcurse/rlistbox.rb', line 124

def find_match regex, ix0=0, ix1=length()
  $log.debug " find_match got #{regex} #{ix0} #{ix1}"
  @last_regex = regex
  @search_start_ix = ix0
  @search_end_ix = ix1
  #@search_found_ix = nil
  @list.each_with_index do |row, ix|
    next if ix < ix0
    break if ix > ix1
    if !row.match(regex).nil?
      @search_found_ix = ix
      return ix 
    end
  end
  return nil
end

#find_nextObject

continues previous search



142
143
144
145
146
# File 'lib/rbcurse/rlistbox.rb', line 142

def find_next
  raise "No previous search" if @last_regex.nil?
  start = @search_found_ix && @search_found_ix+1 || 0
  return find_match @last_regex, start, @search_end_ix
end

#find_prev(regex = @last_regex, start = @search_found_ix) ⇒ Object

find backwards, list_data_model Using this to start a search or continue search



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rbcurse/rlistbox.rb', line 150

def find_prev regex=@last_regex, start = @search_found_ix 
  raise "No previous search" if regex.nil? # @last_regex.nil?
  $log.debug " find_prev #{@search_found_ix} : #{@current_index}"
  start -= 1 unless start == 0
  @last_regex = regex
  @search_start_ix = start
  start.downto(0) do |ix| 
    row = @list[ix]
    if !row.match(regex).nil?
      @search_found_ix = ix
      return ix 
    end
  end
  return nil
  #return find_match @last_regex, start, @search_end_ix
end

#include?(obj) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/rbcurse/rlistbox.rb', line 110

def include?(obj)
  return @list.include?(obj)
end

#index(obj) ⇒ Object

def each

@list.each { |item| yield item }

end not sure how to do this XXX removed on 2009-01-14 12:28 def <=>(other)

@list <=> other

end



64
65
66
# File 'lib/rbcurse/rlistbox.rb', line 64

def index obj
  @list.index(obj)
end

#insert(off0, *data) ⇒ Object



70
71
72
73
74
# File 'lib/rbcurse/rlistbox.rb', line 70

def insert off0, *data
  @list.insert off0, *data
  lde = ListDataEvent.new(off0, off0+data.length-1, self, :INTERVAL_ADDED)
  fire_handler :LIST_DATA_EVENT, lde
end

#lengthObject Also known as: size



67
# File 'lib/rbcurse/rlistbox.rb', line 67

def length ; @list.length; end

#on_enter_row(object) ⇒ Object



116
117
118
119
# File 'lib/rbcurse/rlistbox.rb', line 116

def on_enter_row object
  #$log.debug " XXX on_enter_row of list_data"
  fire_handler :ENTER_ROW, object
end

#remove_allObject



97
98
99
100
101
# File 'lib/rbcurse/rlistbox.rb', line 97

def remove_all
  lde = ListDataEvent.new(0, @list.size, self, :INTERVAL_REMOVED)
  @list = []
  fire_handler :LIST_DATA_EVENT, lde
end

#update(off0, data) ⇒ Object



80
81
82
83
84
# File 'lib/rbcurse/rlistbox.rb', line 80

def update off0, data
  @list[off0] = data
  lde = ListDataEvent.new(off0, off0, self, :CONTENTS_CHANGED)
  fire_handler :LIST_DATA_EVENT, lde
end

#valuesObject Also known as: to_array



113
114
115
# File 'lib/rbcurse/rlistbox.rb', line 113

def values
  @list.dup
end