KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > swing > BasicFeedback


1 /*
2  * Copyright 2006 Schlichtherle IT Services
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package de.schlichtherle.key.passwd.swing;
18
19 import java.awt.Toolkit JavaDoc;
20
21 import javax.swing.JPanel JavaDoc;
22
23 /**
24  * Provides feedback by beeping using the default toolkit.
25  * If you would like to play a nice sound for feedback, you need to override
26  * the {@link #startSound} method.
27  * <p>
28  * <b>Warning:</b> Playing a <code>java.applet.AudioClip</code> on J2SE
29  * 1.4.2_12 causes a client application not to terminate until System.exit(0)
30  * is called explicitly - hence this feature is currently not implemented in
31  * this class!
32  * This issue is fixed in JSE 1.5.0_07 (and probably earlier versions).
33  *
34  * @author Christian Schlichtherle
35  * @version @version@
36  * @since TrueZIP 6.2
37  */

38 public abstract class BasicFeedback implements Feedback {
39
40     private JPanel JavaDoc panel;
41
42     public JPanel JavaDoc getPanel() {
43         return panel;
44     }
45
46     public void setPanel(final JPanel JavaDoc panel) {
47         this.panel = panel;
48     }
49
50     /**
51      * Starts the visual/audible feedback.
52      * Subclasses should not override this method directly, but override
53      * {@link #startSound} and/or {@link #startAnimation} instead.
54      * <p>
55      * The implementation in this class calls {@link #startSound} and then
56      * {@link #startAnimation}.
57      */

58     public void run() {
59         startSound();
60         startAnimation();
61     }
62
63     /**
64      * Starts the audible feedback.
65      * Subclasses may override this method to play a sound of their liking.
66      * <p>
67      */

68     protected void startSound() {
69         Toolkit.getDefaultToolkit().beep();
70     }
71
72     /**
73      * Starts the visual feedback.
74      * Subclasses may override this method to animate the GUI according to
75      * their liking.
76      * This method is called when the panel is shown in its containing window.
77      * It is run on AWT's Event Dispatch Thread, so it must complete fast
78      * in order not to block the GUI.
79      * If an implementation is going to do animations, the
80      * {@link javax.swing.Timer} class should be used to schedule timer events
81      * for the animation.
82      * <p>
83      * The implementation in this class is a no-op.
84      */

85     protected void startAnimation() {
86     }
87 }
88
Popular Tags