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); super.setBorder(null);
} }
public Component getPopup() { public Component getPopup() {
return popup; return popup;
} }
public void setPopup(final Component component) { public void setPopup(final Component component) {
removeAll(); 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); add(component, BorderLayout.CENTER);
this.popup = component; this.popup = component;
revalidate(); 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 javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.components.border.MutableLineBorder; 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.components.uiresource.JLabelUIResource;
import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.ui.button.DarkButtonUI;
import com.github.weisj.darklaf.ui.panel.DarkPanelUI; import com.github.weisj.darklaf.ui.panel.DarkPanelUI;
@ -54,7 +57,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
protected Color headerBackground; protected Color headerBackground;
protected Color headerButtonHoverBackground; protected Color headerButtonHoverBackground;
protected Color headerButtonClickBackground; protected Color headerButtonClickBackground;
protected String accelerator; protected KeyStroke closeAccelerator;
private PanelPopup popupComponent; private PanelPopup popupComponent;
private JPanel header; private JPanel header;
private MutableLineBorder headerBorder; private MutableLineBorder headerBorder;
@ -82,10 +85,9 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
headerFocusBackground = UIManager.getColor("TabFramePopup.headerFocusBackground"); headerFocusBackground = UIManager.getColor("TabFramePopup.headerFocusBackground");
headerButtonFocusHoverBackground = UIManager.getColor("TabFramePopup.headerButtonFocusHoverBackground"); headerButtonFocusHoverBackground = UIManager.getColor("TabFramePopup.headerButtonFocusHoverBackground");
headerButtonFocusClickBackground = UIManager.getColor("TabFramePopup.headerButtonFocusClickBackground"); headerButtonFocusClickBackground = UIManager.getColor("TabFramePopup.headerButtonFocusClickBackground");
accelerator = UIManager.getString("TabFramePopup.closeAccelerator"); closeAccelerator = KeyStroke.getKeyStroke(UIManager.getString("TabFramePopup.closeAccelerator"));
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(closeAccelerator, "close");
.put(KeyStroke.getKeyStroke(accelerator), accelerator); popupComponent.getActionMap().put("close", closeAction);
popupComponent.getActionMap().put(accelerator, closeAction);
popupComponent.setLayout(new BorderLayout()); popupComponent.setLayout(new BorderLayout());
} }
@ -173,9 +175,8 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe
uninstallComponents(); uninstallComponents();
uninstallListeners(); uninstallListeners();
popupComponent.removeAll(); popupComponent.removeAll();
popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) popupComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(closeAccelerator);
.remove(KeyStroke.getKeyStroke(accelerator)); popupComponent.getActionMap().remove("close");
popupComponent.getActionMap().remove(accelerator);
popupComponent = null; popupComponent = null;
} }

Loading…
Cancel
Save