1
package org.pushingpixels.lafwidget.tabbed;
4
import java.awt.image.BufferedImage;
7
import javax.swing.border.*;
9
import org.pushingpixels.lafwidget.animation.AnimationConfigurationManager;
10
import org.pushingpixels.lafwidget.utils.ShadowPopupBorder;
11
import org.pushingpixels.trident.Timeline;
14
* Control to display the a single tab preview.
16
* @author Kirill Grouchnikov
18
public class TabPreviewControl extends JPanel {
20
* Label for the tab icon.
22
protected JLabel iconLabel;
25
* Label for the tab title.
27
protected JLabel titleLabel;
30
* Panel for the tab preview image.
32
protected JPanel previewImagePanel;
35
* The preview image itself.
37
protected BufferedImage previewImage;
40
* The associated tabbed pane.
42
protected JTabbedPane tabPane;
49
* Creates a tab preview control.
56
public TabPreviewControl(final JTabbedPane tabPane, final int tabIndex) {
57
this.tabPane = tabPane;
58
this.setLayout(new TabPreviewControlLayout());
59
this.iconLabel = new JLabel(tabPane.getIconAt(tabIndex));
60
this.titleLabel = new JLabel(tabPane.getTitleAt(tabIndex));
62
.setFont(this.titleLabel.getFont().deriveFont(Font.BOLD));
64
// the panel with the preview image - perhaps use JLabel
66
this.previewImagePanel = new JPanel() {
68
public void paintComponent(Graphics g) {
69
super.paintComponent(g);
73
this.add(this.iconLabel);
74
this.add(this.titleLabel);
75
this.add(this.previewImagePanel);
77
final boolean isSelected = (tabPane.getSelectedIndex() == tabIndex);
78
Border innerBorder = isSelected ? new LineBorder(Color.black, 2)
79
: new LineBorder(Color.black, 1);
81
.setBorder(new CompoundBorder(new ShadowPopupBorder(),
89
* Paints the tab thumbnail on the specified graphics context.
94
public synchronized void paintTabThumbnail(Graphics g) {
95
if (TabPreviewControl.this.previewImage != null) {
96
int pw = TabPreviewControl.this.previewImage.getWidth();
97
int ph = TabPreviewControl.this.previewImage.getHeight();
98
int w = this.previewImagePanel.getWidth();
99
int h = this.previewImagePanel.getHeight();
101
Graphics2D g2 = (Graphics2D) g.create();
102
g2.setComposite(AlphaComposite.SrcOver.derive(alpha));
103
int dx = (w - pw) / 2;
104
int dy = (h - ph) / 2;
105
g2.drawImage(TabPreviewControl.this.previewImage, dx, dy, null);
111
* Stes the tab index.
116
public void setTabIndex(int tabIndex) {
117
this.iconLabel.setIcon(this.tabPane.getIconAt(tabIndex));
118
this.titleLabel.setText(this.tabPane.getTitleAt(tabIndex));
119
final boolean isSelected = (this.tabPane.getSelectedIndex() == tabIndex);
120
Border innerBorder = isSelected ? new LineBorder(Color.black, 2)
121
: new LineBorder(Color.black, 1);
123
.setBorder(new CompoundBorder(new ShadowPopupBorder(),
128
* Layout for the tab preview control.
130
* @author Kirill Grouchnikov
132
protected class TabPreviewControlLayout implements LayoutManager {
136
* @see java.awt.LayoutManager#addLayoutComponent(java.lang.String,
137
* java.awt.Component)
140
public void addLayoutComponent(String name, Component comp) {
146
* @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
149
public void removeLayoutComponent(Component comp) {
155
* @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
158
public void layoutContainer(Container parent) {
159
int width = parent.getWidth();
160
int height = parent.getHeight();
162
Insets insets = TabPreviewControl.this.getInsets();
163
TabPreviewControl.this.iconLabel.setBounds(insets.left + 1,
164
insets.top + 1, 16, 16);
165
TabPreviewControl.this.titleLabel
166
.setBounds(insets.left + 18, insets.top + 1, width - 18
167
- insets.left - insets.right, 16);
168
TabPreviewControl.this.previewImagePanel.setBounds(insets.left + 1,
169
insets.top + 17, width - insets.left - insets.right - 2,
170
height - 17 - insets.top - insets.bottom);
176
* @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
179
public Dimension minimumLayoutSize(Container parent) {
180
return parent.getSize();
186
* @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
189
public Dimension preferredLayoutSize(Container parent) {
190
return this.minimumLayoutSize(parent);
195
* Sets the tab preview thumbnail.
197
* @param previewImage
198
* Tab preview thumbnail.
200
* if <code>true</code>, the image will be faded-in.
202
public void setPreviewImage(BufferedImage previewImage, boolean toAnimate) {
203
this.previewImage = previewImage;
205
Timeline fadeTimeline = new Timeline(this);
206
AnimationConfigurationManager.getInstance().configureTimeline(
208
fadeTimeline.addPropertyToInterpolate("alpha", 0.0f, 1.0f);
213
public void setAlpha(float alpha) {
218
public void setZoom(float zoom) {
222
public float getZoom() {
b'\\ No newline at end of file'