Debian Codegraph @

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

raw
1 /*
2 * @(#)WindowsTabbedPaneUI.java
3 *
4 * Copyright 2002 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 java.awt.*;
17
18
19 /**
20 * JideTabbedPane UI implementation
21 */
22 public class EclipseJideTabbedPaneUI extends VsnetJideTabbedPaneUI {
23
24 public static ComponentUI createUI(JComponent c) {
25 return new EclipseJideTabbedPaneUI();
26 }
27
28 /**
29 * this function draws the border around each tab
30 * note that this function does now draw the background of the tab.
31 * that is done elsewhere
32 */
33 @Override
34 protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
35 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
36 Color old = g.getColor();
37
38 boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight();
39
40 switch (tabPlacement) {
41 case LEFT:
42 if (isSelected) {
43 g.setColor(_lightHighlight);
44 g.drawRect(x + 1, y + 1, w - 1, h - 3);
45
46 g.setColor(_shadow);
47 g.drawLine(x + 1, y, x + w - 1, y);
48 g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
49 g.drawLine(x, y + 1, x, y + 1);
50 g.drawLine(x, y + h - 2, x, y + h - 2);
51 }
52 else {
53 g.setColor(_shadow);
54 if (tabIndex > _tabPane.getSelectedIndex()/* && tabIndex != _tabPane.getTabCount() - 1*/) {
55 if (tabIndex == _tabPane.getTabCount() - 1) {
56 g.drawLine(x, y + h - 1, x + w, y + h - 1); // bottom shadow
57 }
58 else {
59 g.drawLine(x, y + h - 1, x + w / 2, y + h - 1); // bottom shadow
60 }
61 }
62 else if (tabIndex < _tabPane.getSelectedIndex()) {
63 if (tabIndex != 0) {
64 g.drawLine(x, y, x + w / 2, y); // top shadow
65 }
66 else {
67 if (isTabLeadingComponentVisible()) {
68 g.drawLine(x, y, x + w, y); // top shadow
69 }
70 }
71 }
72 }
73
74 if (isTabTopVisible(tabPlacement)) {
75 g.setColor(_shadow);
76 g.drawLine(x, y, x, y + h - 1); // tab top
77 }
78 break;
79 case RIGHT:
80 if (isSelected) {
81 g.setColor(_lightHighlight);
82 g.drawRect(x, y + 1, w - 1, h - 3);
83
84 g.setColor(_shadow);
85 g.drawLine(x, y, x + w - 1, y);
86 g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
87 g.drawLine(x + w, y + 1, x + w, y + 1);
88 g.drawLine(x + w, y + h - 2, x + w, y + h - 2);
89 }
90 else { // not selected
91 g.setColor(_shadow);
92 if (tabIndex > _tabPane.getSelectedIndex()) {
93 if (tabIndex == _tabPane.getTabCount() - 1) {
94 g.drawLine(x, y + h - 1, x + w, y + h - 1); // bottom shadow
95 }
96 else {
97 g.drawLine(x + w / 2, y + h - 1, x + w, y + h - 1); // bottom shadow
98 }
99 }
100 else if (tabIndex < _tabPane.getSelectedIndex()) {
101 if (tabIndex != 0) {
102 g.drawLine(x + w / 2, y, x + w, y); // top shadow
103 }
104 else {
105 if (isTabLeadingComponentVisible()) {
106 g.drawLine(x, y, x + w, y); // top shadow
107 }
108 }
109 }
110 }
111
112 if (isTabTopVisible(tabPlacement)) {
113 g.setColor(_shadow);
114 g.drawLine(x + w, y, x + w, y + h - 1); // tab top
115 }
116 break;
117 case BOTTOM:
118 if (isSelected) {
119 g.setColor(_lightHighlight);
120 g.drawRect(x + 1, y, w - 3, h - 1);
121
122 g.setColor(_shadow);
123 g.drawLine(x, y, x, y + h - 1);
124 g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
125 g.drawLine(x + 1, y + h, x + 1, y + h);
126 g.drawLine(x + w - 2, y + h, x + w - 2, y + h);
127 }
128 else { // not selected
129 g.setColor(_shadow);
130 if (leftToRight) {
131 if (tabIndex > _tabPane.getSelectedIndex()) {
132 if (tabIndex == _tabPane.getTabCount() - 1) {
133 g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
134 }
135 else {
136 g.drawLine(x + w - 1, y + h / 2, x + w - 1, y + h); // right shadow
137 }
138 }
139 else if (tabIndex < _tabPane.getSelectedIndex()) {
140 if (tabIndex != 0) {
141 g.drawLine(x, y + h / 2, x, y + h); // right shadow
142 }
143 else {
144 if (isTabLeadingComponentVisible()) {
145 g.drawLine(x, y, x, y + h); // right shadow
146 }
147 }
148 }
149 }
150 else {
151 if (tabIndex > _tabPane.getSelectedIndex()) {
152 if (tabIndex == _tabPane.getTabCount() - 1) {
153 g.drawLine(x, y, x, y + h); // right shadow
154 }
155 else {
156 g.drawLine(x, y + h / 2, x, y + h); // right shadow
157 }
158 }
159 else if (tabIndex < _tabPane.getSelectedIndex()) {
160 if (tabIndex != 0) {
161 g.drawLine(x + w - 1, y + h / 2, x + w - 1, y + h); // right shadow
162 }
163 else {
164 if (isTabLeadingComponentVisible()) {
165 g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
166 }
167 }
168 }
169
170 }
171 }
172
173 if (isTabTopVisible(tabPlacement)) {
174 g.setColor(_shadow);
175 g.drawLine(x, y + h, x + w - 1, y + h); // tab top
176 }
177 break;
178 case TOP:
179 default:
180 if (isSelected) {
181 g.setColor(_lightHighlight);
182 g.drawRect(x + 1, y + 1, w - 3, h);
183
184 g.setColor(_shadow);
185 g.drawLine(x, y + 1, x, y + h - 1);
186 g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
187 g.drawLine(x + 1, y, x + 1, y);
188 g.drawLine(x + w - 2, y, x + w - 2, y);
189 }
190 else {
191 g.setColor(_shadow);
192 if (leftToRight) {
193 if (tabIndex > _tabPane.getSelectedIndex()) {
194 if (tabIndex == _tabPane.getTabCount() - 1) {
195 g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
196 }
197 else {
198 g.drawLine(x + w - 1, y, x + w - 1, y + h / 2); // right shadow
199 }
200 }
201 else if (tabIndex < _tabPane.getSelectedIndex()) {
202 if (tabIndex != 0) {
203 g.drawLine(x, y, x, y + h / 2); // right shadow
204 }
205 else {
206 if (isTabLeadingComponentVisible()) {
207 g.drawLine(x, y, x, y + h); // right shadow
208 }
209 }
210 }
211 }
212 else {
213 if (tabIndex > _tabPane.getSelectedIndex()) {
214 if (tabIndex == _tabPane.getTabCount() - 1) {
215 g.drawLine(x, y, x, y + h); // right shadow
216 }
217 else {
218 g.drawLine(x, y, x, y + h / 2); // right shadow
219 }
220 }
221 else if (tabIndex < _tabPane.getSelectedIndex()) {
222 if (tabIndex != 0) {
223 g.drawLine(x + w - 1, y, x + w - 1, y + h / 2); // right shadow
224 }
225 else {
226 if (isTabLeadingComponentVisible()) {
227 g.drawLine(x + w - 1, y, x + w - 1, y + h); // right shadow
228 }
229 }
230 }
231 }
232 }
233
234 if (isTabTopVisible(tabPlacement)) {
235 g.setColor(_shadow);
236 g.drawLine(x, y, x + w - 1, y); // tab top
237 }
238 break;
239 }
240 g.setColor(old);
241
242 }
243 else {
244 super.paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
245 }
246 }
247
248 @Override
249 protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex, Component c) {
250 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
251 int tabCount = _tabPane.getTabCount();
252
253 Rectangle iconRect = new Rectangle(),
254 textRect = new Rectangle();
255 Rectangle clipRect = g.getClipBounds();
256
257 g.setColor(_tabBackground);
258 g.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
259
260 // Paint tabRuns of tabs from back to front
261 for (int i = _runCount - 1; i >= 0; i--) {
262 int start = _tabRuns[i];
263 int next = _tabRuns[(i == _runCount - 1) ? 0 : i + 1];
264 int end = (next != 0 ? next - 1 : tabCount - 1);
265 for (int j = start; j <= end; j++) {
266 if (_rects[j].intersects(clipRect)) {
267 paintTab(g, tabPlacement, _rects, j, iconRect, textRect);
268 }
269 }
270 }
271
272 // Paint selected tab if its in the front run
273 // since it may overlap other tabs
274 if (selectedIndex >= 0 && getRunForTab(tabCount, selectedIndex) == 0) {
275 if (_rects[selectedIndex].intersects(clipRect)) {
276 paintTab(g, tabPlacement, _rects, selectedIndex, iconRect, textRect);
277 }
278 }
279 }
280 else {
281 super.paintTabArea(g, tabPlacement, selectedIndex, c);
282 }
283 }
284
285 @Override
286 protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
287 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
288 if (_tabPane.isTabShown()) {
289 g.setColor(_shadow);
290 g.drawLine(x, y, x + w - 1, y);
291 }
292 }
293 else {
294 super.paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
295 }
296 }
297
298 @Override
299 protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
300 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
301 if (_tabPane.isTabShown()) {
302 g.setColor(_shadow);
303 g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
304 }
305 }
306 else {
307 super.paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
308 }
309 }
310
311 @Override
312 protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
313 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
314 if (_tabPane.isTabShown()) {
315 g.setColor(_shadow);
316 g.drawLine(x, y, x, y + h - 1);
317 }
318 }
319 else {
320 super.paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
321 }
322 }
323
324 @Override
325 protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
326 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
327 if (_tabPane.isTabShown()) {
328 g.setColor(_shadow);
329 g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
330 }
331 }
332 else {
333 super.paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
334 }
335 }
336
337 @Override
338 protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
339 if (getTabShape() == JideTabbedPane.SHAPE_ECLIPSE) {
340 _tabPane.setBackgroundAt(tabIndex, _tabBackground);
341
342 if (isSelected) {
343 Color background1;
344 Color background2;
345 if (showFocusIndicator()) {
346 background1 = _activeBackground;
347 background2 = UIDefaultsLookup.getColor("DockableFrame.activeTitleBackground2");
348 }
349 else {
350 background1 = Color.WHITE;
351 background2 = _background;
352 }
353
354 Graphics2D g2d = (Graphics2D) g;
355 int buttonSize = 16;
356 int restWidth = w - (isShowCloseButtonOnTab() ? buttonSize : 0) - 3;
357 int restHeight = h - (isShowCloseButtonOnTab() ? buttonSize : 0) - 3;
358 switch (tabPlacement) {
359 case LEFT:
360 JideSwingUtilities.fillGradient(g2d, new Rectangle(x, y + 1, w, restHeight >> 1), background1, background2, true);
361 break;
362 case RIGHT:
363 JideSwingUtilities.fillGradient(g2d, new Rectangle(x, y + 1, w - 1, restHeight >> 1), background1, background2, true);
364 break;
365 case BOTTOM:
366 JideSwingUtilities.fillGradient(g2d, new Rectangle(x + 1, y, restWidth >> 1, h - 1), background1, background2, false);
367 break;
368 case TOP:
369 default:
370 JideSwingUtilities.fillGradient(g2d, new Rectangle(x + 1, y + 1, restWidth >> 1, h), background1, background2, false);
371 break;
372 }
373 switch (tabPlacement) {
374 case LEFT:
375 JideSwingUtilities.fillGradient(g2d, new Rectangle(x, y + 1 + (restHeight >> 1), w, restHeight >> 1), background2, _tabBackground, true);
376 break;
377 case RIGHT:
378 JideSwingUtilities.fillGradient(g2d, new Rectangle(x, y + 1 + (restHeight >> 1), w - 1, restHeight >> 1), background2, _tabBackground, true);
379 break;
380 case BOTTOM:
381 JideSwingUtilities.fillGradient(g2d, new Rectangle(x + 1 + (restWidth >> 1), y, restWidth >> 1, h - 1), background2, _tabBackground, false);
382 break;
383 case TOP:
384 default:
385 JideSwingUtilities.fillGradient(g2d, new Rectangle(x + 1 + (restWidth >> 1), y + 1, restWidth >> 1, h), background2, _tabBackground, false);
386 break;
387 }
388 }
389 else {
390 super.paintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
391 }
392 }
393 else {
394 super.paintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
395 }
396 }
397 }