2
* Copyright (c) 2005-2010 Laf-Widget 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 Laf-Widget 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.lafwidget.tabbed;
33
import java.awt.image.BufferedImage;
35
import javax.swing.JTabbedPane;
37
import org.pushingpixels.lafwidget.LafWidgetUtilities;
40
* Default implementation of the tab preview painter. The tab preview is a
41
* scaled-down (as necessary) thumbnail of the relevant tab.
43
* @author Kirill Grouchnikov
45
public class DefaultTabPreviewPainter extends TabPreviewPainter {
49
* @see org.pushingpixels.lafwidget.tabbed.TabPreviewPainter#hasPreview(javax.swing.JTabbedPane,
53
public boolean hasPreview(JTabbedPane tabPane, int tabIndex) {
54
return (tabPane.getComponentAt(tabIndex) != null);
60
* @see org.pushingpixels.lafwidget.tabbed.TabPreviewPainter#isSensitiveToEvents(javax.swing.JTabbedPane,
64
public boolean isSensitiveToEvents(JTabbedPane tabPane, int tabIndex) {
65
return tabPane.isEnabledAt(tabIndex);
71
* @see org.pushingpixels.lafwidget.tabbed.TabPreviewPainter#previewTab(javax.swing.JTabbedPane,
72
* int, java.awt.Graphics, int, int, int, int)
75
public void previewTab(JTabbedPane tabPane, int tabIndex, Graphics g,
76
int x, int y, int w, int h) {
77
Component tabComponent = tabPane.getComponentAt(tabIndex);
78
if (tabComponent == null)
80
// if (!tabComponent.isShowing())
82
int compWidth = tabComponent.getWidth();
83
int compHeight = tabComponent.getHeight();
85
if ((compWidth > 0) && (compHeight > 0)) {
87
BufferedImage tempCanvas = new BufferedImage(compWidth, compHeight,
88
BufferedImage.TYPE_INT_ARGB);
89
Graphics tempCanvasGraphics = tempCanvas.getGraphics();
90
tabComponent.paint(tempCanvasGraphics);
92
// check if need to scale down
93
double coef = Math.min((double) w / (double) compWidth, (double) h
94
/ (double) compHeight);
95
// fix for issue 177 in Substance - disabled tabs painted in
97
Graphics2D g2 = (Graphics2D) g.create();
98
if (!tabPane.isEnabledAt(tabIndex)) {
99
g2.setComposite(AlphaComposite.getInstance(
100
AlphaComposite.SRC_OVER, 0.5f));
103
int sdWidth = (int) (coef * compWidth);
104
int sdHeight = (int) (coef * compHeight);
105
int dx = (w - sdWidth) / 2;
106
int dy = (h - sdHeight) / 2;
108
g2.drawImage(LafWidgetUtilities.createThumbnail(tempCanvas,
109
sdWidth), dx, dy, null);
112
// System.out.println("Putting " + frame.hashCode() + "
113
// -> " + snapshot.hashCode());
114
g2.drawImage(tempCanvas, 0, 0, null);
123
* @see org.pushingpixels.lafwidget.tabbed.TabPreviewPainter#hasPreviewWindow(javax.swing.JTabbedPane,
127
public boolean hasPreviewWindow(JTabbedPane tabPane, int tabIndex) {
134
* @see org.pushingpixels.lafwidget.tabbed.TabPreviewPainter#hasOverviewDialog(javax.swing.JTabbedPane)
137
public boolean hasOverviewDialog(JTabbedPane tabPane) {