001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance;
031:
032: import java.awt.*;
033:
034: import javax.swing.*;
035: import javax.swing.plaf.ComponentUI;
036: import javax.swing.plaf.basic.BasicOptionPaneUI;
037:
038: import org.jvnet.lafwidget.LafWidgetUtilities;
039: import org.jvnet.lafwidget.animation.*;
040: import org.jvnet.substance.utils.*;
041: import org.jvnet.substance.utils.icon.GlowingIcon;
042:
043: /**
044: * UI for option panes in <b>Substance</b> look and feel.
045: *
046: * @author Kirill Grouchnikov
047: */
048: public class SubstanceOptionPaneUI extends BasicOptionPaneUI {
049: static {
050: FadeConfigurationManager.getInstance().allowFades(
051: FadeKind.ICON_GLOW, OptionPaneLabel.class);
052: }
053:
054: /**
055: * Delegate for filling the background.
056: */
057: private static SubstanceFillBackgroundDelegate bgDelegate = new SubstanceFillBackgroundDelegate();
058:
059: /**
060: * Label extension class. Due to defect 250, the option pane icon animation
061: * (glowing icon) should repaint only the icon itself and not the entire
062: * option pane. While the FadeConfigurationManager API provides an option to
063: * enable animations on the specific component, it's better to enable it on
064: * the component class (to make the lookups faster). So, when the option
065: * pane icon label is created (in addIcon method), we use this class.
066: *
067: * @author Kirill Grouchnikov
068: */
069: protected static class OptionPaneLabel extends JLabel {
070: }
071:
072: /**
073: * Icon label.
074: */
075: private OptionPaneLabel substanceIconLabel;
076:
077: /**
078: * Creates a new SubstanceOptionPaneUI instance.
079: */
080: public static ComponentUI createUI(JComponent c) {
081: return new SubstanceOptionPaneUI();
082: }
083:
084: /*
085: * (non-Javadoc)
086: *
087: * @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics,
088: * javax.swing.JComponent)
089: */
090: @Override
091: public void paint(Graphics g, JComponent c) {
092: SubstanceOptionPaneUI.bgDelegate.updateIfOpaque(g, c);
093: }
094:
095: /*
096: * (non-Javadoc)
097: *
098: * @see javax.swing.plaf.basic.BasicOptionPaneUI#addIcon(java.awt.Container)
099: */
100: @Override
101: protected void addIcon(Container top) {
102: Icon sideIcon = (optionPane == null ? null : optionPane
103: .getIcon());
104:
105: if (sideIcon == null && optionPane != null)
106: sideIcon = super
107: .getIconForType(optionPane.getMessageType());
108:
109: if (sideIcon != null) {
110: if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) {
111: sideIcon = new ImageIcon(SubstanceImageCreator
112: .getThemeImage(null, sideIcon,
113: SubstanceThemeUtilities.getTheme(
114: optionPane,
115: ComponentState.ACTIVE), false));
116: }
117:
118: substanceIconLabel = new OptionPaneLabel();
119: substanceIconLabel.setIcon(new GlowingIcon(sideIcon,
120: substanceIconLabel));
121:
122: substanceIconLabel.setName("OptionPane.iconLabel");
123: substanceIconLabel.setVerticalAlignment(SwingConstants.TOP);
124: top
125: .add(substanceIconLabel,
126: BorderLayout.BEFORE_LINE_BEGINS);
127: }
128: }
129:
130: /*
131: * (non-Javadoc)
132: *
133: * @see javax.swing.plaf.basic.BasicOptionPaneUI#getIconForType(int)
134: */
135: @Override
136: protected Icon getIconForType(int messageType) {
137: switch (messageType) {
138: case JOptionPane.ERROR_MESSAGE:
139: return SubstanceCoreUtilities
140: .getIcon("resource/32/dialog-error.png");
141: case JOptionPane.INFORMATION_MESSAGE:
142: return SubstanceCoreUtilities
143: .getIcon("resource/32/dialog-information.png");
144: case JOptionPane.WARNING_MESSAGE:
145: return SubstanceCoreUtilities
146: .getIcon("resource/32/dialog-warning.png");
147: case JOptionPane.QUESTION_MESSAGE:
148: return SubstanceCoreUtilities
149: .getIcon("resource/32/help-browser.png");
150: }
151: return null;
152: }
153:
154: /*
155: * (non-Javadoc)
156: *
157: * @see javax.swing.plaf.basic.BasicOptionPaneUI#installComponents()
158: */
159: @Override
160: protected void installComponents() {
161: super .installComponents();
162: // fix for defect 265 - check that the label is not null
163: // before activating the loop.
164: if (this .substanceIconLabel != null) {
165: // Make the icon glow for three cycles. There's no need to
166: // explicitly cancel the animation when the option pane is closed
167: // before the animation is over - when the three cycles are up,
168: // the animation will be removed by the tracker.
169: FadeTracker.getInstance().trackFadeLooping(
170: FadeKind.ICON_GLOW,
171: LafWidgetUtilities
172: .getAnimationKind(this .optionPane).derive(
173: 0.1f), this .substanceIconLabel,
174: null, false, null, 3, true);
175: }
176: }
177: }
|