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.BasicEditorPaneUI;
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 editor panes in <b>Substance</b> look and feel.
50
* @author Kirill Grouchnikov
52
public class SubstanceEditorPaneUI extends BasicEditorPaneUI implements
54
protected StateTransitionTracker stateTransitionTracker;
57
* The associated editor pane.
59
protected JEditorPane editorPane;
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 SubstanceEditorPaneUI(comp);
90
* Component (editor pane).
92
public SubstanceEditorPaneUI(JComponent c) {
94
this.editorPane = (JEditorPane) 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.editorPane.isEnabled());
103
this.stateTransitionTracker = new StateTransitionTracker(
104
this.editorPane, this.transitionModel);
110
* @see javax.swing.plaf.basic.BasicTextUI#installListeners()
113
protected void installListeners() {
114
super.installListeners();
115
super.installListeners();
117
this.substanceRolloverListener = new RolloverTextControlListener(
118
this.editorPane, this, this.transitionModel);
119
this.substanceRolloverListener.registerListeners();
121
this.stateTransitionTracker.registerModelListeners();
122
this.stateTransitionTracker.registerFocusListeners();
124
this.substancePropertyChangeListener = new PropertyChangeListener() {
126
public void propertyChange(PropertyChangeEvent evt) {
127
if ("font".equals(evt.getPropertyName())) {
128
SwingUtilities.invokeLater(new Runnable() {
131
// remember the caret location - issue 404
132
int caretPos = editorPane.getCaretPosition();
133
editorPane.updateUI();
134
editorPane.setCaretPosition(caretPos);
135
Container parent = editorPane.getParent();
136
if (parent != null) {
144
if ("enabled".equals(evt.getPropertyName())) {
145
transitionModel.setEnabled(editorPane.isEnabled());
150
.addPropertyChangeListener(this.substancePropertyChangeListener);
156
* @see javax.swing.plaf.basic.BasicTextUI#uninstallListeners()
159
protected void uninstallListeners() {
160
this.stateTransitionTracker.unregisterModelListeners();
161
this.stateTransitionTracker.unregisterFocusListeners();
164
.removePropertyChangeListener(this.substancePropertyChangeListener);
165
this.substancePropertyChangeListener = null;
167
super.uninstallListeners();
173
* @see javax.swing.plaf.basic.BasicTextUI#installDefaults()
176
protected void installDefaults() {
177
super.installDefaults();
179
// support for per-window skins
180
SwingUtilities.invokeLater(new Runnable() {
183
if (editorPane == null)
185
Color foregr = editorPane.getForeground();
186
if ((foregr == null) || (foregr instanceof UIResource)) {
188
.setForeground(SubstanceColorUtilities
189
.getForegroundColor(SubstanceLookAndFeel
190
.getCurrentSkin(editorPane)
191
.getEnabledColorScheme(
193
.getDecorationType(editorPane))));
203
* javax.swing.plaf.basic.BasicTextUI#paintBackground(java.awt.Graphics)
206
protected void paintBackground(Graphics g) {
207
SubstanceTextUtilities.paintTextCompBackground(g, this.editorPane);
211
public boolean isInside(MouseEvent me) {
216
public StateTransitionTracker getTransitionTracker() {
217
return this.stateTransitionTracker;