Class: TrayApplication

Inherits:
Object
  • Object
show all
Includes:
Java
Defined in:
lib/deskshot/tray.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TrayApplication

Returns a new instance of TrayApplication.



9
10
11
12
13
# File 'lib/deskshot/tray.rb', line 9

def initialize(name)
  @menu_items = []
  @name = name
  puts "Application is started successfully!! Right click on Tray Icon"
end

Instance Attribute Details

Returns the value of attribute menu_items.



7
8
9
# File 'lib/deskshot/tray.rb', line 7

def menu_items
  @menu_items
end

Instance Method Details

#item(label, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/deskshot/tray.rb', line 15

def item(label, &block)
  item = java.awt.MenuItem.new(label)
  item.add_action_listener(block)

  @menu_items << item
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deskshot/tray.rb', line 22

def run
  popup = java.awt.PopupMenu.new
  @menu_items.each { |i| popup.add(i)}
  abs_path = File.dirname(__FILE__)
  image = java.awt.Toolkit::default_toolkit.get_image(abs_path + '/deskshot_icon.png')
  tray_icon = TrayIcon.new(image, @name, popup)
  tray_icon.image_auto_size = true

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