Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java
66646 views
1
/*
2
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.apple.laf;
27
28
import java.awt.*;
29
import java.awt.event.*;
30
import java.beans.PropertyChangeEvent;
31
32
import javax.swing.*;
33
import javax.swing.border.Border;
34
import javax.swing.event.*;
35
import javax.swing.plaf.*;
36
import javax.swing.plaf.basic.*;
37
import javax.swing.text.View;
38
39
import sun.swing.SwingUtilities2;
40
41
import apple.laf.JRSUIConstants.Size;
42
43
import com.apple.laf.AquaButtonExtendedTypes.TypeSpecifier;
44
import com.apple.laf.AquaUtilControlSize.Sizeable;
45
import com.apple.laf.AquaUtils.*;
46
47
public class AquaButtonUI extends BasicButtonUI implements Sizeable {
48
private static final String BUTTON_TYPE = "JButton.buttonType";
49
private static final String SEGMENTED_BUTTON_POSITION = "JButton.segmentPosition";
50
51
private static final RecyclableSingleton<AquaButtonUI> buttonUI = new RecyclableSingletonFromDefaultConstructor<AquaButtonUI>(AquaButtonUI.class);
52
public static ComponentUI createUI(final JComponent c) {
53
return buttonUI.get();
54
}
55
56
// Has the shared instance defaults been initialized?
57
private boolean defaults_initialized = false;
58
private Color defaultDisabledTextColor = null;
59
60
protected void installDefaults(final AbstractButton b) {
61
// load shared instance defaults
62
final String pp = getPropertyPrefix();
63
64
if (!defaults_initialized) {
65
defaultDisabledTextColor = UIManager.getColor(pp + "disabledText");
66
defaults_initialized = true;
67
}
68
69
setButtonMarginIfNeeded(b, UIManager.getInsets(pp + "margin"));
70
71
LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
72
LookAndFeel.installProperty(b, "opaque", UIManager.getBoolean(pp + "opaque"));
73
74
final Object borderProp = b.getClientProperty(BUTTON_TYPE);
75
boolean hasBorder = false;
76
77
if (borderProp != null) {
78
hasBorder = setButtonType(b, borderProp);
79
}
80
if (!hasBorder) setThemeBorder(b);
81
82
final Object segmentProp = b.getClientProperty(SEGMENTED_BUTTON_POSITION);
83
if (segmentProp != null) {
84
final Border border = b.getBorder();
85
if (!(border instanceof AquaBorder)) return;
86
87
b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), segmentProp));
88
}
89
}
90
91
public void applySizeFor(final JComponent c, final Size size) {
92
// this space intentionally left blank
93
// (subclasses need to do work here)
94
}
95
96
protected void setThemeBorder(final AbstractButton b) {
97
// Set the correct border
98
final ButtonUI genericUI = b.getUI();
99
if (!(genericUI instanceof AquaButtonUI)) return;
100
final AquaButtonUI ui = (AquaButtonUI)genericUI;
101
102
Border border = b.getBorder();
103
if (!ui.isBorderFromProperty(b) && (border == null || border instanceof UIResource || border instanceof AquaButtonBorder)) {
104
// See BasicGraphicsUtils.getPreferredButtonSize - it returns null for preferred size,
105
// causing it to use the subcomponent's size, which doesn't allow space for Aqua pushbuttons
106
boolean iconFont = true;
107
if (isOnToolbar(b)) {
108
if (b instanceof JToggleButton) {
109
border = AquaButtonBorder.getToolBarButtonBorder();
110
} else {
111
border = AquaButtonBorder.getBevelButtonBorder();
112
}
113
} else if (b.getIcon() != null || b.getComponentCount() > 0) {
114
// radar 3308129 && (b.getText() == null || b.getText().equals("")))
115
// we used to only do this for buttons that had images and no text
116
// now we do it for all buttons that have any images - they cannot
117
// be a default button.
118
border = AquaButtonBorder.getToggleButtonBorder();
119
} else {
120
border = UIManager.getBorder(getPropertyPrefix() + "border");
121
iconFont = false;
122
}
123
124
b.setBorder(border);
125
126
final Font currentFont = b.getFont();
127
if (iconFont && (currentFont == null || currentFont instanceof UIResource)) {
128
b.setFont(UIManager.getFont("IconButton.font"));
129
}
130
}
131
}
132
133
protected static boolean isOnToolbar(final AbstractButton b) {
134
Component parent = b.getParent();
135
while (parent != null) {
136
if (parent instanceof JToolBar) return true;
137
parent = parent.getParent();
138
}
139
return false;
140
}
141
142
// A state that affects border has changed. Make sure we have the right one
143
protected static void updateBorder(final AbstractButton b) {
144
// See if the button has overridden the automatic button type
145
final Object prop = b.getClientProperty(BUTTON_TYPE);
146
if (prop != null) return;
147
148
final ButtonUI ui = b.getUI();
149
if (!(ui instanceof AquaButtonUI)) return;
150
if (b.getBorder() != null) ((AquaButtonUI)ui).setThemeBorder(b);
151
}
152
153
protected void setButtonMarginIfNeeded(final AbstractButton b, final Insets insets) {
154
final Insets margin = b.getMargin();
155
if (margin == null || (margin instanceof UIResource)) {
156
b.setMargin(insets);
157
}
158
}
159
160
public boolean isBorderFromProperty(final AbstractButton button) {
161
return button.getClientProperty(BUTTON_TYPE) != null;
162
}
163
164
protected boolean setButtonType(final AbstractButton b, final Object prop) {
165
if (!(prop instanceof String)) {
166
b.putClientProperty(BUTTON_TYPE, null); // so we know to use the automatic button type
167
return false;
168
}
169
170
final String buttonType = (String)prop;
171
boolean iconFont = true;
172
173
final TypeSpecifier specifier = AquaButtonExtendedTypes.getSpecifierByName(buttonType);
174
if (specifier != null) {
175
b.setBorder(specifier.getBorder());
176
iconFont = specifier.setIconFont;
177
}
178
179
final Font currentFont = b.getFont();
180
if (currentFont == null || currentFont instanceof UIResource) {
181
b.setFont(UIManager.getFont(iconFont ? "IconButton.font" : "Button.font"));
182
}
183
184
return true;
185
}
186
187
protected void installListeners(final AbstractButton b) {
188
super.installListeners(b);
189
AquaButtonListener listener = getAquaButtonListener(b);
190
if (listener != null) {
191
// put the listener in the button's client properties so that
192
// we can get at it later
193
b.putClientProperty(this, listener);
194
195
b.addAncestorListener(listener);
196
}
197
installHierListener(b);
198
AquaUtilControlSize.addSizePropertyListener(b);
199
}
200
201
protected void installKeyboardActions(final AbstractButton b) {
202
final BasicButtonListener listener = (BasicButtonListener)b.getClientProperty(this);
203
if (listener != null) listener.installKeyboardActions(b);
204
}
205
206
// Uninstall PLAF
207
public void uninstallUI(final JComponent c) {
208
uninstallKeyboardActions((AbstractButton)c);
209
uninstallListeners((AbstractButton)c);
210
uninstallDefaults((AbstractButton)c);
211
//BasicHTML.updateRenderer(c, "");
212
}
213
214
protected void uninstallKeyboardActions(final AbstractButton b) {
215
final BasicButtonListener listener = (BasicButtonListener)b.getClientProperty(this);
216
if (listener != null) listener.uninstallKeyboardActions(b);
217
}
218
219
protected void uninstallListeners(final AbstractButton b) {
220
super.uninstallListeners(b);
221
final AquaButtonListener listener = (AquaButtonListener)b.getClientProperty(this);
222
b.putClientProperty(this, null);
223
if (listener != null) {
224
b.removeAncestorListener(listener);
225
}
226
uninstallHierListener(b);
227
AquaUtilControlSize.removeSizePropertyListener(b);
228
}
229
230
protected void uninstallDefaults(final AbstractButton b) {
231
LookAndFeel.uninstallBorder(b);
232
defaults_initialized = false;
233
}
234
235
// Create Listeners
236
protected AquaButtonListener createButtonListener(final AbstractButton b) {
237
return new AquaButtonListener(b);
238
}
239
240
/**
241
* Returns the AquaButtonListener for the passed in Button, or null if one
242
* could not be found.
243
*/
244
private AquaButtonListener getAquaButtonListener(AbstractButton b) {
245
MouseMotionListener[] listeners = b.getMouseMotionListeners();
246
247
if (listeners != null) {
248
for (MouseMotionListener listener : listeners) {
249
if (listener instanceof AquaButtonListener) {
250
return (AquaButtonListener) listener;
251
}
252
}
253
}
254
return null;
255
}
256
257
// Paint Methods
258
public void paint(final Graphics g, final JComponent c) {
259
final AbstractButton b = (AbstractButton)c;
260
final ButtonModel model = b.getModel();
261
262
final Insets i = c.getInsets();
263
264
Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
265
Rectangle iconRect = new Rectangle();
266
Rectangle textRect = new Rectangle();
267
268
// we are overdrawing here with translucent colors so we get
269
// a darkening effect. How can we avoid it. Try clear rect?
270
if (b.isOpaque()) {
271
g.setColor(c.getBackground());
272
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
273
}
274
275
AquaButtonBorder aquaBorder = null;
276
if (((AbstractButton)c).isBorderPainted()) {
277
final Border border = c.getBorder();
278
279
if (border instanceof AquaButtonBorder) {
280
// only do this if borders are on!
281
// this also takes care of focus painting.
282
aquaBorder = (AquaButtonBorder)border;
283
aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
284
}
285
} else {
286
if (b.isOpaque()) {
287
viewRect.x = i.left - 2;
288
viewRect.y = i.top - 2;
289
viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
290
viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
291
if (b.isContentAreaFilled() || model.isSelected()) {
292
if (model.isSelected()) // Toggle buttons
293
g.setColor(c.getBackground().darker());
294
else g.setColor(c.getBackground());
295
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
296
}
297
}
298
299
// needs focus to be painted
300
// for now we don't know exactly what to do...we'll see!
301
if (b.isFocusPainted() && b.hasFocus()) {
302
// paint UI specific focus
303
paintFocus(g, b, viewRect, textRect, iconRect);
304
}
305
}
306
307
// performs icon and text rect calculations
308
final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
309
310
// Paint the Icon
311
if (b.getIcon() != null) {
312
paintIcon(g, b, iconRect);
313
}
314
315
if (textRect.width == 0) {
316
textRect.width = 50;
317
}
318
319
if (text != null && !text.isEmpty()) {
320
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
321
if (v != null) {
322
v.paint(g, textRect);
323
} else {
324
paintText(g, b, textRect, text);
325
}
326
}
327
}
328
329
protected void paintFocus(Graphics g, AbstractButton b,
330
Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
331
Graphics2D g2d = null;
332
Stroke oldStroke = null;
333
Object oldAntialiasingHint = null;
334
Color oldColor = g.getColor();
335
if (g instanceof Graphics2D) {
336
g2d = (Graphics2D)g;
337
oldStroke = g2d.getStroke();
338
oldAntialiasingHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
339
g2d.setStroke(new BasicStroke(3));
340
g2d.setRenderingHint(
341
RenderingHints.KEY_ANTIALIASING,
342
RenderingHints.VALUE_ANTIALIAS_ON);
343
344
}
345
Color ringColor = UIManager.getColor("Focus.color");
346
g.setColor(ringColor);
347
g.drawRoundRect(5, 3, b.getWidth() - 10, b.getHeight() - 7, 15, 15);
348
if (g2d != null) {
349
// Restore old state of Java2D renderer
350
g2d.setStroke(oldStroke);
351
g2d.setRenderingHint(
352
RenderingHints.KEY_ANTIALIASING,
353
oldAntialiasingHint);
354
}
355
g.setColor(oldColor);
356
}
357
358
protected String layoutAndGetText(final Graphics g, final AbstractButton b, final AquaButtonBorder aquaBorder, final Insets i, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
359
// re-initialize the view rect to the selected insets
360
viewRect.x = i.left;
361
viewRect.y = i.top;
362
viewRect.width = b.getWidth() - (i.right + viewRect.x);
363
viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
364
365
// reset the text and icon rects
366
textRect.x = textRect.y = textRect.width = textRect.height = 0;
367
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
368
369
// setup the font
370
g.setFont(b.getFont());
371
final FontMetrics fm = g.getFontMetrics();
372
373
// layout the text and icon
374
final String originalText = b.getText();
375
final String text = SwingUtilities.layoutCompoundLabel(b, fm, originalText, b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, originalText == null ? 0 : b.getIconTextGap());
376
if (text == originalText || aquaBorder == null) return text; // everything fits
377
378
// if the text didn't fit - check if the aqua border has alternate Insets that are more adhering
379
final Insets alternateContentInsets = aquaBorder.getContentInsets(b, b.getWidth(), b.getHeight());
380
if (alternateContentInsets != null) {
381
// recursively call and don't pass AquaBorder
382
return layoutAndGetText(g, b, null, alternateContentInsets, viewRect, iconRect, textRect);
383
}
384
385
// there is no Aqua border, go with what we've got
386
return text;
387
}
388
389
protected void paintIcon(final Graphics g, final AbstractButton b, final Rectangle localIconRect) {
390
final ButtonModel model = b.getModel();
391
Icon icon = b.getIcon();
392
Icon tmpIcon = null;
393
394
if (icon == null) return;
395
396
if (!model.isEnabled()) {
397
if (model.isSelected()) {
398
tmpIcon = b.getDisabledSelectedIcon();
399
} else {
400
tmpIcon = b.getDisabledIcon();
401
}
402
} else if (model.isPressed() && model.isArmed()) {
403
tmpIcon = b.getPressedIcon();
404
if (tmpIcon == null) {
405
if (icon instanceof ImageIcon) {
406
tmpIcon = new ImageIcon(AquaUtils.generateSelectedDarkImage(((ImageIcon)icon).getImage()));
407
}
408
}
409
} else if (b.isRolloverEnabled() && model.isRollover()) {
410
if (model.isSelected()) {
411
tmpIcon = b.getRolloverSelectedIcon();
412
} else {
413
tmpIcon = b.getRolloverIcon();
414
}
415
} else if (model.isSelected()) {
416
tmpIcon = b.getSelectedIcon();
417
}
418
419
if (model.isEnabled() && b.isFocusOwner() && b.getBorder() instanceof AquaButtonBorder.Toolbar) {
420
if (tmpIcon == null) tmpIcon = icon;
421
if (tmpIcon instanceof ImageIcon) {
422
tmpIcon = AquaFocus.createFocusedIcon(tmpIcon, b, 3);
423
tmpIcon.paintIcon(b, g, localIconRect.x - 3, localIconRect.y - 3);
424
return;
425
}
426
}
427
428
if (tmpIcon != null) {
429
icon = tmpIcon;
430
}
431
432
icon.paintIcon(b, g, localIconRect.x, localIconRect.y);
433
}
434
435
/**
436
* As of Java 2 platform v 1.4 this method should not be used or overriden.
437
* Use the paintText method which takes the AbstractButton argument.
438
*/
439
protected void paintText(final Graphics g, final JComponent c, final Rectangle localTextRect, final String text) {
440
final Graphics2D g2d = g instanceof Graphics2D ? (Graphics2D)g : null;
441
442
final AbstractButton b = (AbstractButton)c;
443
final ButtonModel model = b.getModel();
444
final FontMetrics fm = g.getFontMetrics();
445
final int mnemonicIndex = AquaMnemonicHandler.isMnemonicHidden() ? -1 : b.getDisplayedMnemonicIndex();
446
447
/* Draw the Text */
448
if (model.isEnabled()) {
449
/*** paint the text normally */
450
g.setColor(b.getForeground());
451
} else {
452
/*** paint the text disabled ***/
453
g.setColor(defaultDisabledTextColor);
454
}
455
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, localTextRect.x, localTextRect.y + fm.getAscent());
456
}
457
458
protected void paintText(final Graphics g, final AbstractButton b, final Rectangle localTextRect, final String text) {
459
paintText(g, (JComponent)b, localTextRect, text);
460
}
461
462
protected void paintButtonPressed(final Graphics g, final AbstractButton b) {
463
paint(g, b);
464
}
465
466
// Layout Methods
467
public Dimension getMinimumSize(final JComponent c) {
468
final Dimension d = getPreferredSize(c);
469
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
470
if (v != null) {
471
d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
472
}
473
return d;
474
}
475
476
public Dimension getPreferredSize(final JComponent c) {
477
final AbstractButton b = (AbstractButton)c;
478
479
// fix for Radar #3134273
480
final Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
481
if (d == null) return null;
482
483
final Border border = b.getBorder();
484
if (border instanceof AquaButtonBorder) {
485
((AquaButtonBorder)border).alterPreferredSize(d);
486
}
487
488
return d;
489
}
490
491
public Dimension getMaximumSize(final JComponent c) {
492
final Dimension d = getPreferredSize(c);
493
494
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
495
if (v != null) {
496
d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
497
}
498
499
return d;
500
}
501
502
private static final RecyclableSingleton<AquaHierarchyButtonListener> fHierListener = new RecyclableSingletonFromDefaultConstructor<AquaHierarchyButtonListener>(AquaHierarchyButtonListener.class);
503
static AquaHierarchyButtonListener getAquaHierarchyButtonListener() {
504
return fHierListener.get();
505
}
506
507
// We need to know when ordinary JButtons are put on JToolbars, but not JComboBoxButtons
508
// JToggleButtons always have the same border
509
510
private boolean shouldInstallHierListener(final AbstractButton b) {
511
return (b instanceof JButton || b instanceof JToggleButton && !(b instanceof AquaComboBoxButton) && !(b instanceof JCheckBox) && !(b instanceof JRadioButton));
512
}
513
514
protected void installHierListener(final AbstractButton b) {
515
if (shouldInstallHierListener(b)) {
516
// super put the listener in the button's client properties
517
b.addHierarchyListener(getAquaHierarchyButtonListener());
518
}
519
}
520
521
protected void uninstallHierListener(final AbstractButton b) {
522
if (shouldInstallHierListener(b)) {
523
b.removeHierarchyListener(getAquaHierarchyButtonListener());
524
}
525
}
526
527
static class AquaHierarchyButtonListener implements HierarchyListener {
528
// Everytime a hierarchy is change we need to check if the button if moved on or from
529
// a toolbar. If that is the case, we need to re-set the border of the button.
530
public void hierarchyChanged(final HierarchyEvent e) {
531
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0) return;
532
533
final Object o = e.getSource();
534
if (!(o instanceof AbstractButton)) return;
535
536
final AbstractButton b = (AbstractButton)o;
537
final ButtonUI ui = b.getUI();
538
if (!(ui instanceof AquaButtonUI)) return;
539
540
if (!(b.getBorder() instanceof UIResource)) return; // if the border is not one of ours, or null
541
((AquaButtonUI)ui).setThemeBorder(b);
542
}
543
}
544
545
class AquaButtonListener extends BasicButtonListener implements AncestorListener {
546
protected final AbstractButton b;
547
548
public AquaButtonListener(final AbstractButton b) {
549
super(b);
550
this.b = b;
551
}
552
553
public void focusGained(final FocusEvent e) {
554
((Component)e.getSource()).repaint();
555
}
556
557
public void focusLost(final FocusEvent e) {
558
// 10-06-03 VL: [Radar 3187049]
559
// If focusLost arrives while the button has been left-clicked this would disarm the button,
560
// causing actionPerformed not to fire on mouse release!
561
//b.getModel().setArmed(false);
562
b.getModel().setPressed(false);
563
((Component)e.getSource()).repaint();
564
}
565
566
public void propertyChange(final PropertyChangeEvent e) {
567
super.propertyChange(e);
568
569
final String propertyName = e.getPropertyName();
570
571
// Repaint the button, since its border needs to handle the new state.
572
if (AquaFocusHandler.FRAME_ACTIVE_PROPERTY.equals(propertyName)) {
573
b.repaint();
574
return;
575
}
576
577
if ("icon".equals(propertyName) || "text".equals(propertyName)) {
578
setThemeBorder(b);
579
return;
580
}
581
582
if (BUTTON_TYPE.equals(propertyName)) {
583
// Forced border types
584
final String value = (String)e.getNewValue();
585
586
final Border border = AquaButtonExtendedTypes.getBorderForPosition(b, value, b.getClientProperty(SEGMENTED_BUTTON_POSITION));
587
if (border != null) {
588
b.setBorder(border);
589
}
590
591
return;
592
}
593
594
if (SEGMENTED_BUTTON_POSITION.equals(propertyName)) {
595
final Border border = b.getBorder();
596
if (!(border instanceof AquaBorder)) return;
597
598
b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), e.getNewValue()));
599
}
600
601
if ("componentOrientation".equals(propertyName)) {
602
final Border border = b.getBorder();
603
if (!(border instanceof AquaBorder)) return;
604
605
Object buttonType = b.getClientProperty(BUTTON_TYPE);
606
Object buttonPosition = b.getClientProperty(SEGMENTED_BUTTON_POSITION);
607
if (buttonType != null && buttonPosition != null) {
608
b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, buttonType, buttonPosition));
609
}
610
}
611
}
612
613
public void ancestorMoved(final AncestorEvent e) {}
614
615
public void ancestorAdded(final AncestorEvent e) {
616
updateDefaultButton();
617
}
618
619
public void ancestorRemoved(final AncestorEvent e) {
620
updateDefaultButton();
621
}
622
623
protected void updateDefaultButton() {
624
if (!(b instanceof JButton)) return;
625
if (!((JButton)b).isDefaultButton()) return;
626
627
final JRootPane rootPane = b.getRootPane();
628
if (rootPane == null) return;
629
630
final RootPaneUI ui = rootPane.getUI();
631
if (!(ui instanceof AquaRootPaneUI)) return;
632
((AquaRootPaneUI)ui).updateDefaultButton(rootPane);
633
}
634
}
635
}
636
637