private static String getSearchAgainMessage(PsiElement element, final FileSearchScope direction) { String message = getNoUsagesFoundMessage(element); if (direction == FileSearchScope.AFTER_CARET) { AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT); String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action); if (shortcutsText.isEmpty()) { message = FindBundle.message("find.search.again.from.top.action.message", message); } else { message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText); } } else { String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS)); if (shortcutsText.isEmpty()) { message = FindBundle.message("find.search.again.from.bottom.action.message", message); } else { message = FindBundle.message( "find.search.again.from.bottom.hotkey.message", message, shortcutsText); } } return message; }
@NotNull private InplaceButton createSettingsButton( @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages, @NotNull final Runnable cancelAction) { String shortcutText = ""; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")"; } return new InplaceButton( "Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { showDialogAndFindUsages(handler, popupPosition, editor, maxUsages); } }); cancelAction.run(); } }); }
@Override public void propertyChange(PropertyChangeEvent event) { boolean internal = myInternal; myInternal = true; Object value = event.getNewValue(); if (ShortcutFilteringPanel.this == event.getSource()) { if (value instanceof KeyboardShortcut) { KeyboardShortcut shortcut = (KeyboardShortcut) value; myMousePanel.setShortcut(null); myKeyboardPanel.setShortcut(shortcut); if (null != shortcut.getSecondKeyStroke()) { myKeyboardPanel.mySecondStrokeEnable.setSelected(true); } } else { MouseShortcut shortcut = value instanceof MouseShortcut ? (MouseShortcut) value : null; String text = shortcut == null ? null : KeymapUtil.getMouseShortcutText(shortcut); myMousePanel.setShortcut(shortcut); myKeyboardPanel.setShortcut(null); myKeyboardPanel.myFirstStroke.setText(text); myKeyboardPanel.mySecondStroke.setText(null); myKeyboardPanel.mySecondStroke.setEnabled(false); } } else if (value instanceof Shortcut) { setShortcut((Shortcut) value); } else if (!internal) { setShortcut(null); } myInternal = internal; }
protected JLabel createActionLabel( final AnAction anAction, final String anActionName, final Color fg, final Color bg, final Icon icon) { final LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(EMPTY_ICON, 0); if (icon != null && icon.getIconWidth() <= EMPTY_ICON.getIconWidth() && icon.getIconHeight() <= EMPTY_ICON.getIconHeight()) { layeredIcon.setIcon( icon, 1, (-icon.getIconWidth() + EMPTY_ICON.getIconWidth()) / 2, (EMPTY_ICON.getIconHeight() - icon.getIconHeight()) / 2); } final Shortcut[] shortcutSet = KeymapManager.getInstance().getActiveKeymap().getShortcuts(getActionId(anAction)); final String actionName = anActionName + (shortcutSet != null && shortcutSet.length > 0 ? " (" + KeymapUtil.getShortcutText(shortcutSet[0]) + ")" : ""); final JLabel actionLabel = new JLabel(actionName, layeredIcon, SwingConstants.LEFT); actionLabel.setBackground(bg); actionLabel.setForeground(fg); return actionLabel; }
public static String getMessage(final boolean multiple, final String name) { final String messageKey = multiple ? "import.popup.multiple" : "import.popup.text"; String hintText = DaemonBundle.message(messageKey, name); hintText += " " + KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)); return hintText; }
@Nullable private static String getShortcutText(String actionId, Keymap keymap) { for (final Shortcut shortcut : keymap.getShortcuts(actionId)) { if (shortcut instanceof KeyboardShortcut) { return KeymapUtil.getShortcutText(shortcut); } } return null; }
public static void invokeImpl( Project project, Editor editor, final PsiFile file, Injectable injectable) { final PsiLanguageInjectionHost host = findInjectionHost(editor, file); if (host == null) return; if (defaultFunctionalityWorked(host, injectable.getId())) return; try { host.putUserData(FIX_KEY, null); Language language = injectable.toLanguage(); for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) { return; } } if (TemporaryPlacesRegistry.getInstance(project) .getLanguageInjectionSupport() .addInjectionInPlace(language, host)) { final Processor<PsiLanguageInjectionHost> data = host.getUserData(FIX_KEY); String text = StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected."; if (data != null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { final SmartPsiElementPointer<PsiLanguageInjectionHost> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(host); final TextRange range = host.getTextRange(); HintManager.getInstance() .showQuestionHint( editor, text + "<br>Do you want to insert annotation? " + KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance() .getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)), range.getStartOffset(), range.getEndOffset(), new QuestionAction() { @Override public boolean execute() { return data.process(pointer.getElement()); } }); } } else { HintManager.getInstance().showInformationHint(editor, text); } } } finally { if (injectable.getLanguage() != null) { // no need for reference injection FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true); } else { ((PsiModificationTrackerImpl) PsiManager.getInstance(project).getModificationTracker()) .incCounter(); DaemonCodeAnalyzer.getInstance(project).restart(); } } }
@Nullable public String getAdText(CompletionResult result) { if (result.myCompletionBase == null) return null; if (result.myCompletionBase.length() == result.myFieldText.length()) return null; String strokeText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction("EditorChooseLookupItemReplace")); return IdeBundle.message("file.chooser.completion.ad.text", strokeText); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) { g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); g.drawLine(0, 0, getWidth(), 0); } if (showEmptyText()) { UIUtil.applyRenderingHints(g); g.setColor(new JBColor(Gray._100, Gray._160)); g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f)); final UIUtil.TextPainter painter = new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f); painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100)); if (!isProjectViewVisible()) { painter .appendLine( "Open Project View with " + KeymapUtil.getShortcutText( new KeyboardShortcut( KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"), null))) .smaller() .withBullet(); } painter .appendLine("Open a file by name with " + getActionShortcutText("GotoFile")) .smaller() .withBullet() .appendLine( "Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES)) .smaller() .withBullet() .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")) .smaller() .withBullet() .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName()) .smaller() .withBullet() .draw( g, new PairFunction<Integer, Integer, Pair<Integer, Integer>>() { @Override public Pair<Integer, Integer> fun(Integer width, Integer height) { final Dimension s = getSize(); return Pair.create((s.width - width) / 2, (s.height - height) / 2); } }); } }
private static String getActionShortcutText(final String actionId) { final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId); String shortcutText = ""; for (final Shortcut shortcut : shortcuts) { if (shortcut instanceof KeyboardShortcut) { shortcutText = KeymapUtil.getShortcutText(shortcut); break; } } return shortcutText; }
@Nullable private static String getSecondInvocationTitle( @NotNull FindUsagesOptions options, @NotNull FindUsagesHandler handler) { if (getShowUsagesShortcut() != null) { GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler); if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) { return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in " + maximalScope.getDisplayName(); } } return null; }
@Override protected void customizeCellRenderer( final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { if (value == null) return; if (value instanceof Pair) { final Pair<AnAction, KeyStroke> pair = (Pair<AnAction, KeyStroke>) value; append( KeymapUtil.getShortcutText(new KeyboardShortcut(pair.getSecond(), null)), SimpleTextAttributes.GRAY_ATTRIBUTES); appendAlign(30); final String text = pair.getFirst().getTemplatePresentation().getText(); append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES); } }
public static void installCompletionHint(@NotNull EditorEx editor) { String completionShortcutText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); if (!StringUtil.isEmpty(completionShortcutText)) { final Ref<Boolean> toShowHintRef = new Ref<Boolean>(true); editor .getDocument() .addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { toShowHintRef.set(false); } }); editor.addFocusListener( new FocusChangeListener() { @Override public void focusGained(final Editor editor) { if (toShowHintRef.get() && editor.getDocument().getText().isEmpty()) { ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { HintManager.getInstance() .showInformationHint( editor, "Code completion available ( " + completionShortcutText + " )"); } }); } } @Override public void focusLost(Editor editor) { // Do nothing } }); } }
public Object getValueAt(Object value, int column) { if (!(value instanceof DefaultMutableTreeNode)) { return "???"; } if (column == 0) { return value; } else if (column == 1) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof QuickList) { userObject = ((QuickList) userObject).getActionId(); } if (userObject instanceof String) { Shortcut[] shortcuts = myKeymap.getShortcuts((String) userObject); return KeymapUtil.getShortcutsText(shortcuts); } else { return ""; } } else { return "???"; } }
/** Updates all UI controls */ private void updatePreviewAndConflicts() { if (myButton == -1 || myModifiers == -1) { return; } myTarConflicts.setText(null); // Set text into preview area // empty string should have same height myLblPreview.setText( KeymapUtil.getMouseShortcutText(myButton, myModifiers, myRbSingleClick.isSelected() ? 1 : 2) + " "); // Detect conflicts final MouseShortcut mouseShortcut; if (myRbSingleClick.isSelected()) { mouseShortcut = new MouseShortcut(myButton, myModifiers, 1); } else { mouseShortcut = new MouseShortcut(myButton, myModifiers, 2); } StringBuilder buffer = new StringBuilder(); String[] actionIds = myKeymap.getActionIds(mouseShortcut); for (String actionId : actionIds) { if (actionId.equals(myActionId)) { continue; } String actionPath = myMainGroup.getActionQualifiedPath(actionId); // actionPath == null for editor actions having corresponding $-actions if (actionPath == null) { continue; } Shortcut[] shortcuts = myKeymap.getShortcuts(actionId); for (Shortcut shortcut1 : shortcuts) { if (!(shortcut1 instanceof MouseShortcut)) { continue; } MouseShortcut shortcut = (MouseShortcut) shortcut1; if (shortcut.getButton() != mouseShortcut.getButton() || shortcut.getModifiers() != mouseShortcut.getModifiers()) { continue; } if (buffer.length() > 1) { buffer.append('\n'); } buffer.append('['); buffer.append(actionPath); buffer.append(']'); break; } } if (buffer.length() == 0) { myTarConflicts.setForeground(UIUtil.getTextAreaForeground()); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.no.conflicts.area")); } else { myTarConflicts.setForeground(Color.red); myTarConflicts.setText( KeyMapBundle.message("mouse.shortcut.dialog.assigned.to.area", buffer.toString())); } }
private boolean inInitState() { Component focusOwner = myContext.getFocusOwner(); boolean isModalContext = myContext.isModalContext(); DataContext dataContext = myContext.getDataContext(); KeyEvent e = myContext.getInputEvent(); // http://www.jetbrains.net/jira/browse/IDEADEV-12372 if (myLeftCtrlPressed && myRightAltPressed && focusOwner != null && e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) { if (Registry.is("actionSystem.force.alt.gr")) { return false; } final InputContext inputContext = focusOwner.getInputContext(); if (inputContext != null) { Locale locale = inputContext.getLocale(); if (locale != null) { @NonNls final String language = locale.getLanguage(); if (ALT_GR_LAYOUTS.contains(language)) { // don't search for shortcuts return false; } } } } KeyStroke originalKeyStroke = KeyStroke.getKeyStrokeForEvent(e); KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke); if (myKeyGestureProcessor.processInitState()) { return true; } if (SystemInfo.isMac) { boolean keyTyped = e.getID() == KeyEvent.KEY_TYPED; boolean hasMnemonicsInWindow = e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode()) || keyTyped && hasMnemonicInWindow(focusOwner, e.getKeyChar()); boolean imEnabled = IdeEventQueue.getInstance().isInputMethodEnabled(); if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK && (hasMnemonicsInWindow || (!imEnabled && keyTyped))) { setPressedWasProcessed(true); setState(KeyState.STATE_PROCESSED); return false; } } updateCurrentContext(focusOwner, new KeyboardShortcut(keyStroke, null), isModalContext); if (myContext.getActions().isEmpty()) { // there's nothing mapped for this stroke return false; } if (myContext.isHasSecondStroke()) { myFirstKeyStroke = keyStroke; final ArrayList<Pair<AnAction, KeyStroke>> secondKeyStrokes = getSecondKeystrokeActions(); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); StringBuilder message = new StringBuilder(); message.append(KeyMapBundle.message("prefix.key.pressed.message")); message.append(' '); for (int i = 0; i < secondKeyStrokes.size(); i++) { Pair<AnAction, KeyStroke> pair = secondKeyStrokes.get(i); if (i > 0) message.append(", "); message.append(pair.getFirst().getTemplatePresentation().getText()); message.append(" ("); message.append(KeymapUtil.getKeystrokeText(pair.getSecond())); message.append(")"); } StatusBar.Info.set(message.toString(), project); mySecondStrokeTimeout.cancelAllRequests(); mySecondStrokeTimeout.addRequest( mySecondStrokeTimeoutRunnable, Registry.intValue("actionSystem.secondKeystrokeTimeout")); if (Registry.is("actionSystem.secondKeystrokeAutoPopupEnabled")) { mySecondKeystrokePopupTimeout.cancelAllRequests(); if (secondKeyStrokes.size() > 1) { final DataContext oldContext = myContext.getDataContext(); mySecondKeystrokePopupTimeout.addRequest( new Runnable() { @Override public void run() { if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) { StatusBar.Info.set(null, PlatformDataKeys.PROJECT.getData(oldContext)); new SecondaryKeystrokePopup(myFirstKeyStroke, secondKeyStrokes, oldContext) .showInBestPositionFor(oldContext); } } }, Registry.intValue("actionSystem.secondKeystrokePopupTimeout")); } } setState(KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE); return true; } else { return processAction(e, myActionProcessor); } }
public String getFirstShortcutText() { return KeymapUtil.getFirstKeyboardShortcutText(myAction.getAction()); }
protected JComponent createNorthPanel() { JPanel panel = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(0, 2, 0, 0); myNameLabel = new JLabel(); panel.add(myNameLabel, c); c.insets.top = 10; c.gridy++; panel.add(new JLabel(RefactoringBundle.message("move.files.to.directory.label")), c); c.insets.top = 0; myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener( RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.moved.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor(); FileChooserFactory.getInstance() .installFileCompletion(textField, descriptor, true, getDisposable()); myTargetDirectoryField.setTextFieldPreferredWidth(60); c.insets.left = 0; c.gridy++; panel.add(myTargetDirectoryField, c); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText( ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); final JLabel label = new JLabel(RefactoringBundle.message("path.completion.shortcut", shortcutText)); UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); c.insets.left = 6; c.gridy++; panel.add(label, c); myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references")); myCbSearchForReferences.setSelected( RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE); c.insets.top = 10; c.insets.left = 0; c.gridy++; panel.add(myCbSearchForReferences, c); textField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); Disposer.register(getDisposable(), myTargetDirectoryField); return panel; }
private void createPopup(Project project) { final JPanel panel = new JPanel(new BorderLayout()); final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class); myEditorField = service.getEditorField( FileTypes.PLAIN_TEXT.getLanguage(), project, Collections.singletonList(EditorCustomization.Feature.SOFT_WRAP), Collections.singletonList(EditorCustomization.Feature.SPELL_CHECK)); myEditorField.setBorder( new CompoundBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2), myEditorField.getBorder())); myEditorField.setText("s"); myEditorField.setText(myCurrentText); myEditorField.setOneLineMode(false); panel.add(myEditorField, BorderLayout.CENTER); myTextFieldCompletionProvider = new TextFieldCompletionProviderDumbAware(true) { @NotNull @Override protected String getPrefix(@NotNull String currentTextPrefix) { final int text = currentTextPrefix.lastIndexOf(','); return text == -1 ? currentTextPrefix : currentTextPrefix.substring(text + 1).trim(); } @Override protected void addCompletionVariants( @NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) { final List<String> list = myUsers.get(); if (list != null) { for (String completionVariant : list) { final LookupElementBuilder element = LookupElementBuilder.create(completionVariant); result.addElement(element.withLookupString(completionVariant.toLowerCase())); } } } }; myComponentPopupBuilder = JBPopupFactory.getInstance() .createComponentPopupBuilder(panel, myEditorField) .setCancelOnClickOutside(true) .setAdText( KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish") .setTitle("Specify user names, comma separated") .setMovable(true) .setRequestFocus(true) .setResizable(true); mySelectOkAction = new AnAction() { @Override public void actionPerformed(AnActionEvent e) { myPopup.closeOk(e.getInputEvent()); final String newText = myEditorField.getText(); if (Comparing.equal(newText.trim(), myCurrentText.trim())) return; myCurrentText = newText; setText(myCurrentText.trim()); myPanel.setToolTipText(USER + " " + myCurrentText); myUserFilterI.filter(myCurrentText); } }; }
private void addCheckbox(final JPanel panel, final TreeAction action) { String text = action instanceof FileStructureFilter ? ((FileStructureFilter) action).getCheckBoxText() : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider) action).getCheckBoxText() : null; if (text == null) return; Shortcut[] shortcuts = action instanceof FileStructureFilter ? ((FileStructureFilter) action).getShortcut() : ((FileStructureNodeProvider) action).getShortcut(); final JCheckBox chkFilter = new JCheckBox(); UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, chkFilter); final boolean selected = getDefaultValue(action); chkFilter.setSelected(selected); myTreeActionsOwner.setActionIncluded( action, action instanceof FileStructureFilter ? !selected : selected); chkFilter.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { final boolean state = chkFilter.isSelected(); if (!myAutoClicked.contains(chkFilter)) { saveState(action, state); } myTreeActionsOwner.setActionIncluded( action, action instanceof FileStructureFilter ? !state : state); // final String filter = mySpeedSearch.isPopupActive() ? // mySpeedSearch.getEnteredPrefix() : null; // mySpeedSearch.hidePopup(); Object selection = ContainerUtil.getFirstItem(myAbstractTreeBuilder.getSelectedElements()); if (selection instanceof FilteringTreeStructure.FilteringNode) { selection = ((FilteringTreeStructure.FilteringNode) selection).getDelegate(); } myTreeStructure.rebuildTree(); myFilteringStructure.rebuild(); final Object sel = selection; final Runnable runnable = new Runnable() { public void run() { ApplicationManager.getApplication() .runReadAction( new Runnable() { @Override public void run() { myAbstractTreeBuilder .refilter(sel, true, false) .doWhenProcessed( new Runnable() { @Override public void run() { if (mySpeedSearch.isPopupActive()) { mySpeedSearch.refreshSelection(); } } }); } }); } }; if (ApplicationManager.getApplication().isUnitTestMode()) { runnable.run(); } else { ApplicationManager.getApplication().invokeLater(runnable); } } }); chkFilter.setFocusable(false); if (shortcuts.length > 0) { text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")"; new AnAction() { public void actionPerformed(final AnActionEvent e) { chkFilter.doClick(); } }.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree); } chkFilter.setText(text); panel.add(chkFilter); myCheckBoxes.put(action.getClass(), chkFilter); }
private void paintRowData(Tree tree, Object data, Rectangle bounds, Graphics2D g) { Shortcut[] shortcuts = null; Set<String> abbreviations = null; if (data instanceof String) { final String actionId = (String) data; shortcuts = myKeymap.getShortcuts(actionId); abbreviations = AbbreviationManager.getInstance().getAbbreviations(actionId); } else if (data instanceof QuickList) { shortcuts = myKeymap.getShortcuts(((QuickList) data).getActionId()); } final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); int totalWidth = 0; final FontMetrics metrics = tree.getFontMetrics(tree.getFont()); if (shortcuts != null && shortcuts.length > 0) { for (Shortcut shortcut : shortcuts) { totalWidth += metrics.stringWidth(KeymapUtil.getShortcutText(shortcut)); totalWidth += 10; } totalWidth -= 5; int x = bounds.x + bounds.width - totalWidth; int fontHeight = (int) metrics.getMaxCharBounds(g).getHeight(); Color c1 = new Color(234, 200, 162); Color c2 = new Color(208, 200, 66); g.translate(0, bounds.y - 1); for (Shortcut shortcut : shortcuts) { int width = metrics.stringWidth(KeymapUtil.getShortcutText(shortcut)); UIUtil.drawSearchMatch(g, x, x + width, bounds.height, c1, c2); g.setColor(Gray._50); g.drawString(KeymapUtil.getShortcutText(shortcut), x, fontHeight); x += width; x += 10; } g.translate(0, -bounds.y + 1); } if (Registry.is("actionSystem.enableAbbreviations") && abbreviations != null && abbreviations.size() > 0) { for (String abbreviation : abbreviations) { totalWidth += metrics.stringWidth(abbreviation); totalWidth += 10; } totalWidth -= 5; int x = bounds.x + bounds.width - totalWidth; int fontHeight = (int) metrics.getMaxCharBounds(g).getHeight(); Color c1 = new Color(206, 234, 176); Color c2 = new Color(126, 208, 82); g.translate(0, bounds.y - 1); for (String abbreviation : abbreviations) { int width = metrics.stringWidth(abbreviation); UIUtil.drawSearchMatch(g, x, x + width, bounds.height, c1, c2); g.setColor(Gray._50); g.drawString(abbreviation, x, fontHeight); x += width; x += 10; } g.translate(0, -bounds.y + 1); } config.restore(); }