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;
35
import javax.swing.plaf.ComponentUI;
36
import javax.swing.plaf.basic.BasicOptionPaneUI;
38
import org.pushingpixels.lafwidget.animation.AnimationConfigurationManager;
39
import org.pushingpixels.lafwidget.animation.AnimationFacet;
40
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
41
import org.pushingpixels.substance.internal.animation.IconGlowTracker;
42
import org.pushingpixels.substance.internal.painter.BackgroundPaintingUtils;
43
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
44
import org.pushingpixels.substance.internal.utils.icon.GlowingIcon;
47
* UI for option panes in <b>Substance</b> look and feel.
49
* @author Kirill Grouchnikov
51
public class SubstanceOptionPaneUI extends BasicOptionPaneUI {
53
AnimationConfigurationManager.getInstance().allowAnimations(
54
AnimationFacet.ICON_GLOW, OptionPaneLabel.class);
58
* Label extension class. Due to defect 250, the option pane icon animation
59
* (glowing icon) should repaint only the icon itself and not the entire
60
* option pane. While the {@link AnimationConfigurationManager} API provides
61
* an option to enable animations on the specific component, it's better to
62
* enable it on the component class (to make the lookups faster). So, when
63
* the option pane icon label is created (in addIcon method), we use this
66
* @author Kirill Grouchnikov
68
protected static class OptionPaneLabel extends JLabel {
74
private OptionPaneLabel substanceIconLabel;
76
private IconGlowTracker iconGlowTracker;
79
* Creates a new SubstanceOptionPaneUI instance.
81
public static ComponentUI createUI(JComponent comp) {
82
SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
83
return new SubstanceOptionPaneUI();
89
* @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics,
90
* javax.swing.JComponent)
93
public void paint(Graphics g, JComponent c) {
94
BackgroundPaintingUtils.updateIfOpaque(g, c);
100
* @see javax.swing.plaf.basic.BasicOptionPaneUI#addIcon(java.awt.Container)
103
protected void addIcon(Container top) {
104
Icon sideIcon = (optionPane == null ? null : optionPane.getIcon());
106
if (sideIcon == null && optionPane != null)
107
sideIcon = super.getIconForType(optionPane.getMessageType());
109
if (sideIcon != null) {
110
if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) {
111
sideIcon = SubstanceCoreUtilities.getThemedIcon(null, sideIcon);
114
this.substanceIconLabel = new OptionPaneLabel();
115
this.iconGlowTracker = new IconGlowTracker(substanceIconLabel);
116
this.substanceIconLabel.setIcon(new GlowingIcon(sideIcon,
117
this.iconGlowTracker));
119
this.substanceIconLabel.setName("OptionPane.iconLabel");
120
this.substanceIconLabel.setVerticalAlignment(SwingConstants.TOP);
121
top.add(this.substanceIconLabel, BorderLayout.BEFORE_LINE_BEGINS);
128
* @see javax.swing.plaf.basic.BasicOptionPaneUI#getIconForType(int)
131
protected Icon getIconForType(int messageType) {
132
switch (messageType) {
133
case JOptionPane.ERROR_MESSAGE:
134
return SubstanceCoreUtilities
135
.getIcon("resource/32/dialog-error.png");
136
case JOptionPane.INFORMATION_MESSAGE:
137
return SubstanceCoreUtilities
138
.getIcon("resource/32/dialog-information.png");
139
case JOptionPane.WARNING_MESSAGE:
140
return SubstanceCoreUtilities
141
.getIcon("resource/32/dialog-warning.png");
142
case JOptionPane.QUESTION_MESSAGE:
143
return SubstanceCoreUtilities
144
.getIcon("resource/32/help-browser.png");
152
* @see javax.swing.plaf.basic.BasicOptionPaneUI#installComponents()
155
protected void installComponents() {
156
super.installComponents();
157
// fix for defect 265 - check that the label is not null
158
// before activating the loop.
159
if (this.substanceIconLabel != null) {
160
// Make the icon glow for three cycles. There's no need to
161
// explicitly cancel the animation when the option pane is closed
162
// before the animation is over - when the three cycles are up,
163
// the animation will be removed by the tracker.
164
if (!this.iconGlowTracker.isPlaying()) {
165
this.iconGlowTracker.play(3);