📄 tabbedpaneui.java
字号:
FontMetrics metrics,
int tabIndex,
String title,
Rectangle textRect,
boolean isSelected)
{
g.setFont(font);
View v= getTextViewForTab(tabIndex);
if (v != null)
{
// html
v.paint(g, textRect);
}
else
{
// plain text
int mnemIndex= tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex))
{
g.setColor(tabPane.getForegroundAt(tabIndex));
BasicGraphicsUtils.drawStringUnderlineCharAt(
g,
title,
mnemIndex,
textRect.x,
textRect.y + metrics.getAscent());
}
else
{ // tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(
g,
title,
mnemIndex,
textRect.x,
textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(
g,
title,
mnemIndex,
textRect.x - 1,
textRect.y + metrics.getAscent() - 1);
}
}
}
protected int getTabLabelShiftX(
int tabPlacement,
int tabIndex,
boolean isSelected)
{
Rectangle tabRect= rects[tabIndex];
int nudge= 0;
// switch (tabPlacement)
// {
// case LEFT :
// nudge= isSelected ? -1 : 1;
// break;
// case RIGHT :
// nudge= isSelected ? 1 : -1;
// break;
// case BOTTOM :
// case TOP :
// default :
// nudge= tabRect.width % 2;
// }
return nudge;
}
protected int getTabLabelShiftY(
int tabPlacement,
int tabIndex,
boolean isSelected)
{
Rectangle tabRect= rects[tabIndex];
int nudge= 0;
// switch (tabPlacement)
// {
// case BOTTOM :
// nudge= isSelected ? 1 : -1;
// break;
// case LEFT :
// case RIGHT :
// nudge= tabRect.height % 2;
// break;
// case TOP :
// default :
// nudge= isSelected ? -1 : 1;
// ;
// }
return nudge;
}
protected void paintFocusIndicator(
Graphics g,
int tabPlacement,
Rectangle[] rects,
int tabIndex,
Rectangle iconRect,
Rectangle textRect,
boolean isSelected)
{
Rectangle tabRect= rects[tabIndex];
if (tabPane.hasFocus() && isSelected)
{
int x, y, w, h;
g.setColor(focus);
switch (tabPlacement)
{
case LEFT :
x= tabRect.x + 3;
y= tabRect.y + 3;
w= tabRect.width - 5;
h= tabRect.height - 6;
break;
case RIGHT :
x= tabRect.x + 2;
y= tabRect.y + 3;
w= tabRect.width - 5;
h= tabRect.height - 6;
break;
case BOTTOM :
x= tabRect.x + 3;
y= tabRect.y + 2;
w= tabRect.width - 6;
h= tabRect.height - 5;
break;
case TOP :
default :
x= tabRect.x + 3;
y= tabRect.y + 3;
w= tabRect.width - 6;
h= tabRect.height - 5;
}
BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
}
}
/**
* this function draws the border around each tab
* note that this function does now draw the background of the tab.
* that is done elsewhere
*/
protected void paintTabBorder(
Graphics g,
int tabPlacement,
int tabIndex,
int x,
int y,
int w,
int h,
boolean isSelected)
{
g.setColor(lightHighlight);
switch (tabPlacement)
{
case LEFT :
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// bottom-left highlight
g.drawLine(x, y + 2, x, y + h - 3); // left highlight
g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
g.drawLine(x + 2, y, x + w - 1, y); // top highlight
g.setColor(shadow);
g.drawLine(x + 2, y + h - 2, x + w - 1, y + h - 2);
// bottom shadow
g.setColor(darkShadow);
g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
// bottom dark shadow
break;
case RIGHT :
g.drawLine(x, y, x + w - 3, y); // top highlight
g.setColor(shadow);
g.drawLine(x, y + h - 2, x + w - 3, y + h - 2); // bottom shadow
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right shadow
g.setColor(darkShadow);
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
// top-right dark shadow
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
// bottom-right dark shadow
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);
// right dark shadow
g.drawLine(x, y + h - 1, x + w - 3, y + h - 1);
// bottom dark shadow
break;
case BOTTOM :
g.drawLine(x, y, x, y + h - 3); // left highlight
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// bottom-left highlight
g.setColor(shadow);
g.drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2);
// bottom shadow
g.drawLine(x + w - 2, y, x + w - 2, y + h - 3); // right shadow
g.setColor(darkShadow);
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1);
// bottom dark shadow
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
// bottom-right dark shadow
g.drawLine(x + w - 1, y, x + w - 1, y + h - 3);
// right dark shadow
break;
case TOP :
default :
// g.drawLine(x, y + 2, x, y + h - 1); // left highlight
// g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
// g.drawLine(x + 2, y, x + w - 3, y); // top highlight
//
// g.setColor(shadow);
// g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1); // right shadow
//
// g.setColor(darkShadow);
// g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);
// // right dark-shadow
// g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top-right shadow
}
}
protected void paintTabBackground(
Graphics g,
int tabPlacement,
int tabIndex,
int x,
int y,
int w,
int h,
boolean isSelected)
{
g.setColor(
!isSelected
|| selectedColor == null
? tabPane.getBackgroundAt(tabIndex)
: selectedColor);
switch (tabPlacement)
{
case LEFT :
g.fillRect(x + 1, y + 1, w - 2, h - 3);
break;
case RIGHT :
g.fillRect(x, y + 1, w - 2, h - 3);
break;
case BOTTOM :
g.fillRect(x + 1, y, w - 3, h - 1);
break;
case TOP :
default :
g.fillRect(x + 1, y + 1, w - 3, h - 1);
}
}
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex)
{
int width= tabPane.getWidth();
int height= tabPane.getHeight();
Insets insets= tabPane.getInsets();
int x= insets.left;
int y= insets.top;
int w= width - insets.right - insets.left;
int h= height - insets.top - insets.bottom;
switch (tabPlacement)
{
case LEFT :
x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
w -= (x - insets.left);
break;
case RIGHT :
w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
break;
case BOTTOM :
h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
break;
case TOP :
default :
y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
h -= (y - insets.top);
}
// Fill region behind content area
if (selectedColor == null)
{
g.setColor(tabPane.getBackground());
}
else
{
g.setColor(selectedColor);
}
g.fillRect(x, y, w, h);
paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
protected void paintContentBorderTopEdge(
Graphics g,
int tabPlacement,
int selectedIndex,
int x,
int y,
int w,
int h)
{
Rectangle selRect=
selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
g.setColor(borderColor);
// Draw unbroken line if tabs are not on TOP, OR
// selected tab is not in run adjacent to content, OR
// selected tab is not visible (SCROLL_TAB_LAYOUT)
//
if (tabPlacement != TOP
|| selectedIndex < 0
|| (selRect.y + selRect.height + 1 < y)
|| (selRect.x < x || selRect.x > x + w))
{
g.drawLine(x, y, x + w - 2, y);
if(drawThickBorder)
g.drawLine(x, y+1, x + w - 2, y+1);
}
else
{
// Break line to show visual connection to selected tab
int delta=(drawThickBorder ? 1 : 0);
g.drawLine(x, y, selRect.x+delta, y);
if(drawThickBorder)
g.drawLine(x, y+1, selRect.x+1, y+1);
if (selRect.x + selRect.width < x + w - 2)
{
g.drawLine(selRect.x + selRect.width-delta, y, x + w - 2, y);
if(drawThickBorder)
g.drawLine(selRect.x + selRect.width-1, y+1, x + w - 2, y+1);
}
else
{
g.setColor(shadow);
g.drawLine(x + w - 2, y, x + w - 2, y);
if(drawThickBorder)
g.drawLine(x + w - 2, y+1, x + w - 2, y+1);
}
}
}
protected void paintContentBorderLeftEdge(
Graphics g,
int tabPlacement,
int selectedIndex,
int x,
int y,
int w,
int h)
{
Rectangle selRect=
selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
g.setColor(borderColor);
// Draw unbroken line if tabs are not on LEFT, OR
// selected tab is not in run adjacent to content, OR
// selected tab is not visible (SCROLL_TAB_LAYOUT)
//
if (tabPlacement != LEFT
|| selectedIndex < 0
|| (selRect.x + selRect.width + 1 < x)
|| (selRect.y < y || selRect.y > y + h))
{
g.drawLine(x, y, x, y + h - 2);
if(drawThickBorder)
g.drawLine(x+1, y, x+1, y + h - 2);
}
else
{
// Break line to show visual connection to selected tab
g.drawLine(x, y, x, selRect.y );
if(drawThickBorder)
g.drawLine(x+1, y, x+1, selRect.y );
if (selRect.y + selRect.height < y + h - 2)
{
g.drawLine(x, selRect.y + selRect.height, x, y + h - 2);
if(drawThickBorder)
g.drawLine(x+1, selRect.y + selRect.height, x+1, y + h - 2);
}
}
}
protected void paintContentBorderBottomEdge(
Graphics g,
int tabPlacement,
int selectedIndex,
int x,
int y,
int w,
int h)
{
Rectangle selRect=
selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
g.setColor(borderColor);
// Draw unbroken line if tabs are not on BOTTOM, OR
// selected tab is not in run adjacent to content, OR
// selected tab is not visible (SCROLL_TAB_LAYOUT)
//
if (tabPlacement != BOTTOM
|| selectedIndex < 0
|| (selRect.y - 1 > h)
|| (selRect.x < x || selRect.x > x + w))
{
//g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
//g.setColor(darkShadow);
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
if(drawThickBorder)
g.drawLine(x, y + h - 2, x+w-1, y+h-2);
}
else
{
// Break line to show visual connection to selected tab
//g.drawLine(x + 1, y + h - 2, selRect.x , y + h - 2);
//g.setColor(darkShadow);
g.drawLine(x, y + h - 1, selRect.x , y + h - 1);
if(drawThickBorder)
g.drawLine(x, y+h-2, selRect.x, y+h-2);
if (selRect.x + selRect.width < x + w - 2)
{
g.setColor(borderColor);
// g.drawLine(
// selRect.x + selRect.width,
// y + h - 2,
// x + w - 2,
// y + h - 2);
g.setColor(darkShadow);
g.drawLine(
selRect.x + selRect.width,
y + h - 1,
x + w - 1,
y + h - 1);
if(drawThickBorder)
g.drawLine(selRect.x+selRect.width, y+h-2, x+w-1, y+h-2);
}
}
}
protected void paintContentBorderRightEdge(
Graphics g,
int tabPlacement,
int selectedIndex,
int x,
int y,
int w,
int h)
{
Rectangle selRect=
selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
g.setColor(borderColor);
// Draw unbroken line if tabs are not on RIGHT, OR
// selected tab is not in run adjacent to content, OR
// selected tab is not visible (SCROLL_TAB_LAYOUT)
//
if (tabPlacement != RIGHT
|| selectedIndex < 0
|| (selRect.x - 1 > w)
|| (selRect.y < y || selRect.y > y + h))
{
//g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 3);
//g.setColor(darkShadow);
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
if(drawThickBorder)
g.drawLine(x + w - 2, y, x + w - 2, y + h - 1);
}
else
{
// Break line to show visual connection to selected tab
//g.drawLine(x + w - 2, y + 1, x + w - 2, selRect.y );
//g.setColor(darkShadow);
g.drawLine(x + w - 1, y, x + w - 1, selRect.y);
if(drawThickBorder)
g.drawLine(x + w - 2, y, x + w - 2, selRect.y);
if (selRect.y + selRect.height < y + h - 2)
{
// g.setColor(shadow);
// g.drawLine(
// x + w - 2,
// selRect.y + selRect.height,
// x + w - 2,
// y + h - 2);
// g.setColor(darkShadow);
g.drawLine(
x + w - 1,
selRect.y + selRect.height,
x + w - 1,
y + h - 2);
if(drawThickBorder)
g.drawLine(
x + w - 2,
selRect.y + selRect.height,
x + w - 2,
y + h - 2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -