01: /*
02: * BorderLessMetalTabbedPaneUI.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Color;
15: import java.awt.Graphics;
16: import java.awt.Insets;
17:
18: import javax.swing.JTabbedPane;
19: import javax.swing.UIManager;
20: import javax.swing.plaf.metal.MetalTabbedPaneUI;
21:
22: public class BorderLessMetalTabbedPaneUI extends MetalTabbedPaneUI {
23: private Color selColor;
24:
25: protected Insets getContentBorderInsets(int tabPlacement) {
26: return TabbedPaneUIFactory.getBorderLessInsets(tabPlacement);
27: }
28:
29: protected void installDefaults() {
30: super .installDefaults();
31: selColor = UIManager.getColor("TabbedPane.selected");
32: }
33:
34: protected void paintContentBorder(Graphics g, int tabPlacement,
35: int selectedIndex) {
36: int width = tabPane.getWidth();
37: int height = tabPane.getHeight();
38: Insets insets = tabPane.getInsets();
39:
40: int x = insets.left;
41: int y = insets.top;
42: int w = width - insets.right - insets.left;
43: int h = height - insets.top - insets.bottom;
44:
45: switch (tabPlacement) {
46: case LEFT:
47: x += calculateTabAreaWidth(tabPlacement, runCount,
48: maxTabWidth);
49: w -= (x - insets.left);
50: break;
51: case RIGHT:
52: w -= calculateTabAreaWidth(tabPlacement, runCount,
53: maxTabWidth);
54: break;
55: case BOTTOM:
56: h -= calculateTabAreaHeight(tabPlacement, runCount,
57: maxTabHeight);
58: break;
59: case TOP:
60: default:
61: y += calculateTabAreaHeight(tabPlacement, runCount,
62: maxTabHeight);
63: h -= (y - insets.top);
64: }
65: // Fill region behind content area
66: if (selColor == null) {
67: g.setColor(tabPane.getBackground());
68: } else {
69: g.setColor(selColor);
70: }
71: g.fillRect(x, y, w, h);
72:
73: switch (tabPlacement) {
74: case JTabbedPane.TOP:
75: paintContentBorderTopEdge(g, tabPlacement, selectedIndex,
76: x, y, w, h);
77: break;
78: case JTabbedPane.BOTTOM:
79: paintContentBorderBottomEdge(g, tabPlacement,
80: selectedIndex, x, y, w, h);
81: break;
82: case JTabbedPane.LEFT:
83: paintContentBorderLeftEdge(g, tabPlacement, selectedIndex,
84: x, y, w, h);
85: break;
86: case JTabbedPane.RIGHT:
87: paintContentBorderRightEdge(g, tabPlacement, selectedIndex,
88: x, y, w, h);
89: break;
90: }
91: }
92:
93: }
|