private void updateConflicts() { myConflicts.removeAll(); myConflicts.setBorder(null); if (!myQaEnabled) { return; } if (myModifiers.size() == 0) { myConflicts.setLayout(new BorderLayout()); myConflicts.add(getSmallLabel("Without assigning modifier keys Quick Access will not function"), BorderLayout.NORTH); return; } myConflicts.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 4, 0, 4); boolean hasConflicts = printConflict(c, KeyEvent.VK_UP, QuickAccessSettings.SWITCH_UP); hasConflicts |= printConflict(c, KeyEvent.VK_DOWN, QuickAccessSettings.SWITCH_DOWN); hasConflicts |= printConflict(c, KeyEvent.VK_LEFT, QuickAccessSettings.SWITCH_LEFT); hasConflicts |= printConflict(c, KeyEvent.VK_RIGHT, QuickAccessSettings.SWITCH_RIGHT); hasConflicts |= printConflict(c, KeyEvent.VK_ENTER, QuickAccessSettings.SWITCH_APPLY); if (hasConflicts) { myConflicts.setBorder(IdeBorderFactory.createTitledBorder("Conflicts", true)); c.gridx = 0; c.gridy++; c.gridwidth = 2; myConflicts.add(new SeparatorWithText(), c); c.gridx = 0; c.gridy++; myConflicts.add(getSmallLabel("These conflicting actions may be not what you use a lot"), c); } }
private boolean printConflict(GridBagConstraints c, int actionKey, String actionId) { boolean hasConflicts = false; int mask = myQuickAccessSettings.getModifierMask(myModifiers); KeyboardShortcut sc = new KeyboardShortcut(KeyStroke.getKeyStroke(actionKey, mask), null); Map<String,ArrayList<KeyboardShortcut>> conflictMap = myQuickAccessSettings.getKeymap().getConflicts(actionId, sc); if (conflictMap.size() > 0) { hasConflicts = true; JLabel scText = new JLabel(sc.toString()); c.gridy++; c.gridx = 0; myConflicts.add(scText, c); Iterator<String> actions = conflictMap.keySet().iterator(); while (actions.hasNext()) { String each = actions.next(); AnAction eachAnAction = ActionManager.getInstance().getAction(each); if (eachAnAction != null) { String text = eachAnAction.getTemplatePresentation().getText(); JLabel eachAction = new JLabel(text != null && text.length() > 0 ? text : each); c.gridx = 1; myConflicts.add(eachAction, c); c.gridy++; } } } c.gridx = 0; c.gridwidth = 2; c.gridy++; myConflicts.add(new SeparatorWithText(), c); c.gridwidth = 1; return hasConflicts; }
private boolean printConflict(GridBagConstraints c, int actionKey, String actionId) { boolean hasConflicts = false; int mask = myQuickAccessSettings.getModiferMask(myModifiers); KeyboardShortcut sc = new KeyboardShortcut(KeyStroke.getKeyStroke(actionKey, mask), null); Map<String,ArrayList<KeyboardShortcut>> conflictMap = myQuickAccessSettings.getKeymap().getConflicts(actionId, sc); if (conflictMap.size() > 0) { hasConflicts = true; JLabel scText = new JLabel(sc.toString()); c.gridy++; c.gridx = 0; myConflicts.add(scText, c); Iterator<String> actions = conflictMap.keySet().iterator(); while (actions.hasNext()) { String each = actions.next(); AnAction eachAnAction = ActionManager.getInstance().getAction(each); if (eachAnAction != null) { String text = eachAnAction.getTemplatePresentation().getText(); JLabel eachAction = new JLabel(text != null && text.length() > 0 ? text : each); c.gridx = 1; myConflicts.add(eachAction, c); c.gridy++; } } } c.gridx = 0; c.gridwidth = 2; c.gridy++; myConflicts.add(new SeparatorWithText(), c); c.gridwidth = 1; return hasConflicts; }
private void createUIComponents() { myList = new CheckBoxList<GutterIconDescriptor>() { @Override protected JComponent adjustRendering(JComponent rootComponent, JCheckBox checkBox, int index, boolean selected, boolean hasFocus) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder()); GutterIconDescriptor descriptor = myList.getItemAt(index); Icon icon = descriptor == null ? null : descriptor.getIcon(); JLabel label = new JLabel(icon == null ? EmptyIcon.ICON_16 : icon); label.setOpaque(true); label.setPreferredSize(new Dimension(25, -1)); label.setHorizontalAlignment(SwingConstants.CENTER); panel.add(label, BorderLayout.WEST); panel.add(checkBox, BorderLayout.CENTER); panel.setBackground(getBackground(false)); label.setBackground(getBackground(selected)); if (!checkBox.isOpaque()) { checkBox.setOpaque(true); } checkBox.setBorder(null); PluginDescriptor pluginDescriptor = myFirstDescriptors.get(descriptor); if (pluginDescriptor instanceof IdeaPluginDescriptor) { SeparatorWithText separator = new SeparatorWithText(); String name = ((IdeaPluginDescriptor)pluginDescriptor).getName(); separator.setCaption("IDEA CORE".equals(name) ? "Common" : name); panel.add(separator, BorderLayout.NORTH); } return panel; } @Nullable @Override protected Point findPointRelativeToCheckBox(int x, int y, @Nonnull JCheckBox checkBox, int index) { return super.findPointRelativeToCheckBoxWithAdjustedRendering(x, y, checkBox, index); } }; myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); myList.setBorder(BorderFactory.createEmptyBorder()); new ListSpeedSearch(myList, (Convertor<Object, String>)o -> o instanceof JCheckBox ? ((JCheckBox)o).getText() : null); }