~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance-swingx/src/main/java/org/pushingpixels/substance/swingx/SubstanceTipOfTheDayUI.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2005-2010 Kirill Grouchnikov, based on work by
 
3
 * Sun Microsystems, Inc. All rights reserved.
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
package org.pushingpixels.substance.swingx;
 
20
 
 
21
import java.awt.BorderLayout;
 
22
import java.awt.event.MouseAdapter;
 
23
import java.awt.event.MouseEvent;
 
24
 
 
25
import javax.swing.*;
 
26
import javax.swing.plaf.ComponentUI;
 
27
 
 
28
import org.jdesktop.swingx.JXHeader;
 
29
import org.jdesktop.swingx.JXTipOfTheDay;
 
30
import org.jdesktop.swingx.plaf.UIManagerExt;
 
31
import org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI;
 
32
import org.pushingpixels.lafwidget.animation.AnimationConfigurationManager;
 
33
import org.pushingpixels.lafwidget.animation.AnimationFacet;
 
34
import org.pushingpixels.substance.api.DecorationAreaType;
 
35
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
 
36
import org.pushingpixels.substance.internal.animation.IconGlowTracker;
 
37
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
 
38
import org.pushingpixels.substance.internal.utils.icon.GlowingIcon;
 
39
 
 
40
/**
 
41
 * Substance-consistent UI delegate for {@link JXTipOfTheDay}.
 
42
 * 
 
43
 * @author Kirill Grouchnikov
 
44
 */
 
45
public class SubstanceTipOfTheDayUI extends BasicTipOfTheDayUI {
 
46
        static {
 
47
                AnimationConfigurationManager.getInstance().allowAnimations(AnimationFacet.ICON_GLOW,
 
48
                                JXTipOfTheDay.class);
 
49
        }
 
50
 
 
51
        protected IconGlowTracker iconGlowTracker;
 
52
 
 
53
        public static ComponentUI createUI(JComponent comp) {
 
54
                SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
 
55
                return new SubstanceTipOfTheDayUI((JXTipOfTheDay) comp);
 
56
        }
 
57
 
 
58
        /**
 
59
         * Creates a new UI delegate.
 
60
         * 
 
61
         * @param tip
 
62
         *            Tip component.
 
63
         */
 
64
        public SubstanceTipOfTheDayUI(JXTipOfTheDay tip) {
 
65
                super(tip);
 
66
        }
 
67
 
 
68
        /*
 
69
         * (non-Javadoc)
 
70
         * 
 
71
         * @see
 
72
         * org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI#installComponents()
 
73
         */
 
74
        @Override
 
75
        protected void installComponents() {
 
76
                tipPane.setLayout(new BorderLayout());
 
77
 
 
78
                // tip area
 
79
                JPanel mainPane = new JPanel(new BorderLayout());
 
80
                JXHeader didYouKnow = new JXHeader();
 
81
                didYouKnow.setTitle(UIManagerExt.getString(
 
82
                                "TipOfTheDay.didYouKnowText", tipPane.getLocale()));
 
83
                SubstanceLookAndFeel.setDecorationType(didYouKnow,
 
84
                                DecorationAreaType.GENERAL);
 
85
 
 
86
                Icon infoIcon = SubstanceLookAndFeel.isToUseConstantThemesOnDialogs() ? SubstanceCoreUtilities
 
87
                                .getIcon("resource/22/dialog-information.png")
 
88
                                : SubstanceCoreUtilities.getThemedIcon(this.tipPane,
 
89
                                                SubstanceCoreUtilities
 
90
                                                                .getIcon("resource/22/dialog-information.png"));
 
91
 
 
92
                this.iconGlowTracker = new IconGlowTracker(didYouKnow);
 
93
                didYouKnow.setIcon(new GlowingIcon(infoIcon, this.iconGlowTracker));
 
94
                didYouKnow.setDescription("");
 
95
 
 
96
                didYouKnow.addMouseListener(new MouseAdapter() {
 
97
                        @Override
 
98
                        public void mouseEntered(MouseEvent e) {
 
99
                                iconGlowTracker.play();
 
100
                        }
 
101
 
 
102
                        @Override
 
103
                        public void mouseExited(MouseEvent e) {
 
104
                                iconGlowTracker.cancel();
 
105
                        }
 
106
                });
 
107
 
 
108
                mainPane.add("North", didYouKnow);
 
109
 
 
110
                tipArea = new JPanel(new BorderLayout());
 
111
                tipArea.setOpaque(false);
 
112
                tipArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
 
113
                tipArea.setBackground(UIManager.getColor("TextArea.background"));
 
114
                mainPane.add("Center", tipArea);
 
115
 
 
116
                tipPane.add("Center", mainPane);
 
117
        }
 
118
}