001: /*
002: * Copyright 2005-2008 Kirill Grouchnikov, based on work by
003: * Sun Microsystems, Inc. All rights reserved.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018: */
019: package org.jvnet.substance.swingx;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.MouseAdapter;
023: import java.awt.event.MouseEvent;
024:
025: import javax.swing.*;
026: import javax.swing.plaf.ComponentUI;
027:
028: import org.jdesktop.swingx.JXHeader;
029: import org.jdesktop.swingx.JXTipOfTheDay;
030: import org.jdesktop.swingx.plaf.UIManagerExt;
031: import org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI;
032: import org.jvnet.lafwidget.LafWidgetUtilities;
033: import org.jvnet.lafwidget.animation.*;
034: import org.jvnet.lafwidget.utils.LafConstants;
035: import org.jvnet.substance.SubstanceImageCreator;
036: import org.jvnet.substance.SubstanceLookAndFeel;
037: import org.jvnet.substance.painter.decoration.DecorationAreaType;
038: import org.jvnet.substance.painter.decoration.SubstanceDecorationUtilities;
039: import org.jvnet.substance.utils.SubstanceCoreUtilities;
040: import org.jvnet.substance.utils.icon.GlowingIcon;
041:
042: /**
043: * Substance-consistent UI delegate for {@link JXTipOfTheDay}.
044: *
045: * @author Kirill Grouchnikov
046: */
047: public class SubstanceTipOfTheDayUI extends BasicTipOfTheDayUI {
048: static {
049: FadeConfigurationManager.getInstance().allowFades(
050: FadeKind.ICON_GLOW, JXTipOfTheDay.class);
051: }
052:
053: public static ComponentUI createUI(JComponent c) {
054: return new SubstanceTipOfTheDayUI((JXTipOfTheDay) c);
055: }
056:
057: /**
058: * Creates a new UI delegate.
059: *
060: * @param tip
061: * Tip component.
062: */
063: public SubstanceTipOfTheDayUI(JXTipOfTheDay tip) {
064: super (tip);
065: }
066:
067: /*
068: * (non-Javadoc)
069: *
070: * @see org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI#installComponents()
071: */
072: @Override
073: protected void installComponents() {
074: tipPane.setLayout(new BorderLayout());
075:
076: // tip area
077: JPanel mainPane = new JPanel(new BorderLayout());
078: JXHeader didYouKnow = new JXHeader();
079: didYouKnow.setTitle(UIManagerExt.getString(
080: "TipOfTheDay.didYouKnowText", tipPane.getLocale()));
081: SubstanceDecorationUtilities.setDecorationType(didYouKnow,
082: DecorationAreaType.GENERAL);
083: // didYouKnow.putClientProperty(
084: // SubstanceCoreUtilities.IS_WINDOW_DECORATION_AREA, Boolean.TRUE);
085: // didYouKnow.putClientProperty(
086: // SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY, Boolean.TRUE);
087:
088: Icon infoIcon = SubstanceLookAndFeel
089: .isToUseConstantThemesOnDialogs() ? SubstanceCoreUtilities
090: .getIcon("resource/22/dialog-information.png")
091: : new ImageIcon(
092: SubstanceImageCreator
093: .getThemeImage(
094: this .tipPane,
095: SubstanceCoreUtilities
096: .getIcon("resource/22/dialog-information.png"),
097: SubstanceLookAndFeel.getTheme()
098: .getActiveTheme(),
099: false));
100:
101: didYouKnow.setIcon(new GlowingIcon(infoIcon, tipPane));
102: didYouKnow.setDescription("");
103:
104: didYouKnow.addMouseListener(new MouseAdapter() {
105: long glowFadeId = -1;
106:
107: @Override
108: public void mouseEntered(MouseEvent e) {
109: final LafConstants.AnimationKind currAnimKind = LafWidgetUtilities
110: .getAnimationKind(tipPane);
111: this .glowFadeId = FadeTracker.getInstance()
112: .trackFadeLooping(FadeKind.ICON_GLOW,
113: currAnimKind.derive(0.2f),
114: // LafWidgetUtilities.getAnimationKind(tipPane),
115: tipPane, null, false, null, -1, true);
116: }
117:
118: @Override
119: public void mouseExited(MouseEvent e) {
120: FadeTracker.getInstance().requestStopOnCycleBreak(
121: this .glowFadeId);
122: }
123: });
124:
125: mainPane.add("North", didYouKnow);
126:
127: tipArea = new JPanel(new BorderLayout());
128: tipArea.setOpaque(false);
129: tipArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
130: tipArea
131: .setBackground(UIManager
132: .getColor("TextArea.background"));
133: mainPane.add("Center", tipArea);
134:
135: tipPane.add("Center", mainPane);
136: }
137: }
|