001: /*
002: * BorderLessWindowsTabbedPaneUI.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.components;
013:
014: import java.awt.Color;
015: import java.awt.Graphics;
016: import java.awt.Insets;
017:
018: import javax.swing.JTabbedPane;
019: import javax.swing.UIManager;
020:
021: import com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI;
022:
023: public class BorderLessWindowsTabbedPaneUI extends WindowsTabbedPaneUI {
024: private Color selColor;
025:
026: protected Insets getContentBorderInsets(int tabPlacement) {
027: switch (tabPlacement) {
028: case JTabbedPane.TOP:
029: return new Insets(3, 1, 1, 1);
030: case JTabbedPane.BOTTOM:
031: return new Insets(1, 1, 3, 1);
032: case JTabbedPane.LEFT:
033: return new Insets(1, 3, 1, 1);
034: case JTabbedPane.RIGHT:
035: return new Insets(0, 0, 0, 5);
036: default:
037: return new Insets(0, 0, 0, 0);
038: }
039: }
040:
041: protected void installDefaults() {
042: super .installDefaults();
043: selColor = UIManager.getColor("TabbedPane.selected");
044: }
045:
046: protected void paintContentBorder(Graphics g, int tabPlacement,
047: int selectedIndex) {
048: int width = tabPane.getWidth();
049: int height = tabPane.getHeight();
050: Insets insets = tabPane.getInsets();
051:
052: int x = insets.left;
053: int y = insets.top;
054: int w = width - insets.right - insets.left;
055: int h = height - insets.top - insets.bottom;
056:
057: switch (tabPlacement) {
058: case LEFT:
059: x += calculateTabAreaWidth(tabPlacement, runCount,
060: maxTabWidth);
061: w -= (x - insets.left);
062: break;
063: case RIGHT:
064: w -= calculateTabAreaWidth(tabPlacement, runCount,
065: maxTabWidth);
066: break;
067: case BOTTOM:
068: h -= calculateTabAreaHeight(tabPlacement, runCount,
069: maxTabHeight);
070: break;
071: case TOP:
072: default:
073: y += calculateTabAreaHeight(tabPlacement, runCount,
074: maxTabHeight);
075: h -= (y - insets.top);
076: }
077: // Fill region behind content area
078: if (selColor == null) {
079: g.setColor(tabPane.getBackground());
080: } else {
081: g.setColor(selColor);
082: }
083: g.fillRect(x, y, w, h);
084:
085: switch (tabPlacement) {
086: case JTabbedPane.TOP:
087: paintContentBorderTopEdge(g, tabPlacement, selectedIndex,
088: x, y, w, h);
089: break;
090: case JTabbedPane.BOTTOM:
091: paintContentBorderBottomEdge(g, tabPlacement,
092: selectedIndex, x, y, w, h);
093: break;
094: case JTabbedPane.LEFT:
095: paintContentBorderLeftEdge(g, tabPlacement, selectedIndex,
096: x, y, w, h);
097: break;
098: case JTabbedPane.RIGHT:
099: paintContentBorderRightEdge(g, tabPlacement, selectedIndex,
100: x, y, w, h);
101: break;
102: }
103: }
104: }
|