📄 paneui.java
字号:
for (int i = 0; i < 4; i++)
pane.addTab(EMPTY_STRING, SizeIcon.EMPTY, getComponent());
pane.setSelectedIndex(-1);
pane.setSize(pane.getMinimumSize());
pane.doValidation();
if (!direction.isHorizontal()) {
int width = pane.getWidth() - 1;
boolean found = false;
while (!found) {
width++;
pane.setSize(width, pane.getHeight());
pane.doValidation();
found = pane.getBoundsAt(0).y == pane.getBoundsAt(3).y;
}
Rectangle endBounds = pane.getBoundsAt(3);
right = pane.getWidth() - endBounds.x - endBounds.width - spacings[index];
}
else {
int height = pane.getHeight() - 1;
boolean found = false;
while (!found) {
height++;
pane.setSize(pane.getWidth(), height);
pane.doValidation();
found = pane.getBoundsAt(0).x == pane.getBoundsAt(3).x;
}
Rectangle endBounds = pane.getBoundsAt(3);
bottom = pane.getHeight() - endBounds.y - endBounds.height - spacings[index];
}
areaInsets[index] = new Insets(top, left, bottom, right);
pane.setSize(size);
pane.doValidation();
}
}
private void estimateContentTabAreaBorderColor(PanePainter pane, int index, final Direction direction) {
Dimension preSize = pane.getSize();
reset(pane);
pane.addTab(EMPTY_STRING, SizeIcon.EMPTY, getComponent());
pane.setSelectedIndex(-1);
Dimension size = pane.getMinimumSize();
if (direction.isHorizontal())
pane.setSize(size.width, size.height * 2);
else
pane.setSize(size.width * 2, size.height);
pane.doValidation();
Rectangle tabBounds = pane.getBoundsAt(0);
BufferedImage img = new BufferedImage(pane.getWidth(), pane.getHeight(), BufferedImage.TYPE_INT_ARGB);
int x = 0;
int y = 0;
if (direction == Direction.UP) {
x = tabBounds.x + (tabBounds.width / 2);
y = pane.getHeight() - contentInsets[index].top - contentInsets[index].bottom - 1;
}
else if (direction == Direction.DOWN) {
x = tabBounds.x + (tabBounds.width / 2);
y = contentInsets[index].top + contentInsets[index].bottom;
}
else if (direction == Direction.LEFT) {
x = pane.getWidth() - contentInsets[index].left - contentInsets[index].right - 1;
y = tabBounds.y + (tabBounds.height / 2);
}
else {
x += contentInsets[index].left + contentInsets[index].right;
y = tabBounds.y + (tabBounds.height / 2);
}
final int px = x;
final int py = y;
RGBImageFilter colorFilter = new RGBImageFilter() {
public int filterRGB(int x, int y, int rgb) {
if (px == x && py == y) {
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = (rgb) & 0xff;
int a = (rgb >> 24) & 0xff;
contentTabAreaBorderColors[getDirectionIndex(direction.getOpposite())] = new Color(r, g, b, a);
}
return rgb;
}
};
FilteredImageSource source = new FilteredImageSource(img.getSource(), colorFilter);
pane.paint(img.getGraphics());
BufferedImage img2 = new BufferedImage(pane.getWidth(), pane.getHeight(), BufferedImage.TYPE_INT_ARGB);
img2.getGraphics().drawImage(Toolkit.getDefaultToolkit().createImage(source), 0, 0, null);
pane.setSize(preSize);
pane.doValidation();
}
private void estimateSwappedTabDirection(PanePainter pane, int index, final Direction direction) {
reset(pane);
SizeIcon icon = new SizeIcon(80, 80);
SizeIcon icon2 = new SizeIcon(160, 80);
pane.addTab(EMPTY_STRING, icon, getComponent());
pane.doValidation();
Rectangle bounds = pane.getBoundsAt(0);
pane.setIconAt(0, icon2);
pane.doValidation();
Rectangle bounds2 = pane.getBoundsAt(0);
swapWidthHeights[index] = bounds2.height > 1.5 * bounds.height;
}
public boolean isContentOpaque() {
return contentOpaque;
}
public boolean isOpaque() {
return opaque;
}
public boolean isTabAreaComponentsOpaque() {
return tabAreaComponentsOpaque;
}
public boolean isTabAreaOpaque() {
return tabAreaOpaque;
}
public Font getFont() {
return paneHandler.getPainter(Direction.UP).getFont();
}
public boolean isSwapWidthHeight(Direction d) {
return swapWidthHeights[getDirectionIndex(d)];
}
public Insets getNormalInsets(Direction d) {
return normalInsets[getDirectionIndex(d)];
}
public Insets getSelectedInsets(Direction d) {
return selectedInsets[getDirectionIndex(d)];
}
public Insets getNormalTabInsets(Direction areaOrientation, Direction tabDirection) {
return getRealTabInsets(areaOrientation, tabDirection, getNormalInsets(areaOrientation));
}
public Insets getSelectedTabInsets(Direction areaOrientation, Direction tabDirection) {
return getRealTabInsets(areaOrientation, tabDirection, getSelectedInsets(areaOrientation));
}
private Insets getRealTabInsets(Direction areaOrientation, Direction tabDirection, Insets insets) {
insets = InsetsUtil.rotate(tabDirection, insets);
if (swapWidthHeights[getDirectionIndex(areaOrientation)]) {
insets = InsetsUtil.rotate(areaOrientation.getNextCCW(), insets);
}
return insets;
}
public Insets getContentInsets(Direction d, boolean tabAreaVisible) {
return tabAreaVisible ?
adjustedContentInsets[getDirectionIndex(d)] : adjustedContentInsetsTabAreaHidden[getDirectionIndex(d)];
}
public Insets getTabAreaInsets(Direction d) {
return areaInsets[getDirectionIndex(d)];
}
public Dimension getTabExternalMinSize(Direction d) {
return minimumSizes[getDirectionIndex(d)];
}
public Insets getTabInsets(Direction d) {
return tabInsets[getDirectionIndex(d)];
}
public int getTabSpacing(Direction d) {
return spacings[getDirectionIndex(d)];
}
public int getSelectedRaised(Direction d) {
return raiseds[getDirectionIndex(d)];
}
public Color getContentTabAreaBorderColor(Direction d) {
return contentTabAreaBorderColors[getDirectionIndex(d)];
}
public int getTabSpacing() {
return 0;
}
public int getTextIconGap() {
return textIconGap;
}
public int getScrollOffset() {
return scrollOffset;
}
private int getWidthCompensate(Direction d) {
if (swapWidthHeights[getDirectionIndex(d)])
return 0;
return TEXT_ICON_GAP_COMPENSATE ? getTextIconGap() : 0;
}
private int getHeightCompensate(Direction d) {
if (!swapWidthHeights[getDirectionIndex(d)])
return 0;
return TEXT_ICON_GAP_COMPENSATE ? getTextIconGap() : 0;
}
private int getDirectionIndex(Direction d) {
for (int i = 0; i < DIRECTIONS.length; i++)
if (DIRECTIONS[i] == d)
return i;
return 0;
}
private Insets getCalculatedInsets(PanePainter pane, int index, boolean selected, Direction direction) {
Rectangle b = pane.getBoundsAt(index);
final int sizer = b.height + b.width;
Icon icon = pane.getIconAt(index);
pane.setIconAt(index, new SizeIcon(sizer, sizer));
if (selected)
pane.setSelectedIndex(index);
Rectangle bounds = pane.getBoundsAt(index);
pane.setIconAt(index, icon);
pane.setSelectedIndex(DEFAULT_SELECTED_INDEX);
int height = bounds.height - sizer - getHeightCompensate(direction);
int width = bounds.width - sizer - getWidthCompensate(direction);
int top = height / 2;
int left = width / 2 + width % 2;
int bottom = height / 2 + height % 2;
int right = width / 2;
return new Insets(top, left, bottom, right);
}
public void setHoveredTab(Tab tab) {
if (enabled) {
if (tab != hoveredTab) {
if (hoveredTab != null && hoveredTab.getTabbedPanel() != null)
findDraggableComponentBox(hoveredTab).getParent().repaint();
hoveredTab = tab;
if (hoveredTab != null && hoveredTab.getTabbedPanel() != null)
findDraggableComponentBox(hoveredTab).getParent().repaint();
}
}
}
public void paintTabArea(TabbedPanel tp, Graphics g, int x, int y, int width, int height) {
if (enabled) {
if (tp.isTabAreaVisible()) {
tabData.initialize(tp);
PanePainter pane = paneHandler.getPainter(tabData.getAreaOrientation());
initTabLocations(pane);
Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation());
if (tp.getTabCount() > 0) {
// Adjust x, y
if (tabData.getAreaOrientation() == Direction.DOWN) {
y += tabData.getTabbedPanelHeight() - height;
}
else if (tabData.getAreaOrientation() == Direction.RIGHT) {
x += tabData.getTabbedPanelWidth() - width;
}
width = x < 0 ? width + x : width;
height = y < 0 ? height + y : height;
x = Math.max(0, x);
y = Math.max(0, y);
if (tabData.isHorizontalLayout())
pane.setSize(tabData.getTabbedPanelSize().width, getTabbedPanelExtraSize());
else
pane.setSize(getTabbedPanelExtraSize(), tabData.getTabbedPanelHeight());
if (PAINT_TAB_AREA && !(pane.getTabCount() == 0 && tabData.getTabCount() > 0)) {
Shape originalClip = g.getClip();
int tx = -x
- (tabData.getAreaOrientation() == Direction.RIGHT ?
-tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize() : 0);
int ty = -y
- (tabData.getAreaOrientation() == Direction.DOWN ?
-tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize() : 0);
Rectangle firstVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(0);
Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1);
Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabCount() - 1);
if (tabData.isHorizontalLayout()) {
int extraWidth = lastTab.getWidth() == lastVisibleRect.width ? 0 : 2 * tabData.getTabbedPanelSize()
.width
- tabData.getTabAreaWidth();
pane.setSize(pane.getWidth() + extraWidth, pane.getHeight());
pane.doValidation();
// Before tabs
g.clipRect(0, 0, aInsets.left + (firstVisibleRect.width > 0 && firstVisibleRect.x == 0 ? 1 : 0), height);
pane.paint(g, tx, ty);
g.setClip(originalClip);
// After tabs
tx -= extraWidth;
int clipExtraWidth = extraWidth == 0 ? 1 : 0;
g.clipRect(aInsets.left + tabData.getTabAreaWidth() - clipExtraWidth, 0, width - aInsets.left - tabData.getTabAreaWidth()
+ clipExtraWidth, height);
pane.paint(g, tx, ty);
g.setClip(originalClip);
}
else {
int extraHeight = lastTab.getHeight() == lastVisibleRect.height ? 0 : 2 * tabData.getTabbedPanelSize()
.height
- tabData.getTabAreaHeight();
pane.setSize(pane.getWidth(), pane.getHeight() + extraHeight);
pane.doValidation();
// Before tabs
g.clipRect(0, 0, width, aInsets.top + (firstVisibleRect.height > 0 && firstVisibleRect.y == 0 ? 1 : 0));
pane.paint(g, tx, ty);
g.setClip(originalClip);
// After tabs
ty -= extraHeight;
int clipExtraHeight = extraHeight == 0 ? 1 : 0;
g.clipRect(0, aInsets.top + tabData.getTabAreaHeight() - clipExtraHeight, width, height - aInsets.top
- tabData.getTabAreaHeight() + clipExtraHeight);
pane.paint(g, tx, ty);
g.setClip(originalClip);
}
}
// First and last tab
paintTabs(pane, tabData, g, x, y, width, height, true);
tabData.reset();
reset(pane);
}
}
}
}
private void paintTabs(PanePainter pane, TabData tabData, Graphics g, int x, int y, int width, int height, boolean first) {
if (enabled) {
if (PAINT_TAB) {
Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabList().size() - 1);
Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1);
// Fix post/pre tabs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -