| 1 |
/* |
| 2 |
* @(#)VsnetMenuItemUI.java |
| 3 |
* |
| 4 |
* Copyright 2002 JIDE Software Inc. All rights reserved. |
| 5 |
*/ |
| 6 |
|
| 7 |
package com.jidesoft.plaf.vsnet; |
| 8 |
|
| 9 |
import com.jidesoft.icons.IconsFactory; |
| 10 |
import com.jidesoft.plaf.UIDefaultsLookup; |
| 11 |
import com.jidesoft.plaf.basic.ThemePainter; |
| 12 |
import com.jidesoft.plaf.windows.WindowsGraphicsUtilsPort; |
| 13 |
import com.jidesoft.swing.ButtonStyle; |
| 14 |
import com.jidesoft.swing.JideSplitButton; |
| 15 |
import com.jidesoft.swing.JideSwingUtilities; |
| 16 |
import com.jidesoft.swing.TopLevelMenuContainer; |
| 17 |
import com.jidesoft.utils.SecurityUtils; |
| 18 |
import com.jidesoft.utils.SystemInfo; |
| 19 |
|
| 20 |
import javax.swing.*; |
| 21 |
import javax.swing.event.*; |
| 22 |
import javax.swing.plaf.*; |
| 23 |
import javax.swing.plaf.basic.BasicHTML; |
| 24 |
import javax.swing.text.View; |
| 25 |
import java.awt.*; |
| 26 |
import java.awt.event.ActionEvent; |
| 27 |
import java.awt.event.InputEvent; |
| 28 |
import java.awt.event.KeyEvent; |
| 29 |
import java.awt.event.MouseEvent; |
| 30 |
import java.beans.PropertyChangeEvent; |
| 31 |
import java.beans.PropertyChangeListener; |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* MenuItem UI implementation |
| 36 |
*/ |
| 37 |
public class VsnetMenuItemUI extends MenuItemUI { |
| 38 |
protected JMenuItem menuItem = null; |
| 39 |
protected Color selectionBackground; |
| 40 |
protected Color selectionForeground; |
| 41 |
protected Color disabledForeground; |
| 42 |
protected Color acceleratorForeground; |
| 43 |
protected Color acceleratorSelectionForeground; |
| 44 |
private String acceleratorDelimiter; |
| 45 |
|
| 46 |
protected int defaultTextIconGap; |
| 47 |
protected Font acceleratorFont; |
| 48 |
|
| 49 |
protected MouseInputListener mouseInputListener; |
| 50 |
protected MenuDragMouseListener menuDragMouseListener; |
| 51 |
protected MenuKeyListener menuKeyListener; |
| 52 |
private PropertyChangeListener propertyChangeListener; |
| 53 |
|
| 54 |
protected Icon arrowIcon = null; |
| 55 |
protected Icon checkIcon = null; |
| 56 |
|
| 57 |
protected boolean oldBorderPainted; |
| 58 |
|
| 59 |
/** |
| 60 |
* Used for accelerator binding, lazily created. |
| 61 |
*/ |
| 62 |
protected InputMap windowInputMap; |
| 63 |
|
| 64 |
/* diagnostic aids -- should be false for production builds. */ |
| 65 |
private static final boolean DEBUG = false; // show bad params, misc. |
| 66 |
|
| 67 |
// added for VsnetMenuItemUI |
| 68 |
protected Color shadowColor; |
| 69 |
protected int defaultAccelEndGap; |
| 70 |
protected int defaultShadowWidth; |
| 71 |
protected Color borderColor; |
| 72 |
protected Color backgroundColor; |
| 73 |
// end added for VsnetMenuItemUI |
| 74 |
|
| 75 |
/* Client Property keys for text and accelerator text widths */ |
| 76 |
static final String MAX_TEXT_WIDTH = "maxTextWidth"; |
| 77 |
static final String MAX_ACC_WIDTH = "maxAccWidth"; |
| 78 |
|
| 79 |
protected boolean _isFloatingIcon = false; |
| 80 |
|
| 81 |
private ThemePainter _painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter"); |
| 82 |
|
| 83 |
public static ComponentUI createUI(JComponent c) { |
| 84 |
return new VsnetMenuItemUI(); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public void installUI(JComponent c) { |
| 89 |
menuItem = (JMenuItem) c; |
| 90 |
|
| 91 |
installDefaults(); |
| 92 |
installComponents(menuItem); |
| 93 |
installListeners(); |
| 94 |
installKeyboardActions(); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
protected void installDefaults() { |
| 99 |
String prefix = getPropertyPrefix(); |
| 100 |
|
| 101 |
acceleratorFont = UIDefaultsLookup.getFont("MenuItem.acceleratorFont"); |
| 102 |
if (acceleratorFont == null) { |
| 103 |
acceleratorFont = UIManager.getFont("MenuItem.font"); |
| 104 |
} |
| 105 |
|
| 106 |
menuItem.setOpaque(true); |
| 107 |
if (menuItem.getMargin() == null || |
| 108 |
(menuItem.getMargin() instanceof UIResource)) { |
| 109 |
menuItem.setMargin(UIDefaultsLookup.getInsets(prefix + ".margin")); |
| 110 |
} |
| 111 |
|
| 112 |
// added for VsnetMenuItemUI |
| 113 |
defaultTextIconGap = UIDefaultsLookup.getInt(prefix + ".textIconGap"); |
| 114 |
defaultAccelEndGap = UIDefaultsLookup.getInt("MenuItem.accelEndGap"); |
| 115 |
defaultShadowWidth = UIDefaultsLookup.getInt("MenuItem.shadowWidth"); |
| 116 |
// end add |
| 117 |
|
| 118 |
borderColor = UIDefaultsLookup.getColor("MenuItem.selectionBorderColor"); |
| 119 |
backgroundColor = UIDefaultsLookup.getColor("MenuItem.background"); |
| 120 |
shadowColor = UIDefaultsLookup.getColor("MenuItem.shadowColor"); |
| 121 |
|
| 122 |
LookAndFeel.installBorder(menuItem, prefix + ".border"); |
| 123 |
oldBorderPainted = menuItem.isBorderPainted(); |
| 124 |
Object borderPainted = UIDefaultsLookup.get(prefix + ".borderPainted"); |
| 125 |
if (borderPainted instanceof Boolean) { |
| 126 |
menuItem.setBorderPainted((Boolean) borderPainted); |
| 127 |
} |
| 128 |
LookAndFeel.installColorsAndFont(menuItem, |
| 129 |
prefix + ".background", |
| 130 |
prefix + ".foreground", |
| 131 |
prefix + ".font"); |
| 132 |
|
| 133 |
// MenuItem specific defaults |
| 134 |
if (selectionBackground == null || |
| 135 |
selectionBackground instanceof UIResource) { |
| 136 |
selectionBackground = |
| 137 |
UIDefaultsLookup.getColor(prefix + ".selectionBackground"); |
| 138 |
} |
| 139 |
if (selectionForeground == null || |
| 140 |
selectionForeground instanceof UIResource) { |
| 141 |
selectionForeground = |
| 142 |
UIDefaultsLookup.getColor(prefix + ".selectionForeground"); |
| 143 |
} |
| 144 |
if (disabledForeground == null || |
| 145 |
disabledForeground instanceof UIResource) { |
| 146 |
disabledForeground = |
| 147 |
UIDefaultsLookup.getColor(prefix + ".disabledForeground"); |
| 148 |
} |
| 149 |
if (acceleratorForeground == null || |
| 150 |
acceleratorForeground instanceof UIResource) { |
| 151 |
acceleratorForeground = |
| 152 |
UIDefaultsLookup.getColor(prefix + ".acceleratorForeground"); |
| 153 |
} |
| 154 |
if (acceleratorSelectionForeground == null || |
| 155 |
acceleratorSelectionForeground instanceof UIResource) { |
| 156 |
acceleratorSelectionForeground = |
| 157 |
UIDefaultsLookup.getColor(prefix + ".acceleratorSelectionForeground"); |
| 158 |
} |
| 159 |
// Get accelerator delimiter |
| 160 |
acceleratorDelimiter = |
| 161 |
UIDefaultsLookup.getString("MenuItem.acceleratorDelimiter"); |
| 162 |
if (acceleratorDelimiter == null) { |
| 163 |
acceleratorDelimiter = "+"; |
| 164 |
} |
| 165 |
// Icons |
| 166 |
if (arrowIcon == null || |
| 167 |
arrowIcon instanceof UIResource) { |
| 168 |
arrowIcon = UIDefaultsLookup.getIcon(prefix + ".arrowIcon"); |
| 169 |
} |
| 170 |
if (checkIcon == null || |
| 171 |
checkIcon instanceof UIResource) { |
| 172 |
checkIcon = UIDefaultsLookup.getIcon(prefix + ".checkIcon"); |
| 173 |
} |
| 174 |
|
| 175 |
_isFloatingIcon = UIDefaultsLookup.getBoolean("Icon.floating"); |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* @param menuItem the menu item |
| 180 |
* @since 1.3 |
| 181 |
*/ |
| 182 |
protected void installComponents(JMenuItem menuItem) { |
| 183 |
BasicHTML.updateRenderer(menuItem, menuItem.getText()); |
| 184 |
} |
| 185 |
|
| 186 |
protected String getPropertyPrefix() { |
| 187 |
return "MenuItem"; |
| 188 |
} |
| 189 |
|
| 190 |
protected void installListeners() { |
| 191 |
if ((mouseInputListener = createMouseInputListener(menuItem)) != null) { |
| 192 |
menuItem.addMouseListener(mouseInputListener); |
| 193 |
menuItem.addMouseMotionListener(mouseInputListener); |
| 194 |
} |
| 195 |
if ((menuDragMouseListener = createMenuDragMouseListener(menuItem)) != null) { |
| 196 |
menuItem.addMenuDragMouseListener(menuDragMouseListener); |
| 197 |
} |
| 198 |
if ((menuKeyListener = createMenuKeyListener(menuItem)) != null) { |
| 199 |
menuItem.addMenuKeyListener(menuKeyListener); |
| 200 |
} |
| 201 |
if ((propertyChangeListener = createPropertyChangeListener(menuItem)) != null) { |
| 202 |
menuItem.addPropertyChangeListener(propertyChangeListener); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
protected void installKeyboardActions() { |
| 207 |
ActionMap actionMap = getActionMap(); |
| 208 |
|
| 209 |
SwingUtilities.replaceUIActionMap(menuItem, actionMap); |
| 210 |
updateAcceleratorBinding(); |
| 211 |
} |
| 212 |
|
| 213 |
@Override |
| 214 |
public void uninstallUI(JComponent c) { |
| 215 |
menuItem = (JMenuItem) c; |
| 216 |
uninstallDefaults(); |
| 217 |
uninstallComponents(menuItem); |
| 218 |
uninstallListeners(); |
| 219 |
uninstallKeyboardActions(); |
| 220 |
|
| 221 |
//Remove the textWidth and accWidth values from the parent's Client Properties. |
| 222 |
Container parent = menuItem.getParent(); |
| 223 |
if ((parent != null && parent instanceof JComponent) && |
| 224 |
!(menuItem instanceof JMenu && ((JMenu) menuItem).isTopLevelMenu())) { |
| 225 |
JComponent p = (JComponent) parent; |
| 226 |
p.putClientProperty(VsnetMenuItemUI.MAX_ACC_WIDTH, null); |
| 227 |
p.putClientProperty(VsnetMenuItemUI.MAX_TEXT_WIDTH, null); |
| 228 |
} |
| 229 |
|
| 230 |
menuItem = null; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
protected void uninstallDefaults() { |
| 235 |
LookAndFeel.uninstallBorder(menuItem); |
| 236 |
menuItem.setBorderPainted(oldBorderPainted); |
| 237 |
if (menuItem.getMargin() instanceof UIResource) |
| 238 |
menuItem.setMargin(null); |
| 239 |
if (arrowIcon instanceof UIResource) |
| 240 |
arrowIcon = null; |
| 241 |
if (checkIcon instanceof UIResource) |
| 242 |
checkIcon = null; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* @param menuItem the menu item |
| 247 |
* @since 1.3 |
| 248 |
*/ |
| 249 |
protected void uninstallComponents(JMenuItem menuItem) { |
| 250 |
BasicHTML.updateRenderer(menuItem, ""); |
| 251 |
} |
| 252 |
|
| 253 |
protected void uninstallListeners() { |
| 254 |
if (mouseInputListener != null) { |
| 255 |
menuItem.removeMouseListener(mouseInputListener); |
| 256 |
menuItem.removeMouseMotionListener(mouseInputListener); |
| 257 |
} |
| 258 |
if (menuDragMouseListener != null) { |
| 259 |
menuItem.removeMenuDragMouseListener(menuDragMouseListener); |
| 260 |
} |
| 261 |
if (menuKeyListener != null) { |
| 262 |
menuItem.removeMenuKeyListener(menuKeyListener); |
| 263 |
} |
| 264 |
if (propertyChangeListener != null) { |
| 265 |
menuItem.removePropertyChangeListener(propertyChangeListener); |
| 266 |
} |
| 267 |
|
| 268 |
mouseInputListener = null; |
| 269 |
menuDragMouseListener = null; |
| 270 |
menuKeyListener = null; |
| 271 |
propertyChangeListener = null; |
| 272 |
} |
| 273 |
|
| 274 |
protected void uninstallKeyboardActions() { |
| 275 |
SwingUtilities.replaceUIActionMap(menuItem, null); |
| 276 |
if (windowInputMap != null) { |
| 277 |
SwingUtilities.replaceUIInputMap(menuItem, JComponent. |
| 278 |
WHEN_IN_FOCUSED_WINDOW, null); |
| 279 |
windowInputMap = null; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
protected MouseInputListener createMouseInputListener(JComponent c) { |
| 284 |
return new MouseInputHandler(); |
| 285 |
} |
| 286 |
|
| 287 |
protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) { |
| 288 |
return new MenuDragMouseHandler(); |
| 289 |
} |
| 290 |
|
| 291 |
protected MenuKeyListener createMenuKeyListener(JComponent c) { |
| 292 |
return new MenuKeyHandler(); |
| 293 |
} |
| 294 |
|
| 295 |
private PropertyChangeListener createPropertyChangeListener(JComponent c) { |
| 296 |
return new PropertyChangeHandler(); |
| 297 |
} |
| 298 |
|
| 299 |
protected ActionMap getActionMap() { |
| 300 |
String propertyPrefix = getPropertyPrefix(); |
| 301 |
String uiKey = propertyPrefix + ".actionMap"; |
| 302 |
ActionMap am = (ActionMap) UIDefaultsLookup.get(uiKey); |
| 303 |
if (am == null) { |
| 304 |
am = createActionMap(); |
| 305 |
UIManager.getLookAndFeelDefaults().put(uiKey, am); |
| 306 |
} |
| 307 |
return am; |
| 308 |
} |
| 309 |
|
| 310 |
protected ActionMap createActionMap() { |
| 311 |
ActionMap map = new ActionMapUIResource(); |
| 312 |
map.put("doClick", new ClickAction()); |
| 313 |
|
| 314 |
// removed for VsnetMenuItem. it's protected method |
| 315 |
// Set the ActionMap's parent to the Auditory Feedback Action Map |
| 316 |
// BasicLookAndFeel lf = (BasicLookAndFeel) UIManager.getLookAndFeel(); |
| 317 |
// ActionMap audioMap = lf.getAudioActionMap(); |
| 318 |
// map.setParent(audioMap); |
| 319 |
|
| 320 |
return map; |
| 321 |
} |
| 322 |
|
| 323 |
protected InputMap createInputMap(int condition) { |
| 324 |
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { |
| 325 |
return new ComponentInputMapUIResource(menuItem); |
| 326 |
} |
| 327 |
return null; |
| 328 |
} |
| 329 |
|
| 330 |
void updateAcceleratorBinding() { |
| 331 |
KeyStroke accelerator = menuItem.getAccelerator(); |
| 332 |
|
| 333 |
if (windowInputMap != null) { |
| 334 |
windowInputMap.clear(); |
| 335 |
} |
| 336 |
if (accelerator != null) { |
| 337 |
if (windowInputMap == null) { |
| 338 |
windowInputMap = createInputMap(JComponent. |
| 339 |
WHEN_IN_FOCUSED_WINDOW); |
| 340 |
SwingUtilities.replaceUIInputMap(menuItem, |
| 341 |
JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap); |
| 342 |
} |
| 343 |
windowInputMap.put(accelerator, "doClick"); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
@Override |
| 348 |
public Dimension getMinimumSize(JComponent c) { |
| 349 |
Dimension d = null; |
| 350 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
| 351 |
if (v != null) { |
| 352 |
d = getPreferredSize(c); |
| 353 |
d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS); |
| 354 |
} |
| 355 |
return d; |
| 356 |
} |
| 357 |
|
| 358 |
@Override |
| 359 |
public Dimension getPreferredSize(JComponent c) { |
| 360 |
return getPreferredMenuItemSize(c, |
| 361 |
checkIcon, |
| 362 |
arrowIcon, |
| 363 |
defaultTextIconGap); |
| 364 |
} |
| 365 |
|
| 366 |
@Override |
| 367 |
public Dimension getMaximumSize(JComponent c) { |
| 368 |
Dimension d = null; |
| 369 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
| 370 |
if (v != null) { |
| 371 |
d = getPreferredSize(c); |
| 372 |
d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS); |
| 373 |
} |
| 374 |
return d; |
| 375 |
} |
| 376 |
|
| 377 |
// these rects are used for painting and preferredsize calculations. |
| 378 |
// they used to be regenerated constantly. Now they are reused. |
| 379 |
protected static Rectangle zeroRect = new Rectangle(0, 0, 0, 0); |
| 380 |
protected static Rectangle iconRect = new Rectangle(); |
| 381 |
protected static Rectangle textRect = new Rectangle(); |
| 382 |
protected static Rectangle acceleratorRect = new Rectangle(); |
| 383 |
protected static Rectangle checkIconRect = new Rectangle(); |
| 384 |
protected static Rectangle arrowIconRect = new Rectangle(); |
| 385 |
protected static Rectangle viewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE); |
| 386 |
static Rectangle r = new Rectangle(); |
| 387 |
|
| 388 |
private void resetRects() { |
| 389 |
iconRect.setBounds(zeroRect); |
| 390 |
textRect.setBounds(zeroRect); |
| 391 |
acceleratorRect.setBounds(zeroRect); |
| 392 |
checkIconRect.setBounds(zeroRect); |
| 393 |
arrowIconRect.setBounds(zeroRect); |
| 394 |
viewRect.setBounds(0, 0, Short.MAX_VALUE, Short.MAX_VALUE); |
| 395 |
r.setBounds(zeroRect); |
| 396 |
} |
| 397 |
|
| 398 |
protected Dimension getPreferredMenuItemSize(JComponent c, |
| 399 |
Icon checkIcon, |
| 400 |
Icon arrowIcon, |
| 401 |
int textIconGap) { |
| 402 |
JMenuItem b = (JMenuItem) c; |
| 403 |
Icon icon = b.getIcon(); |
| 404 |
String text = b.getText(); |
| 405 |
KeyStroke accelerator = b.getAccelerator(); |
| 406 |
String acceleratorText = ""; |
| 407 |
|
| 408 |
if (accelerator != null) { |
| 409 |
int modifiers = accelerator.getModifiers(); |
| 410 |
if (modifiers > 0) { |
| 411 |
acceleratorText = KeyEvent.getKeyModifiersText(modifiers); |
| 412 |
//acceleratorText += "-"; |
| 413 |
acceleratorText += acceleratorDelimiter; |
| 414 |
} |
| 415 |
int keyCode = accelerator.getKeyCode(); |
| 416 |
if (keyCode != 0) { |
| 417 |
acceleratorText += KeyEvent.getKeyText(keyCode); |
| 418 |
} |
| 419 |
else { |
| 420 |
acceleratorText += accelerator.getKeyChar(); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
Font font = b.getFont(); |
| 425 |
FontMetrics fm = b.getFontMetrics(font); |
| 426 |
FontMetrics fmAccel = b.getFontMetrics(acceleratorFont); |
| 427 |
|
| 428 |
resetRects(); |
| 429 |
|
| 430 |
layoutMenuItem(fm, text, fmAccel, acceleratorText, icon, checkIcon, arrowIcon, |
| 431 |
b.getVerticalAlignment(), b.getHorizontalAlignment(), |
| 432 |
b.getVerticalTextPosition(), b.getHorizontalTextPosition(), |
| 433 |
viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, |
| 434 |
text == null ? 0 : textIconGap, |
| 435 |
defaultTextIconGap); |
| 436 |
|
| 437 |
// find the union of the icon and text rects |
| 438 |
if (text != null && text.trim().length() != 0) { |
| 439 |
r.setBounds(textRect); |
| 440 |
} |
| 441 |
if (!iconRect.isEmpty()) { |
| 442 |
r = SwingUtilities.computeUnion(iconRect.x, |
| 443 |
iconRect.y, |
| 444 |
iconRect.width, |
| 445 |
iconRect.height, |
| 446 |
r); |
| 447 |
} |
| 448 |
|
| 449 |
// To make the accelerator texts appear in a column, find the widest MenuItem text |
| 450 |
// and the widest accelerator text. |
| 451 |
|
| 452 |
//Get the parent, which stores the information. |
| 453 |
Container parent = menuItem.getParent(); |
| 454 |
|
| 455 |
//Check the parent, and see that it is not a top-level menu. |
| 456 |
if (parent != null && parent instanceof JComponent && |
| 457 |
!(menuItem instanceof JMenu && ((JMenu) menuItem).isTopLevelMenu())) { |
| 458 |
JComponent p = (JComponent) parent; |
| 459 |
|
| 460 |
//Get widest text so far from parent, if no one exists null is returned. |
| 461 |
Integer maxTextWidth = (Integer) p.getClientProperty(VsnetMenuItemUI.MAX_TEXT_WIDTH); |
| 462 |
Integer maxAccWidth = (Integer) p.getClientProperty(VsnetMenuItemUI.MAX_ACC_WIDTH); |
| 463 |
|
| 464 |
int maxTextValue = maxTextWidth != null ? maxTextWidth : 0; |
| 465 |
int maxAccValue = maxAccWidth != null ? maxAccWidth : 0; |
| 466 |
|
| 467 |
//Compare the text widths, and adjust the r.width to the widest. |
| 468 |
if (r.width < maxTextValue) { |
| 469 |
r.width = maxTextValue; |
| 470 |
} |
| 471 |
else { |
| 472 |
p.putClientProperty(VsnetMenuItemUI.MAX_TEXT_WIDTH, r.width); |
| 473 |
} |
| 474 |
|
| 475 |
//Compare the accelerator widths. |
| 476 |
if (acceleratorRect.width > maxAccValue) { |
| 477 |
maxAccValue = acceleratorRect.width; |
| 478 |
p.putClientProperty(VsnetMenuItemUI.MAX_ACC_WIDTH, acceleratorRect.width); |
| 479 |
} |
| 480 |
|
| 481 |
r.width += maxAccValue; |
| 482 |
r.width += textIconGap; |
| 483 |
r.width += defaultAccelEndGap; |
| 484 |
} |
| 485 |
|
| 486 |
if (text != null && text.trim().length() != 0) { |
| 487 |
if (icon != null) { |
| 488 |
r.width += textIconGap; |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
Insets insets = b.getInsets(); |
| 493 |
|
| 494 |
if (useCheckAndArrow()) { |
| 495 |
insets.left = 0; |
| 496 |
insets.right = 0; |
| 497 |
r.width += 5; |
| 498 |
} |
| 499 |
|
| 500 |
if (isDownArrowVisible(parent)) { |
| 501 |
insets.left = 0; |
| 502 |
insets.right = 0; |
| 503 |
r.width += 7; |
| 504 |
} |
| 505 |
|
| 506 |
if (insets != null) { |
| 507 |
r.width += insets.left + insets.right; |
| 508 |
r.height += insets.top + insets.bottom; |
| 509 |
} |
| 510 |
|
| 511 |
// if the width is even, bump it up one. This is critical |
| 512 |
// for the focus dash line to draw properly |
| 513 |
if (r.width % 2 == 0) { |
| 514 |
r.width++; |
| 515 |
} |
| 516 |
|
| 517 |
// if the height is even, bump it up one. This is critical |
| 518 |
// for the text to center properly |
| 519 |
// if (r.height % 2 == 0) { |
| 520 |
// r.height++; |
| 521 |
// } |
| 522 |
|
| 523 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) { |
| 524 |
return r.getSize(); |
| 525 |
} |
| 526 |
else { |
| 527 |
//noinspection SuspiciousNameCombination |
| 528 |
return new Dimension(r.height, r.width); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* We draw the background in paintMenuItem() so override update (which fills the background of opaque components by |
| 534 |
* default) to just call paint(). |
| 535 |
*/ |
| 536 |
@Override |
| 537 |
public void update(Graphics g, JComponent c) { |
| 538 |
paint(g, c); |
| 539 |
} |
| 540 |
|
| 541 |
@Override |
| 542 |
public void paint(Graphics g, JComponent c) { |
| 543 |
paintMenuItem(g, c, checkIcon, arrowIcon, |
| 544 |
selectionBackground, selectionForeground, |
| 545 |
defaultTextIconGap); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
protected void paintMenuItem(Graphics g, JComponent c, |
| 550 |
Icon checkIcon, Icon arrowIcon, |
| 551 |
Color background, Color foreground, |
| 552 |
int defaultTextIconGap) { |
| 553 |
JMenuItem b = (JMenuItem) c; |
| 554 |
ButtonModel model = b.getModel(); |
| 555 |
Object property = b.getClientProperty("MenuItem.shadowWidth"); |
| 556 |
if (property instanceof Number) { |
| 557 |
defaultShadowWidth = ((Number) property).intValue(); |
| 558 |
if (b instanceof JMenu) { |
| 559 |
for (Component comp : ((JMenu) b).getMenuComponents()) { |
| 560 |
if (comp instanceof JMenuItem && ((JMenuItem) comp).getClientProperty("MenuItem.shadowWidth") == null) { |
| 561 |
((JMenuItem) comp).putClientProperty("MenuItem.shadowWidth", defaultShadowWidth); |
| 562 |
} |
| 563 |
} |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
int menuWidth; |
| 568 |
int menuHeight; |
| 569 |
|
| 570 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) { |
| 571 |
menuWidth = b.getWidth(); |
| 572 |
menuHeight = b.getHeight(); |
| 573 |
} |
| 574 |
else { |
| 575 |
// Dimension size = b.getSize(); |
| 576 |
menuWidth = b.getHeight(); |
| 577 |
menuHeight = b.getWidth(); |
| 578 |
Graphics2D g2d = (Graphics2D) g; |
| 579 |
g2d.rotate(Math.PI / 2); |
| 580 |
g2d.translate(0, -menuHeight + 1); |
| 581 |
} |
| 582 |
|
| 583 |
Insets i = c.getInsets(); |
| 584 |
|
| 585 |
resetRects(); |
| 586 |
|
| 587 |
viewRect.setBounds(0, 0, menuWidth, menuHeight); |
| 588 |
|
| 589 |
if (isDownArrowVisible(b.getParent())) { |
| 590 |
viewRect.x += 3; |
| 591 |
viewRect.width -= 7; |
| 592 |
} |
| 593 |
else { |
| 594 |
viewRect.x += i.left; |
| 595 |
viewRect.width -= (i.right + viewRect.x); |
| 596 |
} |
| 597 |
viewRect.y += i.top; |
| 598 |
viewRect.height -= (i.bottom + viewRect.y); |
| 599 |
|
| 600 |
|
| 601 |
Font holdf = g.getFont(); |
| 602 |
Font f = c.getFont(); |
| 603 |
g.setFont(f); |
| 604 |
FontMetrics fm = g.getFontMetrics(f); |
| 605 |
FontMetrics fmAccel = g.getFontMetrics(acceleratorFont); |
| 606 |
|
| 607 |
// get Accelerator text |
| 608 |
KeyStroke accelerator = b.getAccelerator(); |
| 609 |
String acceleratorText = ""; |
| 610 |
if (accelerator != null) { |
| 611 |
int modifiers = accelerator.getModifiers(); |
| 612 |
if (modifiers > 0) { |
| 613 |
acceleratorText = KeyEvent.getKeyModifiersText(modifiers); |
| 614 |
//acceleratorText += "-"; |
| 615 |
acceleratorText += acceleratorDelimiter; |
| 616 |
} |
| 617 |
|
| 618 |
int keyCode = accelerator.getKeyCode(); |
| 619 |
if (keyCode != 0) { |
| 620 |
acceleratorText += KeyEvent.getKeyText(keyCode); |
| 621 |
} |
| 622 |
else { |
| 623 |
acceleratorText += accelerator.getKeyChar(); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
// layout the text and icon |
| 628 |
String text = layoutMenuItem(fm, b.getText(), fmAccel, acceleratorText, b.getIcon(), |
| 629 |
checkIcon, arrowIcon, |
| 630 |
b.getVerticalAlignment(), b.getHorizontalAlignment(), |
| 631 |
b.getVerticalTextPosition(), b.getHorizontalTextPosition(), |
| 632 |
viewRect, iconRect, textRect, acceleratorRect, |
| 633 |
checkIconRect, arrowIconRect, |
| 634 |
b.getText() == null ? 0 : defaultTextIconGap, |
| 635 |
defaultTextIconGap); |
| 636 |
|
| 637 |
// Paint background |
| 638 |
paintBackground(g, b, background); |
| 639 |
|
| 640 |
Color holdc = g.getColor(); |
| 641 |
|
| 642 |
// Paint the Check |
| 643 |
if ((c.getUIClassID().indexOf("CheckBoxMenu") >= 0 || c.getUIClassID().indexOf("RadioButtonMenu") >= 0) && checkIcon != null) { |
| 644 |
paintCheckBox(b, g, checkIcon); |
| 645 |
g.setColor(holdc); |
| 646 |
} |
| 647 |
|
| 648 |
// rotate back since we don't want to paint icon in rotated way. |
| 649 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.VERTICAL) { |
| 650 |
// Dimension size = b.getSize(); |
| 651 |
Graphics2D g2d = (Graphics2D) g; |
| 652 |
g2d.rotate(-Math.PI / 2); |
| 653 |
g2d.translate(-menuHeight + 1, 0); |
| 654 |
int save = iconRect.x; |
| 655 |
//noinspection SuspiciousNameCombination |
| 656 |
iconRect.x = iconRect.y; |
| 657 |
iconRect.y = save; |
| 658 |
} |
| 659 |
|
| 660 |
paintIcon(b, g); |
| 661 |
|
| 662 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.VERTICAL) { |
| 663 |
int save = iconRect.x; |
| 664 |
//noinspection SuspiciousNameCombination |
| 665 |
iconRect.x = iconRect.y; |
| 666 |
iconRect.y = save; |
| 667 |
// Dimension size = b.getSize(); |
| 668 |
Graphics2D g2d = (Graphics2D) g; |
| 669 |
g2d.rotate(Math.PI / 2); |
| 670 |
g2d.translate(0, -menuHeight + 1); |
| 671 |
} |
| 672 |
|
| 673 |
// Draw the Text |
| 674 |
if (text != null) { |
| 675 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
| 676 |
if (v != null) { |
| 677 |
v.paint(g, textRect); |
| 678 |
} |
| 679 |
else { |
| 680 |
paintText(g, b, textRect, text); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
// Draw the Accelerator Text |
| 685 |
if (acceleratorText != null && !acceleratorText.equals("")) { |
| 686 |
|
| 687 |
//Get the maxAccWidth from the parent to calculate the offset. |
| 688 |
int accOffset = 0; |
| 689 |
Container parent = menuItem.getParent(); |
| 690 |
if (parent != null && parent instanceof JComponent) { |
| 691 |
JComponent p = (JComponent) parent; |
| 692 |
Integer maxValueInt = (Integer) p.getClientProperty(VsnetMenuItemUI.MAX_ACC_WIDTH); |
| 693 |
int maxValue = maxValueInt != null ? |
| 694 |
maxValueInt : acceleratorRect.width; |
| 695 |
|
| 696 |
//Calculate the offset, with which the accelerator texts will be drawn with. |
| 697 |
accOffset = maxValue - acceleratorRect.width; |
| 698 |
} |
| 699 |
if (!parent.getComponentOrientation().isLeftToRight()) { |
| 700 |
// in right to left case, no need to offset the accelerator, always start from the same X |
| 701 |
accOffset = 0; |
| 702 |
} |
| 703 |
|
| 704 |
g.setFont(acceleratorFont); |
| 705 |
if (!model.isEnabled()) { |
| 706 |
// *** paint the acceleratorText disabled |
| 707 |
if (disabledForeground != null) { |
| 708 |
g.setColor(disabledForeground); |
| 709 |
JideSwingUtilities.drawString(menuItem, g, acceleratorText, |
| 710 |
acceleratorRect.x - accOffset, |
| 711 |
acceleratorRect.y + fmAccel.getAscent()); |
| 712 |
} |
| 713 |
else { |
| 714 |
g.setColor(b.getBackground().brighter()); |
| 715 |
JideSwingUtilities.drawString(menuItem, g, acceleratorText, |
| 716 |
acceleratorRect.x - accOffset, |
| 717 |
acceleratorRect.y + fmAccel.getAscent()); |
| 718 |
g.setColor(b.getBackground().darker()); |
| 719 |
JideSwingUtilities.drawString(menuItem, g, acceleratorText, |
| 720 |
acceleratorRect.x - accOffset - 1, |
| 721 |
acceleratorRect.y + fmAccel.getAscent() - 1); |
| 722 |
} |
| 723 |
} |
| 724 |
else { |
| 725 |
// *** paint the acceleratorText normally |
| 726 |
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { |
| 727 |
g.setColor(acceleratorSelectionForeground); |
| 728 |
} |
| 729 |
else { |
| 730 |
g.setColor(acceleratorForeground); |
| 731 |
} |
| 732 |
JideSwingUtilities.drawString(menuItem, g, acceleratorText, |
| 733 |
acceleratorRect.x - accOffset, |
| 734 |
acceleratorRect.y + fmAccel.getAscent()); |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
// Paint the Arrow |
| 739 |
if (arrowIcon != null) { |
| 740 |
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) |
| 741 |
g.setColor(foreground); |
| 742 |
if (useCheckAndArrow()) { |
| 743 |
arrowIcon.paintIcon(c, g, arrowIconRect.x, arrowIconRect.y); |
| 744 |
} |
| 745 |
} |
| 746 |
g.setColor(holdc); |
| 747 |
g.setFont(holdf); |
| 748 |
} |
| 749 |
|
| 750 |
protected void paintCheckBox(JMenuItem b, Graphics g, Icon checkIcon) { |
| 751 |
ButtonModel model = b.getModel(); |
| 752 |
boolean isSelected = false; |
| 753 |
if (b instanceof JCheckBoxMenuItem) |
| 754 |
isSelected = b.isSelected(); |
| 755 |
else if (b instanceof JRadioButtonMenuItem) |
| 756 |
isSelected = b.isSelected(); |
| 757 |
if (isSelected) { |
| 758 |
if (model.isArmed() || model.isSelected()) { |
| 759 |
getPainter().paintMenuItemBackground(b, g, checkIconRect, SwingConstants.HORIZONTAL, ThemePainter.STATE_PRESSED); |
| 760 |
if (b.getIcon() == null) { |
| 761 |
checkIcon.paintIcon(b, g, checkIconRect.x, checkIconRect.y); |
| 762 |
} |
| 763 |
} |
| 764 |
else { |
| 765 |
getPainter().paintMenuItemBackground(b, g, checkIconRect, SwingConstants.HORIZONTAL, ThemePainter.STATE_SELECTED); |
| 766 |
if (b.getIcon() == null) { |
| 767 |
checkIcon.paintIcon(b, g, checkIconRect.x, checkIconRect.y); |
| 768 |
} |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
protected void paintIcon(JMenuItem b, Graphics g) { |
| 774 |
if (b.getIcon() != null) { |
| 775 |
Icon icon = getIcon(b); |
| 776 |
|
| 777 |
ButtonModel model = b.getModel(); |
| 778 |
if (icon != null) { |
| 779 |
if (isFloatingIcon()) { |
| 780 |
if (model.isArmed() || (b instanceof JMenu && model.isSelected())) { |
| 781 |
if (icon instanceof ImageIcon) { |
| 782 |
ImageIcon shadow = IconsFactory.createGrayImage(((ImageIcon) icon).getImage()); |
| 783 |
shadow.paintIcon(b, g, iconRect.x + 1, iconRect.y + 1); |
| 784 |
} |
| 785 |
else { |
| 786 |
ImageIcon shadow = IconsFactory.createGrayImage(b, icon); |
| 787 |
shadow.paintIcon(b, g, iconRect.x + 1, iconRect.y + 1); |
| 788 |
} |
| 789 |
icon.paintIcon(b, g, iconRect.x - 1, iconRect.y - 1); |
| 790 |
} |
| 791 |
else { |
| 792 |
icon.paintIcon(b, g, iconRect.x, iconRect.y); |
| 793 |
} |
| 794 |
} |
| 795 |
else { |
| 796 |
icon.paintIcon(b, g, iconRect.x, iconRect.y); |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
/** |
| 803 |
* Draws the background of the menu item. |
| 804 |
* |
| 805 |
* @param g the paint graphics |
| 806 |
* @param menuItem menu item to be painted |
| 807 |
* @param bgColor selection background color |
| 808 |
* @since 1.4 |
| 809 |
*/ |
| 810 |
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { |
| 811 |
ButtonModel model = menuItem.getModel(); |
| 812 |
Color oldColor = g.getColor(); |
| 813 |
int menuWidth; |
| 814 |
int menuHeight; |
| 815 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) { |
| 816 |
menuWidth = menuItem.getWidth(); |
| 817 |
menuHeight = menuItem.getHeight(); |
| 818 |
} |
| 819 |
else { |
| 820 |
menuWidth = menuItem.getHeight(); |
| 821 |
menuHeight = menuItem.getWidth(); |
| 822 |
} |
| 823 |
|
| 824 |
if (menuItem.isOpaque()) { |
| 825 |
if (menuItem.getComponentOrientation().isLeftToRight()) { |
| 826 |
if (menuItem.getBackground() instanceof UIResource) { |
| 827 |
g.setColor(getPainter().getMenuItemBackground()); |
| 828 |
} |
| 829 |
else { |
| 830 |
g.setColor(menuItem.getBackground()); |
| 831 |
} |
| 832 |
g.fillRect(defaultShadowWidth, 0, menuWidth - defaultShadowWidth, menuHeight); |
| 833 |
getPainter().paintMenuShadow(menuItem, g, new Rectangle(0, 0, defaultShadowWidth, menuHeight), SwingConstants.HORIZONTAL, ThemePainter.STATE_DEFAULT); |
| 834 |
|
| 835 |
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
| 836 |
getPainter().paintMenuItemBackground(menuItem, g, new Rectangle(1, 0, menuWidth - 2, menuHeight), SwingConstants.HORIZONTAL, ThemePainter.STATE_ROLLOVER); |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
if ("true".equals(SecurityUtils.getProperty("shadingtheme", "false"))) { |
| 841 |
JideSwingUtilities.fillSingleGradient(g, new Rectangle(0, 0, defaultShadowWidth, menuHeight), SwingConstants.EAST, 255); |
| 842 |
} |
| 843 |
|
| 844 |
g.setColor(oldColor); |
| 845 |
} |
| 846 |
else { |
| 847 |
if (menuItem.getBackground() instanceof UIResource) { |
| 848 |
g.setColor(getPainter().getMenuItemBackground()); |
| 849 |
} |
| 850 |
else { |
| 851 |
g.setColor(menuItem.getBackground()); |
| 852 |
} |
| 853 |
g.fillRect(0, 0, menuWidth - defaultShadowWidth, menuHeight); |
| 854 |
getPainter().paintMenuShadow(menuItem, g, new Rectangle(menuWidth - defaultShadowWidth, 0, defaultShadowWidth, menuHeight), SwingConstants.HORIZONTAL, ThemePainter.STATE_DEFAULT); |
| 855 |
|
| 856 |
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
| 857 |
getPainter().paintMenuItemBackground(menuItem, g, new Rectangle(0, 0, menuWidth, menuHeight), SwingConstants.HORIZONTAL, ThemePainter.STATE_ROLLOVER); |
| 858 |
} |
| 859 |
|
| 860 |
if ("true".equals(SecurityUtils.getProperty("shadingtheme", "false"))) { |
| 861 |
JideSwingUtilities.fillSingleGradient(g, new Rectangle(menuWidth - defaultShadowWidth, 0, defaultShadowWidth, menuHeight), SwingConstants.WEST, 255); |
| 862 |
} |
| 863 |
|
| 864 |
g.setColor(oldColor); |
| 865 |
} |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
/** |
| 870 |
* Method which renders the text of the current menu item. |
| 871 |
* <p/> |
| 872 |
* |
| 873 |
* @param g Graphics context |
| 874 |
* @param menuItem Current menu item to render |
| 875 |
* @param textRect Bounding rectangle to render the text. |
| 876 |
* @param text String to render |
| 877 |
*/ |
| 878 |
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
| 879 |
// Note: This method is almost identical to the same method in WindowsMenuUI |
| 880 |
ButtonModel model = menuItem.getModel(); |
| 881 |
|
| 882 |
FontMetrics fm = g.getFontMetrics(); |
| 883 |
|
| 884 |
if (!model.isEnabled()) { |
| 885 |
// *** paint the text disabled |
| 886 |
WindowsGraphicsUtilsPort.paintText(g, menuItem, textRect, text, 0); |
| 887 |
} |
| 888 |
else { |
| 889 |
int mnemonicIndex = menuItem.getDisplayedMnemonicIndex(); |
| 890 |
// W2K Feature: Check to see if the Underscore should be rendered. |
| 891 |
if (SystemInfo.isMnemonicHidden()) { |
| 892 |
mnemonicIndex = -1; |
| 893 |
} |
| 894 |
|
| 895 |
Color oldColor = g.getColor(); |
| 896 |
|
| 897 |
// *** paint the text normally |
| 898 |
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
| 899 |
g.setColor(selectionForeground); // Uses protected field. |
| 900 |
} |
| 901 |
JideSwingUtilities.drawStringUnderlineCharAt(menuItem, g, text, |
| 902 |
mnemonicIndex, |
| 903 |
textRect.x, |
| 904 |
textRect.y + fm.getAscent()); |
| 905 |
g.setColor(oldColor); |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
private String layoutMenuItem(FontMetrics fm, |
| 910 |
String text, |
| 911 |
FontMetrics fmAccel, |
| 912 |
String acceleratorText, |
| 913 |
Icon icon, |
| 914 |
Icon checkIcon, |
| 915 |
Icon arrowIcon, |
| 916 |
int verticalAlignment, |
| 917 |
int horizontalAlignment, |
| 918 |
int verticalTextPosition, |
| 919 |
int horizontalTextPosition, |
| 920 |
Rectangle viewRect, |
| 921 |
Rectangle iconRect, |
| 922 |
Rectangle textRect, |
| 923 |
Rectangle acceleratorRect, |
| 924 |
Rectangle checkIconRect, |
| 925 |
Rectangle arrowIconRect, |
| 926 |
int textIconGap, |
| 927 |
int menuItemGap) { |
| 928 |
if (icon != null) |
| 929 |
if ((icon.getIconHeight() == 0) || (icon.getIconWidth() == 0)) |
| 930 |
icon = null; // An exception may occur in case of zero sized icons |
| 931 |
|
| 932 |
viewRect.width -= getRightMargin(); // this line is mainly for JideSplitButton |
| 933 |
String newText = SwingUtilities.layoutCompoundLabel(menuItem, fm, text, icon, verticalAlignment, |
| 934 |
horizontalAlignment, verticalTextPosition, |
| 935 |
horizontalTextPosition, viewRect, iconRect, textRect, |
| 936 |
textIconGap); |
| 937 |
// only do it for split menu |
| 938 |
if (getRightMargin() > 0) { |
| 939 |
text = newText; |
| 940 |
} |
| 941 |
viewRect.width += getRightMargin(); // this line is mainly for JideSplitButton |
| 942 |
|
| 943 |
Insets insets = isDownArrowVisible(menuItem.getParent()) ? new Insets(0, 0, 0, 0) : menuItem.getInsets(); |
| 944 |
// get viewRect which is the bounds of menuitem |
| 945 |
viewRect.x = insets.left; |
| 946 |
viewRect.y = insets.top; |
| 947 |
if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) { |
| 948 |
// Dimension size = b.getSize(); |
| 949 |
viewRect.height = menuItem.getHeight() - insets.top - insets.bottom; |
| 950 |
viewRect.width = menuItem.getWidth() - insets.left - insets.right; |
| 951 |
} |
| 952 |
else { |
| 953 |
// Dimension size = b.getSize(); |
| 954 |
viewRect.height = menuItem.getWidth() - insets.top - insets.bottom; |
| 955 |
viewRect.width = menuItem.getHeight() - insets.left - insets.right; |
| 956 |
} |
| 957 |
|
| 958 |
/* Initialize the acceelratorText bounds rectangle textRect. If a null |
| 959 |
* or and empty String was specified we substitute "" here |
| 960 |
* and use 0,0,0,0 for acceleratorTextRect. |
| 961 |
*/ |
| 962 |
if ((acceleratorText == null) || acceleratorText.equals("")) { |
| 963 |
acceleratorRect.width = acceleratorRect.height = 0; |
| 964 |
} |
| 965 |
else { |
| 966 |
acceleratorRect.width = SwingUtilities.computeStringWidth(fmAccel, acceleratorText); |
| 967 |
acceleratorRect.height = fmAccel.getHeight(); |
| 968 |
} |
| 969 |
|
| 970 |
if ((text == null) || text.equals("")) { |
| 971 |
textRect.width = textRect.height = 0; |
| 972 |
text = ""; |
| 973 |
} |
| 974 |
else { |
| 975 |
View v; |
| 976 |
v = (menuItem != null) ? (View) menuItem.getClientProperty("html") : null; |
| 977 |
if (v != null) { |
| 978 |
textRect.width = (int) v.getPreferredSpan(View.X_AXIS); |
| 979 |
textRect.height = (int) v.getPreferredSpan(View.Y_AXIS); |
| 980 |
} |
| 981 |
else { |
| 982 |
textRect.width = SwingUtilities.computeStringWidth(fm, text); |
| 983 |
textRect.height = fm.getHeight(); |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
if (icon == null) { |
| 988 |
if (useCheckAndArrow()) |
| 989 |
iconRect.width = iconRect.height = 16; |
| 990 |
else |
| 991 |
iconRect.width = iconRect.height = 0; |
| 992 |
} |
| 993 |
else { |
| 994 |
iconRect.width = icon.getIconWidth(); |
| 995 |
iconRect.height = icon.getIconHeight(); |
| 996 |
} |
| 997 |
|
| 998 |
if (arrowIcon == null) { |
| 999 |
arrowIconRect.width = arrowIconRect.height = 0; |
| 1000 |
} |
| 1001 |
else { |
| 1002 |
try { |
| 1003 |
arrowIconRect.width = arrowIcon.getIconWidth(); |
| 1004 |
arrowIconRect.height = arrowIcon.getIconHeight(); |
| 1005 |
} |
| 1006 |
catch (Exception e) { |
| 1007 |
arrowIconRect.width = arrowIconRect.height = 0; |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
if (checkIcon == null) { |
| 1012 |
checkIconRect.width = checkIconRect.height = 0; |
| 1013 |
} |
| 1014 |
else { |
| 1015 |
try { |
| 1016 |
checkIconRect.width = icon != null ? icon.getIconWidth() : checkIcon.getIconWidth(); |
| 1017 |
checkIconRect.height = icon != null ? icon.getIconHeight() : checkIcon.getIconHeight(); |
| 1018 |
} |
| 1019 |
catch (Exception e) { |
| 1020 |
checkIconRect.width = checkIconRect.height = 0; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
// left a shadow for non-top level menu |
| 1025 |
if (useCheckAndArrow()) { |
| 1026 |
iconRect.x = (defaultShadowWidth - iconRect.width) >> 1; |
| 1027 |
if (text != null && !text.equals("")) { |
| 1028 |
textRect.x = viewRect.x + defaultShadowWidth + textIconGap; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
else { |
| 1032 |
// if (icon != null) { |
| 1033 |
// if (isDownArrowVisible(menuItem.getParent())) { |
| 1034 |
// iconRect.x = 3; |
| 1035 |
// } |
| 1036 |
// else { |
| 1037 |
// iconRect.x = menuItem.getInsets().left; |
| 1038 |
// } |
| 1039 |
// if (text != null && !text.equals("")) { |
| 1040 |
// textRect.x = iconRect.x + iconRect.width + textIconGap; |
| 1041 |
// } |
| 1042 |
// } |
| 1043 |
// else { |
| 1044 |
// if (text != null && !text.equals("")) { |
| 1045 |
// if (isDownArrowVisible(menuItem.getParent())) { |
| 1046 |
// textRect.x = 3; |
| 1047 |
// } |
| 1048 |
// else { |
| 1049 |
// textRect.x = menuItem.getInsets().left; |
| 1050 |
// } |
| 1051 |
// } |
| 1052 |
// } |
| 1053 |
} |
| 1054 |
|
| 1055 |
// Position the Accelerator text rect |
| 1056 |
acceleratorRect.x = viewRect.x + viewRect.width - menuItemGap |
| 1057 |
- acceleratorRect.width; |
| 1058 |
|
| 1059 |
// Position the Check and Arrow Icons |
| 1060 |
if (useCheckAndArrow()) { |
| 1061 |
checkIconRect.x = viewRect.x + (defaultShadowWidth - checkIconRect.width) >> 1; |
| 1062 |
arrowIconRect.x = viewRect.x + viewRect.width - menuItemGap - 5 |
| 1063 |
- arrowIconRect.width; |
| 1064 |
} |
| 1065 |
|
| 1066 |
if (verticalTextPosition == SwingConstants.CENTER && verticalAlignment == SwingConstants.CENTER) { |
| 1067 |
// put it in the middle |
| 1068 |
if (text != null && !text.equals("")) { |
| 1069 |
textRect.y = viewRect.y + ((viewRect.height - textRect.height) >> 1); |
| 1070 |
} |
| 1071 |
iconRect.y = viewRect.y + ((viewRect.height - iconRect.height) >> 1); |
| 1072 |
} |
| 1073 |
|
| 1074 |
Rectangle labelRect = iconRect.union(textRect); |
| 1075 |
|
| 1076 |
// Align the accelerator text and the check and arrow icons vertically |
| 1077 |
// with the center of the label rect. |
| 1078 |
acceleratorRect.y = labelRect.y + (labelRect.height >> 1) - (acceleratorRect.height >> 1); |
| 1079 |
|
| 1080 |
if (useCheckAndArrow()) { |
| 1081 |
arrowIconRect.y = viewRect.y + ((viewRect.height - arrowIconRect.height) >> 1);// |
| 1082 |
checkIconRect.y = viewRect.y + ((viewRect.height - checkIconRect.height) >> 1);//labelRect.y + (labelRect.height / 2) - (checkIconRect.height / 2); |
| 1083 |
} |
| 1084 |
|
| 1085 |
if ((useCheckAndArrow() || menuItem instanceof JideSplitButton) && !menuItem.getComponentOrientation().isLeftToRight()) { |
| 1086 |
checkIconRect.x = viewRect.width - checkIconRect.width - checkIconRect.x; |
| 1087 |
iconRect.x = viewRect.width - iconRect.width - iconRect.x; |
| 1088 |
textRect.x = viewRect.width - textRect.width - textRect.x; |
| 1089 |
acceleratorRect.x = viewRect.width - acceleratorRect.width - acceleratorRect.x; |
| 1090 |
arrowIconRect.x = viewRect.width - arrowIconRect.width - arrowIconRect.x; |
| 1091 |
} |
| 1092 |
|
| 1093 |
// System.out.println("Layout: text=" + menuItem.getText() + "\n\tv=" |
| 1094 |
// + viewRect + "\n\tc=" + checkIconRect + "\n\ti=" |
| 1095 |
// + iconRect + "\n\tt=" + textRect + "\n\tacc=" |
| 1096 |
// + acceleratorRect + "\n\ta=" + arrowIconRect + "\n"); |
| 1097 |
|
| 1098 |
return text; |
| 1099 |
} |
| 1100 |
|
| 1101 |
/* |
| 1102 |
* Returns false if the component is a JMenu and it is a top |
| 1103 |
* level menu (on the menubar). |
| 1104 |
*/ |
| 1105 |
protected boolean useCheckAndArrow() { |
| 1106 |
boolean b = true; |
| 1107 |
if ((menuItem instanceof JMenu) && |
| 1108 |
(((JMenu) menuItem).isTopLevelMenu())) { |
| 1109 |
b = false; |
| 1110 |
} |
| 1111 |
return b; |
| 1112 |
} |
| 1113 |
|
| 1114 |
public MenuElement[] getPath() { |
| 1115 |
MenuSelectionManager m = MenuSelectionManager.defaultManager(); |
| 1116 |
MenuElement oldPath[] = m.getSelectedPath(); |
| 1117 |
MenuElement newPath[]; |
| 1118 |
int i = oldPath.length; |
| 1119 |
if (i == 0) |
| 1120 |
return new MenuElement[0]; |
| 1121 |
Component parent = menuItem.getParent(); |
| 1122 |
if (oldPath[i - 1].getComponent() == parent) { |
| 1123 |
// The parent popup menu is the last so far |
| 1124 |
newPath = new MenuElement[i + 1]; |
| 1125 |
System.arraycopy(oldPath, 0, newPath, 0, i); |
| 1126 |
newPath[i] = menuItem; |
| 1127 |
} |
| 1128 |
else { |
| 1129 |
// A sibling menuitem is the current selection |
| 1130 |
// |
| 1131 |
// This probably needs to handle 'exit submenu into |
| 1132 |
// a menu item. Search backwards along the current |
| 1133 |
// selection until you find the parent popup menu, |
| 1134 |
// then copy up to that and add yourself... |
| 1135 |
int j; |
| 1136 |
for (j = oldPath.length - 1; j >= 0; j--) { |
| 1137 |
if (oldPath[j].getComponent() == parent) |
| 1138 |
break; |
| 1139 |
} |
| 1140 |
newPath = new MenuElement[j + 2]; |
| 1141 |
System.arraycopy(oldPath, 0, newPath, 0, j + 1); |
| 1142 |
newPath[j + 1] = menuItem; |
| 1143 |
/* |
| 1144 |
System.out.println("Sibling condition -- "); |
| 1145 |
System.out.println("Old array : "); |
| 1146 |
printMenuElementArray(oldPath, false); |
| 1147 |
System.out.println("New array : "); |
| 1148 |
printMenuElementArray(newPath, false); |
| 1149 |
*/ |
| 1150 |
} |
| 1151 |
return newPath; |
| 1152 |
} |
| 1153 |
|
| 1154 |
/* |
| 1155 |
void printMenuElementArray(MenuElement path[], boolean dumpStack) { |
| 1156 |
System.out.println("Path is("); |
| 1157 |
int i, j; |
| 1158 |
for (i = 0, j = path.length; i < j; i++) { |
| 1159 |
for (int k = 0; k <= i; k++) |
| 1160 |
System.out.print(" "); |
| 1161 |
MenuElement me = (MenuElement) path[i]; |
| 1162 |
if (me instanceof JMenuItem) |
| 1163 |
System.out.println(((JMenuItem) me).getText() + ", "); |
| 1164 |
else if (me == null) |
| 1165 |
System.out.println("NULL , "); |
| 1166 |
else |
| 1167 |
System.out.println("" + me + ", "); |
| 1168 |
} |
| 1169 |
System.out.println(")"); |
| 1170 |
|
| 1171 |
if (dumpStack == true) |
| 1172 |
Thread.dumpStack(); |
| 1173 |
} |
| 1174 |
|
| 1175 |
*/ |
| 1176 |
|
| 1177 |
protected class MouseInputHandler implements MouseInputListener { |
| 1178 |
public void mouseClicked(MouseEvent e) { |
| 1179 |
} |
| 1180 |
|
| 1181 |
public void mousePressed(MouseEvent e) { |
| 1182 |
} |
| 1183 |
|
| 1184 |
public void mouseReleased(MouseEvent e) { |
| 1185 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1186 |
MenuSelectionManager manager = MenuSelectionManager.defaultManager(); |
| 1187 |
Point p = e.getPoint(); |
| 1188 |
if (p.x >= 0 && p.x < menuItem.getWidth() && |
| 1189 |
p.y >= 0 && p.y < menuItem.getHeight()) { |
| 1190 |
doClick(manager); |
| 1191 |
} |
| 1192 |
else { |
| 1193 |
manager.processMouseEvent(e); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
public void mouseEntered(MouseEvent e) { |
| 1199 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1200 |
MenuSelectionManager manager = MenuSelectionManager.defaultManager(); |
| 1201 |
int modifiers = e.getModifiers(); |
| 1202 |
// 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2 |
| 1203 |
if ((modifiers & (InputEvent.BUTTON1_MASK | |
| 1204 |
InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) { |
| 1205 |
MenuSelectionManager.defaultManager().processMouseEvent(e); |
| 1206 |
} |
| 1207 |
else { |
| 1208 |
manager.setSelectedPath(getPath()); |
| 1209 |
} |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
public void mouseExited(MouseEvent e) { |
| 1214 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1215 |
MenuSelectionManager manager = MenuSelectionManager.defaultManager(); |
| 1216 |
|
| 1217 |
int modifiers = e.getModifiers(); |
| 1218 |
// 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2 |
| 1219 |
if ((modifiers & (InputEvent.BUTTON1_MASK | |
| 1220 |
InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) { |
| 1221 |
MenuSelectionManager.defaultManager().processMouseEvent(e); |
| 1222 |
} |
| 1223 |
else { |
| 1224 |
|
| 1225 |
MenuElement path[] = manager.getSelectedPath(); |
| 1226 |
if (path.length > 1) { |
| 1227 |
MenuElement newPath[] = new MenuElement[path.length - 1]; |
| 1228 |
int i, c; |
| 1229 |
for (i = 0, c = path.length - 1; i < c; i++) |
| 1230 |
newPath[i] = path[i]; |
| 1231 |
manager.setSelectedPath(newPath); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
} |
| 1235 |
} |
| 1236 |
|
| 1237 |
public void mouseDragged(MouseEvent e) { |
| 1238 |
MenuSelectionManager.defaultManager().processMouseEvent(e); |
| 1239 |
} |
| 1240 |
|
| 1241 |
public void mouseMoved(MouseEvent e) { |
| 1242 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1243 |
MenuSelectionManager manager = MenuSelectionManager.defaultManager(); |
| 1244 |
int modifiers = e.getModifiers(); |
| 1245 |
// 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2 |
| 1246 |
if ((modifiers & (InputEvent.BUTTON1_MASK | |
| 1247 |
InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) == 0) { |
| 1248 |
MenuElement[] path = manager.getSelectedPath(); |
| 1249 |
if (getPath().length > path.length) { // MOUSE ENTER event is missed because of overlap menu items, for example the JideSplitButton |
| 1250 |
manager.setSelectedPath(getPath()); |
| 1251 |
} |
| 1252 |
} |
| 1253 |
} |
| 1254 |
} |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
private class MenuDragMouseHandler implements MenuDragMouseListener { |
| 1259 |
public void menuDragMouseEntered(MenuDragMouseEvent e) { |
| 1260 |
} |
| 1261 |
|
| 1262 |
public void menuDragMouseDragged(MenuDragMouseEvent e) { |
| 1263 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1264 |
MenuSelectionManager manager = e.getMenuSelectionManager(); |
| 1265 |
MenuElement path[] = e.getPath(); |
| 1266 |
manager.setSelectedPath(path); |
| 1267 |
} |
| 1268 |
} |
| 1269 |
|
| 1270 |
public void menuDragMouseExited(MenuDragMouseEvent e) { |
| 1271 |
} |
| 1272 |
|
| 1273 |
public void menuDragMouseReleased(MenuDragMouseEvent e) { |
| 1274 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1275 |
MenuSelectionManager manager = e.getMenuSelectionManager(); |
| 1276 |
Point p = e.getPoint(); |
| 1277 |
if (p.x >= 0 && p.x < menuItem.getWidth() && |
| 1278 |
p.y >= 0 && p.y < menuItem.getHeight()) { |
| 1279 |
doClick(manager); |
| 1280 |
} |
| 1281 |
else { |
| 1282 |
manager.clearSelectedPath(); |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
private class MenuKeyHandler implements MenuKeyListener { |
| 1289 |
|
| 1290 |
/** |
| 1291 |
* Handles the mnemonic key typed in the MenuItem if this menuItem is in a standalone popup menu. This |
| 1292 |
* invocation normally handled in BasicMenuUI.MenuKeyHandler.menuKeyPressed. Ideally, the MenuKeyHandlers for |
| 1293 |
* both BasicMenuItemUI and BasicMenuUI can be consolidated into BasicPopupMenuUI but that would require an |
| 1294 |
* semantic change. This would result in a performance win since we can shortcut a lot of the needless |
| 1295 |
* processing from MenuSelectionManager.processKeyEvent(). See 4670831. |
| 1296 |
*/ |
| 1297 |
public void menuKeyTyped(MenuKeyEvent e) { |
| 1298 |
if (menuItem != null && menuItem.isEnabled()) { |
| 1299 |
int key = menuItem.getMnemonic(); |
| 1300 |
if (key == 0 || e.getPath().length != 2) // Hack! Only proceed if in a JPopupMenu |
| 1301 |
return; |
| 1302 |
if (lower((char) key) == lower(e.getKeyChar())) { |
| 1303 |
MenuSelectionManager manager = |
| 1304 |
e.getMenuSelectionManager(); |
| 1305 |
doClick(manager); |
| 1306 |
e.consume(); |
| 1307 |
} |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
public void menuKeyPressed(MenuKeyEvent e) { |
| 1312 |
} |
| 1313 |
|
| 1314 |
public void menuKeyReleased(MenuKeyEvent e) { |
| 1315 |
} |
| 1316 |
|
| 1317 |
private char lower(char keyChar) { |
| 1318 |
return Character.toLowerCase(keyChar); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
private class PropertyChangeHandler implements PropertyChangeListener { |
| 1323 |
public void propertyChange(PropertyChangeEvent e) { |
| 1324 |
String name = e.getPropertyName(); |
| 1325 |
|
| 1326 |
if (name.equals("labelFor") || name.equals("displayedMnemonic") || |
| 1327 |
name.equals("accelerator")) { |
| 1328 |
updateAcceleratorBinding(); |
| 1329 |
} |
| 1330 |
else if (ButtonStyle.BUTTON_STYLE_PROPERTY.equals(name) |
| 1331 |
|| "opaque".equals(name) |
| 1332 |
|| AbstractButton.CONTENT_AREA_FILLED_CHANGED_PROPERTY.equals(name) |
| 1333 |
) { |
| 1334 |
JMenuItem lbl = ((JMenuItem) e.getSource()); |
| 1335 |
lbl.repaint(); |
| 1336 |
} |
| 1337 |
else if (name.equals("orientation")) { |
| 1338 |
JMenuItem lbl = ((JMenuItem) e.getSource()); |
| 1339 |
lbl.invalidate(); |
| 1340 |
lbl.repaint(); |
| 1341 |
} |
| 1342 |
else if (name.equals("text") || "font".equals(name) || |
| 1343 |
"foreground".equals(name)) { |
| 1344 |
// remove the old html view client property if one |
| 1345 |
// existed, and install a new one if the text installed |
| 1346 |
// into the JLabel is html source. |
| 1347 |
JMenuItem lbl = ((JMenuItem) e.getSource()); |
| 1348 |
String text = lbl.getText(); |
| 1349 |
BasicHTML.updateRenderer(lbl, text); |
| 1350 |
} |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
private static class ClickAction extends AbstractAction { |
| 1355 |
private static final long serialVersionUID = -8707660318949717143L; |
| 1356 |
|
| 1357 |
public void actionPerformed(ActionEvent e) { |
| 1358 |
JMenuItem mi = (JMenuItem) e.getSource(); |
| 1359 |
MenuSelectionManager.defaultManager().clearSelectedPath(); |
| 1360 |
mi.doClick(); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
|
| 1364 |
/** |
| 1365 |
* Call this method when a menu item is to be activated. This method handles some of the details of menu item |
| 1366 |
* activation such as clearing the selected path and messaging the JMenuItem's doClick() method. |
| 1367 |
* |
| 1368 |
* @param msm A MenuSelectionManager. The visual feedback and internal bookkeeping tasks are delegated to this |
| 1369 |
* MenuSelectionManager. If <code>null</code> is passed as this argument, the |
| 1370 |
* <code>MenuSelectionManager.defaultManager</code> is used. |
| 1371 |
* @see MenuSelectionManager |
| 1372 |
* @see JMenuItem#doClick(int) |
| 1373 |
* @since 1.4 |
| 1374 |
*/ |
| 1375 |
protected void doClick(MenuSelectionManager msm) { |
| 1376 |
// Auditory cue |
| 1377 |
// if (!isInternalFrameSystemMenu()) { |
| 1378 |
// ActionMap map = menuItem.getActionMap(); |
| 1379 |
// if (map != null) { |
| 1380 |
// Action audioAction = map.get(getPropertyPrefix() + |
| 1381 |
// ".commandSound"); |
| 1382 |
// if (audioAction != null) { |
| 1383 |
// pass off firing the Action to a utility method |
| 1384 |
// BasicLookAndFeel lf = (BasicLookAndFeel) |
| 1385 |
// UIManager.getLookAndFeel(); |
| 1386 |
// lf.playSound(audioAction); |
| 1387 |
// } |
| 1388 |
// } |
| 1389 |
// } |
| 1390 |
// // Visual feedback |
| 1391 |
if (msm == null) { |
| 1392 |
msm = MenuSelectionManager.defaultManager(); |
| 1393 |
} |
| 1394 |
msm.clearSelectedPath(); |
| 1395 |
menuItem.doClick(0); |
| 1396 |
} |
| 1397 |
|
| 1398 |
protected ThemePainter getPainter() { |
| 1399 |
return _painter; |
| 1400 |
} |
| 1401 |
|
| 1402 |
protected boolean isDownArrowVisible(Container c) { |
| 1403 |
if (c instanceof TopLevelMenuContainer && ((TopLevelMenuContainer) c).isMenuBar()) { |
| 1404 |
return false; |
| 1405 |
} |
| 1406 |
else if (c instanceof TopLevelMenuContainer && !((TopLevelMenuContainer) c).isMenuBar()) { |
| 1407 |
return true; |
| 1408 |
} |
| 1409 |
else if (c instanceof JMenuBar) { |
| 1410 |
return false; |
| 1411 |
} |
| 1412 |
else { |
| 1413 |
return true; |
| 1414 |
} |
| 1415 |
} |
| 1416 |
|
| 1417 |
protected boolean isFloatingIcon() { |
| 1418 |
return _isFloatingIcon; |
| 1419 |
} |
| 1420 |
|
| 1421 |
protected Icon getIcon(AbstractButton b) { |
| 1422 |
ButtonModel model = b.getModel(); |
| 1423 |
Icon icon = b.getIcon(); |
| 1424 |
Icon tmpIcon = null; |
| 1425 |
if (!model.isEnabled()) { |
| 1426 |
if (model.isSelected()) { |
| 1427 |
tmpIcon = b.getDisabledSelectedIcon(); |
| 1428 |
} |
| 1429 |
else { |
| 1430 |
tmpIcon = b.getDisabledIcon(); |
| 1431 |
} |
| 1432 |
|
| 1433 |
// create default disabled icon |
| 1434 |
if (tmpIcon == null) { |
| 1435 |
if (icon instanceof ImageIcon) { |
| 1436 |
icon = IconsFactory.createGrayImage(((ImageIcon) icon).getImage()); |
| 1437 |
} |
| 1438 |
else { |
| 1439 |
icon = IconsFactory.createGrayImage(b, icon); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
} |
| 1443 |
else if (model.isPressed() && model.isArmed()) { |
| 1444 |
tmpIcon = b.getPressedIcon(); |
| 1445 |
if (tmpIcon != null) { |
| 1446 |
} |
| 1447 |
} |
| 1448 |
else if (b.isRolloverEnabled() && model.isRollover()) { |
| 1449 |
if (model.isSelected()) { |
| 1450 |
tmpIcon = b.getRolloverSelectedIcon(); |
| 1451 |
} |
| 1452 |
else { |
| 1453 |
tmpIcon = b.getRolloverIcon(); |
| 1454 |
} |
| 1455 |
} |
| 1456 |
else if (model.isSelected()) { |
| 1457 |
tmpIcon = b.getSelectedIcon(); |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (tmpIcon != null) { |
| 1461 |
icon = tmpIcon; |
| 1462 |
} |
| 1463 |
return icon; |
| 1464 |
} |
| 1465 |
|
| 1466 |
protected int getRightMargin() { |
| 1467 |
return 0; |
| 1468 |
} |
| 1469 |
} |