package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.Objects;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;

// http://docs.oracle.com/javase/7/docs/api/javax/swing/plaf/multi/doc-files/multi_tsc.html
//???: Don't extend visual look and feels.
public class AuxiliaryWindowsComboBoxUI extends WindowsComboBoxUI {
    public static ComponentUI createUI(JComponent c) {
        return new AuxiliaryWindowsComboBoxUI();
    }
    @Override protected ComboPopup createPopup() {
        //System.out.println("AuxiliaryWindowsComboBoxUI#createPopup");
        return new BasicComboPopup2(comboBox);
    }
//     //???: Use the installUI method to perform all initialization, and the uninstallUI method to perform all cleanup.
//     @Override public void installUI(JComponent c) {
//         //super.installUI(c);
//     }
//     @Override public void uninstallUI(JComponent c) {
//         //super.uninstallUI(c);
//     }
    //Override all UI-specific methods your UI classes inherit.
    @Override protected void configureEditor()   { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override protected void unconfigureEditor() { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override public void removeEditor()         { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override public void addEditor() {
        removeEditor();
        ComboBoxEditor cbe = comboBox.getEditor();
        if (Objects.nonNull(cbe)) {
            editor = cbe.getEditorComponent();
            if (Objects.nonNull(editor)) {
                configureEditor();
                comboBox.add(editor);
                if (comboBox.isFocusOwner()) {
                    // Switch focus to the editor component
                    editor.requestFocusInWindow();
                }
            }
        }
    }
//     @Override public void unconfigureArrowButton() {}
//     @Override public void configureArrowButton() {}
    @Override public void update(Graphics g, JComponent c) { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override public void paint(Graphics g, JComponent c)  { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)           { /* Override all UI-specific methods your UI classes inherit. */ }
    @Override public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) { /* Override all UI-specific methods your UI classes inherit. */ }
}

class BasicComboPopup2 extends BasicComboPopup {
    private transient Handler2 handler2;
    protected BasicComboPopup2(JComboBox combo) {
        super(combo);
    }
    @Override public void uninstallingUI() {
        super.uninstallingUI();
        handler2 = null;
    }
    @Override protected MouseListener createListMouseListener() {
        if (Objects.isNull(handler2)) {
            handler2 = new Handler2();
        }
        return handler2;
    }
    private class Handler2 extends MouseAdapter {
        @Override public void mouseReleased(MouseEvent e) {
            if (Objects.equals(e.getSource(), list)) {
                if (list.getModel().getSize() > 0) {
                    // <ins>
                    if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled()) {
                        return;
                    }
                    // </ins>
                    // JList mouse listener
                    if (comboBox.getSelectedIndex() == list.getSelectedIndex()) {
                        comboBox.getEditor().setItem(list.getSelectedValue());
                    }
                    comboBox.setSelectedIndex(list.getSelectedIndex());
                }
                comboBox.setPopupVisible(false);
                // workaround for cancelling an edited item (bug 4530953)
                if (comboBox.isEditable() && Objects.nonNull(comboBox.getEditor())) {
                    comboBox.configureEditor(comboBox.getEditor(), comboBox.getSelectedItem());
                }
            }
        }
    }
}

@@ -151,23 +151,17 @@
 va.util.
-Objects
+*
 ;%0Aimport
@@ -1594,84 +1594,66 @@
     
-ComboBoxEditor cbe = comboBox.getEditor();%0A        if (Objects.nonNull
+Optional.ofNullable(comboBox.getEditor()).ifPresent
 (cbe
-))
+ -%3E
  %7B%0A 
@@ -1714,36 +1714,51 @@
     
-if (Objects.nonNull(editor))
+Optional.ofNullable(editor).ifPresent(ec -%3E
  %7B%0A 
@@ -1821,21 +1821,17 @@
 ox.add(e
-ditor
+c
 );%0A     
@@ -1953,21 +1953,17 @@
        e
-ditor
+c
 .request
@@ -2002,32 +2002,34 @@
  %7D%0A            %7D
+);
 %0A        %7D%0A    %7D
@@ -2018,24 +2018,26 @@
 );%0A        %7D
+);
 %0A    %7D%0A//   
@@ -3078,24 +3078,27 @@
 istener() %7B%0A
+// 
         if (
@@ -3121,24 +3121,27 @@
 andler2)) %7B%0A
+// 
             
@@ -3163,24 +3163,27 @@
 Handler2();%0A
+// 
         %7D%0A  
@@ -3172,32 +3172,107 @@
 );%0A//         %7D%0A
+        handler2 = Optional.ofNullable(handler2).orElseGet(Handler2::new);%0A
         return h

use Optional#ifPresent(...) instead of if (Objects.nonNull(o)) {...}