1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package tsukuba_bunko.peko; |
20 |
|
|
21 |
|
import java.awt.event.ActionListener; |
22 |
|
import java.awt.event.MouseEvent; |
23 |
|
import java.awt.event.MouseListener; |
24 |
|
import java.awt.event.KeyEvent; |
25 |
|
import java.awt.event.KeyListener; |
26 |
|
|
27 |
|
import java.text.MessageFormat; |
28 |
|
|
29 |
|
import java.util.Timer; |
30 |
|
import java.util.TimerTask; |
31 |
|
|
32 |
|
import javax.swing.ButtonGroup; |
33 |
|
import javax.swing.ImageIcon; |
34 |
|
import javax.swing.JButton; |
35 |
|
import javax.swing.JCheckBoxMenuItem; |
36 |
|
import javax.swing.JDialog; |
37 |
|
import javax.swing.JFrame; |
38 |
|
import javax.swing.JMenu; |
39 |
|
import javax.swing.JMenuBar; |
40 |
|
import javax.swing.JMenuItem; |
41 |
|
import javax.swing.JOptionPane; |
42 |
|
import javax.swing.JRadioButtonMenuItem; |
43 |
|
import javax.swing.KeyStroke; |
44 |
|
|
45 |
|
import tsukuba_bunko.util.GenericListener; |
46 |
|
|
47 |
|
import tsukuba_bunko.peko.canvas.CanvasManager; |
48 |
|
|
49 |
|
import tsukuba_bunko.peko.resource.ResourceManager; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
0 |
public class ActionControler implements KeyListener, MouseListener { |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
public static final long SM_DEFAULT = -1; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
public static final long SM_NONSTOP = 0; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public static final int PM_SKIP = 1; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
public static final int PM_NORMAL = 0; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
public static final int PM_AUTOMATIC = 2; |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
0 |
private Object _lock = this; |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
0 |
private boolean _activity = false; |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0 |
private int _playMode = -1; |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
0 |
private JMenuItem[] _buttons = new JMenuItem[3]; |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
0 |
private JMenuItem _usingEffectMenu = null; |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
0 |
private JMenuItem _saveMenu = null; |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
0 |
private JMenuItem _loadMenu = null; |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
0 |
private JMenuItem _returnTileMenu = null; |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
0 |
private JMenuItem _readAgainMenu = null; |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
0 |
private Timer _timer = new Timer( true ); |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
0 |
private TimerTask _lastTask = null; |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
0 |
private TextHistoryControler _readAgainControler = null; |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
0 |
private int _lastKeyCode = -1; |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
0 |
private boolean _waitingActivate = false; |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
0 |
private boolean _hiddenText = false; |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
public ActionControler() |
166 |
|
{ |
167 |
0 |
super(); |
168 |
0 |
prepareMenuBar(); |
169 |
0 |
setPlayModeToNormal(); |
170 |
0 |
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
public void setActive( boolean activity ) |
177 |
|
{ |
178 |
0 |
_activity = activity; |
179 |
0 |
if( !activity ) { |
180 |
0 |
_lastKeyCode = -1; |
181 |
0 |
} |
182 |
0 |
else if( _playMode != ActionControler.PM_NORMAL ) { |
183 |
0 |
if( _waitingActivate ) { |
184 |
0 |
synchronized( _lock ) { |
185 |
0 |
if( _waitingActivate ) { |
186 |
0 |
_lock.notify(); |
187 |
|
} |
188 |
0 |
} |
189 |
|
} |
190 |
|
} |
191 |
0 |
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
public boolean isActive() |
198 |
|
{ |
199 |
0 |
return _activity && !PekoSystem.getInstance().getCanvasManager().isShowingSelect(); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
public synchronized void setSaveEnabled( boolean enabled ) |
207 |
|
{ |
208 |
0 |
_saveMenu.setEnabled( enabled ); |
209 |
0 |
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
public int getPlayMode() |
215 |
|
{ |
216 |
0 |
return _playMode; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
protected void setPlayMode( int playMode ) |
224 |
|
{ |
225 |
0 |
_playMode = playMode; |
226 |
0 |
_buttons[playMode].setSelected( true ); |
227 |
0 |
if( playMode == ActionControler.PM_SKIP ) { |
228 |
0 |
_readAgainMenu.setEnabled( false ); |
229 |
0 |
} |
230 |
0 |
else if( !_readAgainMenu.isEnabled() ) { |
231 |
0 |
_readAgainMenu.setEnabled( true ); |
232 |
|
} |
233 |
0 |
PekoSystem.getInstance().getCanvasManager().getStageCanvas().setUsingEffect( !_usingEffectMenu.isSelected() && (playMode != ActionControler.PM_SKIP) ); |
234 |
0 |
if( (_playMode != ActionControler.PM_NORMAL) && !PekoSystem.getInstance().getCanvasManager().isShowingSelect() ) { |
235 |
0 |
start(); |
236 |
|
} |
237 |
0 |
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
public void setPlayModeToSKip() |
243 |
|
{ |
244 |
0 |
setPlayMode( ActionControler.PM_SKIP ); |
245 |
0 |
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
public void setPlayModeToNormal() |
251 |
|
{ |
252 |
0 |
setPlayMode( ActionControler.PM_NORMAL ); |
253 |
0 |
} |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
public void setPlayModeToAutomatic() |
259 |
|
{ |
260 |
0 |
setPlayMode( ActionControler.PM_AUTOMATIC ); |
261 |
0 |
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
public void changeUsingEffect() |
267 |
|
{ |
268 |
0 |
PekoSystem.getInstance().getCanvasManager().getStageCanvas().setUsingEffect( !_usingEffectMenu.isSelected() && (_playMode != ActionControler.PM_SKIP) ); |
269 |
0 |
} |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
public void showReadAgain() |
275 |
|
{ |
276 |
0 |
setActive( false ); |
277 |
0 |
_saveMenu.setEnabled( false ); |
278 |
0 |
_loadMenu.setEnabled( false ); |
279 |
0 |
_returnTileMenu.setEnabled( false ); |
280 |
0 |
_readAgainMenu.setEnabled( false ); |
281 |
0 |
if( _readAgainControler == null ) { |
282 |
0 |
_readAgainControler = new TextHistoryControler(); |
283 |
0 |
_readAgainControler.setLocationRelativeTo( PekoSystem.getInstance().getMainWindow() ); |
284 |
|
} |
285 |
0 |
_readAgainControler.setVisible( true ); |
286 |
0 |
setActive( true ); |
287 |
0 |
_saveMenu.setEnabled( true ); |
288 |
0 |
_loadMenu.setEnabled( true ); |
289 |
0 |
_returnTileMenu.setEnabled( true ); |
290 |
0 |
_readAgainMenu.setEnabled( true ); |
291 |
0 |
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
public void showLoadDialog() |
297 |
|
{ |
298 |
0 |
setActive( false ); |
299 |
0 |
_saveMenu.setEnabled( false ); |
300 |
0 |
_loadMenu.setEnabled( false ); |
301 |
0 |
_returnTileMenu.setEnabled( false ); |
302 |
0 |
_readAgainMenu.setEnabled( false ); |
303 |
0 |
PekoSystem system = PekoSystem.getInstance(); |
304 |
0 |
if( !system.load() ) { |
305 |
0 |
setActive( true ); |
306 |
|
} |
307 |
0 |
_saveMenu.setEnabled( true ); |
308 |
0 |
_loadMenu.setEnabled( true ); |
309 |
0 |
_returnTileMenu.setEnabled( true ); |
310 |
0 |
_readAgainMenu.setEnabled( true ); |
311 |
0 |
} |
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
public synchronized void showSaveDialog() |
317 |
|
{ |
318 |
0 |
PekoSystem system = PekoSystem.getInstance(); |
319 |
0 |
setActive( false ); |
320 |
0 |
_saveMenu.setEnabled( false ); |
321 |
0 |
_loadMenu.setEnabled( false ); |
322 |
0 |
_returnTileMenu.setEnabled( false ); |
323 |
0 |
_readAgainMenu.setEnabled( false ); |
324 |
0 |
system.save(); |
325 |
0 |
_saveMenu.setEnabled( true ); |
326 |
0 |
_loadMenu.setEnabled( true ); |
327 |
0 |
_returnTileMenu.setEnabled( true ); |
328 |
0 |
_readAgainMenu.setEnabled( true ); |
329 |
0 |
setActive( true ); |
330 |
0 |
} |
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
public void returnTitle() |
336 |
|
{ |
337 |
0 |
returnTitle( false ); |
338 |
0 |
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
public void returnTitle( boolean silence ) |
344 |
|
{ |
345 |
0 |
setActive( false ); |
346 |
0 |
setPlayMode( ActionControler.PM_NORMAL ); |
347 |
0 |
_saveMenu.setEnabled( false ); |
348 |
0 |
_loadMenu.setEnabled( false ); |
349 |
0 |
_returnTileMenu.setEnabled( false ); |
350 |
0 |
_readAgainMenu.setEnabled( false ); |
351 |
0 |
if( silence ) { |
352 |
0 |
PekoSystem.getInstance().showTitle(); |
353 |
0 |
} |
354 |
|
else { |
355 |
0 |
ResourceManager resources = ResourceManager.getInstance(); |
356 |
0 |
String message = (String)resources.getResource( "peko.dialog.return-title.message" ); |
357 |
0 |
if( message == null ) { |
358 |
0 |
message = "Are you return title ?"; |
359 |
|
} |
360 |
|
|
361 |
0 |
String title = (String)resources.getResource( "peko.dialog.return-title.title" ); |
362 |
0 |
if( title == null ) { |
363 |
0 |
title = "Confirm"; |
364 |
|
} |
365 |
|
|
366 |
0 |
if( JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(PekoSystem.getInstance().getMainWindow(), message, title, JOptionPane.OK_CANCEL_OPTION) ) { |
367 |
0 |
PekoSystem.getInstance().showTitle(); |
368 |
0 |
} |
369 |
|
else { |
370 |
0 |
setActive( true ); |
371 |
|
} |
372 |
|
} |
373 |
0 |
_saveMenu.setEnabled( true ); |
374 |
0 |
_loadMenu.setEnabled( true ); |
375 |
0 |
_returnTileMenu.setEnabled( true ); |
376 |
0 |
_readAgainMenu.setEnabled( true ); |
377 |
0 |
} |
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
public void start() |
384 |
|
{ |
385 |
0 |
synchronized( _lock ) { |
386 |
0 |
if( _lastTask != null ) { |
387 |
0 |
_lastTask.cancel(); |
388 |
|
} |
389 |
0 |
_lastTask = null; |
390 |
0 |
_lock.notify(); |
391 |
0 |
Logger.debug( "[system.controler] notify to finish wait." ); |
392 |
0 |
} |
393 |
0 |
} |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
public void stop() |
399 |
|
{ |
400 |
0 |
stop( ActionControler.SM_DEFAULT ); |
401 |
0 |
} |
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
public void stop( long wait ) |
408 |
|
{ |
409 |
0 |
Logger.debug( "[system.controler] stop :" + wait ); |
410 |
0 |
if( (wait == 0) || (_playMode == ActionControler.PM_SKIP) ) { |
411 |
|
|
412 |
0 |
} |
413 |
0 |
else if( wait < 0 ) { |
414 |
0 |
synchronized( _lock ) { |
415 |
|
try { |
416 |
0 |
if( (_playMode == ActionControler.PM_AUTOMATIC) && !PekoSystem.getInstance().getCanvasManager().isShowingSelect() ) { |
417 |
0 |
TimerTask task = new TimerTask() { |
418 |
|
public void run() { |
419 |
|
synchronized( _lock ) { |
420 |
|
_lock.notify(); |
421 |
|
} |
422 |
|
} |
423 |
|
}; |
424 |
0 |
_timer.schedule( task, 1000L ); |
425 |
0 |
_lastTask = task; |
426 |
|
} |
427 |
0 |
_lock.wait(); |
428 |
|
} |
429 |
0 |
catch( InterruptedException ie ) { |
430 |
0 |
Logger.debug( "[system.action] interrupted." ); |
431 |
0 |
} |
432 |
0 |
} |
433 |
0 |
} |
434 |
|
else { |
435 |
0 |
synchronized( _lock ) { |
436 |
|
try { |
437 |
0 |
TimerTask task = new TimerTask() { |
438 |
|
public void run() { |
439 |
|
synchronized( _lock ) { |
440 |
|
_lock.notify(); |
441 |
|
} |
442 |
|
} |
443 |
|
}; |
444 |
0 |
_timer.schedule( task, wait ); |
445 |
0 |
_lastTask = task; |
446 |
0 |
_lock.wait(); |
447 |
|
} |
448 |
0 |
catch( InterruptedException ie ) { |
449 |
0 |
Logger.debug( "[system.action] interrupted." ); |
450 |
0 |
} |
451 |
0 |
} |
452 |
|
} |
453 |
|
|
454 |
0 |
if( !isActive() && (_lastTask != null) ) { |
455 |
0 |
synchronized( _lock ) { |
456 |
0 |
if( !_activity && (_lastTask != null) ) { |
457 |
0 |
_waitingActivate = true; |
458 |
|
try { |
459 |
0 |
_lock.wait(); |
460 |
0 |
_lock.wait( 500 ); |
461 |
|
} |
462 |
0 |
catch( InterruptedException ie ) { |
463 |
0 |
} |
464 |
0 |
_waitingActivate = false; |
465 |
|
} |
466 |
0 |
} |
467 |
|
} |
468 |
|
|
469 |
0 |
_lastTask = null; |
470 |
0 |
Logger.debug( "[system.controler] finish wait." ); |
471 |
0 |
} |
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
private void prepareMenuBar() |
478 |
|
{ |
479 |
0 |
PekoSystem system = PekoSystem.getInstance(); |
480 |
0 |
ResourceManager resources = ResourceManager.getInstance(); |
481 |
|
|
482 |
0 |
JMenuBar menubar = new JMenuBar(); |
483 |
0 |
JMenu menu = null; |
484 |
0 |
JMenuItem item = null; |
485 |
|
|
486 |
0 |
menu = new JMenu( (String)resources.getResource("peko.menu.system.menu-caption") ); |
487 |
0 |
menu.setMnemonic( 'S' ); |
488 |
0 |
menubar.add( menu ); |
489 |
|
|
490 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.system.save") ); |
491 |
0 |
item.setEnabled( false ); |
492 |
0 |
item.setMnemonic( 'S' ); |
493 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK) ); |
494 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "showSaveDialog", true ); |
495 |
0 |
menu.add( item ); |
496 |
0 |
_saveMenu = item; |
497 |
|
|
498 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.system.load") ); |
499 |
0 |
item.setEnabled( false ); |
500 |
0 |
item.setMnemonic( 'O' ); |
501 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK) ); |
502 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "showLoadDialog", true ); |
503 |
0 |
menu.add( item ); |
504 |
0 |
_loadMenu = item; |
505 |
|
|
506 |
0 |
menu.addSeparator(); |
507 |
|
|
508 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.system.return-title") ); |
509 |
0 |
item.setEnabled( false ); |
510 |
0 |
item.setMnemonic( 'T' ); |
511 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK) ); |
512 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "returnTitle", true ); |
513 |
0 |
menu.add( item ); |
514 |
0 |
_returnTileMenu = item; |
515 |
|
|
516 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.system.read-again") ); |
517 |
0 |
item.setEnabled( false ); |
518 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, 0) ); |
519 |
0 |
item.setMnemonic( 'R' ); |
520 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "showReadAgain" ); |
521 |
0 |
menu.add( item ); |
522 |
0 |
_readAgainMenu = item; |
523 |
|
|
524 |
0 |
menu.addSeparator(); |
525 |
|
|
526 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.system.exit") ); |
527 |
0 |
item.setMnemonic( 'X' ); |
528 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK) ); |
529 |
0 |
GenericListener.connect( item, system, ActionListener.class, "actionPerformed", "exit" ); |
530 |
0 |
menu.add( item ); |
531 |
|
|
532 |
|
|
533 |
0 |
menu = new JMenu( (String)resources.getResource("peko.menu.config.menu-caption") ); |
534 |
0 |
menu.setMnemonic( 'C' ); |
535 |
0 |
menubar.add( menu ); |
536 |
|
|
537 |
0 |
JMenu submenu = new JMenu( (String)resources.getResource("peko.menu.config.playmode.menu-caption") ); |
538 |
0 |
submenu.setMnemonic( 'P' ); |
539 |
0 |
menu.add( submenu ); |
540 |
|
|
541 |
0 |
ButtonGroup group = new ButtonGroup(); |
542 |
0 |
item = new JRadioButtonMenuItem( (String)resources.getResource("peko.menu.config.playmode.normal") ); |
543 |
0 |
item.setMnemonic( 'N' ); |
544 |
|
|
545 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "setPlayModeToNormal" ); |
546 |
0 |
group.add( item ); |
547 |
0 |
submenu.add( item ); |
548 |
0 |
_buttons[ ActionControler.PM_NORMAL ] = item; |
549 |
|
|
550 |
0 |
item = new JRadioButtonMenuItem( (String)resources.getResource("peko.menu.config.playmode.automatic") ); |
551 |
0 |
item.setMnemonic( 'A' ); |
552 |
|
|
553 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "setPlayModeToAutomatic" ); |
554 |
0 |
group.add( item ); |
555 |
0 |
submenu.add( item ); |
556 |
0 |
_buttons[ ActionControler.PM_AUTOMATIC ] = item; |
557 |
|
|
558 |
0 |
item = new JRadioButtonMenuItem( (String)resources.getResource("peko.menu.config.playmode.skip") ); |
559 |
0 |
item.setMnemonic( 'S' ); |
560 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, 0) ); |
561 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "setPlayModeToSKip" ); |
562 |
0 |
group.add( item ); |
563 |
0 |
submenu.add( item ); |
564 |
0 |
_buttons[ ActionControler.PM_SKIP ] = item; |
565 |
|
|
566 |
0 |
menu.addSeparator(); |
567 |
|
|
568 |
0 |
item = new JCheckBoxMenuItem( (String)resources.getResource("peko.menu.config.use-effect") ); |
569 |
0 |
item.setSelected( false ); |
570 |
0 |
item.setMnemonic( 'E' ); |
571 |
0 |
GenericListener.connect( item, this, ActionListener.class, "actionPerformed", "changeUsingEffect" ); |
572 |
0 |
menu.add( item ); |
573 |
0 |
_usingEffectMenu = item; |
574 |
|
|
575 |
|
|
576 |
0 |
menu = new JMenu( (String)resources.getResource("peko.menu.help.menu-caption") ); |
577 |
0 |
menu.setMnemonic( 'H' ); |
578 |
0 |
menubar.add( menu ); |
579 |
|
|
580 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.help.help-contents") ); |
581 |
0 |
item.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0) ); |
582 |
0 |
item.setMnemonic( 'H' ); |
583 |
0 |
item.setEnabled( false ); |
584 |
|
|
585 |
0 |
menu.add( item ); |
586 |
|
|
587 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.help.version") ); |
588 |
0 |
item.setMnemonic( 'A' ); |
589 |
0 |
GenericListener.connect( item, system, ActionListener.class, "actionPerformed", "showGameVersionInfo" ); |
590 |
0 |
menu.add( item ); |
591 |
|
|
592 |
0 |
menu.addSeparator(); |
593 |
|
|
594 |
0 |
item = new JMenuItem( (String)resources.getResource("peko.menu.help.about-pvns") ); |
595 |
0 |
item.setMnemonic( 'P' ); |
596 |
0 |
GenericListener.connect( item, system, ActionListener.class, "actionPerformed", "showSystemVersionInfo" ); |
597 |
0 |
menu.add( item ); |
598 |
|
|
599 |
|
|
600 |
0 |
JFrame mainWindow = system.getMainWindow(); |
601 |
0 |
mainWindow.setJMenuBar( menubar ); |
602 |
0 |
mainWindow.pack(); |
603 |
0 |
mainWindow.setResizable( false ); |
604 |
0 |
} |
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
public void mousePressed( MouseEvent ev ) |
611 |
|
{ |
612 |
0 |
} |
613 |
|
|
614 |
|
public void mouseReleased( MouseEvent ev ) |
615 |
|
{ |
616 |
0 |
} |
617 |
|
|
618 |
|
public void mouseEntered( MouseEvent ev ) |
619 |
|
{ |
620 |
0 |
} |
621 |
|
|
622 |
|
public void mouseExited( MouseEvent ev ) |
623 |
|
{ |
624 |
0 |
} |
625 |
|
|
626 |
|
public void mouseClicked( MouseEvent ev ) |
627 |
|
{ |
628 |
0 |
int code = ev.getModifiers(); |
629 |
0 |
if( isActive() && (code == MouseEvent.BUTTON1_MASK) ) { |
630 |
0 |
start(); |
631 |
0 |
} |
632 |
0 |
else if( (_playMode == ActionControler.PM_SKIP) && (code == MouseEvent.BUTTON3_MASK) ) { |
633 |
0 |
setPlayModeToNormal(); |
634 |
0 |
return; |
635 |
|
} |
636 |
0 |
else if( _hiddenText ) { |
637 |
0 |
CanvasManager canvasManager = PekoSystem.getInstance().getCanvasManager(); |
638 |
0 |
canvasManager.hideTextCanvas(); |
639 |
0 |
setActive( true ); |
640 |
|
} |
641 |
0 |
} |
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
public void keyPressed( KeyEvent ev ) |
648 |
|
{ |
649 |
0 |
if( isActive() ) { |
650 |
0 |
int code = ev.getKeyCode(); |
651 |
0 |
if( _lastKeyCode == -1 ) { |
652 |
0 |
_lastKeyCode = code; |
653 |
0 |
} |
654 |
0 |
else if( _lastKeyCode != code ) { |
655 |
0 |
_lastKeyCode = -1; |
656 |
|
} |
657 |
|
} |
658 |
0 |
} |
659 |
|
|
660 |
|
public void keyReleased( KeyEvent ev ) |
661 |
|
{ |
662 |
0 |
int code = ev.getKeyCode(); |
663 |
0 |
if( code != _lastKeyCode ) { |
664 |
0 |
_lastKeyCode = -1; |
665 |
0 |
return; |
666 |
|
} |
667 |
|
|
668 |
0 |
if( _hiddenText ) { |
669 |
0 |
CanvasManager canvasManager = PekoSystem.getInstance().getCanvasManager(); |
670 |
0 |
canvasManager.showTextCanvas(); |
671 |
0 |
_saveMenu.setEnabled( true ); |
672 |
0 |
_loadMenu.setEnabled( true ); |
673 |
0 |
_returnTileMenu.setEnabled( true ); |
674 |
0 |
_hiddenText = false; |
675 |
0 |
} |
676 |
0 |
else if( isActive() && (code == KeyEvent.VK_ENTER) ) { |
677 |
0 |
start(); |
678 |
0 |
} |
679 |
0 |
else if( (_playMode != ActionControler.PM_NORMAL) && (code == KeyEvent.VK_ESCAPE) ) { |
680 |
0 |
setPlayModeToNormal(); |
681 |
0 |
} |
682 |
0 |
else if( !_hiddenText && (code == KeyEvent.VK_SPACE) ) { |
683 |
0 |
CanvasManager canvasManager = PekoSystem.getInstance().getCanvasManager(); |
684 |
0 |
_saveMenu.setEnabled( false ); |
685 |
0 |
_loadMenu.setEnabled( false ); |
686 |
0 |
_returnTileMenu.setEnabled( false ); |
687 |
0 |
canvasManager.hideTextCanvas(); |
688 |
0 |
_hiddenText = true; |
689 |
|
} |
690 |
0 |
_lastKeyCode = -1; |
691 |
0 |
} |
692 |
|
|
693 |
|
public void keyTyped( KeyEvent ev ) |
694 |
|
{ |
695 |
0 |
} |
696 |
|
} |
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
class TextHistoryControler extends JDialog { |
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
private static final long serialVersionUID = -5321584449609116120L; |
710 |
|
|
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
private int _index = 0; |
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
|
private CanvasManager _canvasManager = null; |
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
|
724 |
|
private JButton _previous = null; |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
private JButton _next = null; |
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
|
public TextHistoryControler() |
736 |
|
{ |
737 |
|
super( PekoSystem.getInstance().getMainWindow(), true ); |
738 |
|
initialize(); |
739 |
|
} |
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
private void initialize() |
746 |
|
{ |
747 |
|
_canvasManager = PekoSystem.getInstance().getCanvasManager(); |
748 |
|
ClassLoader cl = getClass().getClassLoader(); |
749 |
|
|
750 |
|
getContentPane().setLayout( new java.awt.FlowLayout() ); |
751 |
|
JButton button = new JButton(); |
752 |
|
button.setIcon( new ImageIcon(cl.getResource("left-arrow.png")) ); |
753 |
|
getContentPane().add( button ); |
754 |
|
GenericListener.connect( button, this, ActionListener.class, "actionPerformed", "previous" ); |
755 |
|
_previous = button; |
756 |
|
button.setEnabled( (_canvasManager.getPageHistoryCount() >= 1) ); |
757 |
|
|
758 |
|
button = new JButton(); |
759 |
|
button.setIcon( new ImageIcon(cl.getResource("right-arrow.png")) ); |
760 |
|
button.setEnabled( false ); |
761 |
|
getContentPane().add( button ); |
762 |
|
_next = button; |
763 |
|
GenericListener.connect( button, this, ActionListener.class, "actionPerformed", "next" ); |
764 |
|
|
765 |
|
pack(); |
766 |
|
setResizable( false ); |
767 |
|
} |
768 |
|
|
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
public void previous() |
773 |
|
{ |
774 |
|
ResourceManager resources = ResourceManager.getInstance(); |
775 |
|
_index++; |
776 |
|
setTitle( ((MessageFormat)resources.getResource("peko.dialog.read-again.title-format")).format(new Object[]{String.valueOf(_index)}) ); |
777 |
|
_next.setEnabled( (_index > 1 ) ); |
778 |
|
if( _index == _canvasManager.getPageHistoryCount() ) { |
779 |
|
_previous.setEnabled( false ); |
780 |
|
} |
781 |
|
_previous.setEnabled( _canvasManager.readAgain(_index) ); |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
public void next() |
788 |
|
{ |
789 |
|
ResourceManager resources = ResourceManager.getInstance(); |
790 |
|
_index--; |
791 |
|
setTitle( ((MessageFormat)resources.getResource("peko.dialog.read-again.title-format")).format(new Object[]{String.valueOf(_index)}) ); |
792 |
|
_previous.setEnabled( true ); |
793 |
|
if( _index == 1 ) { |
794 |
|
_next.setEnabled( false ); |
795 |
|
} |
796 |
|
_canvasManager.readAgain( _index ); |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
public void setVisible( boolean visible ) |
804 |
|
{ |
805 |
|
if( visible ) { |
806 |
|
_index = 0; |
807 |
|
if( _canvasManager.getPageHistoryCount() > 0 ) { |
808 |
|
previous(); |
809 |
|
} |
810 |
|
} |
811 |
|
else { |
812 |
|
_canvasManager.returnCurrent(); |
813 |
|
} |
814 |
|
super.setVisible( visible ); |
815 |
|
} |
816 |
|
} |