| 1 |
/* @(#)BasicJideTabbedPaneUI.java |
| 2 |
* |
| 3 |
* Copyright 2002 JIDE Software Inc. All rights reserved. |
| 4 |
*/ |
| 5 |
|
| 6 |
package com.jidesoft.plaf.basic; |
| 7 |
|
| 8 |
import com.jidesoft.plaf.JideTabbedPaneUI; |
| 9 |
import com.jidesoft.plaf.UIDefaultsLookup; |
| 10 |
import com.jidesoft.swing.JideSwingUtilities; |
| 11 |
import com.jidesoft.swing.JideTabbedPane; |
| 12 |
import com.jidesoft.swing.PartialLineBorder; |
| 13 |
import com.jidesoft.swing.TabColorProvider; |
| 14 |
import com.jidesoft.utils.SecurityUtils; |
| 15 |
import com.jidesoft.utils.SystemInfo; |
| 16 |
|
| 17 |
import javax.swing.*; |
| 18 |
import javax.swing.Timer; |
| 19 |
import javax.swing.event.ChangeEvent; |
| 20 |
import javax.swing.event.ChangeListener; |
| 21 |
import javax.swing.event.DocumentEvent; |
| 22 |
import javax.swing.event.DocumentListener; |
| 23 |
import javax.swing.plaf.*; |
| 24 |
import javax.swing.plaf.basic.BasicGraphicsUtils; |
| 25 |
import javax.swing.plaf.basic.BasicHTML; |
| 26 |
import javax.swing.text.View; |
| 27 |
import java.awt.*; |
| 28 |
import java.awt.dnd.*; |
| 29 |
import java.awt.event.*; |
| 30 |
import java.awt.geom.AffineTransform; |
| 31 |
import java.beans.PropertyChangeEvent; |
| 32 |
import java.beans.PropertyChangeListener; |
| 33 |
import java.util.*; |
| 34 |
import java.util.List; |
| 35 |
|
| 36 |
/** |
| 37 |
* A basic L&f implementation of JideTabbedPaneUI |
| 38 |
*/ |
| 39 |
public class BasicJideTabbedPaneUI extends JideTabbedPaneUI implements SwingConstants, DocumentListener { |
| 40 |
|
| 41 |
// pixels |
| 42 |
protected int _tabRectPadding;// distance from tab rect to icon/text |
| 43 |
|
| 44 |
protected int _closeButtonMarginHorizon; // when tab is on top or bottom, and each tab has close button, the gap around the close button |
| 45 |
|
| 46 |
protected int _closeButtonMarginVertical;// when tab is on left or right, and each tab has close button, the gap around the close button |
| 47 |
|
| 48 |
protected int _textMarginVertical;// tab area and text area gap |
| 49 |
|
| 50 |
protected int _noIconMargin;// gap around text area when there is no icon |
| 51 |
|
| 52 |
protected int _iconMargin;// distance from icon to tab rect start x |
| 53 |
|
| 54 |
protected int _textPadding;// distance from text to tab rect start |
| 55 |
|
| 56 |
protected int _buttonSize;// scroll button size |
| 57 |
|
| 58 |
protected int _buttonMargin;// scroll button margin |
| 59 |
|
| 60 |
protected int _fitStyleBoundSize;// margin for the whole tab area |
| 61 |
|
| 62 |
protected int _fitStyleFirstTabMargin;// the first tab position |
| 63 |
|
| 64 |
protected int _fitStyleIconMinWidth;// minimum width to display icon |
| 65 |
|
| 66 |
protected int _fitStyleTextMinWidth;// minimum width to display text |
| 67 |
|
| 68 |
protected int _compressedStyleNoIconRectSize;// tab size when there is no icon and tab not selected |
| 69 |
|
| 70 |
protected int _compressedStyleIconMargin;// margin around icon |
| 71 |
|
| 72 |
protected int _compressedStyleCloseButtonMarginHorizon;// the close button margin on the left or right when the tab is on the top or bottom |
| 73 |
|
| 74 |
protected int _compressedStyleCloseButtonMarginVertical;// the close button margin on the top or bottom when the tab is on the left or right |
| 75 |
|
| 76 |
protected int _fixedStyleRectSize;// tab rect size |
| 77 |
|
| 78 |
protected int _closeButtonMargin;// margin around close button |
| 79 |
|
| 80 |
protected int _gripLeftMargin;// left margin |
| 81 |
|
| 82 |
protected int _closeButtonMarginSize;// margin around the close button |
| 83 |
|
| 84 |
protected int _closeButtonLeftMargin;// the close button gap when the tab is on the left |
| 85 |
|
| 86 |
protected int _closeButtonRightMargin;// the close button gap when the tab is on the right |
| 87 |
|
| 88 |
|
| 89 |
protected Component _tabLeadingComponent = null; |
| 90 |
|
| 91 |
protected Component _tabTrailingComponent = null; |
| 92 |
|
| 93 |
protected JideTabbedPane _tabPane; |
| 94 |
|
| 95 |
protected Font _selectedTabFont; |
| 96 |
protected Color _tabBackground; |
| 97 |
|
| 98 |
protected Color _background; |
| 99 |
|
| 100 |
protected Color _highlight; |
| 101 |
|
| 102 |
protected Color _lightHighlight; |
| 103 |
|
| 104 |
protected Color _shadow; |
| 105 |
|
| 106 |
protected Color _darkShadow; |
| 107 |
|
| 108 |
protected Color _focus; |
| 109 |
|
| 110 |
protected Color _inactiveTabForeground; |
| 111 |
protected Color _inactiveSelectedTabForeground; |
| 112 |
protected Color _activeTabForeground; |
| 113 |
protected Color _tabListBackground; |
| 114 |
|
| 115 |
protected Color _selectedColor; |
| 116 |
protected Color _activeBackground; |
| 117 |
|
| 118 |
protected int _textIconGap; |
| 119 |
|
| 120 |
protected int _tabRunOverlay; |
| 121 |
|
| 122 |
protected boolean _showIconOnTab; |
| 123 |
|
| 124 |
protected boolean _showCloseButtonOnTab; |
| 125 |
|
| 126 |
protected int _closeButtonAlignment = SwingConstants.TRAILING; |
| 127 |
|
| 128 |
protected Insets _tabInsets; |
| 129 |
|
| 130 |
protected Insets _selectedTabPadInsets; |
| 131 |
|
| 132 |
protected Insets _tabAreaInsets; |
| 133 |
|
| 134 |
protected boolean _ignoreContentBorderInsetsIfNoTabs; |
| 135 |
|
| 136 |
// Transient variables (recalculated each time TabbedPane is laid out) |
| 137 |
|
| 138 |
protected int _tabRuns[] = new int[10]; |
| 139 |
|
| 140 |
protected int _runCount = 0; |
| 141 |
|
| 142 |
protected int _selectedRun = -1; |
| 143 |
|
| 144 |
protected Rectangle _rects[] = new Rectangle[0]; |
| 145 |
protected int _additionalWidth = 0; |
| 146 |
|
| 147 |
protected int _maxTabHeight; |
| 148 |
|
| 149 |
protected int _maxTabWidth; |
| 150 |
|
| 151 |
protected int _gripperWidth = 6; |
| 152 |
|
| 153 |
protected int _gripperHeight = 6; |
| 154 |
|
| 155 |
// Listeners |
| 156 |
|
| 157 |
protected ChangeListener _tabChangeListener; |
| 158 |
protected FocusListener _tabFocusListener; |
| 159 |
|
| 160 |
protected PropertyChangeListener _propertyChangeListener; |
| 161 |
protected ChangeListener _tabModelChangeListener; |
| 162 |
|
| 163 |
protected MouseListener _mouseListener; |
| 164 |
|
| 165 |
protected MouseMotionListener _mousemotionListener; |
| 166 |
|
| 167 |
protected MouseWheelListener _mouseWheelListener; |
| 168 |
|
| 169 |
// PENDING(api): See comment for ContainerHandler |
| 170 |
private ContainerListener _containerListener; |
| 171 |
|
| 172 |
private ComponentListener _componentListener; |
| 173 |
|
| 174 |
// Private instance data |
| 175 |
|
| 176 |
private Insets _currentTabInsets = new Insets(0, 0, 0, 0); |
| 177 |
|
| 178 |
private Insets _currentPadInsets = new Insets(0, 0, 0, 0); |
| 179 |
|
| 180 |
private Insets _currentTabAreaInsets = new Insets(2, 4, 0, 4); |
| 181 |
|
| 182 |
private Insets _currentContentBorderInsets = new Insets(3, 0, 0, 0); |
| 183 |
|
| 184 |
private Component visibleComponent; |
| 185 |
|
| 186 |
// PENDING(api): See comment for ContainerHandler |
| 187 |
private Vector htmlViews; |
| 188 |
|
| 189 |
private Hashtable _mnemonicToIndexMap; |
| 190 |
|
| 191 |
/** |
| 192 |
* InputMap used for mnemonics. Only non-null if the JTabbedPane has mnemonics associated with it. Lazily created in |
| 193 |
* initMnemonics. |
| 194 |
*/ |
| 195 |
private InputMap _mnemonicInputMap; |
| 196 |
|
| 197 |
// For use when tabLayoutPolicy = SCROLL_TAB_LAYOUT |
| 198 |
public ScrollableTabSupport _tabScroller; |
| 199 |
|
| 200 |
/** |
| 201 |
* A rectangle used for general layout calculations in order to avoid constructing many new Rectangles on the fly. |
| 202 |
*/ |
| 203 |
protected transient Rectangle _calcRect = new Rectangle(0, 0, 0, 0); |
| 204 |
|
| 205 |
/** |
| 206 |
* Number of tabs. When the count differs, the mnemonics are updated. |
| 207 |
*/ |
| 208 |
// PENDING: This wouldn't be necessary if JTabbedPane had a better |
| 209 |
// way of notifying listeners when the count changed. |
| 210 |
protected int _tabCount; |
| 211 |
|
| 212 |
protected JButton[] _closeButtons; |
| 213 |
|
| 214 |
// UI creation |
| 215 |
|
| 216 |
private ThemePainter _painter; |
| 217 |
|
| 218 |
private Painter _gripperPainter; |
| 219 |
|
| 220 |
private DropTargetListener _dropListener; |
| 221 |
private boolean _layouted; |
| 222 |
|
| 223 |
public DropTarget _dt; |
| 224 |
|
| 225 |
// the left margin of the first tab according to the style |
| 226 |
public static final int DEFAULT_LEFT_MARGIN = 0; |
| 227 |
public static final int OFFICE2003_LEFT_MARGIN = 18; |
| 228 |
public static final int EXCEL_LEFT_MARGIN = 6; |
| 229 |
|
| 230 |
|
| 231 |
protected int _rectSizeExtend = 0;//when the style is eclipse, |
| 232 |
//we should extend the size of the rects for hold the title |
| 233 |
|
| 234 |
protected Polygon tabRegion = null; |
| 235 |
|
| 236 |
protected Color _selectColor1 = null; |
| 237 |
protected Color _selectColor2 = null; |
| 238 |
protected Color _selectColor3 = null; |
| 239 |
protected Color _unselectColor1 = null; |
| 240 |
protected Color _unselectColor2 = null; |
| 241 |
protected Color _unselectColor3 = null; |
| 242 |
|
| 243 |
protected Color _officeTabBorderColor; |
| 244 |
protected Color _defaultTabBorderShadowColor; |
| 245 |
|
| 246 |
protected boolean _mouseEnter = false; |
| 247 |
|
| 248 |
protected int _indexMouseOver; |
| 249 |
|
| 250 |
protected boolean _alwaysShowLineBorder = false; |
| 251 |
protected boolean _showFocusIndicator = false; |
| 252 |
private TabContainer _tabContainer; |
| 253 |
|
| 254 |
public static final String BUTTON_NAME_CLOSE = "JideTabbedPane.close"; |
| 255 |
public static final String BUTTON_NAME_TAB_LIST = "JideTabbedPane.showList"; |
| 256 |
public static final String BUTTON_NAME_SCROLL_BACKWARD = "JideTabbedPane.scrollBackward"; |
| 257 |
public static final String BUTTON_NAME_SCROLL_FORWARD = "JideTabbedPane.scrollForward"; |
| 258 |
|
| 259 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 260 |
public static ComponentUI createUI(JComponent c) { |
| 261 |
return new BasicJideTabbedPaneUI(); |
| 262 |
} |
| 263 |
|
| 264 |
// UI Installation/De-installation |
| 265 |
|
| 266 |
@Override |
| 267 |
public void installUI(JComponent c) { |
| 268 |
if (c == null) { |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
_tabPane = (JideTabbedPane) c; |
| 273 |
|
| 274 |
if (_tabPane.isTabShown() && _tabPane.getTabLeadingComponent() != null) { |
| 275 |
_tabLeadingComponent = _tabPane.getTabLeadingComponent(); |
| 276 |
} |
| 277 |
if (_tabPane.isTabShown() && _tabPane.getTabTrailingComponent() != null) { |
| 278 |
_tabTrailingComponent = _tabPane.getTabTrailingComponent(); |
| 279 |
} |
| 280 |
|
| 281 |
setMouseOverTabIndex(-1); |
| 282 |
|
| 283 |
c.setLayout(createLayoutManager()); |
| 284 |
installComponents(); |
| 285 |
installDefaults(); |
| 286 |
installColorTheme(); |
| 287 |
installListeners(); |
| 288 |
installKeyboardActions(); |
| 289 |
} |
| 290 |
|
| 291 |
public void installColorTheme() { |
| 292 |
switch (getTabShape()) { |
| 293 |
case JideTabbedPane.SHAPE_EXCEL: |
| 294 |
_selectColor1 = _darkShadow; |
| 295 |
_selectColor2 = _lightHighlight; |
| 296 |
_selectColor3 = _shadow; |
| 297 |
_unselectColor1 = _darkShadow; |
| 298 |
_unselectColor2 = _lightHighlight; |
| 299 |
_unselectColor3 = _shadow; |
| 300 |
break; |
| 301 |
case JideTabbedPane.SHAPE_WINDOWS: |
| 302 |
case JideTabbedPane.SHAPE_WINDOWS_SELECTED: |
| 303 |
_selectColor1 = _lightHighlight; |
| 304 |
_selectColor2 = _shadow; |
| 305 |
_selectColor3 = _defaultTabBorderShadowColor; |
| 306 |
_unselectColor1 = _selectColor1; |
| 307 |
_unselectColor2 = _selectColor2; |
| 308 |
_unselectColor3 = _selectColor3; |
| 309 |
break; |
| 310 |
case JideTabbedPane.SHAPE_VSNET: |
| 311 |
_selectColor1 = _shadow; |
| 312 |
_selectColor2 = _shadow; |
| 313 |
_unselectColor1 = _selectColor1; |
| 314 |
break; |
| 315 |
case JideTabbedPane.SHAPE_ROUNDED_VSNET: |
| 316 |
_selectColor1 = _shadow; |
| 317 |
_selectColor2 = _selectColor1; |
| 318 |
_unselectColor1 = _selectColor1; |
| 319 |
break; |
| 320 |
case JideTabbedPane.SHAPE_FLAT: |
| 321 |
_selectColor1 = _shadow; |
| 322 |
_unselectColor1 = _selectColor1; |
| 323 |
break; |
| 324 |
case JideTabbedPane.SHAPE_ROUNDED_FLAT: |
| 325 |
_selectColor1 = _shadow; |
| 326 |
_selectColor2 = _shadow; |
| 327 |
_unselectColor1 = _selectColor1; |
| 328 |
_unselectColor2 = _selectColor2; |
| 329 |
break; |
| 330 |
case JideTabbedPane.SHAPE_BOX: |
| 331 |
_selectColor1 = _shadow; |
| 332 |
_selectColor2 = _lightHighlight; |
| 333 |
_unselectColor1 = getPainter().getControlShadow(); |
| 334 |
_unselectColor2 = _lightHighlight; |
| 335 |
break; |
| 336 |
case JideTabbedPane.SHAPE_OFFICE2003: |
| 337 |
default: |
| 338 |
_selectColor1 = _shadow; |
| 339 |
_selectColor2 = _lightHighlight; |
| 340 |
_unselectColor1 = _shadow; |
| 341 |
_unselectColor2 = null; |
| 342 |
_unselectColor3 = null; |
| 343 |
} |
| 344 |
|
| 345 |
} |
| 346 |
|
| 347 |
@Override |
| 348 |
public void uninstallUI(JComponent c) { |
| 349 |
uninstallKeyboardActions(); |
| 350 |
uninstallListeners(); |
| 351 |
uninstallColorTheme(); |
| 352 |
uninstallDefaults(); |
| 353 |
uninstallComponents(); |
| 354 |
c.setLayout(null); |
| 355 |
_tabTrailingComponent = null; |
| 356 |
_tabLeadingComponent = null; |
| 357 |
_tabPane = null; |
| 358 |
} |
| 359 |
|
| 360 |
public void uninstallColorTheme() { |
| 361 |
_selectColor1 = null; |
| 362 |
_selectColor2 = null; |
| 363 |
_selectColor3 = null; |
| 364 |
_unselectColor1 = null; |
| 365 |
_unselectColor2 = null; |
| 366 |
_unselectColor3 = null; |
| 367 |
} |
| 368 |
|
| 369 |
/** |
| 370 |
* Invoked by <code>installUI</code> to create a layout manager object to manage the <code>JTabbedPane</code>. |
| 371 |
* |
| 372 |
* @return a layout manager object |
| 373 |
* @see TabbedPaneLayout |
| 374 |
* @see JTabbedPane#getTabLayoutPolicy |
| 375 |
*/ |
| 376 |
protected LayoutManager createLayoutManager() { |
| 377 |
if (_tabPane.getTabLayoutPolicy() == JideTabbedPane.SCROLL_TAB_LAYOUT) { |
| 378 |
return new TabbedPaneScrollLayout(); |
| 379 |
} |
| 380 |
else { /* WRAP_TAB_LAYOUT */ |
| 381 |
return new TabbedPaneLayout(); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
/* In an attempt to preserve backward compatibility for programs |
| 386 |
* which have extended VsnetJideTabbedPaneUI to do their own layout, the |
| 387 |
* UI uses the installed layoutManager (and not tabLayoutPolicy) to |
| 388 |
* determine if scrollTabLayout is enabled. |
| 389 |
*/ |
| 390 |
|
| 391 |
protected boolean scrollableTabLayoutEnabled() { |
| 392 |
return (_tabPane.getLayout() instanceof TabbedPaneScrollLayout); |
| 393 |
} |
| 394 |
|
| 395 |
/** |
| 396 |
* Creates and installs any required subcomponents for the JTabbedPane. Invoked by installUI. |
| 397 |
*/ |
| 398 |
protected void installComponents() { |
| 399 |
if (scrollableTabLayoutEnabled()) { |
| 400 |
if (_tabScroller == null) { |
| 401 |
_tabScroller = new ScrollableTabSupport(_tabPane.getTabPlacement()); |
| 402 |
_tabPane.add(_tabScroller.viewport); |
| 403 |
_tabPane.add(_tabScroller.scrollForwardButton); |
| 404 |
_tabPane.add(_tabScroller.scrollBackwardButton); |
| 405 |
_tabPane.add(_tabScroller.listButton); |
| 406 |
_tabPane.add(_tabScroller.closeButton); |
| 407 |
if (_tabLeadingComponent != null) { |
| 408 |
_tabPane.add(_tabLeadingComponent); |
| 409 |
} |
| 410 |
if (_tabTrailingComponent != null) { |
| 411 |
_tabPane.add(_tabTrailingComponent); |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
installTabContainer(); |
| 416 |
} |
| 417 |
|
| 418 |
private void installTabContainer() { |
| 419 |
for (int i = 0; i < _tabPane.getTabCount(); i++) { |
| 420 |
Component tabComponent = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt(i) : null; |
| 421 |
if (tabComponent != null) { |
| 422 |
if (_tabContainer == null) { |
| 423 |
_tabContainer = new TabContainer(); |
| 424 |
} |
| 425 |
_tabContainer.add(tabComponent); |
| 426 |
} |
| 427 |
} |
| 428 |
if (_tabContainer == null) { |
| 429 |
return; |
| 430 |
} |
| 431 |
if (scrollableTabLayoutEnabled()) { |
| 432 |
_tabScroller.tabPanel.add(_tabContainer); |
| 433 |
} |
| 434 |
else { |
| 435 |
_tabPane.add(_tabContainer); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Removes any installed subcomponents from the JTabbedPane. Invoked by uninstallUI. |
| 441 |
*/ |
| 442 |
protected void uninstallComponents() { |
| 443 |
uninstallTabContainer(); |
| 444 |
if (scrollableTabLayoutEnabled()) { |
| 445 |
_tabPane.remove(_tabScroller.viewport); |
| 446 |
_tabPane.remove(_tabScroller.scrollForwardButton); |
| 447 |
_tabPane.remove(_tabScroller.scrollBackwardButton); |
| 448 |
_tabPane.remove(_tabScroller.listButton); |
| 449 |
_tabPane.remove(_tabScroller.closeButton); |
| 450 |
if (_tabLeadingComponent != null) { |
| 451 |
_tabPane.remove(_tabLeadingComponent); |
| 452 |
} |
| 453 |
if (_tabTrailingComponent != null) { |
| 454 |
_tabPane.remove(_tabTrailingComponent); |
| 455 |
} |
| 456 |
_tabScroller = null; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
private void uninstallTabContainer() { |
| 461 |
if (_tabContainer == null) { |
| 462 |
return; |
| 463 |
} |
| 464 |
// Remove all the tabComponents, making sure not to notify |
| 465 |
// the tabbedpane. |
| 466 |
_tabContainer.notifyTabbedPane = false; |
| 467 |
_tabContainer.removeAll(); |
| 468 |
if (scrollableTabLayoutEnabled()) { |
| 469 |
// _tabContainer.remove(_tabScroller.croppedEdge); |
| 470 |
_tabScroller.tabPanel.remove(_tabContainer); |
| 471 |
} |
| 472 |
else { |
| 473 |
_tabPane.remove(_tabContainer); |
| 474 |
} |
| 475 |
_tabContainer = null; |
| 476 |
} |
| 477 |
|
| 478 |
protected void installDefaults() { |
| 479 |
_painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter"); |
| 480 |
_gripperPainter = (Painter) UIDefaultsLookup.get("JideTabbedPane.gripperPainter"); |
| 481 |
|
| 482 |
LookAndFeel.installColorsAndFont(_tabPane, "JideTabbedPane.background", |
| 483 |
"JideTabbedPane.foreground", "JideTabbedPane.font"); |
| 484 |
LookAndFeel.installBorder(_tabPane, "JideTabbedPane.border"); |
| 485 |
_selectedTabFont = UIDefaultsLookup.getFont("JideTabbedPane.selectedTabFont"); |
| 486 |
_highlight = UIDefaultsLookup.getColor("JideTabbedPane.light"); |
| 487 |
_lightHighlight = UIDefaultsLookup.getColor("JideTabbedPane.highlight"); |
| 488 |
_shadow = UIDefaultsLookup.getColor("JideTabbedPane.shadow"); |
| 489 |
_darkShadow = UIDefaultsLookup.getColor("JideTabbedPane.darkShadow"); |
| 490 |
_focus = UIDefaultsLookup.getColor("TabbedPane.focus"); |
| 491 |
|
| 492 |
if (getTabShape() == JideTabbedPane.SHAPE_BOX) { |
| 493 |
_background = UIDefaultsLookup.getColor("JideTabbedPane.selectedTabBackground"); |
| 494 |
_tabBackground = UIDefaultsLookup.getColor("JideTabbedPane.selectedTabBackground"); |
| 495 |
_inactiveTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.foreground"); // text is black |
| 496 |
_inactiveSelectedTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.foreground"); // text is black |
| 497 |
_activeTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.foreground"); // text is black |
| 498 |
_selectedColor = _lightHighlight; |
| 499 |
_activeBackground = _lightHighlight; |
| 500 |
} |
| 501 |
else { |
| 502 |
_background = UIDefaultsLookup.getColor("JideTabbedPane.background"); |
| 503 |
_tabBackground = UIDefaultsLookup.getColor("JideTabbedPane.tabAreaBackground"); |
| 504 |
_inactiveTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.unselectedTabTextForeground"); |
| 505 |
_inactiveSelectedTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.selectedTabTextForeground"); |
| 506 |
_activeTabForeground = UIDefaultsLookup.getColor("JideTabbedPane.activeTabTextForeground"); |
| 507 |
if (_activeTabForeground == null) { |
| 508 |
_activeTabForeground = _inactiveSelectedTabForeground; |
| 509 |
} |
| 510 |
_selectedColor = UIDefaultsLookup.getColor("JideTabbedPane.selectedTabBackground"); |
| 511 |
_activeBackground = UIDefaultsLookup.getColor("DockableFrame.activeTitleBackground"); |
| 512 |
if (_activeBackground == null) { |
| 513 |
_activeBackground = UIDefaultsLookup.getColor("JideTabbedPane.activeTabBackground"); |
| 514 |
} |
| 515 |
if (_activeBackground == null) { |
| 516 |
_activeBackground = _selectedColor; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
_tabListBackground = UIDefaultsLookup.getColor("JideTabbedPane.tabListBackground"); |
| 521 |
|
| 522 |
_textIconGap = UIDefaultsLookup.getInt("JideTabbedPane.textIconGap"); |
| 523 |
|
| 524 |
Insets tabInsets = _tabPane.getTabInsets(); |
| 525 |
if (tabInsets == null || tabInsets instanceof UIResource) { |
| 526 |
_tabPane.setTabInsets(UIDefaultsLookup.getInsets("JideTabbedPane.tabInsets")); |
| 527 |
} |
| 528 |
|
| 529 |
_selectedTabPadInsets = UIDefaultsLookup.getInsets("TabbedPane.selectedTabPadInsets"); |
| 530 |
if (_selectedTabPadInsets == null) _selectedTabPadInsets = new InsetsUIResource(0, 0, 0, 0); |
| 531 |
|
| 532 |
Insets tabAreaInsets = _tabPane.getTabAreaInsets(); |
| 533 |
if (tabAreaInsets == null || tabAreaInsets instanceof UIResource) { |
| 534 |
_tabPane.setTabAreaInsets(UIDefaultsLookup.getInsets("JideTabbedPane.tabAreaInsets")); |
| 535 |
} |
| 536 |
|
| 537 |
Insets insets = _tabPane.getContentBorderInsets(); |
| 538 |
if (insets == null || insets instanceof UIResource) { |
| 539 |
_tabPane.setContentBorderInsets(UIDefaultsLookup.getInsets("JideTabbedPane.contentBorderInsets")); |
| 540 |
} |
| 541 |
|
| 542 |
_ignoreContentBorderInsetsIfNoTabs = UIDefaultsLookup.getBoolean("JideTabbedPane.ignoreContentBorderInsetsIfNoTabs"); |
| 543 |
_tabRunOverlay = UIDefaultsLookup.getInt("JideTabbedPane.tabRunOverlay"); |
| 544 |
_showIconOnTab = UIDefaultsLookup.getBoolean("JideTabbedPane.showIconOnTab"); |
| 545 |
_showCloseButtonOnTab = UIDefaultsLookup.getBoolean("JideTabbedPane.showCloseButtonOnTab"); |
| 546 |
_closeButtonAlignment = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonAlignment"); |
| 547 |
_gripperWidth = UIDefaultsLookup.getInt("Gripper.size"); |
| 548 |
|
| 549 |
_tabRectPadding = UIDefaultsLookup.getInt("JideTabbedPane.tabRectPadding"); |
| 550 |
_closeButtonMarginHorizon = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMarginHorizonal"); |
| 551 |
_closeButtonMarginVertical = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMarginVertical"); |
| 552 |
_textMarginVertical = UIDefaultsLookup.getInt("JideTabbedPane.textMarginVertical"); |
| 553 |
_noIconMargin = UIDefaultsLookup.getInt("JideTabbedPane.noIconMargin"); |
| 554 |
_iconMargin = UIDefaultsLookup.getInt("JideTabbedPane.iconMargin"); |
| 555 |
_textPadding = UIDefaultsLookup.getInt("JideTabbedPane.textPadding"); |
| 556 |
_buttonSize = UIDefaultsLookup.getInt("JideTabbedPane.buttonSize"); |
| 557 |
_buttonMargin = UIDefaultsLookup.getInt("JideTabbedPane.buttonMargin"); |
| 558 |
_fitStyleBoundSize = UIDefaultsLookup.getInt("JideTabbedPane.fitStyleBoundSize"); |
| 559 |
_fitStyleFirstTabMargin = UIDefaultsLookup.getInt("JideTabbedPane.fitStyleFirstTabMargin"); |
| 560 |
_fitStyleIconMinWidth = UIDefaultsLookup.getInt("JideTabbedPane.fitStyleIconMinWidth"); |
| 561 |
_fitStyleTextMinWidth = UIDefaultsLookup.getInt("JideTabbedPane.fitStyleTextMinWidth"); |
| 562 |
_compressedStyleNoIconRectSize = UIDefaultsLookup.getInt("JideTabbedPane.compressedStyleNoIconRectSize"); |
| 563 |
_compressedStyleIconMargin = UIDefaultsLookup.getInt("JideTabbedPane.compressedStyleIconMargin"); |
| 564 |
_compressedStyleCloseButtonMarginHorizon = UIDefaultsLookup.getInt("JideTabbedPane.compressedStyleCloseButtonMarginHorizontal"); |
| 565 |
_compressedStyleCloseButtonMarginVertical = UIDefaultsLookup.getInt("JideTabbedPane.compressedStyleCloseButtonMarginVertical"); |
| 566 |
_fixedStyleRectSize = UIDefaultsLookup.getInt("JideTabbedPane.fixedStyleRectSize"); |
| 567 |
_closeButtonMargin = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMargin"); |
| 568 |
_gripLeftMargin = UIDefaultsLookup.getInt("JideTabbedPane.gripLeftMargin"); |
| 569 |
_closeButtonMarginSize = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonMarginSize"); |
| 570 |
_closeButtonLeftMargin = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonLeftMargin"); |
| 571 |
_closeButtonRightMargin = UIDefaultsLookup.getInt("JideTabbedPane.closeButtonRightMargin"); |
| 572 |
|
| 573 |
_defaultTabBorderShadowColor = UIDefaultsLookup.getColor("JideTabbedPane.defaultTabBorderShadowColor"); |
| 574 |
_alwaysShowLineBorder = UIDefaultsLookup.getBoolean("JideTabbedPane.alwaysShowLineBorder"); |
| 575 |
_showFocusIndicator = UIDefaultsLookup.getBoolean("JideTabbedPane.showFocusIndicator"); |
| 576 |
} |
| 577 |
|
| 578 |
protected void uninstallDefaults() { |
| 579 |
_painter = null; |
| 580 |
_gripperPainter = null; |
| 581 |
|
| 582 |
_highlight = null; |
| 583 |
_lightHighlight = null; |
| 584 |
_shadow = null; |
| 585 |
_darkShadow = null; |
| 586 |
_focus = null; |
| 587 |
_inactiveTabForeground = null; |
| 588 |
_selectedColor = null; |
| 589 |
_tabInsets = null; |
| 590 |
_selectedTabPadInsets = null; |
| 591 |
_tabAreaInsets = null; |
| 592 |
|
| 593 |
_defaultTabBorderShadowColor = null; |
| 594 |
} |
| 595 |
|
| 596 |
protected void installListeners() { |
| 597 |
if (_tabModelChangeListener == null) { |
| 598 |
_tabModelChangeListener = new ChangeListener() { |
| 599 |
public void stateChanged(ChangeEvent e) { |
| 600 |
if (_tabPane != null) { // in case updateUI() was invoked, it could be null |
| 601 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 602 |
if (selectedIndex >= 0 && selectedIndex < _tabPane.getTabCount() && _tabScroller != null && _tabScroller.closeButton != null) { |
| 603 |
_tabScroller.closeButton.setEnabled(_tabPane.isTabClosableAt(selectedIndex)); |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
}; |
| 608 |
_tabPane.getModel().addChangeListener(_tabModelChangeListener); |
| 609 |
} |
| 610 |
if (_propertyChangeListener == null) { |
| 611 |
_propertyChangeListener = createPropertyChangeListener(); |
| 612 |
_tabPane.addPropertyChangeListener(_propertyChangeListener); |
| 613 |
} |
| 614 |
if (_tabChangeListener == null) { |
| 615 |
_tabChangeListener = createChangeListener(); |
| 616 |
_tabPane.addChangeListener(_tabChangeListener); |
| 617 |
} |
| 618 |
if (_tabFocusListener == null) { |
| 619 |
_tabFocusListener = createFocusListener(); |
| 620 |
_tabPane.addFocusListener(_tabFocusListener); |
| 621 |
} |
| 622 |
|
| 623 |
if (_mouseListener == null) { |
| 624 |
_mouseListener = createMouseListener(); |
| 625 |
_tabPane.addMouseListener(_mouseListener); |
| 626 |
} |
| 627 |
|
| 628 |
if (_mousemotionListener == null) { |
| 629 |
_mousemotionListener = createMouseMotionListener(); |
| 630 |
_tabPane.addMouseMotionListener(_mousemotionListener); |
| 631 |
} |
| 632 |
|
| 633 |
if (_mouseWheelListener == null) { |
| 634 |
_mouseWheelListener = createMouseWheelListener(); |
| 635 |
_tabPane.addMouseWheelListener(_mouseWheelListener); |
| 636 |
} |
| 637 |
|
| 638 |
// PENDING(api) : See comment for ContainerHandler |
| 639 |
if (_containerListener == null) { |
| 640 |
_containerListener = new ContainerHandler(); |
| 641 |
_tabPane.addContainerListener(_containerListener); |
| 642 |
if (_tabPane.getTabCount() > 0) { |
| 643 |
htmlViews = createHTMLVector(); |
| 644 |
} |
| 645 |
} |
| 646 |
if (_componentListener == null) { |
| 647 |
_componentListener = new ComponentHandler(); |
| 648 |
_tabPane.addComponentListener(_componentListener); |
| 649 |
} |
| 650 |
|
| 651 |
if (!_tabPane.isDragOverDisabled()) { |
| 652 |
if (_dropListener == null) { |
| 653 |
_dropListener = createDropListener(); |
| 654 |
_dt = new DropTarget(getTabPanel(), _dropListener); |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
protected DropListener createDropListener() { |
| 660 |
return new DropListener(); |
| 661 |
} |
| 662 |
|
| 663 |
protected void uninstallListeners() { |
| 664 |
if (_tabModelChangeListener != null) { |
| 665 |
_tabPane.getModel().removeChangeListener(_tabModelChangeListener); |
| 666 |
_tabModelChangeListener = null; |
| 667 |
} |
| 668 |
// PENDING(api): See comment for ContainerHandler |
| 669 |
if (_containerListener != null) { |
| 670 |
_tabPane.removeContainerListener(_containerListener); |
| 671 |
_containerListener = null; |
| 672 |
if (htmlViews != null) { |
| 673 |
htmlViews.removeAllElements(); |
| 674 |
htmlViews = null; |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
if (_componentListener != null) { |
| 679 |
_tabPane.removeComponentListener(_componentListener); |
| 680 |
_componentListener = null; |
| 681 |
} |
| 682 |
|
| 683 |
if (_tabChangeListener != null) { |
| 684 |
_tabPane.removeChangeListener(_tabChangeListener); |
| 685 |
_tabChangeListener = null; |
| 686 |
} |
| 687 |
|
| 688 |
if (_tabFocusListener != null) { |
| 689 |
_tabPane.removeFocusListener(_tabFocusListener); |
| 690 |
_tabFocusListener = null; |
| 691 |
} |
| 692 |
|
| 693 |
if (_mouseListener != null) { |
| 694 |
_tabPane.removeMouseListener(_mouseListener); |
| 695 |
_mouseListener = null; |
| 696 |
} |
| 697 |
|
| 698 |
if (_mousemotionListener != null) { |
| 699 |
_tabPane.removeMouseMotionListener(_mousemotionListener); |
| 700 |
_mousemotionListener = null; |
| 701 |
} |
| 702 |
|
| 703 |
if (_mouseWheelListener != null) { |
| 704 |
_tabPane.removeMouseWheelListener(_mouseWheelListener); |
| 705 |
_mouseWheelListener = null; |
| 706 |
} |
| 707 |
|
| 708 |
if (_propertyChangeListener != null) { |
| 709 |
_tabPane.removePropertyChangeListener(_propertyChangeListener); |
| 710 |
_propertyChangeListener = null; |
| 711 |
} |
| 712 |
|
| 713 |
if (_dt != null && _dropListener != null) { |
| 714 |
_dt.removeDropTargetListener(_dropListener); |
| 715 |
_dropListener = null; |
| 716 |
_dt = null; |
| 717 |
getTabPanel().setDropTarget(null); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
protected ChangeListener createChangeListener() { |
| 722 |
return new TabSelectionHandler(); |
| 723 |
} |
| 724 |
|
| 725 |
protected FocusListener createFocusListener() { |
| 726 |
return new TabFocusListener(); |
| 727 |
} |
| 728 |
|
| 729 |
protected PropertyChangeListener createPropertyChangeListener() { |
| 730 |
return new PropertyChangeHandler(); |
| 731 |
} |
| 732 |
|
| 733 |
protected void installKeyboardActions() { |
| 734 |
InputMap km = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); |
| 735 |
SwingUtilities.replaceUIInputMap(_tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km); |
| 736 |
km = getInputMap(JComponent.WHEN_FOCUSED); |
| 737 |
SwingUtilities.replaceUIInputMap(_tabPane, JComponent.WHEN_FOCUSED, km); |
| 738 |
ActionMap am = getActionMap(); |
| 739 |
|
| 740 |
SwingUtilities.replaceUIActionMap(_tabPane, am); |
| 741 |
|
| 742 |
ensureCloseButtonCreated(); |
| 743 |
|
| 744 |
if (scrollableTabLayoutEnabled()) { |
| 745 |
Icon forwardIcon = _tabScroller.scrollForwardButton.getIcon(); |
| 746 |
_tabScroller.scrollForwardButton.setAction(am.get("scrollTabsForwardAction")); |
| 747 |
if (forwardIcon != null) { |
| 748 |
_tabScroller.scrollForwardButton.setIcon(forwardIcon); |
| 749 |
} |
| 750 |
Icon backwardIcon = _tabScroller.scrollBackwardButton.getIcon(); |
| 751 |
_tabScroller.scrollBackwardButton.setAction(am.get("scrollTabsBackwardAction")); |
| 752 |
if (backwardIcon != null) { |
| 753 |
_tabScroller.scrollBackwardButton.setIcon(backwardIcon); |
| 754 |
} |
| 755 |
Icon listIcon = _tabScroller.listButton.getIcon(); |
| 756 |
_tabScroller.listButton.setAction(am.get("scrollTabsListAction")); |
| 757 |
if (listIcon != null) { |
| 758 |
_tabScroller.listButton.setIcon(listIcon); |
| 759 |
} |
| 760 |
Action action = _tabPane.getCloseAction(); |
| 761 |
updateButtonFromAction(_tabScroller.closeButton, action); |
| 762 |
Icon closeIcon = _tabScroller.closeButton.getIcon(); |
| 763 |
_tabScroller.closeButton.setAction(am.get("closeTabAction")); |
| 764 |
if (closeIcon != null) { |
| 765 |
_tabScroller.closeButton.setIcon(closeIcon); |
| 766 |
} |
| 767 |
_tabScroller.scrollForwardButton.setToolTipText(getResourceString(BUTTON_NAME_SCROLL_FORWARD)); |
| 768 |
_tabScroller.scrollBackwardButton.setToolTipText(getResourceString(BUTTON_NAME_SCROLL_BACKWARD)); |
| 769 |
_tabScroller.listButton.setToolTipText(getResourceString(BUTTON_NAME_TAB_LIST)); |
| 770 |
_tabScroller.closeButton.setToolTipText(getResourceString(BUTTON_NAME_CLOSE)); |
| 771 |
} |
| 772 |
|
| 773 |
} |
| 774 |
|
| 775 |
InputMap getInputMap(int condition) { |
| 776 |
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { |
| 777 |
return (InputMap) UIDefaultsLookup.get("JideTabbedPane.ancestorInputMap"); |
| 778 |
} |
| 779 |
else if (condition == JComponent.WHEN_FOCUSED) { |
| 780 |
return (InputMap) UIDefaultsLookup.get("JideTabbedPane.focusInputMap"); |
| 781 |
} |
| 782 |
return null; |
| 783 |
} |
| 784 |
|
| 785 |
ActionMap getActionMap() { |
| 786 |
ActionMap map = (ActionMap) UIDefaultsLookup.get("JideTabbedPane.actionMap"); |
| 787 |
|
| 788 |
if (map == null) { |
| 789 |
map = createActionMap(); |
| 790 |
if (map != null) { |
| 791 |
UIManager.getLookAndFeelDefaults().put("JideTabbedPane.actionMap", map); |
| 792 |
} |
| 793 |
} |
| 794 |
return map; |
| 795 |
} |
| 796 |
|
| 797 |
ActionMap createActionMap() { |
| 798 |
ActionMap map = new ActionMapUIResource(); |
| 799 |
map.put("navigateNext", new NextAction()); |
| 800 |
map.put("navigatePrevious", new PreviousAction()); |
| 801 |
map.put("navigateRight", new RightAction()); |
| 802 |
map.put("navigateLeft", new LeftAction()); |
| 803 |
map.put("navigateUp", new UpAction()); |
| 804 |
map.put("navigateDown", new DownAction()); |
| 805 |
map.put("navigatePageUp", new PageUpAction()); |
| 806 |
map.put("navigatePageDown", new PageDownAction()); |
| 807 |
map.put("requestFocus", new RequestFocusAction()); |
| 808 |
map.put("requestFocusForVisibleComponent", new RequestFocusForVisibleAction()); |
| 809 |
map.put("setSelectedIndex", new SetSelectedIndexAction()); |
| 810 |
map.put("scrollTabsForwardAction", new ScrollTabsForwardAction()); |
| 811 |
map.put("scrollTabsBackwardAction", new ScrollTabsBackwardAction()); |
| 812 |
map.put("scrollTabsListAction", new ScrollTabsListAction()); |
| 813 |
map.put("closeTabAction", new CloseTabAction()); |
| 814 |
return map; |
| 815 |
} |
| 816 |
|
| 817 |
protected void uninstallKeyboardActions() { |
| 818 |
SwingUtilities.replaceUIActionMap(_tabPane, null); |
| 819 |
SwingUtilities.replaceUIInputMap(_tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); |
| 820 |
SwingUtilities.replaceUIInputMap(_tabPane, JComponent.WHEN_FOCUSED, null); |
| 821 |
|
| 822 |
if (_closeButtons != null) { |
| 823 |
for (int i = 0; i < _closeButtons.length; i++) { |
| 824 |
_closeButtons[i] = null; |
| 825 |
} |
| 826 |
_closeButtons = null; |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
/** |
| 831 |
* Reloads the mnemonics. This should be invoked when a mnemonic changes, when the title of a mnemonic changes, or |
| 832 |
* when tabs are added/removed. |
| 833 |
*/ |
| 834 |
protected void updateMnemonics() { |
| 835 |
resetMnemonics(); |
| 836 |
for (int counter = _tabPane.getTabCount() - 1; counter >= 0; counter--) { |
| 837 |
int mnemonic = _tabPane.getMnemonicAt(counter); |
| 838 |
|
| 839 |
if (mnemonic > 0) { |
| 840 |
addMnemonic(counter, mnemonic); |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
/** |
| 846 |
* Resets the mnemonics bindings to an empty state. |
| 847 |
*/ |
| 848 |
private void resetMnemonics() { |
| 849 |
if (_mnemonicToIndexMap != null) { |
| 850 |
_mnemonicToIndexMap.clear(); |
| 851 |
_mnemonicInputMap.clear(); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
/** |
| 856 |
* Adds the specified mnemonic at the specified index. |
| 857 |
* |
| 858 |
* @param index the index |
| 859 |
* @param mnemonic the mnemonic for the index |
| 860 |
*/ |
| 861 |
private void addMnemonic(int index, int mnemonic) { |
| 862 |
if (_mnemonicToIndexMap == null) { |
| 863 |
initMnemonics(); |
| 864 |
} |
| 865 |
_mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, Event.ALT_MASK), "setSelectedIndex"); |
| 866 |
_mnemonicToIndexMap.put(mnemonic, index); |
| 867 |
} |
| 868 |
|
| 869 |
/** |
| 870 |
* Installs the state needed for mnemonics. |
| 871 |
*/ |
| 872 |
private void initMnemonics() { |
| 873 |
_mnemonicToIndexMap = new Hashtable(); |
| 874 |
_mnemonicInputMap = new InputMapUIResource(); |
| 875 |
_mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(_tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)); |
| 876 |
SwingUtilities.replaceUIInputMap(_tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, _mnemonicInputMap); |
| 877 |
} |
| 878 |
|
| 879 |
// Geometry |
| 880 |
|
| 881 |
@Override |
| 882 |
public Dimension getPreferredSize(JComponent c) { |
| 883 |
// Default to LayoutManager's preferredLayoutSize |
| 884 |
return null; |
| 885 |
} |
| 886 |
|
| 887 |
@Override |
| 888 |
public Dimension getMinimumSize(JComponent c) { |
| 889 |
// Default to LayoutManager's minimumLayoutSize |
| 890 |
return null; |
| 891 |
} |
| 892 |
|
| 893 |
@Override |
| 894 |
public Dimension getMaximumSize(JComponent c) { |
| 895 |
// Default to LayoutManager's maximumLayoutSize |
| 896 |
return null; |
| 897 |
} |
| 898 |
|
| 899 |
// UI Rendering |
| 900 |
|
| 901 |
@Override |
| 902 |
public void paint(Graphics g, JComponent c) { |
| 903 |
int tc = _tabPane.getTabCount(); |
| 904 |
|
| 905 |
paintBackground(g, c); |
| 906 |
|
| 907 |
if (tc == 0) { |
| 908 |
return; |
| 909 |
} |
| 910 |
|
| 911 |
if (_tabCount != tc) { |
| 912 |
_tabCount = tc; |
| 913 |
updateMnemonics(); |
| 914 |
} |
| 915 |
|
| 916 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 917 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 918 |
|
| 919 |
ensureCurrentLayout(); |
| 920 |
|
| 921 |
// Paint tab area |
| 922 |
// If scrollable tabs are enabled, the tab area will be |
| 923 |
// painted by the scrollable tab panel instead. |
| 924 |
// |
| 925 |
if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT |
| 926 |
paintTabArea(g, tabPlacement, selectedIndex, c); |
| 927 |
} |
| 928 |
|
| 929 |
// Paint content border |
| 930 |
// if (_tabPane.isTabShown()) |
| 931 |
paintContentBorder(g, tabPlacement, selectedIndex); |
| 932 |
} |
| 933 |
|
| 934 |
public void paintBackground(Graphics g, Component c) { |
| 935 |
if (_tabPane.isOpaque()) { |
| 936 |
int width = c.getWidth(); |
| 937 |
int height = c.getHeight(); |
| 938 |
g.setColor(_background); |
| 939 |
g.fillRect(0, 0, width, height); |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
/** |
| 944 |
* Paints the tabs in the tab area. Invoked by paint(). The graphics parameter must be a valid <code>Graphics</code> |
| 945 |
* object. Tab placement may be either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>, |
| 946 |
* <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>. The selected index must be a valid tabbed pane |
| 947 |
* tab index (0 to tab count - 1, inclusive) or -1 if no tab is currently selected. The handling of invalid |
| 948 |
* parameters is unspecified. |
| 949 |
* |
| 950 |
* @param g the graphics object to use for rendering |
| 951 |
* @param tabPlacement the placement for the tabs within the JTabbedPane |
| 952 |
* @param selectedIndex the tab index of the selected component |
| 953 |
* @param c the component |
| 954 |
*/ |
| 955 |
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex, Component c) { |
| 956 |
|
| 957 |
if (!PAINT_TABAREA) { |
| 958 |
return; |
| 959 |
} |
| 960 |
|
| 961 |
int tabCount = _tabPane.getTabCount(); |
| 962 |
|
| 963 |
Rectangle iconRect = new Rectangle(), |
| 964 |
textRect = new Rectangle(); |
| 965 |
|
| 966 |
Rectangle rect = new Rectangle(0, 0, c.getWidth(), c.getHeight()); |
| 967 |
|
| 968 |
paintTabAreaBackground(g, rect, tabPlacement); |
| 969 |
boolean leftToRight = tabPlacement == LEFT || tabPlacement == RIGHT || _tabPane.getComponentOrientation().isLeftToRight(); |
| 970 |
|
| 971 |
// Paint tabRuns of tabs from back to front |
| 972 |
for (int i = _runCount - 1; i >= 0; i--) { |
| 973 |
int start = _tabRuns[i]; |
| 974 |
int next = _tabRuns[(i == _runCount - 1) ? 0 : i + 1]; |
| 975 |
int end = (next != 0 ? next - 1 : tabCount - 1); |
| 976 |
for (int j = start; j <= end; j++) { |
| 977 |
if ((_rects[j].intersects(rect) || !leftToRight) && j != selectedIndex) { |
| 978 |
paintTab(g, tabPlacement, _rects, j, iconRect, textRect); |
| 979 |
} |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
// Paint selected tab if its in the front run |
| 984 |
// since it may overlap other tabs |
| 985 |
if (selectedIndex >= 0 && selectedIndex < _tabPane.getTabCount() && getRunForTab(tabCount, selectedIndex) == 0) { |
| 986 |
if (_rects[selectedIndex].intersects(rect) || !leftToRight) { |
| 987 |
paintTab(g, tabPlacement, _rects, selectedIndex, iconRect, textRect); |
| 988 |
} |
| 989 |
} |
| 990 |
} |
| 991 |
|
| 992 |
protected void paintTabAreaBackground(Graphics g, Rectangle rect, int tabPlacement) { |
| 993 |
getPainter().paintTabAreaBackground(_tabPane, g, rect, |
| 994 |
tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM ? SwingConstants.HORIZONTAL : SwingConstants.VERTICAL, |
| 995 |
ThemePainter.STATE_DEFAULT); |
| 996 |
} |
| 997 |
|
| 998 |
protected void paintTab(Graphics g, int tabPlacement, |
| 999 |
Rectangle[] rects, int tabIndex, |
| 1000 |
Rectangle iconRect, Rectangle textRect) { |
| 1001 |
|
| 1002 |
if (!PAINT_TAB) { |
| 1003 |
return; |
| 1004 |
} |
| 1005 |
|
| 1006 |
Rectangle tabRect = rects[tabIndex]; |
| 1007 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 1008 |
boolean isSelected = selectedIndex == tabIndex; |
| 1009 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 1010 |
|
| 1011 |
paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, |
| 1012 |
tabRect.width, tabRect.height, isSelected); |
| 1013 |
|
| 1014 |
Object savedHints = JideSwingUtilities.setupShapeAntialiasing(g); |
| 1015 |
paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, |
| 1016 |
tabRect.width, tabRect.height, isSelected); |
| 1017 |
JideSwingUtilities.restoreShapeAntialiasing(g, savedHints); |
| 1018 |
|
| 1019 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 1020 |
|
| 1021 |
Rectangle tempTabRect = new Rectangle(tabRect); |
| 1022 |
|
| 1023 |
if (_tabPane.isShowGripper()) { |
| 1024 |
if (leftToRight) { |
| 1025 |
tempTabRect.x += _gripperWidth; |
| 1026 |
} |
| 1027 |
tempTabRect.width -= _gripperWidth; |
| 1028 |
Rectangle gripperRect = new Rectangle(tabRect); |
| 1029 |
if (leftToRight) { |
| 1030 |
gripperRect.x += _gripLeftMargin; |
| 1031 |
} |
| 1032 |
else { |
| 1033 |
gripperRect.x = tabRect.x + tabRect.width - _gripLeftMargin - _gripperWidth; |
| 1034 |
} |
| 1035 |
gripperRect.width = _gripperWidth; |
| 1036 |
if (_gripperPainter != null) { |
| 1037 |
_gripperPainter.paint(_tabPane, g, gripperRect, SwingConstants.HORIZONTAL, isSelected ? ThemePainter.STATE_SELECTED : ThemePainter.STATE_DEFAULT); |
| 1038 |
} |
| 1039 |
else { |
| 1040 |
getPainter().paintGripper(_tabPane, g, gripperRect, SwingConstants.HORIZONTAL, isSelected ? ThemePainter.STATE_SELECTED : ThemePainter.STATE_DEFAULT); |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
if (isShowCloseButton() && isShowCloseButtonOnTab() && _tabPane.isTabClosableAt(tabIndex) |
| 1045 |
&& (!_tabPane.isShowCloseButtonOnSelectedTab() || isSelected)) { |
| 1046 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 1047 |
int buttonWidth = _closeButtons[tabIndex].getPreferredSize().width + _closeButtonLeftMargin + _closeButtonRightMargin; |
| 1048 |
if (!(_closeButtonAlignment == SwingConstants.LEADING ^ leftToRight)) { |
| 1049 |
tempTabRect.x += buttonWidth; |
| 1050 |
} |
| 1051 |
tempTabRect.width -= buttonWidth; |
| 1052 |
} |
| 1053 |
else { |
| 1054 |
int buttonHeight = _closeButtons[tabIndex].getPreferredSize().height + _closeButtonLeftMargin + _closeButtonRightMargin; |
| 1055 |
if (_closeButtonAlignment == SwingConstants.LEADING) { |
| 1056 |
tempTabRect.y += buttonHeight; |
| 1057 |
tempTabRect.height -= buttonHeight; |
| 1058 |
} |
| 1059 |
else { |
| 1060 |
tempTabRect.height -= buttonHeight; |
| 1061 |
} |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
String title = getCurrentDisplayTitleAt(_tabPane, tabIndex); |
| 1066 |
Font font; |
| 1067 |
|
| 1068 |
if (isSelected) { |
| 1069 |
if (_tabPane.getSelectedTabFont() != null) { |
| 1070 |
font = _tabPane.getSelectedTabFont(); |
| 1071 |
} |
| 1072 |
else { |
| 1073 |
if (_tabPane.getFont() instanceof UIResource) { |
| 1074 |
font = _selectedTabFont; |
| 1075 |
} |
| 1076 |
else { |
| 1077 |
font = _tabPane.getFont(); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
} |
| 1081 |
else { |
| 1082 |
font = _tabPane.getFont(); |
| 1083 |
} |
| 1084 |
|
| 1085 |
if (isSelected && _tabPane.isBoldActiveTab() && font.getStyle() != Font.BOLD) { |
| 1086 |
font = font.deriveFont(Font.BOLD); |
| 1087 |
} |
| 1088 |
|
| 1089 |
FontMetrics metrics = _tabPane.getFontMetrics(font); |
| 1090 |
|
| 1091 |
// while (title == null || title.length() < 3) |
| 1092 |
// title += " "; |
| 1093 |
|
| 1094 |
layoutLabel(tabPlacement, metrics, tabIndex, title, icon, |
| 1095 |
tempTabRect, iconRect, textRect, isSelected); |
| 1096 |
|
| 1097 |
if ((!_isEditing || (!isSelected)) && (!SystemInfo.isJdk6Above() || _tabPane.getTabComponentAt(tabIndex) == null)) |
| 1098 |
paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected); |
| 1099 |
|
| 1100 |
if (!SystemInfo.isJdk6Above() || _tabPane.getTabComponentAt(tabIndex) == null) { |
| 1101 |
paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected); |
| 1102 |
} |
| 1103 |
|
| 1104 |
paintFocusIndicator(g, tabPlacement, rects, tabIndex, |
| 1105 |
iconRect, textRect, isSelected); |
| 1106 |
} |
| 1107 |
|
| 1108 |
|
| 1109 |
/* This method will create and return a polygon shape for the given tab rectangle |
| 1110 |
* which has been cropped at the specified crop line with a torn edge visual. |
| 1111 |
* e.g. A "File" tab which has cropped been cropped just after the "i": |
| 1112 |
* ------------- |
| 1113 |
* | ..... | |
| 1114 |
* | . | |
| 1115 |
* | ... . | |
| 1116 |
* | . . | |
| 1117 |
* | . . | |
| 1118 |
* | . . | |
| 1119 |
* -------------- |
| 1120 |
* |
| 1121 |
* The x, y arrays below define the pattern used to create a "torn" edge |
| 1122 |
* segment which is repeated to fill the edge of the tab. |
| 1123 |
* For tabs placed on TOP and BOTTOM, this righthand torn edge is created by |
| 1124 |
* line segments which are defined by coordinates obtained by |
| 1125 |
* subtracting xCropLen[i] from (tab.x + tab.width) and adding yCroplen[i] |
| 1126 |
* to (tab.y). |
| 1127 |
* For tabs placed on LEFT or RIGHT, the bottom torn edge is created by |
| 1128 |
* subtracting xCropLen[i] from (tab.y + tab.height) and adding yCropLen[i] |
| 1129 |
* to (tab.x). |
| 1130 |
*/ |
| 1131 |
private int xCropLen[] = {1, 1, 0, 0, 1, 1, 2, 2}; |
| 1132 |
|
| 1133 |
private int yCropLen[] = {0, 3, 3, 6, 6, 9, 9, 12}; |
| 1134 |
|
| 1135 |
private static final int CROP_SEGMENT = 12; |
| 1136 |
|
| 1137 |
/* |
| 1138 |
private Polygon createCroppedTabClip(int tabPlacement, Rectangle tabRect, int cropline) { |
| 1139 |
int rlen = 0; |
| 1140 |
int start = 0; |
| 1141 |
int end = 0; |
| 1142 |
int ostart = 0; |
| 1143 |
|
| 1144 |
switch (tabPlacement) { |
| 1145 |
case LEFT: |
| 1146 |
case RIGHT: |
| 1147 |
rlen = tabRect.width; |
| 1148 |
start = tabRect.x; |
| 1149 |
end = tabRect.x + tabRect.width; |
| 1150 |
ostart = tabRect.y; |
| 1151 |
break; |
| 1152 |
case TOP: |
| 1153 |
case BOTTOM: |
| 1154 |
default: |
| 1155 |
rlen = tabRect.height; |
| 1156 |
start = tabRect.y; |
| 1157 |
end = tabRect.y + tabRect.height; |
| 1158 |
ostart = tabRect.x; |
| 1159 |
} |
| 1160 |
int rcnt = rlen / CROP_SEGMENT; |
| 1161 |
if (rlen % CROP_SEGMENT > 0) { |
| 1162 |
rcnt++; |
| 1163 |
} |
| 1164 |
int npts = 2 + (rcnt << 3); |
| 1165 |
int xp[] = new int[npts]; |
| 1166 |
int yp[] = new int[npts]; |
| 1167 |
int pcnt = 0; |
| 1168 |
|
| 1169 |
xp[pcnt] = ostart; |
| 1170 |
yp[pcnt++] = end; |
| 1171 |
xp[pcnt] = ostart; |
| 1172 |
yp[pcnt++] = start; |
| 1173 |
for (int i = 0; i < rcnt; i++) { |
| 1174 |
for (int j = 0; j < xCropLen.length; j++) { |
| 1175 |
xp[pcnt] = cropline - xCropLen[j]; |
| 1176 |
yp[pcnt] = start + (i * CROP_SEGMENT) + yCropLen[j]; |
| 1177 |
if (yp[pcnt] >= end) { |
| 1178 |
yp[pcnt] = end; |
| 1179 |
pcnt++; |
| 1180 |
break; |
| 1181 |
} |
| 1182 |
pcnt++; |
| 1183 |
} |
| 1184 |
} |
| 1185 |
if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) { |
| 1186 |
return new Polygon(xp, yp, pcnt); |
| 1187 |
|
| 1188 |
} |
| 1189 |
else { // LEFT or RIGHT |
| 1190 |
return new Polygon(yp, xp, pcnt); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
*/ |
| 1194 |
|
| 1195 |
/* If tabLayoutPolicy == SCROLL_TAB_LAYOUT, this method will paint an edge |
| 1196 |
* indicating the tab is cropped in the viewport display |
| 1197 |
*/ |
| 1198 |
|
| 1199 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 1200 |
private void paintCroppedTabEdge(Graphics g, int tabPlacement, int tabIndex, |
| 1201 |
boolean isSelected, |
| 1202 |
int x, int y) { |
| 1203 |
switch (tabPlacement) { |
| 1204 |
case LEFT: |
| 1205 |
case RIGHT: |
| 1206 |
int xx = x; |
| 1207 |
g.setColor(_shadow); |
| 1208 |
while (xx <= x + _rects[tabIndex].width) { |
| 1209 |
for (int i = 0; i < xCropLen.length; i += 2) { |
| 1210 |
g.drawLine(xx + yCropLen[i], y - xCropLen[i], |
| 1211 |
xx + yCropLen[i + 1] - 1, y - xCropLen[i + 1]); |
| 1212 |
} |
| 1213 |
xx += CROP_SEGMENT; |
| 1214 |
} |
| 1215 |
break; |
| 1216 |
case TOP: |
| 1217 |
case BOTTOM: |
| 1218 |
default: |
| 1219 |
int yy = y; |
| 1220 |
g.setColor(_shadow); |
| 1221 |
while (yy <= y + _rects[tabIndex].height) { |
| 1222 |
for (int i = 0; i < xCropLen.length; i += 2) { |
| 1223 |
g.drawLine(x - xCropLen[i], yy + yCropLen[i], |
| 1224 |
x - xCropLen[i + 1], yy + yCropLen[i + 1] - 1); |
| 1225 |
} |
| 1226 |
yy += CROP_SEGMENT; |
| 1227 |
} |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
protected void layoutLabel(int tabPlacement, |
| 1232 |
FontMetrics metrics, int tabIndex, |
| 1233 |
String title, Icon icon, |
| 1234 |
Rectangle tabRect, Rectangle iconRect, |
| 1235 |
Rectangle textRect, boolean isSelected) { |
| 1236 |
textRect.x = textRect.y = iconRect.x = iconRect.y = 0; |
| 1237 |
|
| 1238 |
View v = getTextViewForTab(tabIndex); |
| 1239 |
if (v != null) { |
| 1240 |
_tabPane.putClientProperty("html", v); |
| 1241 |
} |
| 1242 |
|
| 1243 |
SwingUtilities.layoutCompoundLabel(_tabPane, |
| 1244 |
metrics, title, icon, |
| 1245 |
SwingUtilities.CENTER, |
| 1246 |
SwingUtilities.CENTER, |
| 1247 |
SwingUtilities.CENTER, |
| 1248 |
SwingUtilities.TRAILING, |
| 1249 |
tabRect, |
| 1250 |
iconRect, |
| 1251 |
textRect, |
| 1252 |
_textIconGap); |
| 1253 |
|
| 1254 |
_tabPane.putClientProperty("html", null); |
| 1255 |
|
| 1256 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 1257 |
if (iconRect.x - tabRect.x < _iconMargin) { |
| 1258 |
iconRect.x = tabRect.x + _iconMargin; |
| 1259 |
textRect.x = (icon != null ? iconRect.x + iconRect.width + _textIconGap : tabRect.x + _textPadding); |
| 1260 |
iconRect.width = Math.min(iconRect.width, tabRect.width - _tabRectPadding); |
| 1261 |
textRect.width = tabRect.width - _tabRectPadding - iconRect.width - (icon != null ? _textIconGap + _iconMargin : _noIconMargin); |
| 1262 |
} |
| 1263 |
|
| 1264 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_COMPRESSED |
| 1265 |
&& isShowCloseButton() && isShowCloseButtonOnTab()) { |
| 1266 |
if (!_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 1267 |
if (!isSelected) { |
| 1268 |
iconRect.width = iconRect.width + _closeButtons[tabIndex].getPreferredSize().width + _closeButtonMarginHorizon; |
| 1269 |
textRect.width = 0; |
| 1270 |
} |
| 1271 |
} |
| 1272 |
} |
| 1273 |
} |
| 1274 |
else {// tabplacement is left or right |
| 1275 |
iconRect.y = tabRect.y + _iconMargin; |
| 1276 |
textRect.y = (icon != null ? iconRect.y + iconRect.height + _textIconGap : tabRect.y + _textPadding); |
| 1277 |
iconRect.x = tabRect.x + 2; |
| 1278 |
textRect.x = tabRect.x + 2; |
| 1279 |
textRect.width = tabRect.width - _textMarginVertical; |
| 1280 |
textRect.height = tabRect.height - _tabRectPadding - iconRect.height - (icon != null ? _textIconGap + _iconMargin : _noIconMargin); |
| 1281 |
|
| 1282 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_COMPRESSED |
| 1283 |
&& isShowCloseButton() && isShowCloseButtonOnTab()) { |
| 1284 |
if (!_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 1285 |
if (!isSelected) { |
| 1286 |
iconRect.height = iconRect.height + _closeButtons[tabIndex].getPreferredSize().height + _closeButtonMarginVertical; |
| 1287 |
textRect.height = 0; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
} |
| 1291 |
} |
| 1292 |
} |
| 1293 |
|
| 1294 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 1295 |
protected void paintIcon(Graphics g, int tabPlacement, |
| 1296 |
int tabIndex, Icon icon, Rectangle iconRect, |
| 1297 |
boolean isSelected) { |
| 1298 |
if (icon != null && iconRect.width >= icon.getIconWidth()) { |
| 1299 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 1300 |
icon.paintIcon(_tabPane, g, iconRect.x, iconRect.y); |
| 1301 |
} |
| 1302 |
else { |
| 1303 |
if (iconRect.height < _rects[tabIndex].height - _gripperHeight) { |
| 1304 |
icon.paintIcon(_tabPane, g, iconRect.x, iconRect.y); |
| 1305 |
} |
| 1306 |
} |
| 1307 |
} |
| 1308 |
} |
| 1309 |
|
| 1310 |
protected void paintText(Graphics g, int tabPlacement, |
| 1311 |
Font font, FontMetrics metrics, int tabIndex, |
| 1312 |
String title, Rectangle textRect, |
| 1313 |
boolean isSelected) { |
| 1314 |
Graphics2D g2d = (Graphics2D) g.create(); |
| 1315 |
if (isSelected && _tabPane.isBoldActiveTab()) { |
| 1316 |
g2d.setFont(font.deriveFont(Font.BOLD)); |
| 1317 |
} |
| 1318 |
else { |
| 1319 |
g2d.setFont(font); |
| 1320 |
} |
| 1321 |
|
| 1322 |
String actualText = title; |
| 1323 |
|
| 1324 |
if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) { |
| 1325 |
if (textRect.width <= 0) |
| 1326 |
return; |
| 1327 |
|
| 1328 |
while (SwingUtilities.computeStringWidth(metrics, actualText) > textRect.width) { |
| 1329 |
actualText = actualText.substring(0, actualText.length() - 1); |
| 1330 |
} |
| 1331 |
if (!actualText.equals(title)) { |
| 1332 |
if (actualText.length() >= 2) |
| 1333 |
actualText = actualText.substring(0, actualText.length() - 2) + ".."; |
| 1334 |
else |
| 1335 |
actualText = ""; |
| 1336 |
} |
| 1337 |
} |
| 1338 |
else { |
| 1339 |
if (textRect.height <= 0) |
| 1340 |
return; |
| 1341 |
|
| 1342 |
while (SwingUtilities.computeStringWidth(metrics, actualText) > textRect.height) { |
| 1343 |
actualText = actualText.substring(0, actualText.length() - 1); |
| 1344 |
} |
| 1345 |
if (!actualText.equals(title)) { |
| 1346 |
if (actualText.length() >= 2) |
| 1347 |
actualText = actualText.substring(0, actualText.length() - 2) + ".."; |
| 1348 |
else |
| 1349 |
actualText = ""; |
| 1350 |
} |
| 1351 |
} |
| 1352 |
|
| 1353 |
View v = getTextViewForTab(tabIndex); |
| 1354 |
if (v != null) { |
| 1355 |
// html |
| 1356 |
v.paint(g2d, textRect); |
| 1357 |
} |
| 1358 |
else { |
| 1359 |
// plain text |
| 1360 |
int mnemIndex = _tabPane.getDisplayedMnemonicIndexAt(tabIndex); |
| 1361 |
Component comp = null; |
| 1362 |
if (tabIndex >= 0 && tabIndex < _tabPane.getTabCount()) { |
| 1363 |
comp = _tabPane.getComponentAt(tabIndex); |
| 1364 |
} |
| 1365 |
JideTabbedPane.ColorProvider colorProvider = _tabPane.getTabColorProvider(); |
| 1366 |
Color color = null; |
| 1367 |
if (comp instanceof TabColorProvider) { |
| 1368 |
color = ((TabColorProvider) comp).getTabForeground(); |
| 1369 |
} |
| 1370 |
if (_tabPane.isEnabled() && _tabPane.isEnabledAt(tabIndex)) { |
| 1371 |
if (color == null && colorProvider != null && colorProvider.getForegroundAt(tabIndex) != null) { |
| 1372 |
g2d.setColor(colorProvider.getForegroundAt(tabIndex)); |
| 1373 |
} |
| 1374 |
else { |
| 1375 |
if (color == null) { |
| 1376 |
color = _tabPane.getForegroundAt(tabIndex); |
| 1377 |
} |
| 1378 |
if (isSelected && showFocusIndicator()) { |
| 1379 |
if (!(color instanceof ColorUIResource)) { |
| 1380 |
g2d.setColor(color); |
| 1381 |
} |
| 1382 |
else { |
| 1383 |
g2d.setColor(_activeTabForeground); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
else if (isSelected) { |
| 1387 |
if (!(color instanceof ColorUIResource)) { |
| 1388 |
g2d.setColor(color); |
| 1389 |
} |
| 1390 |
else { |
| 1391 |
g2d.setColor(_inactiveSelectedTabForeground); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
else { |
| 1395 |
if (!(color instanceof ColorUIResource)) { |
| 1396 |
g2d.setColor(color); |
| 1397 |
} |
| 1398 |
else { |
| 1399 |
g2d.setColor(_inactiveTabForeground); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
} |
| 1403 |
|
| 1404 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 1405 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); |
| 1406 |
} |
| 1407 |
else {// draw string from top to bottom |
| 1408 |
AffineTransform old = g2d.getTransform(); |
| 1409 |
g2d.translate(textRect.x, textRect.y); |
| 1410 |
if (tabPlacement == RIGHT) { |
| 1411 |
g2d.rotate(Math.PI / 2); |
| 1412 |
g2d.translate(0, -textRect.width); |
| 1413 |
} |
| 1414 |
else { |
| 1415 |
g2d.rotate(-Math.PI / 2); |
| 1416 |
g2d.translate(-textRect.height + metrics.getHeight() / 2 + _rectSizeExtend, 0); // no idea why i need 7 here |
| 1417 |
} |
| 1418 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, 0, |
| 1419 |
((textRect.width - metrics.getHeight()) / 2) + metrics.getAscent()); |
| 1420 |
g2d.setTransform(old); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
else { // tab disabled |
| 1424 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 1425 |
g2d.setColor(_tabPane.getBackgroundAt(tabIndex).brighter()); |
| 1426 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); |
| 1427 |
g2d.setColor(_tabPane.getBackgroundAt(tabIndex).darker()); |
| 1428 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1); |
| 1429 |
} |
| 1430 |
else {// draw string from top to bottom |
| 1431 |
AffineTransform old = g2d.getTransform(); |
| 1432 |
g2d.translate(textRect.x, textRect.y); |
| 1433 |
if (tabPlacement == RIGHT) { |
| 1434 |
g2d.rotate(Math.PI / 2); |
| 1435 |
g2d.translate(0, -textRect.width); |
| 1436 |
} |
| 1437 |
else { |
| 1438 |
g2d.rotate(-Math.PI / 2); |
| 1439 |
g2d.translate(-textRect.height + metrics.getHeight() / 2 + _rectSizeExtend, 0); // no idea why i need 7 here |
| 1440 |
} |
| 1441 |
g2d.setColor(_tabPane.getBackgroundAt(tabIndex).brighter()); |
| 1442 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, |
| 1443 |
0, ((textRect.width - metrics.getHeight()) / 2) + metrics.getAscent()); |
| 1444 |
g2d.setColor(_tabPane.getBackgroundAt(tabIndex).darker()); |
| 1445 |
JideSwingUtilities.drawStringUnderlineCharAt(_tabPane, g2d, actualText, mnemIndex, |
| 1446 |
tabPlacement == RIGHT ? -1 : 1, ((textRect.width - metrics.getHeight()) / 2) + metrics.getAscent() - 1); |
| 1447 |
g2d.setTransform(old); |
| 1448 |
} |
| 1449 |
} |
| 1450 |
} |
| 1451 |
g2d.dispose(); |
| 1452 |
} |
| 1453 |
|
| 1454 |
/** |
| 1455 |
* this function draws the border around each tab note that this function does now draw the background of the tab. |
| 1456 |
* that is done elsewhere |
| 1457 |
* |
| 1458 |
* @param g the Graphics instance |
| 1459 |
* @param tabPlacement the tab placement |
| 1460 |
* @param tabIndex the tab index |
| 1461 |
* @param x x |
| 1462 |
* @param y y |
| 1463 |
* @param w width |
| 1464 |
* @param h height |
| 1465 |
* @param isSelected if the tab is selected |
| 1466 |
*/ |
| 1467 |
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 1468 |
if (!PAINT_TAB_BORDER) { |
| 1469 |
return; |
| 1470 |
} |
| 1471 |
|
| 1472 |
switch (getTabShape()) { |
| 1473 |
case JideTabbedPane.SHAPE_BOX: |
| 1474 |
paintBoxTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1475 |
break; |
| 1476 |
case JideTabbedPane.SHAPE_EXCEL: |
| 1477 |
paintExcelTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1478 |
break; |
| 1479 |
case JideTabbedPane.SHAPE_WINDOWS: |
| 1480 |
paintWindowsTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1481 |
break; |
| 1482 |
case JideTabbedPane.SHAPE_WINDOWS_SELECTED: |
| 1483 |
if (isSelected) { |
| 1484 |
paintWindowsTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1485 |
} |
| 1486 |
break; |
| 1487 |
case JideTabbedPane.SHAPE_VSNET: |
| 1488 |
paintVsnetTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1489 |
break; |
| 1490 |
case JideTabbedPane.SHAPE_ROUNDED_VSNET: |
| 1491 |
paintRoundedVsnetTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1492 |
break; |
| 1493 |
case JideTabbedPane.SHAPE_FLAT: |
| 1494 |
paintFlatTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1495 |
break; |
| 1496 |
case JideTabbedPane.SHAPE_ROUNDED_FLAT: |
| 1497 |
paintRoundedFlatTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1498 |
break; |
| 1499 |
case JideTabbedPane.SHAPE_OFFICE2003: |
| 1500 |
default: |
| 1501 |
paintOffice2003TabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1502 |
} |
| 1503 |
|
| 1504 |
int tabShape = getTabShape(); |
| 1505 |
if (tabShape == JideTabbedPane.SHAPE_WINDOWS) { |
| 1506 |
if (_mouseEnter && _tabPane.getColorTheme() == JideTabbedPane.COLOR_THEME_WINXP |
| 1507 |
&& tabIndex == _indexMouseOver && !isSelected && _tabPane.isEnabledAt(_indexMouseOver)) { |
| 1508 |
paintTabBorderMouseOver(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1509 |
} |
| 1510 |
} |
| 1511 |
else if (tabShape == JideTabbedPane.SHAPE_WINDOWS_SELECTED) { |
| 1512 |
if (_mouseEnter && tabIndex == _indexMouseOver && !isSelected && _tabPane.isEnabledAt(_indexMouseOver)) { |
| 1513 |
paintTabBorderMouseOver(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
protected void paintOffice2003TabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 1519 |
int x, int y, int w, int h, boolean isSelected) { |
| 1520 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 1521 |
|
| 1522 |
switch (tabPlacement) { |
| 1523 |
case LEFT:// when the tab on the left |
| 1524 |
y += 2; |
| 1525 |
if (isSelected) {// the tab is selected |
| 1526 |
g.setColor(_selectColor1); |
| 1527 |
|
| 1528 |
g.drawLine(x, y + 3, x, y + h - 5);// left |
| 1529 |
g.drawLine(x + 1, y + h - 4, x + 1, y + h - 4);// bottom |
| 1530 |
// arc |
| 1531 |
g.drawLine(x + 2, y + h - 3, x + w - 1, y + h - 3);// bottom |
| 1532 |
|
| 1533 |
g.drawLine(x + 1, y + 2, x + 1, y + 1);// top arc |
| 1534 |
g.drawLine(x + 2, y, x + 2, y - 1); |
| 1535 |
|
| 1536 |
for (int i = 0; i < w - 4; i++) {// top |
| 1537 |
g.drawLine(x + 3 + i, y - 2 - i, x + 3 + i, y - 2 - i); |
| 1538 |
} |
| 1539 |
|
| 1540 |
g.drawLine(x + w - 1, y - w + 1, x + w - 1, y - w + 2); |
| 1541 |
|
| 1542 |
g.setColor(_selectColor2); |
| 1543 |
|
| 1544 |
g.drawLine(x + 1, y + 3, x + 1, y + h - 5);// left |
| 1545 |
g.drawLine(x + 2, y + h - 4, x + w - 1, y + h - 4);// bottom |
| 1546 |
|
| 1547 |
g.drawLine(x + 2, y + 2, x + 2, y + 1);// top arc |
| 1548 |
g.drawLine(x + 3, y, x + 3, y - 1); |
| 1549 |
|
| 1550 |
for (int i = 0; i < w - 4; i++) {// top |
| 1551 |
g.drawLine(x + 4 + i, y - 2 - i, x + 4 + i, y - 2 - i); |
| 1552 |
} |
| 1553 |
|
| 1554 |
} |
| 1555 |
else { |
| 1556 |
if (tabIndex == 0) { |
| 1557 |
g.setColor(_unselectColor1); |
| 1558 |
|
| 1559 |
g.drawLine(x, y + 3, x, y + h - 5);// left |
| 1560 |
g.drawLine(x + 1, y + h - 4, x + 1, y + h - 4);// bottom |
| 1561 |
// arc |
| 1562 |
g.drawLine(x + 2, y + h - 3, x + w - 1, y + h - 3);// bottom |
| 1563 |
|
| 1564 |
g.drawLine(x + 1, y + 2, x + 1, y + 1);// top arc |
| 1565 |
g.drawLine(x + 2, y, x + 2, y - 1); |
| 1566 |
|
| 1567 |
for (int i = 0; i < w - 4; i++) {// top |
| 1568 |
g.drawLine(x + 3 + i, y - 2 - i, x + 3 + i, y - 2 - i); |
| 1569 |
} |
| 1570 |
|
| 1571 |
g.drawLine(x + w - 1, y - w + 1, x + w - 1, y - w + 2); |
| 1572 |
|
| 1573 |
if (_unselectColor2 != null) { |
| 1574 |
g.setColor(_unselectColor2); |
| 1575 |
|
| 1576 |
g.drawLine(x + 1, y + 3, x + 1, y + h - 6);// left |
| 1577 |
|
| 1578 |
g.drawLine(x + 2, y + 2, x + 2, y + 1);// top arc |
| 1579 |
g.drawLine(x + 3, y, x + 3, y - 1); |
| 1580 |
|
| 1581 |
for (int i = 0; i < w - 4; i++) {// top |
| 1582 |
g.drawLine(x + 4 + i, y - 2 - i, x + 4 + i, y - 2 - i); |
| 1583 |
} |
| 1584 |
|
| 1585 |
g.setColor(getPainter().getControlDk()); |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (_unselectColor3 != null) { |
| 1589 |
g.setColor(_unselectColor3); |
| 1590 |
|
| 1591 |
g.drawLine(x + 2, y + h - 4, x + w - 1, y + h - 4);// bottom |
| 1592 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5);// bottom |
| 1593 |
// arc |
| 1594 |
} |
| 1595 |
} |
| 1596 |
else { |
| 1597 |
g.setColor(_unselectColor1); |
| 1598 |
|
| 1599 |
g.drawLine(x, y + 3, x, y + h - 5);// left |
| 1600 |
g.drawLine(x + 1, y + h - 4, x + 1, y + h - 4);// bottom |
| 1601 |
// arc |
| 1602 |
g.drawLine(x + 2, y + h - 3, x + w - 1, y + h - 3);// bottom |
| 1603 |
|
| 1604 |
g.drawLine(x + 1, y + 2, x + 1, y + 1);// top arc |
| 1605 |
g.drawLine(x + 2, y, x + 2, y - 1); |
| 1606 |
g.drawLine(x + 3, y - 2, x + 3, y - 2); |
| 1607 |
|
| 1608 |
if (_unselectColor2 != null) { |
| 1609 |
g.setColor(_unselectColor2); |
| 1610 |
|
| 1611 |
g.drawLine(x + 1, y + 3, x + 1, y + h - 6);// left |
| 1612 |
|
| 1613 |
g.drawLine(x + 2, y + 2, x + 2, y + 1);// top arc |
| 1614 |
g.drawLine(x + 3, y, x + 3, y - 1); |
| 1615 |
g.drawLine(x + 4, y - 2, x + 4, y - 2); |
| 1616 |
|
| 1617 |
} |
| 1618 |
|
| 1619 |
if (_unselectColor3 != null) { |
| 1620 |
g.setColor(_unselectColor3); |
| 1621 |
|
| 1622 |
g.drawLine(x + 2, y + h - 4, x + w - 1, y + h - 4);// bottom |
| 1623 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5); |
| 1624 |
} |
| 1625 |
} |
| 1626 |
} |
| 1627 |
break; |
| 1628 |
case RIGHT: |
| 1629 |
if (isSelected) {// the tab is selected |
| 1630 |
g.setColor(_selectColor1); |
| 1631 |
|
| 1632 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 3);// right |
| 1633 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 1634 |
// arc |
| 1635 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 1636 |
|
| 1637 |
g.drawLine(x + w - 2, y + 4, x + w - 2, y + 3);// top arc |
| 1638 |
g.drawLine(x + w - 3, y + 2, x + w - 3, y + 1);// top arc |
| 1639 |
|
| 1640 |
for (int i = 0; i < w - 4; i++) {// top |
| 1641 |
g.drawLine(x + w - 4 - i, y - i, x + w - 4 - i, y - i); |
| 1642 |
} |
| 1643 |
|
| 1644 |
g.drawLine(x, y - w + 3, x, y - w + 4); |
| 1645 |
|
| 1646 |
g.setColor(_selectColor2); |
| 1647 |
|
| 1648 |
g.drawLine(x + w - 2, y + 5, x + w - 2, y + h - 3);// right |
| 1649 |
g.drawLine(x + w - 3, y + h - 2, x, y + h - 2);// bottom |
| 1650 |
|
| 1651 |
g.drawLine(x + w - 3, y + 4, x + w - 3, y + 3);// top arc |
| 1652 |
g.drawLine(x + w - 4, y + 2, x + w - 4, y + 1); |
| 1653 |
|
| 1654 |
for (int i = 0; i < w - 4; i++) {// top |
| 1655 |
g.drawLine(x + w - 5 - i, y - i, x + w - 5 - i, y - i); |
| 1656 |
} |
| 1657 |
} |
| 1658 |
else { |
| 1659 |
if (tabIndex == 0) { |
| 1660 |
g.setColor(_unselectColor1); |
| 1661 |
|
| 1662 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 3);// right |
| 1663 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 1664 |
// arc |
| 1665 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 1666 |
|
| 1667 |
g.drawLine(x + w - 2, y + 4, x + w - 2, y + 3);// top arc |
| 1668 |
g.drawLine(x + w - 3, y + 2, x + w - 3, y + 1);// top arc |
| 1669 |
|
| 1670 |
for (int i = 0; i < w - 4; i++) {// top |
| 1671 |
g.drawLine(x + w - 4 - i, y - i, x + w - 4 - i, y - i); |
| 1672 |
} |
| 1673 |
|
| 1674 |
g.drawLine(x, y - w + 3, x, y - w + 4); |
| 1675 |
|
| 1676 |
if (_unselectColor2 != null) { |
| 1677 |
g.setColor(_unselectColor2); |
| 1678 |
|
| 1679 |
g.drawLine(x + w - 2, y + 5, x + w - 2, y + h - 4);// right |
| 1680 |
|
| 1681 |
g.drawLine(x + w - 3, y + 4, x + w - 3, y + 3);// top |
| 1682 |
// arc |
| 1683 |
g.drawLine(x + w - 4, y + 2, x + w - 4, y + 1); |
| 1684 |
|
| 1685 |
for (int i = 0; i < w - 4; i++) {// top |
| 1686 |
g.drawLine(x + w - 5 - i, y - i, x + w - 5 - i, y |
| 1687 |
- i); |
| 1688 |
} |
| 1689 |
} |
| 1690 |
|
| 1691 |
if (_unselectColor3 != null) { |
| 1692 |
g.setColor(_unselectColor3); |
| 1693 |
|
| 1694 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y + h - 3);// bottom |
| 1695 |
// arc |
| 1696 |
g.drawLine(x + w - 3, y + h - 2, x, y + h - 2);// bottom |
| 1697 |
|
| 1698 |
} |
| 1699 |
} |
| 1700 |
else { |
| 1701 |
g.setColor(_unselectColor1); |
| 1702 |
|
| 1703 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 3);// right |
| 1704 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 1705 |
// arc |
| 1706 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 1707 |
|
| 1708 |
g.drawLine(x + w - 2, y + 4, x + w - 2, y + 3);// top arc |
| 1709 |
g.drawLine(x + w - 3, y + 2, x + w - 3, y + 1);// top arc |
| 1710 |
g.drawLine(x + w - 4, y, x + w - 4, y);// top arc |
| 1711 |
|
| 1712 |
if (_unselectColor2 != null) { |
| 1713 |
g.setColor(_unselectColor2); |
| 1714 |
|
| 1715 |
g.drawLine(x + w - 2, y + 5, x + w - 2, y + h - 4);// right |
| 1716 |
|
| 1717 |
g.drawLine(x + w - 3, y + 4, x + w - 3, y + 3);// top |
| 1718 |
// arc |
| 1719 |
g.drawLine(x + w - 4, y + 2, x + w - 4, y + 1); |
| 1720 |
g.drawLine(x + w - 5, y, x + w - 5, y); |
| 1721 |
} |
| 1722 |
|
| 1723 |
if (_unselectColor3 != null) { |
| 1724 |
g.setColor(_unselectColor3); |
| 1725 |
|
| 1726 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y + h - 3);// bottom |
| 1727 |
// arc |
| 1728 |
g.drawLine(x + w - 3, y + h - 2, x, y + h - 2);// bottom |
| 1729 |
} |
| 1730 |
} |
| 1731 |
} |
| 1732 |
break; |
| 1733 |
case BOTTOM: |
| 1734 |
if (leftToRight) { |
| 1735 |
if (isSelected) {// the tab is selected |
| 1736 |
g.setColor(_selectColor1); |
| 1737 |
|
| 1738 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y);// right |
| 1739 |
|
| 1740 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// right |
| 1741 |
// arc |
| 1742 |
|
| 1743 |
g.drawLine(x + 5, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 1744 |
|
| 1745 |
g.drawLine(x + 3, y + h - 2, x + 4, y + h - 2);// left arc |
| 1746 |
g.drawLine(x + 1, y + h - 3, x + 2, y + h - 3);// left arc |
| 1747 |
g.drawLine(x, y + h - 4, x, y + h - 4);// left arc |
| 1748 |
|
| 1749 |
// left |
| 1750 |
for (int i = 3; i < h - 2; i++) { |
| 1751 |
g.drawLine(x + 2 - i, y + h - 2 - i, x + 2 - i, y + h |
| 1752 |
- 2 - i); |
| 1753 |
} |
| 1754 |
|
| 1755 |
g.drawLine(x - h + 3, y, x - h + 4, y); |
| 1756 |
|
| 1757 |
g.setColor(_selectColor2); |
| 1758 |
|
| 1759 |
g.drawLine(x + 5, y + h - 2, x + w - 3, y + h - 2);// bottom |
| 1760 |
|
| 1761 |
g.drawLine(x + w - 2, y, x + w - 2, y + h - 3);// right |
| 1762 |
|
| 1763 |
g.drawLine(x + 3, y + h - 3, x + 4, y + h - 3);// left arc |
| 1764 |
g.drawLine(x + 1, y + h - 4, x + 2, y + h - 4);// left arc |
| 1765 |
g.drawLine(x, y + h - 5, x, y + h - 5);// left arc |
| 1766 |
|
| 1767 |
for (int i = 3; i < h - 2; i++) {// left |
| 1768 |
g.drawLine(x + 2 - i, y + h - 3 - i, x + 2 - i, y + h |
| 1769 |
- 3 - i); |
| 1770 |
} |
| 1771 |
|
| 1772 |
} |
| 1773 |
else { |
| 1774 |
if (tabIndex == 0) { |
| 1775 |
g.setColor(_unselectColor1); |
| 1776 |
|
| 1777 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y);// right |
| 1778 |
|
| 1779 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// right |
| 1780 |
// arc |
| 1781 |
|
| 1782 |
g.drawLine(x + 5, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 1783 |
|
| 1784 |
g.drawLine(x + 3, y + h - 2, x + 4, y + h - 2);// left arc |
| 1785 |
g.drawLine(x + 1, y + h - 3, x + 2, y + h - 3);// left arc |
| 1786 |
g.drawLine(x, y + h - 4, x, y + h - 4);// left arc |
| 1787 |
|
| 1788 |
// left |
| 1789 |
for (int i = 3; i < h - 2; i++) { |
| 1790 |
g.drawLine(x + 2 - i, y + h - 2 - i, x + 2 - i, y + h |
| 1791 |
- 2 - i); |
| 1792 |
} |
| 1793 |
|
| 1794 |
g.drawLine(x - h + 3, y, x - h + 4, y); |
| 1795 |
|
| 1796 |
if (_unselectColor2 != null) { |
| 1797 |
g.setColor(_unselectColor2); |
| 1798 |
|
| 1799 |
g.drawLine(x + 3, y + h - 3, x + 4, y + h - 3);// left |
| 1800 |
// arc |
| 1801 |
g.drawLine(x + 1, y + h - 4, x + 2, y + h - 4);// left |
| 1802 |
// arc |
| 1803 |
g.drawLine(x, y + h - 5, x, y + h - 5);// left arc |
| 1804 |
|
| 1805 |
// left |
| 1806 |
for (int i = 3; i < h - 2; i++) { |
| 1807 |
g.drawLine(x + 2 - i, y + h - 3 - i, x + 2 - i, y |
| 1808 |
+ h - 3 - i); |
| 1809 |
} |
| 1810 |
|
| 1811 |
g.drawLine(x + 5, y + h - 2, x + w - 4, y + h - 2);// bottom |
| 1812 |
|
| 1813 |
} |
| 1814 |
|
| 1815 |
if (_unselectColor3 != null) { |
| 1816 |
g.setColor(_unselectColor3); |
| 1817 |
|
| 1818 |
g.drawLine(x + w - 3, y + h - 2, x + w - 3, y + h - 2); |
| 1819 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y);// right |
| 1820 |
} |
| 1821 |
} |
| 1822 |
else { |
| 1823 |
g.setColor(_unselectColor1); |
| 1824 |
|
| 1825 |
g.drawLine(x + 5, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 1826 |
|
| 1827 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y);// right |
| 1828 |
|
| 1829 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// right |
| 1830 |
// arc |
| 1831 |
|
| 1832 |
g.drawLine(x + 3, y + h - 2, x + 4, y + h - 2);// left arc |
| 1833 |
g.drawLine(x + 1, y + h - 3, x + 2, y + h - 3);// left arc |
| 1834 |
g.drawLine(x, y + h - 4, x, y + h - 4);// left arc |
| 1835 |
|
| 1836 |
if (_unselectColor2 != null) { |
| 1837 |
g.setColor(_unselectColor2); |
| 1838 |
|
| 1839 |
g.drawLine(x + 3, y + h - 3, x + 4, y + h - 3);// left |
| 1840 |
// arc |
| 1841 |
g.drawLine(x + 1, y + h - 4, x + 2, y + h - 4);// left |
| 1842 |
// arc |
| 1843 |
g.drawLine(x, y + h - 5, x, y + h - 5);// left arc |
| 1844 |
|
| 1845 |
g.drawLine(x + 5, y + h - 2, x + w - 4, y + h - 2);// bottom |
| 1846 |
} |
| 1847 |
|
| 1848 |
if (_unselectColor3 != null) { |
| 1849 |
g.setColor(_unselectColor3); |
| 1850 |
|
| 1851 |
g.drawLine(x + w - 3, y + h - 2, x + w - 3, y + h - 2); |
| 1852 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y);// right |
| 1853 |
} |
| 1854 |
} |
| 1855 |
} |
| 1856 |
} |
| 1857 |
else { |
| 1858 |
if (isSelected) {// the tab is selected |
| 1859 |
g.setColor(_selectColor1); |
| 1860 |
|
| 1861 |
g.drawLine(x, y + h - 3, x, y);// left |
| 1862 |
|
| 1863 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);// left |
| 1864 |
// arc |
| 1865 |
|
| 1866 |
g.drawLine(x + w - 6, y + h - 1, x + 2, y + h - 1);// bottom |
| 1867 |
|
| 1868 |
g.drawLine(x + w - 4, y + h - 2, x + w - 5, y + h - 2);// right arc |
| 1869 |
g.drawLine(x + w - 2, y + h - 3, x + w - 3, y + h - 3);// right arc |
| 1870 |
g.drawLine(x + w - 1, y + h - 4, x + w - 1, y + h - 4);// right arc |
| 1871 |
|
| 1872 |
// right |
| 1873 |
for (int i = 3; i < h - 2; i++) { |
| 1874 |
g.drawLine(x + w - 3 + i, y + h - 2 - i, x + w - 3 + i, y + h - 2 - i); |
| 1875 |
} |
| 1876 |
|
| 1877 |
g.drawLine(x + w - 4 + h, y, x + w - 5 + h, y); |
| 1878 |
|
| 1879 |
g.setColor(_selectColor2); |
| 1880 |
|
| 1881 |
g.drawLine(x + w - 6, y + h - 2, x + 2, y + h - 2);// bottom |
| 1882 |
|
| 1883 |
g.drawLine(x + 1, y, x + 1, y + h - 3);// left |
| 1884 |
|
| 1885 |
g.drawLine(x + w - 4, y + h - 3, x + w - 5, y + h - 3);// right arc |
| 1886 |
g.drawLine(x + w - 2, y + h - 4, x + w - 3, y + h - 4);// right arc |
| 1887 |
g.drawLine(x + w - 1, y + h - 5, x + w - 1, y + h - 5);// right arc |
| 1888 |
|
| 1889 |
for (int i = 3; i < h - 2; i++) {// right |
| 1890 |
g.drawLine(x + w - 3 + i, y + h - 3 - i, x + w - 3 + i, y + h - 3 - i); |
| 1891 |
} |
| 1892 |
} |
| 1893 |
else { |
| 1894 |
if (tabIndex == 0) { |
| 1895 |
g.setColor(_unselectColor1); |
| 1896 |
|
| 1897 |
g.drawLine(x, y + h - 3, x, y);// left |
| 1898 |
|
| 1899 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);// left |
| 1900 |
// arc |
| 1901 |
|
| 1902 |
g.drawLine(x + w - 6, y + h - 1, x + 2, y + h - 1);// bottom |
| 1903 |
|
| 1904 |
g.drawLine(x + w - 4, y + h - 2, x + w - 5, y + h - 2);// right arc |
| 1905 |
g.drawLine(x + w - 2, y + h - 3, x + w - 3, y + h - 3);// right arc |
| 1906 |
g.drawLine(x + w - 1, y + h - 4, x + w - 1, y + h - 4);// right arc |
| 1907 |
|
| 1908 |
// right |
| 1909 |
for (int i = 3; i < h - 2; i++) { |
| 1910 |
g.drawLine(x + w - 3 + i, y + h - 2 - i, x + w - 3 + i, y + h - 2 - i); |
| 1911 |
} |
| 1912 |
|
| 1913 |
g.drawLine(x + w - 4 + h, y, x + w - 5 + h, y); |
| 1914 |
|
| 1915 |
if (_unselectColor2 != null) { |
| 1916 |
g.setColor(_unselectColor2); |
| 1917 |
|
| 1918 |
g.drawLine(x + w - 4, y + h - 3, x + w - 5, y + h - 3);// right |
| 1919 |
// arc |
| 1920 |
g.drawLine(x + w - 2, y + h - 4, x + w - 3, y + h - 4);// right |
| 1921 |
// arc |
| 1922 |
g.drawLine(x + w - 1, y + h - 5, x + w - 1, y + h - 5);// right arc |
| 1923 |
|
| 1924 |
// right |
| 1925 |
for (int i = 3; i < h - 2; i++) { |
| 1926 |
g.drawLine(x + w - 3 + i, y + h - 3 - i, x + w - 3 + i, y + h - 3 - i); |
| 1927 |
} |
| 1928 |
|
| 1929 |
g.drawLine(x + w - 6, y + h - 2, x + 3, y + h - 2);// bottom |
| 1930 |
} |
| 1931 |
|
| 1932 |
if (_unselectColor3 != null) { |
| 1933 |
g.setColor(_unselectColor3); |
| 1934 |
|
| 1935 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2); |
| 1936 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left |
| 1937 |
} |
| 1938 |
} |
| 1939 |
else { |
| 1940 |
g.setColor(_unselectColor1); |
| 1941 |
|
| 1942 |
g.drawLine(x + w - 6, y + h - 1, x + 2, y + h - 1);// bottom |
| 1943 |
|
| 1944 |
g.drawLine(x, y + h - 3, x, y);// left |
| 1945 |
|
| 1946 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);// left |
| 1947 |
// arc |
| 1948 |
|
| 1949 |
g.drawLine(x + w - 4, y + h - 2, x + w - 5, y + h - 2);// right arc |
| 1950 |
g.drawLine(x + w - 2, y + h - 3, x + w - 3, y + h - 3);// right arc |
| 1951 |
g.drawLine(x + w - 1, y + h - 4, x + w - 1, y + h - 4);// right arc |
| 1952 |
|
| 1953 |
if (_unselectColor2 != null) { |
| 1954 |
g.setColor(_unselectColor2); |
| 1955 |
|
| 1956 |
g.drawLine(x + w - 4, y + h - 3, x + w - 5, y + h - 3);// right |
| 1957 |
// arc |
| 1958 |
g.drawLine(x + w - 2, y + h - 4, x + w - 3, y + h - 4);// right |
| 1959 |
// arc |
| 1960 |
g.drawLine(x + w - 1, y + h - 5, x + w - 1, y + h - 5);// right arc |
| 1961 |
|
| 1962 |
g.drawLine(x + w - 6, y + h - 2, x + 3, y + h - 2);// bottom |
| 1963 |
} |
| 1964 |
|
| 1965 |
if (_unselectColor3 != null) { |
| 1966 |
g.setColor(_unselectColor3); |
| 1967 |
|
| 1968 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2); |
| 1969 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left |
| 1970 |
} |
| 1971 |
} |
| 1972 |
} |
| 1973 |
} |
| 1974 |
break; |
| 1975 |
case TOP: |
| 1976 |
default: |
| 1977 |
if (leftToRight) { |
| 1978 |
if (isSelected) {// the tab is selected |
| 1979 |
g.setColor(_selectColor1); |
| 1980 |
|
| 1981 |
g.drawLine(x + 3, y + 1, x + 4, y + 1);// left arc |
| 1982 |
g.drawLine(x + 1, y + 2, x + 2, y + 2);// left arc |
| 1983 |
g.drawLine(x, y + 3, x, y + 3); |
| 1984 |
|
| 1985 |
g.drawLine(x + 5, y, x + w - 3, y);// top |
| 1986 |
|
| 1987 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// right arc |
| 1988 |
|
| 1989 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);// right |
| 1990 |
|
| 1991 |
// left |
| 1992 |
for (int i = 3; i < h - 2; i++) { |
| 1993 |
g.drawLine(x + 2 - i, y + 1 + i, x + 2 - i, y + 1 + i); |
| 1994 |
} |
| 1995 |
g.drawLine(x - h + 3, y + h - 1, x - h + 4, y + h - 1); |
| 1996 |
|
| 1997 |
g.setColor(_selectColor2); |
| 1998 |
|
| 1999 |
g.drawLine(x + 3, y + 2, x + 4, y + 2);// left arc |
| 2000 |
g.drawLine(x + 1, y + 3, x + 2, y + 3);// left arc |
| 2001 |
g.drawLine(x, y + 4, x, y + 4); |
| 2002 |
|
| 2003 |
g.drawLine(x + 5, y + 1, x + w - 3, y + 1);// top |
| 2004 |
|
| 2005 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1);// right |
| 2006 |
|
| 2007 |
// left |
| 2008 |
for (int i = 3; i < h - 2; i++) { |
| 2009 |
g.drawLine(x + 2 - i, y + 2 + i, x + 2 - i, y + 2 + i); |
| 2010 |
} |
| 2011 |
} |
| 2012 |
else { |
| 2013 |
if (tabIndex == 0) { |
| 2014 |
g.setColor(_unselectColor1); |
| 2015 |
|
| 2016 |
g.drawLine(x + 3, y + 1, x + 4, y + 1);// left arc |
| 2017 |
g.drawLine(x + 1, y + 2, x + 2, y + 2);// left arc |
| 2018 |
g.drawLine(x, y + 3, x, y + 3); |
| 2019 |
|
| 2020 |
g.drawLine(x + 5, y, x + w - 3, y);// top |
| 2021 |
|
| 2022 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// right arc |
| 2023 |
|
| 2024 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);// right |
| 2025 |
|
| 2026 |
// left |
| 2027 |
for (int i = 3; i < h - 2; i++) { |
| 2028 |
g.drawLine(x + 2 - i, y + 1 + i, x + 2 - i, y + 1 + i); |
| 2029 |
} |
| 2030 |
g.drawLine(x - h + 3, y + h - 1, x - h + 4, y + h - 1); |
| 2031 |
|
| 2032 |
if (_unselectColor2 != null) { |
| 2033 |
g.setColor(_unselectColor2); |
| 2034 |
|
| 2035 |
g.drawLine(x + 3, y + 2, x + 4, y + 2);// left arc |
| 2036 |
g.drawLine(x + 1, y + 3, x + 2, y + 3);// left arc |
| 2037 |
g.drawLine(x, y + 4, x, y + 4); |
| 2038 |
|
| 2039 |
// left |
| 2040 |
for (int i = 3; i < h - 2; i++) { |
| 2041 |
g.drawLine(x + 2 - i, y + 2 + i, x + 2 - i, y + 2 |
| 2042 |
+ i); |
| 2043 |
} |
| 2044 |
|
| 2045 |
g.drawLine(x + 5, y + 1, x + w - 4, y + 1);// top |
| 2046 |
} |
| 2047 |
|
| 2048 |
if (_unselectColor3 != null) { |
| 2049 |
g.setColor(_unselectColor3); |
| 2050 |
|
| 2051 |
g.drawLine(x + w - 3, y + 1, x + w - 3, y + 1); |
| 2052 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1);// right |
| 2053 |
} |
| 2054 |
} |
| 2055 |
else { |
| 2056 |
g.setColor(_unselectColor1); |
| 2057 |
|
| 2058 |
g.drawLine(x + 3, y + 1, x + 4, y + 1);// left arc |
| 2059 |
g.drawLine(x + 1, y + 2, x + 2, y + 2);// left arc |
| 2060 |
g.drawLine(x, y + 3, x, y + 3); |
| 2061 |
|
| 2062 |
g.drawLine(x + 5, y, x + w - 3, y);// top |
| 2063 |
|
| 2064 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// right arc |
| 2065 |
|
| 2066 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);// right |
| 2067 |
|
| 2068 |
if (_unselectColor2 != null) { |
| 2069 |
g.setColor(_unselectColor2); |
| 2070 |
|
| 2071 |
g.drawLine(x + 3, y + 2, x + 4, y + 2);// left arc |
| 2072 |
g.drawLine(x + 1, y + 3, x + 2, y + 3);// left arc |
| 2073 |
g.drawLine(x, y + 4, x, y + 4); |
| 2074 |
|
| 2075 |
g.drawLine(x + 5, y + 1, x + w - 4, y + 1);// top |
| 2076 |
} |
| 2077 |
|
| 2078 |
if (_unselectColor3 != null) { |
| 2079 |
g.setColor(_unselectColor3); |
| 2080 |
|
| 2081 |
g.drawLine(x + w - 3, y + 1, x + w - 3, y + 1); |
| 2082 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1);// right |
| 2083 |
} |
| 2084 |
} |
| 2085 |
} |
| 2086 |
} |
| 2087 |
else { |
| 2088 |
if (isSelected) {// the tab is selected |
| 2089 |
g.setColor(_selectColor1); |
| 2090 |
|
| 2091 |
g.drawLine(x + w - 4, y + 1, x + w - 5, y + 1);// right arc |
| 2092 |
g.drawLine(x + w - 2, y + 2, x + w - 3, y + 2);// right arc |
| 2093 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + 3); |
| 2094 |
|
| 2095 |
g.drawLine(x + w - 6, y, x + 2, y);// top |
| 2096 |
|
| 2097 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// left arc |
| 2098 |
|
| 2099 |
g.drawLine(x, y + 2, x, y + h - 1);// left |
| 2100 |
|
| 2101 |
// right |
| 2102 |
for (int i = 3; i < h - 2; i++) { |
| 2103 |
g.drawLine(x + w - 3 + i, y + 1 + i, x + w - 3 + i, y + 1 + i); |
| 2104 |
} |
| 2105 |
g.drawLine(x + w - 4 + h, y + h - 1, x + w - 5 + h, y + h - 1); |
| 2106 |
|
| 2107 |
g.setColor(_selectColor2); |
| 2108 |
|
| 2109 |
g.drawLine(x + w - 4, y + 2, x + w - 5, y + 2);// right arc |
| 2110 |
g.drawLine(x + w - 2, y + 3, x + w - 3, y + 3);// right arc |
| 2111 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + 4); |
| 2112 |
|
| 2113 |
g.drawLine(x + w - 6, y + 1, x + 2, y + 1);// top |
| 2114 |
|
| 2115 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1);// right |
| 2116 |
|
| 2117 |
// right |
| 2118 |
for (int i = 3; i < h - 2; i++) { |
| 2119 |
g.drawLine(x + w - 3 + i, y + 2 + i, x + w - 3 + i, y + 2 + i); |
| 2120 |
} |
| 2121 |
} |
| 2122 |
else { |
| 2123 |
if (tabIndex == 0) { |
| 2124 |
g.setColor(_unselectColor1); |
| 2125 |
|
| 2126 |
g.drawLine(x + w - 4, y + 1, x + w - 5, y + 1);// right arc |
| 2127 |
g.drawLine(x + w - 2, y + 2, x + w - 3, y + 2);// right arc |
| 2128 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + 3); |
| 2129 |
|
| 2130 |
g.drawLine(x + w - 6, y, x + 2, y);// top |
| 2131 |
|
| 2132 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// left arc |
| 2133 |
|
| 2134 |
g.drawLine(x, y + 2, x, y + h - 1);// left |
| 2135 |
|
| 2136 |
// right |
| 2137 |
for (int i = 3; i < h - 2; i++) { |
| 2138 |
g.drawLine(x + w - 3 + i, y + 1 + i, x + w - 3 + i, y + 1 + i); |
| 2139 |
} |
| 2140 |
g.drawLine(x + w - 4 + h, y + h - 1, x + w - 5 + h, y + h - 1);// |
| 2141 |
|
| 2142 |
if (_unselectColor2 != null) { |
| 2143 |
g.setColor(_unselectColor2); |
| 2144 |
|
| 2145 |
g.drawLine(x + w - 4, y + 2, x + w - 5, y + 2);// right arc |
| 2146 |
g.drawLine(x + w - 2, y + 3, x + w - 3, y + 3);// right arc |
| 2147 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + 4); |
| 2148 |
|
| 2149 |
// right |
| 2150 |
for (int i = 3; i < h - 2; i++) { |
| 2151 |
g.drawLine(x + w - 3 + i, y + 2 + i, x + w - 3 + i, y + 2 + i); |
| 2152 |
} |
| 2153 |
|
| 2154 |
g.drawLine(x + w - 6, y + 1, x + 3, y + 1);// top |
| 2155 |
} |
| 2156 |
|
| 2157 |
if (_unselectColor3 != null) { |
| 2158 |
g.setColor(_unselectColor3); |
| 2159 |
|
| 2160 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); |
| 2161 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1);// left |
| 2162 |
} |
| 2163 |
} |
| 2164 |
else { |
| 2165 |
g.setColor(_unselectColor1); |
| 2166 |
|
| 2167 |
g.drawLine(x + w - 4, y + 1, x + w - 5, y + 1);// right arc |
| 2168 |
g.drawLine(x + w - 2, y + 2, x + w - 3, y + 2);// right arc |
| 2169 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + 3); |
| 2170 |
|
| 2171 |
g.drawLine(x + w - 6, y, x + 2, y);// top |
| 2172 |
|
| 2173 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// left arc |
| 2174 |
|
| 2175 |
g.drawLine(x, y + 2, x, y + h - 1);// left |
| 2176 |
|
| 2177 |
if (_unselectColor2 != null) { |
| 2178 |
g.setColor(_unselectColor2); |
| 2179 |
|
| 2180 |
g.drawLine(x + w - 4, y + 2, x + w - 5, y + 2);// right arc |
| 2181 |
g.drawLine(x + w - 2, y + 3, x + w - 3, y + 3);// right arc |
| 2182 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + 4); |
| 2183 |
|
| 2184 |
g.drawLine(x + w - 6, y + 1, x + 3, y + 1);// top |
| 2185 |
} |
| 2186 |
|
| 2187 |
if (_unselectColor3 != null) { |
| 2188 |
g.setColor(_unselectColor3); |
| 2189 |
|
| 2190 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); |
| 2191 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1);// left |
| 2192 |
} |
| 2193 |
} |
| 2194 |
} |
| 2195 |
} |
| 2196 |
} |
| 2197 |
|
| 2198 |
} |
| 2199 |
|
| 2200 |
|
| 2201 |
protected void paintExcelTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 2202 |
int x, int y, int w, int h, boolean isSelected) { |
| 2203 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 2204 |
switch (tabPlacement) { |
| 2205 |
case LEFT: |
| 2206 |
if (isSelected) { |
| 2207 |
g.setColor(_selectColor1); |
| 2208 |
g.drawLine(x, y + 5, x, y + h - 5);// left |
| 2209 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// top |
| 2210 |
g.drawLine(x + 1 + j, y + 4 - i, x + 2 + j, y + 4 - i); |
| 2211 |
} |
| 2212 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2213 |
g.drawLine(x + j, y + h - 4 + i, x + 1 + j, y + h - 4 + i); |
| 2214 |
} |
| 2215 |
|
| 2216 |
if (_selectColor2 != null) { |
| 2217 |
g.setColor(_selectColor2); |
| 2218 |
g.drawLine(x + 1, y + 6, x + 1, y + h - 6);// left |
| 2219 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// top |
| 2220 |
g.drawLine(x + 1 + j, y + 5 - i, x + 2 + j, y + 5 - i); |
| 2221 |
} |
| 2222 |
} |
| 2223 |
|
| 2224 |
if (_selectColor3 != null) { |
| 2225 |
g.setColor(_selectColor3); |
| 2226 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5);// a point |
| 2227 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2228 |
g.drawLine(x + 2 + j, y + h - 4 + i, x + 3 + j, y + h - 4 + i); |
| 2229 |
} |
| 2230 |
} |
| 2231 |
} |
| 2232 |
else { |
| 2233 |
if (tabIndex == 0) { |
| 2234 |
g.setColor(_unselectColor1); |
| 2235 |
g.drawLine(x, y + 5, x, y + h - 5);// left |
| 2236 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// top |
| 2237 |
g.drawLine(x + 1 + j, y + 4 - i, x + 2 + j, y + 4 - i); |
| 2238 |
} |
| 2239 |
|
| 2240 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2241 |
g.drawLine(x + j, y + h - 4 + i, x + 1 + j, y + h - 4 + i); |
| 2242 |
} |
| 2243 |
|
| 2244 |
if (_unselectColor2 != null) { |
| 2245 |
g.setColor(_unselectColor2); |
| 2246 |
g.drawLine(x + 1, y + 6, x + 1, y + h - 6);// left |
| 2247 |
for (int i = 0, j = 0; i < w / 2; i++, j = j + 2) {// top |
| 2248 |
g.drawLine(x + 1 + j, y + 5 - i, x + 2 + j, y + 5 - i); |
| 2249 |
} |
| 2250 |
} |
| 2251 |
|
| 2252 |
if (_unselectColor3 != null) { |
| 2253 |
g.setColor(_unselectColor3); |
| 2254 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5);// a point |
| 2255 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2256 |
g.drawLine(x + 2 + j, y + h - 4 + i, x + 3 + j, y + h - 4 + i); |
| 2257 |
} |
| 2258 |
} |
| 2259 |
} |
| 2260 |
else if (tabIndex == _tabPane.getSelectedIndex() - 1) { |
| 2261 |
g.setColor(_unselectColor1); |
| 2262 |
g.drawLine(x, y + 5, x, y + h - 5);// left |
| 2263 |
for (int i = 0, j = 0; i < 4; i++, j = j + 2) {// top |
| 2264 |
g.drawLine(x + 1 + j, y + 4 - i, x + 2 + j, y + 4 - i); |
| 2265 |
} |
| 2266 |
|
| 2267 |
for (int i = 0, j = 0; i < 5; i++, j = j + 2) {// bottom |
| 2268 |
g.drawLine(x + j, y + h - 4 + i, x + 1 + j, y + h - 4 + i); |
| 2269 |
} |
| 2270 |
|
| 2271 |
if (_unselectColor2 != null) { |
| 2272 |
g.setColor(_unselectColor2); |
| 2273 |
g.drawLine(x + 1, y + 6, x + 1, y + h - 6);// left |
| 2274 |
for (int i = 0, j = 0; i < 4; i++, j = j + 2) {// top |
| 2275 |
g.drawLine(x + 1 + j, y + 5 - i, x + 2 + j, y + 5 - i); |
| 2276 |
} |
| 2277 |
} |
| 2278 |
|
| 2279 |
if (_unselectColor3 != null) { |
| 2280 |
g.setColor(_unselectColor3); |
| 2281 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5);// a point |
| 2282 |
for (int i = 0, j = 0; i < 5; i++, j = j + 2) {// bottom |
| 2283 |
g.drawLine(x + 2 + j, y + h - 4 + i, x + 3 + j, y + h - 4 + i); |
| 2284 |
} |
| 2285 |
} |
| 2286 |
} |
| 2287 |
else if (tabIndex != _tabPane.getSelectedIndex() - 1) { |
| 2288 |
g.setColor(_unselectColor1); |
| 2289 |
g.drawLine(x, y + 5, x, y + h - 5);// left |
| 2290 |
for (int i = 0, j = 0; i < 4; i++, j = j + 2) {// top |
| 2291 |
g.drawLine(x + 1 + j, y + 4 - i, x + 2 + j, y + 4 - i); |
| 2292 |
} |
| 2293 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2294 |
g.drawLine(x + j, y + h - 4 + i, x + 1 + j, y + h - 4 + i); |
| 2295 |
} |
| 2296 |
|
| 2297 |
if (_unselectColor2 != null) { |
| 2298 |
g.setColor(_unselectColor2); |
| 2299 |
g.drawLine(x + 1, y + 6, x + 1, y + h - 6);// left |
| 2300 |
for (int i = 0, j = 0; i < 4; i++, j = j + 2) {// top |
| 2301 |
g.drawLine(x + 1 + j, y + 5 - i, x + 2 + j, y + 5 - i); |
| 2302 |
} |
| 2303 |
} |
| 2304 |
|
| 2305 |
if (_unselectColor3 != null) { |
| 2306 |
g.setColor(_unselectColor3); |
| 2307 |
g.drawLine(x + 1, y + h - 5, x + 1, y + h - 5);// a point |
| 2308 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j = j + 2) {// bottom |
| 2309 |
g.drawLine(x + 2 + j, y + h - 4 + i, x + 3 + j, y + h - 4 + i); |
| 2310 |
} |
| 2311 |
} |
| 2312 |
} |
| 2313 |
} |
| 2314 |
break; |
| 2315 |
case RIGHT: |
| 2316 |
if (isSelected) { |
| 2317 |
g.setColor(_selectColor1); |
| 2318 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 5);// right |
| 2319 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// top |
| 2320 |
g.drawLine(x + w - 2 - j, y + 4 - i, x + w - 3 - j, y + 4 - i); |
| 2321 |
} |
| 2322 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2323 |
g.drawLine(x + w - 1 - j, y + h - 4 + i, x + w - 2 - j, y + h - 4 + i); |
| 2324 |
} |
| 2325 |
|
| 2326 |
if (_selectColor2 != null) { |
| 2327 |
g.setColor(_selectColor2); |
| 2328 |
g.drawLine(x + w - 2, y + 6, x + w - 2, y + h - 6);// right |
| 2329 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// top |
| 2330 |
g.drawLine(x + w - 2 - j, y + 5 - i, x + w - 3 - j, y + 5 - i); |
| 2331 |
} |
| 2332 |
} |
| 2333 |
|
| 2334 |
if (_selectColor3 != null) { |
| 2335 |
g.setColor(_selectColor3); |
| 2336 |
g.drawLine(x + w - 2, y + h - 5, x + w - 2, y + h - 5);// a point |
| 2337 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2338 |
g.drawLine(x + w - 3 - j, y + h - 4 + i, x + w - 4 - j, y + h - 4 + i); |
| 2339 |
} |
| 2340 |
} |
| 2341 |
} |
| 2342 |
else { |
| 2343 |
if (tabIndex == 0) { |
| 2344 |
g.setColor(_unselectColor1); |
| 2345 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 5);// right |
| 2346 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// top |
| 2347 |
g.drawLine(x + w - 2 - j, y + 4 - i, x + w - 3 - j, y + 4 - i); |
| 2348 |
} |
| 2349 |
|
| 2350 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2351 |
g.drawLine(x + w - 1 - j, y + h - 4 + i, x + w - 2 - j, y + h - 4 + i); |
| 2352 |
} |
| 2353 |
|
| 2354 |
if (_unselectColor2 != null) { |
| 2355 |
g.setColor(_unselectColor2); |
| 2356 |
g.drawLine(x + w - 2, y + 6, x + w - 2, y + h - 6);// right |
| 2357 |
|
| 2358 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// top |
| 2359 |
g.drawLine(x + w - 2 - j, y + 5 - i, x + w - 3 - j, y + 5 - i); |
| 2360 |
} |
| 2361 |
} |
| 2362 |
|
| 2363 |
if (_unselectColor3 != null) { |
| 2364 |
g.setColor(_unselectColor3); |
| 2365 |
|
| 2366 |
g.drawLine(x + w - 2, y + h - 5, x + w - 2, y + h - 5);// a |
| 2367 |
// point |
| 2368 |
|
| 2369 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2370 |
g.drawLine(x + w - 3 - j, y + h - 4 + i, x + w - 4 - j, y + h - 4 + i); |
| 2371 |
} |
| 2372 |
} |
| 2373 |
} |
| 2374 |
else if (tabIndex == _tabPane.getSelectedIndex() - 1) { |
| 2375 |
g.setColor(_unselectColor1); |
| 2376 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 5);// right |
| 2377 |
for (int i = 0, j = 0; i < 4; i++, j += 2) {// top |
| 2378 |
g.drawLine(x + w - 2 - j, y + 4 - i, x + w - 3 - j, y + 4 - i); |
| 2379 |
} |
| 2380 |
|
| 2381 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// bottom |
| 2382 |
g.drawLine(x + w - 1 - j, y + h - 4 + i, x + w - 2 - j, y + h - 4 + i); |
| 2383 |
} |
| 2384 |
|
| 2385 |
if (_unselectColor2 != null) { |
| 2386 |
g.setColor(_unselectColor2); |
| 2387 |
g.drawLine(x + w - 2, y + 6, x + w - 2, y + h - 6);// right |
| 2388 |
for (int i = 0, j = 0; i < 4; i++, j += 2) {// top |
| 2389 |
g.drawLine(x + w - 2 - j, y + 5 - i, x + w - 3 - j, y + 5 - i); |
| 2390 |
} |
| 2391 |
|
| 2392 |
} |
| 2393 |
|
| 2394 |
if (_unselectColor3 != null) { |
| 2395 |
g.setColor(_unselectColor3); |
| 2396 |
|
| 2397 |
g.drawLine(x + w - 2, y + h - 5, x + w - 2, y + h - 5);// a point |
| 2398 |
|
| 2399 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// bottom |
| 2400 |
g.drawLine(x + w - 3 - j, y + h - 4 + i, x + w - 4 - j, y + h - 4 + i); |
| 2401 |
} |
| 2402 |
} |
| 2403 |
} |
| 2404 |
else if (tabIndex != _tabPane.getSelectedIndex() - 1) { |
| 2405 |
g.setColor(_unselectColor1); |
| 2406 |
g.drawLine(x + w - 1, y + 5, x + w - 1, y + h - 5);// right |
| 2407 |
for (int i = 0, j = 0; i < 4; i++, j += 2) {// top |
| 2408 |
g.drawLine(x + w - 2 - j, y + 4 - i, x + w - 3 - j, y + 4 - i); |
| 2409 |
} |
| 2410 |
|
| 2411 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2412 |
g.drawLine(x + w - 1 - j, y + h - 4 + i, x + w - 2 - j, y + h - 4 + i); |
| 2413 |
} |
| 2414 |
|
| 2415 |
if (_unselectColor2 != null) { |
| 2416 |
g.setColor(_unselectColor2); |
| 2417 |
g.drawLine(x + w - 2, y + 6, x + w - 2, y + h - 6);// right |
| 2418 |
for (int i = 0, j = 0; i < 4; i++, j += 2) {// top |
| 2419 |
g.drawLine(x + w - 2 - j, y + 5 - i, x + w - 3 - j, y + 5 - i); |
| 2420 |
} |
| 2421 |
} |
| 2422 |
|
| 2423 |
if (_unselectColor3 != null) { |
| 2424 |
g.setColor(_unselectColor3); |
| 2425 |
g.drawLine(x + w - 2, y + h - 5, x + w - 2, y + h - 5);// a point |
| 2426 |
for (int i = 0, j = 0; i < w / 2 + 1; i++, j += 2) {// bottom |
| 2427 |
g.drawLine(x + w - 3 - j, y + h - 4 + i, x + w - 4 - j, y + h - 4 + i); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
} |
| 2431 |
} |
| 2432 |
break; |
| 2433 |
case BOTTOM: |
| 2434 |
if (isSelected) { |
| 2435 |
g.setColor(_selectColor1); |
| 2436 |
g.drawLine(x + 5, y + h - 1, x + w - 5, y + h - 1);// bottom |
| 2437 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2438 |
g.drawLine(x + 4 - i, y + h - 2 - j, x + 4 - i, y + h - 3 - j); |
| 2439 |
} |
| 2440 |
|
| 2441 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2442 |
g.drawLine(x + w - 4 - 1 + i, y + h - 1 - j, x + w - 4 - 1 + i, y + h - 2 - j); |
| 2443 |
} |
| 2444 |
|
| 2445 |
if (_selectColor2 != null) { |
| 2446 |
g.setColor(_selectColor2); |
| 2447 |
|
| 2448 |
g.drawLine(x + 5, y + h - 3, x + 5, y + h - 3);// bottom |
| 2449 |
|
| 2450 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2451 |
g.drawLine(x + 4 - i, y + h - 4 - j, x + 4 - i, y + h - 5 - j); |
| 2452 |
} |
| 2453 |
|
| 2454 |
} |
| 2455 |
|
| 2456 |
if (_selectColor3 != null) { |
| 2457 |
g.setColor(_selectColor3); |
| 2458 |
g.drawLine(x + 5, y + h - 2, x + w - 6, y + h - 2);// a point |
| 2459 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2460 |
g.drawLine(x + w - 5 + i, y + h - 3 - j, x + w - 5 + i, y + h - 4 - j); |
| 2461 |
} |
| 2462 |
} |
| 2463 |
} |
| 2464 |
else { |
| 2465 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 2466 |
g.setColor(_unselectColor1); |
| 2467 |
g.drawLine(x + 5, y + h - 1, x + w - 5, y + h - 1);// bottom |
| 2468 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2469 |
g.drawLine(x + 4 - i, y + h - 2 - j, x + 4 - i, y + h - 3 - j); |
| 2470 |
} |
| 2471 |
|
| 2472 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2473 |
g.drawLine(x + w - 4 - 1 + i, y + h - 1 - j, x + w - 4 - 1 + i, y + h - 2 - j); |
| 2474 |
} |
| 2475 |
|
| 2476 |
if (_unselectColor2 != null) { |
| 2477 |
g.setColor(_unselectColor2); |
| 2478 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2479 |
g.drawLine(x + 5 - i, y + h - 2 - j, x + 5 - i, y + h - 3 - j); |
| 2480 |
} |
| 2481 |
} |
| 2482 |
|
| 2483 |
if (_unselectColor3 != null) { |
| 2484 |
g.setColor(_unselectColor3); |
| 2485 |
g.drawLine(x + w - 6, y + h - 2, x + w - 6, y + h - 2);// a point |
| 2486 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2487 |
g.drawLine(x + w - 5 + i, y + h - 3 - j, x + w - 5 + i, y + h - 4 - j); |
| 2488 |
} |
| 2489 |
} |
| 2490 |
} |
| 2491 |
else if (tabIndex == _tabPane.getSelectedIndex() + (leftToRight ? -1 : 1)) { |
| 2492 |
g.setColor(_unselectColor1); |
| 2493 |
g.drawLine(x + 5, y + h - 1, x + w - 6, y + h - 1);// bottom |
| 2494 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2495 |
g.drawLine(x + 4 - i, y + h - 2 - j, x + 4 - i, y + h - 3 - j); |
| 2496 |
} |
| 2497 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// right |
| 2498 |
g.drawLine(x + w - 5 + i, y + h - 1 - j, x + w - 5 + i, y + h - 2 - j); |
| 2499 |
} |
| 2500 |
|
| 2501 |
if (_unselectColor2 != null) { |
| 2502 |
g.setColor(_unselectColor2); |
| 2503 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2504 |
g.drawLine(x + 5 - i, y + h - 2 - j, x + 5 - i, y + h - 3 - j); |
| 2505 |
} |
| 2506 |
} |
| 2507 |
|
| 2508 |
if (_unselectColor3 != null) { |
| 2509 |
g.setColor(_unselectColor3); |
| 2510 |
g.drawLine(x + w - 6, y + h - 2, x + w - 6, y + h - 2);// a point |
| 2511 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// right |
| 2512 |
g.drawLine(x + w - 5 + i, y + h - 3 - j, x + w - 5 + i, y + h - 4 - j); |
| 2513 |
} |
| 2514 |
} |
| 2515 |
} |
| 2516 |
else if (tabIndex != _tabPane.getSelectedIndex() + (leftToRight ? -1 : 1)) { |
| 2517 |
g.setColor(_unselectColor1); |
| 2518 |
g.drawLine(x + 5, y + h - 1, x + w - 6, y + h - 1);// bottom |
| 2519 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2520 |
g.drawLine(x + 4 - i, y + h - 2 - j, x + 4 - i, y + h - 3 - j); |
| 2521 |
} |
| 2522 |
|
| 2523 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2524 |
g.drawLine(x + w - 5 + i, y + h - 1 - j, x + w - 5 + i, y + h - 2 - j); |
| 2525 |
} |
| 2526 |
|
| 2527 |
if (_unselectColor2 != null) { |
| 2528 |
g.setColor(_unselectColor2); |
| 2529 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2530 |
g.drawLine(x + 5 - i, y + h - 2 - j, x + 5 - i, y + h - 3 - j); |
| 2531 |
} |
| 2532 |
} |
| 2533 |
|
| 2534 |
if (_unselectColor3 != null) { |
| 2535 |
g.setColor(_unselectColor3); |
| 2536 |
g.drawLine(x + w - 6, y + h - 2, x + w - 6, y + h - 2);// a point |
| 2537 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2538 |
g.drawLine(x + w - 5 + i, y + h - 3 - j, x + w - 5 + i, y + h - 4 - j); |
| 2539 |
} |
| 2540 |
} |
| 2541 |
} |
| 2542 |
} |
| 2543 |
break; |
| 2544 |
case TOP: |
| 2545 |
default: |
| 2546 |
if (isSelected) { |
| 2547 |
g.setColor(_selectColor1); |
| 2548 |
g.drawLine(x + 5, y, x + w - 5, y);// top |
| 2549 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2550 |
g.drawLine(x + 4 - i, y + 1 + j, x + 4 - i, y + 2 + j); |
| 2551 |
} |
| 2552 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2553 |
g.drawLine(x + w - 4 - 1 + i, y + j, x + w - 4 - 1 + i, y + 1 + j); |
| 2554 |
} |
| 2555 |
|
| 2556 |
if (_selectColor2 != null) { |
| 2557 |
g.setColor(_selectColor2); |
| 2558 |
g.drawLine(x + 6, y + 1, x + w - 7, y + 1);// top |
| 2559 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2560 |
g.drawLine(x + 5 - i, y + 1 + j, x + 5 - i, y + 2 + j); |
| 2561 |
} |
| 2562 |
} |
| 2563 |
|
| 2564 |
if (_selectColor3 != null) { |
| 2565 |
g.setColor(_selectColor3); |
| 2566 |
g.drawLine(x + w - 6, y + 1, x + w - 6, y + 1);// a point |
| 2567 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2568 |
g.drawLine(x + w - 5 + i, y + 2 + j, x + w - 5 + i, y + 3 + j); |
| 2569 |
} |
| 2570 |
} |
| 2571 |
} |
| 2572 |
else { |
| 2573 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 2574 |
g.setColor(_unselectColor1); |
| 2575 |
g.drawLine(x + 5, y, x + w - 5, y);// top |
| 2576 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2577 |
g.drawLine(x + 4 - i, y + 1 + j, x + 4 - i, y + 2 + j); |
| 2578 |
} |
| 2579 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2580 |
g.drawLine(x + w - 4 - 1 + i, y + j, x + w - 4 - 1 + i, y + 1 + j); |
| 2581 |
} |
| 2582 |
if (_unselectColor2 != null) { |
| 2583 |
g.setColor(_unselectColor2); |
| 2584 |
g.drawLine(x + 6, y + 1, x + w - 7, y + 1);// top |
| 2585 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// left |
| 2586 |
g.drawLine(x + 5 - i, y + 1 + j, x + 5 - i, y + 2 + j); |
| 2587 |
} |
| 2588 |
} |
| 2589 |
if (_unselectColor3 != null) { |
| 2590 |
g.setColor(_unselectColor3); |
| 2591 |
g.drawLine(x + w - 6, y + 1, x + w - 6, y + 1);// a point |
| 2592 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2593 |
g.drawLine(x + w - 5 + i, y + 2 + j, x + w - 5 + i, y + 3 + j); |
| 2594 |
} |
| 2595 |
} |
| 2596 |
} |
| 2597 |
else if (tabIndex == _tabPane.getSelectedIndex() + (leftToRight ? -1 : 1)) { |
| 2598 |
g.setColor(_unselectColor1); |
| 2599 |
g.drawLine(x + 5, y, x + w - 5, y);// top |
| 2600 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2601 |
g.drawLine(x + 4 - i, y + 1 + j, x + 4 - i, y + 2 + j); |
| 2602 |
} |
| 2603 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// right |
| 2604 |
g.drawLine(x + w - 4 - 1 + i, y + j, x + w - 4 - 1 + i, y + 1 + j); |
| 2605 |
} |
| 2606 |
|
| 2607 |
if (_unselectColor2 != null) { |
| 2608 |
g.setColor(_unselectColor2); |
| 2609 |
g.drawLine(x + 6, y + 1, x + w - 7, y + 1);// top |
| 2610 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2611 |
g.drawLine(x + 5 - i, y + 1 + j, x + 5 - i, y + 2 + j); |
| 2612 |
} |
| 2613 |
} |
| 2614 |
if (_unselectColor3 != null) { |
| 2615 |
g.setColor(_unselectColor3); |
| 2616 |
g.drawLine(x + w - 6, y + 1, x + w - 6, y + 1);// a point |
| 2617 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// right |
| 2618 |
g.drawLine(x + w - 5 + i, y + 2 + j, x + w - 5 + i, y + 3 + j); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
} |
| 2622 |
else if (tabIndex != _tabPane.getSelectedIndex() + (leftToRight ? -1 : 1)) { |
| 2623 |
g.setColor(_unselectColor1); |
| 2624 |
g.drawLine(x + 5, y, x + w - 5, y);// top |
| 2625 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2626 |
g.drawLine(x + 4 - i, y + 1 + j, x + 4 - i, y + 2 + j); |
| 2627 |
} |
| 2628 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2629 |
g.drawLine(x + w - 4 - 1 + i, y + j, x + w - 4 - 1 + i, y + 1 + j); |
| 2630 |
} |
| 2631 |
if (_unselectColor2 != null) { |
| 2632 |
g.setColor(_unselectColor2); |
| 2633 |
g.drawLine(x + 6, y + 1, x + w - 7, y + 1);// top |
| 2634 |
for (int i = 0, j = 0; i < 5; i++, j += 2) {// left |
| 2635 |
g.drawLine(x + 5 - i, y + 1 + j, x + 5 - i, y + 2 + j); |
| 2636 |
} |
| 2637 |
} |
| 2638 |
|
| 2639 |
if (_unselectColor3 != null) { |
| 2640 |
g.setColor(_unselectColor3); |
| 2641 |
g.drawLine(x + w - 6, y + 1, x + w - 6, y + 1);// a point |
| 2642 |
for (int i = 0, j = 0; i < h / 2 + 1; i++, j += 2) {// right |
| 2643 |
g.drawLine(x + w - 5 + i, y + 2 + j, x + w - 5 + i, y + 3 + j); |
| 2644 |
} |
| 2645 |
} |
| 2646 |
} |
| 2647 |
} |
| 2648 |
} |
| 2649 |
} |
| 2650 |
|
| 2651 |
|
| 2652 |
protected void paintWindowsTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 2653 |
int x, int y, int w, int h, boolean isSelected) { |
| 2654 |
int colorTheme = getColorTheme(); |
| 2655 |
switch (tabPlacement) { |
| 2656 |
case LEFT: |
| 2657 |
if (colorTheme == JideTabbedPane.COLOR_THEME_OFFICE2003 || colorTheme == JideTabbedPane.COLOR_THEME_WIN2K) { |
| 2658 |
if (isSelected) { |
| 2659 |
g.setColor(_selectColor1); |
| 2660 |
g.drawLine(x - 2, y + 1, x - 2, y + h - 1);// left |
| 2661 |
g.drawLine(x - 1, y, x - 1, y);// top arc |
| 2662 |
g.drawLine(x, y - 1, x + w - 1, y - 1);// top |
| 2663 |
|
| 2664 |
g.setColor(_selectColor2); |
| 2665 |
g.drawLine(x - 1, y + h, x - 1, y + h);// bottom arc |
| 2666 |
g.drawLine(x, y + h + 1, x, y + h + 1);// bottom arc |
| 2667 |
g.drawLine(x + 1, y + h, x + w - 1, y + h);// bottom |
| 2668 |
|
| 2669 |
g.setColor(_selectColor3); |
| 2670 |
g.drawLine(x, y + h, x, y + h);// bottom arc |
| 2671 |
g.drawLine(x + 1, y + h + 1, x + w - 1, y + h + 1);// bottom |
| 2672 |
} |
| 2673 |
else { |
| 2674 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2675 |
g.setColor(_unselectColor1); |
| 2676 |
g.drawLine(x, y + 2, x, y + h - 3);// left |
| 2677 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// top arc |
| 2678 |
g.drawLine(x + 2, y, x + w - 1, y);// top |
| 2679 |
|
| 2680 |
g.setColor(_unselectColor2); |
| 2681 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);// bottom arc |
| 2682 |
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);// bottom arc |
| 2683 |
g.drawLine(x + 3, y + h - 2, x + w - 1, y + h - 2);// bottom |
| 2684 |
|
| 2685 |
g.setColor(_unselectColor3); |
| 2686 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2);// bottom arc |
| 2687 |
g.drawLine(x + 3, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 2688 |
} |
| 2689 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2690 |
g.setColor(_unselectColor1); |
| 2691 |
g.drawLine(x, y + 3, x, y + h - 2);// left |
| 2692 |
g.drawLine(x + 1, y + 2, x + 1, y + 2);// top arc |
| 2693 |
g.drawLine(x + 2, y + 1, x + w - 1, y + 1);// top |
| 2694 |
|
| 2695 |
g.setColor(_unselectColor2); |
| 2696 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);// bottom arc |
| 2697 |
g.drawLine(x + 2, y + h, x + 2, y + h);// bottom arc |
| 2698 |
g.drawLine(x + 3, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 2699 |
|
| 2700 |
g.setColor(_unselectColor3); |
| 2701 |
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);// bottom arc |
| 2702 |
g.drawLine(x + 3, y + h, x + w - 1, y + h);// bottom |
| 2703 |
} |
| 2704 |
} |
| 2705 |
} |
| 2706 |
else { |
| 2707 |
if (isSelected) { |
| 2708 |
g.setColor(_selectColor1); |
| 2709 |
g.drawLine(x - 2, y + 1, x - 2, y + h - 1);// left |
| 2710 |
g.drawLine(x - 1, y, x - 1, y);// top arc |
| 2711 |
g.drawLine(x, y - 1, x, y - 1);// top arc |
| 2712 |
g.drawLine(x - 1, y + h, x - 1, y + h);// bottom arc |
| 2713 |
g.drawLine(x, y + h + 1, x, y + h + 1);// bottom arc |
| 2714 |
|
| 2715 |
g.setColor(_selectColor2); |
| 2716 |
g.drawLine(x - 1, y + 1, x - 1, y + h - 1);// left |
| 2717 |
g.drawLine(x, y, x, y + h);// left |
| 2718 |
|
| 2719 |
g.setColor(_selectColor3); |
| 2720 |
g.drawLine(x + 1, y - 2, x + w - 1, y - 2);// top |
| 2721 |
g.drawLine(x + 1, y + h + 2, x + w - 1, y + h + 2);// bottom |
| 2722 |
} |
| 2723 |
else { |
| 2724 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2725 |
g.setColor(_unselectColor1); |
| 2726 |
g.drawLine(x, y + 2, x, y + h - 4);// left |
| 2727 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// top arc |
| 2728 |
g.drawLine(x + 2, y, x + w - 1, y);// top |
| 2729 |
g.drawLine(x + 1, y + h - 3, x + 1, y + h - 3);// bottom arc |
| 2730 |
g.drawLine(x + 2, y + h - 2, x + w - 1, y + h - 2);// bottom |
| 2731 |
} |
| 2732 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2733 |
g.setColor(_unselectColor1); |
| 2734 |
g.drawLine(x, y + 4, x, y + h - 2);// left |
| 2735 |
g.drawLine(x + 1, y + 3, x + 1, y + 3);// top arc |
| 2736 |
g.drawLine(x + 2, y + 2, x + w - 1, y + 2);// top |
| 2737 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);// bottom arc |
| 2738 |
g.drawLine(x + 2, y + h, x + w - 1, y + h);// bottom |
| 2739 |
} |
| 2740 |
} |
| 2741 |
} |
| 2742 |
break; |
| 2743 |
case RIGHT: |
| 2744 |
if (colorTheme == JideTabbedPane.COLOR_THEME_OFFICE2003 || colorTheme == JideTabbedPane.COLOR_THEME_WIN2K) { |
| 2745 |
if (isSelected) { |
| 2746 |
g.setColor(_selectColor1); |
| 2747 |
g.drawLine(x + w - 1, y - 1, x, y - 1);// top |
| 2748 |
|
| 2749 |
g.setColor(_selectColor2); |
| 2750 |
g.drawLine(x + w, y + 1, x + w, y + h - 1);// right |
| 2751 |
g.drawLine(x + w - 1, y + h, x, y + h);// bottom |
| 2752 |
|
| 2753 |
g.setColor(_selectColor3); |
| 2754 |
g.drawLine(x + w, y, x + w, y);// top arc |
| 2755 |
g.drawLine(x + w + 1, y + 1, x + w + 1, y + h - 1);// right |
| 2756 |
g.drawLine(x + w, y + h, x + w, y + h);// bottom arc |
| 2757 |
g.drawLine(x + w - 1, y + h + 1, x, y + h + 1);// bottom |
| 2758 |
} |
| 2759 |
else { |
| 2760 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2761 |
g.setColor(_unselectColor1); |
| 2762 |
g.drawLine(x + w - 3, y, x, y);// top |
| 2763 |
|
| 2764 |
g.setColor(_unselectColor2); |
| 2765 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3);// right |
| 2766 |
g.drawLine(x + w - 3, y + h - 2, x, y + h - 2);// bottom |
| 2767 |
|
| 2768 |
g.setColor(_unselectColor3); |
| 2769 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// top arc |
| 2770 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);// right |
| 2771 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// bottom arc |
| 2772 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 2773 |
} |
| 2774 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2775 |
g.setColor(_unselectColor1); |
| 2776 |
g.drawLine(x + w - 3, y + 1, x, y + 1);// top |
| 2777 |
|
| 2778 |
g.setColor(_unselectColor2); |
| 2779 |
g.drawLine(x + w - 2, y + 3, x + w - 2, y + h - 2);// right |
| 2780 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 2781 |
|
| 2782 |
g.setColor(_unselectColor3); |
| 2783 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);// top arc |
| 2784 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + h - 2);// right |
| 2785 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);// bottom arc |
| 2786 |
g.drawLine(x + w - 3, y + h, x, y + h);// bottom |
| 2787 |
} |
| 2788 |
} |
| 2789 |
} |
| 2790 |
else { |
| 2791 |
if (isSelected) { |
| 2792 |
g.setColor(_selectColor1); |
| 2793 |
g.drawLine(x + w + 1, y + 1, x + w + 1, y + h - 1);// right |
| 2794 |
g.drawLine(x + w, y, x + w, y);// top arc |
| 2795 |
g.drawLine(x + w - 1, y - 1, x + w - 1, y - 1);// top arc |
| 2796 |
g.drawLine(x + w, y + h, x + w, y + h);// bottom arc |
| 2797 |
g.drawLine(x + w - 1, y + h + 1, x + w - 1, y + h + 1);// bottom arc |
| 2798 |
|
| 2799 |
g.setColor(_selectColor2); |
| 2800 |
g.drawLine(x + w, y + 1, x + w, y + h - 1);// right |
| 2801 |
g.drawLine(x + w - 1, y, x + w - 1, y + h);// right |
| 2802 |
|
| 2803 |
g.setColor(_selectColor3); |
| 2804 |
g.drawLine(x + w - 2, y - 2, x, y - 2);// top |
| 2805 |
g.drawLine(x + w - 2, y + h + 2, x, y + h + 2);// bottom |
| 2806 |
} |
| 2807 |
else { |
| 2808 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2809 |
g.setColor(_unselectColor1); |
| 2810 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 4);// right |
| 2811 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// top arc |
| 2812 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y + h - 3);// bottom arc |
| 2813 |
g.drawLine(x + w - 3, y, x, y);// top |
| 2814 |
g.drawLine(x + w - 3, y + h - 2, x, y + h - 2);// bottom |
| 2815 |
} |
| 2816 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2817 |
g.setColor(_unselectColor1); |
| 2818 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + h - 2);// right |
| 2819 |
g.drawLine(x + w - 2, y + 3, x + w - 2, y + 3);// top arc |
| 2820 |
g.drawLine(x + w - 3, y + 2, x, y + 2);// top |
| 2821 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);// bottom arc |
| 2822 |
g.drawLine(x + w - 3, y + h, x, y + h);// bottom |
| 2823 |
} |
| 2824 |
} |
| 2825 |
} |
| 2826 |
break; |
| 2827 |
case BOTTOM: |
| 2828 |
if (colorTheme == JideTabbedPane.COLOR_THEME_OFFICE2003 || colorTheme == JideTabbedPane.COLOR_THEME_WIN2K) { |
| 2829 |
if (isSelected) { |
| 2830 |
g.setColor(_selectColor1); |
| 2831 |
g.drawLine(x, y + h, x, y + h);// left arc |
| 2832 |
g.drawLine(x - 1, y + h - 1, x - 1, y);// left |
| 2833 |
|
| 2834 |
g.setColor(_selectColor2); |
| 2835 |
g.drawLine(x + 1, y + h, x + w - 2, y + h);// bottom |
| 2836 |
g.drawLine(x + w - 1, y + h - 1, x + w - 1, y - 1);// right |
| 2837 |
|
| 2838 |
g.setColor(_selectColor3); |
| 2839 |
g.drawLine(x + 1, y + h + 1, x + w - 2, y + h + 1);// bottom |
| 2840 |
g.drawLine(x + w - 1, y + h, x + w - 1, y + h);// right arc |
| 2841 |
g.drawLine(x + w, y + h - 1, x + w, y - 1);// right |
| 2842 |
} |
| 2843 |
else { |
| 2844 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2845 |
g.setColor(_unselectColor1); |
| 2846 |
g.drawLine(x, y + h - 2, x, y + h - 2);// left arc |
| 2847 |
g.drawLine(x - 1, y + h - 3, x - 1, y);// left |
| 2848 |
|
| 2849 |
g.setColor(_unselectColor2); |
| 2850 |
g.drawLine(x + 1, y + h - 2, x + w - 4, y + h - 2);// bottom |
| 2851 |
g.drawLine(x + w - 3, y + h - 3, x + w - 3, y - 1);// right |
| 2852 |
|
| 2853 |
g.setColor(_unselectColor3); |
| 2854 |
g.drawLine(x + 1, y + h - 1, x + w - 4, y + h - 1);// bottom |
| 2855 |
g.drawLine(x + w - 3, y + h - 2, x + w - 3, y + h - 2);// right arc |
| 2856 |
g.drawLine(x + w - 2, y + h - 3, x + w - 2, y - 1);// right |
| 2857 |
} |
| 2858 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2859 |
g.setColor(_unselectColor1); |
| 2860 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2);// left arc |
| 2861 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left |
| 2862 |
|
| 2863 |
g.setColor(_unselectColor2); |
| 2864 |
g.drawLine(x + 3, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 2865 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y);// right |
| 2866 |
|
| 2867 |
g.setColor(_unselectColor3); |
| 2868 |
g.drawLine(x + 3, y + h - 1, x + w - 2, y + h - 1);// bottom |
| 2869 |
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);// right arc |
| 2870 |
g.drawLine(x + w, y + h - 3, x + w, y);// right |
| 2871 |
} |
| 2872 |
} |
| 2873 |
} |
| 2874 |
else { |
| 2875 |
if (isSelected) { |
| 2876 |
g.setColor(_selectColor1); |
| 2877 |
g.drawLine(x + 1, y + h + 1, x + w, y + h + 1);// bottom |
| 2878 |
g.drawLine(x, y + h, x, y + h);// right arc |
| 2879 |
g.drawLine(x - 1, y + h - 1, x - 1, y + h - 1);// right arc |
| 2880 |
g.drawLine(x + w + 1, y + h, x + w + 1, y + h);// left arc |
| 2881 |
g.drawLine(x + w + 2, y + h - 1, x + w + 2, y + h - 1);// left arc |
| 2882 |
|
| 2883 |
g.setColor(_selectColor2); |
| 2884 |
g.drawLine(x + 1, y + h, x + w, y + h);// bottom |
| 2885 |
g.drawLine(x, y + h - 1, x + w + 1, y + h - 1);// bottom |
| 2886 |
|
| 2887 |
g.setColor(_selectColor3); |
| 2888 |
g.drawLine(x - 1, y + h - 2, x - 1, y);// left |
| 2889 |
g.drawLine(x + w + 2, y + h - 2, x + w + 2, y);// right |
| 2890 |
} |
| 2891 |
else { |
| 2892 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2893 |
g.setColor(_unselectColor1); |
| 2894 |
g.drawLine(x + 3, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 2895 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// right arc |
| 2896 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y - 1);// right |
| 2897 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2);// left arc |
| 2898 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left |
| 2899 |
} |
| 2900 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2901 |
g.setColor(_unselectColor1); |
| 2902 |
g.drawLine(x + 3, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 2903 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// right arc |
| 2904 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y - 1);// right |
| 2905 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2);// left arc |
| 2906 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left |
| 2907 |
} |
| 2908 |
} |
| 2909 |
} |
| 2910 |
break; |
| 2911 |
case TOP: |
| 2912 |
default: |
| 2913 |
if (colorTheme == JideTabbedPane.COLOR_THEME_OFFICE2003 || colorTheme == JideTabbedPane.COLOR_THEME_WIN2K) { |
| 2914 |
if (isSelected) { |
| 2915 |
g.setColor(_selectColor1); |
| 2916 |
g.drawLine(x, y - 1, x, y - 1); // left arc |
| 2917 |
g.drawLine(x - 1, y, x - 1, y + h - 1);// left |
| 2918 |
g.drawLine(x + 1, y - 2, x + w + 1, y - 2);// top |
| 2919 |
|
| 2920 |
g.setColor(_selectColor2); |
| 2921 |
g.drawLine(x + w + 2, y - 1, x + w + 2, y + h - 1);// right |
| 2922 |
|
| 2923 |
g.setColor(_selectColor3); |
| 2924 |
g.drawLine(x + w + 2, y - 1, x + w + 2, y - 1);// right arc |
| 2925 |
g.drawLine(x + w + 3, y, x + w + 3, y + h - 1);// right |
| 2926 |
} |
| 2927 |
else { |
| 2928 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2929 |
g.setColor(_unselectColor1); |
| 2930 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); // left arc |
| 2931 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1); // left |
| 2932 |
g.drawLine(x + 3, y, x + w - 2, y); // top |
| 2933 |
|
| 2934 |
g.setColor(_unselectColor2); |
| 2935 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);// right |
| 2936 |
|
| 2937 |
g.setColor(_unselectColor3); |
| 2938 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);// right arc |
| 2939 |
g.drawLine(x + w, y + 2, x + w, y + h - 1);// right |
| 2940 |
} |
| 2941 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2942 |
g.setColor(_unselectColor1); |
| 2943 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); // left arc |
| 2944 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1); // left |
| 2945 |
g.drawLine(x + 3, y, x + w - 2, y); // top |
| 2946 |
|
| 2947 |
g.setColor(_unselectColor2); |
| 2948 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);// right |
| 2949 |
|
| 2950 |
g.setColor(_unselectColor3); |
| 2951 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);// right arc |
| 2952 |
g.drawLine(x + w, y + 2, x + w, y + h - 1);// right |
| 2953 |
} |
| 2954 |
} |
| 2955 |
} |
| 2956 |
else { |
| 2957 |
if (isSelected) { |
| 2958 |
g.setColor(_selectColor1); |
| 2959 |
g.drawLine(x + 1, y - 2, x + w, y - 2); // top |
| 2960 |
g.drawLine(x, y - 1, x, y - 1); // left arc |
| 2961 |
g.drawLine(x - 1, y, x - 1, y); // left arc |
| 2962 |
g.drawLine(x + w + 1, y - 1, x + w + 1, y - 1);// right arc |
| 2963 |
g.drawLine(x + w + 2, y, x + w + 2, y);// right arc |
| 2964 |
|
| 2965 |
g.setColor(_selectColor2); |
| 2966 |
g.drawLine(x + 1, y - 1, x + w, y - 1);// top |
| 2967 |
g.drawLine(x, y, x + w + 1, y);// top |
| 2968 |
|
| 2969 |
g.setColor(_selectColor3); |
| 2970 |
g.drawLine(x - 1, y + 1, x - 1, y + h - 1);// left |
| 2971 |
g.drawLine(x + w + 2, y + 1, x + w + 2, y + h - 1);// right |
| 2972 |
} |
| 2973 |
else { |
| 2974 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 2975 |
g.setColor(_unselectColor1); |
| 2976 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1); // left |
| 2977 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); // left arc |
| 2978 |
g.drawLine(x + 3, y, x + w - 3, y); // top |
| 2979 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// right arc |
| 2980 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);// right |
| 2981 |
} |
| 2982 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 2983 |
g.setColor(_unselectColor1); |
| 2984 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1); // left |
| 2985 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); // left arc |
| 2986 |
g.drawLine(x + 3, y, x + w - 3, y); // top |
| 2987 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// right arc |
| 2988 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);// right |
| 2989 |
} |
| 2990 |
} |
| 2991 |
} |
| 2992 |
} |
| 2993 |
} |
| 2994 |
|
| 2995 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 2996 |
protected void paintTabBorderMouseOver(Graphics g, int tabPlacement, int tabIndex, |
| 2997 |
int x, int y, int w, int h, boolean isSelected) { |
| 2998 |
if (getTabShape() == JideTabbedPane.SHAPE_WINDOWS) { |
| 2999 |
switch (tabPlacement) { |
| 3000 |
case LEFT: |
| 3001 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3002 |
y = y - 2; |
| 3003 |
} |
| 3004 |
|
| 3005 |
g.setColor(_selectColor1); |
| 3006 |
g.drawLine(x, y + 4, x, y + h - 2); |
| 3007 |
g.drawLine(x + 1, y + 3, x + 1, y + 3); |
| 3008 |
g.drawLine(x + 2, y + 2, x + 2, y + 2); |
| 3009 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3010 |
g.drawLine(x + 2, y + h, x + 2, y + h); |
| 3011 |
|
| 3012 |
g.setColor(_selectColor2); |
| 3013 |
g.drawLine(x + 1, y + 4, x + 1, y + h - 2); |
| 3014 |
g.drawLine(x + 2, y + 3, x + 2, y + h - 1); |
| 3015 |
break; |
| 3016 |
case RIGHT: |
| 3017 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3018 |
y = y - 2; |
| 3019 |
} |
| 3020 |
|
| 3021 |
g.setColor(_selectColor1); |
| 3022 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + h - 2); |
| 3023 |
g.drawLine(x + w - 2, y + 3, x + w - 2, y + 3); |
| 3024 |
g.drawLine(x + w - 3, y + 2, x + w - 3, y + 2); |
| 3025 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3026 |
g.drawLine(x + w - 3, y + h, x + w - 3, y + h); |
| 3027 |
|
| 3028 |
g.setColor(_selectColor2); |
| 3029 |
g.drawLine(x + w - 2, y + 4, x + w - 2, y + h - 2); |
| 3030 |
g.drawLine(x + w - 3, y + 3, x + w - 3, y + h - 1); |
| 3031 |
break; |
| 3032 |
case BOTTOM: |
| 3033 |
g.setColor(_selectColor1); |
| 3034 |
g.drawLine(x + 3, y + h - 1, x + w - 3, y + h - 1); |
| 3035 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2); |
| 3036 |
g.drawLine(x + 1, y + h - 3, x + 1, y + h - 3); |
| 3037 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); |
| 3038 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y + h - 3); |
| 3039 |
|
| 3040 |
g.setColor(_selectColor2); |
| 3041 |
g.drawLine(x + 3, y + h - 2, x + w - 3, y + h - 2); |
| 3042 |
g.drawLine(x + 2, y + h - 3, x + w - 2, y + h - 3); |
| 3043 |
break; |
| 3044 |
case TOP: |
| 3045 |
default: |
| 3046 |
g.setColor(_selectColor1); |
| 3047 |
g.drawLine(x + 3, y, x + w - 3, y); |
| 3048 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); |
| 3049 |
g.drawLine(x + 1, y + 2, x + 1, y + 2); |
| 3050 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
| 3051 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + 2); |
| 3052 |
|
| 3053 |
g.setColor(_selectColor2); |
| 3054 |
g.drawLine(x + 3, y + 1, x + w - 3, y + 1); |
| 3055 |
g.drawLine(x + 2, y + 2, x + w - 2, y + 2); |
| 3056 |
} |
| 3057 |
} |
| 3058 |
else if (getTabShape() == JideTabbedPane.SHAPE_WINDOWS_SELECTED) { |
| 3059 |
switch (tabPlacement) { |
| 3060 |
case LEFT: |
| 3061 |
if (getColorTheme() == JideTabbedPane.COLOR_THEME_WINXP) { |
| 3062 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3063 |
y -= 2; |
| 3064 |
} |
| 3065 |
|
| 3066 |
g.setColor(_selectColor1); |
| 3067 |
g.drawLine(x, y + 4, x, y + h - 2); |
| 3068 |
g.drawLine(x + 1, y + 3, x + 1, y + 3); |
| 3069 |
g.drawLine(x + 2, y + 2, x + 2, y + 2); |
| 3070 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3071 |
g.drawLine(x + 2, y + h, x + 2, y + h); |
| 3072 |
|
| 3073 |
g.setColor(_selectColor2); |
| 3074 |
g.drawLine(x + 1, y + 4, x + 1, y + h - 2); |
| 3075 |
g.drawLine(x + 2, y + 3, x + 2, y + h - 1); |
| 3076 |
|
| 3077 |
g.setColor(_selectColor3); |
| 3078 |
g.drawLine(x + 3, y + 2, x + w - 1, y + 2); |
| 3079 |
g.drawLine(x + 3, y + h, x + w - 1, y + h); |
| 3080 |
} |
| 3081 |
else { |
| 3082 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3083 |
y = y - 1; |
| 3084 |
} |
| 3085 |
g.setColor(_selectColor1); |
| 3086 |
g.drawLine(x, y + 3, x, y + h - 2);// left |
| 3087 |
g.drawLine(x + 1, y + 2, x + 1, y + 2);// top arc |
| 3088 |
g.drawLine(x + 2, y + 1, x + w - 1, y + 1);// top |
| 3089 |
|
| 3090 |
g.setColor(_selectColor2); |
| 3091 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);// bottom arc |
| 3092 |
g.drawLine(x + 2, y + h, x + 2, y + h);// bottom arc |
| 3093 |
g.drawLine(x + 3, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 3094 |
|
| 3095 |
g.setColor(_selectColor3); |
| 3096 |
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);// bottom arc |
| 3097 |
g.drawLine(x + 3, y + h, x + w - 1, y + h);// bottom |
| 3098 |
} |
| 3099 |
break; |
| 3100 |
case RIGHT: |
| 3101 |
if (getColorTheme() == JideTabbedPane.COLOR_THEME_WINXP) { |
| 3102 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3103 |
y = y - 2; |
| 3104 |
} |
| 3105 |
|
| 3106 |
g.setColor(_selectColor1); |
| 3107 |
g.drawLine(x + w - 1, y + 4, x + w - 1, y + h - 2); |
| 3108 |
g.drawLine(x + w - 2, y + 3, x + w - 2, y + 3); |
| 3109 |
g.drawLine(x + w - 3, y + 2, x + w - 3, y + 2); |
| 3110 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3111 |
g.drawLine(x + w - 3, y + h, x + w - 3, y + h); |
| 3112 |
|
| 3113 |
g.setColor(_selectColor2); |
| 3114 |
g.drawLine(x + w - 2, y + 4, x + w - 2, y + h - 2); |
| 3115 |
g.drawLine(x + w - 3, y + 3, x + w - 3, y + h - 1); |
| 3116 |
|
| 3117 |
g.setColor(_selectColor3); |
| 3118 |
g.drawLine(x + w - 4, y + 2, x, y + 2); |
| 3119 |
g.drawLine(x + w - 4, y + h, x, y + h); |
| 3120 |
} |
| 3121 |
else { |
| 3122 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3123 |
y = y - 1; |
| 3124 |
} |
| 3125 |
|
| 3126 |
g.setColor(_selectColor3); |
| 3127 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + h - 2);// right |
| 3128 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);// bottom arc |
| 3129 |
g.drawLine(x + w - 3, y + h, x, y + h);// bottom |
| 3130 |
|
| 3131 |
g.setColor(_selectColor2); |
| 3132 |
g.drawLine(x + w - 2, y + 3, x + w - 2, y + h - 2);// right |
| 3133 |
g.drawLine(x + w - 3, y + h - 1, x, y + h - 1);// bottom |
| 3134 |
|
| 3135 |
g.setColor(_selectColor1); |
| 3136 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);// top arc |
| 3137 |
g.drawLine(x + w - 3, y + 1, x, y + 1);// top |
| 3138 |
} |
| 3139 |
break; |
| 3140 |
case BOTTOM: |
| 3141 |
if (getColorTheme() == JideTabbedPane.COLOR_THEME_WINXP) { |
| 3142 |
g.setColor(_selectColor1); |
| 3143 |
g.drawLine(x + 3, y + h - 1, x + w - 3, y + h - 1); |
| 3144 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2); |
| 3145 |
g.drawLine(x + 1, y + h - 3, x + 1, y + h - 3); |
| 3146 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); |
| 3147 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y + h - 3); |
| 3148 |
|
| 3149 |
g.setColor(_selectColor2); |
| 3150 |
g.drawLine(x + 3, y + h - 2, x + w - 3, y + h - 2); |
| 3151 |
g.drawLine(x + 2, y + h - 3, x + w - 2, y + h - 3); |
| 3152 |
|
| 3153 |
g.setColor(_selectColor3); |
| 3154 |
g.drawLine(x + 1, y, x + 1, y + h - 4); // left |
| 3155 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 4);// right |
| 3156 |
} |
| 3157 |
else { |
| 3158 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3159 |
x = x - 2; |
| 3160 |
} |
| 3161 |
|
| 3162 |
g.setColor(_selectColor3); |
| 3163 |
g.drawLine(x + 3, y + h - 1, x + w - 2, y + h - 1);// bottom |
| 3164 |
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);// right arc |
| 3165 |
g.drawLine(x + w, y + h - 3, x + w, y);// right |
| 3166 |
|
| 3167 |
g.setColor(_selectColor1); |
| 3168 |
g.drawLine(x + 2, y + h - 2, x + 2, y + h - 2);// left |
| 3169 |
g.drawLine(x + 1, y + h - 3, x + 1, y);// left arc |
| 3170 |
|
| 3171 |
g.setColor(_selectColor2); |
| 3172 |
g.drawLine(x + 3, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 3173 |
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y);// right |
| 3174 |
} |
| 3175 |
break; |
| 3176 |
case TOP: |
| 3177 |
default: |
| 3178 |
if (getColorTheme() == JideTabbedPane.COLOR_THEME_WINXP) { |
| 3179 |
g.setColor(_selectColor1); |
| 3180 |
g.drawLine(x + 3, y, x + w - 3, y); |
| 3181 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); |
| 3182 |
g.drawLine(x + 1, y + 2, x + 1, y + 2); |
| 3183 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
| 3184 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + 2); |
| 3185 |
|
| 3186 |
g.setColor(_selectColor2); |
| 3187 |
g.drawLine(x + 3, y + 1, x + w - 3, y + 1); |
| 3188 |
g.drawLine(x + 2, y + 2, x + w - 2, y + 2); |
| 3189 |
|
| 3190 |
g.setColor(_selectColor3); |
| 3191 |
g.drawLine(x + 1, y + 3, x + 1, y + h - 1); // left |
| 3192 |
g.drawLine(x + w - 1, y + 3, x + w - 1, y + h - 1);// right |
| 3193 |
} |
| 3194 |
else { |
| 3195 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3196 |
x = x - 1; |
| 3197 |
} |
| 3198 |
g.setColor(_selectColor1); |
| 3199 |
g.drawLine(x + 2, y + 1, x + 2, y + 1); // left arc |
| 3200 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 1); // left |
| 3201 |
g.drawLine(x + 3, y, x + w - 2, y); // top |
| 3202 |
|
| 3203 |
g.setColor(_selectColor2); |
| 3204 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);// right |
| 3205 |
|
| 3206 |
g.setColor(_selectColor3); |
| 3207 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);// right arc |
| 3208 |
g.drawLine(x + w, y + 2, x + w, y + h - 1);// right |
| 3209 |
} |
| 3210 |
} |
| 3211 |
|
| 3212 |
} |
| 3213 |
} |
| 3214 |
|
| 3215 |
protected void paintVsnetTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 3216 |
int x, int y, int w, int h, boolean isSelected) { |
| 3217 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 3218 |
switch (tabPlacement) { |
| 3219 |
case LEFT: |
| 3220 |
if (isSelected) { |
| 3221 |
g.setColor(_selectColor1); |
| 3222 |
g.drawLine(x, y, x + w - 1, y);// top |
| 3223 |
g.drawLine(x, y, x, y + h - 2);// left |
| 3224 |
|
| 3225 |
g.setColor(_selectColor2); |
| 3226 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 3227 |
} |
| 3228 |
else { |
| 3229 |
g.setColor(_unselectColor1); |
| 3230 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3231 |
g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 3232 |
} |
| 3233 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3234 |
g.drawLine(x + 2, y, x + w - 2, y);// top |
| 3235 |
} |
| 3236 |
} |
| 3237 |
break; |
| 3238 |
case RIGHT: |
| 3239 |
if (isSelected) { |
| 3240 |
g.setColor(_selectColor1); |
| 3241 |
g.drawLine(x, y, x + w - 1, y);// top |
| 3242 |
|
| 3243 |
g.setColor(_selectColor2); |
| 3244 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 2);// left |
| 3245 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 3246 |
} |
| 3247 |
else { |
| 3248 |
g.setColor(_unselectColor1); |
| 3249 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3250 |
g.drawLine(x + 1, y + h - 2, x + w - 3, y + h - 2);// bottom |
| 3251 |
} |
| 3252 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3253 |
g.drawLine(x + 1, y, x + w - 3, y);// top |
| 3254 |
} |
| 3255 |
} |
| 3256 |
break; |
| 3257 |
case BOTTOM: |
| 3258 |
if (isSelected) { |
| 3259 |
g.setColor(_selectColor1); |
| 3260 |
g.drawLine(x, y, x, y + h - 1); // left |
| 3261 |
|
| 3262 |
g.setColor(_selectColor2); |
| 3263 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); // bottom |
| 3264 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 2); // right |
| 3265 |
} |
| 3266 |
else { |
| 3267 |
g.setColor(_unselectColor1); |
| 3268 |
if (leftToRight) { |
| 3269 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3270 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3271 |
} |
| 3272 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3273 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3274 |
} |
| 3275 |
} |
| 3276 |
else { |
| 3277 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3278 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3279 |
} |
| 3280 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != _tabPane.getTabCount() - 1) { |
| 3281 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3282 |
} |
| 3283 |
} |
| 3284 |
} |
| 3285 |
break; |
| 3286 |
case TOP: |
| 3287 |
default: |
| 3288 |
if (isSelected) { |
| 3289 |
g.setColor(_selectColor1); |
| 3290 |
g.drawLine(x, y + 1, x, y + h - 1); // left |
| 3291 |
g.drawLine(x, y, x + w - 1, y); // top |
| 3292 |
|
| 3293 |
g.setColor(_selectColor2); |
| 3294 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); // right |
| 3295 |
} |
| 3296 |
else { |
| 3297 |
g.setColor(_unselectColor1); |
| 3298 |
if (leftToRight) { |
| 3299 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3300 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3301 |
} |
| 3302 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3303 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3304 |
} |
| 3305 |
} |
| 3306 |
else { |
| 3307 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3308 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3309 |
} |
| 3310 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != _tabPane.getTabCount() - 1) { |
| 3311 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3312 |
} |
| 3313 |
} |
| 3314 |
} |
| 3315 |
} |
| 3316 |
|
| 3317 |
} |
| 3318 |
|
| 3319 |
protected void paintRoundedVsnetTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 3320 |
int x, int y, int w, int h, boolean isSelected) { |
| 3321 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 3322 |
switch (tabPlacement) { |
| 3323 |
case LEFT: |
| 3324 |
if (isSelected) { |
| 3325 |
g.setColor(_selectColor1); |
| 3326 |
g.drawLine(x + 2, y, x + w - 1, y);// top |
| 3327 |
g.drawLine(x + 1, y + 1, x + 1, y + 1);// top-left |
| 3328 |
g.drawLine(x, y + 2, x, y + h - 3);// left |
| 3329 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);// bottom-left |
| 3330 |
g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 3331 |
} |
| 3332 |
else { |
| 3333 |
g.setColor(_unselectColor1); |
| 3334 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3335 |
g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);// bottom |
| 3336 |
} |
| 3337 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3338 |
g.drawLine(x + 2, y + 1, x + w - 2, y + 1);// top |
| 3339 |
} |
| 3340 |
} |
| 3341 |
break; |
| 3342 |
case RIGHT: |
| 3343 |
if (isSelected) { |
| 3344 |
g.setColor(_selectColor1); |
| 3345 |
g.drawLine(x, y, x + w - 3, y);// top |
| 3346 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);// top-left |
| 3347 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);// left |
| 3348 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);// bottom-left |
| 3349 |
g.drawLine(x, y + h - 1, x + w - 3, y + h - 1);// bottom |
| 3350 |
} |
| 3351 |
else { |
| 3352 |
g.setColor(_unselectColor1); |
| 3353 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3354 |
g.drawLine(x + 1, y + h - 2, x + w - 3, y + h - 2);// bottom |
| 3355 |
} |
| 3356 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3357 |
g.drawLine(x + 1, y + 1, x + w - 3, y + 1);// top |
| 3358 |
} |
| 3359 |
} |
| 3360 |
break; |
| 3361 |
case BOTTOM: |
| 3362 |
if (isSelected) { |
| 3363 |
g.setColor(_selectColor1); |
| 3364 |
g.drawLine(x, y, x, y + h - 3); // left |
| 3365 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); // bottom-left |
| 3366 |
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom |
| 3367 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); // bottom-right |
| 3368 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 3); // right |
| 3369 |
} |
| 3370 |
else { |
| 3371 |
g.setColor(_unselectColor1); |
| 3372 |
if (leftToRight) { |
| 3373 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3374 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3375 |
} |
| 3376 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3377 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3378 |
} |
| 3379 |
} |
| 3380 |
else { |
| 3381 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3382 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3383 |
} |
| 3384 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != _tabPane.getTabCount() - 1) { |
| 3385 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3386 |
} |
| 3387 |
} |
| 3388 |
} |
| 3389 |
break; |
| 3390 |
case TOP: |
| 3391 |
default: |
| 3392 |
if (isSelected) { |
| 3393 |
g.setColor(_selectColor1); |
| 3394 |
g.drawLine(x, y + 2, x, y + h - 1); // left |
| 3395 |
g.drawLine(x, y + 2, x + 2, y); // top-left |
| 3396 |
g.drawLine(x + 2, y, x + w - 3, y); // top |
| 3397 |
g.drawLine(x + w - 3, y, x + w - 1, y + 2); // top-left |
| 3398 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1); // right |
| 3399 |
} |
| 3400 |
else { |
| 3401 |
g.setColor(_unselectColor1); |
| 3402 |
if (leftToRight) { |
| 3403 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3404 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3405 |
} |
| 3406 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != 0) { |
| 3407 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3408 |
} |
| 3409 |
} |
| 3410 |
else { |
| 3411 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3412 |
g.drawLine(x, y + 2, x, y + h - 2); // left |
| 3413 |
} |
| 3414 |
else if (tabIndex < _tabPane.getSelectedIndex() && tabIndex != _tabPane.getTabCount() - 1) { |
| 3415 |
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 2); // right |
| 3416 |
} |
| 3417 |
} |
| 3418 |
} |
| 3419 |
} |
| 3420 |
|
| 3421 |
} |
| 3422 |
|
| 3423 |
protected void paintFlatTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 3424 |
int x, int y, int w, int h, boolean isSelected) { |
| 3425 |
switch (tabPlacement) { |
| 3426 |
case LEFT: |
| 3427 |
if (isSelected) { |
| 3428 |
g.setColor(_selectColor1); |
| 3429 |
g.drawRect(x, y, w, h); |
| 3430 |
} |
| 3431 |
else { |
| 3432 |
g.setColor(_unselectColor1); |
| 3433 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3434 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3435 |
g.drawRect(x, y, w, h - 1); |
| 3436 |
} |
| 3437 |
else { |
| 3438 |
g.drawRect(x, y, w, h); |
| 3439 |
} |
| 3440 |
} |
| 3441 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3442 |
g.drawRect(x, y, w, h); |
| 3443 |
} |
| 3444 |
} |
| 3445 |
break; |
| 3446 |
case RIGHT: |
| 3447 |
if (isSelected) { |
| 3448 |
g.setColor(_selectColor1); |
| 3449 |
g.drawRect(x - 1, y, w, h); |
| 3450 |
} |
| 3451 |
else { |
| 3452 |
g.setColor(_unselectColor1); |
| 3453 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3454 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3455 |
g.drawRect(x - 1, y, w, h - 1); |
| 3456 |
} |
| 3457 |
else { |
| 3458 |
g.drawRect(x - 1, y, w, h); |
| 3459 |
} |
| 3460 |
} |
| 3461 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3462 |
g.drawRect(x - 1, y, w, h); |
| 3463 |
} |
| 3464 |
} |
| 3465 |
break; |
| 3466 |
case BOTTOM: |
| 3467 |
if (isSelected) { |
| 3468 |
g.setColor(_selectColor1); |
| 3469 |
g.drawRect(x, y - 1, w, h); |
| 3470 |
} |
| 3471 |
else { |
| 3472 |
g.setColor(_unselectColor1); |
| 3473 |
g.drawRect(x, y - 1, w, h); |
| 3474 |
} |
| 3475 |
break; |
| 3476 |
case TOP: |
| 3477 |
default: |
| 3478 |
if (isSelected) { |
| 3479 |
g.setColor(_selectColor1); |
| 3480 |
g.drawRect(x, y, w, h); |
| 3481 |
} |
| 3482 |
else { |
| 3483 |
g.setColor(_unselectColor1); |
| 3484 |
g.drawRect(x, y, w, h); |
| 3485 |
} |
| 3486 |
} |
| 3487 |
} |
| 3488 |
|
| 3489 |
protected void paintRoundedFlatTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 3490 |
int x, int y, int w, int h, boolean isSelected) { |
| 3491 |
switch (tabPlacement) { |
| 3492 |
case LEFT: |
| 3493 |
if (isSelected) { |
| 3494 |
g.setColor(_selectColor1); |
| 3495 |
g.drawLine(x + 2, y, x + w - 1, y); |
| 3496 |
g.drawLine(x + 2, y + h, x + w - 1, y + h); |
| 3497 |
g.drawLine(x, y + 2, x, y + h - 2); |
| 3498 |
|
| 3499 |
g.setColor(_selectColor2); |
| 3500 |
g.drawLine(x + 1, y + 1, x + 1, y + 1); |
| 3501 |
// g.drawLine(x, y + 1, x, y + 1); |
| 3502 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3503 |
// g.drawLine(x + 1, y + h, x + 1, y + h); |
| 3504 |
} |
| 3505 |
else { |
| 3506 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3507 |
g.setColor(_unselectColor1); |
| 3508 |
g.drawLine(x + 2, y, x + w - 1, y); |
| 3509 |
|
| 3510 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3511 |
g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1); |
| 3512 |
g.drawLine(x, y + 2, x, y + h - 3); |
| 3513 |
} |
| 3514 |
else { |
| 3515 |
g.drawLine(x + 2, y + h, x + w - 1, y + h); |
| 3516 |
g.drawLine(x, y + 2, x, y + h - 2); |
| 3517 |
} |
| 3518 |
|
| 3519 |
g.setColor(_unselectColor2); |
| 3520 |
g.drawLine(x + 1, y + 1, x + 1, y + 1); |
| 3521 |
// g.drawLine(x, y + 1, x, y + 1); |
| 3522 |
|
| 3523 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3524 |
g.drawLine(x, y + h - 2, x, y + h - 2); |
| 3525 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3526 |
} |
| 3527 |
else { |
| 3528 |
g.drawLine(x, y + h - 1, x, y + h - 1); |
| 3529 |
g.drawLine(x + 1, y + h, x + 1, y + h); |
| 3530 |
} |
| 3531 |
} |
| 3532 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3533 |
g.setColor(_unselectColor1); |
| 3534 |
g.drawLine(x + 2, y, x + w - 1, y); |
| 3535 |
g.drawLine(x + 2, y + h, x + w - 1, y + h); |
| 3536 |
g.drawLine(x, y + 2, x, y + h - 2); |
| 3537 |
|
| 3538 |
g.setColor(_unselectColor2); |
| 3539 |
g.drawLine(x + 1, y + 1, x + 1, y + 1); |
| 3540 |
// g.drawLine(x, y + 1, x, y + 1); |
| 3541 |
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3542 |
// g.drawLine(x + 1, y + h, x + 1, y + h); |
| 3543 |
} |
| 3544 |
} |
| 3545 |
break; |
| 3546 |
case RIGHT: |
| 3547 |
if (isSelected) { |
| 3548 |
g.setColor(_selectColor1); |
| 3549 |
g.drawLine(x, y, x + w - 3, y); |
| 3550 |
g.drawLine(x, y + h, x + w - 3, y + h); |
| 3551 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 2); |
| 3552 |
|
| 3553 |
g.setColor(_selectColor2); |
| 3554 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
| 3555 |
// g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1); |
| 3556 |
// g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1); |
| 3557 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3558 |
} |
| 3559 |
else { |
| 3560 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3561 |
g.setColor(_unselectColor1); |
| 3562 |
g.drawLine(x, y, x + w - 3, y); |
| 3563 |
|
| 3564 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3565 |
g.drawLine(x, y + h - 1, x + w - 3, y + h - 1); |
| 3566 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); |
| 3567 |
} |
| 3568 |
else { |
| 3569 |
g.drawLine(x, y + h, x + w - 3, y + h); |
| 3570 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 2); |
| 3571 |
} |
| 3572 |
|
| 3573 |
g.setColor(_unselectColor2); |
| 3574 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
| 3575 |
// g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1); |
| 3576 |
|
| 3577 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3578 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); |
| 3579 |
// g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3580 |
} |
| 3581 |
else { |
| 3582 |
// g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1); |
| 3583 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3584 |
} |
| 3585 |
} |
| 3586 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3587 |
g.setColor(_unselectColor1); |
| 3588 |
g.drawLine(x, y, x + w - 3, y); |
| 3589 |
g.drawLine(x, y + h, x + w - 3, y + h); |
| 3590 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 2); |
| 3591 |
|
| 3592 |
g.setColor(_unselectColor2); |
| 3593 |
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
| 3594 |
// g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1); |
| 3595 |
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3596 |
// g.drawLine(x + w - 2, y + h, x + w - 2, y + h); |
| 3597 |
} |
| 3598 |
} |
| 3599 |
break; |
| 3600 |
case BOTTOM: |
| 3601 |
if (isSelected) { |
| 3602 |
g.setColor(_selectColor1); |
| 3603 |
g.drawLine(x, y, x, y + h - 3); |
| 3604 |
g.drawLine(x + 2, y + h - 1, x + w - 2, y + h - 1); |
| 3605 |
g.drawLine(x + w, y, x + w, y + h - 3); |
| 3606 |
|
| 3607 |
g.setColor(_selectColor2); |
| 3608 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); |
| 3609 |
// g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3610 |
// g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1); |
| 3611 |
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2); |
| 3612 |
} |
| 3613 |
else { |
| 3614 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3615 |
g.setColor(_unselectColor1); |
| 3616 |
g.drawLine(x, y, x, y + h - 3); |
| 3617 |
|
| 3618 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3619 |
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); |
| 3620 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 3); |
| 3621 |
} |
| 3622 |
else { |
| 3623 |
g.drawLine(x + 2, y + h - 1, x + w - 2, y + h - 1); |
| 3624 |
g.drawLine(x + w, y, x + w, y + h - 3); |
| 3625 |
} |
| 3626 |
|
| 3627 |
g.setColor(_unselectColor2); |
| 3628 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); |
| 3629 |
// g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3630 |
|
| 3631 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3632 |
// g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1); |
| 3633 |
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); |
| 3634 |
} |
| 3635 |
else { |
| 3636 |
// g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1); |
| 3637 |
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2); |
| 3638 |
} |
| 3639 |
} |
| 3640 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3641 |
g.setColor(_unselectColor1); |
| 3642 |
g.drawLine(x, y, x, y + h - 3); |
| 3643 |
g.drawLine(x + 2, y + h - 1, x + w - 2, y + h - 1); |
| 3644 |
g.drawLine(x + w, y, x + w, y + h - 3); |
| 3645 |
|
| 3646 |
g.setColor(_unselectColor2); |
| 3647 |
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); |
| 3648 |
// g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1); |
| 3649 |
// g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1); |
| 3650 |
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2); |
| 3651 |
} |
| 3652 |
} |
| 3653 |
break; |
| 3654 |
case TOP: |
| 3655 |
default: |
| 3656 |
if (isSelected) { |
| 3657 |
g.setColor(_selectColor1); |
| 3658 |
g.drawLine(x, y + h - 1, x, y + 2); |
| 3659 |
g.drawLine(x + 2, y, x + w - 2, y); |
| 3660 |
g.drawLine(x + w, y + 2, x + w, y + h - 1); |
| 3661 |
|
| 3662 |
g.setColor(_selectColor2); |
| 3663 |
g.drawLine(x, y + 2, x + 2, y); // top-left |
| 3664 |
g.drawLine(x + w - 2, y, x + w, y + 2); |
| 3665 |
// g.drawLine(x + w, y + 1, x + w, y + 1); |
| 3666 |
} |
| 3667 |
else { |
| 3668 |
if (tabIndex > _tabPane.getSelectedIndex()) { |
| 3669 |
g.setColor(_unselectColor1); |
| 3670 |
g.drawLine(x, y + h - 1, x, y + 2); |
| 3671 |
|
| 3672 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3673 |
g.drawLine(x + 2, y, x + w - 3, y); |
| 3674 |
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1); |
| 3675 |
} |
| 3676 |
else { |
| 3677 |
g.drawLine(x + 2, y, x + w - 2, y); |
| 3678 |
g.drawLine(x + w, y + 2, x + w, y + h - 1); |
| 3679 |
} |
| 3680 |
|
| 3681 |
g.setColor(_unselectColor2); |
| 3682 |
g.drawLine(x, y + 2, x + 2, y); // top-left |
| 3683 |
|
| 3684 |
if (tabIndex == _tabPane.getTabCount() - 1) { |
| 3685 |
g.drawLine(x + w - 3, y, x + w - 1, y + 2); |
| 3686 |
} |
| 3687 |
else { |
| 3688 |
g.drawLine(x + w - 2, y, x + w, y + 2); |
| 3689 |
} |
| 3690 |
} |
| 3691 |
else if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3692 |
g.setColor(_unselectColor1); |
| 3693 |
g.drawLine(x, y + h - 1, x, y + 2); |
| 3694 |
g.drawLine(x + 2, y, x + w - 2, y); |
| 3695 |
g.drawLine(x + w, y + 2, x + w, y + h - 1); |
| 3696 |
|
| 3697 |
g.setColor(_unselectColor2); |
| 3698 |
g.drawLine(x, y + 2, x + 2, y); |
| 3699 |
g.drawLine(x + w - 2, y, x + w, y + 2); |
| 3700 |
} |
| 3701 |
} |
| 3702 |
} |
| 3703 |
} |
| 3704 |
|
| 3705 |
protected void paintBoxTabBorder(Graphics g, int tabPlacement, int tabIndex, |
| 3706 |
int x, int y, int w, int h, boolean isSelected) { |
| 3707 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 3708 |
|
| 3709 |
if (isSelected) { |
| 3710 |
g.setColor(_selectColor1); |
| 3711 |
g.drawLine(x, y, x + w - 2, y);// top |
| 3712 |
g.drawLine(x, y, x, y + h - 2);// left |
| 3713 |
|
| 3714 |
g.setColor(_selectColor2); |
| 3715 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);// right |
| 3716 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);// bottom |
| 3717 |
} |
| 3718 |
else { |
| 3719 |
if (tabIndex != _tabPane.getSelectedIndex() - 1) { |
| 3720 |
switch (tabPlacement) { |
| 3721 |
case LEFT: |
| 3722 |
case RIGHT: |
| 3723 |
g.setColor(_unselectColor1); |
| 3724 |
g.drawLine(x + 2, y + h, x + w - 2, y + h);// bottom |
| 3725 |
|
| 3726 |
g.setColor(_unselectColor2); |
| 3727 |
g.drawLine(x + 2, y + h + 1, x + w - 2, y + h + 1);// bottom |
| 3728 |
break; |
| 3729 |
case BOTTOM: |
| 3730 |
case TOP: |
| 3731 |
default: |
| 3732 |
if (leftToRight) { |
| 3733 |
g.setColor(_unselectColor1); |
| 3734 |
g.drawLine(x + w, y + 2, x + w, y + h - 2);// right |
| 3735 |
|
| 3736 |
g.setColor(_unselectColor2); |
| 3737 |
g.drawLine(x + w + 1, y + 2, x + w + 1, y + h - 2);// right |
| 3738 |
} |
| 3739 |
else { |
| 3740 |
g.setColor(_unselectColor1); |
| 3741 |
g.drawLine(x, y + 2, x, y + h - 2);// right |
| 3742 |
|
| 3743 |
g.setColor(_unselectColor2); |
| 3744 |
g.drawLine(x + 1, y + 2, x + 1, y + h - 2);// right |
| 3745 |
} |
| 3746 |
} |
| 3747 |
} |
| 3748 |
} |
| 3749 |
} |
| 3750 |
|
| 3751 |
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 3752 |
if (!PAINT_TAB_BACKGROUND) { |
| 3753 |
return; |
| 3754 |
} |
| 3755 |
|
| 3756 |
switch (getTabShape()) { |
| 3757 |
case JideTabbedPane.SHAPE_BOX: |
| 3758 |
paintButtonTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3759 |
break; |
| 3760 |
case JideTabbedPane.SHAPE_EXCEL: |
| 3761 |
paintExcelTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3762 |
break; |
| 3763 |
case JideTabbedPane.SHAPE_WINDOWS: |
| 3764 |
paintDefaultTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3765 |
break; |
| 3766 |
case JideTabbedPane.SHAPE_WINDOWS_SELECTED: |
| 3767 |
if (isSelected) { |
| 3768 |
paintDefaultTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3769 |
} |
| 3770 |
break; |
| 3771 |
case JideTabbedPane.SHAPE_VSNET: |
| 3772 |
case JideTabbedPane.SHAPE_ROUNDED_VSNET: |
| 3773 |
paintVsnetTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3774 |
break; |
| 3775 |
case JideTabbedPane.SHAPE_FLAT: |
| 3776 |
case JideTabbedPane.SHAPE_ROUNDED_FLAT: |
| 3777 |
paintFlatTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3778 |
break; |
| 3779 |
case JideTabbedPane.SHAPE_OFFICE2003: |
| 3780 |
default: |
| 3781 |
paintOffice2003TabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); |
| 3782 |
} |
| 3783 |
|
| 3784 |
} |
| 3785 |
|
| 3786 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 3787 |
protected void paintOffice2003TabBackground(Graphics g, int tabPlacement, |
| 3788 |
int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 3789 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 3790 |
switch (tabPlacement) { |
| 3791 |
case LEFT: |
| 3792 |
if (tabIndex != 0 && !isSelected) { |
| 3793 |
int xp[] = {x + w, x + 4, x + 2, x, x, x + 3, x + w}; |
| 3794 |
int yp[] = {y, y, y + 2, y + 5, y + h - 5, y + h - 2, y + h - 2}; |
| 3795 |
int np = yp.length; |
| 3796 |
tabRegion = new Polygon(xp, yp, np); |
| 3797 |
} |
| 3798 |
else {// tabIndex != 0 |
| 3799 |
int xp[] = {x + w, x + 2, x, x, x + 3, x + w}; |
| 3800 |
int yp[] = {y - w + 2 + 2, y + 2, y + 5, y + h - 5, y + h - 2, y + h - 2}; |
| 3801 |
int np = yp.length; |
| 3802 |
tabRegion = new Polygon(xp, yp, np); |
| 3803 |
} |
| 3804 |
break; |
| 3805 |
case RIGHT: |
| 3806 |
if (tabIndex != 0 && !isSelected) { |
| 3807 |
int xp[] = {x, x + w - 4, x + w - 3, x + w - 1, x + w - 1, x + w - 3, x}; |
| 3808 |
int yp[] = {y, y, y + 2, y + 5, y + h - 5, y + h - 2, y + h - 2}; |
| 3809 |
int np = yp.length; |
| 3810 |
tabRegion = new Polygon(xp, yp, np); |
| 3811 |
} |
| 3812 |
else { |
| 3813 |
int xp[] = {x, x + w - 3, x + w - 1, x + w - 1, x + w - 3, x}; |
| 3814 |
int yp[] = {y - w + 2 + 2, y + 2, y + 5, y + h - 5, y + h - 2, y + h - 2}; |
| 3815 |
int np = yp.length; |
| 3816 |
tabRegion = new Polygon(xp, yp, np); |
| 3817 |
} |
| 3818 |
break; |
| 3819 |
case BOTTOM: |
| 3820 |
if (leftToRight) { |
| 3821 |
int xp[] = {x - (tabIndex == 0 || isSelected ? h - 5 : 0), x, x + 4, x + w - 3, x + w - 1, x + w - 1}; |
| 3822 |
int yp[] = {y, y + h - 5, y + h - 1, y + h - 1, y + h - 5, y}; |
| 3823 |
int np = yp.length; |
| 3824 |
tabRegion = new Polygon(xp, yp, np); |
| 3825 |
} |
| 3826 |
else { |
| 3827 |
int xp[] = {x, x, x + 2, x + w - 5, x + w - 1, x + w - 1 + (tabIndex == 0 || isSelected ? h - 5 : 0)}; |
| 3828 |
int yp[] = {y, y + h - 5, y + h - 1, y + h - 1, y + h - 5, y}; |
| 3829 |
int np = yp.length; |
| 3830 |
tabRegion = new Polygon(xp, yp, np); |
| 3831 |
} |
| 3832 |
break; |
| 3833 |
case TOP: |
| 3834 |
default: |
| 3835 |
if (leftToRight) { |
| 3836 |
int xp[] = {x - (tabIndex == 0 || isSelected ? h - 5 : 0), x, x + 4, x + w - 3, x + w - 1, x + w - 1}; |
| 3837 |
int yp[] = {y + h, y + 3, y + 1, y + 1, y + 3, y + h}; |
| 3838 |
int np = yp.length; |
| 3839 |
tabRegion = new Polygon(xp, yp, np); |
| 3840 |
} |
| 3841 |
else { |
| 3842 |
int xp[] = {x, x, x + 2, x + w - 5, x + w - 1, x + w - 1 + (tabIndex == 0 || isSelected ? h - 5 : 0)}; |
| 3843 |
int yp[] = {y + h, y + 3, y + 1, y + 1, y + 3, y + h}; |
| 3844 |
int np = yp.length; |
| 3845 |
tabRegion = new Polygon(xp, yp, np); |
| 3846 |
} |
| 3847 |
} |
| 3848 |
} |
| 3849 |
|
| 3850 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 3851 |
protected void paintExcelTabBackground(Graphics g, int tabPlacement, |
| 3852 |
int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 3853 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 3854 |
switch (tabPlacement) { |
| 3855 |
case LEFT: |
| 3856 |
if (!isSelected) { |
| 3857 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 3858 |
int xp[] = {x + w, x, x, x + w}; |
| 3859 |
int yp[] = {y - 5, y + 5, y + h - 5, y + h + 6}; |
| 3860 |
int np = yp.length; |
| 3861 |
tabRegion = new Polygon(xp, yp, np); |
| 3862 |
} |
| 3863 |
else { |
| 3864 |
int xp[] = {x + w, x + 9, x, x, x + w}; |
| 3865 |
int yp[] = {y + 8, y + 2, y + 6, y + h - 5, y + h + 6}; |
| 3866 |
int np = yp.length; |
| 3867 |
tabRegion = new Polygon(xp, yp, np); |
| 3868 |
} |
| 3869 |
} |
| 3870 |
else { |
| 3871 |
int xp[] = {x + w, x, x, x + w}; |
| 3872 |
int yp[] = {y - 5, y + 5, y + h - 5, y + h + 6}; |
| 3873 |
int np = yp.length; |
| 3874 |
tabRegion = new Polygon(xp, yp, np); |
| 3875 |
} |
| 3876 |
break; |
| 3877 |
case RIGHT: |
| 3878 |
if (!isSelected) { |
| 3879 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 3880 |
int xp[] = {x, x + w - 1, x + w - 1, x}; |
| 3881 |
int yp[] = {y - 5, y + 5, y + h - 5, y + h + 6}; |
| 3882 |
int np = yp.length; |
| 3883 |
tabRegion = new Polygon(xp, yp, np); |
| 3884 |
} |
| 3885 |
else { |
| 3886 |
int xp[] = {x, x + w - 10, x + w - 1, x + w - 1, x}; |
| 3887 |
int yp[] = {y + 8, y + 2, y + 6, y + h - 5, |
| 3888 |
y + h + 6}; |
| 3889 |
int np = yp.length; |
| 3890 |
tabRegion = new Polygon(xp, yp, np); |
| 3891 |
} |
| 3892 |
} |
| 3893 |
else { |
| 3894 |
int xp[] = {x, x + w - 1, x + w - 1, x}; |
| 3895 |
int yp[] = {y - 5, y + 5, y + h - 4, y + h + 6}; |
| 3896 |
int np = yp.length; |
| 3897 |
tabRegion = new Polygon(xp, yp, np); |
| 3898 |
} |
| 3899 |
break; |
| 3900 |
case BOTTOM: |
| 3901 |
if (!isSelected) { |
| 3902 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 3903 |
int xp[] = {x - 5, x + 5, x + w - 5, x + w + 5}; |
| 3904 |
int yp[] = {y, y + h - 1, y + h - 1, y}; |
| 3905 |
int np = yp.length; |
| 3906 |
tabRegion = new Polygon(xp, yp, np); |
| 3907 |
} |
| 3908 |
else { |
| 3909 |
int xp[] = {x + 7, x + 1, x + 5, x + w - 5, x + w + 5}; |
| 3910 |
int yp[] = {y, y + h - 10, y + h - 1, y + h - 1, y}; |
| 3911 |
int np = yp.length; |
| 3912 |
tabRegion = new Polygon(xp, yp, np); |
| 3913 |
} |
| 3914 |
} |
| 3915 |
else { |
| 3916 |
int xp[] = {x - 5, x + 5, x + w - 5, x + w + 5}; |
| 3917 |
int yp[] = {y, y + h - 1, y + h - 1, y}; |
| 3918 |
int np = yp.length; |
| 3919 |
tabRegion = new Polygon(xp, yp, np); |
| 3920 |
} |
| 3921 |
break; |
| 3922 |
case TOP: |
| 3923 |
default: |
| 3924 |
if (!isSelected) { |
| 3925 |
if ((leftToRight && tabIndex == 0) || (!leftToRight && tabIndex == _tabPane.getTabCount() - 1)) { |
| 3926 |
int xp[] = {x - 6, x + 5, x + w - 5, x + w + 5}; |
| 3927 |
int yp[] = {y + h, y, y, y + h}; |
| 3928 |
int np = yp.length; |
| 3929 |
tabRegion = new Polygon(xp, yp, np); |
| 3930 |
} |
| 3931 |
else { |
| 3932 |
int xp[] = {x + 7, x + 1, x + 6, x + w - 5, x + w + 5}; |
| 3933 |
int yp[] = {y + h, y + 9, y, y, y + h}; |
| 3934 |
int np = yp.length; |
| 3935 |
tabRegion = new Polygon(xp, yp, np); |
| 3936 |
} |
| 3937 |
} |
| 3938 |
else { |
| 3939 |
int xp[] = {x - 6, x + 5, x + w - 5, x + w + 5}; |
| 3940 |
int yp[] = {y + h, y, y, y + h}; |
| 3941 |
int np = yp.length; |
| 3942 |
tabRegion = new Polygon(xp, yp, np); |
| 3943 |
} |
| 3944 |
} |
| 3945 |
} |
| 3946 |
|
| 3947 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 3948 |
protected void paintDefaultTabBackground(Graphics g, int tabPlacement, |
| 3949 |
int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 3950 |
switch (tabPlacement) { |
| 3951 |
case LEFT: |
| 3952 |
if (isSelected) { |
| 3953 |
x = x + 1; |
| 3954 |
int xp[] = {x + w, x, x - 2, x - 2, x + w}; |
| 3955 |
int yp[] = {y - 1, y - 1, y + 1, y + h + 2, y + h + 2}; |
| 3956 |
int np = yp.length; |
| 3957 |
tabRegion = new Polygon(xp, yp, np); |
| 3958 |
} |
| 3959 |
else { |
| 3960 |
if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3961 |
y = y + 1; |
| 3962 |
int xp[] = {x + w, x + 2, x, x, x + w}; |
| 3963 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 1, |
| 3964 |
y + h - 1}; |
| 3965 |
int np = yp.length; |
| 3966 |
tabRegion = new Polygon(xp, yp, np); |
| 3967 |
} |
| 3968 |
else { |
| 3969 |
int xp[] = {x + w, x + 2, x, x, x + w}; |
| 3970 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 2, |
| 3971 |
y + h - 2}; |
| 3972 |
int np = yp.length; |
| 3973 |
tabRegion = new Polygon(xp, yp, np); |
| 3974 |
} |
| 3975 |
} |
| 3976 |
break; |
| 3977 |
case RIGHT: |
| 3978 |
if (isSelected) { |
| 3979 |
|
| 3980 |
int xp[] = {x, x + w - 1, x + w, x + w, x}; |
| 3981 |
int yp[] = {y - 1, y - 1, y + 1, y + h + 2, y + h + 2}; |
| 3982 |
int np = yp.length; |
| 3983 |
tabRegion = new Polygon(xp, yp, np); |
| 3984 |
} |
| 3985 |
else { |
| 3986 |
if (tabIndex < _tabPane.getSelectedIndex()) { |
| 3987 |
y = y + 1; |
| 3988 |
int xp[] = {x, x + w - 3, x + w - 1, x + w - 1, x}; |
| 3989 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 1, |
| 3990 |
y + h - 1}; |
| 3991 |
int np = yp.length; |
| 3992 |
tabRegion = new Polygon(xp, yp, np); |
| 3993 |
} |
| 3994 |
else { |
| 3995 |
int xp[] = {x, x + w - 2, x + w - 1, x + w - 1, x}; |
| 3996 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 2, |
| 3997 |
y + h - 2}; |
| 3998 |
int np = yp.length; |
| 3999 |
tabRegion = new Polygon(xp, yp, np); |
| 4000 |
} |
| 4001 |
} |
| 4002 |
break; |
| 4003 |
case BOTTOM: |
| 4004 |
if (isSelected) { |
| 4005 |
int xp[] = {x, x, x + 2, x + w + 2, x + w + 2}; |
| 4006 |
int yp[] = {y + h, y, y - 2, y - 2, y + h}; |
| 4007 |
int np = yp.length; |
| 4008 |
tabRegion = new Polygon(xp, yp, np); |
| 4009 |
} |
| 4010 |
else { |
| 4011 |
int xp[] = {x + 1, x + 1, x + 1, x + w - 1, x + w - 1}; |
| 4012 |
int yp[] = {y + h - 1, y + 2, y, y, y + h - 1}; |
| 4013 |
int np = yp.length; |
| 4014 |
tabRegion = new Polygon(xp, yp, np); |
| 4015 |
} |
| 4016 |
break; |
| 4017 |
case TOP: |
| 4018 |
default: |
| 4019 |
if (isSelected) { |
| 4020 |
int xp[] = {x, x, x + 2, x + w + 2, x + w + 2}; |
| 4021 |
int yp[] = {y + h + 1, y, y - 2, y - 2, y + h + 1}; |
| 4022 |
int np = yp.length; |
| 4023 |
tabRegion = new Polygon(xp, yp, np); |
| 4024 |
} |
| 4025 |
else { |
| 4026 |
int xp[] = {x + 1, x + 1, x + 3, x + w - 1, x + w - 1}; |
| 4027 |
int yp[] = {y + h, y + 2, y, y, y + h}; |
| 4028 |
int np = yp.length; |
| 4029 |
tabRegion = new Polygon(xp, yp, np); |
| 4030 |
} |
| 4031 |
} |
| 4032 |
} |
| 4033 |
|
| 4034 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4035 |
protected void paintTabBackgroundMouseOver(Graphics g, int tabPlacement, int tabIndex, |
| 4036 |
int x, int y, int w, int h, boolean isSelected, Color backgroundUnselectedColorStart, Color backgroundUnselectedColorEnd) { |
| 4037 |
Graphics2D g2d = (Graphics2D) g; |
| 4038 |
|
| 4039 |
Polygon polygon; |
| 4040 |
|
| 4041 |
switch (tabPlacement) { |
| 4042 |
case LEFT: |
| 4043 |
if (tabIndex < _tabPane.getSelectedIndex()) { |
| 4044 |
|
| 4045 |
int xp[] = {x + w, x + 2, x, x, x + 2, x + w}; |
| 4046 |
int yp[] = {y + 2, y + 2, y + 4, y + h - 1, y + h, |
| 4047 |
y + h}; |
| 4048 |
int np = yp.length; |
| 4049 |
polygon = new Polygon(xp, yp, np); |
| 4050 |
|
| 4051 |
} |
| 4052 |
else {// tabIndex > _tabPane.getSelectedIndex() |
| 4053 |
|
| 4054 |
int xp[] = {x + w, x + 2, x, x, x + 2, x + w}; |
| 4055 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 3, |
| 4056 |
y + h - 2, y + h - 2}; |
| 4057 |
int np = yp.length; |
| 4058 |
polygon = new Polygon(xp, yp, np); |
| 4059 |
|
| 4060 |
} |
| 4061 |
JideSwingUtilities.fillGradient(g2d, polygon, backgroundUnselectedColorStart, backgroundUnselectedColorEnd, false); |
| 4062 |
break; |
| 4063 |
case RIGHT: |
| 4064 |
if (tabIndex < _tabPane.getSelectedIndex()) { |
| 4065 |
int xp[] = {x, x + w - 3, x + w - 1, x + w - 1, |
| 4066 |
x + w - 3, x}; |
| 4067 |
int yp[] = {y + 2, y + 2, y + 4, y + h - 1, y + h, |
| 4068 |
y + h}; |
| 4069 |
int np = yp.length; |
| 4070 |
polygon = new Polygon(xp, yp, np); |
| 4071 |
} |
| 4072 |
else { |
| 4073 |
int xp[] = {x, x + w - 2, x + w - 1, x + w - 1, |
| 4074 |
x + w - 3, x}; |
| 4075 |
int yp[] = {y + 1, y + 1, y + 3, y + h - 3, |
| 4076 |
y + h - 2, y + h - 2}; |
| 4077 |
int np = yp.length; |
| 4078 |
polygon = new Polygon(xp, yp, np); |
| 4079 |
} |
| 4080 |
JideSwingUtilities.fillGradient(g2d, polygon, backgroundUnselectedColorEnd, backgroundUnselectedColorStart, false); |
| 4081 |
break; |
| 4082 |
case BOTTOM: |
| 4083 |
int xp[] = {x + 1, x + 1, x + 1, x + w - 1, x + w - 1}; |
| 4084 |
int yp[] = {y + h - 2, y + 2, y, y, y + h - 2}; |
| 4085 |
int np = yp.length; |
| 4086 |
polygon = new Polygon(xp, yp, np); |
| 4087 |
JideSwingUtilities.fillGradient(g2d, polygon, backgroundUnselectedColorEnd, backgroundUnselectedColorStart, true); |
| 4088 |
break; |
| 4089 |
case TOP: |
| 4090 |
default: |
| 4091 |
int xp1[] = {x + 1, x + 1, x + 3, x + w - 1, x + w - 1}; |
| 4092 |
int yp1[] = {y + h, y + 2, y, y, y + h}; |
| 4093 |
int np1 = yp1.length; |
| 4094 |
polygon = new Polygon(xp1, yp1, np1); |
| 4095 |
JideSwingUtilities.fillGradient(g2d, polygon, backgroundUnselectedColorStart, backgroundUnselectedColorEnd, true); |
| 4096 |
} |
| 4097 |
} |
| 4098 |
|
| 4099 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4100 |
protected void paintVsnetTabBackground(Graphics g, int tabPlacement, |
| 4101 |
int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 4102 |
int xp[]; |
| 4103 |
int yp[]; |
| 4104 |
switch (tabPlacement) { |
| 4105 |
case LEFT: |
| 4106 |
xp = new int[]{x + 1, x + 1, x + w, x + w}; |
| 4107 |
yp = new int[]{y + h - 1, y + 1, y + 1, y + h - 1}; |
| 4108 |
break; |
| 4109 |
case RIGHT: |
| 4110 |
xp = new int[]{x, x, x + w - 1, x + w - 1}; |
| 4111 |
yp = new int[]{y + h - 1, y + 1, y + 1, y + h - 1}; |
| 4112 |
break; |
| 4113 |
case BOTTOM: |
| 4114 |
xp = new int[]{x + 1, x + 1, x + w - 1, x + w - 1}; |
| 4115 |
yp = new int[]{y + h - 1, y, y, y + h - 1}; |
| 4116 |
break; |
| 4117 |
case TOP: |
| 4118 |
default: |
| 4119 |
xp = new int[]{x + 1, x + 1, x + w - 1, x + w - 1}; |
| 4120 |
yp = new int[]{y + h, y + 1, y + 1, y + h}; |
| 4121 |
break; |
| 4122 |
} |
| 4123 |
int np = yp.length; |
| 4124 |
tabRegion = new Polygon(xp, yp, np); |
| 4125 |
} |
| 4126 |
|
| 4127 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4128 |
protected void paintFlatTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 4129 |
switch (tabPlacement) { |
| 4130 |
case LEFT: |
| 4131 |
int xp1[] = {x + 1, x + 1, x + w, x + w}; |
| 4132 |
int yp1[] = {y + h, y + 1, y + 1, y + h}; |
| 4133 |
int np1 = yp1.length; |
| 4134 |
tabRegion = new Polygon(xp1, yp1, np1); |
| 4135 |
break; |
| 4136 |
case RIGHT: |
| 4137 |
int xp2[] = {x, x, x + w - 1, x + w - 1}; |
| 4138 |
int yp2[] = {y + h, y + 1, y + 1, y + h}; |
| 4139 |
int np2 = yp2.length; |
| 4140 |
tabRegion = new Polygon(xp2, yp2, np2); |
| 4141 |
break; |
| 4142 |
case BOTTOM: |
| 4143 |
int xp3[] = {x + 1, x + 1, x + w, x + w}; |
| 4144 |
int yp3[] = {y + h - 1, y, y, y + h - 1}; |
| 4145 |
int np3 = yp3.length; |
| 4146 |
tabRegion = new Polygon(xp3, yp3, np3); |
| 4147 |
break; |
| 4148 |
case TOP: |
| 4149 |
default: |
| 4150 |
int xp4[] = {x, x + 1, x + w, x + w}; |
| 4151 |
int yp4[] = {y + h, y + 1, y + 1, y + h}; |
| 4152 |
int np4 = yp4.length; |
| 4153 |
tabRegion = new Polygon(xp4, yp4, np4); |
| 4154 |
} |
| 4155 |
} |
| 4156 |
|
| 4157 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4158 |
protected void paintButtonTabBackground(Graphics g, int tabPlacement, |
| 4159 |
int tabIndex, int x, int y, int w, int h, boolean isSelected) { |
| 4160 |
int xp[] = {x, x, x + w, x + w}; |
| 4161 |
int yp[] = {y + h, y, y, y + h}; |
| 4162 |
int np = yp.length; |
| 4163 |
tabRegion = new Polygon(xp, yp, np); |
| 4164 |
} |
| 4165 |
|
| 4166 |
/** |
| 4167 |
* Paints the border of the conten pane which should reflect the tabs as well. |
| 4168 |
* |
| 4169 |
* @param g the Graphics instance |
| 4170 |
* @param tabPlacement the tab placement |
| 4171 |
* @param selectedIndex the selected tab index |
| 4172 |
*/ |
| 4173 |
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) { |
| 4174 |
int width = _tabPane.getWidth(); |
| 4175 |
int height = _tabPane.getHeight(); |
| 4176 |
Insets insets = _tabPane.getInsets(); |
| 4177 |
|
| 4178 |
int x = insets.left; |
| 4179 |
int y = insets.top; |
| 4180 |
int w = width - insets.right - insets.left; |
| 4181 |
int h = height - insets.top - insets.bottom; |
| 4182 |
|
| 4183 |
Dimension lsize = new Dimension(0, 0); |
| 4184 |
Dimension tsize = new Dimension(0, 0); |
| 4185 |
|
| 4186 |
if (isTabLeadingComponentVisible()) { |
| 4187 |
lsize = _tabLeadingComponent.getPreferredSize(); |
| 4188 |
} |
| 4189 |
if (isTabTrailingComponentVisible()) { |
| 4190 |
tsize = _tabTrailingComponent.getPreferredSize(); |
| 4191 |
} |
| 4192 |
|
| 4193 |
switch (tabPlacement) { |
| 4194 |
case LEFT: |
| 4195 |
int tabAreaWidth = calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth); |
| 4196 |
if (isTabLeadingComponentVisible()) { |
| 4197 |
if (lsize.width > tabAreaWidth) { |
| 4198 |
tabAreaWidth = lsize.width; |
| 4199 |
} |
| 4200 |
} |
| 4201 |
if (isTabTrailingComponentVisible()) { |
| 4202 |
if (tsize.width > tabAreaWidth) { |
| 4203 |
tabAreaWidth = tsize.width; |
| 4204 |
} |
| 4205 |
} |
| 4206 |
if (scrollableTabLayoutEnabled()) |
| 4207 |
paintTabAreaBackground(g, new Rectangle(x, y, tabAreaWidth, h), tabPlacement); |
| 4208 |
x += tabAreaWidth; |
| 4209 |
w -= (x - insets.left); |
| 4210 |
break; |
| 4211 |
case RIGHT: |
| 4212 |
int areaWidth = calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth); |
| 4213 |
if (scrollableTabLayoutEnabled()) |
| 4214 |
paintTabAreaBackground(g, new Rectangle(x, y, areaWidth, h), tabPlacement); |
| 4215 |
w -= areaWidth; |
| 4216 |
break; |
| 4217 |
case BOTTOM: |
| 4218 |
int areaHeight = calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight); |
| 4219 |
if (scrollableTabLayoutEnabled()) |
| 4220 |
paintTabAreaBackground(g, new Rectangle(x, y, w, areaHeight), tabPlacement); |
| 4221 |
h -= areaHeight; |
| 4222 |
break; |
| 4223 |
case TOP: |
| 4224 |
default: |
| 4225 |
int tabAreaHeight = calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight); |
| 4226 |
if (isTabLeadingComponentVisible()) { |
| 4227 |
if (lsize.height > tabAreaHeight) { |
| 4228 |
tabAreaHeight = lsize.height; |
| 4229 |
} |
| 4230 |
} |
| 4231 |
if (isTabTrailingComponentVisible()) { |
| 4232 |
if (tabAreaHeight < tsize.height) { |
| 4233 |
tabAreaHeight = tsize.height; |
| 4234 |
} |
| 4235 |
} |
| 4236 |
if (scrollableTabLayoutEnabled()) |
| 4237 |
paintTabAreaBackground(g, new Rectangle(x, y, w, tabAreaHeight), tabPlacement); |
| 4238 |
y += tabAreaHeight; |
| 4239 |
h -= (y - insets.top); |
| 4240 |
} |
| 4241 |
|
| 4242 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 4243 |
|
| 4244 |
// Fill region behind content area |
| 4245 |
paintContentBorder(g, x, y, w, h); |
| 4246 |
|
| 4247 |
switch (tabPlacement) { |
| 4248 |
case LEFT: |
| 4249 |
paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h); |
| 4250 |
break; |
| 4251 |
case RIGHT: |
| 4252 |
paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h); |
| 4253 |
break; |
| 4254 |
case BOTTOM: |
| 4255 |
paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h); |
| 4256 |
break; |
| 4257 |
case TOP: |
| 4258 |
default: |
| 4259 |
paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h); |
| 4260 |
break; |
| 4261 |
|
| 4262 |
} |
| 4263 |
} |
| 4264 |
|
| 4265 |
} |
| 4266 |
|
| 4267 |
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, |
| 4268 |
int selectedIndex, int x, int y, int w, int h) { |
| 4269 |
|
| 4270 |
} |
| 4271 |
|
| 4272 |
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, |
| 4273 |
int selectedIndex, int x, int y, int w, int h) { |
| 4274 |
|
| 4275 |
} |
| 4276 |
|
| 4277 |
protected void paintContentBorder(Graphics g, int x, int y, int w, int h) { |
| 4278 |
if (!PAINT_CONTENT_BORDER) { |
| 4279 |
return; |
| 4280 |
} |
| 4281 |
|
| 4282 |
if (_tabPane.isOpaque()) { |
| 4283 |
g.setColor(_tabBackground); |
| 4284 |
g.fillRect(x, y, w, h); |
| 4285 |
} |
| 4286 |
} |
| 4287 |
|
| 4288 |
protected Color getBorderEdgeColor() { |
| 4289 |
if ("true".equals(SecurityUtils.getProperty("shadingtheme", "false"))) { |
| 4290 |
return _shadow; |
| 4291 |
} |
| 4292 |
else { |
| 4293 |
return _lightHighlight; |
| 4294 |
} |
| 4295 |
} |
| 4296 |
|
| 4297 |
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, |
| 4298 |
int selectedIndex, |
| 4299 |
int x, int y, int w, int h) { |
| 4300 |
|
| 4301 |
if (!PAINT_CONTENT_BORDER_EDGE) { |
| 4302 |
return; |
| 4303 |
} |
| 4304 |
|
| 4305 |
if (selectedIndex < 0) { |
| 4306 |
return; |
| 4307 |
} |
| 4308 |
|
| 4309 |
if (!_tabPane.isTabShown()) { |
| 4310 |
return; |
| 4311 |
} |
| 4312 |
|
| 4313 |
Rectangle selRect = getTabBounds(selectedIndex, _calcRect); |
| 4314 |
|
| 4315 |
g.setColor(getBorderEdgeColor()); |
| 4316 |
|
| 4317 |
// Draw unbroken line if tabs are not on TOP, OR |
| 4318 |
// selected tab is not in run adjacent to content, OR |
| 4319 |
// selected tab is not visible (SCROLL_TAB_LAYOUT) |
| 4320 |
// |
| 4321 |
if (tabPlacement != TOP || selectedIndex < 0 || |
| 4322 |
/*(selRect.y + selRect.height + 1 < y) ||*/ |
| 4323 |
(selRect.x < x || selRect.x > x + w)) { |
| 4324 |
g.drawLine(x, y, x + w - 1, y); |
| 4325 |
} |
| 4326 |
else { |
| 4327 |
// Break line to show visual connection to selected tab |
| 4328 |
g.drawLine(x, y, selRect.x, y); |
| 4329 |
if (!getBorderEdgeColor().equals(_lightHighlight)) { |
| 4330 |
if (selRect.x + selRect.width < x + w - 2) { |
| 4331 |
g.drawLine(selRect.x + selRect.width - 1, y, |
| 4332 |
selRect.x + selRect.width - 1, y); |
| 4333 |
g.drawLine(selRect.x + selRect.width, y, x + w - 1, y); |
| 4334 |
} |
| 4335 |
else { |
| 4336 |
g.drawLine(x + w - 2, y, x + w - 1, y); |
| 4337 |
} |
| 4338 |
} |
| 4339 |
else { |
| 4340 |
if (selRect.x + selRect.width < x + w - 2) { |
| 4341 |
g.setColor(_darkShadow); |
| 4342 |
g.drawLine(selRect.x + selRect.width - 1, y, |
| 4343 |
selRect.x + selRect.width - 1, y); |
| 4344 |
g.setColor(_lightHighlight); |
| 4345 |
g.drawLine(selRect.x + selRect.width, y, x + w - 1, y); |
| 4346 |
} |
| 4347 |
else { |
| 4348 |
g.setColor(_selectedColor == null ? |
| 4349 |
_tabPane.getBackground() : _selectedColor); |
| 4350 |
g.drawLine(x + w - 2, y, x + w - 1, y); |
| 4351 |
} |
| 4352 |
} |
| 4353 |
} |
| 4354 |
} |
| 4355 |
|
| 4356 |
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, |
| 4357 |
int selectedIndex, |
| 4358 |
int x, int y, int w, int h) { |
| 4359 |
if (!PAINT_CONTENT_BORDER_EDGE) { |
| 4360 |
return; |
| 4361 |
} |
| 4362 |
|
| 4363 |
if (selectedIndex < 0) { |
| 4364 |
return; |
| 4365 |
} |
| 4366 |
|
| 4367 |
if (!_tabPane.isTabShown()) { |
| 4368 |
return; |
| 4369 |
} |
| 4370 |
|
| 4371 |
Rectangle selRect = getTabBounds(selectedIndex, _calcRect); |
| 4372 |
|
| 4373 |
// Draw unbroken line if tabs are not on BOTTOM, OR |
| 4374 |
// selected tab is not in run adjacent to content, OR |
| 4375 |
// selected tab is not visible (SCROLL_TAB_LAYOUT) |
| 4376 |
// |
| 4377 |
if (tabPlacement != BOTTOM || selectedIndex < 0 || |
| 4378 |
/*(selRect.y - 1 > h) ||*/ |
| 4379 |
(selRect.x < x || selRect.x > x + w)) { |
| 4380 |
g.setColor(getBorderEdgeColor()); |
| 4381 |
g.drawLine(x, y + h - 1, x + w - 2, y + h - 1); |
| 4382 |
} |
| 4383 |
else { |
| 4384 |
if (!getBorderEdgeColor().equals(_lightHighlight)) { |
| 4385 |
g.setColor(getBorderEdgeColor()); |
| 4386 |
g.drawLine(x, y + h - 1, selRect.x - 1, y + h - 1); |
| 4387 |
g.drawLine(selRect.x, y + h - 1, selRect.x, y + h - 1); |
| 4388 |
if (selRect.x + selRect.width < x + w - 2) { |
| 4389 |
g.drawLine(selRect.x + selRect.width - 1, y + h - 1, x + w - 2, y + h - 1); // dark line to the end |
| 4390 |
} |
| 4391 |
} |
| 4392 |
else { |
| 4393 |
// Break line to show visual connection to selected tab |
| 4394 |
g.setColor(_darkShadow); // dark line at the beginning |
| 4395 |
g.drawLine(x, y + h - 1, selRect.x - 1, y + h - 1); |
| 4396 |
g.setColor(_lightHighlight); // light line to meet with tab |
| 4397 |
// border |
| 4398 |
g.drawLine(selRect.x, y + h - 1, selRect.x, y + h - 1); |
| 4399 |
if (selRect.x + selRect.width < x + w - 2) { |
| 4400 |
g.setColor(_darkShadow); |
| 4401 |
g.drawLine(selRect.x + selRect.width - 1, y + h - 1, x + w - 2, y + h - 1); // dark line to the end |
| 4402 |
} |
| 4403 |
} |
| 4404 |
} |
| 4405 |
|
| 4406 |
} |
| 4407 |
|
| 4408 |
|
| 4409 |
protected void ensureCurrentLayout() { |
| 4410 |
/* |
| 4411 |
* If tabPane doesn't have a peer yet, the validate() call will |
| 4412 |
* silently fail. We handle that by forcing a layout if tabPane |
| 4413 |
* is still invalid. See bug 4237677. |
| 4414 |
*/ |
| 4415 |
if (!_tabPane.isValid()) { |
| 4416 |
TabbedPaneLayout layout = (TabbedPaneLayout) _tabPane.getLayout(); |
| 4417 |
layout.calculateLayoutInfo(); |
| 4418 |
} |
| 4419 |
} |
| 4420 |
|
| 4421 |
private void updateCloseButtons() { |
| 4422 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 4423 |
if (scrollableTabLayoutEnabled() && isShowCloseButton() && isShowCloseButtonOnTab()) { |
| 4424 |
for (int i = 0; i < _closeButtons.length; i++) { |
| 4425 |
if (_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 4426 |
if (i != _tabPane.getSelectedIndex()) { |
| 4427 |
_closeButtons[i].setBounds(0, 0, 0, 0); |
| 4428 |
continue; |
| 4429 |
} |
| 4430 |
} |
| 4431 |
else { |
| 4432 |
if (i >= _rects.length) { |
| 4433 |
_closeButtons[i].setBounds(0, 0, 0, 0); |
| 4434 |
continue; |
| 4435 |
} |
| 4436 |
} |
| 4437 |
|
| 4438 |
if (!_tabPane.isTabClosableAt(i)) { |
| 4439 |
_closeButtons[i].setBounds(0, 0, 0, 0); |
| 4440 |
continue; |
| 4441 |
} |
| 4442 |
Dimension size = _closeButtons[i].getPreferredSize(); |
| 4443 |
|
| 4444 |
Rectangle bounds; |
| 4445 |
if (_closeButtonAlignment == SwingConstants.TRAILING) { |
| 4446 |
if (_tabPane.getTabPlacement() == JideTabbedPane.TOP || _tabPane.getTabPlacement() == JideTabbedPane.BOTTOM) { |
| 4447 |
if (leftToRight) { |
| 4448 |
bounds = new Rectangle(_rects[i].x + _rects[i].width - size.width - _closeButtonRightMargin, |
| 4449 |
_rects[i].y + (_rects[i].height - size.height) / 2, size.width, size.height); |
| 4450 |
bounds.x -= getTabGap(); |
| 4451 |
if (i > _tabPane.getSelectedIndex() && (JideTabbedPane.SHAPE_ROUNDED_VSNET == _tabPane.getTabShape() || JideTabbedPane.SHAPE_VSNET == _tabPane.getTabShape())) { |
| 4452 |
bounds.x--; |
| 4453 |
} |
| 4454 |
} |
| 4455 |
else { |
| 4456 |
bounds = new Rectangle(_rects[i].x + _closeButtonLeftMargin + getTabGap(), _rects[i].y + (_rects[i].height - size.height) / 2, size.width, size.height); |
| 4457 |
} |
| 4458 |
} |
| 4459 |
else /*if (_tabPane.getTabPlacement() == JideTabbedPane.LEFT || _tabPane.getTabPlacement() == JideTabbedPane.RIGHT)*/ { |
| 4460 |
bounds = new Rectangle(_rects[i].x + (_rects[i].width - size.width) / 2, _rects[i].y + _rects[i].height - size.height - _closeButtonRightMargin, size.width, size.height); |
| 4461 |
bounds.y -= getTabGap(); |
| 4462 |
} |
| 4463 |
} |
| 4464 |
else { |
| 4465 |
if (_tabPane.getTabPlacement() == JideTabbedPane.TOP || _tabPane.getTabPlacement() == JideTabbedPane.BOTTOM) { |
| 4466 |
if (leftToRight) { |
| 4467 |
bounds = new Rectangle(_rects[i].x + _closeButtonLeftMargin + getTabGap(), _rects[i].y + (_rects[i].height - size.height) / 2, size.width, size.height); |
| 4468 |
} |
| 4469 |
else { |
| 4470 |
bounds = new Rectangle(_rects[i].x + _rects[i].width - size.width - _closeButtonRightMargin, |
| 4471 |
_rects[i].y + (_rects[i].height - size.height) / 2, size.width, size.height); |
| 4472 |
bounds.x -= getTabGap(); |
| 4473 |
} |
| 4474 |
} |
| 4475 |
else if (_tabPane.getTabPlacement() == JideTabbedPane.LEFT) { |
| 4476 |
bounds = new Rectangle(_rects[i].x + (_rects[i].width - size.width) / 2, _rects[i].y + _closeButtonLeftMargin, size.width, size.height); |
| 4477 |
} |
| 4478 |
else /*if (_tabPane.getTabPlacement() == JideTabbedPane.RIGHT)*/ { |
| 4479 |
bounds = new Rectangle(_rects[i].x + (_rects[i].width - size.width) / 2 - 2, _rects[i].y + _closeButtonLeftMargin, size.width, size.height); |
| 4480 |
} |
| 4481 |
} |
| 4482 |
if (_closeButtons[i] instanceof JideTabbedPane.NoFocusButton) { |
| 4483 |
((JideTabbedPane.NoFocusButton) _closeButtons[i]).setIndex(i); |
| 4484 |
} |
| 4485 |
if (!bounds.equals(_closeButtons[i].getBounds())) { |
| 4486 |
_closeButtons[i].setBounds(bounds); |
| 4487 |
} |
| 4488 |
if (_tabPane.getSelectedIndex() == i) { |
| 4489 |
_closeButtons[i].setBackground(_selectedColor == null ? _tabPane.getBackgroundAt(i) : _selectedColor); |
| 4490 |
} |
| 4491 |
else { |
| 4492 |
_closeButtons[i].setBackground(_tabPane.getBackgroundAt(i)); |
| 4493 |
} |
| 4494 |
} |
| 4495 |
} |
| 4496 |
} |
| 4497 |
|
| 4498 |
// TabbedPaneUI methods |
| 4499 |
|
| 4500 |
/** |
| 4501 |
* Returns the bounds of the specified tab index. The bounds are with respect to the JTabbedPane's coordinate |
| 4502 |
* space. |
| 4503 |
*/ |
| 4504 |
@Override |
| 4505 |
public Rectangle getTabBounds(JTabbedPane pane, int i) { |
| 4506 |
ensureCurrentLayout(); |
| 4507 |
Rectangle tabRect = new Rectangle(); |
| 4508 |
return getTabBounds(i, tabRect); |
| 4509 |
} |
| 4510 |
|
| 4511 |
@Override |
| 4512 |
public int getTabRunCount(JTabbedPane pane) { |
| 4513 |
ensureCurrentLayout(); |
| 4514 |
return _runCount; |
| 4515 |
} |
| 4516 |
|
| 4517 |
/** |
| 4518 |
* Returns the tab index which intersects the specified point in the JTabbedPane's coordinate space. |
| 4519 |
*/ |
| 4520 |
@Override |
| 4521 |
public int tabForCoordinate(JTabbedPane pane, int x, int y) { |
| 4522 |
ensureCurrentLayout(); |
| 4523 |
Point p = new Point(x, y); |
| 4524 |
if (!_tabPane.isShowTabArea()) { |
| 4525 |
return -1; |
| 4526 |
} |
| 4527 |
|
| 4528 |
if (scrollableTabLayoutEnabled()) { |
| 4529 |
translatePointToTabPanel(x, y, p); |
| 4530 |
} |
| 4531 |
int tabCount = _tabPane.getTabCount(); |
| 4532 |
boolean horizontalTab = _tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM; |
| 4533 |
boolean isRTL = horizontalTab && !_tabPane.getComponentOrientation().isLeftToRight(); |
| 4534 |
|
| 4535 |
int firstButtonPos = isRTL ? 0 : Integer.MAX_VALUE; |
| 4536 |
Component[] components = _tabPane.getComponents(); |
| 4537 |
for (Component component : components) { |
| 4538 |
if (component instanceof JideTabbedPane.NoFocusButton && component.isVisible()) { |
| 4539 |
Rectangle bounds = component.getBounds(); |
| 4540 |
if (horizontalTab && bounds.x != 0) { |
| 4541 |
if (isRTL) { |
| 4542 |
firstButtonPos = Math.max(firstButtonPos, bounds.x); |
| 4543 |
} |
| 4544 |
else { |
| 4545 |
firstButtonPos = Math.min(firstButtonPos, bounds.x); |
| 4546 |
} |
| 4547 |
} |
| 4548 |
else if (!horizontalTab && bounds.y != 0) { |
| 4549 |
firstButtonPos = Math.min(firstButtonPos, bounds.y); |
| 4550 |
} |
| 4551 |
} |
| 4552 |
} |
| 4553 |
if (_tabPane.getTabTrailingComponent() != null && _tabPane.getTabTrailingComponent().isVisible()) { |
| 4554 |
Rectangle bounds = _tabPane.getTabTrailingComponent().getBounds(); |
| 4555 |
if (horizontalTab && bounds.x != 0) { |
| 4556 |
if (isRTL) { |
| 4557 |
firstButtonPos = Math.max(firstButtonPos, bounds.x); |
| 4558 |
} |
| 4559 |
else { |
| 4560 |
firstButtonPos = Math.min(firstButtonPos, bounds.x); |
| 4561 |
} |
| 4562 |
} |
| 4563 |
else if (!horizontalTab && bounds.y != 0) { |
| 4564 |
firstButtonPos = Math.min(firstButtonPos, bounds.y); |
| 4565 |
} |
| 4566 |
} |
| 4567 |
if (horizontalTab) { |
| 4568 |
if ((isRTL && x <= firstButtonPos) || (!isRTL && x >= firstButtonPos)) { |
| 4569 |
return -1; |
| 4570 |
} |
| 4571 |
} |
| 4572 |
else { |
| 4573 |
if (y >= firstButtonPos) { |
| 4574 |
return -1; |
| 4575 |
} |
| 4576 |
} |
| 4577 |
|
| 4578 |
for (int i = 0; i < tabCount; i++) { |
| 4579 |
if (_rects[i].contains(p.x, p.y)) { |
| 4580 |
return i; |
| 4581 |
} |
| 4582 |
} |
| 4583 |
return -1; |
| 4584 |
} |
| 4585 |
|
| 4586 |
/** |
| 4587 |
* Returns the bounds of the specified tab in the coordinate space of the JTabbedPane component. This is required |
| 4588 |
* because the tab rects are by default defined in the coordinate space of the component where they are rendered, |
| 4589 |
* which could be the JTabbedPane (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel (SCROLL_TAB_LAYOUT). This method |
| 4590 |
* should be used whenever the tab rectangle must be relative to the JTabbedPane itself and the result should be |
| 4591 |
* placed in a designated Rectangle object (rather than instantiating and returning a new Rectangle each time). The |
| 4592 |
* tab index parameter must be a valid tabbed pane tab index (0 to tab count - 1, inclusive). The destination |
| 4593 |
* rectangle parameter must be a valid <code>Rectangle</code> instance. The handling of invalid parameters is |
| 4594 |
* unspecified. |
| 4595 |
* |
| 4596 |
* @param tabIndex the index of the tab |
| 4597 |
* @param dest the rectangle where the result should be placed |
| 4598 |
* @return the resulting rectangle |
| 4599 |
*/ |
| 4600 |
protected Rectangle getTabBounds(int tabIndex, Rectangle dest) { |
| 4601 |
if (_rects.length == 0) { |
| 4602 |
return null; |
| 4603 |
} |
| 4604 |
// to make the index is in bound. |
| 4605 |
if (tabIndex > _rects.length - 1) { |
| 4606 |
tabIndex = _rects.length - 1; |
| 4607 |
} |
| 4608 |
if (tabIndex < 0) { |
| 4609 |
tabIndex = 0; |
| 4610 |
} |
| 4611 |
|
| 4612 |
dest.width = _rects[tabIndex].width; |
| 4613 |
dest.height = _rects[tabIndex].height; |
| 4614 |
|
| 4615 |
if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT |
| 4616 |
// Need to translate coordinates based on viewport location & |
| 4617 |
// view position |
| 4618 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 4619 |
Point vpp = _tabScroller.viewport.getLocation(); |
| 4620 |
Point viewp = _tabScroller.viewport.getViewPosition(); |
| 4621 |
dest.x = _rects[tabIndex].x + vpp.x - (((tabPlacement == TOP || tabPlacement == BOTTOM) && !_tabPane.getComponentOrientation().isLeftToRight()) ? -viewp.x : viewp.x); |
| 4622 |
dest.y = _rects[tabIndex].y + vpp.y - viewp.y; |
| 4623 |
|
| 4624 |
} |
| 4625 |
else { // WRAP_TAB_LAYOUT |
| 4626 |
dest.x = _rects[tabIndex].x; |
| 4627 |
dest.y = _rects[tabIndex].y; |
| 4628 |
} |
| 4629 |
return dest; |
| 4630 |
} |
| 4631 |
|
| 4632 |
/** |
| 4633 |
* Returns the tab index which intersects the specified point in the coordinate space of the component where the |
| 4634 |
* tabs are actually rendered, which could be the JTabbedPane (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel |
| 4635 |
* (SCROLL_TAB_LAYOUT). |
| 4636 |
* |
| 4637 |
* @param x x value of the point |
| 4638 |
* @param y y value of the point |
| 4639 |
* @return the tab index in the point (x, y). -1 if no tab could be found. |
| 4640 |
*/ |
| 4641 |
public int getTabAtLocation(int x, int y) { |
| 4642 |
ensureCurrentLayout(); |
| 4643 |
|
| 4644 |
int tabCount = _tabPane.getTabCount(); |
| 4645 |
for (int i = 0; i < tabCount; i++) { |
| 4646 |
if (_rects[i].contains(x, y)) { |
| 4647 |
return i; |
| 4648 |
} |
| 4649 |
} |
| 4650 |
return -1; |
| 4651 |
} |
| 4652 |
|
| 4653 |
/** |
| 4654 |
* Returns if the point resides in the empty tab area, which means it is in the tab area however no real tab |
| 4655 |
* contains that point. |
| 4656 |
* |
| 4657 |
* @param x x value of the point |
| 4658 |
* @param y y value of the point |
| 4659 |
* @return true if the point is in empty tab area. Otherwise false. |
| 4660 |
*/ |
| 4661 |
public boolean isEmptyTabArea(int x, int y) { |
| 4662 |
int tabCount = _tabPane.getTabCount(); |
| 4663 |
if (getTabAtLocation(x, y) >= 0 || tabCount <= 0) { |
| 4664 |
return false; |
| 4665 |
} |
| 4666 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 4667 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 4668 |
if (_rects[0].contains(_rects[0].x + 1, y)) { |
| 4669 |
return true; |
| 4670 |
} |
| 4671 |
} |
| 4672 |
else { |
| 4673 |
if (_rects[0].contains(x, _rects[0].y + 1)) { |
| 4674 |
return true; |
| 4675 |
} |
| 4676 |
} |
| 4677 |
return false; |
| 4678 |
} |
| 4679 |
|
| 4680 |
/* |
| 4681 |
* Returns the index of the tab closest to the passed in location, note that the returned tab may not contain the |
| 4682 |
* location x,y. |
| 4683 |
*/ |
| 4684 |
private int getClosestTab(int x, int y) { |
| 4685 |
int min = 0; |
| 4686 |
int tabCount = Math.min(_rects.length, _tabPane.getTabCount()); |
| 4687 |
int max = tabCount; |
| 4688 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 4689 |
boolean useX = (tabPlacement == TOP || tabPlacement == BOTTOM); |
| 4690 |
int want = (useX) ? x : y; |
| 4691 |
Rectangle[] rects = new Rectangle[_rects.length]; |
| 4692 |
boolean needConvert = false; |
| 4693 |
if (!useX || _tabPane.getComponentOrientation().isLeftToRight()) { |
| 4694 |
System.arraycopy(_rects, 0, rects, 0, _rects.length); |
| 4695 |
} |
| 4696 |
else { |
| 4697 |
needConvert = true; |
| 4698 |
for (int i = 0; i < _rects.length; i++) { |
| 4699 |
rects[i] = new Rectangle(_rects[_rects.length - 1 - i]); |
| 4700 |
if (i == _rects.length - 1) { |
| 4701 |
rects[i].width += _additionalWidth; |
| 4702 |
} |
| 4703 |
} |
| 4704 |
} |
| 4705 |
|
| 4706 |
while (min != max) { |
| 4707 |
int current = (max + min) >> 1; |
| 4708 |
int minLoc; |
| 4709 |
int maxLoc; |
| 4710 |
|
| 4711 |
if (useX) { |
| 4712 |
minLoc = rects[current].x; |
| 4713 |
maxLoc = minLoc + rects[current].width; |
| 4714 |
} |
| 4715 |
else { |
| 4716 |
minLoc = rects[current].y; |
| 4717 |
maxLoc = minLoc + rects[current].height; |
| 4718 |
} |
| 4719 |
if (want < minLoc) { |
| 4720 |
max = current; |
| 4721 |
if (min == max) { |
| 4722 |
int tabIndex = Math.max(0, current - 1); |
| 4723 |
return needConvert ? rects.length - 1 - tabIndex : tabIndex; |
| 4724 |
} |
| 4725 |
} |
| 4726 |
else if (want >= maxLoc) { |
| 4727 |
min = current; |
| 4728 |
if (max - min <= 1) { |
| 4729 |
int tabIndex = Math.max(current + 1, tabCount - 1); |
| 4730 |
return needConvert ? rects.length - 1 - tabIndex : tabIndex; |
| 4731 |
} |
| 4732 |
} |
| 4733 |
else { |
| 4734 |
return needConvert ? rects.length - 1 - current : current; |
| 4735 |
} |
| 4736 |
} |
| 4737 |
return needConvert ? rects.length - 1 - min : min; |
| 4738 |
} |
| 4739 |
|
| 4740 |
/* |
| 4741 |
* Returns a point which is translated from the specified point in the JTabbedPane's coordinate space to the |
| 4742 |
* coordinate space of the ScrollableTabPanel. This is used for SCROLL_TAB_LAYOUT ONLY. |
| 4743 |
*/ |
| 4744 |
|
| 4745 |
private Point translatePointToTabPanel(int srcx, int srcy, Point dest) { |
| 4746 |
Point vpp = _tabScroller.viewport.getLocation(); |
| 4747 |
Point viewp = _tabScroller.viewport.getViewPosition(); |
| 4748 |
dest.x = srcx - vpp.x + viewp.x; |
| 4749 |
dest.y = srcy - vpp.y + viewp.y; |
| 4750 |
return dest; |
| 4751 |
} |
| 4752 |
|
| 4753 |
// VsnetJideTabbedPaneUI methods |
| 4754 |
|
| 4755 |
protected Component getVisibleComponent() { |
| 4756 |
return visibleComponent; |
| 4757 |
} |
| 4758 |
|
| 4759 |
protected void setVisibleComponent(Component component) { |
| 4760 |
if (visibleComponent != null && visibleComponent != component && |
| 4761 |
visibleComponent.getParent() == _tabPane) { |
| 4762 |
visibleComponent.setVisible(false); |
| 4763 |
} |
| 4764 |
if (component != null && !component.isVisible()) { |
| 4765 |
component.setVisible(true); |
| 4766 |
} |
| 4767 |
visibleComponent = component; |
| 4768 |
} |
| 4769 |
|
| 4770 |
protected void assureRectsCreated(int tabCount) { |
| 4771 |
int rectArrayLen = _rects.length; |
| 4772 |
if (tabCount != rectArrayLen) { |
| 4773 |
Rectangle[] tempRectArray = new Rectangle[tabCount]; |
| 4774 |
System.arraycopy(_rects, 0, tempRectArray, 0, |
| 4775 |
Math.min(rectArrayLen, tabCount)); |
| 4776 |
_rects = tempRectArray; |
| 4777 |
for (int rectIndex = rectArrayLen; rectIndex < tabCount; rectIndex++) { |
| 4778 |
_rects[rectIndex] = new Rectangle(); |
| 4779 |
} |
| 4780 |
} |
| 4781 |
|
| 4782 |
} |
| 4783 |
|
| 4784 |
protected void expandTabRunsArray() { |
| 4785 |
int rectLen = _tabRuns.length; |
| 4786 |
int[] newArray = new int[rectLen + 10]; |
| 4787 |
System.arraycopy(_tabRuns, 0, newArray, 0, _runCount); |
| 4788 |
_tabRuns = newArray; |
| 4789 |
} |
| 4790 |
|
| 4791 |
protected int getRunForTab(int tabCount, int tabIndex) { |
| 4792 |
for (int i = 0; i < _runCount; i++) { |
| 4793 |
int first = _tabRuns[i]; |
| 4794 |
int last = lastTabInRun(tabCount, i); |
| 4795 |
if (tabIndex >= first && tabIndex <= last) { |
| 4796 |
return i; |
| 4797 |
} |
| 4798 |
} |
| 4799 |
return 0; |
| 4800 |
} |
| 4801 |
|
| 4802 |
protected int lastTabInRun(int tabCount, int run) { |
| 4803 |
if (_runCount == 1) { |
| 4804 |
return tabCount - 1; |
| 4805 |
} |
| 4806 |
int nextRun = (run == _runCount - 1 ? 0 : run + 1); |
| 4807 |
if (_tabRuns[nextRun] == 0) { |
| 4808 |
return tabCount - 1; |
| 4809 |
} |
| 4810 |
return _tabRuns[nextRun] - 1; |
| 4811 |
} |
| 4812 |
|
| 4813 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4814 |
protected int getTabRunOverlay(int tabPlacement) { |
| 4815 |
return _tabRunOverlay; |
| 4816 |
} |
| 4817 |
|
| 4818 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4819 |
protected int getTabRunIndent(int tabPlacement, int run) { |
| 4820 |
return 0; |
| 4821 |
} |
| 4822 |
|
| 4823 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4824 |
protected boolean shouldPadTabRun(int tabPlacement, int run) { |
| 4825 |
return _runCount > 1; |
| 4826 |
} |
| 4827 |
|
| 4828 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 4829 |
protected boolean shouldRotateTabRuns(int tabPlacement) { |
| 4830 |
return true; |
| 4831 |
} |
| 4832 |
|
| 4833 |
/** |
| 4834 |
* Returns the text View object required to render stylized text (HTML) for the specified tab or null if no |
| 4835 |
* specialized text rendering is needed for this tab. This is provided to support html rendering inside tabs. |
| 4836 |
* |
| 4837 |
* @param tabIndex the index of the tab |
| 4838 |
* @return the text view to render the tab's text or null if no specialized rendering is required |
| 4839 |
*/ |
| 4840 |
protected View getTextViewForTab(int tabIndex) { |
| 4841 |
if (htmlViews != null && tabIndex < htmlViews.size()) { |
| 4842 |
return (View) htmlViews.elementAt(tabIndex); |
| 4843 |
} |
| 4844 |
return null; |
| 4845 |
} |
| 4846 |
|
| 4847 |
protected int calculateTabHeight(int tabPlacement, int tabIndex, FontMetrics metrics) { |
| 4848 |
int height = 0; |
| 4849 |
Component c = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt(tabIndex) : null; |
| 4850 |
if (c != null) { |
| 4851 |
height = c.getPreferredSize().height; |
| 4852 |
return height; |
| 4853 |
} |
| 4854 |
if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) { |
| 4855 |
View v = getTextViewForTab(tabIndex); |
| 4856 |
if (v != null) { |
| 4857 |
// html |
| 4858 |
height += (int) v.getPreferredSpan(View.Y_AXIS); |
| 4859 |
} |
| 4860 |
else { |
| 4861 |
// plain text |
| 4862 |
height += metrics.getHeight(); |
| 4863 |
} |
| 4864 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 4865 |
Insets tabInsets = getTabInsets(tabPlacement, tabIndex); |
| 4866 |
|
| 4867 |
if (icon != null) { |
| 4868 |
height = Math.max(height, icon.getIconHeight()); |
| 4869 |
} |
| 4870 |
height += tabInsets.top + tabInsets.bottom + 2; |
| 4871 |
} |
| 4872 |
else { |
| 4873 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 4874 |
Insets tabInsets = getTabInsets(tabPlacement, tabIndex); |
| 4875 |
height = tabInsets.top + tabInsets.bottom + 3; |
| 4876 |
|
| 4877 |
if (icon != null) { |
| 4878 |
height += icon.getIconHeight() + _textIconGap; |
| 4879 |
} |
| 4880 |
View v = getTextViewForTab(tabIndex); |
| 4881 |
if (v != null) { |
| 4882 |
// html |
| 4883 |
height += (int) v.getPreferredSpan(View.X_AXIS); |
| 4884 |
} |
| 4885 |
else { |
| 4886 |
// plain text |
| 4887 |
String title = getCurrentDisplayTitleAt(_tabPane, tabIndex); |
| 4888 |
height += SwingUtilities.computeStringWidth(metrics, title); |
| 4889 |
} |
| 4890 |
|
| 4891 |
// for gripper |
| 4892 |
if (_tabPane.isShowGripper()) { |
| 4893 |
height += _gripperHeight; |
| 4894 |
} |
| 4895 |
|
| 4896 |
if (scrollableTabLayoutEnabled() && isShowCloseButton() && isShowCloseButtonOnTab() && _tabPane.isTabClosableAt(tabIndex)) { |
| 4897 |
if (_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 4898 |
if (_tabPane.getSelectedIndex() == tabIndex) { |
| 4899 |
height += _closeButtons[tabIndex].getPreferredSize().height + _closeButtonRightMargin + _closeButtonLeftMargin; |
| 4900 |
} |
| 4901 |
} |
| 4902 |
else { |
| 4903 |
height += _closeButtons[tabIndex].getPreferredSize().height + _closeButtonRightMargin + _closeButtonLeftMargin; |
| 4904 |
} |
| 4905 |
} |
| 4906 |
|
| 4907 |
// height += _tabRectPadding; |
| 4908 |
} |
| 4909 |
return height; |
| 4910 |
} |
| 4911 |
|
| 4912 |
protected int calculateMaxTabHeight(int tabPlacement) { |
| 4913 |
int tabCount = _tabPane.getTabCount(); |
| 4914 |
int result = 0; |
| 4915 |
for (int i = 0; i < tabCount; i++) { |
| 4916 |
FontMetrics metrics = getFontMetrics(i); |
| 4917 |
result = Math.max(calculateTabHeight(tabPlacement, i, metrics), result); |
| 4918 |
} |
| 4919 |
return result; |
| 4920 |
} |
| 4921 |
|
| 4922 |
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { |
| 4923 |
int width = 0; |
| 4924 |
if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) { |
| 4925 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 4926 |
Insets tabInsets = getTabInsets(tabPlacement, tabIndex); |
| 4927 |
width = tabInsets.left + tabInsets.right + 3 + getTabGap(); |
| 4928 |
Component tabComponent = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt(tabIndex) : null; |
| 4929 |
if (tabComponent != null) { |
| 4930 |
width += tabComponent.getPreferredSize().width; |
| 4931 |
return width; |
| 4932 |
} |
| 4933 |
|
| 4934 |
if (icon != null) { |
| 4935 |
width += icon.getIconWidth() + _textIconGap; |
| 4936 |
} |
| 4937 |
View v = getTextViewForTab(tabIndex); |
| 4938 |
if (v != null) { |
| 4939 |
// html |
| 4940 |
width += (int) v.getPreferredSpan(View.X_AXIS); |
| 4941 |
} |
| 4942 |
else { |
| 4943 |
// plain text |
| 4944 |
String title = getCurrentDisplayTitleAt(_tabPane, tabIndex); |
| 4945 |
// while (title == null || title.length() < 3) |
| 4946 |
// title += " "; |
| 4947 |
width += SwingUtilities.computeStringWidth(metrics, title); |
| 4948 |
} |
| 4949 |
|
| 4950 |
// for gripper |
| 4951 |
if (_tabPane.isShowGripper()) { |
| 4952 |
width += _gripperWidth; |
| 4953 |
} |
| 4954 |
|
| 4955 |
if (scrollableTabLayoutEnabled() && isShowCloseButton() && isShowCloseButtonOnTab() && _tabPane.isTabClosableAt(tabIndex)) { |
| 4956 |
if (_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 4957 |
if (_tabPane.getSelectedIndex() == tabIndex) { |
| 4958 |
width += _closeButtons[tabIndex].getPreferredSize().width + _closeButtonRightMargin + _closeButtonLeftMargin; |
| 4959 |
} |
| 4960 |
} |
| 4961 |
else { |
| 4962 |
width += _closeButtons[tabIndex].getPreferredSize().width + _closeButtonRightMargin + _closeButtonLeftMargin; |
| 4963 |
} |
| 4964 |
} |
| 4965 |
|
| 4966 |
// width += _tabRectPadding; |
| 4967 |
} |
| 4968 |
else { |
| 4969 |
Component tabComponent = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt(tabIndex) : null; |
| 4970 |
if (tabComponent != null) { |
| 4971 |
Insets tabInsets = getTabInsets(tabPlacement, tabIndex); |
| 4972 |
width = tabComponent.getPreferredSize().width + tabInsets.left + tabInsets.right + 3; |
| 4973 |
return width; |
| 4974 |
} |
| 4975 |
View v = getTextViewForTab(tabIndex); |
| 4976 |
if (v != null) { |
| 4977 |
// html |
| 4978 |
width += (int) v.getPreferredSpan(View.Y_AXIS); |
| 4979 |
} |
| 4980 |
else { |
| 4981 |
// plain text |
| 4982 |
width += metrics.getHeight(); |
| 4983 |
} |
| 4984 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 4985 |
Insets tabInsets = getTabInsets(tabPlacement, tabIndex); |
| 4986 |
|
| 4987 |
if (icon != null) { |
| 4988 |
width = Math.max(width, icon.getIconWidth()); |
| 4989 |
} |
| 4990 |
width += tabInsets.left + tabInsets.right + 2; |
| 4991 |
} |
| 4992 |
return width; |
| 4993 |
} |
| 4994 |
|
| 4995 |
protected int calculateMaxTabWidth(int tabPlacement) { |
| 4996 |
int tabCount = _tabPane.getTabCount(); |
| 4997 |
int result = 0; |
| 4998 |
for (int i = 0; i < tabCount; i++) { |
| 4999 |
FontMetrics metrics = getFontMetrics(i); |
| 5000 |
result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result); |
| 5001 |
} |
| 5002 |
return result; |
| 5003 |
} |
| 5004 |
|
| 5005 |
protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) { |
| 5006 |
if (!_tabPane.isTabShown()) { |
| 5007 |
return 0; |
| 5008 |
} |
| 5009 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 5010 |
int tabRunOverlay = getTabRunOverlay(tabPlacement); |
| 5011 |
return (horizRunCount > 0 ? horizRunCount * (maxTabHeight - tabRunOverlay) + tabRunOverlay + tabAreaInsets.top + tabAreaInsets.bottom : 0); |
| 5012 |
} |
| 5013 |
|
| 5014 |
protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount, int maxTabWidth) { |
| 5015 |
if (!_tabPane.isTabShown()) { |
| 5016 |
return 0; |
| 5017 |
} |
| 5018 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 5019 |
int tabRunOverlay = getTabRunOverlay(tabPlacement); |
| 5020 |
return (vertRunCount > 0 ? vertRunCount * (maxTabWidth - tabRunOverlay) + tabRunOverlay + tabAreaInsets.left + tabAreaInsets.right : 0); |
| 5021 |
} |
| 5022 |
|
| 5023 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 5024 |
protected Insets getTabInsets(int tabPlacement, int tabIndex) { |
| 5025 |
rotateInsets(_tabPane.getTabInsets(), _currentTabInsets, tabPlacement); |
| 5026 |
return _currentTabInsets; |
| 5027 |
} |
| 5028 |
|
| 5029 |
protected Insets getSelectedTabPadInsets(int tabPlacement) { |
| 5030 |
rotateInsets(_selectedTabPadInsets, _currentPadInsets, tabPlacement); |
| 5031 |
return _currentPadInsets; |
| 5032 |
} |
| 5033 |
|
| 5034 |
protected Insets getTabAreaInsets(int tabPlacement) { |
| 5035 |
rotateInsets(_tabPane.getTabAreaInsets(), _currentTabAreaInsets, tabPlacement); |
| 5036 |
return _currentTabAreaInsets; |
| 5037 |
} |
| 5038 |
|
| 5039 |
protected Insets getContentBorderInsets(int tabPlacement) { |
| 5040 |
rotateInsets(_tabPane.getContentBorderInsets(), _currentContentBorderInsets, tabPlacement); |
| 5041 |
if (_ignoreContentBorderInsetsIfNoTabs && !_tabPane.isTabShown()) |
| 5042 |
return new Insets(0, 0, 0, 0); |
| 5043 |
else |
| 5044 |
return _currentContentBorderInsets; |
| 5045 |
|
| 5046 |
} |
| 5047 |
|
| 5048 |
protected FontMetrics getFontMetrics(int tab) { |
| 5049 |
Font font; |
| 5050 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 5051 |
if (selectedIndex == tab) { |
| 5052 |
if (_tabPane.getSelectedTabFont() != null) { |
| 5053 |
font = _tabPane.getSelectedTabFont(); |
| 5054 |
} |
| 5055 |
else { |
| 5056 |
font = _selectedTabFont; |
| 5057 |
} |
| 5058 |
} |
| 5059 |
else { |
| 5060 |
font = _tabPane.getFont(); |
| 5061 |
} |
| 5062 |
|
| 5063 |
if (selectedIndex == tab && _tabPane.isBoldActiveTab() && font.getStyle() != Font.BOLD) { |
| 5064 |
font = font.deriveFont(Font.BOLD); |
| 5065 |
} |
| 5066 |
return _tabPane.getFontMetrics(font); |
| 5067 |
} |
| 5068 |
|
| 5069 |
// Tab Navigation methods |
| 5070 |
|
| 5071 |
protected void navigateSelectedTab(int direction) { |
| 5072 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 5073 |
int current = _tabPane.getSelectedIndex(); |
| 5074 |
int tabCount = _tabPane.getTabCount(); |
| 5075 |
|
| 5076 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 5077 |
|
| 5078 |
// If we have no tabs then don't navigate. |
| 5079 |
if (tabCount <= 0) { |
| 5080 |
return; |
| 5081 |
} |
| 5082 |
|
| 5083 |
int offset; |
| 5084 |
switch (tabPlacement) { |
| 5085 |
case NEXT: |
| 5086 |
selectNextTab(current); |
| 5087 |
break; |
| 5088 |
case PREVIOUS: |
| 5089 |
selectPreviousTab(current); |
| 5090 |
break; |
| 5091 |
case LEFT: |
| 5092 |
case RIGHT: |
| 5093 |
switch (direction) { |
| 5094 |
case NORTH: |
| 5095 |
selectPreviousTabInRun(current); |
| 5096 |
break; |
| 5097 |
case SOUTH: |
| 5098 |
selectNextTabInRun(current); |
| 5099 |
break; |
| 5100 |
case WEST: |
| 5101 |
offset = getTabRunOffset(tabPlacement, tabCount, current, false); |
| 5102 |
selectAdjacentRunTab(tabPlacement, current, offset); |
| 5103 |
break; |
| 5104 |
case EAST: |
| 5105 |
offset = getTabRunOffset(tabPlacement, tabCount, current, true); |
| 5106 |
selectAdjacentRunTab(tabPlacement, current, offset); |
| 5107 |
break; |
| 5108 |
default: |
| 5109 |
} |
| 5110 |
break; |
| 5111 |
case BOTTOM: |
| 5112 |
case TOP: |
| 5113 |
default: |
| 5114 |
switch (direction) { |
| 5115 |
case NORTH: |
| 5116 |
offset = getTabRunOffset(tabPlacement, tabCount, current, false); |
| 5117 |
selectAdjacentRunTab(tabPlacement, current, offset); |
| 5118 |
break; |
| 5119 |
case SOUTH: |
| 5120 |
offset = getTabRunOffset(tabPlacement, tabCount, current, true); |
| 5121 |
selectAdjacentRunTab(tabPlacement, current, offset); |
| 5122 |
break; |
| 5123 |
case EAST: |
| 5124 |
if (leftToRight) { |
| 5125 |
selectNextTabInRun(current); |
| 5126 |
} |
| 5127 |
else { |
| 5128 |
selectPreviousTabInRun(current); |
| 5129 |
} |
| 5130 |
break; |
| 5131 |
case WEST: |
| 5132 |
if (leftToRight) { |
| 5133 |
selectPreviousTabInRun(current); |
| 5134 |
} |
| 5135 |
else { |
| 5136 |
selectNextTabInRun(current); |
| 5137 |
} |
| 5138 |
break; |
| 5139 |
default: |
| 5140 |
} |
| 5141 |
} |
| 5142 |
} |
| 5143 |
|
| 5144 |
protected void selectNextTabInRun(int current) { |
| 5145 |
int tabCount = _tabPane.getTabCount(); |
| 5146 |
int tabIndex = getNextTabIndexInRun(tabCount, current); |
| 5147 |
|
| 5148 |
while (tabIndex != current && !_tabPane.isEnabledAt(tabIndex)) { |
| 5149 |
tabIndex = getNextTabIndexInRun(tabCount, tabIndex); |
| 5150 |
} |
| 5151 |
_tabPane.setSelectedIndex(tabIndex); |
| 5152 |
} |
| 5153 |
|
| 5154 |
protected void selectPreviousTabInRun(int current) { |
| 5155 |
int tabCount = _tabPane.getTabCount(); |
| 5156 |
int tabIndex = getPreviousTabIndexInRun(tabCount, current); |
| 5157 |
|
| 5158 |
while (tabIndex != current && !_tabPane.isEnabledAt(tabIndex)) { |
| 5159 |
tabIndex = getPreviousTabIndexInRun(tabCount, tabIndex); |
| 5160 |
} |
| 5161 |
_tabPane.setSelectedIndex(tabIndex); |
| 5162 |
} |
| 5163 |
|
| 5164 |
protected void selectNextTab(int current) { |
| 5165 |
int tabIndex = getNextTabIndex(current); |
| 5166 |
|
| 5167 |
while (tabIndex != current && !_tabPane.isEnabledAt(tabIndex)) { |
| 5168 |
tabIndex = getNextTabIndex(tabIndex); |
| 5169 |
} |
| 5170 |
_tabPane.setSelectedIndex(tabIndex); |
| 5171 |
} |
| 5172 |
|
| 5173 |
protected void selectPreviousTab(int current) { |
| 5174 |
int tabIndex = getPreviousTabIndex(current); |
| 5175 |
|
| 5176 |
while (tabIndex != current && !_tabPane.isEnabledAt(tabIndex)) { |
| 5177 |
tabIndex = getPreviousTabIndex(tabIndex); |
| 5178 |
} |
| 5179 |
_tabPane.setSelectedIndex(tabIndex); |
| 5180 |
} |
| 5181 |
|
| 5182 |
protected void selectAdjacentRunTab(int tabPlacement, |
| 5183 |
int tabIndex, int offset) { |
| 5184 |
if (_runCount < 2) { |
| 5185 |
return; |
| 5186 |
} |
| 5187 |
int newIndex; |
| 5188 |
Rectangle r = _rects[tabIndex]; |
| 5189 |
switch (tabPlacement) { |
| 5190 |
case LEFT: |
| 5191 |
case RIGHT: |
| 5192 |
newIndex = getTabAtLocation(r.x + (r.width >> 1) + offset, |
| 5193 |
r.y + (r.height >> 1)); |
| 5194 |
break; |
| 5195 |
case BOTTOM: |
| 5196 |
case TOP: |
| 5197 |
default: |
| 5198 |
newIndex = getTabAtLocation(r.x + (r.width >> 1), |
| 5199 |
r.y + (r.height >> 1) + offset); |
| 5200 |
} |
| 5201 |
if (newIndex != -1) { |
| 5202 |
while (!_tabPane.isEnabledAt(newIndex) && newIndex != tabIndex) { |
| 5203 |
newIndex = getNextTabIndex(newIndex); |
| 5204 |
} |
| 5205 |
_tabPane.setSelectedIndex(newIndex); |
| 5206 |
} |
| 5207 |
} |
| 5208 |
|
| 5209 |
protected int getTabRunOffset(int tabPlacement, int tabCount, |
| 5210 |
int tabIndex, boolean forward) { |
| 5211 |
int run = getRunForTab(tabCount, tabIndex); |
| 5212 |
int offset; |
| 5213 |
switch (tabPlacement) { |
| 5214 |
case LEFT: { |
| 5215 |
if (run == 0) { |
| 5216 |
offset = (forward ? |
| 5217 |
-(calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth) - _maxTabWidth) : |
| 5218 |
-_maxTabWidth); |
| 5219 |
|
| 5220 |
} |
| 5221 |
else if (run == _runCount - 1) { |
| 5222 |
offset = (forward ? |
| 5223 |
_maxTabWidth : |
| 5224 |
calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth) - _maxTabWidth); |
| 5225 |
} |
| 5226 |
else { |
| 5227 |
offset = (forward ? _maxTabWidth : -_maxTabWidth); |
| 5228 |
} |
| 5229 |
break; |
| 5230 |
} |
| 5231 |
case RIGHT: { |
| 5232 |
if (run == 0) { |
| 5233 |
offset = (forward ? |
| 5234 |
_maxTabWidth : |
| 5235 |
calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth) - _maxTabWidth); |
| 5236 |
} |
| 5237 |
else if (run == _runCount - 1) { |
| 5238 |
offset = (forward ? |
| 5239 |
-(calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth) - _maxTabWidth) : |
| 5240 |
-_maxTabWidth); |
| 5241 |
} |
| 5242 |
else { |
| 5243 |
offset = (forward ? _maxTabWidth : -_maxTabWidth); |
| 5244 |
} |
| 5245 |
break; |
| 5246 |
} |
| 5247 |
case BOTTOM: { |
| 5248 |
if (run == 0) { |
| 5249 |
offset = (forward ? |
| 5250 |
_maxTabHeight : |
| 5251 |
calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight) - _maxTabHeight); |
| 5252 |
} |
| 5253 |
else if (run == _runCount - 1) { |
| 5254 |
offset = (forward ? |
| 5255 |
-(calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight) - _maxTabHeight) : |
| 5256 |
-_maxTabHeight); |
| 5257 |
} |
| 5258 |
else { |
| 5259 |
offset = (forward ? _maxTabHeight : -_maxTabHeight); |
| 5260 |
} |
| 5261 |
break; |
| 5262 |
} |
| 5263 |
case TOP: |
| 5264 |
default: { |
| 5265 |
if (run == 0) { |
| 5266 |
offset = (forward ? |
| 5267 |
-(calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight) - _maxTabHeight) : |
| 5268 |
-_maxTabHeight); |
| 5269 |
} |
| 5270 |
else if (run == _runCount - 1) { |
| 5271 |
offset = (forward ? |
| 5272 |
_maxTabHeight : |
| 5273 |
calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight) - _maxTabHeight); |
| 5274 |
} |
| 5275 |
else { |
| 5276 |
offset = (forward ? _maxTabHeight : -_maxTabHeight); |
| 5277 |
} |
| 5278 |
} |
| 5279 |
} |
| 5280 |
return offset; |
| 5281 |
} |
| 5282 |
|
| 5283 |
protected int getPreviousTabIndex(int base) { |
| 5284 |
int tabIndex = (base - 1 >= 0 ? base - 1 : _tabPane.getTabCount() - 1); |
| 5285 |
return (tabIndex >= 0 ? tabIndex : 0); |
| 5286 |
} |
| 5287 |
|
| 5288 |
protected int getNextTabIndex(int base) { |
| 5289 |
return (base + 1) % _tabPane.getTabCount(); |
| 5290 |
} |
| 5291 |
|
| 5292 |
protected int getNextTabIndexInRun(int tabCount, int base) { |
| 5293 |
if (_runCount < 2) { |
| 5294 |
return getNextTabIndex(base); |
| 5295 |
} |
| 5296 |
int currentRun = getRunForTab(tabCount, base); |
| 5297 |
int next = getNextTabIndex(base); |
| 5298 |
if (next == _tabRuns[getNextTabRun(currentRun)]) { |
| 5299 |
return _tabRuns[currentRun]; |
| 5300 |
} |
| 5301 |
return next; |
| 5302 |
} |
| 5303 |
|
| 5304 |
protected int getPreviousTabIndexInRun(int tabCount, int base) { |
| 5305 |
if (_runCount < 2) { |
| 5306 |
return getPreviousTabIndex(base); |
| 5307 |
} |
| 5308 |
int currentRun = getRunForTab(tabCount, base); |
| 5309 |
if (base == _tabRuns[currentRun]) { |
| 5310 |
int previous = _tabRuns[getNextTabRun(currentRun)] - 1; |
| 5311 |
return (previous != -1 ? previous : tabCount - 1); |
| 5312 |
} |
| 5313 |
return getPreviousTabIndex(base); |
| 5314 |
} |
| 5315 |
|
| 5316 |
protected int getPreviousTabRun(int baseRun) { |
| 5317 |
int runIndex = (baseRun - 1 >= 0 ? baseRun - 1 : _runCount - 1); |
| 5318 |
return (runIndex >= 0 ? runIndex : 0); |
| 5319 |
} |
| 5320 |
|
| 5321 |
protected int getNextTabRun(int baseRun) { |
| 5322 |
return (baseRun + 1) % _runCount; |
| 5323 |
} |
| 5324 |
|
| 5325 |
public static void rotateInsets(Insets topInsets, Insets targetInsets, int targetPlacement) { |
| 5326 |
if (topInsets == null) { |
| 5327 |
targetInsets.top = 0; |
| 5328 |
targetInsets.left = 0; |
| 5329 |
targetInsets.bottom = 0; |
| 5330 |
targetInsets.right = 0; |
| 5331 |
return; |
| 5332 |
} |
| 5333 |
|
| 5334 |
switch (targetPlacement) { |
| 5335 |
case LEFT: |
| 5336 |
targetInsets.top = topInsets.left; |
| 5337 |
targetInsets.left = topInsets.top; |
| 5338 |
targetInsets.bottom = topInsets.right; |
| 5339 |
targetInsets.right = topInsets.bottom; |
| 5340 |
break; |
| 5341 |
case BOTTOM: |
| 5342 |
targetInsets.top = topInsets.bottom; |
| 5343 |
targetInsets.left = topInsets.left; |
| 5344 |
targetInsets.bottom = topInsets.top; |
| 5345 |
targetInsets.right = topInsets.right; |
| 5346 |
break; |
| 5347 |
case RIGHT: |
| 5348 |
targetInsets.top = topInsets.left; |
| 5349 |
targetInsets.left = topInsets.bottom; |
| 5350 |
targetInsets.bottom = topInsets.right; |
| 5351 |
targetInsets.right = topInsets.top; |
| 5352 |
break; |
| 5353 |
case TOP: |
| 5354 |
default: |
| 5355 |
targetInsets.top = topInsets.top; |
| 5356 |
targetInsets.left = topInsets.left; |
| 5357 |
targetInsets.bottom = topInsets.bottom; |
| 5358 |
targetInsets.right = topInsets.right; |
| 5359 |
} |
| 5360 |
} |
| 5361 |
|
| 5362 |
public boolean requestFocusForVisibleComponent() { |
| 5363 |
Component visibleComponent = getVisibleComponent(); |
| 5364 |
Component lastFocused = _tabPane.getLastFocusedComponent(visibleComponent); |
| 5365 |
if (lastFocused != null && lastFocused.requestFocusInWindow()) { |
| 5366 |
return true; |
| 5367 |
} |
| 5368 |
else if (visibleComponent != null && JideSwingUtilities.passesFocusabilityTest(visibleComponent)) { // visibleComponent.isFocusTraversable()) { |
| 5369 |
JideSwingUtilities.compositeRequestFocus(visibleComponent); |
| 5370 |
return true; |
| 5371 |
} |
| 5372 |
else if (visibleComponent != null && visibleComponent.requestFocusInWindow()) { |
| 5373 |
return true; |
| 5374 |
} |
| 5375 |
return false; |
| 5376 |
} |
| 5377 |
|
| 5378 |
private static class RightAction extends AbstractAction { |
| 5379 |
private static final long serialVersionUID = -1759791760116532857L; |
| 5380 |
|
| 5381 |
public void actionPerformed(ActionEvent e) { |
| 5382 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5383 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5384 |
ui.navigateSelectedTab(EAST); |
| 5385 |
} |
| 5386 |
} |
| 5387 |
|
| 5388 |
private static class LeftAction extends AbstractAction { |
| 5389 |
private static final long serialVersionUID = 8670680299012169408L; |
| 5390 |
|
| 5391 |
public void actionPerformed(ActionEvent e) { |
| 5392 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5393 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5394 |
ui.navigateSelectedTab(WEST); |
| 5395 |
} |
| 5396 |
} |
| 5397 |
|
| 5398 |
private static class UpAction extends AbstractAction { |
| 5399 |
private static final long serialVersionUID = -6961702501242792445L; |
| 5400 |
|
| 5401 |
public void actionPerformed(ActionEvent e) { |
| 5402 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5403 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5404 |
ui.navigateSelectedTab(NORTH); |
| 5405 |
} |
| 5406 |
} |
| 5407 |
|
| 5408 |
private static class DownAction extends AbstractAction { |
| 5409 |
private static final long serialVersionUID = -453174268282628886L; |
| 5410 |
|
| 5411 |
public void actionPerformed(ActionEvent e) { |
| 5412 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5413 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5414 |
ui.navigateSelectedTab(SOUTH); |
| 5415 |
} |
| 5416 |
} |
| 5417 |
|
| 5418 |
private static class NextAction extends AbstractAction { |
| 5419 |
private static final long serialVersionUID = -154035573464933924L; |
| 5420 |
|
| 5421 |
public void actionPerformed(ActionEvent e) { |
| 5422 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5423 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5424 |
ui.navigateSelectedTab(NEXT); |
| 5425 |
} |
| 5426 |
} |
| 5427 |
|
| 5428 |
private static class PreviousAction extends AbstractAction { |
| 5429 |
private static final long serialVersionUID = 2095403667386334865L; |
| 5430 |
|
| 5431 |
public void actionPerformed(ActionEvent e) { |
| 5432 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5433 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5434 |
ui.navigateSelectedTab(PREVIOUS); |
| 5435 |
} |
| 5436 |
} |
| 5437 |
|
| 5438 |
private static class PageUpAction extends AbstractAction { |
| 5439 |
private static final long serialVersionUID = 1154273528778779166L; |
| 5440 |
|
| 5441 |
public void actionPerformed(ActionEvent e) { |
| 5442 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5443 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5444 |
int tabPlacement = pane.getTabPlacement(); |
| 5445 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 5446 |
ui.navigateSelectedTab(WEST); |
| 5447 |
} |
| 5448 |
else { |
| 5449 |
ui.navigateSelectedTab(NORTH); |
| 5450 |
} |
| 5451 |
} |
| 5452 |
} |
| 5453 |
|
| 5454 |
private static class PageDownAction extends AbstractAction { |
| 5455 |
private static final long serialVersionUID = 4895454480954468453L; |
| 5456 |
|
| 5457 |
public void actionPerformed(ActionEvent e) { |
| 5458 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5459 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5460 |
int tabPlacement = pane.getTabPlacement(); |
| 5461 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 5462 |
ui.navigateSelectedTab(EAST); |
| 5463 |
} |
| 5464 |
else { |
| 5465 |
ui.navigateSelectedTab(SOUTH); |
| 5466 |
} |
| 5467 |
} |
| 5468 |
} |
| 5469 |
|
| 5470 |
private static class RequestFocusAction extends AbstractAction { |
| 5471 |
private static final long serialVersionUID = 3791111435639724577L; |
| 5472 |
|
| 5473 |
public void actionPerformed(ActionEvent e) { |
| 5474 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5475 |
if (!pane.requestFocusInWindow()) { |
| 5476 |
pane.requestFocus(); |
| 5477 |
} |
| 5478 |
} |
| 5479 |
} |
| 5480 |
|
| 5481 |
private static class RequestFocusForVisibleAction extends AbstractAction { |
| 5482 |
private static final long serialVersionUID = 6677797853998039155L; |
| 5483 |
|
| 5484 |
public void actionPerformed(ActionEvent e) { |
| 5485 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5486 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5487 |
ui.requestFocusForVisibleComponent(); |
| 5488 |
} |
| 5489 |
} |
| 5490 |
|
| 5491 |
/** |
| 5492 |
* Selects a tab in the JTabbedPane based on the String of the action command. The tab selected is based on the |
| 5493 |
* first tab that has a mnemonic matching the first character of the action command. |
| 5494 |
*/ |
| 5495 |
private static class SetSelectedIndexAction extends AbstractAction { |
| 5496 |
private static final long serialVersionUID = 6216635910156115469L; |
| 5497 |
|
| 5498 |
public void actionPerformed(ActionEvent e) { |
| 5499 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 5500 |
|
| 5501 |
if (pane != null && (pane.getUI() instanceof BasicJideTabbedPaneUI)) { |
| 5502 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5503 |
String command = e.getActionCommand(); |
| 5504 |
|
| 5505 |
if (command != null && command.length() > 0) { |
| 5506 |
int mnemonic = (int) e.getActionCommand().charAt(0); |
| 5507 |
if (mnemonic >= 'a' && mnemonic <= 'z') { |
| 5508 |
mnemonic -= ('a' - 'A'); |
| 5509 |
} |
| 5510 |
Integer index = (Integer) ui._mnemonicToIndexMap |
| 5511 |
.get(new Integer(mnemonic)); |
| 5512 |
if (index != null && pane.isEnabledAt(index)) { |
| 5513 |
pane.setSelectedIndex(index); |
| 5514 |
} |
| 5515 |
} |
| 5516 |
} |
| 5517 |
} |
| 5518 |
} |
| 5519 |
|
| 5520 |
/** |
| 5521 |
* Creates a button. |
| 5522 |
* |
| 5523 |
* @param type the button type |
| 5524 |
* @return the button |
| 5525 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#createNoFocusButton(int)} |
| 5526 |
*/ |
| 5527 |
@Deprecated |
| 5528 |
protected TabCloseButton createNoFocusButton(int type) { |
| 5529 |
return new TabCloseButton(type); |
| 5530 |
} |
| 5531 |
|
| 5532 |
private JButton createButton(int type) { |
| 5533 |
return _tabPane.createNoFocusButton(type); |
| 5534 |
} |
| 5535 |
|
| 5536 |
private static class ScrollTabsForwardAction extends AbstractAction { |
| 5537 |
private static final long serialVersionUID = 8772616556895545931L; |
| 5538 |
|
| 5539 |
public ScrollTabsForwardAction() { |
| 5540 |
super(); |
| 5541 |
putValue(Action.SHORT_DESCRIPTION, Resource.getResourceBundle(Locale.getDefault()).getString(BUTTON_NAME_SCROLL_FORWARD)); |
| 5542 |
} |
| 5543 |
|
| 5544 |
public void actionPerformed(ActionEvent e) { |
| 5545 |
JTabbedPane pane = null; |
| 5546 |
Object src = e.getSource(); |
| 5547 |
if (src instanceof JTabbedPane) { |
| 5548 |
pane = (JTabbedPane) src; |
| 5549 |
} |
| 5550 |
else if (src instanceof JideTabbedPane.NoFocusButton) { |
| 5551 |
pane = (JTabbedPane) SwingUtilities.getAncestorOfClass(JTabbedPane.class, (JideTabbedPane.NoFocusButton) src); |
| 5552 |
} |
| 5553 |
|
| 5554 |
if (pane != null) { |
| 5555 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5556 |
|
| 5557 |
if (ui.scrollableTabLayoutEnabled()) { |
| 5558 |
ui._tabScroller.scrollForward(pane.getTabPlacement()); |
| 5559 |
} |
| 5560 |
} |
| 5561 |
} |
| 5562 |
} |
| 5563 |
|
| 5564 |
private static class ScrollTabsBackwardAction extends AbstractAction { |
| 5565 |
private static final long serialVersionUID = -426408621939940046L; |
| 5566 |
|
| 5567 |
public ScrollTabsBackwardAction() { |
| 5568 |
super(); |
| 5569 |
putValue(Action.SHORT_DESCRIPTION, Resource.getResourceBundle(Locale.getDefault()).getString(BUTTON_NAME_SCROLL_BACKWARD)); |
| 5570 |
} |
| 5571 |
|
| 5572 |
public void actionPerformed(ActionEvent e) { |
| 5573 |
JTabbedPane pane = null; |
| 5574 |
Object src = e.getSource(); |
| 5575 |
if (src instanceof JTabbedPane) { |
| 5576 |
pane = (JTabbedPane) src; |
| 5577 |
} |
| 5578 |
else if (src instanceof JideTabbedPane.NoFocusButton) { |
| 5579 |
pane = (JTabbedPane) SwingUtilities.getAncestorOfClass(JTabbedPane.class, (JideTabbedPane.NoFocusButton) src); |
| 5580 |
} |
| 5581 |
|
| 5582 |
if (pane != null) { |
| 5583 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5584 |
|
| 5585 |
if (ui.scrollableTabLayoutEnabled()) { |
| 5586 |
ui._tabScroller.scrollBackward(pane.getTabPlacement()); |
| 5587 |
} |
| 5588 |
} |
| 5589 |
} |
| 5590 |
} |
| 5591 |
|
| 5592 |
|
| 5593 |
private static class ScrollTabsListAction extends AbstractAction { |
| 5594 |
private static final long serialVersionUID = 246103712600916771L; |
| 5595 |
|
| 5596 |
public ScrollTabsListAction() { |
| 5597 |
super(); |
| 5598 |
putValue(Action.SHORT_DESCRIPTION, Resource.getResourceBundle(Locale.getDefault()).getString(BUTTON_NAME_TAB_LIST)); |
| 5599 |
} |
| 5600 |
|
| 5601 |
public void actionPerformed(ActionEvent e) { |
| 5602 |
JTabbedPane pane = null; |
| 5603 |
Object src = e.getSource(); |
| 5604 |
if (src instanceof JTabbedPane) { |
| 5605 |
pane = (JTabbedPane) src; |
| 5606 |
} |
| 5607 |
else if (src instanceof JideTabbedPane.NoFocusButton) { |
| 5608 |
pane = (JTabbedPane) SwingUtilities.getAncestorOfClass(JTabbedPane.class, (JideTabbedPane.NoFocusButton) src); |
| 5609 |
} |
| 5610 |
|
| 5611 |
if (pane instanceof JideTabbedPane) { |
| 5612 |
BasicJideTabbedPaneUI ui = (BasicJideTabbedPaneUI) pane.getUI(); |
| 5613 |
|
| 5614 |
if (ui.scrollableTabLayoutEnabled()) { |
| 5615 |
if (((JideTabbedPane) pane).isTabListPopupVisible()) { |
| 5616 |
((JideTabbedPane) pane).hideTabListPopup(); |
| 5617 |
} |
| 5618 |
else { |
| 5619 |
ui._tabScroller.createPopup(pane.getTabPlacement()); |
| 5620 |
} |
| 5621 |
} |
| 5622 |
} |
| 5623 |
} |
| 5624 |
} |
| 5625 |
|
| 5626 |
protected void stopOrCancelEditing() { |
| 5627 |
boolean isEditValid = true; |
| 5628 |
if (_tabPane != null && _tabPane.isTabEditing() && _tabPane.getTabEditingValidator() != null) { |
| 5629 |
isEditValid = _tabPane.getTabEditingValidator().isValid(_editingTab, _oldPrefix + _tabEditor.getText() + _oldPostfix); |
| 5630 |
} |
| 5631 |
if (isEditValid) |
| 5632 |
_tabPane.stopTabEditing(); |
| 5633 |
else |
| 5634 |
_tabPane.cancelTabEditing(); |
| 5635 |
} |
| 5636 |
|
| 5637 |
private static class CloseTabAction extends AbstractAction { |
| 5638 |
private static final long serialVersionUID = 7779678389793199733L; |
| 5639 |
|
| 5640 |
public CloseTabAction() { |
| 5641 |
super(); |
| 5642 |
putValue(Action.SHORT_DESCRIPTION, Resource.getResourceBundle(Locale.getDefault()).getString(BUTTON_NAME_CLOSE)); |
| 5643 |
} |
| 5644 |
|
| 5645 |
public void actionPerformed(ActionEvent e) { |
| 5646 |
JideTabbedPane pane; |
| 5647 |
Object src = e.getSource(); |
| 5648 |
int index; |
| 5649 |
boolean closeSelected = false; |
| 5650 |
if (src instanceof JideTabbedPane) { |
| 5651 |
pane = (JideTabbedPane) src; |
| 5652 |
} |
| 5653 |
else if (src instanceof JideTabbedPane.NoFocusButton && ((JideTabbedPane.NoFocusButton) src).getParent() instanceof JideTabbedPane) { |
| 5654 |
pane = (JideTabbedPane) ((JideTabbedPane.NoFocusButton) src).getParent(); |
| 5655 |
closeSelected = true; |
| 5656 |
} |
| 5657 |
else if (src instanceof JideTabbedPane.NoFocusButton && ((JideTabbedPane.NoFocusButton) src).getParent() instanceof ScrollableTabPanel) { |
| 5658 |
pane = (JideTabbedPane) SwingUtilities.getAncestorOfClass(JideTabbedPane.class, (JideTabbedPane.NoFocusButton) src); |
| 5659 |
closeSelected = false; |
| 5660 |
} |
| 5661 |
else { |
| 5662 |
return; // shouldn't happen |
| 5663 |
} |
| 5664 |
|
| 5665 |
if (pane.isTabEditing()) { |
| 5666 |
((BasicJideTabbedPaneUI) pane.getUI()).stopOrCancelEditing();//pane.stopTabEditing(); |
| 5667 |
} |
| 5668 |
|
| 5669 |
ActionEvent e2 = e; |
| 5670 |
if (src instanceof JideTabbedPane.NoFocusButton) { |
| 5671 |
index = ((JideTabbedPane.NoFocusButton) src).getIndex(); |
| 5672 |
Component compSrc = index != -1 ? pane.getComponentAt(index) : pane.getSelectedComponent(); |
| 5673 |
// note - We create a new action because we could be in the middle of a chain and |
| 5674 |
// if we just use setSource we could cause problems. |
| 5675 |
// also the AWT documentation pooh-pooh this. (for good reason) |
| 5676 |
if (compSrc != null) |
| 5677 |
e2 = new ActionEvent(compSrc, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()); |
| 5678 |
} |
| 5679 |
else if ("middleMouseButtonClicked".equals(e.getActionCommand())) { |
| 5680 |
index = e.getID(); |
| 5681 |
Component compSrc = index != -1 ? pane.getComponentAt(index) : pane.getSelectedComponent(); |
| 5682 |
// note - We create a new action because we could be in the middle of a chain and |
| 5683 |
// if we just use setSource we could cause problems. |
| 5684 |
// also the AWT documentation pooh-pooh this. (for good reason) |
| 5685 |
if (compSrc != null) |
| 5686 |
e2 = new ActionEvent(compSrc, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()); |
| 5687 |
} |
| 5688 |
|
| 5689 |
if (pane.getCloseAction() != null) { |
| 5690 |
e2 = new ActionEvent(e2.getSource(), e2.getID(), (String) pane.getCloseAction().getValue(Action.ACTION_COMMAND_KEY), e2.getWhen(), e2.getModifiers()); |
| 5691 |
pane.getCloseAction().actionPerformed(e2); |
| 5692 |
} |
| 5693 |
else { |
| 5694 |
if ("middleMouseButtonClicked".equals(e.getActionCommand())) { |
| 5695 |
index = e.getID(); |
| 5696 |
if (index >= 0) |
| 5697 |
pane.removeTabAt(index); |
| 5698 |
if (pane.getTabCount() == 0) { |
| 5699 |
pane.updateUI(); |
| 5700 |
} |
| 5701 |
pane.doLayout(); |
| 5702 |
if (pane.getSelectedIndex() >= 0) { |
| 5703 |
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex()); |
| 5704 |
} |
| 5705 |
} |
| 5706 |
else if (closeSelected) { |
| 5707 |
if (pane.getSelectedIndex() >= 0) |
| 5708 |
pane.removeTabAt(pane.getSelectedIndex()); |
| 5709 |
if (pane.getTabCount() == 0) { |
| 5710 |
pane.updateUI(); |
| 5711 |
} |
| 5712 |
pane.doLayout(); |
| 5713 |
if (pane.getSelectedIndex() >= 0) { |
| 5714 |
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex()); |
| 5715 |
} |
| 5716 |
} |
| 5717 |
else if (src instanceof JideTabbedPane.NoFocusButton) { |
| 5718 |
int i = ((JideTabbedPane.NoFocusButton) src).getIndex(); |
| 5719 |
if (i != -1) { |
| 5720 |
|
| 5721 |
int tabIndex = pane.getSelectedIndex(); |
| 5722 |
|
| 5723 |
pane.removeTabAt(i); |
| 5724 |
|
| 5725 |
if (i < tabIndex) { |
| 5726 |
pane.setSelectedIndex(tabIndex - 1); |
| 5727 |
} |
| 5728 |
|
| 5729 |
if (pane.getTabCount() == 0) { |
| 5730 |
pane.updateUI(); |
| 5731 |
} |
| 5732 |
pane.doLayout(); |
| 5733 |
if (pane.getSelectedIndex() >= 0) { |
| 5734 |
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex()); |
| 5735 |
} |
| 5736 |
} |
| 5737 |
} |
| 5738 |
} |
| 5739 |
} |
| 5740 |
} |
| 5741 |
|
| 5742 |
private class TabContainer extends JPanel implements UIResource { |
| 5743 |
private boolean notifyTabbedPane = true; |
| 5744 |
|
| 5745 |
public TabContainer() { |
| 5746 |
super(null); |
| 5747 |
setOpaque(false); |
| 5748 |
} |
| 5749 |
|
| 5750 |
public void remove(Component comp) { |
| 5751 |
int index = _tabPane.indexOfTabComponent(comp); |
| 5752 |
super.remove(comp); |
| 5753 |
if (notifyTabbedPane && index != -1) { |
| 5754 |
_tabPane.setTabComponentAt(index, null); |
| 5755 |
} |
| 5756 |
} |
| 5757 |
|
| 5758 |
private void removeUnusedTabComponents() { |
| 5759 |
for (Component c : getComponents()) { |
| 5760 |
if (!(c instanceof UIResource)) { |
| 5761 |
int index = _tabPane.indexOfTabComponent(c); |
| 5762 |
if (index == -1) { |
| 5763 |
super.remove(c); |
| 5764 |
} |
| 5765 |
} |
| 5766 |
} |
| 5767 |
} |
| 5768 |
|
| 5769 |
public boolean isOptimizedDrawingEnabled() { |
| 5770 |
return _tabScroller != null; |
| 5771 |
} |
| 5772 |
|
| 5773 |
public void doLayout() { |
| 5774 |
// We layout tabComponents in JTabbedPane's layout manager |
| 5775 |
// and use this method as a hook for repainting tabs |
| 5776 |
// to update tabs area e.g. when the size of tabComponent was changed |
| 5777 |
if (scrollableTabLayoutEnabled()) { |
| 5778 |
_tabScroller.tabPanel.repaint(); |
| 5779 |
// _tabScroller.updateView(); |
| 5780 |
} |
| 5781 |
else { |
| 5782 |
_tabPane.repaint(getBounds()); |
| 5783 |
} |
| 5784 |
} |
| 5785 |
} |
| 5786 |
|
| 5787 |
/** |
| 5788 |
* This inner class is marked "public" due to a compiler bug. This class should be treated as a |
| 5789 |
* "protected" inner class. Instantiate it only within subclasses of VsnetJideTabbedPaneUI. |
| 5790 |
*/ |
| 5791 |
public class TabbedPaneLayout implements LayoutManager { |
| 5792 |
public void addLayoutComponent(String name, Component comp) { |
| 5793 |
} |
| 5794 |
|
| 5795 |
public void removeLayoutComponent(Component comp) { |
| 5796 |
} |
| 5797 |
|
| 5798 |
public Dimension preferredLayoutSize(Container parent) { |
| 5799 |
return calculateSize(false); |
| 5800 |
} |
| 5801 |
|
| 5802 |
public Dimension minimumLayoutSize(Container parent) { |
| 5803 |
return calculateSize(true); |
| 5804 |
} |
| 5805 |
|
| 5806 |
protected Dimension calculateSize(boolean minimum) { |
| 5807 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 5808 |
Insets insets = _tabPane.getInsets(); |
| 5809 |
Insets contentInsets = getContentBorderInsets(tabPlacement); |
| 5810 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 5811 |
|
| 5812 |
Dimension zeroSize = new Dimension(0, 0); |
| 5813 |
int height = contentInsets.top + contentInsets.bottom; |
| 5814 |
int width = contentInsets.left + contentInsets.right; |
| 5815 |
int cWidth = 0; |
| 5816 |
int cHeight = 0; |
| 5817 |
|
| 5818 |
synchronized (this) { |
| 5819 |
ensureCloseButtonCreated(); |
| 5820 |
calculateLayoutInfo(); |
| 5821 |
|
| 5822 |
// Determine minimum size required to display largest |
| 5823 |
// child in each dimension |
| 5824 |
// |
| 5825 |
|
| 5826 |
if (_tabPane.isShowTabContent()) { |
| 5827 |
for (int i = 0; i < _tabPane.getTabCount(); i++) { |
| 5828 |
Component component = _tabPane.getComponentAt(i); |
| 5829 |
if (component != null) { |
| 5830 |
Dimension size = zeroSize; |
| 5831 |
size = minimum ? component.getMinimumSize() : |
| 5832 |
component.getPreferredSize(); |
| 5833 |
|
| 5834 |
if (size != null) { |
| 5835 |
cHeight = Math.max(size.height, cHeight); |
| 5836 |
cWidth = Math.max(size.width, cWidth); |
| 5837 |
} |
| 5838 |
} |
| 5839 |
} |
| 5840 |
// Add content border insets to minimum size |
| 5841 |
width += cWidth; |
| 5842 |
height += cHeight; |
| 5843 |
} |
| 5844 |
|
| 5845 |
int tabExtent; |
| 5846 |
|
| 5847 |
// Calculate how much space the tabs will need, based on the |
| 5848 |
// minimum size required to display largest child + content border |
| 5849 |
// |
| 5850 |
Dimension lsize = new Dimension(0, 0); |
| 5851 |
Dimension tsize = new Dimension(0, 0); |
| 5852 |
|
| 5853 |
if (isTabLeadingComponentVisible()) { |
| 5854 |
lsize = _tabLeadingComponent.getPreferredSize(); |
| 5855 |
} |
| 5856 |
if (isTabTrailingComponentVisible()) { |
| 5857 |
tsize = _tabTrailingComponent.getPreferredSize(); |
| 5858 |
} |
| 5859 |
|
| 5860 |
switch (tabPlacement) { |
| 5861 |
case LEFT: |
| 5862 |
case RIGHT: |
| 5863 |
height = Math.max(height, (minimum ? 0 : calculateMaxTabHeight(tabPlacement)) + tabAreaInsets.top + tabAreaInsets.bottom); |
| 5864 |
tabExtent = calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth); |
| 5865 |
|
| 5866 |
if (isTabLeadingComponentVisible()) { |
| 5867 |
tabExtent = Math.max(lsize.width, tabExtent); |
| 5868 |
} |
| 5869 |
if (isTabTrailingComponentVisible()) { |
| 5870 |
tabExtent = Math.max(tsize.width, tabExtent); |
| 5871 |
} |
| 5872 |
|
| 5873 |
width += tabExtent; |
| 5874 |
break; |
| 5875 |
case TOP: |
| 5876 |
case BOTTOM: |
| 5877 |
default: |
| 5878 |
if (_tabPane.getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT) { |
| 5879 |
width = Math.max(width, (_tabPane.getTabCount() << 2) + |
| 5880 |
tabAreaInsets.left + tabAreaInsets.right); |
| 5881 |
} |
| 5882 |
else { |
| 5883 |
width = Math.max(width, (minimum ? 0 : calculateMaxTabWidth(tabPlacement)) + |
| 5884 |
tabAreaInsets.left + tabAreaInsets.right); |
| 5885 |
} |
| 5886 |
|
| 5887 |
if (_tabPane.isTabShown()) { |
| 5888 |
tabExtent = calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight); |
| 5889 |
|
| 5890 |
if (isTabLeadingComponentVisible()) { |
| 5891 |
tabExtent = Math.max(lsize.height, tabExtent); |
| 5892 |
} |
| 5893 |
if (isTabTrailingComponentVisible()) { |
| 5894 |
tabExtent = Math.max(tsize.height, tabExtent); |
| 5895 |
} |
| 5896 |
|
| 5897 |
height += tabExtent; |
| 5898 |
} |
| 5899 |
} |
| 5900 |
} |
| 5901 |
return new Dimension(width + insets.left + insets.right, |
| 5902 |
height + insets.bottom + insets.top); |
| 5903 |
|
| 5904 |
} |
| 5905 |
|
| 5906 |
protected int preferredTabAreaHeight(int tabPlacement, int width) { |
| 5907 |
int tabCount = _tabPane.getTabCount(); |
| 5908 |
int total = 0; |
| 5909 |
if (tabCount > 0) { |
| 5910 |
int rows = 1; |
| 5911 |
int x = 0; |
| 5912 |
|
| 5913 |
int maxTabHeight = calculateMaxTabHeight(tabPlacement); |
| 5914 |
|
| 5915 |
for (int i = 0; i < tabCount; i++) { |
| 5916 |
FontMetrics metrics = getFontMetrics(i); |
| 5917 |
int tabWidth = calculateTabWidth(tabPlacement, i, metrics); |
| 5918 |
|
| 5919 |
if (x != 0 && x + tabWidth > width) { |
| 5920 |
rows++; |
| 5921 |
x = 0; |
| 5922 |
} |
| 5923 |
x += tabWidth; |
| 5924 |
} |
| 5925 |
total = calculateTabAreaHeight(tabPlacement, rows, maxTabHeight); |
| 5926 |
} |
| 5927 |
return total; |
| 5928 |
} |
| 5929 |
|
| 5930 |
protected int preferredTabAreaWidth(int tabPlacement, int height) { |
| 5931 |
int tabCount = _tabPane.getTabCount(); |
| 5932 |
int total = 0; |
| 5933 |
if (tabCount > 0) { |
| 5934 |
int columns = 1; |
| 5935 |
int y = 0; |
| 5936 |
|
| 5937 |
_maxTabWidth = calculateMaxTabWidth(tabPlacement); |
| 5938 |
|
| 5939 |
for (int i = 0; i < tabCount; i++) { |
| 5940 |
FontMetrics metrics = getFontMetrics(i); |
| 5941 |
int tabHeight = calculateTabHeight(tabPlacement, i, metrics); |
| 5942 |
if (y != 0 && y + tabHeight > height) { |
| 5943 |
columns++; |
| 5944 |
y = 0; |
| 5945 |
} |
| 5946 |
y += tabHeight; |
| 5947 |
} |
| 5948 |
total = calculateTabAreaWidth(tabPlacement, columns, _maxTabWidth); |
| 5949 |
} |
| 5950 |
return total; |
| 5951 |
} |
| 5952 |
|
| 5953 |
public void layoutContainer(Container parent) { |
| 5954 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 5955 |
Insets insets = _tabPane.getInsets(); |
| 5956 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 5957 |
Component visibleComponent = getVisibleComponent(); |
| 5958 |
|
| 5959 |
synchronized (this) { |
| 5960 |
ensureCloseButtonCreated(); |
| 5961 |
calculateLayoutInfo(); |
| 5962 |
|
| 5963 |
if (selectedIndex < 0) { |
| 5964 |
if (visibleComponent != null) { |
| 5965 |
// The last tab was removed, so remove the component |
| 5966 |
setVisibleComponent(null); |
| 5967 |
} |
| 5968 |
} |
| 5969 |
else { |
| 5970 |
int cx, cy, cw, ch; |
| 5971 |
int totalTabWidth = 0; |
| 5972 |
int totalTabHeight = 0; |
| 5973 |
Insets contentInsets = getContentBorderInsets(tabPlacement); |
| 5974 |
|
| 5975 |
Component selectedComponent = _tabPane.getComponentAt(selectedIndex); |
| 5976 |
boolean shouldChangeFocus = false; |
| 5977 |
|
| 5978 |
// In order to allow programs to use a single component |
| 5979 |
// as the display for multiple tabs, we will not change |
| 5980 |
// the visible compnent if the currently selected tab |
| 5981 |
// has a null component. This is a bit dicey, as we don't |
| 5982 |
// explicitly state we support this in the spec, but since |
| 5983 |
// programs are now depending on this, we're making it work. |
| 5984 |
// |
| 5985 |
if (selectedComponent != null) { |
| 5986 |
if (selectedComponent != visibleComponent && visibleComponent != null) { |
| 5987 |
if (JideSwingUtilities.isAncestorOfFocusOwner(visibleComponent) && _tabPane.isAutoRequestFocus()) { |
| 5988 |
shouldChangeFocus = true; |
| 5989 |
} |
| 5990 |
} |
| 5991 |
setVisibleComponent(selectedComponent); |
| 5992 |
} |
| 5993 |
|
| 5994 |
Rectangle bounds = _tabPane.getBounds(); |
| 5995 |
int numChildren = _tabPane.getComponentCount(); |
| 5996 |
|
| 5997 |
if (numChildren > 0) { |
| 5998 |
switch (tabPlacement) { |
| 5999 |
case LEFT: |
| 6000 |
totalTabWidth = calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth); |
| 6001 |
cx = insets.left + totalTabWidth + contentInsets.left; |
| 6002 |
cy = insets.top + contentInsets.top; |
| 6003 |
break; |
| 6004 |
case RIGHT: |
| 6005 |
totalTabWidth = calculateTabAreaWidth(tabPlacement, _runCount, _maxTabWidth); |
| 6006 |
cx = insets.left + contentInsets.left; |
| 6007 |
cy = insets.top + contentInsets.top; |
| 6008 |
break; |
| 6009 |
case BOTTOM: |
| 6010 |
totalTabHeight = calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight); |
| 6011 |
cx = insets.left + contentInsets.left; |
| 6012 |
cy = insets.top + contentInsets.top; |
| 6013 |
break; |
| 6014 |
case TOP: |
| 6015 |
default: |
| 6016 |
totalTabHeight = calculateTabAreaHeight(tabPlacement, _runCount, _maxTabHeight); |
| 6017 |
cx = insets.left + contentInsets.left; |
| 6018 |
cy = insets.top + totalTabHeight + contentInsets.top; |
| 6019 |
} |
| 6020 |
|
| 6021 |
cw = bounds.width - totalTabWidth - |
| 6022 |
insets.left - insets.right - |
| 6023 |
contentInsets.left - contentInsets.right; |
| 6024 |
ch = bounds.height - totalTabHeight - |
| 6025 |
insets.top - insets.bottom - |
| 6026 |
contentInsets.top - contentInsets.bottom; |
| 6027 |
|
| 6028 |
for (int i = 0; i < numChildren; i++) { |
| 6029 |
Component child = _tabPane.getComponent(i); |
| 6030 |
if (child == _tabContainer) { |
| 6031 |
int tabContainerWidth = totalTabWidth == 0 ? bounds.width : totalTabWidth + insets.left + insets.right + contentInsets.left + contentInsets.right; |
| 6032 |
int tabContainerHeight = totalTabHeight == 0 ? bounds.height : totalTabHeight + insets.top + insets.bottom + contentInsets.top + contentInsets.bottom; |
| 6033 |
int tabContainerX = 0; |
| 6034 |
int tabContainerY = 0; |
| 6035 |
if (tabPlacement == BOTTOM) { |
| 6036 |
tabContainerY = bounds.height - tabContainerHeight; |
| 6037 |
} |
| 6038 |
else if (tabPlacement == RIGHT) { |
| 6039 |
tabContainerX = bounds.width - tabContainerWidth; |
| 6040 |
} |
| 6041 |
child.setBounds(tabContainerX, tabContainerY, tabContainerWidth, tabContainerHeight); |
| 6042 |
} |
| 6043 |
else { |
| 6044 |
child.setBounds(cx, cy, cw, ch); |
| 6045 |
} |
| 6046 |
} |
| 6047 |
} |
| 6048 |
|
| 6049 |
layoutTabComponents(); |
| 6050 |
if (shouldChangeFocus) { |
| 6051 |
if (!requestFocusForVisibleComponent()) { |
| 6052 |
if (!_tabPane.requestFocusInWindow()) { |
| 6053 |
_tabPane.requestFocus(); |
| 6054 |
} |
| 6055 |
} |
| 6056 |
} |
| 6057 |
} |
| 6058 |
} |
| 6059 |
} |
| 6060 |
|
| 6061 |
public void calculateLayoutInfo() { |
| 6062 |
int tabCount = _tabPane.getTabCount(); |
| 6063 |
assureRectsCreated(tabCount); |
| 6064 |
calculateTabRects(_tabPane.getTabPlacement(), tabCount); |
| 6065 |
} |
| 6066 |
|
| 6067 |
private void layoutTabComponents() { |
| 6068 |
if (_tabContainer == null) { |
| 6069 |
return; |
| 6070 |
} |
| 6071 |
Rectangle rect = new Rectangle(); |
| 6072 |
Point delta = new Point(-_tabContainer.getX(), -_tabContainer.getY()); |
| 6073 |
if (scrollableTabLayoutEnabled()) { |
| 6074 |
translatePointToTabPanel(0, 0, delta); |
| 6075 |
} |
| 6076 |
for (int i = 0; i < _tabPane.getTabCount(); i++) { |
| 6077 |
Component c = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt(i) : null; |
| 6078 |
if (c == null) { |
| 6079 |
continue; |
| 6080 |
} |
| 6081 |
getTabBounds(i, rect); |
| 6082 |
Dimension preferredSize = c.getPreferredSize(); |
| 6083 |
Insets insets = getTabInsets(_tabPane.getTabPlacement(), i); |
| 6084 |
int outerX = rect.x + insets.left + delta.x; |
| 6085 |
int outerY = rect.y + insets.top + delta.y; |
| 6086 |
int outerWidth = rect.width - insets.left - insets.right; |
| 6087 |
int outerHeight = rect.height - insets.top - insets.bottom; |
| 6088 |
//centralize component |
| 6089 |
int x = outerX + (outerWidth - preferredSize.width) / 2; |
| 6090 |
int y = outerY + (outerHeight - preferredSize.height) / 2; |
| 6091 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 6092 |
boolean isSeleceted = i == _tabPane.getSelectedIndex(); |
| 6093 |
c.setBounds(x + getTabLabelShiftX(tabPlacement, i, isSeleceted), |
| 6094 |
y + getTabLabelShiftY(tabPlacement, i, isSeleceted), |
| 6095 |
preferredSize.width, preferredSize.height); |
| 6096 |
} |
| 6097 |
} |
| 6098 |
|
| 6099 |
protected void calculateTabRects(int tabPlacement, int tabCount) { |
| 6100 |
Dimension size = _tabPane.getSize(); |
| 6101 |
Insets insets = _tabPane.getInsets(); |
| 6102 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 6103 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 6104 |
int tabRunOverlay; |
| 6105 |
int i, j; |
| 6106 |
int x, y; |
| 6107 |
int returnAt; |
| 6108 |
boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT); |
| 6109 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 6110 |
|
| 6111 |
// |
| 6112 |
// Calculate bounds within which a tab run must fit |
| 6113 |
// |
| 6114 |
int calculatedMaxTabHeight = calculateMaxTabHeight(tabPlacement); |
| 6115 |
switch (tabPlacement) { |
| 6116 |
case LEFT: |
| 6117 |
_maxTabWidth = calculateMaxTabWidth(tabPlacement); |
| 6118 |
x = insets.left + tabAreaInsets.left; |
| 6119 |
y = insets.top + tabAreaInsets.top; |
| 6120 |
returnAt = size.height - (insets.bottom + tabAreaInsets.bottom); |
| 6121 |
break; |
| 6122 |
case RIGHT: |
| 6123 |
_maxTabWidth = calculateMaxTabWidth(tabPlacement); |
| 6124 |
x = size.width - insets.right - tabAreaInsets.right - _maxTabWidth; |
| 6125 |
y = insets.top + tabAreaInsets.top; |
| 6126 |
returnAt = size.height - (insets.bottom + tabAreaInsets.bottom); |
| 6127 |
break; |
| 6128 |
case BOTTOM: |
| 6129 |
_maxTabHeight = calculatedMaxTabHeight; |
| 6130 |
x = insets.left + tabAreaInsets.left; |
| 6131 |
y = size.height - insets.bottom - tabAreaInsets.bottom - _maxTabHeight; |
| 6132 |
returnAt = size.width - (insets.right + tabAreaInsets.right); |
| 6133 |
break; |
| 6134 |
case TOP: |
| 6135 |
default: |
| 6136 |
_maxTabHeight = calculatedMaxTabHeight; |
| 6137 |
x = insets.left + tabAreaInsets.left; |
| 6138 |
y = insets.top + tabAreaInsets.top; |
| 6139 |
returnAt = size.width - (insets.right + tabAreaInsets.right); |
| 6140 |
break; |
| 6141 |
} |
| 6142 |
|
| 6143 |
tabRunOverlay = getTabRunOverlay(tabPlacement); |
| 6144 |
|
| 6145 |
_runCount = 0; |
| 6146 |
_selectedRun = -1; |
| 6147 |
|
| 6148 |
if (tabCount == 0) { |
| 6149 |
return; |
| 6150 |
} |
| 6151 |
|
| 6152 |
// Run through tabs and partition them into runs |
| 6153 |
Rectangle rect; |
| 6154 |
for (i = 0; i < tabCount; i++) { |
| 6155 |
FontMetrics metrics = getFontMetrics(i); |
| 6156 |
rect = _rects[i]; |
| 6157 |
|
| 6158 |
if (!verticalTabRuns) { |
| 6159 |
// Tabs on TOP or BOTTOM.... |
| 6160 |
if (i > 0) { |
| 6161 |
rect.x = _rects[i - 1].x + _rects[i - 1].width; |
| 6162 |
} |
| 6163 |
else { |
| 6164 |
_tabRuns[0] = 0; |
| 6165 |
_runCount = 1; |
| 6166 |
_maxTabWidth = 0; |
| 6167 |
rect.x = x; |
| 6168 |
} |
| 6169 |
rect.width = calculateTabWidth(tabPlacement, i, metrics); |
| 6170 |
_maxTabWidth = Math.max(_maxTabWidth, rect.width); |
| 6171 |
|
| 6172 |
// Never move a TAB down a run if it is in the first column. |
| 6173 |
// Even if there isn't enough room, moving it to a fresh |
| 6174 |
// line won't help. |
| 6175 |
if (rect.x != 2 + insets.left && rect.x + rect.width > returnAt) { |
| 6176 |
if (_runCount > _tabRuns.length - 1) { |
| 6177 |
expandTabRunsArray(); |
| 6178 |
} |
| 6179 |
_tabRuns[_runCount] = i; |
| 6180 |
_runCount++; |
| 6181 |
rect.x = x; |
| 6182 |
} |
| 6183 |
// Initialize y position in case there's just one run |
| 6184 |
rect.y = y; |
| 6185 |
rect.height = _maxTabHeight/* - 2 */; |
| 6186 |
|
| 6187 |
} |
| 6188 |
else { |
| 6189 |
// Tabs on LEFT or RIGHT... |
| 6190 |
if (i > 0) { |
| 6191 |
rect.y = _rects[i - 1].y + _rects[i - 1].height; |
| 6192 |
} |
| 6193 |
else { |
| 6194 |
_tabRuns[0] = 0; |
| 6195 |
_runCount = 1; |
| 6196 |
_maxTabHeight = 0; |
| 6197 |
rect.y = y; |
| 6198 |
} |
| 6199 |
rect.height = calculateTabHeight(tabPlacement, i, metrics); |
| 6200 |
_maxTabHeight = Math.max(_maxTabHeight, rect.height); |
| 6201 |
|
| 6202 |
// Never move a TAB over a run if it is in the first run. |
| 6203 |
// Even if there isn't enough room, moving it to a fresh |
| 6204 |
// column won't help. |
| 6205 |
if (rect.y != 2 + insets.top && rect.y + rect.height > returnAt) { |
| 6206 |
if (_runCount > _tabRuns.length - 1) { |
| 6207 |
expandTabRunsArray(); |
| 6208 |
} |
| 6209 |
_tabRuns[_runCount] = i; |
| 6210 |
_runCount++; |
| 6211 |
rect.y = y; |
| 6212 |
} |
| 6213 |
// Initialize x position in case there's just one column |
| 6214 |
rect.x = x; |
| 6215 |
rect.width = _maxTabWidth/* - 2 */; |
| 6216 |
|
| 6217 |
} |
| 6218 |
if (i == selectedIndex) { |
| 6219 |
_selectedRun = _runCount - 1; |
| 6220 |
} |
| 6221 |
} |
| 6222 |
|
| 6223 |
if (_runCount > 1) { |
| 6224 |
// Re-distribute tabs in case last run has leftover space |
| 6225 |
normalizeTabRuns(tabPlacement, tabCount, verticalTabRuns ? y : x, returnAt); |
| 6226 |
|
| 6227 |
_selectedRun = getRunForTab(tabCount, selectedIndex); |
| 6228 |
|
| 6229 |
// Rotate run array so that selected run is first |
| 6230 |
if (shouldRotateTabRuns(tabPlacement)) { |
| 6231 |
rotateTabRuns(tabPlacement, _selectedRun); |
| 6232 |
} |
| 6233 |
} |
| 6234 |
|
| 6235 |
// Step through runs from back to front to calculate |
| 6236 |
// tab y locations and to pad runs appropriately |
| 6237 |
for (i = _runCount - 1; i >= 0; i--) { |
| 6238 |
int start = _tabRuns[i]; |
| 6239 |
int next = _tabRuns[i == (_runCount - 1) ? 0 : i + 1]; |
| 6240 |
int end = (next != 0 ? next - 1 : tabCount - 1); |
| 6241 |
if (!verticalTabRuns) { |
| 6242 |
for (j = start; j <= end; j++) { |
| 6243 |
rect = _rects[j]; |
| 6244 |
rect.y = y; |
| 6245 |
rect.x += getTabRunIndent(tabPlacement, i); |
| 6246 |
} |
| 6247 |
if (shouldPadTabRun(tabPlacement, i)) { |
| 6248 |
padTabRun(tabPlacement, start, end, returnAt); |
| 6249 |
} |
| 6250 |
if (tabPlacement == BOTTOM) { |
| 6251 |
y -= (_maxTabHeight - tabRunOverlay); |
| 6252 |
} |
| 6253 |
else { |
| 6254 |
y += (_maxTabHeight - tabRunOverlay); |
| 6255 |
} |
| 6256 |
} |
| 6257 |
else { |
| 6258 |
for (j = start; j <= end; j++) { |
| 6259 |
rect = _rects[j]; |
| 6260 |
rect.x = x; |
| 6261 |
rect.y += getTabRunIndent(tabPlacement, i); |
| 6262 |
} |
| 6263 |
if (shouldPadTabRun(tabPlacement, i)) { |
| 6264 |
padTabRun(tabPlacement, start, end, returnAt); |
| 6265 |
} |
| 6266 |
if (tabPlacement == RIGHT) { |
| 6267 |
x -= (_maxTabWidth - tabRunOverlay); |
| 6268 |
} |
| 6269 |
else { |
| 6270 |
x += (_maxTabWidth - tabRunOverlay); |
| 6271 |
} |
| 6272 |
} |
| 6273 |
} |
| 6274 |
|
| 6275 |
// Pad the selected tab so that it appears raised in front |
| 6276 |
padSelectedTab(tabPlacement, selectedIndex); |
| 6277 |
|
| 6278 |
// if right to left and tab placement on the top or |
| 6279 |
// the bottom, flip x positions and adjust by widths |
| 6280 |
if (!leftToRight && !verticalTabRuns) { |
| 6281 |
int rightMargin = size.width |
| 6282 |
- (insets.right + tabAreaInsets.right); |
| 6283 |
for (i = 0; i < tabCount; i++) { |
| 6284 |
_rects[i].x = rightMargin - _rects[i].x - _rects[i].width; |
| 6285 |
} |
| 6286 |
} |
| 6287 |
} |
| 6288 |
|
| 6289 |
/* |
| 6290 |
* Rotates the run-index array so that the selected run is run[0] |
| 6291 |
*/ |
| 6292 |
|
| 6293 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 6294 |
protected void rotateTabRuns(int tabPlacement, int selectedRun) { |
| 6295 |
for (int i = 0; i < selectedRun; i++) { |
| 6296 |
int save = _tabRuns[0]; |
| 6297 |
for (int j = 1; j < _runCount; j++) { |
| 6298 |
_tabRuns[j - 1] = _tabRuns[j]; |
| 6299 |
} |
| 6300 |
_tabRuns[_runCount - 1] = save; |
| 6301 |
} |
| 6302 |
} |
| 6303 |
|
| 6304 |
protected void normalizeTabRuns(int tabPlacement, int tabCount, |
| 6305 |
int start, int max) { |
| 6306 |
boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT); |
| 6307 |
int run = _runCount - 1; |
| 6308 |
boolean keepAdjusting = true; |
| 6309 |
double weight = 1.25; |
| 6310 |
|
| 6311 |
// At this point the tab runs are packed to fit as many |
| 6312 |
// tabs as possible, which can leave the last run with a lot |
| 6313 |
// of extra space (resulting in very fat tabs on the last run). |
| 6314 |
// So we'll attempt to distribute this extra space more evenly |
| 6315 |
// across the runs in order to make the runs look more consistent. |
| 6316 |
// |
| 6317 |
// Starting with the last run, determine whether the last tab in |
| 6318 |
// the previous run would fit (generously) in this run; if so, |
| 6319 |
// move tab to current run and shift tabs accordingly. Cycle |
| 6320 |
// through remaining runs using the same algorithm. |
| 6321 |
// |
| 6322 |
while (keepAdjusting) { |
| 6323 |
int last = lastTabInRun(tabCount, run); |
| 6324 |
int prevLast = lastTabInRun(tabCount, run - 1); |
| 6325 |
int end; |
| 6326 |
int prevLastLen; |
| 6327 |
|
| 6328 |
if (!verticalTabRuns) { |
| 6329 |
end = _rects[last].x + _rects[last].width; |
| 6330 |
prevLastLen = (int) (_maxTabWidth * weight); |
| 6331 |
} |
| 6332 |
else { |
| 6333 |
end = _rects[last].y + _rects[last].height; |
| 6334 |
prevLastLen = (int) (_maxTabHeight * weight * 2); |
| 6335 |
} |
| 6336 |
|
| 6337 |
// Check if the run has enough extra space to fit the last tab |
| 6338 |
// from the previous row... |
| 6339 |
if (max - end > prevLastLen) { |
| 6340 |
|
| 6341 |
// Insert tab from previous row and shift rest over |
| 6342 |
_tabRuns[run] = prevLast; |
| 6343 |
if (!verticalTabRuns) { |
| 6344 |
_rects[prevLast].x = start; |
| 6345 |
} |
| 6346 |
else { |
| 6347 |
_rects[prevLast].y = start; |
| 6348 |
} |
| 6349 |
for (int i = prevLast + 1; i <= last; i++) { |
| 6350 |
if (!verticalTabRuns) { |
| 6351 |
_rects[i].x = _rects[i - 1].x + _rects[i - 1].width; |
| 6352 |
} |
| 6353 |
else { |
| 6354 |
_rects[i].y = _rects[i - 1].y + _rects[i - 1].height; |
| 6355 |
} |
| 6356 |
} |
| 6357 |
|
| 6358 |
} |
| 6359 |
else if (run == _runCount - 1) { |
| 6360 |
// no more room left in last run, so we're done! |
| 6361 |
keepAdjusting = false; |
| 6362 |
} |
| 6363 |
if (run - 1 > 0) { |
| 6364 |
// check previous run next... |
| 6365 |
run -= 1; |
| 6366 |
} |
| 6367 |
else { |
| 6368 |
// check last run again...but require a higher ratio |
| 6369 |
// of extraspace-to-tabsize because we don't want to |
| 6370 |
// end up with too many tabs on the last run! |
| 6371 |
run = _runCount - 1; |
| 6372 |
weight += .25; |
| 6373 |
} |
| 6374 |
} |
| 6375 |
} |
| 6376 |
|
| 6377 |
protected void padTabRun(int tabPlacement, int start, int end, int max) { |
| 6378 |
Rectangle lastRect = _rects[end]; |
| 6379 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 6380 |
int runWidth = (lastRect.x + lastRect.width) - _rects[start].x; |
| 6381 |
int deltaWidth = max - (lastRect.x + lastRect.width); |
| 6382 |
float factor = (float) deltaWidth / (float) runWidth; |
| 6383 |
|
| 6384 |
for (int j = start; j <= end; j++) { |
| 6385 |
Rectangle pastRect = _rects[j]; |
| 6386 |
if (j > start) { |
| 6387 |
pastRect.x = _rects[j - 1].x + _rects[j - 1].width; |
| 6388 |
} |
| 6389 |
pastRect.width += Math.round((float) pastRect.width * factor); |
| 6390 |
} |
| 6391 |
lastRect.width = max - lastRect.x; |
| 6392 |
} |
| 6393 |
else { |
| 6394 |
int runHeight = (lastRect.y + lastRect.height) - _rects[start].y; |
| 6395 |
int deltaHeight = max - (lastRect.y + lastRect.height); |
| 6396 |
float factor = (float) deltaHeight / (float) runHeight; |
| 6397 |
|
| 6398 |
for (int j = start; j <= end; j++) { |
| 6399 |
Rectangle pastRect = _rects[j]; |
| 6400 |
if (j > start) { |
| 6401 |
pastRect.y = _rects[j - 1].y + _rects[j - 1].height; |
| 6402 |
} |
| 6403 |
pastRect.height += Math.round((float) pastRect.height * factor); |
| 6404 |
} |
| 6405 |
lastRect.height = max - lastRect.y; |
| 6406 |
} |
| 6407 |
} |
| 6408 |
|
| 6409 |
protected void padSelectedTab(int tabPlacement, int selectedIndex) { |
| 6410 |
|
| 6411 |
if (selectedIndex >= 0) { |
| 6412 |
Rectangle selRect = _rects[selectedIndex]; |
| 6413 |
Insets padInsets = getSelectedTabPadInsets(tabPlacement); |
| 6414 |
selRect.x -= padInsets.left; |
| 6415 |
selRect.width += (padInsets.left + padInsets.right); |
| 6416 |
selRect.y -= padInsets.top; |
| 6417 |
selRect.height += (padInsets.top + padInsets.bottom); |
| 6418 |
} |
| 6419 |
} |
| 6420 |
} |
| 6421 |
|
| 6422 |
protected TabSpaceAllocator tryTabSpacer = new TabSpaceAllocator(); |
| 6423 |
|
| 6424 |
protected class TabbedPaneScrollLayout extends TabbedPaneLayout { |
| 6425 |
|
| 6426 |
@Override |
| 6427 |
protected int preferredTabAreaHeight(int tabPlacement, int width) { |
| 6428 |
return calculateMaxTabHeight(tabPlacement); |
| 6429 |
} |
| 6430 |
|
| 6431 |
@Override |
| 6432 |
protected int preferredTabAreaWidth(int tabPlacement, int height) { |
| 6433 |
return calculateMaxTabWidth(tabPlacement); |
| 6434 |
} |
| 6435 |
|
| 6436 |
@Override |
| 6437 |
public void layoutContainer(Container parent) { |
| 6438 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 6439 |
int tabCount = _tabPane.getTabCount(); |
| 6440 |
Insets insets = _tabPane.getInsets(); |
| 6441 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 6442 |
Component visibleComponent = getVisibleComponent(); |
| 6443 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 6444 |
JViewport viewport = null; |
| 6445 |
|
| 6446 |
calculateLayoutInfo(); |
| 6447 |
|
| 6448 |
if (selectedIndex < 0) { |
| 6449 |
if (visibleComponent != null) { |
| 6450 |
// The last tab was removed, so remove the component |
| 6451 |
setVisibleComponent(null); |
| 6452 |
} |
| 6453 |
|
| 6454 |
} |
| 6455 |
else { |
| 6456 |
Component selectedComponent = selectedIndex >= _tabPane.getTabCount() ? null : _tabPane.getComponentAt(selectedIndex); // check for range because of a change in JDK1.6-rc-b89 |
| 6457 |
boolean shouldChangeFocus = false; |
| 6458 |
|
| 6459 |
// In order to allow programs to use a single component |
| 6460 |
// as the display for multiple tabs, we will not change |
| 6461 |
// the visible compnent if the currently selected tab |
| 6462 |
// has a null component. This is a bit dicey, as we don't |
| 6463 |
// explicitly state we support this in the spec, but since |
| 6464 |
// programs are now depending on this, we're making it work. |
| 6465 |
// |
| 6466 |
if (selectedComponent != null) { |
| 6467 |
if (selectedComponent != visibleComponent && visibleComponent != null) { |
| 6468 |
if (JideSwingUtilities.isAncestorOfFocusOwner(visibleComponent) && _tabPane.isAutoRequestFocus()) { |
| 6469 |
shouldChangeFocus = true; |
| 6470 |
} |
| 6471 |
} |
| 6472 |
setVisibleComponent(selectedComponent); |
| 6473 |
} |
| 6474 |
int tx, ty, tw, th; // tab area bounds |
| 6475 |
int cx, cy, cw, ch; // content area bounds |
| 6476 |
Insets contentInsets = getContentBorderInsets(tabPlacement); |
| 6477 |
Rectangle bounds = _tabPane.getBounds(); |
| 6478 |
int numChildren = _tabPane.getComponentCount(); |
| 6479 |
|
| 6480 |
Dimension lsize = new Dimension(0, 0); |
| 6481 |
Dimension tsize = new Dimension(0, 0); |
| 6482 |
|
| 6483 |
if (isTabLeadingComponentVisible()) { |
| 6484 |
lsize = _tabLeadingComponent.getPreferredSize(); |
| 6485 |
} |
| 6486 |
if (isTabTrailingComponentVisible()) { |
| 6487 |
tsize = _tabTrailingComponent.getPreferredSize(); |
| 6488 |
} |
| 6489 |
|
| 6490 |
if (numChildren > 0) { |
| 6491 |
switch (tabPlacement) { |
| 6492 |
case LEFT: |
| 6493 |
// calculate tab area bounds |
| 6494 |
tw = calculateTabAreaHeight(TOP, _runCount, _maxTabWidth); |
| 6495 |
th = bounds.height - insets.top - insets.bottom; |
| 6496 |
tx = insets.left; |
| 6497 |
ty = insets.top; |
| 6498 |
|
| 6499 |
if (isTabLeadingComponentVisible()) { |
| 6500 |
ty += lsize.height; |
| 6501 |
th -= lsize.height; |
| 6502 |
|
| 6503 |
if (lsize.width > tw) { |
| 6504 |
tw = lsize.width; |
| 6505 |
} |
| 6506 |
} |
| 6507 |
if (isTabTrailingComponentVisible()) { |
| 6508 |
th -= tsize.height; |
| 6509 |
|
| 6510 |
if (tsize.width > tw) { |
| 6511 |
tw = tsize.width; |
| 6512 |
} |
| 6513 |
} |
| 6514 |
|
| 6515 |
// calculate content area bounds |
| 6516 |
cx = tx + tw + contentInsets.left; |
| 6517 |
cy = insets.top + contentInsets.top; |
| 6518 |
cw = bounds.width - insets.left - insets.right - tw - contentInsets.left - contentInsets.right; |
| 6519 |
ch = bounds.height - insets.top - insets.bottom - contentInsets.top - contentInsets.bottom; |
| 6520 |
break; |
| 6521 |
case RIGHT: |
| 6522 |
// calculate tab area bounds |
| 6523 |
tw = calculateTabAreaHeight(TOP, _runCount, |
| 6524 |
_maxTabWidth); |
| 6525 |
th = bounds.height - insets.top - insets.bottom; |
| 6526 |
tx = bounds.width - insets.right - tw; |
| 6527 |
ty = insets.top; |
| 6528 |
|
| 6529 |
if (isTabLeadingComponentVisible()) { |
| 6530 |
ty += lsize.height; |
| 6531 |
th -= lsize.height; |
| 6532 |
|
| 6533 |
if (lsize.width > tw) { |
| 6534 |
tw = lsize.width; |
| 6535 |
tx = bounds.width - insets.right - tw; |
| 6536 |
} |
| 6537 |
} |
| 6538 |
if (isTabTrailingComponentVisible()) { |
| 6539 |
th -= tsize.height; |
| 6540 |
|
| 6541 |
if (tsize.width > tw) { |
| 6542 |
tw = tsize.width; |
| 6543 |
tx = bounds.width - insets.right - tw; |
| 6544 |
} |
| 6545 |
} |
| 6546 |
|
| 6547 |
// calculate content area bounds |
| 6548 |
cx = insets.left + contentInsets.left; |
| 6549 |
cy = insets.top + contentInsets.top; |
| 6550 |
cw = bounds.width - insets.left - insets.right - tw - contentInsets.left - contentInsets.right; |
| 6551 |
ch = bounds.height - insets.top - insets.bottom - contentInsets.top - contentInsets.bottom; |
| 6552 |
break; |
| 6553 |
case BOTTOM: |
| 6554 |
// calculate tab area bounds |
| 6555 |
tw = bounds.width - insets.left - insets.right; |
| 6556 |
th = calculateTabAreaHeight(tabPlacement, _runCount, |
| 6557 |
_maxTabHeight); |
| 6558 |
tx = insets.left; |
| 6559 |
ty = bounds.height - insets.bottom - th; |
| 6560 |
|
| 6561 |
if (leftToRight) { |
| 6562 |
if (isTabLeadingComponentVisible()) { |
| 6563 |
tx += lsize.width; |
| 6564 |
tw -= lsize.width; |
| 6565 |
|
| 6566 |
if (lsize.height > th) { |
| 6567 |
th = lsize.height; |
| 6568 |
ty = bounds.height - insets.bottom - th; |
| 6569 |
} |
| 6570 |
} |
| 6571 |
if (isTabTrailingComponentVisible()) { |
| 6572 |
tw -= tsize.width; |
| 6573 |
|
| 6574 |
if (tsize.height > th) { |
| 6575 |
th = tsize.height; |
| 6576 |
ty = bounds.height - insets.bottom - th; |
| 6577 |
} |
| 6578 |
} |
| 6579 |
} |
| 6580 |
else { |
| 6581 |
if (isTabTrailingComponentVisible()) { |
| 6582 |
tx += tsize.width; |
| 6583 |
tw -= tsize.width; |
| 6584 |
|
| 6585 |
if (tsize.height > th) { |
| 6586 |
th = tsize.height; |
| 6587 |
ty = bounds.height - insets.bottom - th; |
| 6588 |
} |
| 6589 |
} |
| 6590 |
if (isTabLeadingComponentVisible()) { |
| 6591 |
tw -= lsize.width; |
| 6592 |
|
| 6593 |
if (lsize.height > th) { |
| 6594 |
th = lsize.height; |
| 6595 |
ty = bounds.height - insets.bottom - th; |
| 6596 |
} |
| 6597 |
} |
| 6598 |
} |
| 6599 |
|
| 6600 |
// calculate content area bounds |
| 6601 |
cx = insets.left + contentInsets.left; |
| 6602 |
cy = insets.top + contentInsets.top; |
| 6603 |
cw = bounds.width - insets.left - insets.right |
| 6604 |
- contentInsets.left - contentInsets.right; |
| 6605 |
ch = bounds.height - insets.top - insets.bottom - th - contentInsets.top - contentInsets.bottom; |
| 6606 |
break; |
| 6607 |
case TOP: |
| 6608 |
default: |
| 6609 |
// calculate tab area bounds |
| 6610 |
tw = bounds.width - insets.left - insets.right; |
| 6611 |
th = calculateTabAreaHeight(tabPlacement, _runCount, |
| 6612 |
_maxTabHeight); |
| 6613 |
tx = insets.left; |
| 6614 |
ty = insets.top; |
| 6615 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 6616 |
if (tabAreaInsets != null) { // TODO: after adding this, setting trailing/leading components cause painting issue in the tab area insets area |
| 6617 |
tx += tabAreaInsets.left; |
| 6618 |
tw -= tabAreaInsets.left + tabAreaInsets.right; |
| 6619 |
} |
| 6620 |
|
| 6621 |
if (leftToRight) { |
| 6622 |
if (isTabLeadingComponentVisible()) { |
| 6623 |
tx += lsize.width; |
| 6624 |
tw -= lsize.width; |
| 6625 |
|
| 6626 |
if (lsize.height > th) { |
| 6627 |
th = lsize.height; |
| 6628 |
} |
| 6629 |
} |
| 6630 |
if (isTabTrailingComponentVisible()) { |
| 6631 |
tw -= tsize.width; |
| 6632 |
|
| 6633 |
if (tsize.height > th) { |
| 6634 |
th = tsize.height; |
| 6635 |
} |
| 6636 |
} |
| 6637 |
} |
| 6638 |
else { |
| 6639 |
if (isTabTrailingComponentVisible()) { |
| 6640 |
tx += tsize.width; |
| 6641 |
tw -= tsize.width; |
| 6642 |
|
| 6643 |
if (tsize.height > th) { |
| 6644 |
th = tsize.height; |
| 6645 |
} |
| 6646 |
} |
| 6647 |
if (isTabLeadingComponentVisible()) { |
| 6648 |
tw -= lsize.width; |
| 6649 |
|
| 6650 |
if (lsize.height > th) { |
| 6651 |
th = lsize.height; |
| 6652 |
} |
| 6653 |
} |
| 6654 |
} |
| 6655 |
|
| 6656 |
// calculate content area bounds |
| 6657 |
cx = insets.left + contentInsets.left; |
| 6658 |
cy = insets.top + th + contentInsets.top; |
| 6659 |
cw = bounds.width - insets.left - insets.right - contentInsets.left - contentInsets.right; |
| 6660 |
ch = bounds.height - insets.top - insets.bottom - th - contentInsets.top - contentInsets.bottom; |
| 6661 |
} |
| 6662 |
|
| 6663 |
// if (tabPlacement == JideTabbedPane.TOP || tabPlacement == JideTabbedPane.BOTTOM) { |
| 6664 |
// if (getTabResizeMode() != JideTabbedPane.RESIZE_MODE_FIT) { |
| 6665 |
// int numberOfButtons = isShrinkTabs() ? 1 : 4; |
| 6666 |
// if (tw < _rects[0].width + numberOfButtons * _buttonSize) { |
| 6667 |
// return; |
| 6668 |
// } |
| 6669 |
// } |
| 6670 |
// } |
| 6671 |
// else { |
| 6672 |
// if (getTabResizeMode() != JideTabbedPane.RESIZE_MODE_FIT) { |
| 6673 |
// int numberOfButtons = isShrinkTabs() ? 1 : 4; |
| 6674 |
// if (th < _rects[0].height + numberOfButtons * _buttonSize) { |
| 6675 |
// return; |
| 6676 |
// } |
| 6677 |
// } |
| 6678 |
// } |
| 6679 |
|
| 6680 |
for (int i = 0; i < numChildren; i++) { |
| 6681 |
Component child = _tabPane.getComponent(i); |
| 6682 |
boolean tabButtonsVisible = true; |
| 6683 |
|
| 6684 |
if (child instanceof ScrollableTabViewport) { |
| 6685 |
viewport = (JViewport) child; |
| 6686 |
// Rectangle viewRect = viewport.getViewRect(); |
| 6687 |
int vx = tx; |
| 6688 |
int vw = tw; |
| 6689 |
int vy = ty; |
| 6690 |
int vh = th; |
| 6691 |
int numberOfButtons = getNumberOfTabButtons(); |
| 6692 |
switch (tabPlacement) { |
| 6693 |
case LEFT: |
| 6694 |
case RIGHT: |
| 6695 |
int totalTabHeight = _rects[tabCount - 1].y + _rects[tabCount - 1].height; |
| 6696 |
if ((totalTabHeight > th && _tabPane.getTabCount() > 1) || isShowTabButtons()) { |
| 6697 |
if (!isShowTabButtons()) numberOfButtons += 3; |
| 6698 |
// Allow space for scrollbuttons |
| 6699 |
vh = Math.max(th - _buttonSize * numberOfButtons, 0); |
| 6700 |
// if (totalTabHeight - viewRect.y <= vh) { |
| 6701 |
// // Scrolled to the end, so ensure the |
| 6702 |
// // viewport size is |
| 6703 |
// // such that the scroll offset aligns |
| 6704 |
// // with a tab |
| 6705 |
// vh = totalTabHeight - viewRect.y; |
| 6706 |
// } |
| 6707 |
} |
| 6708 |
else { |
| 6709 |
// Allow space for scrollbuttons |
| 6710 |
vh = Math.max(th - _buttonSize * numberOfButtons, 0); |
| 6711 |
tabButtonsVisible = false; |
| 6712 |
} |
| 6713 |
|
| 6714 |
if (vh + getLayoutSize() < th - _buttonSize * numberOfButtons) { |
| 6715 |
vh += getLayoutSize(); |
| 6716 |
} |
| 6717 |
break; |
| 6718 |
case BOTTOM: |
| 6719 |
case TOP: |
| 6720 |
default: |
| 6721 |
int totalTabWidth = 0; |
| 6722 |
if (_rects.length > 0) { |
| 6723 |
if (leftToRight) { |
| 6724 |
totalTabWidth = _rects[tabCount - 1].x + _rects[tabCount - 1].width; |
| 6725 |
} |
| 6726 |
else { |
| 6727 |
totalTabWidth = _rects[0].x + _rects[0].width + getLeftMargin(); |
| 6728 |
} |
| 6729 |
} |
| 6730 |
boolean widthEnough = totalTabWidth <= tw || _tabPane.getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT; |
| 6731 |
if (isShowTabButtons() || (!widthEnough && _tabPane.getTabCount() > 1)) { |
| 6732 |
if (!isShowTabButtons()) numberOfButtons += 3; |
| 6733 |
// Need to allow space for scrollbuttons |
| 6734 |
vw = Math.max(tw - _buttonSize * numberOfButtons, 0); |
| 6735 |
if (!leftToRight) { |
| 6736 |
vx += _buttonSize * numberOfButtons; |
| 6737 |
} |
| 6738 |
|
| 6739 |
// if (totalTabWidth - viewRect.x <= vw) { |
| 6740 |
// // Scrolled to the end, so ensure the |
| 6741 |
// // viewport size is |
| 6742 |
// // such that the scroll offset aligns |
| 6743 |
// // with a tab |
| 6744 |
// vw = totalTabWidth - viewRect.x; |
| 6745 |
// } |
| 6746 |
} |
| 6747 |
else { |
| 6748 |
tabButtonsVisible = false; |
| 6749 |
// Allow space for scrollbuttons |
| 6750 |
vw = Math.max(tw - _buttonSize * numberOfButtons, 0); |
| 6751 |
if (!leftToRight) { |
| 6752 |
vx += _buttonSize * numberOfButtons; |
| 6753 |
} |
| 6754 |
} |
| 6755 |
if (vw + getLayoutSize() < tw - _buttonSize * numberOfButtons) { |
| 6756 |
vw += getLayoutSize(); |
| 6757 |
if (!leftToRight) { |
| 6758 |
vx -= getLayoutSize(); |
| 6759 |
} |
| 6760 |
} |
| 6761 |
break; |
| 6762 |
} |
| 6763 |
if (_tabTrailingComponent != null && _tabPane.isHideTrailingWhileNoButtons()) { |
| 6764 |
_tabTrailingComponent.setVisible(tabButtonsVisible); |
| 6765 |
} |
| 6766 |
child.setBounds(vx, vy, vw, vh); |
| 6767 |
try { |
| 6768 |
if (!leftToRight && (tabPlacement == TOP || tabPlacement == BOTTOM)) { |
| 6769 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT) { |
| 6770 |
viewport.setViewPosition(new Point(0, 0)); |
| 6771 |
} |
| 6772 |
else if (!_layouted) { |
| 6773 |
_tabScroller.setLeadingTabIndex(tabPlacement, 0); |
| 6774 |
} |
| 6775 |
} |
| 6776 |
} |
| 6777 |
finally { |
| 6778 |
_layouted = true; |
| 6779 |
} |
| 6780 |
} |
| 6781 |
else if (child instanceof JideTabbedPane.NoFocusButton) { |
| 6782 |
JideTabbedPane.NoFocusButton scrollbutton = (JideTabbedPane.NoFocusButton) child; |
| 6783 |
if (_tabPane.isTabShown() && (scrollbutton.getType() != JideTabbedPane.BUTTON_CLOSE || !isShowCloseButtonOnTab())) { |
| 6784 |
Dimension bsize = scrollbutton.getPreferredSize(); |
| 6785 |
int bx = 0; |
| 6786 |
int by = 0; |
| 6787 |
int bw = bsize.width; |
| 6788 |
int bh = bsize.height; |
| 6789 |
boolean visible = false; |
| 6790 |
|
| 6791 |
switch (tabPlacement) { |
| 6792 |
case LEFT: |
| 6793 |
case RIGHT: |
| 6794 |
int totalTabHeight = _rects[tabCount - 1].y + _rects[tabCount - 1].height; |
| 6795 |
if (_tabPane.isTabShown() && (isShowTabButtons() || (totalTabHeight > th && _tabPane.getTabCount() > 1))) { |
| 6796 |
int dir = scrollbutton.getType();//NoFocusButton.BUTTON_EAST : NoFocusButton.BUTTON_WEST; |
| 6797 |
scrollbutton.setType(dir); |
| 6798 |
switch (dir) { |
| 6799 |
case JideTabbedPane.BUTTON_CLOSE: |
| 6800 |
if (isShowCloseButton()) { |
| 6801 |
visible = true; |
| 6802 |
by = bounds.height - insets.top - bsize.height - 5; |
| 6803 |
} |
| 6804 |
else { |
| 6805 |
visible = false; |
| 6806 |
by = 0; |
| 6807 |
} |
| 6808 |
break; |
| 6809 |
case JideTabbedPane.BUTTON_LIST: |
| 6810 |
visible = true; |
| 6811 |
by = bounds.height - insets.top - (2 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.height - 5; |
| 6812 |
break; |
| 6813 |
case JideTabbedPane.BUTTON_EAST: |
| 6814 |
visible = !isShrinkTabs(); |
| 6815 |
by = bounds.height - insets.top - (3 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.height - 5; |
| 6816 |
break; |
| 6817 |
case JideTabbedPane.BUTTON_WEST: |
| 6818 |
visible = !isShrinkTabs(); |
| 6819 |
by = bounds.height - insets.top - (4 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.height - 5; |
| 6820 |
break; |
| 6821 |
} |
| 6822 |
bx = tx + 2; |
| 6823 |
|
| 6824 |
} |
| 6825 |
else { |
| 6826 |
tabButtonsVisible = false; |
| 6827 |
int dir = scrollbutton.getType(); |
| 6828 |
scrollbutton.setType(dir); |
| 6829 |
if (dir == JideTabbedPane.BUTTON_CLOSE) { |
| 6830 |
if (isShowCloseButton()) { |
| 6831 |
visible = true; |
| 6832 |
by = bounds.height - insets.top - bsize.height - 5; |
| 6833 |
} |
| 6834 |
else { |
| 6835 |
visible = false; |
| 6836 |
by = 0; |
| 6837 |
} |
| 6838 |
bx = tx + 2; |
| 6839 |
} |
| 6840 |
} |
| 6841 |
if (_tabTrailingComponent != null && _tabPane.isHideTrailingWhileNoButtons()) { |
| 6842 |
_tabTrailingComponent.setVisible(tabButtonsVisible); |
| 6843 |
} |
| 6844 |
if (isTabTrailingComponentVisible()) { |
| 6845 |
by = by - tsize.height; |
| 6846 |
} |
| 6847 |
int temp = -1; |
| 6848 |
if (isTabLeadingComponentVisible()) { |
| 6849 |
if (lsize.width >= _rects[0].width) { |
| 6850 |
if (tabPlacement == LEFT) { |
| 6851 |
bx += lsize.width - _rects[0].width; |
| 6852 |
temp = lsize.width; |
| 6853 |
} |
| 6854 |
} |
| 6855 |
} |
| 6856 |
if (isTabTrailingComponentVisible()) { |
| 6857 |
if (tsize.width >= _rects[0].width |
| 6858 |
&& temp < tsize.width) { |
| 6859 |
if (tabPlacement == LEFT) { |
| 6860 |
bx += tsize.width - _rects[0].width; |
| 6861 |
} |
| 6862 |
} |
| 6863 |
} |
| 6864 |
break; |
| 6865 |
case TOP: |
| 6866 |
case BOTTOM: |
| 6867 |
default: |
| 6868 |
int totalTabWidth = 0; |
| 6869 |
if (_rects.length > 0) { |
| 6870 |
if (leftToRight) { |
| 6871 |
totalTabWidth = _rects[tabCount - 1].x + _rects[tabCount - 1].width; |
| 6872 |
} |
| 6873 |
else { |
| 6874 |
totalTabWidth = _rects[0].x + _rects[0].width + _additionalWidth; |
| 6875 |
} |
| 6876 |
} |
| 6877 |
boolean widthEnough = totalTabWidth <= tw || _tabPane.getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT; |
| 6878 |
if (_tabPane.isTabShown() && (isShowTabButtons() || (!widthEnough && _tabPane.getTabCount() > 1) || (scrollbutton.getType() == JideTabbedPane.BUTTON_CLOSE && isShowCloseButton()))) { |
| 6879 |
int dir = scrollbutton.getType();// NoFocusButton.BUTTON_EAST |
| 6880 |
// NoFocusButton.BUTTON_WEST; |
| 6881 |
scrollbutton.setType(dir); |
| 6882 |
switch (dir) { |
| 6883 |
case JideTabbedPane.BUTTON_CLOSE: |
| 6884 |
if (isShowCloseButton()) { |
| 6885 |
visible = true; |
| 6886 |
if (leftToRight) { |
| 6887 |
bx = bounds.width - insets.left - bsize.width - 5; |
| 6888 |
} |
| 6889 |
else { |
| 6890 |
bx = insets.left - 5; |
| 6891 |
} |
| 6892 |
} |
| 6893 |
else { |
| 6894 |
visible = false; |
| 6895 |
bx = 0; |
| 6896 |
} |
| 6897 |
break; |
| 6898 |
case JideTabbedPane.BUTTON_LIST: |
| 6899 |
visible = true; |
| 6900 |
if (leftToRight) { |
| 6901 |
bx = bounds.width - insets.left - (2 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width - 5; |
| 6902 |
} |
| 6903 |
else { |
| 6904 |
bx = insets.left + (1 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width + 5; |
| 6905 |
} |
| 6906 |
break; |
| 6907 |
case JideTabbedPane.BUTTON_EAST: |
| 6908 |
visible = !isShrinkTabs(); |
| 6909 |
if (leftToRight) { |
| 6910 |
bx = bounds.width - insets.left - (3 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width - 5; |
| 6911 |
} |
| 6912 |
else { |
| 6913 |
bx = insets.left + (2 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width + 5; |
| 6914 |
} |
| 6915 |
break; |
| 6916 |
case JideTabbedPane.BUTTON_WEST: |
| 6917 |
visible = !isShrinkTabs(); |
| 6918 |
if (leftToRight) { |
| 6919 |
bx = bounds.width - insets.left - (4 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width - 5; |
| 6920 |
} |
| 6921 |
else { |
| 6922 |
bx = insets.left + (3 - (!isShowCloseButton() || isShowCloseButtonOnTab() ? 1 : 0)) * bsize.width + 5; |
| 6923 |
} |
| 6924 |
break; |
| 6925 |
} |
| 6926 |
by = ((th - bsize.height) >> 1) + ty; |
| 6927 |
|
| 6928 |
} |
| 6929 |
else { |
| 6930 |
tabButtonsVisible = false; |
| 6931 |
int dir = scrollbutton.getType(); |
| 6932 |
scrollbutton.setType(dir); |
| 6933 |
if (dir == JideTabbedPane.BUTTON_CLOSE) { |
| 6934 |
if (isShowCloseButton()) { |
| 6935 |
visible = true; |
| 6936 |
bx = bounds.width - insets.left - bsize.width - 5; |
| 6937 |
} |
| 6938 |
else { |
| 6939 |
visible = false; |
| 6940 |
bx = 0; |
| 6941 |
} |
| 6942 |
by = ((th - bsize.height) >> 1) + ty; |
| 6943 |
} |
| 6944 |
} |
| 6945 |
if (_tabTrailingComponent != null && _tabPane.isHideTrailingWhileNoButtons()) { |
| 6946 |
_tabTrailingComponent.setVisible(tabButtonsVisible); |
| 6947 |
} |
| 6948 |
if (isTabTrailingComponentVisible()) { |
| 6949 |
if (leftToRight) { |
| 6950 |
bx -= tsize.width; |
| 6951 |
} |
| 6952 |
else { |
| 6953 |
bx += tsize.width; |
| 6954 |
} |
| 6955 |
} |
| 6956 |
temp = -1; |
| 6957 |
if (isTabLeadingComponentVisible()) { |
| 6958 |
if (lsize.height >= _rects[0].height) { |
| 6959 |
if (tabPlacement == TOP) { |
| 6960 |
by = ty + 2 + lsize.height - _rects[0].height; |
| 6961 |
temp = lsize.height; |
| 6962 |
} |
| 6963 |
else { |
| 6964 |
by = ty + 2; |
| 6965 |
} |
| 6966 |
} |
| 6967 |
} |
| 6968 |
if (isTabTrailingComponentVisible()) { |
| 6969 |
if (tsize.height >= _rects[0].height |
| 6970 |
&& temp < tsize.height) { |
| 6971 |
if (tabPlacement == TOP) { |
| 6972 |
by = ty + 2 + tsize.height - _rects[0].height; |
| 6973 |
} |
| 6974 |
else { |
| 6975 |
by = ty + 2; |
| 6976 |
} |
| 6977 |
} |
| 6978 |
} |
| 6979 |
|
| 6980 |
} |
| 6981 |
|
| 6982 |
child.setVisible(visible); |
| 6983 |
if (visible) { |
| 6984 |
child.setBounds(bx, by, bw, bh); |
| 6985 |
} |
| 6986 |
} |
| 6987 |
else { |
| 6988 |
scrollbutton.setBounds(0, 0, 0, 0); |
| 6989 |
} |
| 6990 |
} |
| 6991 |
else if (child != _tabPane.getTabLeadingComponent() && child != _tabPane.getTabTrailingComponent()) { |
| 6992 |
if (_tabPane.isShowTabContent()) { |
| 6993 |
// All content children... |
| 6994 |
child.setBounds(cx, cy, cw, ch); |
| 6995 |
} |
| 6996 |
else { |
| 6997 |
child.setBounds(0, 0, 0, 0); |
| 6998 |
} |
| 6999 |
} |
| 7000 |
} |
| 7001 |
|
| 7002 |
if (leftToRight) { |
| 7003 |
if (isTabLeadingComponentVisible()) { |
| 7004 |
switch (_tabPane.getTabPlacement()) { |
| 7005 |
case LEFT: |
| 7006 |
_tabLeadingComponent.setBounds(tx + tw - lsize.width, ty - lsize.height, lsize.width, lsize.height); |
| 7007 |
break; |
| 7008 |
case RIGHT: |
| 7009 |
_tabLeadingComponent.setBounds(tx, ty - lsize.height, lsize.width, lsize.height); |
| 7010 |
break; |
| 7011 |
case BOTTOM: |
| 7012 |
_tabLeadingComponent.setBounds(tx - lsize.width, ty, lsize.width, lsize.height); |
| 7013 |
break; |
| 7014 |
case TOP: |
| 7015 |
default: |
| 7016 |
_tabLeadingComponent.setBounds(tx - lsize.width, ty + th - lsize.height, lsize.width, lsize.height); |
| 7017 |
break; |
| 7018 |
} |
| 7019 |
|
| 7020 |
} |
| 7021 |
|
| 7022 |
if (isTabTrailingComponentVisible()) { |
| 7023 |
switch (_tabPane.getTabPlacement()) { |
| 7024 |
case LEFT: |
| 7025 |
_tabTrailingComponent.setBounds(tx + tw - tsize.width, ty + th, tsize.width, tsize.height); |
| 7026 |
break; |
| 7027 |
case RIGHT: |
| 7028 |
_tabTrailingComponent.setBounds(tx, ty + th, tsize.width, tsize.height); |
| 7029 |
break; |
| 7030 |
case BOTTOM: |
| 7031 |
_tabTrailingComponent.setBounds(tx + tw, ty, tsize.width, tsize.height); |
| 7032 |
break; |
| 7033 |
case TOP: |
| 7034 |
default: |
| 7035 |
_tabTrailingComponent.setBounds(tx + tw, ty + th - tsize.height, tsize.width, tsize.height); |
| 7036 |
break; |
| 7037 |
} |
| 7038 |
} |
| 7039 |
} |
| 7040 |
else { |
| 7041 |
if (isTabTrailingComponentVisible()) { |
| 7042 |
switch (_tabPane.getTabPlacement()) { |
| 7043 |
case LEFT: |
| 7044 |
_tabTrailingComponent.setBounds(tx + tw - tsize.width, ty - tsize.height, tsize.width, tsize.height); |
| 7045 |
break; |
| 7046 |
case RIGHT: |
| 7047 |
_tabTrailingComponent.setBounds(tx, ty - tsize.height, tsize.width, tsize.height); |
| 7048 |
break; |
| 7049 |
case BOTTOM: |
| 7050 |
_tabTrailingComponent.setBounds(tx - tsize.width, ty, tsize.width, tsize.height); |
| 7051 |
break; |
| 7052 |
case TOP: |
| 7053 |
default: |
| 7054 |
_tabTrailingComponent.setBounds(tx - tsize.width, ty + th - tsize.height, tsize.width, tsize.height); |
| 7055 |
break; |
| 7056 |
} |
| 7057 |
|
| 7058 |
} |
| 7059 |
|
| 7060 |
if (isTabLeadingComponentVisible()) { |
| 7061 |
switch (_tabPane.getTabPlacement()) { |
| 7062 |
case LEFT: |
| 7063 |
_tabLeadingComponent.setBounds(tx + tw - lsize.width, ty + th, lsize.width, lsize.height); |
| 7064 |
break; |
| 7065 |
case RIGHT: |
| 7066 |
_tabLeadingComponent.setBounds(tx, ty + th, lsize.width, lsize.height); |
| 7067 |
break; |
| 7068 |
case BOTTOM: |
| 7069 |
_tabLeadingComponent.setBounds(tx + tw, ty, lsize.width, lsize.height); |
| 7070 |
break; |
| 7071 |
case TOP: |
| 7072 |
default: |
| 7073 |
_tabLeadingComponent.setBounds(tx + tw, ty + th - lsize.height, lsize.width, lsize.height); |
| 7074 |
break; |
| 7075 |
} |
| 7076 |
} |
| 7077 |
} |
| 7078 |
|
| 7079 |
boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT); |
| 7080 |
if (isTabTrailingComponentVisible() && _tabPane.isLayoutTrailingComponentBeforeButtons()) { |
| 7081 |
List<JButton> buttons = new ArrayList<JButton>(); |
| 7082 |
for (int i = 0; i < numChildren; i++) { |
| 7083 |
Component child = _tabPane.getComponent(i); |
| 7084 |
if (child instanceof JButton && child instanceof UIResource && child != _tabLeadingComponent && child != _tabTrailingComponent && child.isVisible() && child.getBounds().width != 0) { |
| 7085 |
buttons.add((JButton) child); |
| 7086 |
} |
| 7087 |
} |
| 7088 |
if (buttons.size() > 0) { |
| 7089 |
Rectangle lastButtonRect = buttons.get(buttons.size() - 1).getBounds(); |
| 7090 |
Rectangle firstButtonRect = buttons.get(0).getBounds(); |
| 7091 |
Rectangle trailingCompRect = _tabTrailingComponent.getBounds(); |
| 7092 |
if (!verticalTabRuns) { |
| 7093 |
_tabTrailingComponent.setBounds(new Rectangle(firstButtonRect.x, trailingCompRect.y, trailingCompRect.width, trailingCompRect.height)); |
| 7094 |
int offset = _tabTrailingComponent.getWidth() - (lastButtonRect.x + lastButtonRect.width - firstButtonRect.x); |
| 7095 |
for (JButton button : buttons) { |
| 7096 |
Rectangle buttonRect = button.getBounds(); |
| 7097 |
button.setBounds(trailingCompRect.x + offset + buttonRect.x - firstButtonRect.x, buttonRect.y, buttonRect.width, buttonRect.height); |
| 7098 |
} |
| 7099 |
} |
| 7100 |
else { |
| 7101 |
_tabTrailingComponent.setBounds(new Rectangle(trailingCompRect.x, firstButtonRect.y, trailingCompRect.width, trailingCompRect.height)); |
| 7102 |
int offset = _tabTrailingComponent.getHeight() - (lastButtonRect.y + lastButtonRect.height - firstButtonRect.y); |
| 7103 |
for (JButton button : buttons) { |
| 7104 |
Rectangle buttonRect = button.getBounds(); |
| 7105 |
button.setBounds(buttonRect.x, trailingCompRect.y + offset + buttonRect.y - firstButtonRect.y, buttonRect.width, buttonRect.height); |
| 7106 |
} |
| 7107 |
} |
| 7108 |
} |
| 7109 |
} |
| 7110 |
if (!leftToRight && !verticalTabRuns && viewport != null && !viewport.getSize().equals(_tabPane.getSize())) { |
| 7111 |
int offset = _tabScroller.tabPanel.getWidth() - viewport.getWidth(); |
| 7112 |
// viewport.setViewPosition(new Point(offset, 0)); |
| 7113 |
} |
| 7114 |
updateCloseButtons(); |
| 7115 |
super.layoutTabComponents(); |
| 7116 |
if (shouldChangeFocus) { |
| 7117 |
if (!requestFocusForVisibleComponent()) { |
| 7118 |
if (!_tabPane.requestFocusInWindow()) { |
| 7119 |
_tabPane.requestFocus(); |
| 7120 |
} |
| 7121 |
} |
| 7122 |
} |
| 7123 |
} |
| 7124 |
} |
| 7125 |
} |
| 7126 |
|
| 7127 |
@Override |
| 7128 |
protected void calculateTabRects(int tabPlacement, int tabCount) { |
| 7129 |
Dimension size = _tabPane.getSize(); |
| 7130 |
Insets insets = _tabPane.getInsets(); |
| 7131 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 7132 |
boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT); |
| 7133 |
boolean leftToRight = _tabPane.getComponentOrientation().isLeftToRight(); |
| 7134 |
int x = tabAreaInsets.left; |
| 7135 |
int y = tabAreaInsets.top; |
| 7136 |
|
| 7137 |
// |
| 7138 |
// Calculate bounds within which a tab run must fit |
| 7139 |
// |
| 7140 |
Dimension lsize = new Dimension(0, 0); |
| 7141 |
Dimension tsize = new Dimension(0, 0); |
| 7142 |
|
| 7143 |
if (isTabLeadingComponentVisible()) { |
| 7144 |
lsize = _tabLeadingComponent.getPreferredSize(); |
| 7145 |
} |
| 7146 |
if (isTabTrailingComponentVisible()) { |
| 7147 |
tsize = _tabTrailingComponent.getPreferredSize(); |
| 7148 |
} |
| 7149 |
|
| 7150 |
int calculatedMaxTabHeight = calculateMaxTabHeight(tabPlacement); |
| 7151 |
switch (tabPlacement) { |
| 7152 |
case LEFT: |
| 7153 |
case RIGHT: |
| 7154 |
_maxTabWidth = calculateMaxTabWidth(tabPlacement); |
| 7155 |
if (isTabLeadingComponentVisible()) { |
| 7156 |
if (tabPlacement == RIGHT) { |
| 7157 |
if (_maxTabWidth < lsize.width) { |
| 7158 |
_maxTabWidth = lsize.width; |
| 7159 |
} |
| 7160 |
} |
| 7161 |
} |
| 7162 |
if (isTabTrailingComponentVisible()) { |
| 7163 |
if (tabPlacement == RIGHT) { |
| 7164 |
if (_maxTabWidth < tsize.width) { |
| 7165 |
_maxTabWidth = tsize.width; |
| 7166 |
} |
| 7167 |
} |
| 7168 |
} |
| 7169 |
break; |
| 7170 |
case BOTTOM: |
| 7171 |
case TOP: |
| 7172 |
default: |
| 7173 |
_maxTabHeight = calculatedMaxTabHeight; |
| 7174 |
if (isTabLeadingComponentVisible()) { |
| 7175 |
if (tabPlacement == BOTTOM) { |
| 7176 |
if (_maxTabHeight < lsize.height) { |
| 7177 |
_maxTabHeight = lsize.height; |
| 7178 |
} |
| 7179 |
} |
| 7180 |
} |
| 7181 |
if (isTabTrailingComponentVisible()) { |
| 7182 |
if (tabPlacement == BOTTOM) { |
| 7183 |
if (_maxTabHeight < tsize.height) { |
| 7184 |
_maxTabHeight = tsize.height; |
| 7185 |
} |
| 7186 |
} |
| 7187 |
} |
| 7188 |
} |
| 7189 |
|
| 7190 |
_runCount = 0; |
| 7191 |
_selectedRun = -1; |
| 7192 |
|
| 7193 |
if (tabCount == 0) { |
| 7194 |
return; |
| 7195 |
} |
| 7196 |
|
| 7197 |
_selectedRun = 0; |
| 7198 |
_runCount = 1; |
| 7199 |
|
| 7200 |
// Run through tabs and lay them out in a single run |
| 7201 |
Rectangle rect; |
| 7202 |
for (int i = 0; i < tabCount; i++) { |
| 7203 |
FontMetrics metrics = getFontMetrics(i); |
| 7204 |
rect = _rects[i]; |
| 7205 |
|
| 7206 |
if (!verticalTabRuns) { |
| 7207 |
// Tabs on TOP or BOTTOM.... |
| 7208 |
if (i > 0) { |
| 7209 |
rect.x = _rects[i - 1].x + _rects[i - 1].width; |
| 7210 |
} |
| 7211 |
else { |
| 7212 |
_tabRuns[0] = 0; |
| 7213 |
_maxTabWidth = 0; |
| 7214 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7215 |
rect.x = x + getLeftMargin();// give the first tab arrow angle extra space |
| 7216 |
} |
| 7217 |
else { |
| 7218 |
rect.x = x; |
| 7219 |
} |
| 7220 |
} |
| 7221 |
rect.width = calculateTabWidth(tabPlacement, i, metrics) + _rectSizeExtend; |
| 7222 |
_maxTabWidth = Math.max(_maxTabWidth, rect.width); |
| 7223 |
|
| 7224 |
rect.y = y; |
| 7225 |
|
| 7226 |
int temp = -1; |
| 7227 |
if (isTabLeadingComponentVisible()) { |
| 7228 |
if (tabPlacement == TOP) { |
| 7229 |
if (_maxTabHeight < lsize.height) { |
| 7230 |
rect.y = y + lsize.height - _maxTabHeight - 2; |
| 7231 |
temp = lsize.height; |
| 7232 |
|
| 7233 |
if (_rectSizeExtend > 0) { |
| 7234 |
rect.y = rect.y + 2; |
| 7235 |
} |
| 7236 |
} |
| 7237 |
|
| 7238 |
} |
| 7239 |
} |
| 7240 |
if (isTabTrailingComponentVisible()) { |
| 7241 |
if (tabPlacement == TOP) { |
| 7242 |
if (_maxTabHeight < tsize.height |
| 7243 |
&& temp < tsize.height) { |
| 7244 |
rect.y = y + tsize.height - _maxTabHeight - 2; |
| 7245 |
|
| 7246 |
if (_rectSizeExtend > 0) { |
| 7247 |
rect.y = rect.y + 2; |
| 7248 |
} |
| 7249 |
} |
| 7250 |
|
| 7251 |
} |
| 7252 |
} |
| 7253 |
rect.height = calculatedMaxTabHeight;///* - 2 */; |
| 7254 |
} |
| 7255 |
else { |
| 7256 |
// Tabs on LEFT or RIGHT... |
| 7257 |
if (i > 0) { |
| 7258 |
rect.y = _rects[i - 1].y + _rects[i - 1].height; |
| 7259 |
} |
| 7260 |
else { |
| 7261 |
_tabRuns[0] = 0; |
| 7262 |
_maxTabHeight = 0; |
| 7263 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7264 |
rect.y = y + getLeftMargin();// give the first tab arrow angle extra space |
| 7265 |
} |
| 7266 |
else { |
| 7267 |
rect.y = y; |
| 7268 |
} |
| 7269 |
} |
| 7270 |
rect.height = calculateTabHeight(tabPlacement, i, metrics) + _rectSizeExtend; |
| 7271 |
_maxTabHeight = Math.max(_maxTabHeight, rect.height); |
| 7272 |
|
| 7273 |
rect.x = x; |
| 7274 |
int temp = -1; |
| 7275 |
if (isTabLeadingComponentVisible()) { |
| 7276 |
if (tabPlacement == LEFT) { |
| 7277 |
if (_maxTabWidth < lsize.width) { |
| 7278 |
rect.x = x + lsize.width - _maxTabWidth - 2; |
| 7279 |
temp = lsize.width; |
| 7280 |
|
| 7281 |
if (_rectSizeExtend > 0) { |
| 7282 |
rect.x = rect.x + 2; |
| 7283 |
} |
| 7284 |
} |
| 7285 |
|
| 7286 |
} |
| 7287 |
} |
| 7288 |
if (isTabTrailingComponentVisible()) { |
| 7289 |
if (tabPlacement == LEFT) { |
| 7290 |
if (_maxTabWidth < tsize.width |
| 7291 |
&& temp < tsize.width) { |
| 7292 |
rect.x = x + tsize.width - _maxTabWidth - 2; |
| 7293 |
|
| 7294 |
if (_rectSizeExtend > 0) { |
| 7295 |
rect.x = rect.x + 2; |
| 7296 |
} |
| 7297 |
} |
| 7298 |
|
| 7299 |
} |
| 7300 |
} |
| 7301 |
rect.width = calculateMaxTabWidth(tabPlacement)/* - 2 */; |
| 7302 |
|
| 7303 |
} |
| 7304 |
} |
| 7305 |
|
| 7306 |
// if right to left and tab placement on the top or |
| 7307 |
// the bottom, flip x positions and adjust by widths |
| 7308 |
if (!leftToRight && !verticalTabRuns) { |
| 7309 |
// here _rects is the rectangle inside the ScrollableTabPanel, which is a view of ScrollableTabViewport, so it should always start from 0 and use the size of the ScrollableTabPanel instead |
| 7310 |
// int rightMargin = size.width - (insets.right + tabAreaInsets.right); |
| 7311 |
int rightMargin = 0; |
| 7312 |
if (_rects.length > 0) { |
| 7313 |
rightMargin = Math.max(_rects[_rects.length - 1].x + _rects[_rects.length - 1].width, size.width - tabAreaInsets.right); |
| 7314 |
_additionalWidth = getLeftMargin(); |
| 7315 |
} |
| 7316 |
// if (isTabLeadingComponentVisible()) { |
| 7317 |
// rightMargin -= lsize.width; // this _rects is the rectangle inside the ScrollableTabPanel so no need count in TabLeadingComponent at all |
| 7318 |
// } |
| 7319 |
for (int i = 0; i < tabCount; i++) { |
| 7320 |
_rects[i].x = rightMargin - _rects[i].x - _rects[i].width + tabAreaInsets.left; |
| 7321 |
// if(i == tabCount - 1) { |
| 7322 |
// _rects[i].width += getLeftMargin(); |
| 7323 |
// _rects[i].x -= getLeftMargin(); |
| 7324 |
// } |
| 7325 |
} |
| 7326 |
} |
| 7327 |
else { |
| 7328 |
_additionalWidth = 0; // always 0 for LTR because the first _rects element already contains the width for the decoration |
| 7329 |
} |
| 7330 |
|
| 7331 |
ensureCurrentRects(getLeftMargin(), tabCount); |
| 7332 |
|
| 7333 |
} |
| 7334 |
} |
| 7335 |
|
| 7336 |
|
| 7337 |
protected void ensureCurrentRects(int leftMargin, int tabCount) { |
| 7338 |
Dimension size = _tabPane.getSize(); |
| 7339 |
Insets insets = _tabPane.getInsets(); |
| 7340 |
int totalWidth = 0; |
| 7341 |
int totalHeight = 0; |
| 7342 |
boolean verticalTabRuns = (_tabPane.getTabPlacement() == LEFT || _tabPane.getTabPlacement() == RIGHT); |
| 7343 |
boolean ltr = _tabPane.getComponentOrientation().isLeftToRight(); |
| 7344 |
|
| 7345 |
if (tabCount == 0) { |
| 7346 |
return; |
| 7347 |
} |
| 7348 |
|
| 7349 |
Rectangle r = _rects[tabCount - 1]; |
| 7350 |
|
| 7351 |
Dimension lsize = new Dimension(0, 0); |
| 7352 |
Dimension tsize = new Dimension(0, 0); |
| 7353 |
|
| 7354 |
if (isTabLeadingComponentVisible()) { |
| 7355 |
lsize = _tabLeadingComponent.getPreferredSize(); |
| 7356 |
} |
| 7357 |
if (isTabTrailingComponentVisible()) { |
| 7358 |
tsize = _tabTrailingComponent.getPreferredSize(); |
| 7359 |
} |
| 7360 |
|
| 7361 |
|
| 7362 |
if (verticalTabRuns) { |
| 7363 |
totalHeight = r.y + r.height; |
| 7364 |
|
| 7365 |
if (_tabLeadingComponent != null) { |
| 7366 |
totalHeight -= lsize.height; |
| 7367 |
} |
| 7368 |
|
| 7369 |
} |
| 7370 |
else { |
| 7371 |
// totalWidth = r.x + r.width; |
| 7372 |
for (Rectangle rect : _rects) { |
| 7373 |
totalWidth += rect.width; |
| 7374 |
} |
| 7375 |
if (ltr) { |
| 7376 |
totalWidth += _rects[0].x; |
| 7377 |
} |
| 7378 |
else { |
| 7379 |
totalWidth += leftMargin; |
| 7380 |
} |
| 7381 |
|
| 7382 |
if (_tabLeadingComponent != null) { |
| 7383 |
totalWidth -= lsize.width; |
| 7384 |
} |
| 7385 |
|
| 7386 |
} |
| 7387 |
|
| 7388 |
|
| 7389 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT) {// LayOut Style is Size to Fix |
| 7390 |
if (verticalTabRuns) { |
| 7391 |
int availHeight; |
| 7392 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7393 |
availHeight = (int) size.getHeight() - _fitStyleBoundSize |
| 7394 |
- insets.top - insets.bottom - leftMargin - getTabRightPadding();// give the first tab extra space |
| 7395 |
} |
| 7396 |
else { |
| 7397 |
availHeight = (int) size.getHeight() - _fitStyleBoundSize |
| 7398 |
- insets.top - insets.bottom; |
| 7399 |
} |
| 7400 |
|
| 7401 |
if (_tabPane.isShowCloseButton()) { |
| 7402 |
availHeight -= _buttonSize; |
| 7403 |
} |
| 7404 |
|
| 7405 |
if (isTabLeadingComponentVisible()) { |
| 7406 |
availHeight = availHeight - lsize.height; |
| 7407 |
} |
| 7408 |
if (isTabTrailingComponentVisible()) { |
| 7409 |
availHeight = availHeight - tsize.height; |
| 7410 |
} |
| 7411 |
|
| 7412 |
int numberOfButtons = getNumberOfTabButtons(); |
| 7413 |
availHeight -= _buttonSize * numberOfButtons; |
| 7414 |
if (totalHeight > availHeight) { // shrink is necessary |
| 7415 |
// calculate each tab width |
| 7416 |
int tabHeight = availHeight / tabCount; |
| 7417 |
|
| 7418 |
totalHeight = _fitStyleFirstTabMargin; // start |
| 7419 |
|
| 7420 |
for (int k = 0; k < tabCount; k++) { |
| 7421 |
_rects[k].height = tabHeight; |
| 7422 |
Rectangle tabRect = _rects[k]; |
| 7423 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7424 |
tabRect.y = totalHeight + leftMargin;// give the first tab extra space |
| 7425 |
} |
| 7426 |
else { |
| 7427 |
tabRect.y = totalHeight; |
| 7428 |
} |
| 7429 |
totalHeight += tabRect.height; |
| 7430 |
} |
| 7431 |
} |
| 7432 |
|
| 7433 |
} |
| 7434 |
else { |
| 7435 |
int availWidth; |
| 7436 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7437 |
availWidth = (int) size.getWidth() - _fitStyleBoundSize |
| 7438 |
- insets.left - insets.right - leftMargin - getTabRightPadding(); |
| 7439 |
} |
| 7440 |
else { |
| 7441 |
availWidth = (int) size.getWidth() - _fitStyleBoundSize |
| 7442 |
- insets.left - insets.right; |
| 7443 |
} |
| 7444 |
|
| 7445 |
if (_tabPane.isShowCloseButton()) { |
| 7446 |
availWidth -= _buttonSize; |
| 7447 |
} |
| 7448 |
|
| 7449 |
if (isTabLeadingComponentVisible()) { |
| 7450 |
availWidth -= lsize.width; |
| 7451 |
} |
| 7452 |
if (isTabTrailingComponentVisible()) { |
| 7453 |
availWidth -= tsize.width; |
| 7454 |
} |
| 7455 |
|
| 7456 |
int numberOfButtons = getNumberOfTabButtons(); |
| 7457 |
availWidth -= _buttonSize * numberOfButtons; |
| 7458 |
if (totalWidth > availWidth) { // shrink is necessary |
| 7459 |
// calculate each tab width |
| 7460 |
int tabWidth = availWidth / tabCount; |
| 7461 |
int gripperWidth = _tabPane.isShowGripper() ? _gripperWidth |
| 7462 |
: 0; |
| 7463 |
if (tabWidth < _textIconGap + _fitStyleTextMinWidth |
| 7464 |
+ _fitStyleIconMinWidth + gripperWidth |
| 7465 |
&& tabWidth > _fitStyleIconMinWidth + gripperWidth) // cannot |
| 7466 |
// hold any text but can hold an icon |
| 7467 |
tabWidth = _fitStyleIconMinWidth + gripperWidth; |
| 7468 |
|
| 7469 |
if (tabWidth < _fitStyleIconMinWidth + gripperWidth |
| 7470 |
&& tabWidth > _fitStyleFirstTabMargin + gripperWidth) // cannot |
| 7471 |
// hold any icon but gripper |
| 7472 |
tabWidth = _fitStyleFirstTabMargin + gripperWidth; |
| 7473 |
|
| 7474 |
tryTabSpacer.reArrange(_rects, insets, availWidth); |
| 7475 |
} |
| 7476 |
totalWidth = _fitStyleFirstTabMargin; // start |
| 7477 |
|
| 7478 |
for (int k = 0; k < tabCount; k++) { |
| 7479 |
Rectangle tabRect = _rects[k]; |
| 7480 |
if (getTabShape() != JideTabbedPane.SHAPE_BOX) { |
| 7481 |
tabRect.x = totalWidth + leftMargin;// give the first tab extra space when the style is not box style |
| 7482 |
} |
| 7483 |
else { |
| 7484 |
tabRect.x = totalWidth; |
| 7485 |
} |
| 7486 |
totalWidth += tabRect.width; |
| 7487 |
} |
| 7488 |
if (!ltr) { |
| 7489 |
Insets tabAreaInsets = getTabAreaInsets(_tabPane.getTabPlacement()); |
| 7490 |
int rightMargin = size.width - lsize.width - tsize.width - (insets.right + tabAreaInsets.right); |
| 7491 |
if (_tabPane.isShowCloseButton()) { |
| 7492 |
rightMargin -= _buttonSize; |
| 7493 |
} |
| 7494 |
for (int k = 0; k < tabCount; k++) { |
| 7495 |
_rects[k].x = rightMargin - _rects[k].x - _rects[k].width; |
| 7496 |
} |
| 7497 |
} |
| 7498 |
} |
| 7499 |
} |
| 7500 |
|
| 7501 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIXED) {// LayOut Style is Fix |
| 7502 |
if (verticalTabRuns) { |
| 7503 |
for (int k = 0; k < tabCount; k++) { |
| 7504 |
_rects[k].height = _fixedStyleRectSize;// + _rectSizeExtend * 2; |
| 7505 |
|
| 7506 |
if (isShowCloseButton() && _tabPane.isShowCloseButtonOnTab()) { |
| 7507 |
_rects[k].height += _closeButtons[k].getPreferredSize().height; |
| 7508 |
} |
| 7509 |
|
| 7510 |
if (k != 0) { |
| 7511 |
_rects[k].y = _rects[k - 1].y + _rects[k - 1].height; |
| 7512 |
} |
| 7513 |
|
| 7514 |
totalHeight = _rects[k].y + _rects[k].height; |
| 7515 |
} |
| 7516 |
|
| 7517 |
} |
| 7518 |
else { |
| 7519 |
for (int k = 0; k < tabCount; k++) { |
| 7520 |
int oldWidth = _rects[k].width; |
| 7521 |
_rects[k].width = _fixedStyleRectSize; |
| 7522 |
|
| 7523 |
if (isShowCloseButton() && _tabPane.isShowCloseButtonOnTab()) { |
| 7524 |
_rects[k].width += _closeButtons[k].getPreferredSize().width; |
| 7525 |
} |
| 7526 |
|
| 7527 |
if (k == 0 && !ltr) { |
| 7528 |
_rects[k].x += oldWidth - _rects[k].width; |
| 7529 |
} |
| 7530 |
|
| 7531 |
if (k != 0) { |
| 7532 |
if (ltr) { |
| 7533 |
_rects[k].x = _rects[k - 1].x + _rects[k - 1].width; |
| 7534 |
} |
| 7535 |
else { |
| 7536 |
_rects[k].x = _rects[k - 1].x - _rects[k - 1].width; |
| 7537 |
} |
| 7538 |
} |
| 7539 |
|
| 7540 |
totalWidth = _rects[k].x + _rects[k].width; |
| 7541 |
} |
| 7542 |
} |
| 7543 |
} |
| 7544 |
|
| 7545 |
if (getTabResizeMode() == JideTabbedPane.RESIZE_MODE_COMPRESSED) {// LayOut Style is Compressed |
| 7546 |
if (verticalTabRuns) { |
| 7547 |
for (int k = 0; k < tabCount; k++) { |
| 7548 |
if (k != _tabPane.getSelectedIndex()) { |
| 7549 |
if (!_tabPane.isShowIconsOnTab() && !_tabPane.isUseDefaultShowIconsOnTab()) { |
| 7550 |
_rects[k].height = _compressedStyleNoIconRectSize; |
| 7551 |
} |
| 7552 |
else { |
| 7553 |
Icon icon = _tabPane.getIconForTab(k); |
| 7554 |
_rects[k].height = (icon == null ? 0 : icon.getIconHeight()) + _compressedStyleIconMargin; |
| 7555 |
} |
| 7556 |
|
| 7557 |
if (isShowCloseButton() && isShowCloseButtonOnTab() && !_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 7558 |
_rects[k].height = _rects[k].height + _closeButtons[k].getPreferredSize().height + _compressedStyleCloseButtonMarginVertical; |
| 7559 |
} |
| 7560 |
} |
| 7561 |
|
| 7562 |
if (k != 0) { |
| 7563 |
_rects[k].y = _rects[k - 1].y + _rects[k - 1].height; |
| 7564 |
} |
| 7565 |
|
| 7566 |
totalHeight = _rects[k].y + _rects[k].height; |
| 7567 |
|
| 7568 |
} |
| 7569 |
|
| 7570 |
} |
| 7571 |
else { |
| 7572 |
for (int k = 0; k < tabCount; k++) { |
| 7573 |
int oldWidth = _rects[k].width; |
| 7574 |
if (k != _tabPane.getSelectedIndex()) { |
| 7575 |
if (!_tabPane.isShowIconsOnTab() |
| 7576 |
&& !_tabPane.isUseDefaultShowIconsOnTab()) { |
| 7577 |
_rects[k].width = _compressedStyleNoIconRectSize; |
| 7578 |
} |
| 7579 |
else { |
| 7580 |
Icon icon = _tabPane.getIconForTab(k); |
| 7581 |
_rects[k].width = (icon == null ? 0 : icon.getIconWidth()) + _compressedStyleIconMargin; |
| 7582 |
} |
| 7583 |
|
| 7584 |
if (isShowCloseButton() && isShowCloseButtonOnTab() && !_tabPane.isShowCloseButtonOnSelectedTab()) { |
| 7585 |
_rects[k].width = _rects[k].width + _closeButtons[k].getPreferredSize().width + _compressedStyleCloseButtonMarginHorizon; |
| 7586 |
} |
| 7587 |
|
| 7588 |
} |
| 7589 |
|
| 7590 |
if (k == 0 && !ltr) { |
| 7591 |
_rects[k].x += oldWidth - _rects[k].width; |
| 7592 |
} |
| 7593 |
|
| 7594 |
if (k != 0) { |
| 7595 |
if (ltr) { |
| 7596 |
_rects[k].x = _rects[k - 1].x + _rects[k - 1].width; |
| 7597 |
} |
| 7598 |
else { |
| 7599 |
_rects[k].x = _rects[k - 1].x - _rects[k - 1].width; |
| 7600 |
} |
| 7601 |
} |
| 7602 |
|
| 7603 |
totalWidth = _rects[k].x + _rects[k].width; |
| 7604 |
|
| 7605 |
} |
| 7606 |
|
| 7607 |
} |
| 7608 |
} |
| 7609 |
|
| 7610 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 7611 |
totalWidth += getLayoutSize(); |
| 7612 |
|
| 7613 |
if (isTabLeadingComponentVisible()) { |
| 7614 |
totalWidth += lsize.width; |
| 7615 |
} |
| 7616 |
} |
| 7617 |
else { |
| 7618 |
totalHeight += getLayoutSize(); |
| 7619 |
|
| 7620 |
if (isTabLeadingComponentVisible()) { |
| 7621 |
totalHeight += tsize.height; |
| 7622 |
} |
| 7623 |
} |
| 7624 |
|
| 7625 |
if (_tabPane.getTabAlignment() == SwingConstants.CENTER) { |
| 7626 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 7627 |
int startX = _rects[0].x; |
| 7628 |
int endX = _rects[_rects.length - 1].x + _rects[_rects.length - 1].width; |
| 7629 |
int width = _tabPane.getWidth(); |
| 7630 |
int offset = width / 2 - (endX - startX) / 2 - startX; |
| 7631 |
for (Rectangle rect : _rects) { |
| 7632 |
rect.x += offset; |
| 7633 |
} |
| 7634 |
} |
| 7635 |
} |
| 7636 |
|
| 7637 |
_tabScroller.tabPanel.setPreferredSize(new Dimension(totalWidth, totalHeight)); |
| 7638 |
|
| 7639 |
} |
| 7640 |
|
| 7641 |
protected class ActivateTabAction extends AbstractAction { |
| 7642 |
int _tabIndex; |
| 7643 |
private static final long serialVersionUID = 3270152106579039554L; |
| 7644 |
|
| 7645 |
public ActivateTabAction(String name, Icon icon, int tabIndex) { |
| 7646 |
super(name, icon); |
| 7647 |
_tabIndex = tabIndex; |
| 7648 |
} |
| 7649 |
|
| 7650 |
public void actionPerformed(ActionEvent e) { |
| 7651 |
_tabPane.setSelectedIndex(_tabIndex); |
| 7652 |
} |
| 7653 |
} |
| 7654 |
|
| 7655 |
protected ListCellRenderer getTabListCellRenderer() { |
| 7656 |
return _tabPane.getTabListCellRenderer(); |
| 7657 |
} |
| 7658 |
|
| 7659 |
public class ScrollableTabSupport implements ChangeListener { |
| 7660 |
public ScrollableTabViewport viewport; |
| 7661 |
public ScrollableTabPanel tabPanel; |
| 7662 |
public JButton scrollForwardButton; |
| 7663 |
public JButton scrollBackwardButton; |
| 7664 |
public JButton listButton; |
| 7665 |
public JButton closeButton; |
| 7666 |
public int leadingTabIndex; |
| 7667 |
|
| 7668 |
private Point tabViewPosition = new Point(0, 0); |
| 7669 |
|
| 7670 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 7671 |
ScrollableTabSupport(int tabPlacement) { |
| 7672 |
viewport = new ScrollableTabViewport(); |
| 7673 |
tabPanel = new ScrollableTabPanel(); |
| 7674 |
viewport.setView(tabPanel); |
| 7675 |
viewport.addChangeListener(this); |
| 7676 |
|
| 7677 |
scrollForwardButton = createButton(JideTabbedPane.BUTTON_EAST); |
| 7678 |
scrollBackwardButton = createButton(JideTabbedPane.BUTTON_WEST); |
| 7679 |
|
| 7680 |
scrollForwardButton.setBackground(viewport.getBackground()); |
| 7681 |
scrollBackwardButton.setBackground(viewport.getBackground()); |
| 7682 |
|
| 7683 |
listButton = createButton(JideTabbedPane.BUTTON_LIST); |
| 7684 |
listButton.setBackground(viewport.getBackground()); |
| 7685 |
|
| 7686 |
closeButton = createButton(JideTabbedPane.BUTTON_CLOSE); |
| 7687 |
closeButton.setBackground(viewport.getBackground()); |
| 7688 |
} |
| 7689 |
|
| 7690 |
public void createPopupMenu(int tabPlacement) { |
| 7691 |
JPopupMenu popup = new JPopupMenu(); |
| 7692 |
int totalCount = _tabPane.getTabCount(); |
| 7693 |
|
| 7694 |
// drop down menu items |
| 7695 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 7696 |
for (int i = 0; i < totalCount; i++) { |
| 7697 |
if (_tabPane.isEnabledAt(i)) { |
| 7698 |
JMenuItem item; |
| 7699 |
popup.add(item = new JCheckBoxMenuItem(new ActivateTabAction(_tabPane.getTitleAt(i), _tabPane.getIconForTab(i), i))); |
| 7700 |
item.setToolTipText(_tabPane.getToolTipTextAt(i)); |
| 7701 |
item.setSelected(selectedIndex == i); |
| 7702 |
item.setHorizontalTextPosition(JMenuItem.RIGHT); |
| 7703 |
} |
| 7704 |
} |
| 7705 |
|
| 7706 |
Dimension preferredSize = popup.getPreferredSize(); |
| 7707 |
Rectangle bounds = listButton.getBounds(); |
| 7708 |
switch (tabPlacement) { |
| 7709 |
case TOP: |
| 7710 |
popup.show(_tabPane, bounds.x + bounds.width - preferredSize.width, bounds.y + bounds.height); |
| 7711 |
break; |
| 7712 |
case BOTTOM: |
| 7713 |
popup.show(_tabPane, bounds.x + bounds.width - preferredSize.width, bounds.y - preferredSize.height); |
| 7714 |
break; |
| 7715 |
case LEFT: |
| 7716 |
popup.show(_tabPane, bounds.x + bounds.width, bounds.y + bounds.height - preferredSize.height); |
| 7717 |
break; |
| 7718 |
case RIGHT: |
| 7719 |
popup.show(_tabPane, bounds.x - preferredSize.width, bounds.y + bounds.height - preferredSize.height); |
| 7720 |
break; |
| 7721 |
} |
| 7722 |
} |
| 7723 |
|
| 7724 |
public void createPopup(int tabPlacement) { |
| 7725 |
_tabPane.showTabListPopup(listButton); |
| 7726 |
} |
| 7727 |
|
| 7728 |
public void scrollForward(int tabPlacement) { |
| 7729 |
Dimension viewSize = viewport.getViewSize(); |
| 7730 |
Rectangle viewRect = viewport.getViewRect(); |
| 7731 |
|
| 7732 |
if (tabPlacement == TOP || tabPlacement == BOTTOM) { |
| 7733 |
if (_tabPane.getComponentOrientation().isLeftToRight()) { |
| 7734 |
if (viewRect.width >= viewSize.width - viewRect.x) { |
| 7735 |
return; // no room left to scroll |
| 7736 |
} |
| 7737 |
} |
| 7738 |
else { |
| 7739 |
if (viewRect.x <= 0) { |
| 7740 |
return; |
| 7741 |
} |
| 7742 |
} |
| 7743 |
} |
| 7744 |
else { // tabPlacement == LEFT || tabPlacement == RIGHT |
| 7745 |
if (viewRect.height >= viewSize.height - viewRect.y) { |
| 7746 |
return; |
| 7747 |
} |
| 7748 |
} |
| 7749 |
setLeadingTabIndex(tabPlacement, leadingTabIndex + 1); |
| 7750 |
} |
| 7751 |
|
| 7752 |
public void scrollBackward(int tabPlacement) { |
| 7753 |
setLeadingTabIndex(tabPlacement, leadingTabIndex > 0 ? leadingTabIndex - 1 : 0); |
| 7754 |
} |
| 7755 |
|
| 7756 |
public void setLeadingTabIndex(int tabPlacement, int index) { |
| 7757 |
// make sure the index is in range |
| 7758 |
if (index < 0 || index >= _tabPane.getTabCount()) { |
| 7759 |
return; |
| 7760 |
} |
| 7761 |
leadingTabIndex = index; |
| 7762 |
Dimension viewSize = viewport.getViewSize(); |
| 7763 |
Rectangle viewRect = viewport.getViewRect(); |
| 7764 |
|
| 7765 |
switch (tabPlacement) { |
| 7766 |
case TOP: |
| 7767 |
case BOTTOM: |
| 7768 |
tabViewPosition.y = 0; |
| 7769 |
if (_tabPane.getComponentOrientation().isLeftToRight()) { |
| 7770 |
tabViewPosition.x = leadingTabIndex == 0 ? 0 : _rects[leadingTabIndex].x; |
| 7771 |
// no need for RTL orientation. Just keep it for LTR as a protection. |
| 7772 |
if ((viewSize.width - tabViewPosition.x) < viewRect.width) { |
| 7773 |
tabViewPosition.x = viewSize.width - viewRect.width; |
| 7774 |
// // We've scrolled to the end, so adjust the viewport size |
| 7775 |
// // to ensure the view position remains aligned on a tab boundary |
| 7776 |
// Dimension extentSize = new Dimension(viewSize.width - tabViewPosition.x, |
| 7777 |
// viewRect.height); |
| 7778 |
// System.out.println("setExtendedSize: " + extentSize); |
| 7779 |
// viewport.setExtentSize(extentSize); |
| 7780 |
} |
| 7781 |
} |
| 7782 |
else { |
| 7783 |
if (_rects.length <= 0) { |
| 7784 |
tabViewPosition.x = 0; |
| 7785 |
} |
| 7786 |
else if (_rects.length == 1) { |
| 7787 |
tabViewPosition.x = _rects[0].x + _rects[0].width + _additionalWidth - viewRect.width; |
| 7788 |
} |
| 7789 |
else { |
| 7790 |
Insets tabAreaInsets = getTabAreaInsets(tabPlacement); |
| 7791 |
Rectangle[] tempRects = _rects; |
| 7792 |
if (_rects[0].x < _rects[1].x) { // first time calling while switching CO |
| 7793 |
tempRects = new Rectangle[_rects.length]; |
| 7794 |
int rightMargin = 0; |
| 7795 |
if (_rects.length > 0) { |
| 7796 |
rightMargin = _rects[_rects.length - 1].x + _rects[_rects.length - 1].width; |
| 7797 |
_additionalWidth = _rects[0].x; |
| 7798 |
} |
| 7799 |
for (int i = 0; i < _tabCount; i++) { |
| 7800 |
tempRects[i] = new Rectangle(_rects[i]); |
| 7801 |
tempRects[i].x = rightMargin - _rects[i].x - _rects[i].width + tabAreaInsets.left; |
| 7802 |
} |
| 7803 |
} |
| 7804 |
tabViewPosition.x = tempRects[leadingTabIndex].x + tempRects[leadingTabIndex].width + (leadingTabIndex == 0 ? _additionalWidth : 0) - viewRect.width; |
| 7805 |
} |
| 7806 |
} |
| 7807 |
|
| 7808 |
break; |
| 7809 |
case LEFT: |
| 7810 |
case RIGHT: |
| 7811 |
tabViewPosition.x = 0; |
| 7812 |
tabViewPosition.y = leadingTabIndex == 0 ? 0 : _rects[leadingTabIndex].y; |
| 7813 |
|
| 7814 |
if ((viewSize.height - tabViewPosition.y) < viewRect.height) { |
| 7815 |
tabViewPosition.y = viewSize.height - viewRect.height; |
| 7816 |
// // We've scrolled to the end, so adjust the viewport size |
| 7817 |
// // to ensure the view position remains aligned on a tab boundary |
| 7818 |
// Dimension extentSize = new Dimension(viewRect.width, |
| 7819 |
// viewSize.height - tabViewPosition.y); |
| 7820 |
// viewport.setExtentSize(extentSize); |
| 7821 |
} |
| 7822 |
break; |
| 7823 |
} |
| 7824 |
viewport.setViewPosition(tabViewPosition); |
| 7825 |
_tabPane.repaint(); |
| 7826 |
} |
| 7827 |
|
| 7828 |
public void stateChanged(ChangeEvent e) { |
| 7829 |
if (_tabPane == null) return; |
| 7830 |
|
| 7831 |
int tabPlacement = _tabPane.getTabPlacement(); |
| 7832 |
// should not call ensureCurrentLayout() anyway but just in case it will impact LTR scenario |
| 7833 |
if (_tabPane.getComponentOrientation().isLeftToRight() || (tabPlacement != TOP && tabPlacement != BOTTOM)) { |
| 7834 |
ensureCurrentLayout(); |
| 7835 |
} |
| 7836 |
|
| 7837 |
JViewport viewport = (JViewport) e.getSource(); |
| 7838 |
int tabCount = _tabPane.getTabCount(); |
| 7839 |
Rectangle vpRect = viewport.getBounds(); |
| 7840 |
Dimension viewSize = viewport.getViewSize(); |
| 7841 |
Rectangle viewRect = viewport.getViewRect(); |
| 7842 |
|
| 7843 |
if ((tabPlacement == TOP || tabPlacement == BOTTOM) && !_tabPane.getComponentOrientation().isLeftToRight()) { |
| 7844 |
leadingTabIndex = getClosestTab(viewRect.x + viewRect.width - 1, viewRect.y + viewRect.height - 1); |
| 7845 |
if (leadingTabIndex < 0) { |
| 7846 |
leadingTabIndex = 0; |
| 7847 |
} |
| 7848 |
} |
| 7849 |
else { |
| 7850 |
leadingTabIndex = getClosestTab(viewRect.x, viewRect.y); |
| 7851 |
} |
| 7852 |
|
| 7853 |
// If the tab isn't right aligned, adjust it. |
| 7854 |
if (leadingTabIndex < _rects.length && leadingTabIndex >= _rects.length) { |
| 7855 |
switch (tabPlacement) { |
| 7856 |
case TOP: |
| 7857 |
case BOTTOM: |
| 7858 |
if (_rects[leadingTabIndex].x < viewRect.x) { |
| 7859 |
leadingTabIndex++; |
| 7860 |
} |
| 7861 |
break; |
| 7862 |
case LEFT: |
| 7863 |
case RIGHT: |
| 7864 |
if (_rects[leadingTabIndex].y < viewRect.y) { |
| 7865 |
leadingTabIndex++; |
| 7866 |
} |
| 7867 |
break; |
| 7868 |
} |
| 7869 |
} |
| 7870 |
|
| 7871 |
|
| 7872 |
Insets contentInsets = getContentBorderInsets(tabPlacement); |
| 7873 |
int checkX; |
| 7874 |
if(_rects.length > 0) { |
| 7875 |
Rectangle rect = _rects[0]; |
| 7876 |
switch (tabPlacement) { |
| 7877 |
case LEFT: |
| 7878 |
_tabPane.repaint(vpRect.x + vpRect.width, vpRect.y, contentInsets.left, vpRect.height); |
| 7879 |
scrollBackwardButton.setEnabled(viewRect.y > 0 || leadingTabIndex > 0); |
| 7880 |
scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.height - viewRect.y > viewRect.height); |
| 7881 |
break; |
| 7882 |
case RIGHT: |
| 7883 |
_tabPane.repaint(vpRect.x - contentInsets.right, vpRect.y, contentInsets.right, vpRect.height); |
| 7884 |
scrollBackwardButton.setEnabled(viewRect.y > 0 || leadingTabIndex > 0); |
| 7885 |
scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.height - viewRect.y > viewRect.height); |
| 7886 |
break; |
| 7887 |
case BOTTOM: |
| 7888 |
_tabPane.repaint(vpRect.x, vpRect.y - contentInsets.bottom, vpRect.width, contentInsets.bottom); |
| 7889 |
if (_tabPane.getComponentOrientation().isLeftToRight()) { |
| 7890 |
scrollBackwardButton.setEnabled(viewRect.x > 0 || leadingTabIndex > 0); |
| 7891 |
scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width); |
| 7892 |
} |
| 7893 |
else { |
| 7894 |
scrollBackwardButton.setEnabled(rect.x + rect.width + _additionalWidth - _tabScroller.viewport.getViewPosition().x > viewRect.width); |
| 7895 |
boolean enabled = leadingTabIndex < tabCount - 1 && _tabScroller.viewport.getViewPosition().x > 0; |
| 7896 |
if (enabled && _rects.length > 0) { |
| 7897 |
if (rect.x + rect.width + _additionalWidth - _rects[_rects.length - 1].x < viewRect.width) { |
| 7898 |
enabled = false; |
| 7899 |
} |
| 7900 |
} |
| 7901 |
scrollForwardButton.setEnabled(enabled); |
| 7902 |
} |
| 7903 |
break; |
| 7904 |
case TOP: |
| 7905 |
default: |
| 7906 |
_tabPane.repaint(vpRect.x, vpRect.y + vpRect.height, vpRect.width, contentInsets.top); |
| 7907 |
if (_tabPane.getComponentOrientation().isLeftToRight()) { |
| 7908 |
scrollBackwardButton.setEnabled(viewRect.x > 0 || leadingTabIndex > 0); |
| 7909 |
scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1 && viewSize.width - viewRect.x > viewRect.width); |
| 7910 |
} |
| 7911 |
else { |
| 7912 |
scrollBackwardButton.setEnabled(rect.x + rect.width + _additionalWidth - _tabScroller.viewport.getViewPosition().x > viewRect.width); |
| 7913 |
boolean enabled = leadingTabIndex < tabCount - 1 && _tabScroller.viewport.getViewPosition().x > 0; |
| 7914 |
if (enabled && _rects.length > 0) { |
| 7915 |
if (rect.x + rect.width + _additionalWidth - _rects[_rects.length - 1].x < viewRect.width) { |
| 7916 |
enabled = false; |
| 7917 |
} |
| 7918 |
} |
| 7919 |
scrollForwardButton.setEnabled(enabled); |
| 7920 |
} |
| 7921 |
} |
| 7922 |
} |
| 7923 |
|
| 7924 |
if (SystemInfo.isJdk15Above()) { |
| 7925 |
_tabPane.setComponentZOrder(_tabScroller.scrollForwardButton, 0); |
| 7926 |
_tabPane.setComponentZOrder(_tabScroller.scrollBackwardButton, 0); |
| 7927 |
} |
| 7928 |
_tabScroller.scrollForwardButton.repaint(); |
| 7929 |
_tabScroller.scrollBackwardButton.repaint(); |
| 7930 |
|
| 7931 |
|
| 7932 |
int selectedIndex = _tabPane.getSelectedIndex(); |
| 7933 |
if (selectedIndex >= 0 && selectedIndex < _tabPane.getTabCount()) { |
| 7934 |
closeButton.setEnabled(_tabPane.isTabClosableAt(selectedIndex)); |
| 7935 |
} |
| 7936 |
} |
| 7937 |
|
| 7938 |
@Override |
| 7939 |
public String toString() { |
| 7940 |
return "viewport.viewSize=" + viewport.getViewSize() + "\n" + |
| 7941 |
"viewport.viewRectangle=" + viewport.getViewRect() + "\n" + |
| 7942 |
"leadingTabIndex=" + leadingTabIndex + "\n" + |
| 7943 |
"tabViewPosition=" + tabViewPosition; |
| 7944 |
} |
| 7945 |
|
| 7946 |
} |
| 7947 |
|
| 7948 |
public class ScrollableTabViewport extends JViewport implements UIResource { |
| 7949 |
|
| 7950 |
public ScrollableTabViewport() { |
| 7951 |
super(); |
| 7952 |
setOpaque(false); |
| 7953 |
} |
| 7954 |
|
| 7955 |
@Override |
| 7956 |
public void setViewPosition(Point p) { |
| 7957 |
super.setViewPosition(p); |
| 7958 |
} |
| 7959 |
|
| 7960 |
/** |
| 7961 |
* Gets the background color of this component. |
| 7962 |
* |
| 7963 |
* @return this component's background color; if this component does not have a background color, the background |
| 7964 |
* color of its parent is returned |
| 7965 |
*/ |
| 7966 |
@Override |
| 7967 |
public Color getBackground() { |
| 7968 |
return UIDefaultsLookup.getColor("JideTabbedPane.background"); |
| 7969 |
} |
| 7970 |
} |
| 7971 |
|
| 7972 |
public class ScrollableTabPanel extends JPanel implements UIResource { |
| 7973 |
public ScrollableTabPanel() { |
| 7974 |
setLayout(null); |
| 7975 |
} |
| 7976 |
|
| 7977 |
@Override |
| 7978 |
public boolean isOpaque() { |
| 7979 |
return false; |
| 7980 |
} |
| 7981 |
|
| 7982 |
public Dimension getPreferredScrollableViewportSize() { |
| 7983 |
return getPreferredSize(); |
| 7984 |
} |
| 7985 |
|
| 7986 |
public void scrollIndexToVisible(int index) { |
| 7987 |
Rectangle rect = new Rectangle(_rects[index]); |
| 7988 |
if ((_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) && !_tabPane.getComponentOrientation().isLeftToRight() && index == 0) { |
| 7989 |
rect.width += getLeftMargin(); |
| 7990 |
} |
| 7991 |
scrollRectToVisible(rect); |
| 7992 |
} |
| 7993 |
|
| 7994 |
@Override |
| 7995 |
public void scrollRectToVisible(Rectangle aRect) { |
| 7996 |
super.scrollRectToVisible(aRect); |
| 7997 |
} |
| 7998 |
|
| 7999 |
@Override |
| 8000 |
public Dimension getPreferredSize() { |
| 8001 |
if (_rects.length <= 0) { |
| 8002 |
return new Dimension(0, 0); |
| 8003 |
} |
| 8004 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 8005 |
if (_tabPane.getComponentOrientation().isLeftToRight()) { |
| 8006 |
return new Dimension(_rects[_rects.length - 1].x + _rects[_rects.length - 1].width + 10, _rects[0].y + _rects[0].height); |
| 8007 |
} |
| 8008 |
else { |
| 8009 |
return new Dimension(_rects[0].x + _rects[0].width + getLeftMargin(), _rects[0].y + _rects[0].height); |
| 8010 |
} |
| 8011 |
} |
| 8012 |
else { |
| 8013 |
return new Dimension(_rects[0].x + _rects[0].width, _rects[_rects.length - 1].y + _rects[_rects.length - 1].height); |
| 8014 |
} |
| 8015 |
} |
| 8016 |
|
| 8017 |
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { |
| 8018 |
return 1; |
| 8019 |
} |
| 8020 |
|
| 8021 |
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { |
| 8022 |
return 1; |
| 8023 |
} |
| 8024 |
|
| 8025 |
public boolean getScrollableTracksViewportWidth() { |
| 8026 |
return false; |
| 8027 |
} |
| 8028 |
|
| 8029 |
public boolean getScrollableTracksViewportHeight() { |
| 8030 |
return false; |
| 8031 |
} |
| 8032 |
|
| 8033 |
@Override |
| 8034 |
public void paintComponent(Graphics g) { |
| 8035 |
super.paintComponent(g); |
| 8036 |
|
| 8037 |
if (_tabPane.isOpaque()) { |
| 8038 |
if (getTabShape() == JideTabbedPane.SHAPE_BOX) { |
| 8039 |
g.setColor(UIDefaultsLookup.getColor("JideTabbedPane.selectedTabBackground")); |
| 8040 |
} |
| 8041 |
else { |
| 8042 |
g.setColor(UIDefaultsLookup.getColor("JideTabbedPane.tabAreaBackground")); |
| 8043 |
} |
| 8044 |
g.fillRect(0, 0, getWidth(), getHeight()); |
| 8045 |
} |
| 8046 |
|
| 8047 |
paintTabArea(g, _tabPane.getTabPlacement(), _tabPane.getSelectedIndex(), this); |
| 8048 |
} |
| 8049 |
|
| 8050 |
@Override |
| 8051 |
public void setToolTipText(String text) { |
| 8052 |
_tabPane.setToolTipText(text); |
| 8053 |
} |
| 8054 |
|
| 8055 |
@Override |
| 8056 |
public String getToolTipText() { |
| 8057 |
return _tabPane.getToolTipText(); |
| 8058 |
} |
| 8059 |
|
| 8060 |
@Override |
| 8061 |
public String getToolTipText(MouseEvent event) { |
| 8062 |
return _tabPane.getToolTipText(SwingUtilities.convertMouseEvent(this, event, _tabPane)); |
| 8063 |
} |
| 8064 |
|
| 8065 |
@Override |
| 8066 |
public Point getToolTipLocation(MouseEvent event) { |
| 8067 |
return _tabPane.getToolTipLocation(SwingUtilities.convertMouseEvent(this, event, _tabPane)); |
| 8068 |
} |
| 8069 |
|
| 8070 |
@Override |
| 8071 |
public JToolTip createToolTip() { |
| 8072 |
return _tabPane.createToolTip(); |
| 8073 |
} |
| 8074 |
|
| 8075 |
public void doLayout() { |
| 8076 |
if (_tabContainer != null && _tabContainer.getParent() == this) { |
| 8077 |
_tabContainer.setBounds(0, 0, getWidth(), getHeight()); |
| 8078 |
} |
| 8079 |
} |
| 8080 |
} |
| 8081 |
|
| 8082 |
protected Color _closeButtonSelectedColor = new Color(255, 162, 165); |
| 8083 |
protected Color _closeButtonColor = Color.BLACK; |
| 8084 |
protected Color _popupColor = Color.BLACK; |
| 8085 |
|
| 8086 |
/** |
| 8087 |
* Close button on the tab. |
| 8088 |
* |
| 8089 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane.NoFocusButton} |
| 8090 |
*/ |
| 8091 |
@Deprecated |
| 8092 |
public class TabCloseButton extends JButton implements MouseMotionListener, MouseListener, UIResource { |
| 8093 |
/** |
| 8094 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_CLOSE} |
| 8095 |
*/ |
| 8096 |
@Deprecated |
| 8097 |
public static final int CLOSE_BUTTON = 0; |
| 8098 |
/** |
| 8099 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_EAST} |
| 8100 |
*/ |
| 8101 |
@Deprecated |
| 8102 |
public static final int EAST_BUTTON = 1; |
| 8103 |
/** |
| 8104 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_WEST} |
| 8105 |
*/ |
| 8106 |
@Deprecated |
| 8107 |
public static final int WEST_BUTTON = 2; |
| 8108 |
/** |
| 8109 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_NORTH} |
| 8110 |
*/ |
| 8111 |
@Deprecated |
| 8112 |
public static final int NORTH_BUTTON = 3; |
| 8113 |
/** |
| 8114 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_SOUTH} |
| 8115 |
*/ |
| 8116 |
@Deprecated |
| 8117 |
public static final int SOUTH_BUTTON = 4; |
| 8118 |
/** |
| 8119 |
* @deprecated replaced by {@link com.jidesoft.swing.JideTabbedPane#BUTTON_LIST} |
| 8120 |
*/ |
| 8121 |
@Deprecated |
| 8122 |
public static final int LIST_BUTTON = 5; |
| 8123 |
private int _type; |
| 8124 |
private int _index = -1; |
| 8125 |
private boolean _mouseOver = false; |
| 8126 |
private boolean _mousePressed = false; |
| 8127 |
|
| 8128 |
/** |
| 8129 |
* Resets the UI property to a value from the current look and feel. |
| 8130 |
* |
| 8131 |
* @see JComponent#updateUI |
| 8132 |
*/ |
| 8133 |
@Override |
| 8134 |
public void updateUI() { |
| 8135 |
super.updateUI(); |
| 8136 |
setMargin(new Insets(0, 0, 0, 0)); |
| 8137 |
setBorder(BorderFactory.createEmptyBorder()); |
| 8138 |
setFocusPainted(false); |
| 8139 |
setFocusable(false); |
| 8140 |
setRequestFocusEnabled(false); |
| 8141 |
String name = getName(); |
| 8142 |
if (name != null) setToolTipText(getResourceString(name)); |
| 8143 |
} |
| 8144 |
|
| 8145 |
public TabCloseButton() { |
| 8146 |
this(JideTabbedPane.BUTTON_CLOSE); |
| 8147 |
} |
| 8148 |
|
| 8149 |
public TabCloseButton(int type) { |
| 8150 |
addMouseMotionListener(this); |
| 8151 |
addMouseListener(this); |
| 8152 |
setFocusPainted(false); |
| 8153 |
setFocusable(false); |
| 8154 |
setType(type); |
| 8155 |
} |
| 8156 |
|
| 8157 |
@Override |
| 8158 |
public Dimension getPreferredSize() { |
| 8159 |
return new Dimension(16, 16); |
| 8160 |
} |
| 8161 |
|
| 8162 |
@Override |
| 8163 |
public Dimension getMinimumSize() { |
| 8164 |
return new Dimension(5, 5); |
| 8165 |
} |
| 8166 |
|
| 8167 |
public int getIndex() { |
| 8168 |
return _index; |
| 8169 |
} |
| 8170 |
|
| 8171 |
public void setIndex(int index) { |
| 8172 |
_index = index; |
| 8173 |
} |
| 8174 |
|
| 8175 |
@Override |
| 8176 |
public Dimension getMaximumSize() { |
| 8177 |
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); |
| 8178 |
} |
| 8179 |
|
| 8180 |
@Override |
| 8181 |
protected void paintComponent(Graphics g) { |
| 8182 |
if (!isEnabled()) { |
| 8183 |
setMouseOver(false); |
| 8184 |
setMousePressed(false); |
| 8185 |
} |
| 8186 |
if (isMouseOver() && isMousePressed()) { |
| 8187 |
g.setColor(UIDefaultsLookup.getColor("controlDkShadow")); |
| 8188 |
g.drawLine(0, 0, getWidth() - 1, 0); |
| 8189 |
g.drawLine(0, getHeight() - 2, 0, 1); |
| 8190 |
g.setColor(UIDefaultsLookup.getColor("control")); |
| 8191 |
g.drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 2); |
| 8192 |
g.drawLine(getWidth() - 1, getHeight() - 1, 0, getHeight() - 1); |
| 8193 |
} |
| 8194 |
else if (isMouseOver()) { |
| 8195 |
g.setColor(UIDefaultsLookup.getColor("control")); |
| 8196 |
g.drawLine(0, 0, getWidth() - 1, 0); |
| 8197 |
g.drawLine(0, getHeight() - 2, 0, 1); |
| 8198 |
g.setColor(UIDefaultsLookup.getColor("controlDkShadow")); |
| 8199 |
g.drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 2); |
| 8200 |
g.drawLine(getWidth() - 1, getHeight() - 1, 0, getHeight() - 1); |
| 8201 |
} |
| 8202 |
g.setColor(UIDefaultsLookup.getColor("controlShadow").darker()); |
| 8203 |
int centerX = getWidth() >> 1; |
| 8204 |
int centerY = getHeight() >> 1; |
| 8205 |
int type = getType(); |
| 8206 |
if ((_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) && !_tabPane.getComponentOrientation().isLeftToRight()) { |
| 8207 |
if (type == EAST_BUTTON) { |
| 8208 |
type = WEST_BUTTON; |
| 8209 |
} |
| 8210 |
else if (type == WEST_BUTTON) { |
| 8211 |
type = EAST_BUTTON; |
| 8212 |
} |
| 8213 |
} |
| 8214 |
switch (type) { |
| 8215 |
case CLOSE_BUTTON: |
| 8216 |
if (isEnabled()) { |
| 8217 |
g.drawLine(centerX - 3, centerY - 3, centerX + 3, centerY + 3); |
| 8218 |
g.drawLine(centerX - 4, centerY - 3, centerX + 2, centerY + 3); |
| 8219 |
g.drawLine(centerX + 3, centerY - 3, centerX - 3, centerY + 3); |
| 8220 |
g.drawLine(centerX + 2, centerY - 3, centerX - 4, centerY + 3); |
| 8221 |
} |
| 8222 |
else { |
| 8223 |
g.drawLine(centerX - 3, centerY - 3, centerX + 3, centerY + 3); |
| 8224 |
g.drawLine(centerX + 3, centerY - 3, centerX - 3, centerY + 3); |
| 8225 |
} |
| 8226 |
break; |
| 8227 |
case EAST_BUTTON: |
| 8228 |
// |
| 8229 |
// | |
| 8230 |
// || |
| 8231 |
// ||| |
| 8232 |
// |||| |
| 8233 |
// ||||* |
| 8234 |
// |||| |
| 8235 |
// ||| |
| 8236 |
// || |
| 8237 |
// | |
| 8238 |
// |
| 8239 |
{ |
| 8240 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 8241 |
int x = centerX + 2, y = centerY; // start point. mark as * above |
| 8242 |
if (isEnabled()) { |
| 8243 |
g.drawLine(x - 4, y - 4, x - 4, y + 4); |
| 8244 |
g.drawLine(x - 3, y - 3, x - 3, y + 3); |
| 8245 |
g.drawLine(x - 2, y - 2, x - 2, y + 2); |
| 8246 |
g.drawLine(x - 1, y - 1, x - 1, y + 1); |
| 8247 |
g.drawLine(x, y, x, y); |
| 8248 |
} |
| 8249 |
else { |
| 8250 |
g.drawLine(x - 4, y - 4, x, y); |
| 8251 |
g.drawLine(x - 4, y - 4, x - 4, y + 4); |
| 8252 |
g.drawLine(x - 4, y + 4, x, y); |
| 8253 |
} |
| 8254 |
|
| 8255 |
} |
| 8256 |
else { |
| 8257 |
int x = centerX + 3, y = centerY - 2; // start point. mark as * above |
| 8258 |
if (isEnabled()) { |
| 8259 |
g.drawLine(x - 8, y, x, y); |
| 8260 |
g.drawLine(x - 7, y + 1, x - 1, y + 1); |
| 8261 |
g.drawLine(x - 6, y + 2, x - 2, y + 2); |
| 8262 |
g.drawLine(x - 5, y + 3, x - 3, y + 3); |
| 8263 |
g.drawLine(x - 4, y + 4, x - 4, y + 4); |
| 8264 |
} |
| 8265 |
else { |
| 8266 |
g.drawLine(x - 8, y, x, y); |
| 8267 |
g.drawLine(x - 8, y, x - 4, y + 4); |
| 8268 |
g.drawLine(x - 4, y + 4, x, y); |
| 8269 |
} |
| 8270 |
} |
| 8271 |
} |
| 8272 |
break; |
| 8273 |
case WEST_BUTTON: { |
| 8274 |
// |
| 8275 |
// | |
| 8276 |
// || |
| 8277 |
// ||| |
| 8278 |
// |||| |
| 8279 |
// *|||| |
| 8280 |
// |||| |
| 8281 |
// ||| |
| 8282 |
// || |
| 8283 |
// | |
| 8284 |
// |
| 8285 |
{ |
| 8286 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 8287 |
int x = centerX - 3, y = centerY; // start point. mark as * above |
| 8288 |
if (isEnabled()) { |
| 8289 |
g.drawLine(x, y, x, y); |
| 8290 |
g.drawLine(x + 1, y - 1, x + 1, y + 1); |
| 8291 |
g.drawLine(x + 2, y - 2, x + 2, y + 2); |
| 8292 |
g.drawLine(x + 3, y - 3, x + 3, y + 3); |
| 8293 |
g.drawLine(x + 4, y - 4, x + 4, y + 4); |
| 8294 |
} |
| 8295 |
else { |
| 8296 |
g.drawLine(x, y, x + 4, y - 4); |
| 8297 |
g.drawLine(x, y, x + 4, y + 4); |
| 8298 |
g.drawLine(x + 4, y - 4, x + 4, y + 4); |
| 8299 |
} |
| 8300 |
} |
| 8301 |
else { |
| 8302 |
|
| 8303 |
int x = centerX - 5, y = centerY + 3; // start point. mark as * above |
| 8304 |
if (isEnabled()) { |
| 8305 |
g.drawLine(x, y, x + 8, y); |
| 8306 |
g.drawLine(x + 1, y - 1, x + 7, y - 1); |
| 8307 |
g.drawLine(x + 2, y - 2, x + 6, y - 2); |
| 8308 |
g.drawLine(x + 3, y - 3, x + 5, y - 3); |
| 8309 |
g.drawLine(x + 4, y - 4, x + 4, y - 4); |
| 8310 |
} |
| 8311 |
else { |
| 8312 |
g.drawLine(x, y, x + 8, y); |
| 8313 |
g.drawLine(x, y, x + 4, y - 4); |
| 8314 |
g.drawLine(x + 8, y, x + 4, y - 4); |
| 8315 |
} |
| 8316 |
} |
| 8317 |
} |
| 8318 |
break; |
| 8319 |
} |
| 8320 |
case LIST_BUTTON: { |
| 8321 |
int x = centerX + 2, y = centerY; // start point. mark as |
| 8322 |
// * above |
| 8323 |
g.drawLine(x - 6, y - 4, x - 6, y + 4); |
| 8324 |
g.drawLine(x + 1, y - 4, x + 1, y + 4); |
| 8325 |
g.drawLine(x - 6, y - 4, x + 1, y - 4); |
| 8326 |
g.drawLine(x - 4, y - 2, x - 1, y - 2); |
| 8327 |
g.drawLine(x - 4, y, x - 1, y); |
| 8328 |
g.drawLine(x - 4, y + 2, x - 1, y + 2); |
| 8329 |
g.drawLine(x - 6, y + 4, x + 1, y + 4); |
| 8330 |
break; |
| 8331 |
} |
| 8332 |
} |
| 8333 |
} |
| 8334 |
|
| 8335 |
@Override |
| 8336 |
public boolean isFocusable() { |
| 8337 |
return false; |
| 8338 |
} |
| 8339 |
|
| 8340 |
@Override |
| 8341 |
public void requestFocus() { |
| 8342 |
} |
| 8343 |
|
| 8344 |
@Override |
| 8345 |
public boolean isOpaque() { |
| 8346 |
return false; |
| 8347 |
} |
| 8348 |
|
| 8349 |
public boolean scrollsForward() { |
| 8350 |
return getType() == EAST_BUTTON || getType() == SOUTH_BUTTON; |
| 8351 |
} |
| 8352 |
|
| 8353 |
public void mouseDragged(MouseEvent e) { |
| 8354 |
} |
| 8355 |
|
| 8356 |
public void mouseMoved(MouseEvent e) { |
| 8357 |
if (!isEnabled()) return; |
| 8358 |
setMouseOver(true); |
| 8359 |
repaint(); |
| 8360 |
} |
| 8361 |
|
| 8362 |
public void mouseClicked(MouseEvent e) { |
| 8363 |
if (!isEnabled()) return; |
| 8364 |
setMouseOver(true); |
| 8365 |
setMousePressed(false); |
| 8366 |
} |
| 8367 |
|
| 8368 |
public void mousePressed(MouseEvent e) { |
| 8369 |
if (!isEnabled()) return; |
| 8370 |
setMousePressed(true); |
| 8371 |
repaint(); |
| 8372 |
} |
| 8373 |
|
| 8374 |
public void mouseReleased(MouseEvent e) { |
| 8375 |
if (!isEnabled()) return; |
| 8376 |
setMousePressed(false); |
| 8377 |
setMouseOver(false); |
| 8378 |
} |
| 8379 |
|
| 8380 |
public void mouseEntered(MouseEvent e) { |
| 8381 |
if (!isEnabled()) return; |
| 8382 |
setMouseOver(true); |
| 8383 |
repaint(); |
| 8384 |
} |
| 8385 |
|
| 8386 |
public void mouseExited(MouseEvent e) { |
| 8387 |
if (!isEnabled()) return; |
| 8388 |
setMouseOver(false); |
| 8389 |
setMousePressed(false); |
| 8390 |
repaint(); |
| 8391 |
_tabScroller.tabPanel.repaint(); |
| 8392 |
} |
| 8393 |
|
| 8394 |
public int getType() { |
| 8395 |
return _type; |
| 8396 |
} |
| 8397 |
|
| 8398 |
public void setType(int type) { |
| 8399 |
_type = type; |
| 8400 |
} |
| 8401 |
|
| 8402 |
public boolean isMouseOver() { |
| 8403 |
return _mouseOver; |
| 8404 |
} |
| 8405 |
|
| 8406 |
public void setMouseOver(boolean mouseOver) { |
| 8407 |
_mouseOver = mouseOver; |
| 8408 |
} |
| 8409 |
|
| 8410 |
public boolean isMousePressed() { |
| 8411 |
return _mousePressed; |
| 8412 |
} |
| 8413 |
|
| 8414 |
public void setMousePressed(boolean mousePressed) { |
| 8415 |
_mousePressed = mousePressed; |
| 8416 |
} |
| 8417 |
} |
| 8418 |
|
| 8419 |
// Controller: event listeners |
| 8420 |
|
| 8421 |
/** |
| 8422 |
* This inner class is marked "public" due to a compiler bug. This class should be treated as a |
| 8423 |
* "protected" inner class. Instantiate it only within subclasses of VsnetJideTabbedPaneUI. |
| 8424 |
*/ |
| 8425 |
public class PropertyChangeHandler implements PropertyChangeListener { |
| 8426 |
public void propertyChange(PropertyChangeEvent e) { |
| 8427 |
JTabbedPane pane = (JTabbedPane) e.getSource(); |
| 8428 |
String name = e.getPropertyName(); |
| 8429 |
if ("mnemonicAt".equals(name)) { |
| 8430 |
updateMnemonics(); |
| 8431 |
pane.repaint(); |
| 8432 |
} |
| 8433 |
else if ("displayedMnemonicIndexAt".equals(name)) { |
| 8434 |
pane.repaint(); |
| 8435 |
} |
| 8436 |
else if (name.equals("indexForTitle")) { |
| 8437 |
int index = (Integer) e.getNewValue(); |
| 8438 |
String title = getCurrentDisplayTitleAt(_tabPane, index); |
| 8439 |
if (BasicHTML.isHTMLString(title)) { |
| 8440 |
if (htmlViews == null) { // Initialize vector |
| 8441 |
htmlViews = createHTMLVector(); |
| 8442 |
} |
| 8443 |
else { // Vector already exists |
| 8444 |
View v = BasicHTML.createHTMLView(_tabPane, title); |
| 8445 |
htmlViews.setElementAt(v, index); |
| 8446 |
} |
| 8447 |
} |
| 8448 |
else { |
| 8449 |
if (htmlViews != null && htmlViews.elementAt(index) != null) { |
| 8450 |
htmlViews.setElementAt(null, index); |
| 8451 |
} |
| 8452 |
} |
| 8453 |
updateMnemonics(); |
| 8454 |
|
| 8455 |
if (scrollableTabLayoutEnabled() && (_tabPane.getTabPlacement() == EAST || _tabPane.getTabPlacement() == WEST || _tabPane.getComponentOrientation().isLeftToRight())) { |
| 8456 |
_tabScroller.viewport.setViewSize(new Dimension( |
| 8457 |
_tabPane.getWidth(), _tabScroller.viewport.getViewSize().height)); |
| 8458 |
ensureActiveTabIsVisible(false); |
| 8459 |
} |
| 8460 |
} |
| 8461 |
else if (name.equals("indexForTabComponent")) { |
| 8462 |
if (_tabContainer != null) { |
| 8463 |
_tabContainer.removeUnusedTabComponents(); |
| 8464 |
} |
| 8465 |
Component c = SystemInfo.isJdk6Above() ? _tabPane.getTabComponentAt((Integer) e.getNewValue()) : null; |
| 8466 |
if (c != null) { |
| 8467 |
if (_tabContainer == null) { |
| 8468 |
installTabContainer(); |
| 8469 |
} |
| 8470 |
else { |
| 8471 |
_tabContainer.add(c); |
| 8472 |
} |
| 8473 |
} |
| 8474 |
_tabPane.revalidate(); |
| 8475 |
_tabPane.repaint(); |
| 8476 |
// calculatedBaseline = false; |
| 8477 |
} |
| 8478 |
else if (name.equals("tabLayoutPolicy")) { |
| 8479 |
_tabPane.updateUI(); |
| 8480 |
} |
| 8481 |
else if (name.equals("closeTabAction")) { |
| 8482 |
updateCloseAction(); |
| 8483 |
} |
| 8484 |
else if (name.equals(JideTabbedPane.PROPERTY_DRAG_OVER_DISABLED)) { |
| 8485 |
_tabPane.updateUI(); |
| 8486 |
} |
| 8487 |
else if (name.equals(JideTabbedPane.PROPERTY_TAB_COLOR_PROVIDER)) { |
| 8488 |
_tabPane.repaint(); |
| 8489 |
} |
| 8490 |
else if (name.equals("locale")) { |
| 8491 |
_tabPane.updateUI(); |
| 8492 |
} |
| 8493 |
else if (name.equals(JideTabbedPane.BOLDACTIVETAB_PROPERTY)) { |
| 8494 |
getTabPanel().invalidate(); |
| 8495 |
_tabPane.invalidate(); |
| 8496 |
if (scrollableTabLayoutEnabled() && (_tabPane.getTabPlacement() == EAST || _tabPane.getTabPlacement() == WEST || _tabPane.getComponentOrientation().isLeftToRight())) { |
| 8497 |
_tabScroller.viewport.setViewSize(new Dimension(_tabPane.getWidth(), _tabScroller.viewport.getViewSize().height)); |
| 8498 |
ensureActiveTabIsVisible(true); |
| 8499 |
} |
| 8500 |
} |
| 8501 |
else if (name.equals(JideTabbedPane.PROPERTY_TAB_LEADING_COMPONENT)) { |
| 8502 |
ensureCurrentLayout(); |
| 8503 |
if (_tabLeadingComponent != null) { |
| 8504 |
_tabLeadingComponent.setVisible(false); |
| 8505 |
_tabPane.remove(_tabLeadingComponent); |
| 8506 |
} |
| 8507 |
_tabLeadingComponent = (Component) e.getNewValue(); |
| 8508 |
if (_tabLeadingComponent != null) { |
| 8509 |
_tabLeadingComponent.setVisible(true); |
| 8510 |
_tabPane.add(_tabLeadingComponent); |
| 8511 |
} |
| 8512 |
_tabScroller.tabPanel.updateUI(); |
| 8513 |
} |
| 8514 |
else if (name.equals(JideTabbedPane.PROPERTY_TAB_TRAILING_COMPONENT)) { |
| 8515 |
ensureCurrentLayout(); |
| 8516 |
if (_tabTrailingComponent != null) { |
| 8517 |
_tabTrailingComponent.setVisible(false); |
| 8518 |
_tabPane.remove(_tabTrailingComponent); |
| 8519 |
} |
| 8520 |
_tabTrailingComponent = (Component) e.getNewValue(); |
| 8521 |
if (_tabTrailingComponent != null) { |
| 8522 |
_tabPane.add(_tabTrailingComponent); |
| 8523 |
_tabTrailingComponent.setVisible(true); |
| 8524 |
} |
| 8525 |
_tabScroller.tabPanel.updateUI(); |
| 8526 |
} |
| 8527 |
else if (name.equals(JideTabbedPane.SHRINK_TAB_PROPERTY) || |
| 8528 |
name.equals(JideTabbedPane.HIDE_IF_ONE_TAB_PROPERTY) || |
| 8529 |
name.equals(JideTabbedPane.SHOW_TAB_AREA_PROPERTY) || |
| 8530 |
name.equals(JideTabbedPane.SHOW_TAB_CONTENT_PROPERTY) || |
| 8531 |
name.equals(JideTabbedPane.BOX_STYLE_PROPERTY) || |
| 8532 |
name.equals(JideTabbedPane.SHOW_ICONS_PROPERTY) || |
| 8533 |
name.equals(JideTabbedPane.SHOW_CLOSE_BUTTON_PROPERTY) || |
| 8534 |
name.equals(JideTabbedPane.USE_DEFAULT_SHOW_ICONS_PROPERTY) || |
| 8535 |
name.equals(JideTabbedPane.SHOW_CLOSE_BUTTON_ON_TAB_PROPERTY) || |
| 8536 |
name.equals(JideTabbedPane.USE_DEFAULT_SHOW_CLOSE_BUTTON_ON_TAB_PROPERTY) || |
| 8537 |
name.equals(JideTabbedPane.TAB_CLOSABLE_PROPERTY) || |
| 8538 |
name.equals(JideTabbedPane.PROPERTY_TAB_SHAPE) || |
| 8539 |
name.equals(JideTabbedPane.PROPERTY_COLOR_THEME) || |
| 8540 |
name.equals(JideTabbedPane.PROPERTY_TAB_RESIZE_MODE) || |
| 8541 |
name.equals(JideTabbedPane.SHOW_TAB_BUTTONS_PROPERTY)) { |
| 8542 |
if ((name.equals(JideTabbedPane.USE_DEFAULT_SHOW_CLOSE_BUTTON_ON_TAB_PROPERTY) || name.equals(JideTabbedPane.SHOW_CLOSE_BUTTON_ON_TAB_PROPERTY)) |
| 8543 |
&& isShowCloseButton() && isShowCloseButtonOnTab()) { |
| 8544 |
ensureCloseButtonCreated(); |
| 8545 |
} |
| 8546 |
_tabPane.updateUI(); |
| 8547 |
} |
| 8548 |
else if (name.equals("__index_to_remove__")) { |
| 8549 |
setVisibleComponent(null); |
| 8550 |
} |
| 8551 |
else if (name.equals("componentOrientation")) { |
| 8552 |
if (_tabPane != null) { |
| 8553 |
if (_tabCount != _tabPane.getTabCount()) { |
| 8554 |
_tabCount = _tabPane.getTabCount(); |
| 8555 |
updateMnemonics(); |
| 8556 |
} |
| 8557 |
if (_tabScroller != null && _tabScroller.tabPanel != null) { |
| 8558 |
_tabScroller.setLeadingTabIndex(_tabPane.getTabPlacement(), _tabScroller.leadingTabIndex); |
| 8559 |
} |
| 8560 |
} |
| 8561 |
} |
| 8562 |
} |
| 8563 |
} |
| 8564 |
|
| 8565 |
protected void updateCloseAction() { |
| 8566 |
ensureCloseButtonCreated(); |
| 8567 |
} |
| 8568 |
|
| 8569 |
/** |
| 8570 |
* This inner class is marked "public" due to a compiler bug. This class should be treated as a |
| 8571 |
* "protected" inner class. Instantiate it only within subclasses of VsnetJideTabbedPaneUI. |
| 8572 |
*/ |
| 8573 |
public class TabSelectionHandler implements ChangeListener { |
| 8574 |
public void stateChanged(ChangeEvent e) { |
| 8575 |
((BasicJideTabbedPaneUI) _tabPane.getUI()).stopOrCancelEditing();//pane.stopTabEditing(); |
| 8576 |
ensureCloseButtonCreated(); |
| 8577 |
Runnable runnable = new Runnable() { |
| 8578 |
public void run() { |
| 8579 |
ensureActiveTabIsVisible(false); |
| 8580 |
} |
| 8581 |
}; |
| 8582 |
SwingUtilities.invokeLater(runnable); |
| 8583 |
} |
| 8584 |
} |
| 8585 |
|
| 8586 |
public class TabFocusListener implements FocusListener { |
| 8587 |
public void focusGained(FocusEvent e) { |
| 8588 |
repaintSelectedTab(); |
| 8589 |
} |
| 8590 |
|
| 8591 |
public void focusLost(FocusEvent e) { |
| 8592 |
repaintSelectedTab(); |
| 8593 |
} |
| 8594 |
|
| 8595 |
private void repaintSelectedTab() { |
| 8596 |
if (_tabPane.getTabCount() > 0) { |
| 8597 |
Rectangle rect = getTabBounds(_tabPane, _tabPane.getSelectedIndex()); |
| 8598 |
if (rect != null) { |
| 8599 |
_tabPane.repaint(rect); |
| 8600 |
} |
| 8601 |
} |
| 8602 |
} |
| 8603 |
} |
| 8604 |
|
| 8605 |
public class MouseMotionHandler extends MouseMotionAdapter { |
| 8606 |
|
| 8607 |
} |
| 8608 |
|
| 8609 |
/** |
| 8610 |
* This inner class is marked "public" due to a compiler bug. This class should be treated as a |
| 8611 |
* "protected" inner class. Instantiate it only within subclasses of VsnetJideTabbedPaneUI. |
| 8612 |
*/ |
| 8613 |
public class MouseHandler extends MouseAdapter { |
| 8614 |
@Override |
| 8615 |
public void mouseReleased(MouseEvent e) { |
| 8616 |
if (_tabPane == null || !_tabPane.isEnabled()) { |
| 8617 |
return; |
| 8618 |
} |
| 8619 |
|
| 8620 |
if (SwingUtilities.isMiddleMouseButton(e)) { |
| 8621 |
int tabIndex = tabForCoordinate(_tabPane, e.getX(), e.getY()); |
| 8622 |
Action action = getActionMap().get("closeTabAction"); |
| 8623 |
if (action != null && tabIndex >= 0 && _tabPane.isEnabledAt(tabIndex) && _tabPane.isCloseTabOnMouseMiddleButton() && _tabPane.isTabClosableAt(tabIndex)) { |
| 8624 |
ActionEvent event = new ActionEvent(_tabPane, tabIndex, "middleMouseButtonClicked"); |
| 8625 |
action.actionPerformed(event); |
| 8626 |
} |
| 8627 |
} |
| 8628 |
} |
| 8629 |
|
| 8630 |
@Override |
| 8631 |
public void mousePressed(MouseEvent e) { |
| 8632 |
if (_tabPane == null || !_tabPane.isEnabled()) { |
| 8633 |
return; |
| 8634 |
} |
| 8635 |
|
| 8636 |
if (SwingUtilities.isLeftMouseButton(e) || _tabPane.isRightClickSelect()) { |
| 8637 |
int tabIndex = tabForCoordinate(_tabPane, e.getX(), e.getY()); |
| 8638 |
if (tabIndex >= 0 && _tabPane.isEnabledAt(tabIndex)) { |
| 8639 |
if (tabIndex == _tabPane.getSelectedIndex() && JideSwingUtilities.isAncestorOfFocusOwner(_tabPane)) { |
| 8640 |
if (_tabPane.isAutoFocusOnTabHideClose() && _tabPane.isRequestFocusEnabled()) { |
| 8641 |
// if (!_tabPane.requestFocusInWindow()) { |
| 8642 |
_tabPane.requestFocus(); |
| 8643 |
// } |
| 8644 |
} |
| 8645 |
} |
| 8646 |
else { |
| 8647 |
_tabPane.setSelectedIndex(tabIndex); |
| 8648 |
if (_tabPane == null) { |
| 8649 |
return; // in case the user invoked some APIs to cause updateUI() being invoked |
| 8650 |
} |
| 8651 |
_tabPane.processMouseSelection(tabIndex, e); |
| 8652 |
final Component comp = _tabPane.getComponentAt(tabIndex); |
| 8653 |
if (_tabPane.isAutoFocusOnTabHideClose() && comp != null && !comp.isVisible() && SystemInfo.isJdk15Above() && !SystemInfo.isJdk6Above()) { |
| 8654 |
comp.addComponentListener(new ComponentAdapter() { |
| 8655 |
@Override |
| 8656 |
public void componentShown(ComponentEvent e) { |
| 8657 |
// remove the listener |
| 8658 |
comp.removeComponentListener(this); |
| 8659 |
|
| 8660 |
Component lastFocused = _tabPane.getLastFocusedComponent(comp); |
| 8661 |
if (lastFocused != null) { |
| 8662 |
// this code works in JDK6 but on JDK5 |
| 8663 |
// if (!lastFocused.requestFocusInWindow()) { |
| 8664 |
lastFocused.requestFocus(); |
| 8665 |
// } |
| 8666 |
} |
| 8667 |
else if (_tabPane.isRequestFocusEnabled()) { |
| 8668 |
// if (!_tabPane.requestFocusInWindow()) { |
| 8669 |
_tabPane.requestFocus(); |
| 8670 |
// } |
| 8671 |
} |
| 8672 |
} |
| 8673 |
}); |
| 8674 |
} |
| 8675 |
else { |
| 8676 |
Component lastFocused = _tabPane.getLastFocusedComponent(comp); |
| 8677 |
if (lastFocused != null) { |
| 8678 |
// this code works in JDK6 but on JDK5 |
| 8679 |
// if (!lastFocused.requestFocusInWindow()) { |
| 8680 |
lastFocused.requestFocus(); |
| 8681 |
// } |
| 8682 |
} |
| 8683 |
else { |
| 8684 |
// first try to find a default component. |
| 8685 |
boolean foundInTab = JideSwingUtilities.compositeRequestFocus(comp); |
| 8686 |
if (!foundInTab) { // && !_tabPane.requestFocusInWindow()) { |
| 8687 |
_tabPane.requestFocus(); |
| 8688 |
} |
| 8689 |
} |
| 8690 |
} |
| 8691 |
} |
| 8692 |
} |
| 8693 |
} |
| 8694 |
if (!isTabEditing()) |
| 8695 |
startEditing(e); // start editing tab |
| 8696 |
} |
| 8697 |
|
| 8698 |
} |
| 8699 |
|
| 8700 |
public class MouseWheelHandler implements MouseWheelListener { |
| 8701 |
public void mouseWheelMoved(MouseWheelEvent e) { |
| 8702 |
if (_tabPane.isScrollSelectedTabOnWheel()) { |
| 8703 |
// set selected tab to the currently selected tab plus the wheel rotation but between |
| 8704 |
// 0 and tabCount-1 |
| 8705 |
_tabPane.setSelectedIndex( |
| 8706 |
Math.min(_tabPane.getTabCount() - 1, Math.max(0, _tabPane.getSelectedIndex() + e.getWheelRotation()))); |
| 8707 |
} |
| 8708 |
else if (scrollableTabLayoutEnabled() && e.getWheelRotation() != 0) { |
| 8709 |
if (e.getWheelRotation() > 0) { |
| 8710 |
for (int i = 0; i < e.getScrollAmount(); i++) { |
| 8711 |
_tabScroller.scrollForward(_tabPane.getTabPlacement()); |
| 8712 |
} |
| 8713 |
} |
| 8714 |
else if (e.getWheelRotation() < 0) { |
| 8715 |
for (int i = 0; i < e.getScrollAmount(); i++) { |
| 8716 |
_tabScroller.scrollBackward(_tabPane.getTabPlacement()); |
| 8717 |
} |
| 8718 |
} |
| 8719 |
} |
| 8720 |
} |
| 8721 |
} |
| 8722 |
|
| 8723 |
private class ComponentHandler implements ComponentListener { |
| 8724 |
public void componentResized(ComponentEvent e) { |
| 8725 |
if (scrollableTabLayoutEnabled() && (_tabPane.getTabPlacement() == EAST || _tabPane.getTabPlacement() == WEST || _tabPane.getComponentOrientation().isLeftToRight())) { |
| 8726 |
_tabScroller.viewport.setViewSize(new Dimension(_tabPane.getWidth(), _tabScroller.viewport.getViewSize().height)); |
| 8727 |
ensureActiveTabIsVisible(true); |
| 8728 |
} |
| 8729 |
} |
| 8730 |
|
| 8731 |
public void componentMoved(ComponentEvent e) { |
| 8732 |
} |
| 8733 |
|
| 8734 |
public void componentShown(ComponentEvent e) { |
| 8735 |
} |
| 8736 |
|
| 8737 |
public void componentHidden(ComponentEvent e) { |
| 8738 |
} |
| 8739 |
} |
| 8740 |
|
| 8741 |
/* GES 2/3/99: |
| 8742 |
The container listener code was added to support HTML |
| 8743 |
rendering of tab titles. |
| 8744 |
|
| 8745 |
Ideally, we would be able to listen for property changes |
| 8746 |
when a tab is added or its text modified. At the moment |
| 8747 |
there are no such events because the Beans spec doesn't |
| 8748 |
allow 'indexed' property changes (i.e. tab 2's text changed |
| 8749 |
from A to B). |
| 8750 |
|
| 8751 |
In order to get around this, we listen for tabs to be added |
| 8752 |
or removed by listening for the container events. we then |
| 8753 |
queue up a runnable (so the component has a chance to complete |
| 8754 |
the add) which checks the tab title of the new component to see |
| 8755 |
if it requires HTML rendering. |
| 8756 |
|
| 8757 |
The Views (one per tab title requiring HTML rendering) are |
| 8758 |
stored in the htmlViews Vector, which is only allocated after |
| 8759 |
the first time we run into an HTML tab. Note that this vector |
| 8760 |
is kept in step with the number of pages, and nulls are added |
| 8761 |
for those pages whose tab title do not require HTML rendering. |
| 8762 |
|
| 8763 |
This makes it easy for the paint and layout code to tell |
| 8764 |
whether to invoke the HTML engine without having to check |
| 8765 |
the string during time-sensitive operations. |
| 8766 |
|
| 8767 |
When we have added a way to listen for tab additions and |
| 8768 |
changes to tab text, this code should be removed and |
| 8769 |
replaced by something which uses that. */ |
| 8770 |
|
| 8771 |
private class ContainerHandler implements ContainerListener { |
| 8772 |
public void componentAdded(ContainerEvent e) { |
| 8773 |
if (_tabPane == null) { |
| 8774 |
return; |
| 8775 |
} |
| 8776 |
JideTabbedPane tp = (JideTabbedPane) e.getContainer(); |
| 8777 |
// updateTabPanel(); |
| 8778 |
Component child = e.getChild(); |
| 8779 |
if (child instanceof UIResource || child == tp.getTabLeadingComponent() || child == tp.getTabTrailingComponent()) { |
| 8780 |
return; |
| 8781 |
} |
| 8782 |
|
| 8783 |
int index = tp.indexOfComponent(child); |
| 8784 |
String title = getCurrentDisplayTitleAt(tp, index); |
| 8785 |
boolean isHTML = BasicHTML.isHTMLString(title); |
| 8786 |
if (isHTML) { |
| 8787 |
if (htmlViews == null) { // Initialize vector |
| 8788 |
htmlViews = createHTMLVector(); |
| 8789 |
} |
| 8790 |
else { // Vector already exists |
| 8791 |
View v = BasicHTML.createHTMLView(tp, title); |
| 8792 |
htmlViews.insertElementAt(v, index); |
| 8793 |
} |
| 8794 |
} |
| 8795 |
else { // Not HTML |
| 8796 |
if (htmlViews != null) { // Add placeholder |
| 8797 |
htmlViews.insertElementAt(null, index); |
| 8798 |
} // else nada! |
| 8799 |
} |
| 8800 |
|
| 8801 |
if (_tabPane.isTabEditing()) { |
| 8802 |
if (index <= _tabPane.getEditingTabIndex()) { |
| 8803 |
((BasicJideTabbedPaneUI) _tabPane.getUI())._editingTab++; |
| 8804 |
} |
| 8805 |
ensureCloseButtonCreated(); |
| 8806 |
((BasicJideTabbedPaneUI) _tabPane.getUI()).stopOrCancelEditing();//_tabPane.stopTabEditing(); |
| 8807 |
} |
| 8808 |
|
| 8809 |
ensureCloseButtonCreated(); |
| 8810 |
} |
| 8811 |
|
| 8812 |
public void componentRemoved(ContainerEvent e) { |
| 8813 |
if (_tabPane == null) { |
| 8814 |
return; |
| 8815 |
} |
| 8816 |
JideTabbedPane tp = (JideTabbedPane) e.getContainer(); |
| 8817 |
// updateTabPanel(); |
| 8818 |
Component child = e.getChild(); |
| 8819 |
if (child instanceof UIResource || child == tp.getTabLeadingComponent() || child == tp.getTabTrailingComponent()) { |
| 8820 |
return; |
| 8821 |
} |
| 8822 |
|
| 8823 |
// NOTE 4/15/2002 (joutwate): |
| 8824 |
// This fix is implemented using client properties since there is |
| 8825 |
// currently no IndexPropertyChangeEvent. Once |
| 8826 |
// IndexPropertyChangeEvents have been added this code should be |
| 8827 |
// modified to use it. |
| 8828 |
Integer index = |
| 8829 |
(Integer) tp.getClientProperty("__index_to_remove__"); |
| 8830 |
if (index != null) { |
| 8831 |
if (htmlViews != null && htmlViews.size() > index) { |
| 8832 |
htmlViews.removeElementAt(index); |
| 8833 |
} |
| 8834 |
tp.putClientProperty("__index_to_remove__", null); |
| 8835 |
} |
| 8836 |
|
| 8837 |
if (_tabPane.isTabEditing()) { |
| 8838 |
((BasicJideTabbedPaneUI) _tabPane.getUI()).stopOrCancelEditing();//_tabPane.stopTabEditing(); |
| 8839 |
} |
| 8840 |
|
| 8841 |
ensureCloseButtonCreated(); |
| 8842 |
// ensureActiveTabIsVisible(true); |
| 8843 |
} |
| 8844 |
} |
| 8845 |
|
| 8846 |
private Vector createHTMLVector() { |
| 8847 |
Vector htmlViews = new Vector(); |
| 8848 |
int count = _tabPane.getTabCount(); |
| 8849 |
if (count > 0) { |
| 8850 |
for (int i = 0; i < count; i++) { |
| 8851 |
String title = getCurrentDisplayTitleAt(_tabPane, i); |
| 8852 |
if (BasicHTML.isHTMLString(title)) { |
| 8853 |
htmlViews.addElement(BasicHTML.createHTMLView(_tabPane, title)); |
| 8854 |
} |
| 8855 |
else { |
| 8856 |
htmlViews.addElement(null); |
| 8857 |
} |
| 8858 |
} |
| 8859 |
} |
| 8860 |
return htmlViews; |
| 8861 |
} |
| 8862 |
|
| 8863 |
@Override |
| 8864 |
public Component getTabPanel() { |
| 8865 |
if (scrollableTabLayoutEnabled()) |
| 8866 |
return _tabScroller.tabPanel; |
| 8867 |
else |
| 8868 |
return _tabPane; |
| 8869 |
} |
| 8870 |
|
| 8871 |
static class AbstractTab { |
| 8872 |
int width; |
| 8873 |
|
| 8874 |
int id; |
| 8875 |
|
| 8876 |
public void copy(AbstractTab tab) { |
| 8877 |
this.width = tab.width; |
| 8878 |
this.id = tab.id; |
| 8879 |
} |
| 8880 |
} |
| 8881 |
|
| 8882 |
public static class TabSpaceAllocator { |
| 8883 |
static final int startOffset = 4; |
| 8884 |
|
| 8885 |
private Insets insets = null; |
| 8886 |
|
| 8887 |
static final int tabWidth = 24; |
| 8888 |
|
| 8889 |
static final int textIconGap = 8; |
| 8890 |
|
| 8891 |
private AbstractTab tabs[]; |
| 8892 |
|
| 8893 |
private void setInsets(Insets insets) { |
| 8894 |
this.insets = (Insets) insets.clone(); |
| 8895 |
} |
| 8896 |
|
| 8897 |
private void init(Rectangle rects[], Insets insets) { |
| 8898 |
setInsets(insets); |
| 8899 |
tabs = new AbstractTab[rects.length]; |
| 8900 |
// fill up internal datastructure |
| 8901 |
for (int i = 0; i < rects.length; i++) { |
| 8902 |
tabs[i] = new AbstractTab(); |
| 8903 |
tabs[i].id = i; |
| 8904 |
tabs[i].width = rects[i].width; |
| 8905 |
} |
| 8906 |
tabSort(); |
| 8907 |
} |
| 8908 |
|
| 8909 |
private void bestfit(AbstractTab tabs[], int freeWidth, int startTab) { |
| 8910 |
int tabCount = tabs.length; |
| 8911 |
int worstWidth; |
| 8912 |
int currentTabWidth; |
| 8913 |
|
| 8914 |
int initialPos; |
| 8915 |
currentTabWidth = tabs[startTab].width; |
| 8916 |
initialPos = startTab; |
| 8917 |
|
| 8918 |
if (startTab == tabCount - 1) { |
| 8919 |
// directly fill as worst case |
| 8920 |
tabs[startTab].width = freeWidth; |
| 8921 |
return; |
| 8922 |
} |
| 8923 |
worstWidth = freeWidth / (tabCount - startTab); |
| 8924 |
|
| 8925 |
while (currentTabWidth < worstWidth) { |
| 8926 |
freeWidth -= currentTabWidth; |
| 8927 |
if (++startTab < tabCount - 1) { |
| 8928 |
currentTabWidth = tabs[startTab].width; |
| 8929 |
} |
| 8930 |
else { |
| 8931 |
tabs[startTab].width = worstWidth; |
| 8932 |
return; |
| 8933 |
} |
| 8934 |
} |
| 8935 |
|
| 8936 |
if (startTab == initialPos) { |
| 8937 |
// didn't find anything smaller |
| 8938 |
for (int i = startTab; i < tabCount; i++) { |
| 8939 |
tabs[i].width = worstWidth; |
| 8940 |
} |
| 8941 |
} |
| 8942 |
else if (startTab < tabCount - 1) { |
| 8943 |
bestfit(tabs, freeWidth, startTab); |
| 8944 |
} |
| 8945 |
} |
| 8946 |
|
| 8947 |
// bubble sort for now |
| 8948 |
|
| 8949 |
private void tabSort() { |
| 8950 |
int tabCount = tabs.length; |
| 8951 |
AbstractTab tempTab = new AbstractTab(); |
| 8952 |
for (int i = 0; i < tabCount - 1; i++) { |
| 8953 |
for (int j = i + 1; j < tabCount; j++) { |
| 8954 |
if (tabs[i].width > tabs[j].width) { |
| 8955 |
tempTab.copy(tabs[j]); |
| 8956 |
tabs[j].copy(tabs[i]); |
| 8957 |
tabs[i].copy(tempTab); |
| 8958 |
} |
| 8959 |
} |
| 8960 |
} |
| 8961 |
} |
| 8962 |
|
| 8963 |
// directly modify the rects |
| 8964 |
|
| 8965 |
private void outpush(Rectangle rects[]) { |
| 8966 |
for (AbstractTab tab : tabs) { |
| 8967 |
rects[tab.id].width = tab.width; |
| 8968 |
} |
| 8969 |
rects[0].x = startOffset; |
| 8970 |
for (int i = 1; i < rects.length; i++) { |
| 8971 |
rects[i].x = rects[i - 1].x + rects[i - 1].width; |
| 8972 |
} |
| 8973 |
} |
| 8974 |
|
| 8975 |
public void reArrange(Rectangle rects[], Insets insets, int totalAvailableSpace) { |
| 8976 |
init(rects, insets); |
| 8977 |
bestfit(tabs, totalAvailableSpace, 0); |
| 8978 |
outpush(rects); |
| 8979 |
int totalUsedWidth = rects[rects.length - 1].x + rects[rects.length - 1].width; |
| 8980 |
if (totalUsedWidth > totalAvailableSpace) { |
| 8981 |
int gap = totalUsedWidth - totalAvailableSpace; |
| 8982 |
rects[rects.length - 1].width -= gap; |
| 8983 |
} |
| 8984 |
clearup(); |
| 8985 |
} |
| 8986 |
|
| 8987 |
private void clearup() { |
| 8988 |
for (int i = 0; i < tabs.length; i++) { |
| 8989 |
tabs[i] = null; |
| 8990 |
} |
| 8991 |
tabs = null; |
| 8992 |
} |
| 8993 |
} |
| 8994 |
|
| 8995 |
@Override |
| 8996 |
public void ensureActiveTabIsVisible(boolean scrollLeft) { |
| 8997 |
if (_tabPane == null || _tabPane.getWidth() == 0) { |
| 8998 |
return; |
| 8999 |
} |
| 9000 |
|
| 9001 |
if (scrollableTabLayoutEnabled()) { |
| 9002 |
ensureCurrentLayout(); |
| 9003 |
/* |
| 9004 |
if (scrollLeft && _rects.length > 0) { |
| 9005 |
if (_tabPane.getTabPlacement() == LEFT || _tabPane.getTabPlacement() == RIGHT || _tabPane.getComponentOrientation().isLeftToRight()) { |
| 9006 |
_tabScroller.viewport.setViewPosition(new Point(0, 0)); |
| 9007 |
_tabScroller.tabPanel.scrollRectToVisible(_rects[0]); |
| 9008 |
} |
| 9009 |
else { |
| 9010 |
_tabScroller.viewport.setViewPosition(new Point(0, 0)); |
| 9011 |
} |
| 9012 |
} |
| 9013 |
*/ |
| 9014 |
int index = _tabPane.getSelectedIndex(); |
| 9015 |
if ((!scrollLeft || index != 0) && index < _rects.length && index != -1) { |
| 9016 |
_tabScroller.tabPanel.scrollIndexToVisible(index); |
| 9017 |
if (_tabPane.getTabPlacement() == LEFT || _tabPane.getTabPlacement() == RIGHT || _tabPane.getComponentOrientation().isLeftToRight()) { |
| 9018 |
_tabScroller.tabPanel.getParent().doLayout(); |
| 9019 |
} |
| 9020 |
} |
| 9021 |
if (_tabPane.getTabPlacement() == LEFT || _tabPane.getTabPlacement() == RIGHT || _tabPane.getComponentOrientation().isLeftToRight()) { |
| 9022 |
_tabPane.revalidate(); |
| 9023 |
_tabPane.repaintTabAreaAndContentBorder(); |
| 9024 |
} |
| 9025 |
else { |
| 9026 |
_tabPane.repaint(); |
| 9027 |
} |
| 9028 |
} |
| 9029 |
} |
| 9030 |
|
| 9031 |
protected boolean isShowCloseButtonOnTab() { |
| 9032 |
if (_tabPane.isUseDefaultShowCloseButtonOnTab()) { |
| 9033 |
return _showCloseButtonOnTab; |
| 9034 |
} |
| 9035 |
else return _tabPane.isShowCloseButtonOnTab(); |
| 9036 |
} |
| 9037 |
|
| 9038 |
protected boolean isShowCloseButton() { |
| 9039 |
return _tabPane.isShowCloseButton(); |
| 9040 |
} |
| 9041 |
|
| 9042 |
public void ensureCloseButtonCreated() { |
| 9043 |
if (isShowCloseButton() && isShowCloseButtonOnTab() && scrollableTabLayoutEnabled()) { |
| 9044 |
if (_closeButtons == null) { |
| 9045 |
_closeButtons = new JButton[_tabPane.getTabCount()]; |
| 9046 |
} |
| 9047 |
else if (_closeButtons.length > _tabPane.getTabCount()) { |
| 9048 |
JButton[] temp = new JButton[_tabPane.getTabCount()]; |
| 9049 |
System.arraycopy(_closeButtons, 0, temp, 0, temp.length); |
| 9050 |
for (int i = temp.length; i < _closeButtons.length; i++) { |
| 9051 |
JButton tabCloseButton = _closeButtons[i]; |
| 9052 |
_tabScroller.tabPanel.remove(tabCloseButton); |
| 9053 |
} |
| 9054 |
_closeButtons = temp; |
| 9055 |
} |
| 9056 |
else if (_closeButtons.length < _tabPane.getTabCount()) { |
| 9057 |
JButton[] temp = new JButton[_tabPane.getTabCount()]; |
| 9058 |
System.arraycopy(_closeButtons, 0, temp, 0, _closeButtons.length); |
| 9059 |
_closeButtons = temp; |
| 9060 |
} |
| 9061 |
ActionMap am = getActionMap(); |
| 9062 |
for (int i = 0; i < _closeButtons.length; i++) { |
| 9063 |
JButton closeButton = _closeButtons[i]; |
| 9064 |
if (closeButton == null) { |
| 9065 |
closeButton = createButton(JideTabbedPane.BUTTON_CLOSE); |
| 9066 |
_closeButtons[i] = closeButton; |
| 9067 |
if (closeButton instanceof JideTabbedPane.NoFocusButton) { |
| 9068 |
((JideTabbedPane.NoFocusButton) closeButton).setIndex(i); |
| 9069 |
} |
| 9070 |
closeButton.setBounds(0, 0, 0, 0); |
| 9071 |
Action action = _tabPane.getCloseAction(); |
| 9072 |
Icon closeIcon = closeButton.getIcon(); |
| 9073 |
closeButton.setAction(am.get("closeTabAction")); |
| 9074 |
updateButtonFromAction(closeButton, action); |
| 9075 |
if (closeIcon != null) { |
| 9076 |
_tabScroller.closeButton.setIcon(closeIcon); |
| 9077 |
} |
| 9078 |
_tabScroller.tabPanel.add(closeButton); |
| 9079 |
} |
| 9080 |
if (closeButton instanceof JideTabbedPane.NoFocusButton) { |
| 9081 |
((JideTabbedPane.NoFocusButton) closeButton).setIndex(i); |
| 9082 |
} |
| 9083 |
} |
| 9084 |
} |
| 9085 |
} |
| 9086 |
|
| 9087 |
private void updateButtonFromAction(JButton closeButton, Action action) { |
| 9088 |
if (action == null) { |
| 9089 |
return; |
| 9090 |
} |
| 9091 |
closeButton.setEnabled(action.isEnabled()); |
| 9092 |
Object desc = action.getValue(Action.SHORT_DESCRIPTION); |
| 9093 |
if (desc instanceof String) { |
| 9094 |
closeButton.setToolTipText((String) desc); |
| 9095 |
} |
| 9096 |
Object icon = action.getValue(Action.SMALL_ICON); |
| 9097 |
if (icon instanceof Icon) { |
| 9098 |
closeButton.setIcon((Icon) icon); |
| 9099 |
} |
| 9100 |
} |
| 9101 |
|
| 9102 |
protected boolean isShowTabButtons() { |
| 9103 |
return _tabPane.getTabCount() != 0 && _tabPane.isShowTabArea() && _tabPane.isShowTabButtons(); |
| 9104 |
} |
| 9105 |
|
| 9106 |
protected boolean isShrinkTabs() { |
| 9107 |
return _tabPane.getTabCount() != 0 && _tabPane.getTabResizeMode() == JideTabbedPane.RESIZE_MODE_FIT; |
| 9108 |
} |
| 9109 |
|
| 9110 |
protected TabEditor _tabEditor; |
| 9111 |
|
| 9112 |
protected boolean _isEditing; |
| 9113 |
|
| 9114 |
protected int _editingTab = -1; |
| 9115 |
|
| 9116 |
protected String _oldValue; |
| 9117 |
|
| 9118 |
protected String _oldPrefix; |
| 9119 |
|
| 9120 |
protected String _oldPostfix; |
| 9121 |
// mtf - changed |
| 9122 |
protected Component _originalFocusComponent; |
| 9123 |
|
| 9124 |
@Override |
| 9125 |
public boolean isTabEditing() { |
| 9126 |
return _isEditing; |
| 9127 |
} |
| 9128 |
|
| 9129 |
protected TabEditor createDefaultTabEditor() { |
| 9130 |
final TabEditor editor = new TabEditor(); |
| 9131 |
editor.getDocument().addDocumentListener(this); |
| 9132 |
editor.setInputVerifier(new InputVerifier() { |
| 9133 |
@Override |
| 9134 |
public boolean verify(JComponent input) { |
| 9135 |
return true; |
| 9136 |
} |
| 9137 |
|
| 9138 |
public boolean shouldYieldFocus(JComponent input) { |
| 9139 |
boolean shouldStopEditing = true; |
| 9140 |
if (_tabPane != null && _tabPane.isTabEditing() && _tabPane.getTabEditingValidator() != null) { |
| 9141 |
shouldStopEditing = _tabPane.getTabEditingValidator().alertIfInvalid(_editingTab, _oldPrefix + _tabEditor.getText() + _oldPostfix); |
| 9142 |
} |
| 9143 |
|
| 9144 |
if (shouldStopEditing && _tabPane != null && _tabPane.isTabEditing()) { |
| 9145 |
_tabPane.stopTabEditing(); |
| 9146 |
} |
| 9147 |
|
| 9148 |
return shouldStopEditing; |
| 9149 |
} |
| 9150 |
}); |
| 9151 |
editor.addFocusListener(new FocusAdapter() { |
| 9152 |
@Override |
| 9153 |
public void focusGained(FocusEvent e) { |
| 9154 |
_originalFocusComponent = e.getOppositeComponent(); |
| 9155 |
} |
| 9156 |
|
| 9157 |
@Override |
| 9158 |
public void focusLost(FocusEvent e) { |
| 9159 |
} |
| 9160 |
}); |
| 9161 |
editor.addActionListener(new ActionListener() { |
| 9162 |
public void actionPerformed(ActionEvent e) { |
| 9163 |
editor.transferFocus(); |
| 9164 |
} |
| 9165 |
}); |
| 9166 |
editor.addKeyListener(new KeyAdapter() { |
| 9167 |
@Override |
| 9168 |
public void keyPressed(KeyEvent e) { |
| 9169 |
if (_isEditing && (e.getKeyCode() == KeyEvent.VK_ESCAPE)) { |
| 9170 |
if (_editingTab >= 0 && _editingTab < _tabPane.getTabCount()) { |
| 9171 |
_tabPane.setTitleAt(_editingTab, _oldValue); |
| 9172 |
} |
| 9173 |
_tabPane.cancelTabEditing(); |
| 9174 |
} |
| 9175 |
} |
| 9176 |
}); |
| 9177 |
editor.setFont(_tabPane.getFont()); |
| 9178 |
|
| 9179 |
return editor; |
| 9180 |
} |
| 9181 |
|
| 9182 |
@Override |
| 9183 |
public void stopTabEditing() { |
| 9184 |
if (_editingTab >= 0 && _editingTab < _tabPane.getTabCount()) { |
| 9185 |
_tabPane.setTitleAt(_editingTab, _oldPrefix + _tabEditor.getText() + _oldPostfix); |
| 9186 |
} |
| 9187 |
cancelTabEditing(); |
| 9188 |
} |
| 9189 |
|
| 9190 |
@Override |
| 9191 |
public void cancelTabEditing() { |
| 9192 |
if (_tabEditor != null) { |
| 9193 |
_isEditing = false; |
| 9194 |
|
| 9195 |
((Container) getTabPanel()).remove(_tabEditor); |
| 9196 |
|
| 9197 |
if (_editingTab >= 0 && _editingTab < _tabPane.getTabCount()) { |
| 9198 |
Rectangle tabRect = _tabPane.getBoundsAt(_editingTab); |
| 9199 |
getTabPanel().repaint(tabRect.x, tabRect.y, |
| 9200 |
tabRect.width, tabRect.height); |
| 9201 |
} |
| 9202 |
else { |
| 9203 |
getTabPanel().repaint(); |
| 9204 |
} |
| 9205 |
|
| 9206 |
if (_originalFocusComponent != null) |
| 9207 |
_originalFocusComponent.requestFocus(); // InWindow(); |
| 9208 |
else |
| 9209 |
_tabPane.requestFocusForVisibleComponent(); |
| 9210 |
|
| 9211 |
_editingTab = -1; |
| 9212 |
_oldValue = null; |
| 9213 |
_tabPane.doLayout(); |
| 9214 |
} |
| 9215 |
} |
| 9216 |
|
| 9217 |
@Override |
| 9218 |
public boolean editTabAt(int tabIndex) { |
| 9219 |
if (_isEditing) { |
| 9220 |
return false; |
| 9221 |
} |
| 9222 |
|
| 9223 |
// _tabPane.popupSelectedIndex(tabIndex); |
| 9224 |
if (_tabEditor == null) |
| 9225 |
_tabEditor = createDefaultTabEditor(); |
| 9226 |
|
| 9227 |
if (_tabEditor != null) { |
| 9228 |
prepareEditor(_tabEditor, tabIndex); |
| 9229 |
|
| 9230 |
((Container) getTabPanel()).add(_tabEditor); |
| 9231 |
resizeEditor(tabIndex); |
| 9232 |
|
| 9233 |
_editingTab = tabIndex; |
| 9234 |
_isEditing = true; |
| 9235 |
|
| 9236 |
_tabEditor.requestFocusInWindow(); |
| 9237 |
_tabEditor.selectAll(); |
| 9238 |
return true; |
| 9239 |
} |
| 9240 |
return false; |
| 9241 |
} |
| 9242 |
|
| 9243 |
@Override |
| 9244 |
public int getEditingTabIndex() { |
| 9245 |
return _editingTab; |
| 9246 |
} |
| 9247 |
|
| 9248 |
protected void prepareEditor(TabEditor e, int tabIndex) { |
| 9249 |
Font font; |
| 9250 |
if (_tabPane.getSelectedTabFont() != null) { |
| 9251 |
font = _tabPane.getSelectedTabFont(); |
| 9252 |
} |
| 9253 |
else { |
| 9254 |
font = _tabPane.getFont(); |
| 9255 |
} |
| 9256 |
if (_tabPane.isBoldActiveTab() && font.getStyle() != Font.BOLD) { |
| 9257 |
font = font.deriveFont(Font.BOLD); |
| 9258 |
} |
| 9259 |
e.setFont(font); |
| 9260 |
|
| 9261 |
_oldValue = _tabPane.getTitleAt(tabIndex); |
| 9262 |
if (_oldValue.startsWith("<HTML>") && _oldValue.endsWith("/HTML>")) { |
| 9263 |
_oldPrefix = "<HTML>"; |
| 9264 |
_oldPostfix = "</HTML>"; |
| 9265 |
String title = _oldValue.substring("<HTML>".length(), _oldValue.length() - "</HTML>".length()); |
| 9266 |
if (title.startsWith("<B>") && title.endsWith("/B>")) { |
| 9267 |
title = title.substring("<B>".length(), title.length() - "</B>".length()); |
| 9268 |
_oldPrefix += "<B>"; |
| 9269 |
_oldPostfix = "</B>" + _oldPostfix; |
| 9270 |
} |
| 9271 |
e.setText(title); |
| 9272 |
} |
| 9273 |
else { |
| 9274 |
_oldPrefix = ""; |
| 9275 |
_oldPostfix = ""; |
| 9276 |
e.setText(_oldValue); |
| 9277 |
} |
| 9278 |
e.selectAll(); |
| 9279 |
e.setForeground(_tabPane.getForegroundAt(tabIndex)); |
| 9280 |
} |
| 9281 |
|
| 9282 |
protected Rectangle getTabsTextBoundsAt(int tabIndex) { |
| 9283 |
Rectangle tabRect = _tabPane.getBoundsAt(tabIndex); |
| 9284 |
Rectangle iconRect = new Rectangle(), |
| 9285 |
textRect = new Rectangle(); |
| 9286 |
|
| 9287 |
if (tabRect.width < 200) // random max size; |
| 9288 |
tabRect.width = 200; |
| 9289 |
|
| 9290 |
String title = getCurrentDisplayTitleAt(_tabPane, tabIndex); |
| 9291 |
if (title == null || title.length() == 0) { |
| 9292 |
title = "i"; // adjust so that the editor is painted at correct position |
| 9293 |
} |
| 9294 |
// while (title == null || title.length() < 3) |
| 9295 |
// title += " "; |
| 9296 |
|
| 9297 |
Icon icon = _tabPane.getIconForTab(tabIndex); |
| 9298 |
|
| 9299 |
Font font = _tabPane.getFont(); |
| 9300 |
if (tabIndex == _tabPane.getSelectedIndex() && _tabPane.isBoldActiveTab()) { |
| 9301 |
font = font.deriveFont(Font.BOLD); |
| 9302 |
} |
| 9303 |
SwingUtilities.layoutCompoundLabel(_tabPane, _tabPane.getGraphics().getFontMetrics(font), title, icon, |
| 9304 |
SwingUtilities.CENTER, SwingUtilities.CENTER, |
| 9305 |
SwingUtilities.CENTER, SwingUtilities.TRAILING, tabRect, |
| 9306 |
iconRect, textRect, icon == null ? 0 : _textIconGap); |
| 9307 |
|
| 9308 |
if (_tabPane.getTabPlacement() == TOP || _tabPane.getTabPlacement() == BOTTOM) { |
| 9309 |
iconRect.x = tabRect.x + _iconMargin; |
| 9310 |
textRect.x = (icon != null ? iconRect.x + iconRect.width + _textIconGap : tabRect.x + _textPadding); |
| 9311 |
textRect.width += 2; |
| 9312 |
} |
| 9313 |
else { |
| 9314 |
iconRect.y = tabRect.y + _iconMargin; |
| 9315 |
textRect.y = (icon != null ? iconRect.y + iconRect.height + _textIconGap : tabRect.y + _textPadding); |
| 9316 |
iconRect.x = tabRect.x + 2; |
| 9317 |
textRect.x = tabRect.x + 2; |
| 9318 |
textRect.height += 2; |
| 9319 |
} |
| 9320 |
|
| 9321 |
return textRect; |
| 9322 |
} |
| 9323 |
|
| 9324 |
private void updateTab() { |
| 9325 |
if (_isEditing) { |
| 9326 |
resizeEditor(getEditingTabIndex()); |
| 9327 |
} |
| 9328 |
} |
| 9329 |
|
| 9330 |
public void insertUpdate(DocumentEvent e) { |
| 9331 |
updateTab(); |
| 9332 |
} |
| 9333 |
|
| 9334 |
public void removeUpdate(DocumentEvent e) { |
| 9335 |
updateTab(); |
| 9336 |
} |
| 9337 |
|
| 9338 |
public void changedUpdate(DocumentEvent e) { |
| 9339 |
updateTab(); |
| 9340 |
} |
| 9341 |
|
| 9342 |
protected void resizeEditor(int tabIndex) { |
| 9343 |
// note - this should use the logic of label paint text so that the text overlays exactly. |
| 9344 |
Rectangle tabsTextBoundsAt = getTabsTextBoundsAt(tabIndex); |
| 9345 |
if (tabsTextBoundsAt.isEmpty()) { |
| 9346 |
tabsTextBoundsAt = new Rectangle(14, 3); // note - 14 should be the font height but... |
| 9347 |
} |
| 9348 |
|
| 9349 |
tabsTextBoundsAt.x = tabsTextBoundsAt.x - _tabEditor.getBorder().getBorderInsets(_tabEditor).left; |
| 9350 |
tabsTextBoundsAt.width = +tabsTextBoundsAt.width + |
| 9351 |
_tabEditor.getBorder().getBorderInsets(_tabEditor).left + |
| 9352 |
_tabEditor.getBorder().getBorderInsets(_tabEditor).right; |
| 9353 |
tabsTextBoundsAt.y = tabsTextBoundsAt.y - _tabEditor.getBorder().getBorderInsets(_tabEditor).top; |
| 9354 |
tabsTextBoundsAt.height = tabsTextBoundsAt.height + |
| 9355 |
_tabEditor.getBorder().getBorderInsets(_tabEditor).top + |
| 9356 |
_tabEditor.getBorder().getBorderInsets(_tabEditor).bottom; |
| 9357 |
_tabEditor.setBounds(SwingUtilities.convertRectangle(_tabPane, tabsTextBoundsAt, getTabPanel())); |
| 9358 |
_tabEditor.invalidate(); |
| 9359 |
_tabEditor.validate(); |
| 9360 |
|
| 9361 |
// getTabPanel().invalidate(); |
| 9362 |
// getTabPanel().validate(); |
| 9363 |
// getTabPanel().repaint(); |
| 9364 |
// getTabPanel().doLayout(); |
| 9365 |
|
| 9366 |
_tabPane.doLayout(); |
| 9367 |
|
| 9368 |
// mtf - note - this is an exteme repaint but we need to paint any content borders |
| 9369 |
getTabPanel().getParent().getParent().repaint(); |
| 9370 |
} |
| 9371 |
|
| 9372 |
protected String getCurrentDisplayTitleAt(JideTabbedPane tp, int index) { |
| 9373 |
String returnTitle = tp.getDisplayTitleAt(index); |
| 9374 |
if ((_isEditing) && (index == _editingTab)) |
| 9375 |
returnTitle = _tabEditor.getText(); |
| 9376 |
|
| 9377 |
return returnTitle; |
| 9378 |
} |
| 9379 |
|
| 9380 |
protected class TabEditor extends JTextField implements UIResource { |
| 9381 |
TabEditor() { |
| 9382 |
setOpaque(false); |
| 9383 |
// setBorder(BorderFactory.createEmptyBorder()); |
| 9384 |
setBorder(BorderFactory |
| 9385 |
.createCompoundBorder(new PartialLineBorder(Color.BLACK, 1, true), |
| 9386 |
BorderFactory.createEmptyBorder(0, 2, 0, 2))); |
| 9387 |
} |
| 9388 |
|
| 9389 |
public boolean stopEditing() { |
| 9390 |
return true; |
| 9391 |
} |
| 9392 |
|
| 9393 |
protected void paintComponent(Graphics g) { |
| 9394 |
Graphics2D g2 = (Graphics2D) g; |
| 9395 |
Composite orgComposite = g2.getComposite(); |
| 9396 |
Color orgColor = g2.getColor(); |
| 9397 |
|
| 9398 |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.70f)); |
| 9399 |
Object o = JideSwingUtilities.setupShapeAntialiasing(g); |
| 9400 |
|
| 9401 |
g2.setColor(getBackground()); |
| 9402 |
g.fillRoundRect(1, 1, getWidth() - 2, getHeight() - 2, 1, 1); |
| 9403 |
|
| 9404 |
JideSwingUtilities.restoreShapeAntialiasing(g, o); |
| 9405 |
g2.setColor(orgColor); |
| 9406 |
g2.setComposite(orgComposite); |
| 9407 |
super.paintComponent(g); |
| 9408 |
} |
| 9409 |
} |
| 9410 |
|
| 9411 |
public void startEditing(MouseEvent e) { |
| 9412 |
int tabIndex = tabForCoordinate(_tabPane, e.getX(), e.getY()); |
| 9413 |
|
| 9414 |
if (!e.isPopupTrigger() && tabIndex >= 0 |
| 9415 |
&& _tabPane.isEnabledAt(tabIndex) |
| 9416 |
&& _tabPane.isTabEditingAllowed() && (e.getClickCount() == 2)) { |
| 9417 |
boolean shouldEdit = true; |
| 9418 |
if (_tabPane.getTabEditingValidator() != null) |
| 9419 |
shouldEdit = _tabPane.getTabEditingValidator().shouldStartEdit(tabIndex, e); |
| 9420 |
|
| 9421 |
if (shouldEdit) { |
| 9422 |
e.consume(); |
| 9423 |
_tabPane.editTabAt(tabIndex); |
| 9424 |
} |
| 9425 |
} |
| 9426 |
if (e.getClickCount() == 1) { |
| 9427 |
if (_tabPane.isTabEditing()) { |
| 9428 |
boolean shouldStopEdit = true; |
| 9429 |
if (_tabPane.getTabEditingValidator() != null) |
| 9430 |
shouldStopEdit = _tabPane.getTabEditingValidator().alertIfInvalid(tabIndex, _oldPrefix + _tabEditor.getText() + _oldPostfix); |
| 9431 |
|
| 9432 |
if (shouldStopEdit) |
| 9433 |
_tabPane.stopTabEditing(); |
| 9434 |
} |
| 9435 |
} |
| 9436 |
} |
| 9437 |
|
| 9438 |
public ThemePainter getPainter() { |
| 9439 |
return _painter; |
| 9440 |
} |
| 9441 |
|
| 9442 |
private class DragOverTimer extends Timer implements ActionListener { |
| 9443 |
private int _index; |
| 9444 |
private static final long serialVersionUID = -2529347876574638854L; |
| 9445 |
|
| 9446 |
public DragOverTimer(int index) { |
| 9447 |
super(500, null); |
| 9448 |
_index = index; |
| 9449 |
addActionListener(this); |
| 9450 |
setRepeats(false); |
| 9451 |
} |
| 9452 |
|
| 9453 |
public void actionPerformed(ActionEvent e) { |
| 9454 |
if (_tabPane.getTabCount() == 0) { |
| 9455 |
return; |
| 9456 |
} |
| 9457 |
if (_index == _tabPane.getSelectedIndex()) { |
| 9458 |
if (_tabPane.isRequestFocusEnabled()) { |
| 9459 |
_tabPane.requestFocusInWindow(); |
| 9460 |
_tabPane.repaint(getTabBounds(_tabPane, _index)); |
| 9461 |
} |
| 9462 |
} |
| 9463 |
else { |
| 9464 |
if (_tabPane.isRequestFocusEnabled()) { |
| 9465 |
_tabPane.requestFocusInWindow(); |
| 9466 |
} |
| 9467 |
_tabPane.setSelectedIndex(_index); |
| 9468 |
} |
| 9469 |
stop(); |
| 9470 |
} |
| 9471 |
} |
| 9472 |
|
| 9473 |
private class DropListener implements DropTargetListener { |
| 9474 |
private DragOverTimer _timer; |
| 9475 |
|
| 9476 |
int _index = -1; |
| 9477 |
|
| 9478 |
public DropListener() { |
| 9479 |
} |
| 9480 |
|
| 9481 |
public void dragEnter(DropTargetDragEvent dtde) { |
| 9482 |
} |
| 9483 |
|
| 9484 |
public void dragOver(DropTargetDragEvent dtde) { |
| 9485 |
if (!_tabPane.isEnabled()) { |
| 9486 |
return; |
| 9487 |
} |
| 9488 |
|
| 9489 |
int tabIndex = getTabAtLocation(dtde.getLocation().x, dtde.getLocation().y); |
| 9490 |
if (tabIndex >= 0 && _tabPane.isEnabledAt(tabIndex)) { |
| 9491 |
if (tabIndex == _tabPane.getSelectedIndex()) { |
| 9492 |
// selected already, do nothing |
| 9493 |
} |
| 9494 |
else if (tabIndex == _index) { |
| 9495 |
// same tab, timer has started |
| 9496 |
} |
| 9497 |
else { |
| 9498 |
stopTimer(); |
| 9499 |
startTimer(tabIndex); |
| 9500 |
_index = tabIndex; // save the index |
| 9501 |
} |
| 9502 |
} |
| 9503 |
else { |
| 9504 |
stopTimer(); |
| 9505 |
} |
| 9506 |
dtde.rejectDrag(); |
| 9507 |
} |
| 9508 |
|
| 9509 |
private void startTimer(int tabIndex) { |
| 9510 |
_timer = new DragOverTimer(tabIndex); |
| 9511 |
_timer.start(); |
| 9512 |
} |
| 9513 |
|
| 9514 |
private void stopTimer() { |
| 9515 |
if (_timer != null) { |
| 9516 |
_timer.stop(); |
| 9517 |
_timer = null; |
| 9518 |
_index = -1; |
| 9519 |
} |
| 9520 |
} |
| 9521 |
|
| 9522 |
public void dropActionChanged(DropTargetDragEvent dtde) { |
| 9523 |
} |
| 9524 |
|
| 9525 |
public void dragExit(DropTargetEvent dte) { |
| 9526 |
stopTimer(); |
| 9527 |
} |
| 9528 |
|
| 9529 |
public void drop(DropTargetDropEvent dtde) { |
| 9530 |
stopTimer(); |
| 9531 |
} |
| 9532 |
} |
| 9533 |
|
| 9534 |
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) { |
| 9535 |
Rectangle tabRect = _rects[tabIndex]; |
| 9536 |
int nudge; |
| 9537 |
switch (tabPlacement) { |
| 9538 |
case LEFT: |
| 9539 |
nudge = isSelected ? -1 : 1; |
| 9540 |
break; |
| 9541 |
case RIGHT: |
| 9542 |
nudge = isSelected ? 1 : -1; |
| 9543 |
break; |
| 9544 |
case BOTTOM: |
| 9545 |
case TOP: |
| 9546 |
default: |
| 9547 |
nudge = tabRect.width % 2; |
| 9548 |
} |
| 9549 |
return nudge; |
| 9550 |
} |
| 9551 |
|
| 9552 |
protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { |
| 9553 |
Rectangle tabRect = _rects[tabIndex]; |
| 9554 |
int nudge; |
| 9555 |
switch (tabPlacement) { |
| 9556 |
case BOTTOM: |
| 9557 |
nudge = isSelected ? 1 : -1; |
| 9558 |
break; |
| 9559 |
case LEFT: |
| 9560 |
case RIGHT: |
| 9561 |
nudge = tabRect.height % 2; |
| 9562 |
break; |
| 9563 |
case TOP: |
| 9564 |
default: |
| 9565 |
nudge = isSelected ? -1 : 1; |
| 9566 |
} |
| 9567 |
return nudge; |
| 9568 |
} |
| 9569 |
|
| 9570 |
protected void paintFocusIndicator(Graphics g, int tabPlacement, |
| 9571 |
Rectangle[] rects, int tabIndex, |
| 9572 |
Rectangle iconRect, Rectangle textRect, |
| 9573 |
boolean isSelected) { |
| 9574 |
Rectangle tabRect = new Rectangle(rects[tabIndex]); |
| 9575 |
if (_tabPane.hasFocus() && isSelected) { |
| 9576 |
int x, y, w, h; |
| 9577 |
g.setColor(_focus); |
| 9578 |
switch (tabPlacement) { |
| 9579 |
case LEFT: |
| 9580 |
x = tabRect.x + 3; |
| 9581 |
y = tabRect.y + 3; |
| 9582 |
w = tabRect.width - 5; |
| 9583 |
h = tabRect.height - 6 - getTabGap(); |
| 9584 |
break; |
| 9585 |
case RIGHT: |
| 9586 |
x = tabRect.x + 2; |
| 9587 |
y = tabRect.y + 3; |
| 9588 |
w = tabRect.width - 5; |
| 9589 |
h = tabRect.height - 6 - getTabGap(); |
| 9590 |
break; |
| 9591 |
case BOTTOM: |
| 9592 |
x = tabRect.x + 3; |
| 9593 |
y = tabRect.y + 2; |
| 9594 |
w = tabRect.width - 6 - getTabGap(); |
| 9595 |
h = tabRect.height - 5; |
| 9596 |
break; |
| 9597 |
case TOP: |
| 9598 |
default: |
| 9599 |
x = tabRect.x + 3; |
| 9600 |
y = tabRect.y + 3; |
| 9601 |
w = tabRect.width - 6 - getTabGap(); |
| 9602 |
h = tabRect.height - 5; |
| 9603 |
} |
| 9604 |
BasicGraphicsUtils.drawDashedRect(g, x, y, w, h); |
| 9605 |
} |
| 9606 |
} |
| 9607 |
|
| 9608 |
protected boolean isRoundedCorner() { |
| 9609 |
return "true".equals(SecurityUtils.getProperty("shadingtheme", "false")); |
| 9610 |
} |
| 9611 |
|
| 9612 |
protected int getTabShape() { |
| 9613 |
return _tabPane.getTabShape(); |
| 9614 |
} |
| 9615 |
|
| 9616 |
protected int getTabResizeMode() { |
| 9617 |
return _tabPane.getTabResizeMode(); |
| 9618 |
} |
| 9619 |
|
| 9620 |
protected int getColorTheme() { |
| 9621 |
return _tabPane.getColorTheme(); |
| 9622 |
} |
| 9623 |
|
| 9624 |
// for debug purpose |
| 9625 |
final protected boolean PAINT_TAB = true; |
| 9626 |
|
| 9627 |
final protected boolean PAINT_TAB_BORDER = true; |
| 9628 |
|
| 9629 |
final protected boolean PAINT_TAB_BACKGROUND = true; |
| 9630 |
|
| 9631 |
final protected boolean PAINT_TABAREA = true; |
| 9632 |
|
| 9633 |
final protected boolean PAINT_CONTENT_BORDER = true; |
| 9634 |
|
| 9635 |
final protected boolean PAINT_CONTENT_BORDER_EDGE = true; |
| 9636 |
|
| 9637 |
protected int getLeftMargin() { |
| 9638 |
if (getTabShape() == JideTabbedPane.SHAPE_OFFICE2003) { |
| 9639 |
return OFFICE2003_LEFT_MARGIN; |
| 9640 |
} |
| 9641 |
else if (getTabShape() == JideTabbedPane.SHAPE_EXCEL) { |
| 9642 |
return EXCEL_LEFT_MARGIN; |
| 9643 |
} |
| 9644 |
else { |
| 9645 |
return DEFAULT_LEFT_MARGIN; |
| 9646 |
} |
| 9647 |
} |
| 9648 |
|
| 9649 |
protected int getTabGap() { |
| 9650 |
if (getTabShape() == JideTabbedPane.SHAPE_OFFICE2003) { |
| 9651 |
return 4; |
| 9652 |
} |
| 9653 |
else { |
| 9654 |
return 0; |
| 9655 |
} |
| 9656 |
} |
| 9657 |
|
| 9658 |
protected int getLayoutSize() { |
| 9659 |
int tabShape = getTabShape(); |
| 9660 |
if (tabShape == JideTabbedPane.SHAPE_EXCEL) { |
| 9661 |
return EXCEL_LEFT_MARGIN; |
| 9662 |
} |
| 9663 |
else if (tabShape == JideTabbedPane.SHAPE_ECLIPSE3X) { |
| 9664 |
return 15; |
| 9665 |
} |
| 9666 |
else if (_tabPane.getTabShape() == JideTabbedPane.SHAPE_FLAT || _tabPane.getTabShape() == JideTabbedPane.SHAPE_ROUNDED_FLAT) { |
| 9667 |
return 2; |
| 9668 |
} |
| 9669 |
else if (tabShape == JideTabbedPane.SHAPE_WINDOWS |
| 9670 |
|| tabShape == JideTabbedPane.SHAPE_WINDOWS_SELECTED) { |
| 9671 |
return 6; |
| 9672 |
} |
| 9673 |
else { |
| 9674 |
return 0; |
| 9675 |
} |
| 9676 |
} |
| 9677 |
|
| 9678 |
protected int getTabRightPadding() { |
| 9679 |
if (getTabShape() == JideTabbedPane.SHAPE_EXCEL) { |
| 9680 |
return 4; |
| 9681 |
} |
| 9682 |
else { |
| 9683 |
return 0; |
| 9684 |
} |
| 9685 |
} |
| 9686 |
|
| 9687 |
protected MouseListener createMouseListener() { |
| 9688 |
if (getTabShape() == JideTabbedPane.SHAPE_WINDOWS || getTabShape() == JideTabbedPane.SHAPE_WINDOWS_SELECTED || _tabPane.isShowCloseButtonOnMouseOver()) { |
| 9689 |
return new RolloverMouseHandler(); |
| 9690 |
} |
| 9691 |
else { |
| 9692 |
return new MouseHandler(); |
| 9693 |
} |
| 9694 |
} |
| 9695 |
|
| 9696 |
protected MouseWheelListener createMouseWheelListener() { |
| 9697 |
return new MouseWheelHandler(); |
| 9698 |
} |
| 9699 |
|
| 9700 |
protected MouseMotionListener createMouseMotionListener() { |
| 9701 |
if (getTabShape() == JideTabbedPane.SHAPE_WINDOWS || getTabShape() == JideTabbedPane.SHAPE_WINDOWS_SELECTED || _tabPane.isShowCloseButtonOnMouseOver()) { |
| 9702 |
return new RolloverMouseMotionHandler(); |
| 9703 |
} |
| 9704 |
else { |
| 9705 |
return new MouseMotionHandler(); |
| 9706 |
} |
| 9707 |
} |
| 9708 |
|
| 9709 |
public class DefaultMouseMotionHandler extends MouseMotionAdapter { |
| 9710 |
@Override |
| 9711 |
public void mouseMoved(MouseEvent e) { |
| 9712 |
super.mouseMoved(e); |
| 9713 |
int tabIndex = getTabAtLocation(e.getX(), e.getY()); |
| 9714 |
if (tabIndex != _indexMouseOver) { |
| 9715 |
setMouseOverTabIndex(tabIndex); |
| 9716 |
_tabPane.repaint(); |
| 9717 |
} |
| 9718 |
|
| 9719 |
} |
| 9720 |
|
| 9721 |
} |
| 9722 |
|
| 9723 |
public class DefaultMouseHandler extends BasicJideTabbedPaneUI.MouseHandler { |
| 9724 |
@Override |
| 9725 |
public void mousePressed(MouseEvent e) { |
| 9726 |
super.mousePressed(e); |
| 9727 |
} |
| 9728 |
|
| 9729 |
@Override |
| 9730 |
public void mouseEntered(MouseEvent e) { |
| 9731 |
super.mouseEntered(e); |
| 9732 |
int tabIndex = getTabAtLocation(e.getX(), e.getY()); |
| 9733 |
_mouseEnter = true; |
| 9734 |
setMouseOverTabIndex(tabIndex); |
| 9735 |
_tabPane.repaint(); |
| 9736 |
} |
| 9737 |
|
| 9738 |
@Override |
| 9739 |
public void mouseExited(MouseEvent e) { |
| 9740 |
super.mouseExited(e); |
| 9741 |
setMouseOverTabIndex(-1); |
| 9742 |
_mouseEnter = false; |
| 9743 |
_tabPane.repaint(); |
| 9744 |
} |
| 9745 |
} |
| 9746 |
|
| 9747 |
public class RolloverMouseMotionHandler extends MouseMotionAdapter { |
| 9748 |
@Override |
| 9749 |
public void mouseMoved(MouseEvent e) { |
| 9750 |
super.mouseMoved(e); |
| 9751 |
int tabIndex = tabForCoordinate(_tabPane, e.getX(), e.getY()); |
| 9752 |
if (tabIndex != _indexMouseOver) { |
| 9753 |
setMouseOverTabIndex(tabIndex); |
| 9754 |
_tabPane.repaint(); |
| 9755 |
} |
| 9756 |
|
| 9757 |
} |
| 9758 |
|
| 9759 |
} |
| 9760 |
|
| 9761 |
public class RolloverMouseHandler extends BasicJideTabbedPaneUI.MouseHandler { |
| 9762 |
@Override |
| 9763 |
public void mouseEntered(MouseEvent e) { |
| 9764 |
super.mouseEntered(e); |
| 9765 |
int tabIndex = tabForCoordinate(_tabPane, e.getX(), e.getY()); |
| 9766 |
_mouseEnter = true; |
| 9767 |
setMouseOverTabIndex(tabIndex); |
| 9768 |
_tabPane.repaint(); |
| 9769 |
} |
| 9770 |
|
| 9771 |
@Override |
| 9772 |
public void mouseExited(MouseEvent e) { |
| 9773 |
super.mouseExited(e); |
| 9774 |
setMouseOverTabIndex(-1); |
| 9775 |
_mouseEnter = false; |
| 9776 |
_tabPane.repaint(); |
| 9777 |
} |
| 9778 |
} |
| 9779 |
|
| 9780 |
protected boolean isTabLeadingComponentVisible() { |
| 9781 |
return _tabPane.isTabShown() && _tabLeadingComponent != null && _tabLeadingComponent.isVisible(); |
| 9782 |
} |
| 9783 |
|
| 9784 |
protected boolean isTabTrailingComponentVisible() { |
| 9785 |
return _tabPane.isTabShown() && _tabTrailingComponent != null && _tabTrailingComponent.isVisible(); |
| 9786 |
} |
| 9787 |
|
| 9788 |
protected boolean isTabTopVisible(int tabPlacement) { |
| 9789 |
switch (tabPlacement) { |
| 9790 |
case LEFT: |
| 9791 |
case RIGHT: |
| 9792 |
return (isTabLeadingComponentVisible() && _tabLeadingComponent.getPreferredSize().width > calculateMaxTabWidth(tabPlacement)) || |
| 9793 |
(isTabTrailingComponentVisible() && _tabTrailingComponent.getPreferredSize().width > calculateMaxTabWidth(tabPlacement)); |
| 9794 |
case TOP: |
| 9795 |
case BOTTOM: |
| 9796 |
default: |
| 9797 |
return (isTabLeadingComponentVisible() && _tabLeadingComponent.getPreferredSize().height > calculateMaxTabHeight(tabPlacement)) || |
| 9798 |
(isTabTrailingComponentVisible() && _tabTrailingComponent.getPreferredSize().height > calculateMaxTabHeight(tabPlacement)); |
| 9799 |
} |
| 9800 |
} |
| 9801 |
|
| 9802 |
protected boolean showFocusIndicator() { |
| 9803 |
return _tabPane.hasFocusComponent() && _showFocusIndicator; |
| 9804 |
} |
| 9805 |
|
| 9806 |
private int getNumberOfTabButtons() { |
| 9807 |
int numberOfButtons = (!isShowTabButtons() || isShrinkTabs()) ? 1 : 4; |
| 9808 |
if (!isShowCloseButton() || isShowCloseButtonOnTab()) { |
| 9809 |
numberOfButtons--; |
| 9810 |
} |
| 9811 |
return numberOfButtons; |
| 9812 |
} |
| 9813 |
|
| 9814 |
/** |
| 9815 |
* Gets the resource string used in JideTabbedPane. Subclass can override it to provide their own strings. |
| 9816 |
* |
| 9817 |
* @param key the resource key |
| 9818 |
* @return the localized string. |
| 9819 |
*/ |
| 9820 |
protected String getResourceString(String key) { |
| 9821 |
if (_tabPane != null) { |
| 9822 |
return _tabPane.getResourceString(key); |
| 9823 |
} |
| 9824 |
return Resource.getResourceBundle(Locale.getDefault()).getString(key); |
| 9825 |
} |
| 9826 |
|
| 9827 |
private void setMouseOverTabIndex(int index) { |
| 9828 |
if (_indexMouseOver != index) { |
| 9829 |
_indexMouseOver = index; |
| 9830 |
_tabPane.putClientProperty("JideTabbedPane.mouseOverTabIndex", _indexMouseOver); |
| 9831 |
/* |
| 9832 |
if (_tabPane.isShowCloseButtonOnMouseOver()) { |
| 9833 |
_tabPane.invalidate(); |
| 9834 |
_tabPane.repaint(); |
| 9835 |
} |
| 9836 |
*/ |
| 9837 |
} |
| 9838 |
} |
| 9839 |
} |