Class: SmarterMeter::Interfaces::LogWindow
- Inherits:
-
Object
- Object
- SmarterMeter::Interfaces::LogWindow
- Defined in:
- lib/smartermeter/interfaces/swing.rb
Constant Summary collapse
- LogFile =
File.("~/.smartermeter.log")
Instance Method Summary collapse
-
#initialize(&block) ⇒ LogWindow
constructor
A new instance of LogWindow.
Constructor Details
#initialize(&block) ⇒ LogWindow
Returns a new instance of LogWindow.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/smartermeter/interfaces/swing.rb', line 111 def initialize(&block) UIManager.set_look_and_feel(UIManager.get_system_look_and_feel_class_name) layout = " [ log_label ] [ (600,200)*log_area ] [ >buttons ] " log = File.read(LogFile) @ui = Profligacy::Swing::LEL.new(JFrame, layout) do |c,i| c.log_label = JLabel.new "Log:" textarea = JTextArea.new(log) textarea.set_caret_position(textarea.get_text().length()) c.log_area = JScrollPane.new(textarea) c. = Profligacy::Swing::LEL.new(JPanel, "[clear|close]") do |cc,ii| cc.clear = JButton.new "Clear" ii.clear = { :action => proc do |t, e| File.open(LogFile, "w") { |f| f.write("") } textarea.text = "" end } cc.close = JButton.new "Close" ii.close = { :action => proc do |t, e| @frame.dispose yield end } end.build :auto_create_container_gaps => false end @frame = @ui.build(:args => "SmarterMeter Log") @frame.set_location_relative_to(nil) @frame.default_close_operation = JFrame::DISPOSE_ON_CLOSE end |