001: /*
002: * @(#)WindowsTabbedPaneUI.java
003: *
004: * Copyright 2002 JIDE Software Inc. All rights reserved.
005: */
006:
007: package com.jidesoft.plaf.eclipse;
008:
009: import com.jidesoft.plaf.UIDefaultsLookup;
010: import com.jidesoft.plaf.vsnet.VsnetJideTabbedPaneUI;
011: import com.jidesoft.swing.JideSwingUtilities;
012: import com.jidesoft.swing.JideTabbedPane;
013:
014: import javax.swing.*;
015: import javax.swing.plaf.ComponentUI;
016: import java.awt.*;
017:
018: /**
019: * JideTabbedPane UI implementation
020: */
021: public class EclipseJideTabbedPaneUI extends VsnetJideTabbedPaneUI {
022:
023: public static ComponentUI createUI(JComponent c) {
024: return new EclipseJideTabbedPaneUI();
025: }
026:
027: /**
028: * this function draws the border around each tab
029: * note that this function does now draw the background of the tab.
030: * that is done elsewhere
031: */
032: @Override
033: protected void paintTabBorder(Graphics g, int tabPlacement,
034: int tabIndex, int x, int y, int w, int h, boolean isSelected) {
035: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
036: Color old = g.getColor();
037:
038: switch (tabPlacement) {
039: case LEFT:
040: if (isSelected) {
041: g.setColor(_lightHighlight);
042: g.drawRect(x + 1, y + 1, w - 1, h - 3);
043:
044: g.setColor(_shadow);
045: g.drawLine(x + 1, y, x + w - 1, y);
046: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
047: g.drawLine(x, y + 1, x, y + 1);
048: g.drawLine(x, y + h - 2, x, y + h - 2);
049: } else {
050: g.setColor(_shadow);
051: if (tabIndex > _tabPane.getSelectedIndex()/* && tabIndex != _tabPane.getTabCount() - 1*/) {
052: if (tabIndex == _tabPane.getTabCount() - 1) {
053: g.drawLine(x, y + h - 1, x + w, y + h - 1); // bottom shadow
054: } else {
055: g.drawLine(x, y + h - 1, x + w / 2, y + h
056: - 1); // bottom shadow
057: }
058: } else if (tabIndex < _tabPane.getSelectedIndex()) {
059: if (tabIndex != 0) {
060: g.drawLine(x, y, x + w / 2, y); // top shadow
061: } else {
062: if (isTabLeadingComponentVisible()) {
063: g.drawLine(x, y, x + w, y); // top shadow
064: }
065: }
066: }
067: }
068:
069: if (isTabTopVisible(tabPlacement)) {
070: g.setColor(_shadow);
071: g.drawLine(x, y, x, y + h - 1); // tab top
072: }
073: break;
074: case RIGHT:
075: if (isSelected) {
076: g.setColor(_lightHighlight);
077: g.drawRect(x, y + 1, w - 1, h - 3);
078:
079: g.setColor(_shadow);
080: g.drawLine(x, y, x + w - 1, y);
081: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
082: g.drawLine(x + w, y + 1, x + w, y + 1);
083: g.drawLine(x + w, y + h - 2, x + w, y + h - 2);
084: } else { // not selected
085: g.setColor(_shadow);
086: if (tabIndex > _tabPane.getSelectedIndex()) {
087: if (tabIndex == _tabPane.getTabCount() - 1) {
088: g.drawLine(x, y + h - 1, x + w, y + h - 1); // bottom shadow
089: } else {
090: g.drawLine(x + w / 2, y + h - 1, x + w, y
091: + h - 1); // bottom shadow
092: }
093: } else if (tabIndex < _tabPane.getSelectedIndex()) {
094: if (tabIndex != 0) {
095: g.drawLine(x + w / 2, y, x + w, y); // top shadow
096: } else {
097: if (isTabLeadingComponentVisible()) {
098: g.drawLine(x, y, x + w, y); // top shadow
099: }
100: }
101: }
102: }
103:
104: if (isTabTopVisible(tabPlacement)) {
105: g.setColor(_shadow);
106: g.drawLine(x + w, y, x + w, y + h - 1); // tab top
107: }
108: break;
109: case BOTTOM:
110: if (isSelected) {
111: g.setColor(_lightHighlight);
112: g.drawRect(x + 1, y, w - 3, h - 1);
113:
114: g.setColor(_shadow);
115: g.drawLine(x, y, x, y + h - 1);
116: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
117: g.drawLine(x + 1, y + h, x + 1, y + h);
118: g.drawLine(x + w - 2, y + h, x + w - 2, y + h);
119: } else { // not selected
120: g.setColor(_shadow);
121: if (tabIndex > _tabPane.getSelectedIndex()) {
122: if (tabIndex == _tabPane.getTabCount() - 1) {
123: g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
124: } else {
125: g.drawLine(x + w - 1, y + h / 2, x + w - 1,
126: y + h); // right shadow
127: }
128: } else if (tabIndex < _tabPane.getSelectedIndex()) {
129: if (tabIndex != 0) {
130: g.drawLine(x, y + h / 2, x, y + h); // right shadow
131: } else {
132: if (isTabLeadingComponentVisible()) {
133: g.drawLine(x, y, x, y + h); // right shadow
134: }
135: }
136: }
137: }
138:
139: if (isTabTopVisible(tabPlacement)) {
140: g.setColor(_shadow);
141: g.drawLine(x, y + h, x + w - 1, y + h); // tab top
142: }
143: break;
144: case TOP:
145: default:
146: if (isSelected) {
147: g.setColor(_lightHighlight);
148: g.drawRect(x + 1, y + 1, w - 3, h);
149:
150: g.setColor(_shadow);
151: g.drawLine(x, y + 1, x, y + h - 1);
152: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
153: g.drawLine(x + 1, y, x + 1, y);
154: g.drawLine(x + w - 2, y, x + w - 2, y);
155: } else {
156: g.setColor(_shadow);
157: if (tabIndex > _tabPane.getSelectedIndex()) {
158: if (tabIndex == _tabPane.getTabCount() - 1) {
159: g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
160: } else {
161: g.drawLine(x + w - 1, y, x + w - 1, y + h
162: / 2); // right shadow
163: }
164: } else if (tabIndex < _tabPane.getSelectedIndex()) {
165: if (tabIndex != 0) {
166: g.drawLine(x, y, x, y + h / 2); // right shadow
167: } else {
168: if (isTabLeadingComponentVisible()) {
169: g.drawLine(x, y, x, y + h); // right shadow
170: }
171: }
172: }
173: }
174:
175: if (isTabTopVisible(tabPlacement)) {
176: g.setColor(_shadow);
177: g.drawLine(x, y, x + w - 1, y); // tab top
178: }
179: break;
180: }
181: g.setColor(old);
182:
183: } else {
184: super .paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h,
185: isSelected);
186: }
187: }
188:
189: @Override
190: protected void paintTabArea(Graphics g, int tabPlacement,
191: int selectedIndex) {
192: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
193: int tabCount = _tabPane.getTabCount();
194:
195: Rectangle iconRect = new Rectangle(), textRect = new Rectangle();
196: Rectangle clipRect = g.getClipBounds();
197:
198: g.setColor(_tabBackground);
199: g.fillRect(clipRect.x, clipRect.y, clipRect.width,
200: clipRect.height);
201:
202: // Paint tabRuns of tabs from back to front
203: for (int i = _runCount - 1; i >= 0; i--) {
204: int start = _tabRuns[i];
205: int next = _tabRuns[(i == _runCount - 1) ? 0 : i + 1];
206: int end = (next != 0 ? next - 1 : tabCount - 1);
207: for (int j = start; j <= end; j++) {
208: if (_rects[j].intersects(clipRect)) {
209: paintTab(g, tabPlacement, _rects, j, iconRect,
210: textRect);
211: }
212: }
213: }
214:
215: // Paint selected tab if its in the front run
216: // since it may overlap other tabs
217: if (selectedIndex >= 0
218: && getRunForTab(tabCount, selectedIndex) == 0) {
219: if (_rects[selectedIndex].intersects(clipRect)) {
220: paintTab(g, tabPlacement, _rects, selectedIndex,
221: iconRect, textRect);
222: }
223: }
224: } else {
225: super .paintTabArea(g, tabPlacement, selectedIndex);
226: }
227: }
228:
229: @Override
230: protected void paintContentBorderTopEdge(Graphics g,
231: int tabPlacement, int selectedIndex, int x, int y, int w,
232: int h) {
233: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
234: if (_tabPane.isTabShown()) {
235: g.setColor(_shadow);
236: g.drawLine(x, y, x + w - 1, y);
237: }
238: } else {
239: super .paintContentBorderTopEdge(g, tabPlacement,
240: selectedIndex, x, y, w, h);
241: }
242: }
243:
244: @Override
245: protected void paintContentBorderBottomEdge(Graphics g,
246: int tabPlacement, int selectedIndex, int x, int y, int w,
247: int h) {
248: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
249: if (_tabPane.isTabShown()) {
250: g.setColor(_shadow);
251: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
252: }
253: } else {
254: super .paintContentBorderBottomEdge(g, tabPlacement,
255: selectedIndex, x, y, w, h);
256: }
257: }
258:
259: @Override
260: protected void paintContentBorderLeftEdge(Graphics g,
261: int tabPlacement, int selectedIndex, int x, int y, int w,
262: int h) {
263: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
264: if (_tabPane.isTabShown()) {
265: g.setColor(_shadow);
266: g.drawLine(x, y, x, y + h - 1);
267: }
268: } else {
269: super .paintContentBorderLeftEdge(g, tabPlacement,
270: selectedIndex, x, y, w, h);
271: }
272: }
273:
274: @Override
275: protected void paintContentBorderRightEdge(Graphics g,
276: int tabPlacement, int selectedIndex, int x, int y, int w,
277: int h) {
278: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
279: if (_tabPane.isTabShown()) {
280: g.setColor(_shadow);
281: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
282: }
283: } else {
284: super .paintContentBorderRightEdge(g, tabPlacement,
285: selectedIndex, x, y, w, h);
286: }
287: }
288:
289: @Override
290: protected void paintTabBackground(Graphics g, int tabPlacement,
291: int tabIndex, int x, int y, int w, int h, boolean isSelected) {
292: if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
293: _tabPane.setBackgroundAt(tabIndex, _tabBackground);
294:
295: if (isSelected) {
296: Color background1;
297: Color background2;
298: if (showFocusIndicator()) {
299: background1 = UIDefaultsLookup
300: .getColor("DockableFrame.activeTitleBackground");
301: background2 = UIDefaultsLookup
302: .getColor("DockableFrame.activeTitleBackground2");
303: } else {
304: background1 = Color.WHITE;
305: background2 = _background;
306: }
307:
308: Graphics2D g2d = (Graphics2D) g;
309: int buttonSize = 16;
310: int restWidth = w
311: - (isShowCloseButtonOnTab() ? buttonSize : 0)
312: - 3;
313: int restHeight = h
314: - (isShowCloseButtonOnTab() ? buttonSize : 0)
315: - 3;
316: switch (tabPlacement) {
317: case LEFT:
318: JideSwingUtilities.fillGradient(g2d, new Rectangle(
319: x, y + 1, w, restHeight >> 1), background1,
320: background2, true);
321: break;
322: case RIGHT:
323: JideSwingUtilities.fillGradient(g2d, new Rectangle(
324: x, y + 1, w - 1, restHeight >> 1),
325: background1, background2, true);
326: break;
327: case BOTTOM:
328: JideSwingUtilities.fillGradient(g2d, new Rectangle(
329: x + 1, y, restWidth >> 1, h - 1),
330: background1, background2, false);
331: break;
332: case TOP:
333: default:
334: JideSwingUtilities.fillGradient(g2d, new Rectangle(
335: x + 1, y + 1, restWidth >> 1, h),
336: background1, background2, false);
337: break;
338: }
339: switch (tabPlacement) {
340: case LEFT:
341: JideSwingUtilities.fillGradient(g2d, new Rectangle(
342: x, y + 1 + (restHeight >> 1), w,
343: restHeight >> 1), background2,
344: _tabBackground, true);
345: break;
346: case RIGHT:
347: JideSwingUtilities.fillGradient(g2d, new Rectangle(
348: x, y + 1 + (restHeight >> 1), w - 1,
349: restHeight >> 1), background2,
350: _tabBackground, true);
351: break;
352: case BOTTOM:
353: JideSwingUtilities.fillGradient(g2d, new Rectangle(
354: x + 1 + (restWidth >> 1), y,
355: restWidth >> 1, h - 1), background2,
356: _tabBackground, false);
357: break;
358: case TOP:
359: default:
360: JideSwingUtilities.fillGradient(g2d, new Rectangle(
361: x + 1 + (restWidth >> 1), y + 1,
362: restWidth >> 1, h), background2,
363: _tabBackground, false);
364: break;
365: }
366: } else {
367: super.paintTabBackground(g, tabPlacement, tabIndex, x,
368: y, w, h, isSelected);
369: }
370: } else {
371: super.paintTabBackground(g, tabPlacement, tabIndex, x, y,
372: w, h, isSelected);
373: }
374: }
375: }
|