Class: SmarterMeter::Interfaces::Swing

Inherits:
Object
  • Object
show all
Defined in:
lib/smartermeter/interfaces/swing.rb

Constant Summary collapse

LogFile =
File.expand_path("~/.smartermeter.log")

Instance Method Summary collapse

Constructor Details

#initializeSwing

Returns a new instance of Swing.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/smartermeter/interfaces/swing.rb', line 13

def initialize
  # TODO: Implement a way to update the settings
  #settings_item = MenuItem.new("Settings")
  #settings_item.add_action_listener { SettingsWindow.new do |config|
  #    puts config.inspect
  #  end
  #}

  update_item = MenuItem.new("Check for Updates")
  update_item.add_action_listener do
    desktop = Desktop.getDesktop();
    uri = Java::JavaNet::URI.new("http://matt.colyer.name/projects/smartermeter/?v=#{SmarterMeter::VERSION}")
    desktop.browse(uri)
  end

  log_item = MenuItem.new("View Log")
  log_item.add_action_listener do
    LogWindow.new {}
  end

  exit_item = MenuItem.new("Exit")
  exit_item.add_action_listener {java.lang.System::exit(0)}


  popup = PopupMenu.new
  popup.add(update_item)
  popup.add(log_item)
  popup.add(MenuItem.new("-"))
  popup.add(exit_item)

  image = Toolkit::default_toolkit.get_image("icons/smartermeter-16x16.png")
  tray_icon = TrayIcon.new(image, "SmarterMeter", popup)
  tray_icon.image_auto_size = true

  tray = SystemTray::system_tray
  tray.add(tray_icon)
end

Instance Method Details

#logObject

Returns a logger like interface to log errors and warnings to.



52
53
54
55
56
57
# File 'lib/smartermeter/interfaces/swing.rb', line 52

def log
  return @logger if @logger
  @logger = Logger.new(LogFile)
  @logger.level = Logger::INFO
  @logger
end

#setupObject

Public: Called when ~/.smartermeter needs to be configured. Yields a hash containing the configuration specified by the user.

Returns nothing.



63
64
65
66
67
# File 'lib/smartermeter/interfaces/swing.rb', line 63

def setup
  Wizard.new do |config|
    yield config
  end
end