2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
14
* o Neither the name of Substance 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.
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.
30
package org.pushingpixels.substance.internal.ui;
33
import java.awt.event.MouseEvent;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
38
import javax.swing.plaf.ComponentUI;
39
import javax.swing.plaf.UIResource;
40
import javax.swing.plaf.basic.BasicTextPaneUI;
42
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
43
import org.pushingpixels.substance.internal.animation.StateTransitionTracker;
44
import org.pushingpixels.substance.internal.animation.TransitionAwareUI;
45
import org.pushingpixels.substance.internal.utils.*;
48
* UI for text panes in <b>Substance</b> look and feel.
50
* @author Kirill Grouchnikov
52
public class SubstanceTextPaneUI extends BasicTextPaneUI implements
54
protected StateTransitionTracker stateTransitionTracker;
57
* The associated text pane.
59
protected JTextPane textPane;
62
* Property change listener.
64
protected PropertyChangeListener substancePropertyChangeListener;
67
* Listener for transition animations.
69
private RolloverTextControlListener substanceRolloverListener;
72
* Surrogate button model for tracking the state transitions.
74
private ButtonModel transitionModel;
79
* @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
81
public static ComponentUI createUI(JComponent comp) {
82
SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
83
return new SubstanceTextPaneUI(comp);
90
* Component (text pane).
92
public SubstanceTextPaneUI(JComponent c) {
94
this.textPane = (JTextPane) c;
96
this.transitionModel = new DefaultButtonModel();
97
this.transitionModel.setArmed(false);
98
this.transitionModel.setSelected(false);
99
this.transitionModel.setPressed(false);
100
this.transitionModel.setRollover(false);
101
this.transitionModel.setEnabled(this.textPane.isEnabled());
103
this.stateTransitionTracker = new StateTransitionTracker(this.textPane,
104
this.transitionModel);
108
protected void installListeners() {
109
super.installListeners();
111
this.substanceRolloverListener = new RolloverTextControlListener(
112
this.textPane, this, this.transitionModel);
113
this.substanceRolloverListener.registerListeners();
115
this.stateTransitionTracker.registerModelListeners();
116
this.stateTransitionTracker.registerFocusListeners();
118
this.substancePropertyChangeListener = new PropertyChangeListener() {
120
public void propertyChange(PropertyChangeEvent evt) {
121
if ("font".equals(evt.getPropertyName())) {
122
SwingUtilities.invokeLater(new Runnable() {
125
// remember the caret location - issue 404
126
int caretPos = textPane.getCaretPosition();
128
textPane.setCaretPosition(caretPos);
129
Container parent = textPane.getParent();
130
if (parent != null) {
138
if ("enabled".equals(evt.getPropertyName())) {
139
transitionModel.setEnabled(textPane.isEnabled());
144
.addPropertyChangeListener(this.substancePropertyChangeListener);
150
* @see javax.swing.plaf.basic.BasicTextUI#uninstallListeners()
153
protected void uninstallListeners() {
154
this.stateTransitionTracker.unregisterModelListeners();
155
this.stateTransitionTracker.unregisterFocusListeners();
158
.removePropertyChangeListener(this.substancePropertyChangeListener);
159
this.substancePropertyChangeListener = null;
161
super.uninstallListeners();
167
* @see javax.swing.plaf.basic.BasicTextUI#installDefaults()
170
protected void installDefaults() {
171
super.installDefaults();
173
// support for per-window skins
174
SwingUtilities.invokeLater(new Runnable() {
177
if (textPane == null)
179
Color foregr = textPane.getForeground();
180
if ((foregr == null) || (foregr instanceof UIResource)) {
182
.setForeground(SubstanceColorUtilities
183
.getForegroundColor(SubstanceLookAndFeel
184
.getCurrentSkin(textPane)
185
.getEnabledColorScheme(
187
.getDecorationType(textPane))));
197
* javax.swing.plaf.basic.BasicTextUI#paintBackground(java.awt.Graphics)
200
protected void paintBackground(Graphics g) {
201
SubstanceTextUtilities.paintTextCompBackground(g, this.textPane);
205
public boolean isInside(MouseEvent me) {
210
public StateTransitionTracker getTransitionTracker() {
211
return this.stateTransitionTracker;