~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/SubstanceDesktopIconUI.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.BorderLayout;
 
33
import java.awt.Dimension;
 
34
import java.awt.Font;
 
35
 
 
36
import javax.swing.JComponent;
 
37
import javax.swing.UIManager;
 
38
import javax.swing.JInternalFrame.JDesktopIcon;
 
39
import javax.swing.event.MouseInputListener;
 
40
import javax.swing.plaf.ComponentUI;
 
41
import javax.swing.plaf.UIResource;
 
42
import javax.swing.plaf.basic.BasicDesktopIconUI;
 
43
 
 
44
import org.pushingpixels.substance.api.DecorationAreaType;
 
45
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
 
46
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
 
47
import org.pushingpixels.substance.internal.utils.SubstanceInternalFrameTitlePane;
 
48
 
 
49
/**
 
50
 * UI for desktop icons in <b>Substance</b> look and feel.
 
51
 * 
 
52
 * @author Kirill Grouchnikov
 
53
 */
 
54
public class SubstanceDesktopIconUI extends BasicDesktopIconUI {
 
55
        /**
 
56
         * Listener on the title label (for the dragging purposes).
 
57
         */
 
58
        private MouseInputListener substanceLabelMouseInputListener;
 
59
 
 
60
        /**
 
61
         * Width of minimized component (desktop icon).
 
62
         */
 
63
        private int width;
 
64
 
 
65
        /*
 
66
         * (non-Javadoc)
 
67
         * 
 
68
         * @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
 
69
         */
 
70
        public static ComponentUI createUI(JComponent comp) {
 
71
                SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
 
72
                return new SubstanceDesktopIconUI();
 
73
        }
 
74
 
 
75
        /*
 
76
         * (non-Javadoc)
 
77
         * 
 
78
         * @see javax.swing.plaf.basic.BasicDesktopIconUI#installDefaults()
 
79
         */
 
80
        @Override
 
81
        protected void installDefaults() {
 
82
                super.installDefaults();
 
83
                Font f = this.desktopIcon.getFont();
 
84
                if ((f == null) || (f instanceof UIResource)) {
 
85
                        this.desktopIcon.setFont(UIManager.getFont("DesktopIcon.font"));
 
86
                }
 
87
                this.width = UIManager.getInt("DesktopIcon.width");
 
88
                this.desktopIcon.setBackground(SubstanceCoreUtilities.getSkin(
 
89
                                this.desktopIcon.getInternalFrame()).getBackgroundColorScheme(
 
90
                                DecorationAreaType.SECONDARY_TITLE_PANE)
 
91
                // SubstanceColorSchemeUtilities
 
92
                                // //.getColorScheme(this.desktopIcon.getInternalFrame(),
 
93
                                // ComponentState.ACTIVE).
 
94
                                .getBackgroundFillColor());
 
95
        }
 
96
 
 
97
        /*
 
98
         * (non-Javadoc)
 
99
         * 
 
100
         * @see javax.swing.plaf.basic.BasicDesktopIconUI#installComponents()
 
101
         */
 
102
        @Override
 
103
        protected void installComponents() {
 
104
                this.frame = this.desktopIcon.getInternalFrame();
 
105
                // this.frame.setOpaque(false);
 
106
                // Icon icon = this.frame.getFrameIcon();
 
107
 
 
108
                this.iconPane = new SubstanceInternalFrameTitlePane(this.frame);
 
109
                this.iconPane.setOpaque(false);
 
110
                this.desktopIcon.setLayout(new BorderLayout());
 
111
                this.desktopIcon.add(this.iconPane, BorderLayout.CENTER);
 
112
        }
 
113
 
 
114
        /*
 
115
         * (non-Javadoc)
 
116
         * 
 
117
         * @see javax.swing.plaf.basic.BasicDesktopIconUI#uninstallComponents()
 
118
         */
 
119
        @Override
 
120
        protected void uninstallComponents() {
 
121
                ((SubstanceInternalFrameTitlePane) this.iconPane).uninstall();
 
122
 
 
123
                this.desktopIcon.setLayout(null);
 
124
                this.desktopIcon.remove(this.iconPane);
 
125
 
 
126
                this.frame = null;
 
127
        }
 
128
 
 
129
        /*
 
130
         * (non-Javadoc)
 
131
         * 
 
132
         * @see javax.swing.plaf.basic.BasicDesktopIconUI#installListeners()
 
133
         */
 
134
        @Override
 
135
        protected void installListeners() {
 
136
                super.installListeners();
 
137
                this.substanceLabelMouseInputListener = this.createMouseInputListener();
 
138
                this.iconPane
 
139
                                .addMouseMotionListener(this.substanceLabelMouseInputListener);
 
140
                this.iconPane.addMouseListener(this.substanceLabelMouseInputListener);
 
141
        }
 
142
 
 
143
        /*
 
144
         * (non-Javadoc)
 
145
         * 
 
146
         * @see javax.swing.plaf.basic.BasicDesktopIconUI#uninstallListeners()
 
147
         */
 
148
        @Override
 
149
        protected void uninstallListeners() {
 
150
                ((SubstanceInternalFrameTitlePane) this.iconPane).uninstallListeners();
 
151
 
 
152
                this.iconPane
 
153
                                .removeMouseMotionListener(this.substanceLabelMouseInputListener);
 
154
                this.iconPane
 
155
                                .removeMouseListener(this.substanceLabelMouseInputListener);
 
156
                this.substanceLabelMouseInputListener = null;
 
157
 
 
158
                super.uninstallListeners();
 
159
        }
 
160
 
 
161
        /*
 
162
         * (non-Javadoc)
 
163
         * 
 
164
         * @see
 
165
         * javax.swing.plaf.ComponentUI#getPreferredSize(javax.swing.JComponent)
 
166
         */
 
167
        @Override
 
168
        public Dimension getPreferredSize(JComponent c) {
 
169
                // Desktop icons can not be resized. Their dimensions should
 
170
                // always be the minimum size. See getMinimumSize(JComponent c).
 
171
                return this.getMinimumSize(c);
 
172
        }
 
173
 
 
174
        /*
 
175
         * (non-Javadoc)
 
176
         * 
 
177
         * @see javax.swing.plaf.ComponentUI#getMinimumSize(javax.swing.JComponent)
 
178
         */
 
179
        @Override
 
180
        public Dimension getMinimumSize(JComponent c) {
 
181
                // For the desktop icon we will use the layout maanger to
 
182
                // determine the correct height of the component, but we want to keep
 
183
                // the width consistent according to the jlf spec.
 
184
                return new Dimension(this.width, this.desktopIcon.getLayout()
 
185
                                .minimumLayoutSize(this.desktopIcon).height);
 
186
        }
 
187
 
 
188
        /*
 
189
         * (non-Javadoc)
 
190
         * 
 
191
         * @see javax.swing.plaf.ComponentUI#getMaximumSize(javax.swing.JComponent)
 
192
         */
 
193
        @Override
 
194
        public Dimension getMaximumSize(JComponent c) {
 
195
                // Desktop icons can not be resized. Their dimensions should
 
196
                // always be the minimum size. See getMinimumSize(JComponent c).
 
197
                return this.getMinimumSize(c);
 
198
        }
 
199
 
 
200
        // /*
 
201
        // * (non-Javadoc)
 
202
        // *
 
203
        // * @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics,
 
204
        // * javax.swing.JComponent)
 
205
        // */
 
206
        // @Override
 
207
        // public void paint(Graphics g, JComponent c) {
 
208
        // JInternalFrame.JDesktopIcon di = (JInternalFrame.JDesktopIcon) c;
 
209
        // di.setOpaque(false);
 
210
        //
 
211
        // int width = di.getWidth();
 
212
        // int height = di.getHeight();
 
213
        //
 
214
        // Graphics2D graphics = (Graphics2D) g.create();
 
215
        // // the background is translucent
 
216
        // // graphics.setComposite(AlphaComposite.getInstance(
 
217
        // // AlphaComposite.SRC_ATOP, 0.6f));
 
218
        // //
 
219
        // // SubstanceImageCreator.paintRectangularBackground(graphics, 0, 0,
 
220
        // // width,
 
221
        // // height, SubstanceCoreUtilities.getActiveScheme(this.desktopIcon
 
222
        // // .getInternalFrame()), false, false);
 
223
        //
 
224
        // di.paintComponents(graphics);
 
225
        //
 
226
        // graphics.dispose();
 
227
        // }
 
228
        //
 
229
        // /*
 
230
        // * (non-Javadoc)
 
231
        // *
 
232
        // * @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics,
 
233
        // * javax.swing.JComponent)
 
234
        // */
 
235
        // @Override
 
236
        // public void update(Graphics g, JComponent c) {
 
237
        // this.paint(g, c);
 
238
        // }
 
239
        //
 
240
        /*
 
241
         * (non-Javadoc)
 
242
         * 
 
243
         * @see
 
244
         * javax.swing.plaf.basic.BasicDesktopIconUI#installUI(javax.swing.JComponent
 
245
         * )
 
246
         */
 
247
        @Override
 
248
        public void installUI(JComponent c) {
 
249
                super.installUI(c);
 
250
                c.setOpaque(false);
 
251
        }
 
252
 
 
253
        @Override
 
254
        public void uninstallUI(JComponent c) {
 
255
                // desktopIcon.remove(this.titleLabel);
 
256
                // super.uninstallUI(c);
 
257
 
 
258
                SubstanceInternalFrameTitlePane thePane = (SubstanceInternalFrameTitlePane) this.iconPane;
 
259
                super.uninstallUI(c);
 
260
                thePane.uninstallListeners();
 
261
        }
 
262
 
 
263
        /**
 
264
         * Returns the component for desktop icon hover (internal frame preview)
 
265
         * functionality.
 
266
         * 
 
267
         * @return The component for desktop icon hover (internal frame preview)
 
268
         *         functionality.
 
269
         */
 
270
        public JComponent getComponentForHover() {
 
271
                return this.iconPane;
 
272
        }
 
273
 
 
274
        /**
 
275
         * Installs the UI delegate on the desktop icon if necessary.
 
276
         * 
 
277
         * @param jdi
 
278
         *            Desktop icon.
 
279
         */
 
280
        public void installIfNecessary(JDesktopIcon jdi) {
 
281
                // fix for issue 344 - reopening an internal frame
 
282
                // that has been closed.
 
283
                if (this.desktopIcon == null) {
 
284
                        this.installUI(jdi);
 
285
                }
 
286
        }
 
287
 
 
288
        /**
 
289
         * Uninstalls the UI delegate from the desktop icon if necessary.
 
290
         * 
 
291
         * @param jdi
 
292
         *            Desktop icon.
 
293
         */
 
294
        public void uninstallIfNecessary(JDesktopIcon jdi) {
 
295
                // fix for issue 345 - an internal frame used in inner option pane
 
296
                // gets closed twice
 
297
                if (this.desktopIcon == jdi) {
 
298
                        this.uninstallUI(jdi);
 
299
                }
 
300
        }
 
301
 
 
302
        void setWindowModified(boolean isWindowModified) {
 
303
                ((SubstanceInternalFrameTitlePane) this.iconPane).getCloseButton()
 
304
                                .putClientProperty(SubstanceLookAndFeel.WINDOW_MODIFIED,
 
305
                        isWindowModified);
 
306
        }
 
307
}