View Javadoc

1   package com.melloware.jukes.util;
2   
3   import java.awt.Graphics;
4   import java.awt.Window;
5   
6   import com.jgoodies.uif.splash.ImageSplash;
7   import com.jgoodies.uif.splash.SplashProvider;
8   
9   /**
10   * <p>A wrapper for <code>com.jgoodies.uif.splash.ImageSplash</code> which is
11   * removing flickering when note or progress changes.</p>
12   *
13   * <p>The reason of flickering is default lightweigt component's <code>update(Graphics)</code>
14   * method which clears the background before <code>paint(Graphics)</code> method invocation.</p>
15   *
16   * <p>Other solution is to ask JGoodies author to override
17   * <code>ImageSplash.update(Graphics)</code>: i.e. <code>void update(Graphics g) {paint(g);}</code>
18   * </p>
19   *
20   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
21   * @author Emil A. Lefkof III <info@melloware.com>
22   */
23  public class NoFlickerSplashWrapper
24      extends Window
25      implements SplashProvider {
26  	
27      private final ImageSplash imageSplash;
28  
29      /**
30       * Creates ImageSplashWrapper and initializes it with wrapped ImageSplash
31       * size/location values.
32       *
33       * @param anImageSplash     image splash screen to wrap.
34       */
35      public NoFlickerSplashWrapper(ImageSplash anImageSplash) {
36          super(anImageSplash.getOwner());
37  
38          imageSplash = anImageSplash;
39  
40          setSize(imageSplash.getSize());
41          setLocation(imageSplash.getLocation());
42      }
43  
44      /**
45       * Sets the note.
46       *
47       * @param note splash note.
48       *
49       * @see SplashProvider#setNote(java.lang.String)
50       */
51      public void setNote(String note) {
52          imageSplash.setNote(note);
53          repaint();
54      }
55  
56      /**
57       * Sets the progress.
58       *
59       * @param percent progress percent value (0 <= ... <= 100).
60       *
61       * @see SplashProvider#setProgress(int)
62       */
63      public void setProgress(int percent) {
64          imageSplash.setProgress(percent);
65          repaint();
66      }
67  
68      /**
69       * Invoked to close splash &amp; release resources.
70       *
71       * @see SplashProvider#closeSplash()
72       */
73      public void closeSplash() {
74          dispose();
75      }
76  
77      /**
78       * Invoked to open splash.
79       *
80       * @see SplashProvider#openSplash()
81       */
82      public void openSplash() {
83          setVisible(true);
84      }
85  
86      /**
87       * Paints the container.
88       *
89       * @param g the specified Graphics window.
90       */
91      public void paint(Graphics g) {
92          imageSplash.paint(g);
93      }
94  
95      /**
96       * Updates the container.
97       *
98       * @param g the specified Graphics window.
99       */
100     public void update(Graphics g) {
101         paint(g);
102     }
103 }