Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/com/apple/laf/AquaComboBoxUI.java
41154 views
1
/*
2
* Copyright (c) 2011, 2020, 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.Color;
29
import java.awt.Container;
30
import java.awt.Dimension;
31
import java.awt.Graphics;
32
import java.awt.Insets;
33
import java.awt.LayoutManager;
34
import java.awt.Rectangle;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.FocusEvent;
37
import java.awt.event.FocusListener;
38
import java.awt.event.ItemEvent;
39
import java.awt.event.ItemListener;
40
import java.awt.event.KeyEvent;
41
42
import javax.accessibility.Accessible;
43
import javax.accessibility.AccessibleContext;
44
import javax.accessibility.AccessibleState;
45
import javax.swing.AbstractAction;
46
import javax.swing.Action;
47
import javax.swing.ActionMap;
48
import javax.swing.ComboBoxEditor;
49
import javax.swing.InputMap;
50
import javax.swing.JButton;
51
import javax.swing.JComboBox;
52
import javax.swing.JComponent;
53
import javax.swing.JList;
54
import javax.swing.JRootPane;
55
import javax.swing.JTextField;
56
import javax.swing.KeyStroke;
57
import javax.swing.ListCellRenderer;
58
import javax.swing.ListModel;
59
import javax.swing.LookAndFeel;
60
import javax.swing.SwingUtilities;
61
import javax.swing.border.Border;
62
import javax.swing.event.DocumentEvent;
63
import javax.swing.event.DocumentListener;
64
import javax.swing.plaf.ActionMapUIResource;
65
import javax.swing.plaf.ComboBoxUI;
66
import javax.swing.plaf.ComponentUI;
67
import javax.swing.plaf.ListUI;
68
import javax.swing.plaf.UIResource;
69
import javax.swing.plaf.basic.BasicComboBoxEditor;
70
import javax.swing.plaf.basic.BasicComboBoxUI;
71
import javax.swing.plaf.basic.ComboPopup;
72
73
import apple.laf.JRSUIConstants.Size;
74
import com.apple.laf.AquaUtilControlSize.Sizeable;
75
import com.apple.laf.AquaUtils.RecyclableSingleton;
76
import com.apple.laf.ClientPropertyApplicator.Property;
77
78
// Inspired by MetalComboBoxUI, which also has a combined text-and-arrow button for noneditables
79
public class AquaComboBoxUI extends BasicComboBoxUI implements Sizeable {
80
static final String POPDOWN_CLIENT_PROPERTY_KEY = "JComboBox.isPopDown";
81
static final String ISSQUARE_CLIENT_PROPERTY_KEY = "JComboBox.isSquare";
82
83
public static ComponentUI createUI(final JComponent c) {
84
return new AquaComboBoxUI();
85
}
86
87
private boolean wasOpaque;
88
public void installUI(final JComponent c) {
89
super.installUI(c);
90
91
// this doesn't work right now, because the JComboBox.init() method calls
92
// .setOpaque(false) directly, and doesn't allow the LaF to decided. Bad Sun!
93
LookAndFeel.installProperty(c, "opaque", Boolean.FALSE);
94
95
wasOpaque = c.isOpaque();
96
c.setOpaque(false);
97
}
98
99
public void uninstallUI(final JComponent c) {
100
c.setOpaque(wasOpaque);
101
super.uninstallUI(c);
102
}
103
104
protected void installListeners() {
105
super.installListeners();
106
AquaUtilControlSize.addSizePropertyListener(comboBox);
107
}
108
109
protected void uninstallListeners() {
110
AquaUtilControlSize.removeSizePropertyListener(comboBox);
111
super.uninstallListeners();
112
}
113
114
protected void installComponents() {
115
super.installComponents();
116
117
// client properties must be applied after the components have been installed,
118
// because isSquare and isPopdown are applied to the installed button
119
getApplicator().attachAndApplyClientProperties(comboBox);
120
}
121
122
protected void uninstallComponents() {
123
getApplicator().removeFrom(comboBox);
124
// AquaButtonUI install some listeners to all parents, which means that
125
// we need to uninstall UI here to remove those listeners, because after
126
// we remove them from ComboBox we lost the latest reference to them,
127
// and our standard uninstallUI machinery will not call them.
128
arrowButton.getUI().uninstallUI(arrowButton);
129
super.uninstallComponents();
130
}
131
132
protected ItemListener createItemListener() {
133
return new ItemListener() {
134
long lastBlink = 0L;
135
public void itemStateChanged(final ItemEvent e) {
136
if (e.getStateChange() != ItemEvent.SELECTED) return;
137
if (!popup.isVisible()) return;
138
139
// sometimes, multiple selection changes can occur while the popup is up,
140
// and blinking more than "once" (in a second) is not desirable
141
final long now = System.currentTimeMillis();
142
if (now - 1000 < lastBlink) return;
143
lastBlink = now;
144
145
final JList<Object> itemList = popup.getList();
146
final ListUI listUI = itemList.getUI();
147
if (!(listUI instanceof AquaListUI)) return;
148
final AquaListUI aquaListUI = (AquaListUI)listUI;
149
150
final int selectedIndex = comboBox.getSelectedIndex();
151
final ListModel<Object> dataModel = itemList.getModel();
152
if (dataModel == null) return;
153
154
final Object value = dataModel.getElementAt(selectedIndex);
155
AquaUtils.blinkMenu(new AquaUtils.Selectable() {
156
public void paintSelected(final boolean selected) {
157
aquaListUI.repaintCell(value, selectedIndex, selected);
158
}
159
});
160
}
161
};
162
}
163
164
public void paint(final Graphics g, final JComponent c) {
165
// this space intentionally left blank
166
}
167
168
protected ListCellRenderer<Object> createRenderer() {
169
return new AquaComboBoxRenderer(comboBox);
170
}
171
172
protected ComboPopup createPopup() {
173
return new AquaComboBoxPopup(comboBox);
174
}
175
176
protected JButton createArrowButton() {
177
return new AquaComboBoxButton(this, comboBox, currentValuePane, listBox);
178
}
179
180
protected ComboBoxEditor createEditor() {
181
return new AquaComboBoxEditor();
182
}
183
184
final class AquaComboBoxEditor extends BasicComboBoxEditor
185
implements UIResource, DocumentListener {
186
187
AquaComboBoxEditor() {
188
super();
189
editor = new AquaCustomComboTextField();
190
editor.addFocusListener(this);
191
editor.getDocument().addDocumentListener(this);
192
}
193
194
@Override
195
public void changedUpdate(final DocumentEvent e) {
196
editorTextChanged();
197
}
198
199
@Override
200
public void insertUpdate(final DocumentEvent e) {
201
editorTextChanged();
202
}
203
204
@Override
205
public void removeUpdate(final DocumentEvent e) {
206
editorTextChanged();
207
}
208
209
private void editorTextChanged() {
210
if (!popup.isVisible()) return;
211
212
final Object text = editor.getText();
213
214
final ListModel<Object> model = listBox.getModel();
215
final int items = model.getSize();
216
for (int i = 0; i < items; i++) {
217
final Object element = model.getElementAt(i);
218
if (element == null) continue;
219
220
final String asString = element.toString();
221
if (asString == null || !asString.equals(text)) continue;
222
223
popup.getList().setSelectedIndex(i);
224
return;
225
}
226
227
popup.getList().clearSelection();
228
}
229
}
230
231
@SuppressWarnings("serial") // Superclass is not serializable across versions
232
class AquaCustomComboTextField extends JTextField {
233
@SuppressWarnings("serial") // anonymous class
234
public AquaCustomComboTextField() {
235
final InputMap inputMap = getInputMap();
236
inputMap.put(KeyStroke.getKeyStroke("DOWN"), highlightNextAction);
237
inputMap.put(KeyStroke.getKeyStroke("KP_DOWN"), highlightNextAction);
238
inputMap.put(KeyStroke.getKeyStroke("UP"), highlightPreviousAction);
239
inputMap.put(KeyStroke.getKeyStroke("KP_UP"), highlightPreviousAction);
240
241
inputMap.put(KeyStroke.getKeyStroke("HOME"), highlightFirstAction);
242
inputMap.put(KeyStroke.getKeyStroke("END"), highlightLastAction);
243
inputMap.put(KeyStroke.getKeyStroke("PAGE_UP"), highlightPageUpAction);
244
inputMap.put(KeyStroke.getKeyStroke("PAGE_DOWN"), highlightPageDownAction);
245
246
final Action action = getActionMap().get(JTextField.notifyAction);
247
inputMap.put(KeyStroke.getKeyStroke("ENTER"), new AbstractAction() {
248
public void actionPerformed(final ActionEvent e) {
249
if (popup.isVisible()) {
250
triggerSelectionEvent(comboBox, e);
251
252
if (editor instanceof AquaCustomComboTextField) {
253
((AquaCustomComboTextField)editor).selectAll();
254
}
255
} else {
256
action.actionPerformed(e);
257
}
258
}
259
});
260
}
261
262
// workaround for 4530952
263
public void setText(final String s) {
264
if (getText().equals(s)) {
265
return;
266
}
267
super.setText(s);
268
}
269
}
270
271
/**
272
* This listener hides the popup when the focus is lost. It also repaints
273
* when focus is gained or lost.
274
*
275
* This override is necessary because the Basic L&F for the combo box is working
276
* around a Solaris-only bug that we don't have on Mac OS X. So, remove the lightweight
277
* popup check here. rdar://Problem/3518582
278
*/
279
protected FocusListener createFocusListener() {
280
return new BasicComboBoxUI.FocusHandler() {
281
@Override
282
public void focusGained(FocusEvent e) {
283
super.focusGained(e);
284
285
if (arrowButton != null) {
286
arrowButton.repaint();
287
}
288
}
289
290
@Override
291
public void focusLost(final FocusEvent e) {
292
hasFocus = false;
293
if (!e.isTemporary()) {
294
setPopupVisible(comboBox, false);
295
}
296
comboBox.repaint();
297
298
// Notify assistive technologies that the combo box lost focus
299
final AccessibleContext ac = ((Accessible)comboBox).getAccessibleContext();
300
if (ac != null) {
301
ac.firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, AccessibleState.FOCUSED, null);
302
}
303
304
if (arrowButton != null) {
305
arrowButton.repaint();
306
}
307
}
308
};
309
}
310
311
protected void installKeyboardActions() {
312
super.installKeyboardActions();
313
314
ActionMap actionMap = new ActionMapUIResource();
315
316
actionMap.put("aquaSelectNext", highlightNextAction);
317
actionMap.put("aquaSelectPrevious", highlightPreviousAction);
318
actionMap.put("enterPressed", triggerSelectionAction);
319
actionMap.put("aquaSpacePressed", toggleSelectionAction);
320
321
actionMap.put("aquaSelectHome", highlightFirstAction);
322
actionMap.put("aquaSelectEnd", highlightLastAction);
323
actionMap.put("aquaSelectPageUp", highlightPageUpAction);
324
actionMap.put("aquaSelectPageDown", highlightPageDownAction);
325
326
actionMap.put("aquaHidePopup", hideAction);
327
328
SwingUtilities.replaceUIActionMap(comboBox, actionMap);
329
}
330
331
@SuppressWarnings("serial") // Superclass is not serializable across versions
332
private abstract class ComboBoxAction extends AbstractAction {
333
public void actionPerformed(final ActionEvent e) {
334
if (!comboBox.isEnabled() || !comboBox.isShowing()) {
335
return;
336
}
337
338
if (comboBox.isPopupVisible()) {
339
final AquaComboBoxUI ui = (AquaComboBoxUI)comboBox.getUI();
340
performComboBoxAction(ui);
341
} else {
342
comboBox.setPopupVisible(true);
343
}
344
}
345
346
abstract void performComboBoxAction(final AquaComboBoxUI ui);
347
}
348
349
/**
350
* Hilight _but do not select_ the next item in the list.
351
*/
352
@SuppressWarnings("serial") // anonymous class
353
private Action highlightNextAction = new ComboBoxAction() {
354
@Override
355
public void performComboBoxAction(AquaComboBoxUI ui) {
356
final int si = listBox.getSelectedIndex();
357
358
if (si < comboBox.getModel().getSize() - 1) {
359
listBox.setSelectedIndex(si + 1);
360
listBox.ensureIndexIsVisible(si + 1);
361
}
362
comboBox.repaint();
363
}
364
};
365
366
/**
367
* Hilight _but do not select_ the previous item in the list.
368
*/
369
@SuppressWarnings("serial") // anonymous class
370
private Action highlightPreviousAction = new ComboBoxAction() {
371
@Override
372
void performComboBoxAction(final AquaComboBoxUI ui) {
373
final int si = listBox.getSelectedIndex();
374
if (si > 0) {
375
listBox.setSelectedIndex(si - 1);
376
listBox.ensureIndexIsVisible(si - 1);
377
}
378
comboBox.repaint();
379
}
380
};
381
382
@SuppressWarnings("serial") // anonymous class
383
private Action highlightFirstAction = new ComboBoxAction() {
384
@Override
385
void performComboBoxAction(final AquaComboBoxUI ui) {
386
listBox.setSelectedIndex(0);
387
listBox.ensureIndexIsVisible(0);
388
}
389
};
390
391
@SuppressWarnings("serial") // anonymous class
392
private Action highlightLastAction = new ComboBoxAction() {
393
@Override
394
void performComboBoxAction(final AquaComboBoxUI ui) {
395
final int size = listBox.getModel().getSize();
396
listBox.setSelectedIndex(size - 1);
397
listBox.ensureIndexIsVisible(size - 1);
398
}
399
};
400
401
@SuppressWarnings("serial") // anonymous class
402
private Action highlightPageUpAction = new ComboBoxAction() {
403
@Override
404
void performComboBoxAction(final AquaComboBoxUI ui) {
405
final int current = listBox.getSelectedIndex();
406
final int first = listBox.getFirstVisibleIndex();
407
408
if (current != first) {
409
listBox.setSelectedIndex(first);
410
return;
411
}
412
413
final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height;
414
int target = first - page;
415
if (target < 0) target = 0;
416
417
listBox.ensureIndexIsVisible(target);
418
listBox.setSelectedIndex(target);
419
}
420
};
421
422
@SuppressWarnings("serial") // anonymous class
423
private Action highlightPageDownAction = new ComboBoxAction() {
424
@Override
425
void performComboBoxAction(final AquaComboBoxUI ui) {
426
final int current = listBox.getSelectedIndex();
427
final int last = listBox.getLastVisibleIndex();
428
429
if (current != last) {
430
listBox.setSelectedIndex(last);
431
return;
432
}
433
434
final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height;
435
final int end = listBox.getModel().getSize() - 1;
436
int target = last + page;
437
if (target > end) target = end;
438
439
listBox.ensureIndexIsVisible(target);
440
listBox.setSelectedIndex(target);
441
}
442
};
443
444
// For <rdar://problem/3759984> Java 1.4.2_5: Serializing Swing components not working
445
// Inner classes were using a this reference and then trying to serialize the AquaComboBoxUI
446
// We shouldn't do that. But we need to be able to get the popup from other classes, so we need
447
// a public accessor.
448
public ComboPopup getPopup() {
449
return popup;
450
}
451
452
protected LayoutManager createLayoutManager() {
453
return new AquaComboBoxLayoutManager();
454
}
455
456
class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
457
public void layoutContainer(final Container parent) {
458
if (arrowButton != null && !comboBox.isEditable()) {
459
final Insets insets = comboBox.getInsets();
460
final int width = comboBox.getWidth();
461
final int height = comboBox.getHeight();
462
arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom));
463
return;
464
}
465
466
final JComboBox<?> cb = (JComboBox<?>) parent;
467
final int width = cb.getWidth();
468
final int height = cb.getHeight();
469
470
final Insets insets = getInsets();
471
final int buttonHeight = height - (insets.top + insets.bottom);
472
final int buttonWidth = 20;
473
474
if (arrowButton != null) {
475
arrowButton.setBounds(width - (insets.right + buttonWidth), insets.top, buttonWidth, buttonHeight);
476
}
477
478
if (editor != null) {
479
final Rectangle editorRect = rectangleForCurrentValue();
480
editorRect.width += 4;
481
editorRect.height += 1;
482
editor.setBounds(editorRect);
483
}
484
}
485
}
486
487
// This is here because Sun can't use protected like they should!
488
protected static final String IS_TABLE_CELL_EDITOR = "JComboBox.isTableCellEditor";
489
490
protected static boolean isTableCellEditor(final JComponent c) {
491
return Boolean.TRUE.equals(c.getClientProperty(AquaComboBoxUI.IS_TABLE_CELL_EDITOR));
492
}
493
494
protected static boolean isPopdown(final JComboBox<?> c) {
495
return c.isEditable() || Boolean.TRUE.equals(c.getClientProperty(AquaComboBoxUI.POPDOWN_CLIENT_PROPERTY_KEY));
496
}
497
498
protected static void triggerSelectionEvent(final JComboBox<?> comboBox, final ActionEvent e) {
499
if (!comboBox.isEnabled()) return;
500
501
final AquaComboBoxUI aquaUi = (AquaComboBoxUI)comboBox.getUI();
502
503
if (aquaUi.getPopup().getList().getSelectedIndex() < 0) {
504
comboBox.setPopupVisible(false);
505
}
506
507
if (isTableCellEditor(comboBox)) {
508
// Forces the selection of the list item if the combo box is in a JTable
509
comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
510
return;
511
}
512
513
if (comboBox.isPopupVisible()) {
514
comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
515
comboBox.setPopupVisible(false);
516
return;
517
}
518
519
// Call the default button binding.
520
// This is a pretty messy way of passing an event through to the root pane
521
final JRootPane root = SwingUtilities.getRootPane(comboBox);
522
if (root == null) return;
523
524
final InputMap im = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
525
final ActionMap am = root.getActionMap();
526
if (im == null || am == null) return;
527
528
final Object obj = im.get(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
529
if (obj == null) return;
530
531
final Action action = am.get(obj);
532
if (action == null) return;
533
534
action.actionPerformed(new ActionEvent(root, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
535
}
536
537
// This is somewhat messy. The difference here from BasicComboBoxUI.EnterAction is that
538
// arrow up or down does not automatically select the
539
@SuppressWarnings("serial") // anonymous class
540
private final Action triggerSelectionAction = new AbstractAction() {
541
public void actionPerformed(final ActionEvent e) {
542
triggerSelectionEvent((JComboBox)e.getSource(), e);
543
}
544
545
@Override
546
public boolean isEnabled() {
547
return comboBox.isPopupVisible() && super.isEnabled();
548
}
549
};
550
551
@SuppressWarnings("serial") // anonymous class
552
private static final Action toggleSelectionAction = new AbstractAction() {
553
public void actionPerformed(final ActionEvent e) {
554
final JComboBox<?> comboBox = (JComboBox<?>) e.getSource();
555
if (!comboBox.isEnabled()) return;
556
if (comboBox.isEditable()) return;
557
558
final AquaComboBoxUI aquaUi = (AquaComboBoxUI)comboBox.getUI();
559
560
if (comboBox.isPopupVisible()) {
561
comboBox.setSelectedIndex(aquaUi.getPopup().getList().getSelectedIndex());
562
comboBox.setPopupVisible(false);
563
return;
564
}
565
566
comboBox.setPopupVisible(true);
567
}
568
};
569
570
@SuppressWarnings("serial") // anonymous class
571
private final Action hideAction = new AbstractAction() {
572
@Override
573
public void actionPerformed(final ActionEvent e) {
574
final JComboBox<?> comboBox = (JComboBox<?>) e.getSource();
575
comboBox.firePopupMenuCanceled();
576
comboBox.setPopupVisible(false);
577
}
578
579
@Override
580
public boolean isEnabled() {
581
return comboBox.isPopupVisible() && super.isEnabled();
582
}
583
};
584
585
public void applySizeFor(final JComponent c, final Size size) {
586
if (arrowButton == null) return;
587
final Border border = arrowButton.getBorder();
588
if (!(border instanceof AquaButtonBorder)) return;
589
final AquaButtonBorder aquaBorder = (AquaButtonBorder)border;
590
arrowButton.setBorder(aquaBorder.deriveBorderForSize(size));
591
}
592
593
public Dimension getMinimumSize(final JComponent c) {
594
if (!isMinimumSizeDirty) {
595
return new Dimension(cachedMinimumSize);
596
}
597
598
final boolean editable = comboBox.isEditable();
599
600
final Dimension size;
601
if (!editable && arrowButton != null && arrowButton instanceof AquaComboBoxButton) {
602
final AquaComboBoxButton button = (AquaComboBoxButton)arrowButton;
603
final Insets buttonInsets = button.getInsets();
604
// Insets insets = comboBox.getInsets();
605
final Insets insets = new Insets(0, 5, 0, 25);//comboBox.getInsets();
606
607
size = getDisplaySize();
608
size.width += insets.left + insets.right;
609
size.width += buttonInsets.left + buttonInsets.right;
610
size.width += buttonInsets.right + 10;
611
size.height += insets.top + insets.bottom;
612
size.height += buttonInsets.top + buttonInsets.bottom;
613
// Min height = Height of arrow button plus 2 pixels fuzz above plus 2 below. 23 + 2 + 2
614
size.height = Math.max(27, size.height);
615
} else if (editable && arrowButton != null && editor != null) {
616
size = super.getMinimumSize(c);
617
final Insets margin = arrowButton.getMargin();
618
size.height += margin.top + margin.bottom;
619
} else {
620
size = super.getMinimumSize(c);
621
}
622
623
final Border border = c.getBorder();
624
if (border != null) {
625
final Insets insets = border.getBorderInsets(c);
626
size.height += insets.top + insets.bottom;
627
size.width += insets.left + insets.right;
628
}
629
630
cachedMinimumSize.setSize(size.width, size.height);
631
isMinimumSizeDirty = false;
632
633
return new Dimension(cachedMinimumSize);
634
}
635
636
@SuppressWarnings("unchecked")
637
private static final RecyclableSingleton<ClientPropertyApplicator<JComboBox<?>, AquaComboBoxUI>> APPLICATOR = new
638
RecyclableSingleton<ClientPropertyApplicator<JComboBox<?>, AquaComboBoxUI>>() {
639
@Override
640
protected ClientPropertyApplicator<JComboBox<?>, AquaComboBoxUI> getInstance() {
641
return new ClientPropertyApplicator<JComboBox<?>, AquaComboBoxUI>(
642
new Property<AquaComboBoxUI>(AquaFocusHandler.FRAME_ACTIVE_PROPERTY) {
643
public void applyProperty(final AquaComboBoxUI target, final Object value) {
644
if (Boolean.FALSE.equals(value)) {
645
if (target.comboBox != null) target.comboBox.hidePopup();
646
}
647
if (target.listBox != null) target.listBox.repaint();
648
}
649
},
650
new Property<AquaComboBoxUI>("editable") {
651
public void applyProperty(final AquaComboBoxUI target, final Object value) {
652
if (target.comboBox == null) return;
653
target.comboBox.repaint();
654
}
655
},
656
new Property<AquaComboBoxUI>("background") {
657
public void applyProperty(final AquaComboBoxUI target, final Object value) {
658
final Color color = (Color)value;
659
if (target.arrowButton != null) target.arrowButton.setBackground(color);
660
if (target.listBox != null) target.listBox.setBackground(color);
661
}
662
},
663
new Property<AquaComboBoxUI>("foreground") {
664
public void applyProperty(final AquaComboBoxUI target, final Object value) {
665
final Color color = (Color)value;
666
if (target.arrowButton != null) target.arrowButton.setForeground(color);
667
if (target.listBox != null) target.listBox.setForeground(color);
668
}
669
},
670
new Property<AquaComboBoxUI>(POPDOWN_CLIENT_PROPERTY_KEY) {
671
public void applyProperty(final AquaComboBoxUI target, final Object value) {
672
if (!(target.arrowButton instanceof AquaComboBoxButton)) return;
673
((AquaComboBoxButton)target.arrowButton).setIsPopDown(Boolean.TRUE.equals(value));
674
}
675
},
676
new Property<AquaComboBoxUI>(ISSQUARE_CLIENT_PROPERTY_KEY) {
677
public void applyProperty(final AquaComboBoxUI target, final Object value) {
678
if (!(target.arrowButton instanceof AquaComboBoxButton)) return;
679
((AquaComboBoxButton)target.arrowButton).setIsSquare(Boolean.TRUE.equals(value));
680
}
681
}
682
) {
683
public AquaComboBoxUI convertJComponentToTarget(final JComboBox<?> combo) {
684
final ComboBoxUI comboUI = combo.getUI();
685
if (comboUI instanceof AquaComboBoxUI) return (AquaComboBoxUI)comboUI;
686
return null;
687
}
688
};
689
}
690
};
691
static ClientPropertyApplicator<JComboBox<?>, AquaComboBoxUI> getApplicator() {
692
return APPLICATOR.get();
693
}
694
}
695
696