001 package com.croftsoft.core.animation;
002
003 import java.awt.*;
004 import java.io.*;
005 import java.beans.*;
006
007 import com.croftsoft.core.CroftSoftConstants;
008 import com.croftsoft.core.animation.animator.*;
009 import com.croftsoft.core.animation.painter.*;
010 import com.croftsoft.core.animation.updater.*;
011 import com.croftsoft.core.lang.Testable;
012
013 /*********************************************************************
014 * Animation initializer.
015 *
016 * @version
017 * 2003-08-02
018 * @since
019 * 2003-03-07
020 * @author
021 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
022 *********************************************************************/
023
024 public class AnimationInit
025 implements Serializable, Testable
026 //////////////////////////////////////////////////////////////////////
027 //////////////////////////////////////////////////////////////////////
028 {
029
030 private static final long serialVersionUID = 0L;
031
032 //
033
034 public static final String DEFAULT_APPLET_INFO
035 = CroftSoftConstants.DEFAULT_APPLET_INFO;
036
037 public static final Color DEFAULT_BACKGROUND_COLOR
038 = Color.WHITE;
039
040 public static final Cursor DEFAULT_CURSOR
041 = null; // new Cursor ( Cursor.CROSSHAIR_CURSOR );
042
043 public static final Font DEFAULT_FONT
044 = new Font ( "Courier New", Font.BOLD, 10 );
045
046 public static final Color DEFAULT_FOREGROUND_COLOR
047 = Color.BLACK;
048
049 public static final String DEFAULT_FRAME_ICON_FILENAME
050 = null;
051
052 public static final Double DEFAULT_FRAME_RATE
053 = null;
054
055 public static final Dimension DEFAULT_FRAME_SIZE
056 = null;
057
058 public static final String DEFAULT_FRAME_TITLE
059 = null;
060
061 public static final String DEFAULT_SHUTDOWN_CONFIRMATION_PROMPT
062 = "Exit?";
063
064 public static final ArrayComponentUpdater
065 DEFAULT_ARRAY_COMPONENT_UPDATER = new ArrayComponentUpdater ( );
066
067 public static final ArrayComponentPainter
068 DEFAULT_ARRAY_COMPONENT_PAINTER = new ArrayComponentPainter ( );
069
070 //////////////////////////////////////////////////////////////////////
071 // instance variables
072 //////////////////////////////////////////////////////////////////////
073
074 private TextAnimator textAnimator;
075
076 private String appletInfo;
077
078 private ArrayComponentPainter arrayComponentPainter;
079
080 private ArrayComponentUpdater arrayComponentUpdater;
081
082 private Color backgroundColor;
083
084 private Cursor cursor;
085
086 private Font font;
087
088 private Color foregroundColor;
089
090 private String frameIconFilename;
091
092 private Double frameRate;
093
094 private Dimension frameSize;
095
096 private String frameTitle;
097
098 private String shutdownConfirmationPrompt;
099
100 //////////////////////////////////////////////////////////////////////
101 // static methods
102 //////////////////////////////////////////////////////////////////////
103
104 /*********************************************************************
105 * Test method.
106 *********************************************************************/
107 public static void main ( String [ ] args )
108 throws Exception
109 //////////////////////////////////////////////////////////////////////
110 {
111 System.out.println ( test ( args ) );
112 }
113
114 /*********************************************************************
115 * Test method.
116 *********************************************************************/
117 public static boolean test ( String [ ] args )
118 //////////////////////////////////////////////////////////////////////
119 {
120 final String TEST = "test";
121
122 try
123 {
124 AnimationInit animationInit1 = new AnimationInit ( );
125
126 animationInit1.setAppletInfo ( TEST );
127
128 ArrayComponentPainter arrayComponentPainter
129 = animationInit1.getArrayComponentPainter ( );
130
131 ArrayComponentUpdater arrayComponentUpdater
132 = animationInit1.getArrayComponentUpdater ( );
133
134 ColorPainter colorPainter = new ColorPainter ( );
135
136 TextAnimator textAnimator = new TextAnimator ( );
137
138 animationInit1.setTextAnimator ( textAnimator );
139
140 textAnimator.setText ( DEFAULT_APPLET_INFO );
141
142 textAnimator.setDeltaX ( 1 );
143
144 textAnimator.setDeltaY ( 1 );
145
146 arrayComponentPainter.add ( colorPainter );
147
148 arrayComponentPainter.add ( textAnimator );
149
150 arrayComponentUpdater.add ( textAnimator );
151
152 animationInit1.setCursor (
153 new Cursor ( Cursor.MOVE_CURSOR ) );
154
155 animationInit1.setBackgroundColor ( Color.BLUE );
156
157 animationInit1.setFont (
158 new Font ( "Courier", Font.BOLD, 10 ) );
159
160 animationInit1.setForegroundColor ( Color.RED );
161
162 animationInit1.setFrameIconFilename ( TEST );
163
164 animationInit1.setFrameSize ( new Dimension ( 600, 400 ) );
165
166 animationInit1.setFrameTitle ( TEST );
167
168 animationInit1.setShutdownConfirmationPrompt ( TEST );
169
170 ByteArrayOutputStream byteArrayOutputStream
171 = new ByteArrayOutputStream ( );
172
173 XMLEncoder xmlEncoder = new XMLEncoder ( byteArrayOutputStream );
174
175 xmlEncoder.writeObject ( animationInit1 );
176
177 xmlEncoder.close ( );
178
179 byte [ ] xmlBytes = byteArrayOutputStream.toByteArray ( );
180
181 System.out.println ( new String ( xmlBytes ) );
182
183 XMLDecoder xmlDecoder
184 = new XMLDecoder ( new ByteArrayInputStream ( xmlBytes ) );
185
186 AnimationInit animationInit2
187 = ( AnimationInit ) xmlDecoder.readObject ( );
188
189 return true;
190 }
191 catch ( Exception ex )
192 {
193 ex.printStackTrace ( );
194
195 return false;
196 }
197 }
198
199 public static AnimationInit load ( String filename )
200 throws FileNotFoundException
201 //////////////////////////////////////////////////////////////////////
202 {
203 XMLDecoder xmlDecoder = new XMLDecoder (
204 new BufferedInputStream ( new FileInputStream ( filename ) ) );
205
206 AnimationInit AnimationInit
207 = ( AnimationInit ) xmlDecoder.readObject ( );
208
209 xmlDecoder.close ( );
210
211 return AnimationInit;
212 }
213
214 public static void save (
215 AnimationInit animationInit,
216 String filename )
217 throws FileNotFoundException
218 //////////////////////////////////////////////////////////////////////
219 {
220 XMLEncoder xmlEncoder = new XMLEncoder (
221 new BufferedOutputStream (
222 new FileOutputStream ( filename ) ) );
223
224 AnimationInit AnimationInit
225 = new AnimationInit ( animationInit );
226
227 xmlEncoder.writeObject ( AnimationInit );
228
229 xmlEncoder.close ( );
230 }
231
232 //////////////////////////////////////////////////////////////////////
233 // constructor methods
234 //////////////////////////////////////////////////////////////////////
235
236 public AnimationInit ( AnimationInit animationInit )
237 //////////////////////////////////////////////////////////////////////
238 {
239 if ( animationInit == null )
240 {
241 appletInfo = DEFAULT_APPLET_INFO;
242
243 arrayComponentPainter = DEFAULT_ARRAY_COMPONENT_PAINTER;
244
245 arrayComponentUpdater = DEFAULT_ARRAY_COMPONENT_UPDATER;
246
247 backgroundColor = DEFAULT_BACKGROUND_COLOR;
248
249 cursor = DEFAULT_CURSOR;
250
251 font = DEFAULT_FONT;
252
253 foregroundColor = DEFAULT_FOREGROUND_COLOR;
254
255 frameIconFilename = DEFAULT_FRAME_ICON_FILENAME;
256
257 frameRate = DEFAULT_FRAME_RATE;
258
259 frameSize = DEFAULT_FRAME_SIZE;
260
261 frameTitle = DEFAULT_FRAME_TITLE;
262
263 shutdownConfirmationPrompt = DEFAULT_SHUTDOWN_CONFIRMATION_PROMPT;
264 }
265 else
266 {
267 appletInfo
268 = animationInit.getAppletInfo ( );
269
270 arrayComponentPainter
271 = animationInit.getArrayComponentPainter ( );
272
273 arrayComponentUpdater
274 = animationInit.getArrayComponentUpdater ( );
275
276 backgroundColor
277 = animationInit.getBackgroundColor ( );
278
279 cursor
280 = animationInit.getCursor ( );
281
282 font
283 = animationInit.getFont ( );
284
285 foregroundColor
286 = animationInit.getForegroundColor ( );
287
288 frameIconFilename
289 = animationInit.getFrameIconFilename ( );
290
291 frameRate
292 = animationInit.getFrameRate ( );
293
294 frameSize
295 = animationInit.getFrameSize ( );
296
297 frameTitle
298 = animationInit.getFrameTitle ( );
299
300 shutdownConfirmationPrompt
301 = animationInit.getShutdownConfirmationPrompt ( );
302 }
303 }
304
305 public AnimationInit ( )
306 //////////////////////////////////////////////////////////////////////
307 {
308 this ( null );
309 }
310
311 //////////////////////////////////////////////////////////////////////
312 // accessor methods
313 //////////////////////////////////////////////////////////////////////
314
315 public TextAnimator getTextAnimator ( ) { return textAnimator; }
316
317 public void setTextAnimator ( TextAnimator textAnimator )
318 { this.textAnimator = textAnimator; }
319
320 public String getAppletInfo ( )
321 //////////////////////////////////////////////////////////////////////
322 {
323 return appletInfo;
324 }
325
326 public ArrayComponentPainter getArrayComponentPainter ( )
327 //////////////////////////////////////////////////////////////////////
328 {
329 return arrayComponentPainter;
330 }
331
332 public ArrayComponentUpdater getArrayComponentUpdater ( )
333 //////////////////////////////////////////////////////////////////////
334 {
335 return arrayComponentUpdater;
336 }
337
338 public Color getBackgroundColor ( )
339 //////////////////////////////////////////////////////////////////////
340 {
341 return backgroundColor;
342 }
343
344 public Cursor getCursor ( )
345 //////////////////////////////////////////////////////////////////////
346 {
347 return cursor;
348 }
349
350 public Font getFont ( )
351 //////////////////////////////////////////////////////////////////////
352 {
353 return font;
354 }
355
356 public Color getForegroundColor ( )
357 //////////////////////////////////////////////////////////////////////
358 {
359 return foregroundColor;
360 }
361
362 public String getFrameIconFilename ( )
363 //////////////////////////////////////////////////////////////////////
364 {
365 return frameIconFilename;
366 }
367
368 public Double getFrameRate ( )
369 //////////////////////////////////////////////////////////////////////
370 {
371 return frameRate;
372 }
373
374 public Dimension getFrameSize ( )
375 //////////////////////////////////////////////////////////////////////
376 {
377 return frameSize;
378 }
379
380 public String getFrameTitle ( )
381 //////////////////////////////////////////////////////////////////////
382 {
383 return frameTitle;
384 }
385
386 public String getShutdownConfirmationPrompt ( )
387 //////////////////////////////////////////////////////////////////////
388 {
389 return shutdownConfirmationPrompt;
390 }
391
392 //////////////////////////////////////////////////////////////////////
393 // mutator methods
394 //////////////////////////////////////////////////////////////////////
395
396 public void setAppletInfo ( String appletInfo )
397 //////////////////////////////////////////////////////////////////////
398 {
399 this.appletInfo = appletInfo;
400 }
401
402 public void setArrayComponentPainter (
403 ArrayComponentPainter arrayComponentPainter )
404 //////////////////////////////////////////////////////////////////////
405 {
406 this.arrayComponentPainter = arrayComponentPainter;
407 }
408
409 public void setArrayComponentUpdater (
410 ArrayComponentUpdater arrayComponentUpdater )
411 //////////////////////////////////////////////////////////////////////
412 {
413 this.arrayComponentUpdater = arrayComponentUpdater;
414 }
415
416 public void setBackgroundColor ( Color backgroundColor )
417 //////////////////////////////////////////////////////////////////////
418 {
419 this.backgroundColor = backgroundColor;
420 }
421
422 public void setCursor ( Cursor cursor )
423 //////////////////////////////////////////////////////////////////////
424 {
425 this.cursor = cursor;
426 }
427
428 public void setFont ( Font font )
429 //////////////////////////////////////////////////////////////////////
430 {
431 this.font = font;
432 }
433
434 public void setForegroundColor ( Color foregroundColor )
435 //////////////////////////////////////////////////////////////////////
436 {
437 this.foregroundColor = foregroundColor;
438 }
439
440 public void setFrameIconFilename ( String frameIconFilename )
441 //////////////////////////////////////////////////////////////////////
442 {
443 this.frameIconFilename = frameIconFilename;
444 }
445
446 public void setFrameRate ( Double frameRate )
447 //////////////////////////////////////////////////////////////////////
448 {
449 this.frameRate = frameRate;
450 }
451
452 public void setFrameSize ( Dimension frameSize )
453 //////////////////////////////////////////////////////////////////////
454 {
455 this.frameSize = frameSize;
456 }
457
458 public void setFrameTitle ( String frameTitle )
459 //////////////////////////////////////////////////////////////////////
460 {
461 this.frameTitle = frameTitle;
462 }
463
464 public void setShutdownConfirmationPrompt (
465 String shutdownConfirmationPrompt )
466 //////////////////////////////////////////////////////////////////////
467 {
468 this.shutdownConfirmationPrompt = shutdownConfirmationPrompt;
469 }
470
471 //////////////////////////////////////////////////////////////////////
472 //////////////////////////////////////////////////////////////////////
473 }