2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
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.
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.
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.
30
package org.pushingpixels.substance.internal.ui;
32
import java.awt.BorderLayout;
33
import java.awt.Dimension;
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;
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;
50
* UI for desktop icons in <b>Substance</b> look and feel.
52
* @author Kirill Grouchnikov
54
public class SubstanceDesktopIconUI extends BasicDesktopIconUI {
56
* Listener on the title label (for the dragging purposes).
58
private MouseInputListener substanceLabelMouseInputListener;
61
* Width of minimized component (desktop icon).
68
* @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
70
public static ComponentUI createUI(JComponent comp) {
71
SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
72
return new SubstanceDesktopIconUI();
78
* @see javax.swing.plaf.basic.BasicDesktopIconUI#installDefaults()
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"));
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());
100
* @see javax.swing.plaf.basic.BasicDesktopIconUI#installComponents()
103
protected void installComponents() {
104
this.frame = this.desktopIcon.getInternalFrame();
105
// this.frame.setOpaque(false);
106
// Icon icon = this.frame.getFrameIcon();
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);
117
* @see javax.swing.plaf.basic.BasicDesktopIconUI#uninstallComponents()
120
protected void uninstallComponents() {
121
((SubstanceInternalFrameTitlePane) this.iconPane).uninstall();
123
this.desktopIcon.setLayout(null);
124
this.desktopIcon.remove(this.iconPane);
132
* @see javax.swing.plaf.basic.BasicDesktopIconUI#installListeners()
135
protected void installListeners() {
136
super.installListeners();
137
this.substanceLabelMouseInputListener = this.createMouseInputListener();
139
.addMouseMotionListener(this.substanceLabelMouseInputListener);
140
this.iconPane.addMouseListener(this.substanceLabelMouseInputListener);
146
* @see javax.swing.plaf.basic.BasicDesktopIconUI#uninstallListeners()
149
protected void uninstallListeners() {
150
((SubstanceInternalFrameTitlePane) this.iconPane).uninstallListeners();
153
.removeMouseMotionListener(this.substanceLabelMouseInputListener);
155
.removeMouseListener(this.substanceLabelMouseInputListener);
156
this.substanceLabelMouseInputListener = null;
158
super.uninstallListeners();
165
* javax.swing.plaf.ComponentUI#getPreferredSize(javax.swing.JComponent)
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);
177
* @see javax.swing.plaf.ComponentUI#getMinimumSize(javax.swing.JComponent)
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);
191
* @see javax.swing.plaf.ComponentUI#getMaximumSize(javax.swing.JComponent)
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);
203
// * @see javax.swing.plaf.ComponentUI#paint(java.awt.Graphics,
204
// * javax.swing.JComponent)
207
// public void paint(Graphics g, JComponent c) {
208
// JInternalFrame.JDesktopIcon di = (JInternalFrame.JDesktopIcon) c;
209
// di.setOpaque(false);
211
// int width = di.getWidth();
212
// int height = di.getHeight();
214
// Graphics2D graphics = (Graphics2D) g.create();
215
// // the background is translucent
216
// // graphics.setComposite(AlphaComposite.getInstance(
217
// // AlphaComposite.SRC_ATOP, 0.6f));
219
// // SubstanceImageCreator.paintRectangularBackground(graphics, 0, 0,
221
// // height, SubstanceCoreUtilities.getActiveScheme(this.desktopIcon
222
// // .getInternalFrame()), false, false);
224
// di.paintComponents(graphics);
226
// graphics.dispose();
232
// * @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics,
233
// * javax.swing.JComponent)
236
// public void update(Graphics g, JComponent c) {
244
* javax.swing.plaf.basic.BasicDesktopIconUI#installUI(javax.swing.JComponent
248
public void installUI(JComponent c) {
254
public void uninstallUI(JComponent c) {
255
// desktopIcon.remove(this.titleLabel);
256
// super.uninstallUI(c);
258
SubstanceInternalFrameTitlePane thePane = (SubstanceInternalFrameTitlePane) this.iconPane;
259
super.uninstallUI(c);
260
thePane.uninstallListeners();
264
* Returns the component for desktop icon hover (internal frame preview)
267
* @return The component for desktop icon hover (internal frame preview)
270
public JComponent getComponentForHover() {
271
return this.iconPane;
275
* Installs the UI delegate on the desktop icon if necessary.
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) {
289
* Uninstalls the UI delegate from the desktop icon if necessary.
294
public void uninstallIfNecessary(JDesktopIcon jdi) {
295
// fix for issue 345 - an internal frame used in inner option pane
297
if (this.desktopIcon == jdi) {
298
this.uninstallUI(jdi);
302
void setWindowModified(boolean isWindowModified) {
303
((SubstanceInternalFrameTitlePane) this.iconPane).getCloseButton()
304
.putClientProperty(SubstanceLookAndFeel.WINDOW_MODIFIED,