Browse Source

Ensure non-opaque popups can be closed using the associated keyboard shortcut.

pull/214/head
weisj 4 years ago
parent
commit
194171ac98
  1. 10
      core/src/main/java/com/github/weisj/darklaf/components/tabframe/PopupContainer.java
  2. 19
      core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java

10
core/src/main/java/com/github/weisj/darklaf/components/tabframe/PopupContainer.java

@ -40,12 +40,22 @@ public class PopupContainer extends JPanel {
super.setBorder(null);
}
public Component getPopup() {
return popup;
}
public void setPopup(final Component component) {
removeAll();
if (component instanceof JComponent) {
JComponent c = (JComponent) component;
setActionMap(c.getActionMap());
setInputMap(JComponent.WHEN_FOCUSED, c.getInputMap(JComponent.WHEN_FOCUSED));
setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
c.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW));
}
add(component, BorderLayout.CENTER);
this.popup = component;
revalidate();

19
core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java

@ -33,7 +33,10 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.components.border.MutableLineBorder;
import com.github.weisj.darklaf.components.tabframe.*;
import com.github.weisj.darklaf.components.tabframe.JTabFrame;
import com.github.weisj.darklaf.components.tabframe.PanelPopup;
import com.github.weisj.darklaf.components.tabframe.TabFramePopup;
import com.github.weisj.darklaf.components.tabframe.TabFramePopupUI;
import com.github.weisj.darklaf.components.uiresource.JLabelUIResource;
import com.github.weisj.darklaf.ui.button.DarkButtonUI;
import com.github.weisj.darklaf.ui.panel.DarkPanelUI;
@ -54,7 +57,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
protected Color headerBackground;
protected Color headerButtonHoverBackground;
protected Color headerButtonClickBackground;
protected String accelerator;
protected KeyStroke closeAccelerator;
private PanelPopup popupComponent;
private JPanel header;
private MutableLineBorder headerBorder;
@ -82,10 +85,9 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
headerFocusBackground = UIManager.getColor("TabFramePopup.headerFocusBackground");
headerButtonFocusHoverBackground = UIManager.getColor("TabFramePopup.headerButtonFocusHoverBackground");
headerButtonFocusClickBackground = UIManager.getColor("TabFramePopup.headerButtonFocusClickBackground");
accelerator = UIManager.getString("TabFramePopup.closeAccelerator");
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(accelerator), accelerator);
popupComponent.getActionMap().put(accelerator, closeAction);
closeAccelerator = KeyStroke.getKeyStroke(UIManager.getString("TabFramePopup.closeAccelerator"));
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(closeAccelerator, "close");
popupComponent.getActionMap().put("close", closeAction);
popupComponent.setLayout(new BorderLayout());
}
@ -173,9 +175,8 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
uninstallComponents();
uninstallListeners();
popupComponent.removeAll();
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.remove(KeyStroke.getKeyStroke(accelerator));
popupComponent.getActionMap().remove(accelerator);
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(closeAccelerator);
popupComponent.getActionMap().remove("close");
popupComponent = null;
}

Loading…
Cancel
Save