Class: Watobo::Gui::HexViewer
- Inherits:
-
FXHorizontalFrame
- Object
- FXHorizontalFrame
- Watobo::Gui::HexViewer
- Defined in:
- lib/watobo/gui/hex_viewer.rb
Instance Method Summary collapse
-
#initialize(owner) ⇒ HexViewer
constructor
A new instance of HexViewer.
- #normalizeText(text) ⇒ Object
- #setText(tobject) ⇒ Object
Constructor Details
#initialize(owner) ⇒ HexViewer
Returns a new instance of HexViewer.
95 96 97 98 99 100 101 |
# File 'lib/watobo/gui/hex_viewer.rb', line 95 def initialize(owner) super(owner, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0) sunken = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0) @hexTable = FXTable.new(sunken, :opts => FRAME_SUNKEN|TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y|TABLE_READONLY|LAYOUT_SIDE_TOP, :padding => 2) end |
Instance Method Details
#normalizeText(text) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/watobo/gui/hex_viewer.rb', line 26 def normalizeText(text) dummy = [] begin text.headers.each do |h| dummy.push h.strip.unpack("C*").pack("C*") + "\r\n" end dummy.push "\r\n" dummy.push text.body.unpack("C*").pack("C*") dummy = dummy.join rescue => bang dummy = text end return dummy end |
#setText(tobject) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/watobo/gui/hex_viewer.rb', line 41 def setText(tobject) raw_text = tobject if tobject.respond_to? :has_body? raw_text = "" raw_text << tobject.body.to_s unless tobject.body.nil? end initTable() if raw_text and not raw_text.empty? then raw_text = normalizeText(raw_text) pos = 1 col = 0 row = @hexTable.getNumRows @hexTable.appendRows(1) @hexTable.rowHeader.setItemJustify(row, FXTableItem::LEFT) @hexTable.setRowText(row, "%0.4X" % row.to_s) while pos <= raw_text.length chunk = raw_text[pos-1].unpack("H2")[0] @hexTable.setItemText(row, col, chunk) @hexTable.getItem(row, col).justify = FXTableItem::LEFT if pos % 16 == 0 then chunk = raw_text[row*16..pos-1] # puts chunk @hexTable.setItemText(row, 16, chunk.gsub(/[^[:print:]]/,'.')) if !chunk.nil? @hexTable.getItem(row, 16).justify = FXTableItem::LEFT row = @hexTable.getNumRows @hexTable.appendRows(1) # puts "=#{pos}/#{row}" @hexTable.rowHeader.setItemJustify(row, FXTableItem::LEFT) @hexTable.setRowText(row, "%0.4X" % row.to_s) col = -1 end pos += 1 col += 1 end chunk = raw_text[row*16..pos-1] @hexTable.setItemText(row, 16, chunk.gsub(/[^[:print:]]/,'.')) if !chunk.nil? @hexTable.getItem(row, 16).justify = FXTableItem::LEFT end end |