Class: Glimmer::Timer

Inherits:
Object
  • Object
show all
Includes:
UI::CustomShell
Defined in:
lib/views/glimmer/timer.rb

Constant Summary collapse

APP_ROOT =
File.expand_path('../../../..', __FILE__)
VERSION =
File.read(File.join(APP_ROOT, 'VERSION'))
LICENSE =
File.read(File.join(APP_ROOT, 'LICENSE.txt'))
FILE_SOUND_ALARM =
File.join(APP_ROOT, 'sounds', 'alarm1.wav')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countdownObject

Add options like the following to configure CustomShell by outside consumers

options :title, :background_color option :width, default: 320 option :height, default: 240



18
19
20
# File 'lib/views/glimmer/timer.rb', line 18

def countdown
  @countdown
end

#minObject

Add options like the following to configure CustomShell by outside consumers

options :title, :background_color option :width, default: 320 option :height, default: 240



18
19
20
# File 'lib/views/glimmer/timer.rb', line 18

def min
  @min
end

#secObject

Add options like the following to configure CustomShell by outside consumers

options :title, :background_color option :width, default: 320 option :height, default: 240



18
19
20
# File 'lib/views/glimmer/timer.rb', line 18

def sec
  @sec
end

Instance Method Details

#display_about_dialogObject



148
149
150
151
152
153
# File 'lib/views/glimmer/timer.rb', line 148

def display_about_dialog
  message_box(body_root) {
    text 'About'
    message "Glimmer - Timer #{VERSION}\n\n#{LICENSE}"
  }.open
end

#play_countdown_done_soundObject



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/views/glimmer/timer.rb', line 165

def play_countdown_done_sound
  begin
    if FILE_SOUND_ALARM.start_with?('uri:classloader')
      jar_file_path = FILE_SOUND_ALARM
      file_path = jar_file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac
      object = java.lang.Object.new
      file_input_stream = object.java_class.resource_as_stream(file_path)          
      file_or_stream = java.io.BufferedInputStream.new(file_input_stream)      
    else
      file_or_stream = java.io.File.new(FILE_SOUND_ALARM)
    end
    audio_stream = AudioSystem.get_audio_input_stream(file_or_stream)
    clip = AudioSystem.clip
    clip.open(audio_stream)
    clip.start
  rescue => e
    pd e
    puts e.full_message
  end
end

#start_countdownObject



155
156
157
158
# File 'lib/views/glimmer/timer.rb', line 155

def start_countdown
  self.countdown = true
  @stop_button.swt_widget.set_focus    
end

#stop_countdownObject



160
161
162
163
# File 'lib/views/glimmer/timer.rb', line 160

def stop_countdown
  self.countdown = false
  @min_spinner.swt_widget.set_focus
end