@Override
 public void removeNotify() {
   super.removeNotify();
   Toolkit.getDefaultToolkit().removeAWTEventListener(this);
   if (myJBPopup != null) {
     getUI().setPopupVisible(this, false);
     myJBPopup.cancel();
   }
 }
  @Override
  public void setPopupVisible(boolean visible) {
    if (!isSwingPopup()) {
      if (visible && (myJBPopup == null || myJBPopup.isDisposed())) {
        final JBList list = createJBList(getModel());
        myJBPopup =
            JBPopupFactory.getInstance()
                .createListPopupBuilder(list)
                .setItemChoosenCallback(
                    new Runnable() {
                      @Override
                      public void run() {
                        final Object value = list.getSelectedValue();
                        if (value != null) {
                          configureEditor(getEditor(), value);
                          IdeFocusManager.getGlobalInstance().requestFocus(ComboBox.this, true);
                          assert myJBPopup != null;
                          ComboBox.this.getUI().setPopupVisible(ComboBox.this, false);
                          myJBPopup.cancel();
                        }
                      }
                    })
                .setFocusOwners(new Component[] {this})
                .setMinSize(new Dimension(getWidth(), -1))
                .createPopup();
        list.setBorder(IdeBorderFactory.createEmptyBorder());
        myJBPopup.showUnderneathOf(this);
        list.addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusLost(FocusEvent e) {
                ComboBox.this.getUI().setPopupVisible(ComboBox.this, false);
                myJBPopup.cancel();
              }
            });
      }
      return;
    }

    if (getModel().getSize() == 0 && visible) return;
    if (visible && JBPopupFactory.getInstance().getChildFocusedPopup(this) != null) return;

    final boolean wasShown = isPopupVisible();
    super.setPopupVisible(visible);
    if (!wasShown
        && visible
        && isEditable()
        && !UIManager.getBoolean("ComboBox.isEnterSelectablePopup")) {

      final ComboBoxEditor editor = getEditor();
      final Object item = editor.getItem();
      final Object selectedItem = getSelectedItem();
      if (isSwingPopup() && (item == null || item != selectedItem)) {
        configureEditor(editor, selectedItem);
      }
    }
  }
  public final void setEditor(final ComboBoxEditor editor) {
    ComboBoxEditor _editor = editor;
    if (SystemInfo.isMac && (UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderIntelliJLaF())) {
      if (editor instanceof UIResource) {
        _editor = new FixedComboBoxEditor();
      }
    }

    super.setEditor(new MyEditor(this, _editor));
  }
  @Override
  public void addNotify() {
    super.addNotify();

    if (getParent() instanceof JTable) {
      putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    }

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.WINDOW_EVENT_MASK);
  }
 @Override
 public void paint(Graphics g) {
   try {
     myPaintingNow = true;
     super.paint(g);
     if (Boolean.TRUE != getClientProperty("JComboBox.isTableCellEditor") && isEditable)
       MacUIUtil.drawComboboxFocusRing(this, g);
   } finally {
     myPaintingNow = false;
   }
 }
Beispiel #6
0
  public final void setEditor(final ComboBoxEditor editor) {
    ComboBoxEditor _editor = editor;
    if (SystemInfo.isMac && (UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderIntelliJLaF())) {
      if ("AquaComboBoxEditor".equals(editor.getClass().getSimpleName())
          || UIUtil.isUnderIntelliJLaF()) {
        _editor = new FixedComboBoxEditor();
      }
    }

    super.setEditor(new MyEditor(this, _editor));
  }
Beispiel #7
0
 @Override
 public void eventDispatched(AWTEvent event) {
   if (event.getID() == WindowEvent.WINDOW_OPENED) {
     final WindowEvent we = (WindowEvent) event;
     for (JBPopup each : JBPopupFactory.getInstance().getChildPopups(this)) {
       if (each.getContent() != null
           && SwingUtilities.isDescendingFrom(each.getContent(), we.getWindow())) {
         super.setPopupVisible(false);
       }
     }
   }
 }