Debian Codegraph @

laf-widget/src/main/java/org/pushingpixels/lafwidget/animation/effects/GhostAnimationWidget.java

raw
1 /*
2 * Copyright (c) 2005-2010 Laf-Widget Kirill Grouchnikov. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * o Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * o Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * o Neither the name of Laf-Widget Kirill Grouchnikov nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.pushingpixels.lafwidget.animation.effects;
31
32 import java.beans.PropertyChangeEvent;
33 import java.beans.PropertyChangeListener;
34
35 import javax.swing.AbstractButton;
36
37 import org.pushingpixels.lafwidget.LafWidgetAdapter;
38
39 /**
40 * Widget that tracks changes to the button for ghost effects.
41 *
42 * @author Kirill Grouchnikov
43 */
44 public class GhostAnimationWidget extends LafWidgetAdapter<AbstractButton> {
45 /**
46 * Model change listener for ghost image effects.
47 */
48 private GhostingListener ghostModelChangeListener;
49
50 /**
51 * Property change listener. Listens on changes to the
52 * {@link AbstractButton#MODEL_CHANGED_PROPERTY} property.
53 */
54 protected PropertyChangeListener ghostPropertyListener;
55
56 /*
57 * (non-Javadoc)
58 *
59 * @see org.pushingpixels.lafwidget.LafWidget#requiresCustomLafSupport()
60 */
61 @Override
62 public boolean requiresCustomLafSupport() {
63 return false;
64 }
65
66 /*
67 * (non-Javadoc)
68 *
69 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#installDefaults()
70 */
71 @Override
72 public void installDefaults() {
73 this.jcomp.setRolloverEnabled(true);
74 }
75
76 /*
77 * (non-Javadoc)
78 *
79 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#installListeners()
80 */
81 @Override
82 public void installListeners() {
83 this.ghostPropertyListener = new PropertyChangeListener() {
84 @Override
85 public void propertyChange(PropertyChangeEvent evt) {
86 if (AbstractButton.MODEL_CHANGED_PROPERTY.equals(evt
87 .getPropertyName())) {
88 if (ghostModelChangeListener != null)
89 ghostModelChangeListener.unregisterListeners();
90 ghostModelChangeListener = new GhostingListener(jcomp,
91 jcomp.getModel());
92 ghostModelChangeListener.registerListeners();
93 }
94
95 // if ("icon.bounds".equals(evt.getPropertyName())) {
96 // try {
97 // throw new IOException(evt.getNewValue().toString());
98 // } catch (Exception ie) {
99 // ie.printStackTrace();
100 // }
101 // }
102 }
103 };
104 jcomp.addPropertyChangeListener(this.ghostPropertyListener);
105
106 this.ghostModelChangeListener = new GhostingListener(jcomp, jcomp
107 .getModel());
108 this.ghostModelChangeListener.registerListeners();
109 }
110
111 /*
112 * (non-Javadoc)
113 *
114 * @see org.pushingpixels.lafwidget.LafWidgetAdapter#uninstallListeners()
115 */
116 @Override
117 public void uninstallListeners() {
118 jcomp.removePropertyChangeListener(this.ghostPropertyListener);
119 this.ghostPropertyListener = null;
120
121 this.ghostModelChangeListener.unregisterListeners();
122 this.ghostModelChangeListener = null;
123 }
124
125 }