Class: FlowTag::FlowTable
- Inherits:
-
Object
- Object
- FlowTag::FlowTable
- Defined in:
- lib/flowtag/flowtable.rb
Constant Summary collapse
- @@column_lengths =
[8,15,15,5,5,6,8,20]
- @@column_names =
['Time', 'Source IP', 'Dest. IP', 'SPort', 'DPort', 'Pkts', 'Bytes', 'Tags']
Instance Method Summary collapse
- #addflow(flow) ⇒ Object
- #addflows(flows) ⇒ Object
- #clear ⇒ Object
-
#initialize(parent, flows) ⇒ FlowTable
constructor
A new instance of FlowTable.
- #pack(*args) ⇒ Object
- #selected ⇒ Object
- #set_select_cb(callback) ⇒ Object
- #unpack ⇒ Object
- #update_flow(idx, flow) ⇒ Object
Constructor Details
#initialize(parent, flows) ⇒ FlowTable
Returns a new instance of FlowTable.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/flowtag/flowtable.rb', line 79 def initialize(parent, flows) @rows = 0 @tableframe = TkFrame.new(parent) header = '' (0..@@column_names.length-1).each do |i| header += @@column_names[i].center(@@column_lengths[i])+"|" end @table_header = TkLabel.new(@tableframe) { text header font TkFont.new('Monaco 12 bold') anchor 'sw' height 1 padx 0 pady 0 foreground 'lightblue' } @scrollbox = scrollbox = TkScrollbox.new(@tableframe) { setgrid 'yes' takefocus 'yes' width 59 font TkFont.new('Monaco 12') } @table_header.pack(:side=>'top',:fill=>'x') scrollbox.pack(:side=>'top',:fill=>'both',:expand=>1) scrollbox.bind('<ListboxSelect>', proc { |x| selected() }) addflows(flows) end |
Instance Method Details
#addflow(flow) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/flowtag/flowtable.rb', line 25 def addflow(flow) entry = Time.at(flow[FlowDB::ST]).strftime("%H:%M:%S")+" " (1..@@column_lengths.length-2).each do |i| entry += flow[i].to_s.rjust(@@column_lengths[i])+" " end entry += flow[FlowDB::TAGS].join(" ")[0,20] @scrollbox.insert 'end', entry end |
#addflows(flows) ⇒ Object
34 35 36 37 38 |
# File 'lib/flowtag/flowtable.rb', line 34 def addflows(flows) flows.each do |flow| addflow(flow) end end |
#clear ⇒ Object
51 52 53 |
# File 'lib/flowtag/flowtable.rb', line 51 def clear @scrollbox.clear end |
#pack(*args) ⇒ Object
55 56 57 |
# File 'lib/flowtag/flowtable.rb', line 55 def pack(*args) @tableframe.pack(*args) end |
#selected ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/flowtag/flowtable.rb', line 63 def selected items = [] indices = @scrollbox.curselection indices.each do |i| items.push(@scrollbox.get(i)) end if @select_cb @select_cb.call indices, items end @scrollbox.focus end |
#set_select_cb(callback) ⇒ Object
75 76 77 |
# File 'lib/flowtag/flowtable.rb', line 75 def set_select_cb(callback) @select_cb = callback end |
#unpack ⇒ Object
59 60 61 |
# File 'lib/flowtag/flowtable.rb', line 59 def unpack @tableframe.unpack end |
#update_flow(idx, flow) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/flowtag/flowtable.rb', line 40 def update_flow(idx, flow) entry = Time.at(flow[FlowDB::ST]).strftime("%H:%M:%S")+" " (1..@@column_lengths.length-2).each do |i| entry += flow[i].to_s.rjust(@@column_lengths[i])+" " end entry += flow[FlowDB::TAGS].join(" ")[0,20] @scrollbox.delete idx @scrollbox.insert idx, entry end |