Added theme support for ContextMenu

This commit is contained in:
delvh 2020-03-23 21:35:55 +01:00
parent 31f9d5bcef
commit 3dd9884cd9
1 changed files with 19 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import java.util.Map;
import javax.swing.*;
import envoy.client.data.Settings;
import envoy.client.ui.Theme;
/**
@ -60,7 +61,10 @@ public class ContextMenu extends JPopupMenu {
* {@link ContextMenu}
* @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
@ -80,13 +84,23 @@ public class ContextMenu extends JPopupMenu {
*/
public ContextMenu(String label, Component parent, Map<String, ActionListener> itemsWithActions, Map<String, Icon> itemIcons,
Map<String, Integer> itemMnemonics) {
super(label);
this(label);
setInvoker(parent);
this.items = (itemsWithActions != null) ? itemsWithActions : items;
this.icons = (itemIcons != null) ? itemIcons : icons;
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
* values have been set.
@ -110,21 +124,16 @@ public class ContextMenu extends JPopupMenu {
else // normal JMenuItem wanted
item = new JMenuItem(text, icons.containsKey(text) ? icons.get(text) : null);
item.addActionListener(action);
item.setOpaque(true);
if (mnemonics.containsKey(text)) item.setMnemonic(mnemonics.get(text));
add(item);
});
getInvoker().addMouseListener(getShowingListener());
applyTheme(Settings.getInstance().getCurrentTheme());
built = true;
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() {
return new MouseAdapter() {
@ -240,7 +249,7 @@ public class ContextMenu extends JPopupMenu {
* @since Envoy v0.1-beta
*/
protected void applyTheme(Theme theme) {
setBackground(theme.getInteractableBackgroundColor());
setBackground(theme.getCellColor());
setForeground(theme.getTextColor());
}
}