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

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/ui/SubstanceOptionPaneUI.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 (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 *  o Redistributions of source code must retain the above copyright notice,
 
8
 *    this list of conditions and the following disclaimer.
 
9
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
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.
 
29
 */
 
30
package org.pushingpixels.substance.internal.ui;
 
31
 
 
32
import java.awt.*;
 
33
 
 
34
import javax.swing.*;
 
35
import javax.swing.plaf.ComponentUI;
 
36
import javax.swing.plaf.basic.BasicOptionPaneUI;
 
37
 
 
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;
 
45
 
 
46
/**
 
47
 * UI for option panes in <b>Substance</b> look and feel.
 
48
 * 
 
49
 * @author Kirill Grouchnikov
 
50
 */
 
51
public class SubstanceOptionPaneUI extends BasicOptionPaneUI {
 
52
        static {
 
53
                AnimationConfigurationManager.getInstance().allowAnimations(
 
54
                                AnimationFacet.ICON_GLOW, OptionPaneLabel.class);
 
55
        }
 
56
 
 
57
        /**
 
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
 
64
         * class.
 
65
         * 
 
66
         * @author Kirill Grouchnikov
 
67
         */
 
68
        protected static class OptionPaneLabel extends JLabel {
 
69
        }
 
70
 
 
71
        /**
 
72
         * Icon label.
 
73
         */
 
74
        private OptionPaneLabel substanceIconLabel;
 
75
 
 
76
        private IconGlowTracker iconGlowTracker;
 
77
 
 
78
        /**
 
79
         * Creates a new SubstanceOptionPaneUI instance.
 
80
         */
 
81
        public static ComponentUI createUI(JComponent comp) {
 
82
                SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
 
83
                return new SubstanceOptionPaneUI();
 
84
        }
 
85
 
 
86
        /*
 
87
         * (non-Javadoc)
 
88
         * 
 
89
         * @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics,
 
90
         * javax.swing.JComponent)
 
91
         */
 
92
        @Override
 
93
        public void paint(Graphics g, JComponent c) {
 
94
                BackgroundPaintingUtils.updateIfOpaque(g, c);
 
95
        }
 
96
 
 
97
        /*
 
98
         * (non-Javadoc)
 
99
         * 
 
100
         * @see javax.swing.plaf.basic.BasicOptionPaneUI#addIcon(java.awt.Container)
 
101
         */
 
102
        @Override
 
103
        protected void addIcon(Container top) {
 
104
                Icon sideIcon = (optionPane == null ? null : optionPane.getIcon());
 
105
 
 
106
                if (sideIcon == null && optionPane != null)
 
107
                        sideIcon = super.getIconForType(optionPane.getMessageType());
 
108
 
 
109
                if (sideIcon != null) {
 
110
                        if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) {
 
111
                                sideIcon = SubstanceCoreUtilities.getThemedIcon(null, sideIcon);
 
112
                        }
 
113
 
 
114
                        this.substanceIconLabel = new OptionPaneLabel();
 
115
                        this.iconGlowTracker = new IconGlowTracker(substanceIconLabel);
 
116
                        this.substanceIconLabel.setIcon(new GlowingIcon(sideIcon,
 
117
                                        this.iconGlowTracker));
 
118
 
 
119
                        this.substanceIconLabel.setName("OptionPane.iconLabel");
 
120
                        this.substanceIconLabel.setVerticalAlignment(SwingConstants.TOP);
 
121
                        top.add(this.substanceIconLabel, BorderLayout.BEFORE_LINE_BEGINS);
 
122
                }
 
123
        }
 
124
 
 
125
        /*
 
126
         * (non-Javadoc)
 
127
         * 
 
128
         * @see javax.swing.plaf.basic.BasicOptionPaneUI#getIconForType(int)
 
129
         */
 
130
        @Override
 
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");
 
145
                }
 
146
                return null;
 
147
        }
 
148
 
 
149
        /*
 
150
         * (non-Javadoc)
 
151
         * 
 
152
         * @see javax.swing.plaf.basic.BasicOptionPaneUI#installComponents()
 
153
         */
 
154
        @Override
 
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);
 
166
                        }
 
167
                }
 
168
        }
 
169
}