48 * @author Tom Santos |
48 * @author Tom Santos |
49 */ |
49 */ |
50 @SuppressWarnings("serial") // Same-version serialization only |
50 @SuppressWarnings("serial") // Same-version serialization only |
51 public class MetalTabbedPaneUI extends BasicTabbedPaneUI { |
51 public class MetalTabbedPaneUI extends BasicTabbedPaneUI { |
52 |
52 |
|
53 /** |
|
54 * The minimum width of a pane. |
|
55 */ |
53 protected int minTabWidth = 40; |
56 protected int minTabWidth = 40; |
54 // Background color for unselected tabs that don't have an explicitly |
57 // Background color for unselected tabs that don't have an explicitly |
55 // set color. |
58 // set color. |
56 private Color unselectedBackground; |
59 private Color unselectedBackground; |
|
60 |
|
61 /** |
|
62 * The color of tab's background. |
|
63 */ |
57 protected Color tabAreaBackground; |
64 protected Color tabAreaBackground; |
|
65 |
|
66 /** |
|
67 * The color of the selected pane. |
|
68 */ |
58 protected Color selectColor; |
69 protected Color selectColor; |
|
70 |
|
71 /** |
|
72 * The color of the highlight. |
|
73 */ |
59 protected Color selectHighlight; |
74 protected Color selectHighlight; |
60 private boolean tabsOpaque = true; |
75 private boolean tabsOpaque = true; |
61 |
76 |
62 // Whether or not we're using ocean. This is cached as it is used |
77 // Whether or not we're using ocean. This is cached as it is used |
63 // extensively during painting. |
78 // extensively during painting. |
64 private boolean ocean; |
79 private boolean ocean; |
65 // Selected border color for ocean. |
80 // Selected border color for ocean. |
66 private Color oceanSelectedBorderColor; |
81 private Color oceanSelectedBorderColor; |
67 |
82 |
|
83 /** |
|
84 * Constructs {@code MetalTabbedPaneUI}. |
|
85 * |
|
86 * @param x a component |
|
87 * @return an instance of {@code MetalTabbedPaneUI} |
|
88 */ |
68 public static ComponentUI createUI( JComponent x ) { |
89 public static ComponentUI createUI( JComponent x ) { |
69 return new MetalTabbedPaneUI(); |
90 return new MetalTabbedPaneUI(); |
70 } |
91 } |
71 |
92 |
72 protected LayoutManager createLayoutManager() { |
93 protected LayoutManager createLayoutManager() { |
114 paintTopTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); |
135 paintTopTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); |
115 } |
136 } |
116 } |
137 } |
117 |
138 |
118 |
139 |
|
140 /** |
|
141 * Paints the top tab border. |
|
142 * |
|
143 * @param tabIndex a tab index |
|
144 * @param g an instance of {@code Graphics} |
|
145 * @param x an X coordinate |
|
146 * @param y an Y coordinate |
|
147 * @param w a width |
|
148 * @param h a height |
|
149 * @param btm bottom |
|
150 * @param rght right |
|
151 * @param isSelected a selection |
|
152 */ |
119 protected void paintTopTabBorder( int tabIndex, Graphics g, |
153 protected void paintTopTabBorder( int tabIndex, Graphics g, |
120 int x, int y, int w, int h, |
154 int x, int y, int w, int h, |
121 int btm, int rght, |
155 int btm, int rght, |
122 boolean isSelected ) { |
156 boolean isSelected ) { |
123 int currentRun = getRunForTab( tabPane.getTabCount(), tabIndex ); |
157 int currentRun = getRunForTab( tabPane.getTabCount(), tabIndex ); |
284 } |
318 } |
285 |
319 |
286 g.translate( -x, -y ); |
320 g.translate( -x, -y ); |
287 } |
321 } |
288 |
322 |
|
323 /** |
|
324 * Returns {@code true} if the gap should be filled. |
|
325 * |
|
326 * @param currentRun the current run |
|
327 * @param tabIndex the tab index |
|
328 * @param x an X coordinate |
|
329 * @param y an Y coordinate |
|
330 * @return {@code true} if the gap should be filled |
|
331 */ |
289 protected boolean shouldFillGap( int currentRun, int tabIndex, int x, int y ) { |
332 protected boolean shouldFillGap( int currentRun, int tabIndex, int x, int y ) { |
290 boolean result = false; |
333 boolean result = false; |
291 |
334 |
292 if (!tabsOpaque) { |
335 if (!tabsOpaque) { |
293 return false; |
336 return false; |
320 } |
363 } |
321 |
364 |
322 return result; |
365 return result; |
323 } |
366 } |
324 |
367 |
|
368 /** |
|
369 * Returns the color of the gap. |
|
370 * |
|
371 * @param currentRun the current run |
|
372 * @param x an X coordinate |
|
373 * @param y an Y coordinate |
|
374 * @return the color of the gap |
|
375 */ |
325 protected Color getColorForGap( int currentRun, int x, int y ) { |
376 protected Color getColorForGap( int currentRun, int x, int y ) { |
326 final int shadowWidth = 4; |
377 final int shadowWidth = 4; |
327 int selectedIndex = tabPane.getSelectedIndex(); |
378 int selectedIndex = tabPane.getSelectedIndex(); |
328 int startIndex = tabRuns[ currentRun + 1 ]; |
379 int startIndex = tabRuns[ currentRun + 1 ]; |
329 int endIndex = lastTabInRun( tabPane.getTabCount(), currentRun + 1 ); |
380 int endIndex = lastTabInRun( tabPane.getTabCount(), currentRun + 1 ); |
347 } |
398 } |
348 |
399 |
349 return tabPane.getBackground(); |
400 return tabPane.getBackground(); |
350 } |
401 } |
351 |
402 |
|
403 /** |
|
404 * Paints the left tab border. |
|
405 * |
|
406 * @param tabIndex a tab index |
|
407 * @param g an instance of {@code Graphics} |
|
408 * @param x an X coordinate |
|
409 * @param y an Y coordinate |
|
410 * @param w a width |
|
411 * @param h a height |
|
412 * @param btm bottom |
|
413 * @param rght right |
|
414 * @param isSelected a selection |
|
415 */ |
352 protected void paintLeftTabBorder( int tabIndex, Graphics g, |
416 protected void paintLeftTabBorder( int tabIndex, Graphics g, |
353 int x, int y, int w, int h, |
417 int x, int y, int w, int h, |
354 int btm, int rght, |
418 int btm, int rght, |
355 boolean isSelected ) { |
419 boolean isSelected ) { |
356 int tabCount = tabPane.getTabCount(); |
420 int tabCount = tabPane.getTabCount(); |
464 |
528 |
465 g.translate( -x, -y ); |
529 g.translate( -x, -y ); |
466 } |
530 } |
467 |
531 |
468 |
532 |
|
533 /** |
|
534 * Paints the bottom tab border. |
|
535 * |
|
536 * @param tabIndex a tab index |
|
537 * @param g an instance of {@code Graphics} |
|
538 * @param x an X coordinate |
|
539 * @param y an Y coordinate |
|
540 * @param w a width |
|
541 * @param h a height |
|
542 * @param btm bottom |
|
543 * @param rght right |
|
544 * @param isSelected a selection |
|
545 */ |
469 protected void paintBottomTabBorder( int tabIndex, Graphics g, |
546 protected void paintBottomTabBorder( int tabIndex, Graphics g, |
470 int x, int y, int w, int h, |
547 int x, int y, int w, int h, |
471 int btm, int rght, |
548 int btm, int rght, |
472 boolean isSelected ) { |
549 boolean isSelected ) { |
473 int tabCount = tabPane.getTabCount(); |
550 int tabCount = tabPane.getTabCount(); |
621 } |
698 } |
622 |
699 |
623 g.translate( -x, -y ); |
700 g.translate( -x, -y ); |
624 } |
701 } |
625 |
702 |
|
703 /** |
|
704 * Paints the right tab border. |
|
705 * |
|
706 * @param tabIndex a tab index |
|
707 * @param g an instance of {@code Graphics} |
|
708 * @param x an X coordinate |
|
709 * @param y an Y coordinate |
|
710 * @param w a width |
|
711 * @param h a height |
|
712 * @param btm bottom |
|
713 * @param rght right |
|
714 * @param isSelected a selection |
|
715 */ |
626 protected void paintRightTabBorder( int tabIndex, Graphics g, |
716 protected void paintRightTabBorder( int tabIndex, Graphics g, |
627 int x, int y, int w, int h, |
717 int x, int y, int w, int h, |
628 int btm, int rght, |
718 int btm, int rght, |
629 boolean isSelected ) { |
719 boolean isSelected ) { |
630 int tabCount = tabPane.getTabCount(); |
720 int tabCount = tabPane.getTabCount(); |
1156 return maxTabHeight / 2; |
1249 return maxTabHeight / 2; |
1157 } |
1250 } |
1158 return 0; |
1251 return 0; |
1159 } |
1252 } |
1160 |
1253 |
1161 // Don't rotate runs! |
1254 /** |
|
1255 * Returns {@code true} if tab runs should be rotated. |
|
1256 * |
|
1257 * @param tabPlacement a tab placement |
|
1258 * @param selectedRun a selected run |
|
1259 * @return {@code true} if tab runs should be rotated. |
|
1260 */ |
1162 protected boolean shouldRotateTabRuns( int tabPlacement, int selectedRun ) { |
1261 protected boolean shouldRotateTabRuns( int tabPlacement, int selectedRun ) { |
1163 return false; |
1262 return false; |
1164 } |
1263 } |
1165 |
1264 |
1166 // Don't pad last run |
1265 // Don't pad last run |
1198 * This class should be treated as a "protected" inner class. |
1297 * This class should be treated as a "protected" inner class. |
1199 * Instantiate it only within subclasses of {@code MetalTabbedPaneUI}. |
1298 * Instantiate it only within subclasses of {@code MetalTabbedPaneUI}. |
1200 */ |
1299 */ |
1201 public class TabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout { |
1300 public class TabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout { |
1202 |
1301 |
|
1302 /** |
|
1303 * Constructs {@code TabbedPaneLayout}. |
|
1304 */ |
1203 public TabbedPaneLayout() { |
1305 public TabbedPaneLayout() { |
1204 MetalTabbedPaneUI.this.super(); |
1306 MetalTabbedPaneUI.this.super(); |
1205 } |
1307 } |
1206 |
1308 |
1207 protected void normalizeTabRuns( int tabPlacement, int tabCount, |
1309 protected void normalizeTabRuns( int tabPlacement, int tabCount, |