add(button);
}
private void showPopupMenu(MouseEvent e) {
JPopupMenu menu = new JPopupMenu();
String label = mLocalizer.ellipsisMsg("configure", "Configure");
String name = null;
boolean configItemEnabled = false;
if (e.getSource() instanceof AbstractButton) {
name = ((AbstractButton) e.getSource()).getName();
if (name.startsWith("#scrollTo") && name.indexOf("Channel") == -1) {
configItemEnabled = true;
label = mLocalizer.ellipsisMsg("configureTime", "Configure time buttons");
}
else if(name.startsWith("#filter")) {
configItemEnabled = true;
label = FilterButtons.mLocalizer.ellipsisMsg("createFilter", "Create filter");
}
else if(name.startsWith("#scrollToChannel")) {
configItemEnabled = true;
label = ChannelContextMenu.mLocalizer.ellipsisMsg("addChannels", "Add/Remove channels");
}
else if (name.indexOf("##") != -1) {
PluginProxy plugin = PluginProxyManager.getInstance().getActivatedPluginForId(name.substring(0,name.indexOf("##")));
configItemEnabled = plugin != null && plugin.getSettingsTab() != null;
}
else if (PluginProxyManager.getInstance().getActivatedPluginForId(name) != null) {
configItemEnabled = PluginProxyManager.getInstance().getActivatedPluginForId(name).getSettingsTab() != null;
}
else if (InternalPluginProxyList.getInstance().getProxyForId(name) != null) {
configItemEnabled = InternalPluginProxyList.getInstance().getProxyForId(name).getSettingsTab() != null;
name = InternalPluginProxyList.getInstance().getProxyForId(name).getSettingsId();
}
} else {
return;
}
JMenuItem item = new JMenuItem(label);
item.setActionCommand(name);
item.setEnabled(configItemEnabled);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().startsWith("#scrollTo") && e.getActionCommand().indexOf("Channel") == -1) {
MainFrame.getInstance().showSettingsDialog("#timebuttons");
} else if (e.getActionCommand().startsWith("#filter")) {
MainFrame.getInstance().showFilterDialog();
} else if (e.getActionCommand().startsWith("#scrollToChannel")) {
MainFrame.getInstance().showSettingsDialog(SettingsItem.CHANNELS);
} else if (e.getActionCommand().indexOf("##") != -1){
MainFrame.getInstance().showSettingsDialog(e.getActionCommand().substring(0,e.getActionCommand().indexOf("##")));
} else {
MainFrame.getInstance().showSettingsDialog(e.getActionCommand());
}
}
});
menu.add(item);
menu.addSeparator();
item = new JMenuItem(mLocalizer.msg("removeButton", "Remove button"));
final String buttonName = name;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Action[] actions = mModel.getActions();
ArrayList<String> idList = new ArrayList<String>();
for(Action a : actions) {
String key = (String)a.getValue(ACTION_ID_KEY);
String test = key;
if (test.equals("searchplugin.SearchPlugin") && buttonName.equals("#search")) {
test = "#search";
} else if (test.equals("reminderplugin.ReminderPlugin") && buttonName.equals("#reminder")) {
test = "#reminder";
} else if (test.equals("favoritesplugin.FavoritesPlugin") && buttonName.equals("#favorite")) {
test = "#favorite";
}
if (test.compareTo(buttonName) != 0) {
idList.add(key);
}
}
String[] ids = new String[idList.size()];
idList.toArray(ids);
DefaultToolBarModel.getInstance().setButtonIds(ids);
MainFrame.getInstance().updateToolbar();
Settings.propToolbarButtons.setStringArray(ids);
}
});
menu.add(item);
menu.add(ContextMenu.getSubMenu());
menu.show(e.getComponent(), e.getX(), e.getY());
}