Added theme support for ContextMenu

This commit is contained in:
delvh 2020-03-23 21:35:55 +01:00
parent ec341e8518
commit 3e48d58628

View File

@ -10,6 +10,7 @@ import java.util.Map;
import javax.swing.*; import javax.swing.*;
import envoy.client.data.Settings;
import envoy.client.ui.Theme; import envoy.client.ui.Theme;
/** /**
@ -60,7 +61,10 @@ public class ContextMenu extends JPopupMenu {
* {@link ContextMenu} * {@link ContextMenu}
* @since Envoy v0.1-beta * @since Envoy v0.1-beta
*/ */
public ContextMenu(Component parent) { setInvoker(parent); } public ContextMenu(Component parent) {
setInvoker(parent);
setOpaque(true);
}
/** /**
* @param label the string that a UI may use to display as a title * @param label the string that a UI may use to display as a title
@ -80,13 +84,23 @@ public class ContextMenu extends JPopupMenu {
*/ */
public ContextMenu(String label, Component parent, Map<String, ActionListener> itemsWithActions, Map<String, Icon> itemIcons, public ContextMenu(String label, Component parent, Map<String, ActionListener> itemsWithActions, Map<String, Icon> itemIcons,
Map<String, Integer> itemMnemonics) { Map<String, Integer> itemMnemonics) {
super(label); this(label);
setInvoker(parent); setInvoker(parent);
this.items = (itemsWithActions != null) ? itemsWithActions : items; this.items = (itemsWithActions != null) ? itemsWithActions : items;
this.icons = (itemIcons != null) ? itemIcons : icons; this.icons = (itemIcons != null) ? itemIcons : icons;
this.mnemonics = (itemMnemonics != null) ? itemMnemonics : mnemonics; this.mnemonics = (itemMnemonics != null) ? itemMnemonics : mnemonics;
} }
/**
* @param label the string that a UI may use to display as a title for the
* pop-up menu.
* @since Envoy v0.1-beta
*/
public ContextMenu(String label) {
super(label);
setOpaque(true);
}
/** /**
* Prepares the PopupMenu to be displayed. Should only be used once all map * Prepares the PopupMenu to be displayed. Should only be used once all map
* values have been set. * values have been set.
@ -110,21 +124,16 @@ public class ContextMenu extends JPopupMenu {
else // normal JMenuItem wanted else // normal JMenuItem wanted
item = new JMenuItem(text, icons.containsKey(text) ? icons.get(text) : null); item = new JMenuItem(text, icons.containsKey(text) ? icons.get(text) : null);
item.addActionListener(action); item.addActionListener(action);
item.setOpaque(true);
if (mnemonics.containsKey(text)) item.setMnemonic(mnemonics.get(text)); if (mnemonics.containsKey(text)) item.setMnemonic(mnemonics.get(text));
add(item); add(item);
}); });
getInvoker().addMouseListener(getShowingListener()); getInvoker().addMouseListener(getShowingListener());
applyTheme(Settings.getInstance().getCurrentTheme());
built = true; built = true;
return this; return this;
} }
/**
* @param label the string that a UI may use to display as a title for the
* pop-up menu.
* @since Envoy v0.1-beta
*/
public ContextMenu(String label) { super(label); }
private MouseAdapter getShowingListener() { private MouseAdapter getShowingListener() {
return new MouseAdapter() { return new MouseAdapter() {
@ -240,7 +249,7 @@ public class ContextMenu extends JPopupMenu {
* @since Envoy v0.1-beta * @since Envoy v0.1-beta
*/ */
protected void applyTheme(Theme theme) { protected void applyTheme(Theme theme) {
setBackground(theme.getInteractableBackgroundColor()); setBackground(theme.getCellColor());
setForeground(theme.getTextColor()); setForeground(theme.getTextColor());
} }
} }