📄 visualstudio2005tabbedpaneui.java
字号:
switch (tabPlacement) {
case SwingConstants.BOTTOM:
// Paint the pseudo-"tails" of the tabs.
for (int i=0; i<runCount; i++) {
int firstInRun = tabRuns[i];
Rectangle r = rects[firstInRun];
g.translate(r.x, r.y);
g.translate(0,TAB_HEIGHT-1);
g2d.scale(1, -1);
paintTabOverlappingBackground(g, tabPlacement,
-9, TAB_HEIGHT, firstInRun);
paintTabOverlappingBorder(g, tabPlacement,
-9, TAB_HEIGHT-1, firstInRun);
g2d.setTransform(oldTransform);
}
break;
case SwingConstants.TOP:
// Paint the pseudo-"tails" of the tabs.
for (int i=0; i<runCount; i++) {
int firstInRun = tabRuns[i];
Rectangle r = rects[firstInRun];
g.translate(r.x, r.y);
paintTabOverlappingBackground(g, tabPlacement,
-9, TAB_HEIGHT, firstInRun);
paintTabOverlappingBorder(g, tabPlacement,
-9, TAB_HEIGHT-1, firstInRun);
g2d.setTransform(oldTransform);
}
break;
default:
}
g2d.setTransform(oldTransform);
// Paint the runs of tabs in reverse order since runs overlap.
for (int i=runCount-1; i>=0; i--) {
int start = tabRuns[i];
int next = tabRuns[(i==runCount-1) ? 0 : i+1];
int end = (next!=0 ? next-1 : tabCount-1);
for (int j=start; j<=end; j++) {
if (rects[j].intersects(clipRect))
paintTab(g, tabPlacement, rects, j, iconRect, textRect);
}
}
}
/**
* Fills in the "background" color of a tab. Also colors the part of the
* tab that is "overlapped" by another, if necessary.
*/
protected void paintTabBackground(Graphics g, int tabPlacement,
int tabIndex, int x, int y, int w,
int h, boolean isSelected) {
g.setColor(isSelected ? UIManager.getColor("TabbedPane.selected") :
UIManager.getColor("TabbedPane.background"));
Graphics2D g2d = (Graphics2D)g;
AffineTransform oldTransform = g2d.getTransform();
g2d.translate(x,y);
switch (tabPlacement) {
case SwingConstants.BOTTOM:
g.translate(0,h);
g2d.scale(1, -1);
// Fall through.
case SwingConstants.TOP:
case SwingConstants.LEFT:
case SwingConstants.RIGHT:
// Fill in this tab.
// NOTE: The fillRect() call works with (0,7, w-1,h-7) for
// SwingConstants.TOP, but not BOTTOM (there will be an
// unapinted line between the rect and the lines painted
// next). Why is this? It must have something to do with
// the scale done above...
g.fillRect(0,6, w-1,h-6);
g.drawLine(1,6, w-2,6);
g.drawLine(2,5, w-2,5);
g.drawLine(3,4, w-2,4);
g.drawLine(4,3, w-2,3);
g.drawLine(6,2, w-2,2);
g.drawLine(8,1, w-3,1);
// (Possibly) paint the background of the overlapping tab.
// Ensure that there is a tab in this run "after" this one.
int nextTabIndexInRun = getNextTabIndexInRun(
tabPane.getTabCount(), tabIndex);
if (nextTabIndexInRun==tabIndex+1 && nextTabIndexInRun==tabPane.getSelectedIndex()) {
x = w - 9;
y = h;
paintTabOverlappingBackground(g, tabPlacement, x,y,
nextTabIndexInRun);
}
break;
default:
g2d.setTransform(oldTransform);
super.paintTabBackground(g, tabPlacement, tabIndex, x,y,w,h, isSelected);
}
// Leave our Graphics object unperturbed.
g2d.setTransform(oldTransform);
}
/**
* Paints the line border around a tab. Also draws the part of the border
* of the "overlapping" tab, if any.
*/
protected void paintTabBorder(Graphics g, int tabPlacement,
int tabIndex, int x, int y, int w,
int h, boolean isSelected) {
g.setColor(isSelected ? UIManager.getColor("VisualStudio2005.TabBorderColor") :
UIManager.getColor("VisualStudio2005.BackgroundTabBorderColor"));
Graphics2D g2d = (Graphics2D)g;
AffineTransform oldTransform = g2d.getTransform();
g2d.translate(x,y);
int rhsYStop = (tabPlacement==SwingConstants.LEFT ||
tabPlacement==SwingConstants.RIGHT) ? h-1 : 7;
switch (tabPlacement) {
case SwingConstants.BOTTOM:
g.translate(0,h-1);
g2d.scale(1, -1);
// Fall through.
case SwingConstants.TOP:
case SwingConstants.LEFT:
case SwingConstants.RIGHT:
// Draw this tab's border.
g.drawLine(0,6, 3,3);
g.drawLine(4,2, 5,2);
g.drawLine(6,1, 7,1);
g.drawLine(8,0, w-3,0); // "Top" line.
g.drawLine(w-2,1, w-2,1); // "Right turn."
g.drawLine(w-1,2, w-1,rhsYStop); // Right-hand side.
// (Possibly) paint the border of the overlapping tab.
int nextTabIndexInRun = getNextTabIndexInRun(
tabPane.getTabCount(), tabIndex);
if (nextTabIndexInRun==tabIndex+1 && nextTabIndexInRun==tabPane.getSelectedIndex()) {
x = w - 9;
paintTabOverlappingBorder(g, tabPlacement, x,h-1, nextTabIndexInRun);
}
else {
g.drawLine(w-1,8, w-1,h-1);
}
break;
default:
g2d.setTransform(oldTransform);
super.paintTabBorder(g, tabPlacement, tabIndex, x,y,w,h, isSelected);
}
// Leave our Graphics object unperturbed.
g2d.setTransform(oldTransform);
}
/**
* Paints the background of the tab overlapping the specified tab, if any.
*
* @param g The graphics context.
* @param tabPlacement The tab placement.
* @param x The x-coordinate of tab <code>tabIndex</code>.
* @param y The y-coordinate of tab <code>tabIndex</code>.
* @param overlappingTabIndex The tab that is BEING overlapped (possibly).
* @see #paintTabOverlappingBorder
*/
protected void paintTabOverlappingBackground(Graphics g, int tabPlacement,
int x, int y,
int overlappingTabIndex) {
boolean overlappingSelected = overlappingTabIndex==tabPane.getSelectedIndex();
g.setColor(overlappingSelected ?
UIManager.getColor("TabbedPane.selected") :
UIManager.getColor("TabbedPane.background"));
switch (tabPlacement) {
case SwingConstants.BOTTOM: // Been mirrored, so fall through.
case SwingConstants.TOP:
int x2 = x + 9;
g.fillPolygon(new int[] { x, x2, x2 },
new int[] { y, y, y-9 }, 3);
break;
case SwingConstants.LEFT:
case SwingConstants.RIGHT:
// Do nothing.
}
}
/**
* Paints the border of the tab overlapping the specified tab, or, if the
* tab is not being overlapped, the last part of the tab is painted.
*
* @param g The graphics context.
* @param tabPlacement The tab placement.
* @param x The x-coordinate of tab <code>tabIndex</code>.
* @param y The y-coordinate of tab <code>tabIndex</code>.
* @param overlappingTabIndex The tab that is BEING overlapped (possibly).
* @see #paintTabOverlappingBackground
*/
protected void paintTabOverlappingBorder(Graphics g, int tabPlacement,
int x, int y,
int overlappingTabIndex) {
boolean overlappingSelected = overlappingTabIndex==tabPane.getSelectedIndex();
g.setColor(overlappingSelected ?
UIManager.getColor("VisualStudio2005.TabBorderColor") :
UIManager.getColor("VisualStudio2005.BackgroundTabBorderColor"));
switch (tabPlacement) {
case SwingConstants.BOTTOM: // Been mirrored, so fall through.
case SwingConstants.TOP:
g.drawLine(x,y, x+9,y-9);
break;
case SwingConstants.LEFT:
case SwingConstants.RIGHT:
// Do nothing.
}
}
/**
* Paints the titles on tabs.
*/
protected void paintText(Graphics g, int tabPlacement, Font font,
FontMetrics metrics, int tabIndex, String title,
Rectangle textRect, boolean isSelected) {
if (isSelected) {
font = getBoldFont(font);
metrics = tabPane.getFontMetrics(font);
}
super.paintText(g, tabPlacement, font, metrics, tabIndex, title,
textRect, isSelected);
}
public int tabForCoordinate(JTabbedPane pane, int x, int y) {
// Returns the rectangular bounds for a tab.
int tab = super.tabForCoordinate(pane, x,y);
if (tab==-1)
return tab;
switch (tabPane.getTabPlacement()) {
case SwingConstants.TOP:
case SwingConstants.BOTTOM:
// If this tab is not selected (as selected tabs never
// have another tab overlapping them)...
if (tab!=tabPane.getSelectedIndex()) {
int nextTab = getNextTabIndexInRun(
tabPane.getTabCount(), tab);
// And we're not at the end of a tab run (as tabs at
// the end of a tab run cannot have a tab overlapping
// them)...
if (nextTab==tab+1) {
//Rectangle tabBounds = getTabBounds(tabPane, tab);
// And they clicked in the triangle area
// representing the overlapping tab...
// FIXME: Add me in when I can think.
}
}
break;
default: // LEFT or RIGHT.
// Nothing special because the tabs don't overlap.
break;
}
return tab;
}
protected void uninstallDefaults() {
tabPane.setFocusable(oldFocusable);
super.uninstallDefaults();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -