VanaClock 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.0.2 / 2007-09-08
2
+
3
+ * updated for VanaTime 2.0.0 and doubled the sleep time. in total this brought
4
+ the cpu usage down from an outrageous 25% to under 8% on my machine. note
5
+ that the wxWidgets version of the clock updates twice as often, uses less
6
+ memory, and barely touches the cpu. I need to investigate how it might be
7
+ possible to improve the jruby+swing version.
8
+
1
9
  == 1.0.1 / 2007-09-02
2
10
 
3
11
  * note to self: dont use = for versioning just in case you break something
data/Manifest CHANGED
@@ -1,8 +1,6 @@
1
1
  README
2
2
  Manifest
3
3
  LICENSE
4
- lib/view.rb
5
4
  lib/vana_clock.rb
6
- lib/control.rb
7
5
  CHANGELOG
8
6
  bin/VanaClock
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Vanaclock-1.0.1
2
+ # Gem::Specification for Vanaclock-1.0.2
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{VanaClock}
7
- s.version = "1.0.1"
8
- s.date = %q{2007-09-04}
7
+ s.version = "1.0.2"
8
+ s.date = %q{2007-09-08}
9
9
  s.summary = %q{VanaClock is a clock for Final Fantasy Online written in jruby and java swing. JRuby is required to run this clock.}
10
10
  s.email = %q{ttilley@gmail.com}
11
11
  s.homepage = %q{http://vanatime.rubyforge.org/}
@@ -14,15 +14,15 @@ Gem::Specification.new do |s|
14
14
  s.default_executable = %q{VanaClock}
15
15
  s.has_rdoc = true
16
16
  s.authors = ["Travis Tilley"]
17
- s.files = ["README", "Manifest", "LICENSE", "lib/view.rb", "lib/vana_clock.rb", "lib/control.rb", "CHANGELOG", "bin/VanaClock", "VanaClock.gemspec"]
17
+ s.files = ["README", "Manifest", "LICENSE", "lib/vana_clock.rb", "CHANGELOG", "bin/VanaClock", "VanaClock.gemspec"]
18
18
  s.executables = ["VanaClock"]
19
- s.add_dependency(%q<VanaTime>, [">= 1.2.1"])
19
+ s.add_dependency(%q<VanaTime>, [">= 2.0.0"])
20
20
  end
21
21
 
22
22
 
23
23
  # # Original Rakefile source (requires the Echoe gem):
24
24
  #
25
- # version = "1.0.1"
25
+ # version = "1.0.2"
26
26
  #
27
27
  # ENV['RUBY_FLAGS'] = ""
28
28
  #
@@ -38,7 +38,7 @@ end
38
38
  # p.url = "http://vanatime.rubyforge.org/"
39
39
  # p.author = 'Travis Tilley'
40
40
  # p.email = "ttilley@gmail.com"
41
- # p.dependencies = ["VanaTime >=1.2.1"]
41
+ # p.dependencies = ["VanaTime >=2.0.0"]
42
42
  # end
43
43
  #
44
44
  # rescue LoadError => boom
@@ -3,4 +3,4 @@
3
3
  raise 'VanaClock requires jruby' if ! RUBY_PLATFORM =~ /java/
4
4
 
5
5
  require 'vana_clock'
6
- VanaClock::Control.start
6
+ VanaClock::ClockWindow.new
@@ -1,11 +1,228 @@
1
- $:.unshift File.dirname(__FILE__)
1
+ raise 'VanaClock requires jruby' if ! RUBY_PLATFORM =~ /java/
2
+ require 'java'
2
3
 
3
4
  require 'rubygems'
4
- gem 'VanaTime', '>=1.2.1'
5
+ gem 'VanaTime', '>=2.0.0'
5
6
  require 'vana_time'
6
- include FFXI
7
+ include FFXI::Constants
7
8
 
8
- if RUBY_PLATFORM =~ /java/
9
- require 'view'
10
- require 'control'
9
+ module VanaClock
10
+ include_class 'javax.swing.JFrame'
11
+ include_class 'javax.swing.JPanel'
12
+ include_class 'javax.swing.JLabel'
13
+ include_class 'javax.swing.JTextField'
14
+ include_class 'javax.swing.BoxLayout'
15
+ include_class 'javax.swing.BorderFactory'
16
+ include_class 'javax.swing.border.LineBorder'
17
+ include_class 'javax.swing.border.TitledBorder'
18
+ include_class 'java.awt.Color'
19
+ include_class 'java.awt.Font'
20
+ include_class 'java.awt.Dimension'
21
+ include_class 'javax.swing.SwingConstants'
22
+ include_class 'javax.swing.AbstractAction'
23
+ include_class 'javax.swing.Timer'
24
+
25
+ class UpdateAction < AbstractAction
26
+ def clock=(clock)
27
+ @clock = clock
28
+ end
29
+ def actionPerformed(event)
30
+ @clock.time_manager.earth_time=(Time.now)
31
+ end
32
+ end
33
+
34
+ class ClockWindow
35
+ attr_reader :time_manager
36
+
37
+ def initialize
38
+ # window frame
39
+ clock_window = JFrame.new "VanaClock"
40
+ clock_window.setSize(366, 152)
41
+ clock_window.default_close_operation = JFrame::EXIT_ON_CLOSE
42
+ clock_window.getContentPane.setLayout(
43
+ BoxLayout.new(clock_window.getContentPane, BoxLayout::Y_AXIS))
44
+
45
+ # create containers
46
+ clock_container = JPanel.new
47
+ vana_time_container = JPanel.new
48
+ earth_time_container = JPanel.new
49
+ moon_phase_container = JPanel.new
50
+ next_phase_container = JPanel.new
51
+ optimal_phase_container = JPanel.new
52
+
53
+ # create labels
54
+ vana_time_label = JLabel.new "Vana'diel Time: "
55
+ earth_time_label = JLabel.new "Earth Time: "
56
+ moon_phase_label = JLabel.new "Moon Phase: "
57
+ next_phase_label = JLabel.new "Next Phase: "
58
+ optimal_phase_label = JLabel.new "Optimal Phase: "
59
+
60
+ # create text fields, all of which we need to be accessible via an
61
+ # instance variable so that we can set them later
62
+ @vana_day = JTextField.new
63
+ @vana_time = JTextField.new
64
+ @earth_time = JTextField.new
65
+ @moon_percent = JTextField.new
66
+ @phase_name = JTextField.new
67
+ @next_phase_countdown = JTextField.new
68
+ @next_phase_name = JTextField.new
69
+ @optimal_phase_countdown = JTextField.new
70
+ @optimal_phase_name = JTextField.new
71
+
72
+ # clock container panel border
73
+ border_color = Color.new(0, 0, 204)
74
+ line_border = LineBorder.new(border_color, 1, true)
75
+ border_title_justification = TitledBorder::CENTER
76
+ border_title_position = TitledBorder::DEFAULT_POSITION
77
+ border_title_font = Font.new("Lucida Grande", 1, 12)
78
+ clock_border = BorderFactory.createTitledBorder(line_border, "clock",
79
+ border_title_justification, border_title_position, border_title_font,
80
+ border_color)
81
+
82
+ # set up the clock container panel
83
+ clock_container.setBorder clock_border
84
+ clock_container.setMinimumSize Dimension.new(366, 152)
85
+ clock_container.setMaximumSize Dimension.new(366, 152)
86
+ clock_container.setPreferredSize Dimension.new(366, 152)
87
+ clock_container.setLayout BoxLayout.new(clock_container,
88
+ BoxLayout::Y_AXIS)
89
+
90
+ # set up the content panels
91
+ [vana_time_container, earth_time_container, moon_phase_container,
92
+ next_phase_container, optimal_phase_container].each do |cont|
93
+ cont.setMinimumSize Dimension.new(366, 24)
94
+ cont.setMaximumSize Dimension.new(32767, 24)
95
+ cont.setPreferredSize Dimension.new(366, 24)
96
+ cont.setLayout BoxLayout.new(cont, BoxLayout::X_AXIS)
97
+ end
98
+
99
+ # set up the labels
100
+ [vana_time_label, earth_time_label, moon_phase_label, next_phase_label,
101
+ optimal_phase_label].each do |label|
102
+ label.setHorizontalAlignment(SwingConstants::LEFT)
103
+ label.setMaximumSize Dimension.new(110, 16)
104
+ label.setMinimumSize Dimension.new(110, 16)
105
+ label.setPreferredSize Dimension.new(110, 16)
106
+ end
107
+
108
+ # set up all the text fields
109
+ @vana_day.setMaximumSize Dimension.new(94, 22)
110
+ @vana_day.setMinimumSize Dimension.new(94, 22)
111
+ @vana_day.setPreferredSize Dimension.new(94, 22)
112
+ @vana_day.setEditable false
113
+ @vana_time.setMaximumSize Dimension.new(32767, 22)
114
+ @vana_time.setPreferredSize Dimension.new(150, 22)
115
+ @vana_time.setEditable false
116
+ @earth_time.setMaximumSize Dimension.new(32767, 22)
117
+ @earth_time.setEditable false
118
+ @moon_percent.setHorizontalAlignment(JTextField::RIGHT)
119
+ @moon_percent.setMinimumSize Dimension.new(42, 22)
120
+ @moon_percent.setMaximumSize Dimension.new(42, 22)
121
+ @moon_percent.setPreferredSize Dimension.new(42, 22)
122
+ @moon_percent.setEditable false
123
+ @phase_name.setMaximumSize Dimension.new(32767, 22)
124
+ @phase_name.setPreferredSize Dimension.new(202, 22)
125
+ @phase_name.setEditable false
126
+ @next_phase_countdown.setHorizontalAlignment(JTextField::RIGHT)
127
+ @next_phase_countdown.setMaximumSize Dimension.new(86, 22)
128
+ @next_phase_countdown.setMinimumSize Dimension.new(86, 22)
129
+ @next_phase_countdown.setPreferredSize Dimension.new(86, 22)
130
+ @next_phase_countdown.setEditable false
131
+ @next_phase_name.setMaximumSize Dimension.new(32767, 22)
132
+ @next_phase_name.setPreferredSize Dimension.new(158, 22)
133
+ @next_phase_name.setEditable false
134
+ @optimal_phase_countdown.setHorizontalAlignment(JTextField::RIGHT)
135
+ @optimal_phase_countdown.setMaximumSize Dimension.new(86, 22)
136
+ @optimal_phase_countdown.setMinimumSize Dimension.new(86, 22)
137
+ @optimal_phase_countdown.setPreferredSize Dimension.new(86, 22)
138
+ @optimal_phase_countdown.setEditable false
139
+ @optimal_phase_name.setMaximumSize Dimension.new(32767, 22)
140
+ @optimal_phase_name.setPreferredSize Dimension.new(158, 22)
141
+ @optimal_phase_name.setEditable false
142
+
143
+ # attach everything
144
+ vana_time_container.add vana_time_label
145
+ vana_time_container.add @vana_day
146
+ vana_time_container.add @vana_time
147
+ clock_container.add vana_time_container
148
+ earth_time_container.add earth_time_label
149
+ earth_time_container.add @earth_time
150
+ clock_container.add earth_time_container
151
+ moon_phase_container.add moon_phase_label
152
+ moon_phase_container.add @moon_percent
153
+ moon_phase_container.add @phase_name
154
+ clock_container.add moon_phase_container
155
+ next_phase_container.add next_phase_label
156
+ next_phase_container.add @next_phase_countdown
157
+ next_phase_container.add @next_phase_name
158
+ clock_container.add next_phase_container
159
+ optimal_phase_container.add optimal_phase_label
160
+ optimal_phase_container.add @optimal_phase_countdown
161
+ optimal_phase_container.add @optimal_phase_name
162
+ clock_container.add optimal_phase_container
163
+ clock_window.getContentPane.add clock_container
164
+
165
+ # create the procs that update UI elements
166
+ on_second = lambda do |time|
167
+ @vana_time.setText time.to_s
168
+ @earth_time.setText time.earth_time.to_s
169
+ end
170
+ on_day = lambda do |day|
171
+ @vana_day.setText day.to_s
172
+ end
173
+ on_moon_percent = lambda do |moon|
174
+ @moon_percent.setText moon.percent
175
+ end
176
+ on_moon_phase = lambda do |moon|
177
+ @phase_name.setText moon.phase
178
+ @next_phase_name.setText moon.next_phase
179
+ end
180
+ on_optimal_phase = lambda do |moon|
181
+ @optimal_phase_name.setText moon.optimal_phase
182
+ end
183
+ on_phase_count = lambda do |countdown|
184
+ @next_phase_countdown.setText countdown.to_next
185
+ end
186
+ on_optimal_count = lambda do |countdown|
187
+ @optimal_phase_countdown.setText countdown.to_optimal
188
+ end
189
+
190
+ # create time, day, and moon objects
191
+ vt = FFXI::VanaTime.now
192
+ vd = FFXI::VanaDay.new(vt)
193
+ vm = FFXI::VanaMoon.new(vt.earth_time)
194
+
195
+ # draw the UI
196
+ on_second.call vt
197
+ on_day.call vd
198
+ on_moon_percent.call vm
199
+ on_moon_phase.call vm
200
+ on_optimal_phase.call vm
201
+
202
+ # manage the above
203
+ @time_manager = FFXI::TimeManager.new
204
+ @time_manager.manage(vt, vd, vm)
205
+
206
+ # register callbacks
207
+ @time_manager.callback_proc(MS_SECOND, on_second)
208
+ @time_manager.callback_proc("day", on_day)
209
+ @time_manager.callback_proc("moon_percent", on_moon_percent)
210
+ @time_manager.callback_proc("moon_phase", on_moon_phase)
211
+ @time_manager.callback_proc("next_optimal_phase", on_optimal_phase)
212
+ @time_manager.callback_proc("next_phase_countdown", on_phase_count)
213
+ @time_manager.callback_proc("optimal_phase_countdown", on_optimal_count)
214
+
215
+ # create AbstractAction
216
+ update_action = UpdateAction.new
217
+ update_action.clock = self
218
+
219
+ # timer bits
220
+ update_timer = Timer.new(80, update_action)
221
+ update_timer.start
222
+
223
+ # pack and set visible
224
+ clock_window.pack
225
+ clock_window.visible = true
226
+ end
227
+ end
11
228
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: VanaClock
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2007-09-04 00:00:00 -04:00
6
+ version: 1.0.2
7
+ date: 2007-09-08 00:00:00 -04:00
8
8
  summary: VanaClock is a clock for Final Fantasy Online written in jruby and java swing. JRuby is required to run this clock.
9
9
  require_paths:
10
10
  - lib
@@ -32,9 +32,7 @@ files:
32
32
  - README
33
33
  - Manifest
34
34
  - LICENSE
35
- - lib/view.rb
36
35
  - lib/vana_clock.rb
37
- - lib/control.rb
38
36
  - CHANGELOG
39
37
  - bin/VanaClock
40
38
  - VanaClock.gemspec
@@ -58,5 +56,5 @@ dependencies:
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
- version: 1.2.1
59
+ version: 2.0.0
62
60
  version:
@@ -1,18 +0,0 @@
1
- module VanaClock
2
- module Control
3
- def Control.start
4
- clock = View::ClockWindow.new
5
- time = VanaTime.now
6
-
7
- updater = Thread.new {
8
- loop do
9
- clock.update(time)
10
- sleep 0.038
11
- time.earth_time=(Time.now)
12
- end
13
- }
14
-
15
- updater.join
16
- end
17
- end
18
- end
@@ -1,201 +0,0 @@
1
- module VanaClock
2
- module View
3
- import 'javax.swing.JFrame'
4
- import 'javax.swing.JPanel'
5
- import 'javax.swing.JLabel'
6
- import 'javax.swing.JTextField'
7
- import 'javax.swing.BoxLayout'
8
- import 'javax.swing.BorderFactory'
9
- import 'javax.swing.border.LineBorder'
10
- import 'javax.swing.border.TitledBorder'
11
- import 'java.awt.Color'
12
- import 'java.awt.Font'
13
- import 'java.awt.Dimension'
14
- import 'javax.swing.SwingConstants'
15
-
16
- class ClockWindow
17
- def initialize
18
- # window frame
19
- clock_window = JFrame.new "VanaClock"
20
- clock_window.setSize(366, 152)
21
- clock_window.default_close_operation = JFrame::EXIT_ON_CLOSE
22
- clock_window.getContentPane.setLayout(
23
- BoxLayout.new(clock_window.getContentPane, BoxLayout::Y_AXIS))
24
-
25
- # create containers
26
- clock_container = JPanel.new
27
- vana_time_container = JPanel.new
28
- earth_time_container = JPanel.new
29
- moon_phase_container = JPanel.new
30
- next_phase_container = JPanel.new
31
- optimal_phase_container = JPanel.new
32
-
33
- # create labels
34
- vana_time_label = JLabel.new "Vana'diel Time: "
35
- earth_time_label = JLabel.new "Earth Time: "
36
- moon_phase_label = JLabel.new "Moon Phase: "
37
- next_phase_label = JLabel.new "Next Phase: "
38
- optimal_phase_label = JLabel.new "Optimal Phase: "
39
-
40
- # create text fields, all of which we need to be accessible via an
41
- # instance variable so that we can set them later
42
- @vana_day = JTextField.new
43
- @vana_time = JTextField.new
44
- @earth_time = JTextField.new
45
- @moon_percent = JTextField.new
46
- @phase_name = JTextField.new
47
- @next_phase_countdown = JTextField.new
48
- @next_phase_name = JTextField.new
49
- @optimal_phase_countdown = JTextField.new
50
- @optimal_phase_name = JTextField.new
51
-
52
- # clock container panel border
53
- border_color = Color.new(0, 0, 204)
54
- line_border = LineBorder.new(border_color, 1, true)
55
- border_title_justification = TitledBorder::CENTER
56
- border_title_position = TitledBorder::DEFAULT_POSITION
57
- border_title_font = Font.new("Lucida Grande", 1, 12)
58
- clock_border = BorderFactory.createTitledBorder(line_border, "clock",
59
- border_title_justification, border_title_position, border_title_font,
60
- border_color)
61
-
62
- # set up the clock container panel
63
- clock_container.setBorder clock_border
64
- clock_container.setMinimumSize Dimension.new(366, 152)
65
- clock_container.setMaximumSize Dimension.new(366, 152)
66
- clock_container.setPreferredSize Dimension.new(366, 152)
67
- clock_container.setLayout BoxLayout.new(clock_container,
68
- BoxLayout::Y_AXIS)
69
-
70
- # set up the content panels
71
- [vana_time_container, earth_time_container, moon_phase_container,
72
- next_phase_container, optimal_phase_container].each do |cont|
73
- cont.setMinimumSize Dimension.new(366, 24)
74
- cont.setMaximumSize Dimension.new(32767, 24)
75
- cont.setPreferredSize Dimension.new(366, 24)
76
- cont.setLayout BoxLayout.new(cont, BoxLayout::X_AXIS)
77
- end
78
-
79
- # set up the labels
80
- [vana_time_label, earth_time_label, moon_phase_label, next_phase_label,
81
- optimal_phase_label].each do |label|
82
- label.setHorizontalAlignment(SwingConstants::LEFT)
83
- label.setMaximumSize Dimension.new(110, 16)
84
- label.setMinimumSize Dimension.new(110, 16)
85
- label.setPreferredSize Dimension.new(110, 16)
86
- end
87
-
88
- # set up all the text fields
89
- @vana_day.setMaximumSize Dimension.new(94, 22)
90
- @vana_day.setMinimumSize Dimension.new(94, 22)
91
- @vana_day.setPreferredSize Dimension.new(94, 22)
92
- @vana_day.setEditable false
93
- @vana_time.setMaximumSize Dimension.new(32767, 22)
94
- @vana_time.setPreferredSize Dimension.new(150, 22)
95
- @vana_time.setEditable false
96
- @earth_time.setMaximumSize Dimension.new(32767, 22)
97
- @earth_time.setEditable false
98
- @moon_percent.setHorizontalAlignment(JTextField::RIGHT)
99
- @moon_percent.setMinimumSize Dimension.new(42, 22)
100
- @moon_percent.setMaximumSize Dimension.new(42, 22)
101
- @moon_percent.setPreferredSize Dimension.new(42, 22)
102
- @moon_percent.setEditable false
103
- @phase_name.setMaximumSize Dimension.new(32767, 22)
104
- @phase_name.setPreferredSize Dimension.new(202, 22)
105
- @phase_name.setEditable false
106
- @next_phase_countdown.setHorizontalAlignment(JTextField::RIGHT)
107
- @next_phase_countdown.setMaximumSize Dimension.new(86, 22)
108
- @next_phase_countdown.setMinimumSize Dimension.new(86, 22)
109
- @next_phase_countdown.setPreferredSize Dimension.new(86, 22)
110
- @next_phase_countdown.setEditable false
111
- @next_phase_name.setMaximumSize Dimension.new(32767, 22)
112
- @next_phase_name.setPreferredSize Dimension.new(158, 22)
113
- @next_phase_name.setEditable false
114
- @optimal_phase_countdown.setHorizontalAlignment(JTextField::RIGHT)
115
- @optimal_phase_countdown.setMaximumSize Dimension.new(86, 22)
116
- @optimal_phase_countdown.setMinimumSize Dimension.new(86, 22)
117
- @optimal_phase_countdown.setPreferredSize Dimension.new(86, 22)
118
- @optimal_phase_countdown.setEditable false
119
- @optimal_phase_name.setMaximumSize Dimension.new(32767, 22)
120
- @optimal_phase_name.setPreferredSize Dimension.new(158, 22)
121
- @optimal_phase_name.setEditable false
122
-
123
- # attach everything
124
- vana_time_container.add vana_time_label
125
- vana_time_container.add @vana_day
126
- vana_time_container.add @vana_time
127
- clock_container.add vana_time_container
128
- earth_time_container.add earth_time_label
129
- earth_time_container.add @earth_time
130
- clock_container.add earth_time_container
131
- moon_phase_container.add moon_phase_label
132
- moon_phase_container.add @moon_percent
133
- moon_phase_container.add @phase_name
134
- clock_container.add moon_phase_container
135
- next_phase_container.add next_phase_label
136
- next_phase_container.add @next_phase_countdown
137
- next_phase_container.add @next_phase_name
138
- clock_container.add next_phase_container
139
- optimal_phase_container.add optimal_phase_label
140
- optimal_phase_container.add @optimal_phase_countdown
141
- optimal_phase_container.add @optimal_phase_name
142
- clock_container.add optimal_phase_container
143
- clock_window.getContentPane.add clock_container
144
-
145
- # pack and set visible
146
- clock_window.pack
147
- clock_window.visible = true
148
- end
149
-
150
- def update(vt)
151
- raise "I can only update with a VanaTime" if ! vt.is_a? FFXI::VanaTime
152
-
153
- self.vana_day = vt.day.to_s
154
- self.vana_time = vt.to_s
155
- self.earth_time = vt.earth_time.to_s
156
- self.moon_percent = vt.moon.percent
157
- self.phase_name = vt.moon.phase
158
- self.next_phase_countdown = vt.moon.to_next
159
- self.next_phase_name = vt.moon.next_phase
160
- self.optimal_phase_countdown = vt.moon.to_optimal
161
- self.optimal_phase_name = vt.moon.optimal_phase
162
- end
163
-
164
- def earth_time=(text)
165
- @earth_time.setText text
166
- end
167
-
168
- def moon_percent=(text)
169
- @moon_percent.setText text
170
- end
171
-
172
- def next_phase_countdown=(text)
173
- @next_phase_countdown.setText text
174
- end
175
-
176
- def next_phase_name=(text)
177
- @next_phase_name.setText text
178
- end
179
-
180
- def optimal_phase_countdown=(text)
181
- @optimal_phase_countdown.setText text
182
- end
183
-
184
- def optimal_phase_name=(text)
185
- @optimal_phase_name.setText text
186
- end
187
-
188
- def phase_name=(text)
189
- @phase_name.setText text
190
- end
191
-
192
- def vana_day=(text)
193
- @vana_day.setText text
194
- end
195
-
196
- def vana_time=(text)
197
- @vana_time.setText text
198
- end
199
- end
200
- end
201
- end