Debian Codegraph @

src/com/jidesoft/plaf/eclipse/Eclipse3xJideTabbedPaneUI.java

raw
1 /*
2 * @(#)Eclipse3xJideTabbedPaneUI.java 8/28/2006
3 *
4 * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.eclipse;
8
9 import com.jidesoft.plaf.UIDefaultsLookup;
10 import com.jidesoft.plaf.vsnet.VsnetJideTabbedPaneUI;
11 import com.jidesoft.swing.JideSwingUtilities;
12 import com.jidesoft.swing.JideTabbedPane;
13
14 import javax.swing.*;
15 import javax.swing.plaf.ComponentUI;
16 import javax.swing.plaf.basic.BasicGraphicsUtils;
17 import javax.swing.text.View;
18 import java.awt.*;
19
20 /**
21 * A eclipse L&f implementation of JideTabbedPaneUI
22 */
23 public class Eclipse3xJideTabbedPaneUI extends VsnetJideTabbedPaneUI {
24 // pixels
25 protected int _closeButtonMargin;// margin around the close button
26
27 protected int _closeButtonMarginSize;// margin of the close button when every tab has a close button
28
29 protected int _iconMarginHorizon;// distance from icon to tab rect start when the tab is on the top or bottom
30
31 protected int _iconMarginVertical;// distance from icon to tab rect start when the tab is on the left or right
32
33 @SuppressWarnings({"UnusedDeclaration"})
34 public static ComponentUI createUI(JComponent c) {
35 return new Eclipse3xJideTabbedPaneUI();
36 }
37
38 @Override
39 public void installUI(JComponent c) {
40 super.installUI(c);
41 _rectSizeExtend = 12;
42 }
43
44 @Override
45 protected void installDefaults() {
46 super.installDefaults();
47 // set the border of the TabbedPane
48 LookAndFeel.installBorder(_tabPane, "JideTabbedPane.border");
49 _closeButtonMargin = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMargin");
50 _closeButtonMarginSize = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMarginSize");
51 _iconMarginHorizon = UIDefaultsLookup.getInt("JideTabbedPane.iconMarginHorizon");
52 _iconMarginVertical = UIDefaultsLookup.getInt("JideTabbedPane.iconMarginVertical");
53 }
54
55 @Override
56 public void paintBackground(Graphics g, Component c) {
57 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
58 if (_tabPane.isOpaque()) {
59 int width = c.getWidth();
60 int height = c.getHeight();
61
62 int temp1 = -1;
63 int temp2 = -1;
64 if (isTabLeadingComponentVisible()) {
65 if (height < _tabLeadingComponent.getSize().height) {
66 height = _tabLeadingComponent.getSize().height;
67 temp1 = _tabLeadingComponent.getSize().height;
68 }
69 if (width < _tabLeadingComponent.getSize().width) {
70 width = _tabLeadingComponent.getSize().width;
71 temp2 = _tabLeadingComponent.getSize().width;
72 }
73 }
74
75 if (isTabTrailingComponentVisible()) {
76 if (height < _tabTrailingComponent.getSize().height && temp1 < _tabTrailingComponent.getSize().height) {
77 height = _tabTrailingComponent.getSize().height;
78 }
79 if (width < _tabTrailingComponent.getSize().width && temp2 < _tabTrailingComponent.getSize().width) {
80 width = _tabTrailingComponent.getSize().width;
81 }
82 }
83
84 g.setColor(_background);
85 g.fillRect(0, 0, width, height);
86 }
87 }
88 else {
89 super.paintBackground(g, c);
90 }
91 }
92
93 @Override
94 protected void ensureCurrentLayout() {
95 /*
96 * If tabPane doesn't have a peer yet, the validate() call will silently
97 * fail. We handle that by forcing a layout if tabPane is still invalid.
98 * See bug 4237677.
99 */
100 if (!_tabPane.isValid()) {
101 TabbedPaneLayout layout = (TabbedPaneLayout) _tabPane.getLayout();
102 layout.calculateLayoutInfo();
103 }
104
105 // ensure the bounds of the close buttons when they are showed on the
106 // tab
107 if (scrollableTabLayoutEnabled() && isShowCloseButton()
108 && isShowCloseButtonOnTab()) {
109 for (int i = 0; i < _closeButtons.length; i++) {
110 if (_tabPane.isShowCloseButtonOnSelectedTab()) {
111 if (i != _tabPane.getSelectedIndex()) {
112 _closeButtons[i].setBounds(0, 0, 0, 0);
113 continue;
114 }
115 }
116 else {
117 if (i >= _rects.length) {
118 _closeButtons[i].setBounds(0, 0, 0, 0);
119 continue;
120 }
121 }
122
123 if (!_tabPane.isTabClosableAt(i)) {
124 _closeButtons[i].setBounds(0, 0, 0, 0);
125 continue;
126 }
127 Dimension size = _closeButtons[i].getPreferredSize();
128
129 Rectangle bounds;
130 if (_closeButtonAlignment == SwingConstants.TRAILING) {
131 if (_tabPane.getTabPlacement() == JideTabbedPane.TOP || _tabPane.getTabPlacement() == JideTabbedPane.BOTTOM) {
132 if (_tabPane.getComponentOrientation().isLeftToRight()) {
133 bounds = new Rectangle(_rects[i].x + _rects[i].width - size.width - 16, _rects[i].y + ((_rects[i].height - size.height) >> 1), size.width, size.height);
134 }
135 else {
136 bounds = new Rectangle(_rects[i].x + 4, ((_rects[i].height - size.height) >> 1), size.width, size.height);
137 }
138 }
139 else if (_tabPane.getTabPlacement() == JideTabbedPane.LEFT) {
140 bounds = new Rectangle(_rects[i].x + ((_rects[i].width - size.width) >> 1), _rects[i].y + _rects[i].height - size.height - 16, size.width, size.height);
141 }
142 else /*if (_tabPane.getTabPlacement() == JideTabbedPane.RIGHT)*/ {
143 bounds = new Rectangle(_rects[i].x + ((_rects[i].width - size.width) >> 1), _rects[i].y + _rects[i].height - size.height - 16, size.width, size.height);
144 }
145 }
146 else {
147 bounds = new Rectangle(_rects[i].x + 4, ((_rects[i].height - size.height) >> 1), size.width, size.height);
148 if (!_tabPane.getComponentOrientation().isLeftToRight() && (_tabPane.getTabPlacement() == JideTabbedPane.TOP || _tabPane.getTabPlacement() == JideTabbedPane.BOTTOM)) {
149 bounds = new Rectangle(_rects[i].x + _rects[i].width - size.width - 16, _rects[i].y + ((_rects[i].height - size.height) >> 1), size.width, size.height);
150 }
151 }
152 if (_closeButtons[i] instanceof JideTabbedPane.NoFocusButton) {
153 ((JideTabbedPane.NoFocusButton) _closeButtons[i]).setIndex(i);
154 }
155 if (!bounds.equals(_closeButtons[i].getBounds())) {
156 _closeButtons[i].setBounds(bounds);
157 }
158 if (_tabPane.getSelectedIndex() == i) {
159 _closeButtons[i].setBackground(_selectedColor == null ? _tabPane.getBackgroundAt(i) : _selectedColor);
160 }
161 else {
162 _closeButtons[i].setBackground(_tabPane.getBackgroundAt(i));
163 }
164 }
165 }
166
167 }
168
169 /**
170 * Paints the tabs in the tab area. Invoked by paint(). The graphics parameter must be a valid <code>Graphics</code>
171 * object. Tab placement may be either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
172 * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>. The selected index must be a valid tabbed pane
173 * tab index (0 to tab count - 1, inclusive) or -1 if no tab is currently selected. The handling of invalid
174 * parameters is unspecified.
175 *
176 * @param g the graphics object to use for rendering
177 * @param tabPlacement the placement for the tabs within the JTabbedPane
178 * @param selectedIndex the tab index of the selected component
179 */
180 @Override
181 protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex, Component c) {
182
183 if (!PAINT_TABAREA) {
184 return;
185 }
186
187 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
188 int tabCount = _tabPane.getTabCount();
189
190 Rectangle iconRect = new Rectangle(), textRect = new Rectangle();
191 Rectangle clipRect = g.getClipBounds();
192 Rectangle viewRect = _tabScroller.viewport.getViewRect();
193
194 if (_tabPane.isOpaque()) {
195 g.setColor(_tabBackground);
196 g.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
197 }
198
199 // Paint tabRuns of tabs from back to front
200 for (int i = _runCount - 1; i >= 0; i--) {
201 int start = _tabRuns[i];
202 int next = _tabRuns[(i == _runCount - 1) ? 0 : i + 1];
203 int end = (next != 0 ? next - 1 : tabCount - 1);
204 for (int j = start; j <= end; j++) {
205 if (_rects[j].intersects(clipRect)) {
206 paintTab(g, tabPlacement, _rects, j, iconRect, textRect);
207 }
208 }
209 }
210
211 // Paint selected tab if its in the front run
212 // since it may overlap other tabs
213 if (selectedIndex >= 0 && getRunForTab(tabCount, selectedIndex) == 0) {
214 if (_rects[selectedIndex].intersects(clipRect)) {
215 paintTab(g, tabPlacement, _rects, selectedIndex, iconRect,
216 textRect);
217 }
218 }
219
220 if (_tabPane.isOpaque()) {
221 g.setColor(_shadow);
222 switch (tabPlacement) {
223 case LEFT:
224 if (!isTabLeadingComponentVisible()) {
225 g.fillRect(viewRect.x, viewRect.y + 3, 1, 2);
226 g.fillRect(viewRect.x + 1, viewRect.y + 2, 1, 1);
227 g.fillRect(viewRect.x + 2, viewRect.y + 1, 1, 1);
228 g.fillRect(viewRect.x + 3, viewRect.y, 2, 1);
229 }
230
231 if (isNoneTabTrailingComponentVisible()) {
232 g.fillRect(viewRect.x + 3, viewRect.y + viewRect.height - 1, 2, 1);
233 g.fillRect(viewRect.x + 2, viewRect.y + viewRect.height - 2, 1, 1);
234 g.fillRect(viewRect.x + 1, viewRect.y + viewRect.height - 3, 1, 1);
235 g.fillRect(viewRect.x, viewRect.y + viewRect.height - 5, 1, 2);
236 }
237
238 g.setColor(_tabBackground);
239 g.fillRect(viewRect.x, viewRect.y, 3, 1);
240 g.fillRect(viewRect.x, viewRect.y + 1, 2, 1);
241 g.fillRect(viewRect.x, viewRect.y + 2, 1, 1);
242 break;
243 case RIGHT:
244 if (!isTabLeadingComponentVisible()) {
245 g.fillRect(viewRect.x + viewRect.width - 5, viewRect.y, 2, 1);
246 g.fillRect(viewRect.x + viewRect.width - 3, viewRect.y + 1, 1, 1);
247 g.fillRect(viewRect.x + viewRect.width - 2, viewRect.y + 2, 1, 1);
248 g.fillRect(viewRect.x + viewRect.width - 1, viewRect.y + 3, 1, 2);
249 }
250
251 if (isNoneTabTrailingComponentVisible()) {
252 g.fillRect(viewRect.x + viewRect.width - 5, viewRect.y + viewRect.height - 1, 2, 1);
253 g.fillRect(viewRect.x + viewRect.width - 3, viewRect.y + viewRect.height - 2, 1, 1);
254 g.fillRect(viewRect.x + viewRect.width - 2, viewRect.y + viewRect.height - 3, 1, 1);
255 g.fillRect(viewRect.x + viewRect.width - 1, viewRect.y + viewRect.height - 5, 1, 2);
256 }
257
258 g.setColor(_tabBackground);
259 g.fillRect(viewRect.x + viewRect.width - 3, viewRect.y, 3, 1);
260 g.fillRect(viewRect.x + viewRect.width - 2, viewRect.y + 1, 2, 1);
261 g.fillRect(viewRect.x + viewRect.width - 1, viewRect.y + 2, 1, 1);
262 break;
263 case BOTTOM:
264 if (!isTabLeadingComponentVisible()) {
265 g.fillRect(viewRect.x + 3, viewRect.y + viewRect.height - 1, 2, 1);
266 g.fillRect(viewRect.x + 2, viewRect.y + viewRect.height - 2, 1, 1);
267 g.fillRect(viewRect.x + 1, viewRect.y + viewRect.height - 3, 1, 1);
268 g.fillRect(viewRect.x, viewRect.y + viewRect.height - 5, 1, 2);
269 }
270
271 if (isNoneTabTrailingComponentVisible()) {
272 g.fillRect(viewRect.x + viewRect.width - 5, viewRect.y + viewRect.height - 1, 2, 1);
273 g.fillRect(viewRect.x + viewRect.width - 3, viewRect.y + viewRect.height - 2, 1, 1);
274 g.fillRect(viewRect.x + viewRect.width - 2, viewRect.y + viewRect.height - 3, 1, 1);
275 g.fillRect(viewRect.x + viewRect.width - 1, viewRect.y + viewRect.height - 5, 1, 2);
276 }
277
278 g.setColor(_tabBackground);
279 g.fillRect(viewRect.x, viewRect.y + viewRect.height - 1, 3, 1);
280 g.fillRect(viewRect.x, viewRect.y + viewRect.height - 2, 2, 1);
281 g.fillRect(viewRect.x, viewRect.y + viewRect.height - 3, 1, 1);
282 break;
283 case TOP:
284 default:
285 if (!isTabLeadingComponentVisible()) {
286 g.fillRect(viewRect.x + 3, viewRect.y, 2, 1);
287 g.fillRect(viewRect.x + 2, viewRect.y + 1, 1, 1);
288 g.fillRect(viewRect.x + 1, viewRect.y + 2, 1, 1);
289 g.fillRect(viewRect.x, viewRect.y + 3, 1, 2);
290 }
291
292 if (isNoneTabTrailingComponentVisible()) {
293 g.fillRect(viewRect.x + viewRect.width - 5, viewRect.y, 2, 1);
294 g.fillRect(viewRect.x + viewRect.width - 3, viewRect.y + 1, 1, 1);
295 g.fillRect(viewRect.x + viewRect.width - 2, viewRect.y + 2, 1, 1);
296 g.fillRect(viewRect.x + viewRect.width - 1, viewRect.y + 3, 1, 2);
297 }
298
299 g.setColor(_tabBackground);
300 g.fillRect(viewRect.x, viewRect.y, 3, 1);
301 g.fillRect(viewRect.x, viewRect.y + 1, 2, 1);
302 g.fillRect(viewRect.x, viewRect.y + 2, 1, 1);
303 }
304 }
305 }
306 else {
307 super.paintTabArea(g, tabPlacement, selectedIndex, c);
308 }
309 }
310
311 private boolean isNoneTabTrailingComponentVisible() {
312 return !_tabScroller.scrollForwardButton.isVisible() && !_tabScroller.scrollBackwardButton.isVisible() && !_tabScroller.closeButton.isVisible() && !isTabTrailingComponentVisible();
313 }
314
315
316 @Override
317 protected void layoutLabel(int tabPlacement, FontMetrics metrics,
318 int tabIndex, String title, Icon icon, Rectangle tabRect,
319 Rectangle iconRect, Rectangle textRect, boolean isSelected) {
320 textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
321
322 View v = getTextViewForTab(tabIndex);
323 if (v != null) {
324 _tabPane.putClientProperty("html", v);
325 }
326
327 SwingUtilities.layoutCompoundLabel(_tabPane, metrics, title, icon,
328 SwingUtilities.CENTER, SwingUtilities.CENTER,
329 SwingUtilities.CENTER, SwingUtilities.TRAILING, tabRect,
330 iconRect, textRect, _textIconGap);
331
332 _tabPane.putClientProperty("html", null);
333
334 if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) {
335 iconRect.x = tabRect.x + _iconMarginHorizon;
336 textRect.x = (icon != null ? iconRect.x + iconRect.width + _textIconGap : tabRect.x + _textPadding);
337 iconRect.width = Math.min(iconRect.width, tabRect.width - _tabRectPadding);
338 textRect.width = tabRect.width - _tabRectPadding - iconRect.width - (icon != null ? _textIconGap : _noIconMargin);
339
340 if ((getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT || _tabPane.getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIXED)) {
341 textRect.width -= 10;
342 if (isShowCloseButton() && isShowCloseButtonOnTab()) {
343 if (_tabPane.isShowCloseButtonOnSelectedTab()) {
344 if (isSelected) {
345 textRect.width -= _closeButtons[tabIndex].getPreferredSize().width;
346 }
347 }
348 else {
349 textRect.width -= _closeButtons[tabIndex].getPreferredSize().width;
350 }
351 }
352 }
353 else if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_COMPRESSED && isShowCloseButton() && isShowCloseButtonOnTab()) {
354 if (!_tabPane.isShowCloseButtonOnSelectedTab()) {
355 if (!isSelected) {
356 iconRect.width = iconRect.width
357 + _closeButtons[tabIndex].getPreferredSize().width
358 + _closeButtonMarginSize;
359 textRect.width = 0;
360 }
361 }
362 }
363 }
364 else {
365 iconRect.y = tabRect.y + _iconMarginVertical;
366 textRect.y = (icon != null ? iconRect.y + iconRect.height
367 + _textIconGap : tabRect.y + _textPadding);
368 iconRect.x = tabRect.x + 3;
369 textRect.x = tabRect.x + 3;
370 textRect.width = tabRect.width - _textMarginVertical;
371 textRect.height = tabRect.height - _tabRectPadding - iconRect.height - (icon != null ? _textIconGap : _noIconMargin);
372
373 if ((getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT || _tabPane
374 .getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIXED)) {
375 textRect.height -= 10;
376 if (isShowCloseButton() && isShowCloseButtonOnTab()) {
377 if (_tabPane.isShowCloseButtonOnSelectedTab()) {
378 if (isSelected) {
379 textRect.height -= _closeButtons[tabIndex].getPreferredSize().height;
380 }
381 }
382 else {
383 textRect.height -= _closeButtons[tabIndex].getPreferredSize().height;
384 }
385 }
386 }
387 else if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_COMPRESSED
388 && isShowCloseButton() && isShowCloseButtonOnTab()) {
389 if (!_tabPane.isShowCloseButtonOnSelectedTab()) {
390 if (!isSelected) {
391 iconRect.height = iconRect.height + _closeButtons[tabIndex].getPreferredSize().height + _closeButtonMarginSize;
392 textRect.height = 0;
393 }
394 }
395
396 }
397 }
398
399 }
400
401
402 /**
403 * this function draws the border around each tab note that this function does now draw the background of the tab.
404 * that is done elsewhere
405 */
406 @Override
407 protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
408 int x, int y, int w, int h, boolean isSelected) {
409 if (!PAINT_TAB_BORDER) {
410 return;
411 }
412
413 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
414 g.setColor(_lightHighlight);
415 boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight();
416 switch (tabPlacement) {
417 case LEFT:
418 if (!isTabLeadingComponentVisible())
419 y--;
420
421 if (isSelected) {
422 g.setColor(_shadow);
423 g.drawLine(x + 5, y, x + w - 1, y);// top
424
425 // top left arc
426 g.drawLine(x + 4, y + 1, x + 3, y + 1);
427 g.drawLine(x + 2, y + 2, x + 2, y + 2);
428 g.drawLine(x + 1, y + 3, x + 1, y + 3);
429 g.drawLine(x, y + 4, x, y + 5);
430
431 if (isTabTopVisible(tabPlacement)) {
432 g.drawLine(x, y + 5, x, y + h - 21);
433 }
434
435 // bottom left arc
436 g.drawLine(x, y + h - 21, x, y + h - 19);
437 g.drawLine(x + 1, y + h - 18, x + 1, y + h - 16);
438 g.drawLine(x + 2, y + h - 15, x + 2, y + h - 14);
439 g.drawLine(x + 3, y + h - 13, x + 3, y + h - 13);
440 g.drawLine(x + 4, y + h - 12, x + 4, y + h - 11);
441
442 // bottom
443 for (int i = 0; i < w - 10; i++) {
444 g.drawLine(x + 5 + i, y + h - 10 + i, x + 5 + i, y + h - 10 + i);
445 }
446
447 // bottom right arc
448 g.drawLine(x + w - 5, y + h + w - 20, x + w - 5, y + h + w - 19);
449 g.drawLine(x + w - 4, y + h + w - 18, x + w - 4, y + h + w - 18);
450 g.drawLine(x + w - 3, y + h + w - 17, x + w - 3, y + h + w - 16);
451 g.drawLine(x + w - 2, y + h + w - 15, x + w - 2, y + h + w - 13);
452 g.drawLine(x + w - 1, y + h + w - 12, x + w - 1, y + h + w - 10);
453
454 if (!isTabLeadingComponentVisible())
455 y++;
456 break;
457 }
458
459 // not selected
460 if (tabIndex > _tabPane.getSelectedIndex()) {
461 g.setColor(_shadow);
462 g.drawLine(x, y + h - 1, (x + w) - 1, y + h - 1);// bottom
463
464 break;
465 }
466
467 if (tabIndex >= _tabPane.getSelectedIndex() || tabIndex == 0)
468 break;
469
470 g.setColor(_shadow);
471 g.drawLine(x, y - 1, x + w - 1, y - 1);// top
472
473 break;
474 case RIGHT:
475 if (!isTabLeadingComponentVisible())
476 y--;
477
478 if (isSelected) {
479 g.setColor(_shadow);
480
481 g.drawLine(x, y, x + w - 6, y);// top
482
483 // top right arc
484 g.drawLine(x + w - 5, y + 1, x + w - 4, y + 1);
485 g.drawLine(x + w - 3, y + 2, x + w - 3, y + 2);
486 g.drawLine(x + w - 2, y + 3, x + w - 2, y + 3);
487 g.drawLine(x + w - 1, y + 4, x + w - 1, y + 5);
488
489 if (isTabTopVisible(tabPlacement)) {
490 g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 21);
491 }
492
493 // bottom right arc
494 g.drawLine(x + w - 1, y + h - 21, x + w - 1, y + h - 19);
495 g.drawLine(x + w - 2, y + h - 18, x + w - 2, y + h - 16);
496 g.drawLine(x + w - 3, y + h - 15, x + w - 3, y + h - 14);
497 g.drawLine(x + w - 4, y + h - 13, x + w - 4, y + h - 13);
498 g.drawLine(x + w - 5, y + h - 12, x + w - 5, y + h - 11);
499
500 // bottom
501 for (int i = 0; i < w - 10; i++) {
502 g.drawLine(x + w - 6 - i, y + h - 10 + i, x + w - 6 - i, y + h - 10 + i);
503 }
504
505 // bottom left arc
506 g.drawLine(x + 4, y + h + w - 20, x + 4, y + h + w - 19);
507 g.drawLine(x + 3, y + h + w - 18, x + 3, y + h + w - 18);
508 g.drawLine(x + 2, y + h + w - 17, x + 2, y + h + w - 16);
509 g.drawLine(x + 1, y + h + w - 15, x + 1, y + h + w - 13);
510 g.drawLine(x, y + h + w - 12, x, y + h + w - 10);
511 break;
512
513 }
514
515 // not selected
516 if (tabIndex > _tabPane.getSelectedIndex()) {
517 g.setColor(_shadow);
518 g.drawLine(x, y + h - 1, (x + w) - 1, y + h - 1);// bottom
519
520 break;
521 }
522
523 if (tabIndex >= _tabPane.getSelectedIndex() || tabIndex == 0)
524 break;
525
526 g.setColor(_shadow);
527 g.drawLine(x, y - 1, x + w - 1, y - 1);// top
528
529 break;
530 case BOTTOM:
531 if (!isTabLeadingComponentVisible()) {
532 x--;
533 }
534 if (isSelected) {
535
536 g.setColor(_shadow);
537
538 g.drawLine(x, y + h - 6, x, y);// left
539
540 // left bottom arc
541 g.drawLine(x + 1, y + h - 5, x + 1, y + h - 4);
542 g.drawLine(x + 2, y + h - 3, x + 2, y + h - 3);
543 g.drawLine(x + 3, y + h - 2, x + 3, y + h - 2);
544 g.drawLine(x + 4, y + h - 1, x + 5, y + h - 1);
545
546 if (isTabTopVisible(tabPlacement)) {
547 g.drawLine(x + 5, y + h - 1, x + w - 20, y + h - 1);
548 }
549
550 // right bottom arc
551 g.drawLine(x + w - 20, y + h - 1, x + w - 18, y + h - 1);
552 g.drawLine(x + w - 17, y + h - 2, x + w - 15, y + h - 2);
553 g.drawLine(x + w - 14, y + h - 3, x + w - 13, y + h - 3);
554 g.drawLine(x + w - 12, y + h - 4, x + w - 12, y + h - 4);
555 g.drawLine(x + w - 11, y + h - 5, x + w - 10, y + h - 5);
556
557 // right
558 for (int i = 0; i < h - 10; i++) {
559 g.drawLine(x + w - 9 + i, y + h - 6 - i, x + w - 9 + i, y + h - 6 - i);
560 }
561
562 // right top arc
563 g.drawLine(x + w + h - 19, y + 4, x + w + h - 18, y + 4);
564 g.drawLine(x + w + h - 17, y + 3, x + w + h - 17, y + 3);
565 g.drawLine(x + w + h - 16, y + 2, x + w + h - 15, y + 2);
566 g.drawLine(x + w + h - 14, y + 1, x + w + h - 12, y + 1);
567 g.drawLine(x + w + h - 11, y, x + w + h - 9, y);
568 break;
569 }
570
571 // not selected
572 if (tabIndex > _tabPane.getSelectedIndex()) {
573 g.setColor(_shadow);
574 if (leftToRight) {
575 g.drawLine(x + w - 2, y - 1, x + w - 2, y + h);// right
576 }
577 else {
578 g.drawLine(x, y - 1, x, y + h);// right
579 }
580 break;
581 }
582
583 if (tabIndex >= _tabPane.getSelectedIndex() || tabIndex == 0)
584 break;
585
586 g.setColor(_shadow);
587 if (leftToRight) {
588 g.drawLine(x, y - 1, x, y + h);// left
589 }
590 else {
591 g.drawLine(x + w - 2, y - 1, x + w - 2, y + h);// left
592 }
593 break;
594 case TOP:
595 default:
596 if (!isTabLeadingComponentVisible())
597 x--;
598
599 if (isSelected) {
600 g.setColor(_shadow);
601
602 g.drawLine(x, y + 5, x, y + h);// left
603
604 // left top arc
605 g.drawLine(x + 4, y, x + 5, y);
606 g.drawLine(x + 3, y + 1, x + 3, y + 1);
607 g.drawLine(x + 2, y + 2, x + 2, y + 2);
608 g.drawLine(x + 1, y + 3, x + 1, y + 4);
609
610 if (isTabTopVisible(tabPlacement)) {
611 g.drawLine(x + 5, y, x + w - 20, y);
612 }
613
614 // right top arc
615 g.drawLine(x + w - 20, y, x + w - 18, y);
616 g.drawLine(x + w - 17, y + 1, x + w - 15, y + 1);
617 g.drawLine(x + w - 14, y + 2, x + w - 13, y + 2);
618 g.drawLine(x + w - 12, y + 3, x + w - 12, y + 3);
619 g.drawLine(x + w - 11, y + 4, x + w - 10, y + 4);
620
621 // right
622 for (int i = 0; i < h - 10; i++) {
623 g.drawLine(x + w - 9 + i, y + 5 + i, x + w - 9 + i, y + 5 + i);
624 }
625
626 // right bottom arc
627 g.drawLine(x + w + h - 19, y + h - 5, x + w + h - 18, y + h - 5);
628 g.drawLine(x + w + h - 17, y + h - 4, x + w + h - 17, y + h - 4);
629 g.drawLine(x + w + h - 16, y + h - 3, x + w + h - 15, y + h - 3);
630 g.drawLine(x + w + h - 14, y + h - 2, x + w + h - 12, y + h - 2);
631 g.drawLine(x + w + h - 11, y + h - 1, x + w + h - 9, y + h - 1);
632 break;
633 }
634
635 if (tabIndex > _tabPane.getSelectedIndex()) {
636 g.setColor(_shadow);
637 if (leftToRight) {
638 g.drawLine(x + w - 2, y, x + w - 2, y + (h - 1));// right
639 }
640 else {
641 g.drawLine(x, y, x, y + (h - 1));// left
642 }
643 break;
644 }
645
646 if (tabIndex >= _tabPane.getSelectedIndex() || tabIndex == 0)
647 break;
648 g.setColor(_shadow);
649
650 if (leftToRight) {
651 g.drawLine(x, y, x, y + (h - 1));// left
652 }
653 else {
654 g.drawLine(x + w - 2, y, x + w - 2, y + (h - 1));// left
655 }
656 break;
657 }
658 }
659 else {
660 super.paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
661 }
662 }
663
664 @Override
665 protected void paintTabBackground(Graphics g, int tabPlacement,
666 int tabIndex, int x, int y, int w, int h, boolean isSelected) {
667 if (!PAINT_TAB_BACKGROUND) {
668 return;
669 }
670
671 if (!isSelected) {
672 return;
673 }
674
675 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
676 Graphics2D g2d = (Graphics2D) g;
677 Color background1;
678 Color background2;
679 if (showFocusIndicator()) {
680 background1 = _activeBackground;
681 background2 = UIDefaultsLookup.getColor("DockableFrame.activeTitleBackground2");
682 }
683 else {
684 background1 = _activeBackground;
685 background2 = _background;
686 }
687
688 switch (tabPlacement) {
689 case LEFT: {
690 if (!isTabLeadingComponentVisible())
691 y--;
692 int[] xp = {x + w, x + 5, x, x, x + 6, x + w - 6, x + w};
693 int[] yp = {y, y, y + 4, y + h - 19, y + h - 8,
694 y + h + w - 21, y + h + w - 10};
695 int np = yp.length;
696 Polygon p = new Polygon(xp, yp, np);
697 JideSwingUtilities.fillGradient(g2d, p, background1, background2, false);
698 }
699 break;
700 case RIGHT: {
701 if (!isTabLeadingComponentVisible())
702 y--;
703 int[] xp = {x, x + w - 6, x + w, x + w, x + w - 5, x + 5, x};
704 int[] yp = {y, y, y + 4, y + h - 21, y + h - 10,
705 y + h + w - 21, y + h + w - 10};
706 int np = yp.length;
707 Polygon p = new Polygon(xp, yp, np);
708 JideSwingUtilities.fillGradient(g2d, p, background2, background1, false);
709 }
710 break;
711 case BOTTOM: {
712 if (!isTabLeadingComponentVisible())
713 x--;
714 // not box style
715 int[] xp = {x, x, x + 6, x + w - 20, x + w - 16, x + w - 14,
716 x + w - 12, x + w - 9, x + w + h - 19, x + w + h - 10,
717 x + w + h - 12};
718 int[] yp = {y, y + h - 6, y + h, y + h, y + h - 2, y + h - 3,
719 y + h - 4, y + h - 6, y + 4, y + 1, y};
720 int np = yp.length;
721 Polygon p = new Polygon(xp, yp, np);
722 JideSwingUtilities.fillGradient(g2d, p, background2, background1, true);
723 }
724 break;
725 case TOP:
726 default: {
727 if (!isTabLeadingComponentVisible())
728 x--;
729 int[] xp = {x, x, x + 2, x + 3, x + 6, x + w - 20, x + w - 14,
730 x + w - 12, x + w - 9, x + w + h - 20, x + w + h - 9};
731 int[] yp = {y + h, y + 5, y + 2, y + 1, y, y, y + 2, y + 3,
732 y + 5, y + h - 6, y + h};
733 int np = xp.length;
734 Polygon p = new Polygon(xp, yp, np);
735 JideSwingUtilities.fillGradient(g2d, p, background1, background2, true);
736 }
737 break;
738 }
739 }
740 else {
741 super.paintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
742 }
743 }
744
745
746 @Override
747 protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
748 if (selectedIndex < 0) {
749 return;
750 }
751
752 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
753 int width = _tabPane.getWidth();
754 int height = _tabPane.getHeight();
755 Insets insets = _tabPane.getInsets();
756
757 int x = insets.left;
758 int y = insets.top;
759 int w = width - insets.right - insets.left;
760 int h = height - insets.top - insets.bottom;
761
762 int temp = -1;
763 switch (tabPlacement) {
764 case LEFT:
765 x += calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth);
766 if (isTabLeadingComponentVisible()) {
767 if (_tabLeadingComponent.getSize().width > calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth)) {
768 x = insets.left + _tabLeadingComponent.getSize().width;
769 temp = _tabLeadingComponent.getSize().width;
770 }
771 }
772 if (isTabTrailingComponentVisible()) {
773 if (_maxTabWidth < _tabTrailingComponent.getSize().width
774 && temp < _tabTrailingComponent.getSize().width) {
775 x = insets.left + _tabTrailingComponent.getSize().width;
776 }
777 }
778 w -= (x - insets.left);
779 break;
780 case RIGHT:
781 w -= calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth);
782 break;
783 case BOTTOM:
784 h -= calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight);
785 break;
786 case TOP:
787 default:
788 y += calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight);
789 if (isTabLeadingComponentVisible()) {
790 if (_tabLeadingComponent.getSize().height > calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight)) {
791 y = insets.top + _tabLeadingComponent.getSize().height;
792 temp = _tabLeadingComponent.getSize().height;
793 }
794 }
795 if (isTabTrailingComponentVisible()) {
796 if (_maxTabHeight < _tabTrailingComponent.getSize().height
797 && temp < _tabTrailingComponent.getSize().height) {
798 y = insets.top + _tabTrailingComponent.getSize().height;
799 }
800 }
801 h -= (y - insets.top);
802 }
803
804 // Fill region behind content area
805 paintContentBorder(g, x, y, w, h);
806
807 Rectangle viewRect = _tabScroller.viewport.getViewRect();
808 Rectangle r = _rects[selectedIndex];
809 Rectangle button = _tabScroller.scrollForwardButton.getBounds();
810 Rectangle panel = _tabScroller.tabPanel.getBounds();
811 int lsize = 0;
812
813 if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) {
814 if (isTabLeadingComponentVisible()) {
815 lsize = _tabLeadingComponent.getSize().width;
816 }
817 }
818 else {
819 if (isTabLeadingComponentVisible()) {
820 lsize = _tabLeadingComponent.getSize().height;
821 }
822 }
823
824
825 switch (tabPlacement) {
826 case LEFT:
827 if (r.y < viewRect.y + viewRect.height
828 && r.y + r.height
829 + _tabPane.getBoundsAt(selectedIndex).width - 9 > viewRect.y
830 + viewRect.height) {
831
832 if (selectedIndex != _tabPane.getTabCount() - 1) {
833 viewRect.y += (r.y + r.height + _tabPane.getBoundsAt(selectedIndex).width - 9 - (viewRect.y + viewRect.height));
834 _tabScroller.viewport.setViewPosition(new Point(
835 viewRect.x, viewRect.y));
836 }
837 else {
838 if (panel.y + panel.height + lsize > button.y) {
839 viewRect.y += (r.y + r.height + _tabPane.getBoundsAt(selectedIndex).width - 9 - (viewRect.y + viewRect.height));
840 _tabScroller.viewport.setViewPosition(new Point(
841 viewRect.x, viewRect.y));
842 }
843 else {
844 _tabScroller.viewport.setSize(viewRect.width, viewRect.height + getLayoutSize());
845 }
846
847 }
848
849 }
850 paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
851 break;
852
853 case RIGHT:
854 if (r.y < viewRect.y + viewRect.height
855 && r.y + r.height
856 + _tabPane.getBoundsAt(selectedIndex).width - 9 > viewRect.y
857 + viewRect.height) {
858
859 if (selectedIndex != _tabPane.getTabCount() - 1) {
860 viewRect.y += (r.y + r.height + _tabPane.getBoundsAt(selectedIndex).width - 9 - (viewRect.y + viewRect.height));
861 _tabScroller.viewport.setViewPosition(new Point(viewRect.x, viewRect.y));
862 }
863 else {
864 if (panel.y + panel.height + lsize > button.y) {
865 viewRect.y += (r.y + r.height + _tabPane.getBoundsAt(selectedIndex).width - 9 - (viewRect.y + viewRect.height));
866 _tabScroller.viewport.setViewPosition(new Point(viewRect.x, viewRect.y));
867 }
868 else {
869 _tabScroller.viewport.setSize(viewRect.width, viewRect.height + getLayoutSize());
870 }
871
872 }
873
874 }
875 paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
876 break;
877
878 case BOTTOM:
879 if (r.x < viewRect.x + viewRect.width
880 && r.x + r.width
881 + _tabPane.getBoundsAt(selectedIndex).height
882 - 9 > viewRect.x + viewRect.width) {
883 if (selectedIndex != _tabPane.getTabCount() - 1) {
884 viewRect.x += (r.x + r.width + _tabPane.getBoundsAt(selectedIndex).height - 9 - (viewRect.x + viewRect.width));
885 _tabScroller.viewport.setViewPosition(new Point(
886 viewRect.x, viewRect.y));
887 }
888 else {
889 if (panel.x + panel.width + lsize > button.x) {
890 viewRect.x += (r.x + r.width + _tabPane.getBoundsAt(selectedIndex).height - 9 - (viewRect.x + viewRect.width));
891 _tabScroller.viewport.setViewPosition(new Point(viewRect.x, viewRect.y));
892 }
893 else {
894 _tabScroller.viewport.setSize(viewRect.width + getLayoutSize(), viewRect.height);
895 }
896
897 }
898
899 }
900 paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
901 break;
902
903 case TOP:
904 default:
905
906 if (r.x < viewRect.x + viewRect.width && r.x + r.width + _tabPane.getBoundsAt(selectedIndex).height - 9 > viewRect.x + viewRect.width) {
907 if (selectedIndex != _tabPane.getTabCount() - 1) {
908 viewRect.x += (r.x + r.width + _tabPane.getBoundsAt(selectedIndex).height - 9 - (viewRect.x + viewRect.width));
909 _tabScroller.viewport.setViewPosition(new Point(viewRect.x, viewRect.y));
910 }
911 else {
912 if (panel.x + panel.width + lsize > button.x) {
913 viewRect.x += (r.x + r.width + _tabPane.getBoundsAt(selectedIndex).height - 9 - (viewRect.x + viewRect.width));
914 _tabScroller.viewport.setViewPosition(new Point(viewRect.x, viewRect.y));
915
916 }
917 else {
918 _tabScroller.viewport.setSize(viewRect.width + getLayoutSize(), viewRect.height);
919 }
920 }
921 }
922
923 paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
924 break;
925
926 }
927
928 g.setColor(_shadow);
929 if (_tabPane.isTabShown()) {
930 switch (tabPlacement) {
931 case LEFT:
932 g.drawLine(width - 1, 0, width - 1, height - 1);
933 g.drawLine(6, 0, width - 1, 0);
934 g.drawLine(6, height - 1, width - 1, height - 1);
935 g.drawLine(0, 6, 0, height - 7);
936
937 g.drawLine(1, height - 6, 1, height - 5);
938 g.drawLine(2, height - 4, 2, height - 4);
939 g.drawLine(3, height - 3, 3, height - 3);
940 g.drawLine(4, height - 2, 5, height - 2);
941
942 g.drawLine(4, 1, 5, 1);
943 g.drawLine(3, 2, 3, 2);
944 g.drawLine(2, 3, 2, 3);
945 g.drawLine(1, 4, 1, 5);
946 break;
947 case RIGHT:
948 g.drawLine(0, 0, 0, height - 1);
949 g.drawLine(0, 0, width - 7, 0);
950 g.drawLine(0, height - 1, width - 7, height - 1);
951 g.drawLine(width - 1, 6, width - 1, height - 7);
952
953 g.drawLine(width - 2, height - 6, width - 2, height - 5);
954 g.drawLine(width - 3, height - 4, width - 3, height - 4);
955 g.drawLine(width - 4, height - 3, width - 4, height - 3);
956 g.drawLine(width - 5, height - 2, width - 6, height - 2);
957
958 g.drawLine(width - 6, 1, width - 5, 1);
959 g.drawLine(width - 4, 2, width - 4, 2);
960 g.drawLine(width - 3, 3, width - 3, 3);
961 g.drawLine(width - 2, 4, width - 2, 5);
962 break;
963 case BOTTOM:
964 g.drawLine(0, 0, width - 1, 0);
965 g.drawLine(0, 0, 0, height - 7);
966 g.drawLine(width - 1, 0, width - 1, height - 7);
967 g.drawLine(6, height - 1, width - 7, height - 1);
968
969 g.drawLine(width - 6, height - 2, width - 5, height - 2);
970 g.drawLine(width - 4, height - 3, width - 4, height - 3);
971 g.drawLine(width - 3, height - 4, width - 3, height - 4);
972 g.drawLine(width - 2, height - 5, width - 2, height - 6);
973
974 g.drawLine(1, height - 6, 1, height - 5);
975 g.drawLine(2, height - 4, 2, height - 4);
976 g.drawLine(3, height - 3, 3, height - 3);
977 g.drawLine(4, height - 2, 5, height - 2);
978 break;
979 case TOP:
980 default:
981 g.drawLine(6, 0, width - 7, 0);
982 g.drawLine(0, height - 1, width - 1, height - 1);
983 g.drawLine(width - 1, 6, width - 1, height - 1);
984 g.drawLine(0, 6, 0, height - 1);
985
986 g.drawLine(width - 6, 1, width - 5, 1);
987 g.drawLine(width - 4, 2, width - 4, 2);
988 g.drawLine(width - 3, 3, width - 3, 3);
989 g.drawLine(width - 2, 4, width - 2, 5);
990
991 g.drawLine(4, 1, 5, 1);
992 g.drawLine(3, 2, 3, 2);
993 g.drawLine(2, 3, 2, 3);
994 g.drawLine(1, 4, 1, 5);
995 break;
996 }
997 }
998 else {
999 g.drawRect(0, 0, width - 1, height - 1);
1000 }
1001 }
1002 else {
1003 super.paintContentBorder(g, tabPlacement, selectedIndex);
1004 }
1005
1006 }
1007
1008 // paint the component border of every tab
1009
1010 @Override
1011 protected void paintContentBorder(Graphics g, int x, int y, int w, int h) {
1012 if (!PAINT_CONTENT_BORDER) {
1013 return;
1014 }
1015
1016 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
1017 if (showFocusIndicator()) {
1018 Insets insets = getContentBorderInsets(_tabPane.getTabPlacement());
1019 Color selectedTitleColor2 = UIDefaultsLookup.getColor("DockableFrame.activeTitleBackground2");
1020 g.setColor(selectedTitleColor2);
1021 g.fillRect(x, y, w, insets.top); // top
1022 g.fillRect(x, y, insets.left, h); // left
1023 g.fillRect(x, y + h - insets.bottom, w, insets.bottom); // bottom
1024 g.fillRect(x + w - insets.right, y, insets.right, h); // right
1025 }
1026 }
1027 else {
1028 super.paintContentBorder(g, x, y, w, h);
1029 }
1030 }
1031
1032 // paint the top line of the content when the tab is on the top
1033
1034 @Override
1035 protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
1036 int selectedIndex, int x, int y, int w, int h) {
1037 if (!PAINT_CONTENT_BORDER_EDGE) {
1038 return;
1039 }
1040
1041 if (selectedIndex < 0) {
1042 return;
1043 }
1044
1045 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
1046 Rectangle selRect = getTabBounds(selectedIndex, _calcRect);
1047
1048 Rectangle viewRect = _tabScroller.viewport.getViewRect();
1049 Rectangle r = _rects[selectedIndex];
1050
1051 g.setColor(getPainter().getControlShadow());
1052
1053 // Break line to show visual connection to selected tab
1054 if (isTabLeadingComponentVisible() && selRect.x > 0) {
1055 g.drawLine(x, y, selRect.x, y);
1056 }
1057
1058 if (r.x > viewRect.x) {
1059 g.drawLine(x, y, selRect.x - 1, y);
1060 }
1061
1062 if (_tabPane.isTabShown()) {
1063 if (r.x >= viewRect.x + viewRect.width) {
1064 g.drawLine(x, y, x + w - 1, y);
1065 }
1066 else {
1067 g.drawLine(selRect.x + selRect.width + _tabPane.getBoundsAt(selectedIndex).height - 9, y, x + w - 1, y);
1068 }
1069 }
1070 }
1071 else {
1072 super.paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
1073 }
1074 }
1075
1076 // paint the bottom line of the content when the tab is on the bottom
1077
1078 @Override
1079 protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
1080 int selectedIndex, int x, int y, int w, int h) {
1081 if (!PAINT_CONTENT_BORDER_EDGE) {
1082 return;
1083 }
1084
1085 if (selectedIndex < 0) {
1086 return;
1087 }
1088
1089 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
1090 Rectangle selRect = getTabBounds(selectedIndex, _calcRect);
1091
1092 g.setColor(getPainter().getControlShadow());
1093
1094 Rectangle viewRect = _tabScroller.viewport.getViewRect();
1095 Rectangle r = _rects[selectedIndex];
1096
1097 if (isTabLeadingComponentVisible() && selRect.x > 0) {
1098 g.drawLine(x, y + h - 1, selRect.x, y + h - 1);
1099 }
1100
1101 // Break line to show visual connection to selected tab
1102 if (r.x > viewRect.x) {
1103 g.drawLine(x, y + h - 1, selRect.x - 1, y + h - 1);
1104 }
1105
1106 if (_tabPane.isTabShown()) {
1107 if (r.x >= viewRect.x + viewRect.width) {
1108 g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
1109 }
1110 else {
1111 g.drawLine(selRect.x + selRect.width + _tabPane.getBoundsAt(selectedIndex).height - 9, y + h - 1, x + w - 1, y + h - 1);
1112 }
1113 }
1114 }
1115 else {
1116 super.paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
1117 }
1118
1119 }
1120
1121 // paint the left line of the content when the tab is on the left
1122
1123 @Override
1124 protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
1125 int selectedIndex, int x, int y, int w, int h) {
1126 if (!PAINT_CONTENT_BORDER_EDGE) {
1127 return;
1128 }
1129
1130 if (selectedIndex < 0) {
1131 return;
1132 }
1133
1134 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
1135 Rectangle selRect = getTabBounds(selectedIndex, _calcRect);
1136
1137 Rectangle viewRect = _tabScroller.viewport.getViewRect();
1138 Rectangle r = _rects[selectedIndex];
1139
1140 g.setColor(getPainter().getControlShadow());
1141
1142 if (isTabLeadingComponentVisible() && selRect.y > 0) {
1143 g.drawLine(x, y, x, selRect.y);
1144 }
1145
1146 // Break line to show visual connection to selected tab
1147 if (r.y - 2 > viewRect.y) {
1148 g.drawLine(x, y, x, selRect.y - 3);
1149 }
1150
1151 if (_tabPane.isTabShown()) {
1152 if (r.y >= viewRect.y + viewRect.height) {
1153 g.drawLine(x, y, x, y + h - 1);
1154 }
1155 else {
1156 g.drawLine(x, selRect.y + selRect.height + _tabPane.getBoundsAt(selectedIndex).width - 9, x, y + h - 1);
1157 }
1158 }
1159 }
1160 else {
1161 super.paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
1162 }
1163 }
1164
1165 // paint the right line of the content when the tab is on the right
1166
1167 @Override
1168 protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
1169 int selectedIndex, int x, int y, int w, int h) {
1170 if (!PAINT_CONTENT_BORDER_EDGE) {
1171 return;
1172 }
1173
1174 if (selectedIndex < 0) {
1175 return;
1176 }
1177
1178 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE3X) {
1179 Rectangle selRect = getTabBounds(selectedIndex, _calcRect);
1180
1181 Rectangle viewRect = _tabScroller.viewport.getViewRect();
1182 Rectangle r = _rects[selectedIndex];
1183
1184 g.setColor(getPainter().getControlShadow());
1185
1186 if (isTabLeadingComponentVisible() && selRect.y > 0) {
1187 g.drawLine(x + w - 1, y, x + w - 1, selRect.y);
1188 }
1189
1190 // Break line to show visual connection to selected tab
1191 if (r.y - 2 > viewRect.y) {
1192 g.drawLine(x + w - 1, y, x + w - 1, selRect.y - 3);
1193 }
1194
1195 if (_tabPane.isTabShown()) {
1196 if (r.y >= viewRect.y + viewRect.height) {
1197 g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
1198 }
1199 else {
1200 g.drawLine(x + w - 1, selRect.y + selRect.height + _tabPane.getBoundsAt(selectedIndex).width - 9, x + w - 1, y + h - 1);
1201 }
1202 }
1203 }
1204 else {
1205 super.paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
1206 }
1207 }
1208
1209
1210 @Override
1211 protected Rectangle getTabsTextBoundsAt(int tabIndex) {
1212 Rectangle tabRect = _tabPane.getBoundsAt(tabIndex);
1213 Rectangle iconRect = new Rectangle(), textRect = new Rectangle();
1214
1215 String title = _tabPane.getDisplayTitleAt(tabIndex);
1216 Icon icon = _tabPane.getIconForTab(tabIndex);
1217
1218 SwingUtilities.layoutCompoundLabel(_tabPane, _tabPane.getGraphics()
1219 .getFontMetrics(_tabPane.getFont()), title, icon,
1220 SwingUtilities.CENTER, SwingUtilities.CENTER,
1221 SwingUtilities.CENTER, SwingUtilities.TRAILING, tabRect,
1222 iconRect, textRect, icon == null ? 0 : _textIconGap);
1223
1224 if (_tabPane.getTabPlacement() == JideTabbedPane.TOP || _tabPane.getTabPlacement() == JideTabbedPane.BOTTOM) {
1225 iconRect.x = tabRect.x + _iconMarginHorizon;
1226 textRect.x = (icon != null ? iconRect.x + iconRect.width + _textIconGap : tabRect.x + _textPadding);
1227 }
1228 else {
1229 iconRect.y = tabRect.y + _iconMarginVertical;
1230 textRect.y = (icon != null ? iconRect.y + iconRect.height + _textIconGap : tabRect.y + _textPadding);
1231 iconRect.x = tabRect.x + 2;
1232 textRect.x = tabRect.x + 2;
1233 }
1234
1235 return textRect;
1236 }
1237
1238
1239 @Override
1240 protected void paintFocusIndicator(Graphics g, int tabPlacement,
1241 Rectangle[] rects, int tabIndex, Rectangle iconRect,
1242 Rectangle textRect, boolean isSelected) {
1243 Rectangle tabRect = rects[tabIndex];
1244 if (_tabPane.hasFocus() && isSelected) {
1245 int x, y, w, h;
1246 g.setColor(_focus);
1247 switch (tabPlacement) {
1248 case LEFT:
1249 x = tabRect.x + 2;
1250 y = tabRect.y + 3;
1251 w = tabRect.width - 4;
1252 h = tabRect.height - 19;
1253 break;
1254 case RIGHT:
1255 x = tabRect.x + 2;
1256 y = tabRect.y + 3;
1257 w = tabRect.width - 4;
1258 h = tabRect.height - 19;
1259 break;
1260 case BOTTOM:
1261 x = tabRect.x + 3;
1262 y = tabRect.y + 2;
1263 w = tabRect.width - 19;
1264 h = tabRect.height - 3;
1265 break;
1266 case TOP:
1267 default:
1268 x = tabRect.x + 3;
1269 y = tabRect.y + 2;
1270 w = tabRect.width - 19;
1271 h = tabRect.height - 3;
1272 }
1273 BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
1274 }
1275 }
1276
1277 @Override
1278 protected TabCloseButton createNoFocusButton(int type) {
1279 return new Eclipse3xTabCloseButton(type);
1280 }
1281
1282 public class Eclipse3xTabCloseButton extends TabCloseButton {
1283 public Eclipse3xTabCloseButton(int type) {
1284 super(type);
1285 }
1286
1287 @Override
1288 public Dimension getPreferredSize() {
1289 return new Dimension(15, 15);
1290 }
1291
1292 @Override
1293 protected void paintComponent(Graphics g) {
1294 if (!isEnabled()) {
1295 setMouseOver(false);
1296 setMousePressed(false);
1297 }
1298 g.setColor(UIDefaultsLookup.getColor("controlShadow").darker());
1299 int centerX = getWidth() >> 1;
1300 int centerY = getHeight() >> 1;
1301 switch (getType()) {
1302 case CLOSE_BUTTON:
1303 g.drawLine(centerX - 4, centerY - 4, centerX - 2, centerY - 4); // top-left top
1304 g.drawLine(centerX - 4, centerY - 4, centerX - 4, centerY - 2); // top-left left
1305
1306 g.drawLine(centerX - 1, centerY - 3, centerX - 0, centerY - 2); // top-left top-diag
1307 g.drawLine(centerX - 3, centerY - 1, centerX - 2, centerY - 0); // top-left left-diag
1308
1309 g.drawLine(centerX + 3, centerY - 4, centerX + 5, centerY - 4); // top-right top
1310 g.drawLine(centerX + 5, centerY - 4, centerX + 5, centerY - 2); // top-right right
1311
1312 g.drawLine(centerX + 2, centerY - 3, centerX + 1, centerY - 2); // top-right top-diag
1313 g.drawLine(centerX + 4, centerY - 1, centerX + 3, centerY - 0); // top-right right-diag
1314
1315 g.drawLine(centerX - 4, centerY + 5, centerX - 2, centerY + 5); // bottom-left bottom
1316 g.drawLine(centerX - 4, centerY + 5, centerX - 4, centerY + 3); // bottom-left left
1317
1318 g.drawLine(centerX - 1, centerY + 4, centerX - 0, centerY + 3); // bottom-left bottom-diag
1319 g.drawLine(centerX - 3, centerY + 2, centerX - 2, centerY + 1); // bottom-left left-diag
1320
1321 g.drawLine(centerX + 3, centerY + 5, centerX + 5, centerY + 5); // bottom-right bottom
1322 g.drawLine(centerX + 5, centerY + 5, centerX + 5, centerY + 3); // bottom-right right
1323
1324 g.drawLine(centerX + 2, centerY + 4, centerX + 1, centerY + 3); // bottom-right bottom-diag
1325 g.drawLine(centerX + 4, centerY + 2, centerX + 3, centerY + 1); // bottom-right right-diag
1326
1327 if (isMouseOver()) {
1328 g.setColor(new Color(252, 160, 160));
1329 }
1330 else {
1331 g.setColor(Color.WHITE);
1332 }
1333 g.drawLine(centerX - 2, centerY - 3, centerX + 4, centerY + 3);
1334 g.drawLine(centerX - 3, centerY - 3, centerX + 4, centerY + 4);
1335 g.drawLine(centerX - 3, centerY - 2, centerX + 3, centerY + 4);
1336
1337 g.drawLine(centerX - 3, centerY + 3, centerX + 3, centerY - 3);
1338 g.drawLine(centerX - 3, centerY + 4, centerX + 4, centerY - 3);
1339 g.drawLine(centerX - 2, centerY + 4, centerX + 4, centerY - 2);
1340 break;
1341 default:
1342 super.paintComponent(g);
1343 }
1344 }
1345 }
1346 }