📄 shadowpainter.java
字号:
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: ShadowPainter.java,v 1.9 2005/12/04 13:46:05 jesper Exp $
package net.infonode.tabbedpanel.internal;
import net.infonode.gui.ComponentUtil;
import net.infonode.gui.GraphicsUtil;
import net.infonode.gui.UIManagerUtil;
import net.infonode.util.ColorUtil;
import net.infonode.util.Direction;
import javax.swing.*;
import java.awt.*;
/**
* @author $Author: jesper $
* @version $Revision: 1.9 $
* @since ITP 1.1.0
*/
public class ShadowPainter {
private Color panelBackgroundColor;
private Color tabBackgroundColor;
private Component component;
private JComponent componentsPanel;
private JComponent highlightedTab;
private JComponent contentPanel;
private JComponent tabAreaComponentsPanel;
private JComponent tabAreaContainer;
private JComponent tabBox;
private Direction tabOrientation;
private boolean paintTabAreaShadow;
private int shadowSize;
private int shadowBlendSize;
private Color shadowColor;
private float shadowStrength;
private boolean highlightedTabIsLast;
public ShadowPainter(Component component, JComponent componentsPanel, JComponent highlightedTab,
JComponent contentPanel, JComponent tabAreaComponentsPanel, JComponent tabAreaContainer,
JComponent tabBox, Direction tabOrientation, boolean paintTabAreaShadow,
int shadowSize, int shadowBlendSize, Color shadowColor,
float shadowStrength, boolean highlightedTabIsLast) {
this.component = component;
this.componentsPanel = componentsPanel;
this.highlightedTab = highlightedTab == null ?
null : !highlightedTab.isVisible() || !tabAreaContainer.isVisible() ? null : highlightedTab;
this.contentPanel = contentPanel;
this.tabAreaComponentsPanel = tabAreaComponentsPanel;
this.tabAreaContainer = tabAreaContainer;
this.tabBox = tabBox;
this.tabOrientation = tabOrientation;
this.paintTabAreaShadow = paintTabAreaShadow && tabAreaContainer.isVisible();
this.shadowSize = shadowSize;
this.shadowBlendSize = shadowBlendSize;
this.shadowColor = shadowColor;
this.shadowStrength = shadowStrength;
this.highlightedTabIsLast = highlightedTabIsLast;
}
public void paint(Graphics g) {
panelBackgroundColor = ComponentUtil.getBackgroundColor(component);
panelBackgroundColor = panelBackgroundColor == null ?
UIManagerUtil.getColor("Panel.background", "control") : panelBackgroundColor;
if (paintTabAreaShadow) {
Rectangle bounds = SwingUtilities.calculateInnerArea(componentsPanel, new Rectangle());
// Right shadow
drawBottomRightEdgeShadow(g, bounds.y, bounds.x + bounds.width, bounds.height, true, panelBackgroundColor);
// Bottom shadow
drawBottomRightEdgeShadow(g, bounds.x, bounds.y + bounds.height, bounds.width, false, panelBackgroundColor);
// Bottom right corner
drawRightCornerShadow(g, bounds.x + bounds.width, bounds.y + bounds.height, false, panelBackgroundColor);
}
else {
tabBackgroundColor = highlightedTab == null ?
panelBackgroundColor :
ComponentUtil.getBackgroundColor(highlightedTab.getParent());
tabBackgroundColor = tabBackgroundColor == null ? panelBackgroundColor : tabBackgroundColor;
Rectangle contentPanelBounds = contentPanel.getBounds();
int len = 0;
if (highlightedTab != null)
len = paintHighlightedTabShadow(g, tabOrientation, contentPanelBounds);
if (tabAreaComponentsPanel.isVisible()) {
len = tabOrientation.isHorizontal() ?
(tabAreaContainer.getInsets().bottom == 0 ? tabAreaComponentsPanel.getWidth() : 0) :
(tabAreaContainer.getInsets().right == 0 ? tabAreaComponentsPanel.getHeight() : 0);
}
if (!tabAreaContainer.isVisible())
len = 0;
if (tabOrientation != Direction.RIGHT || highlightedTab == null)
drawBottomRightEdgeShadow(g,
contentPanelBounds.y - (tabOrientation == Direction.UP ? len : 0),
contentPanelBounds.x + contentPanelBounds.width,
contentPanelBounds.height + (!tabOrientation.isHorizontal() ? len : 0),
true,
highlightedTab == null ? null : panelBackgroundColor);
if (tabOrientation != Direction.DOWN || highlightedTab == null)
drawBottomRightEdgeShadow(g,
contentPanelBounds.x - (tabOrientation == Direction.LEFT ? len : 0),
contentPanelBounds.y + contentPanelBounds.height,
contentPanelBounds.width + (tabOrientation.isHorizontal() ? len : 0),
false,
highlightedTab == null ? null : panelBackgroundColor);
drawRightCornerShadow(g,
contentPanelBounds.x + contentPanelBounds.width + (tabOrientation == Direction.RIGHT ?
len : 0),
contentPanelBounds.y + contentPanelBounds.height + (tabOrientation == Direction.DOWN ?
len : 0),
false,
panelBackgroundColor);
}
}
private int paintHighlightedTabShadow(Graphics g, Direction tabOrientation, Rectangle contentPanelBounds) {
Point p = SwingUtilities.convertPoint(highlightedTab.getParent(), highlightedTab.getLocation(), component);
// JComponent tabBox = draggableComponentBox;
Dimension tabsSize = tabBox.getSize();
Rectangle bounds = tabAreaComponentsPanel.isVisible() ?
SwingUtilities.convertRectangle(tabAreaComponentsPanel.getParent(),
tabAreaComponentsPanel.getBounds(),
component) :
new Rectangle(contentPanelBounds.x + contentPanelBounds.width,
contentPanelBounds.y + contentPanelBounds.height,
0,
0);
Point tabsPos = SwingUtilities.convertPoint(tabBox, 0, 0, component);
// Set tab clip
int width = (tabOrientation.isHorizontal() ? 0 : tabsPos.x) + tabsSize.width;
int height = (tabOrientation.isHorizontal() ? tabsPos.y : 0) + tabsSize.height;
if (tabOrientation == Direction.DOWN)
drawBottomRightTabShadow(g,
contentPanelBounds.x,
contentPanelBounds.y + contentPanelBounds.height,
contentPanelBounds.width,
p.x,
highlightedTab.getWidth(),
highlightedTab.getHeight(),
bounds.x,
bounds.width,
bounds.height,
false,
highlightedTabIsLast);
else if (tabOrientation == Direction.RIGHT)
drawBottomRightTabShadow(g,
contentPanelBounds.y,
contentPanelBounds.x + contentPanelBounds.width,
contentPanelBounds.height,
p.y,
highlightedTab.getHeight(),
highlightedTab.getWidth(),
bounds.y,
bounds.height,
bounds.width,
true,
highlightedTabIsLast);
else if (tabOrientation == Direction.UP) {
drawTopLeftTabShadow(g,
p.x + highlightedTab.getWidth(),
p.y, highlightedTab.getHeight(),
bounds,
contentPanelBounds.width,
false,
highlightedTabIsLast);
}
else
drawTopLeftTabShadow(g,
p.y + highlightedTab.getHeight(),
p.x,
highlightedTab.getWidth(),
flipRectangle(bounds),
contentPanelBounds.height,
true,
highlightedTabIsLast);
if (highlightedTabIsLast) {
return tabOrientation.isHorizontal() ? (p.y + highlightedTab.getHeight() >= contentPanelBounds.height &&
contentPanelBounds.height == height ? highlightedTab.getWidth() : 0) :
(p.x + highlightedTab.getWidth() >= contentPanelBounds.width &&
contentPanelBounds.width == width ? highlightedTab.getHeight() : 0);
}
else
return 0;
}
private static Rectangle flipRectangle(Rectangle bounds) {
return new Rectangle(bounds.y, bounds.x, bounds.height, bounds.width);
}
private static Rectangle createRectangle(int x, int y, int width, int height, boolean flip) {
return flip ? new Rectangle(y, x, height, width) : new Rectangle(x, y, width, height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -