use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class SearchReplaceComponent method updateTextComponent.
private boolean updateTextComponent(boolean search) {
JTextComponent oldComponent = search ? mySearchTextComponent : myReplaceTextComponent;
if (oldComponent != null)
return false;
final MyTextComponentWrapper wrapper = search ? mySearchFieldWrapper : myReplaceFieldWrapper;
final JTextComponent textComponent;
SearchTextArea textArea = new SearchTextArea(search);
textComponent = textArea.getTextArea();
((JTextArea) textComponent).setRows(isMultiline() ? 2 : 1);
wrapper.setContent(textArea);
UIUtil.addUndoRedoActions(textComponent);
if (UIUtil.isUnderWindowsLookAndFeel()) {
textComponent.setFont(UIManager.getFont("TextField.font"));
} else {
Utils.setSmallerFont(textComponent);
}
textComponent.putClientProperty("AuxEditorComponent", Boolean.TRUE);
textComponent.setBackground(UIUtil.getTextFieldBackground());
textComponent.addFocusListener(new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
textComponent.repaint();
}
@Override
public void focusLost(final FocusEvent e) {
textComponent.repaint();
}
});
installCloseOnEscapeAction(textComponent);
return true;
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class Messages method showInputDialog.
@Nullable
public static String showInputDialog(Project project, @Nls String message, @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon, @Nullable String initialValue, @Nullable InputValidator validator, @Nullable TextRange selection) {
if (isApplicationInUnitTestOrHeadless()) {
return ourTestInputImplementation.show(message, validator);
} else {
InputDialog dialog = new InputDialog(project, message, title, icon, initialValue, validator);
final JTextComponent field = dialog.getTextField();
if (selection != null) {
// set custom selection
field.select(selection.getStartOffset(), selection.getEndOffset());
} else {
// reset selection
final int length = field.getDocument().getLength();
field.select(length, length);
}
field.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
dialog.show();
return dialog.getInputString();
}
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class FindDialog method initCombobox.
private void initCombobox(@NotNull final ComboBox comboBox) {
comboBox.setEditable(true);
comboBox.setMaximumRowCount(8);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
validateFindButton();
}
});
final Component editorComponent = comboBox.getEditor().getEditorComponent();
if (editorComponent instanceof EditorTextField) {
final EditorTextField etf = (EditorTextField) editorComponent;
DocumentAdapter listener = new DocumentAdapter() {
@Override
public void documentChanged(final DocumentEvent e) {
handleComboBoxValueChanged(comboBox);
}
};
etf.addDocumentListener(listener);
myComboBoxListeners.put(etf, listener);
} else {
if (editorComponent instanceof JTextComponent) {
final javax.swing.text.Document document = ((JTextComponent) editorComponent).getDocument();
final com.intellij.ui.DocumentAdapter documentAdapter = new com.intellij.ui.DocumentAdapter() {
@Override
protected void textChanged(javax.swing.event.DocumentEvent e) {
handleAnyComboBoxValueChanged(comboBox);
}
};
document.addDocumentListener(documentAdapter);
Disposer.register(myDisposable, new Disposable() {
@Override
public void dispose() {
document.removeDocumentListener(documentAdapter);
}
});
} else {
assert false;
}
}
if (!myHelper.getModel().isReplaceState()) {
makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "choosePrevious", () -> {
int row = myResultsPreviewTable.getSelectedRow();
if (row > 0)
myResultsPreviewTable.setRowSelectionInterval(row - 1, row - 1);
TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
});
makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "chooseNext", () -> {
int row = myResultsPreviewTable.getSelectedRow();
if (row >= -1 && row + 1 < myResultsPreviewTable.getRowCount()) {
myResultsPreviewTable.setRowSelectionInterval(row + 1, row + 1);
TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
}
});
makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "scrollUp", () -> {
ScrollingUtil.movePageUp(myResultsPreviewTable);
});
makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "scrollDown", () -> {
ScrollingUtil.movePageDown(myResultsPreviewTable);
});
AnAction action = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (isResultsPreviewTabActive()) {
navigateToSelectedUsage(myResultsPreviewTable);
}
}
};
action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), comboBox, myDisposable);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (!isResultsPreviewTabActive() || myResultsPreviewTable.getSelectedRowCount() == 0)
doOKAction();
else
action.actionPerformed(e);
}
}.registerCustomShortcutSet(CommonShortcuts.ENTER, comboBox, myDisposable);
}
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class ScrollingUtil method installActions.
public static void installActions(final JTable table, final boolean cycleScrolling, JComponent focusParent) {
ActionMap actionMap = table.getActionMap();
actionMap.put(SCROLLUP_ACTION_ID, new MoveAction(SCROLLUP_ACTION_ID, table, cycleScrolling));
actionMap.put(SCROLLDOWN_ACTION_ID, new MoveAction(SCROLLDOWN_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_PREVIOUS_ROW_ACTION_ID, new MoveAction(SELECT_PREVIOUS_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_NEXT_ROW_ACTION_ID, new MoveAction(SELECT_NEXT_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_LAST_ROW_ACTION_ID, new MoveAction(SELECT_LAST_ROW_ACTION_ID, table, cycleScrolling));
actionMap.put(SELECT_FIRST_ROW_ACTION_ID, new MoveAction(SELECT_FIRST_ROW_ACTION_ID, table, cycleScrolling));
maybeInstallDefaultShortcuts(table);
JComponent target = focusParent == null ? table : focusParent;
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveHome(table);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), table);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveEnd(table);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), table);
if (!(focusParent instanceof JTextComponent)) {
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveHome(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveHome(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveEnd(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveEnd(), target);
}
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveDown(table, e.getModifiers(), cycleScrolling);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveDown(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
moveUp(table, e.getModifiers(), cycleScrolling);
}
}.registerCustomShortcutSet(CommonShortcuts.getMoveUp(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
movePageUp(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMovePageUp(), target);
new MyScrollingAction(table) {
@Override
public void actionPerformed(AnActionEvent e) {
movePageDown(table);
}
}.registerCustomShortcutSet(CommonShortcuts.getMovePageDown(), target);
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class JBList method installDefaultCopyAction.
private void installDefaultCopyAction() {
final Action copy = getActionMap().get("copy");
if (copy == null || copy instanceof UIResource) {
Action newCopy = new AbstractAction() {
@Override
public boolean isEnabled() {
return getSelectedIndex() != -1;
}
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<String> selected = new ArrayList<>();
JBList list = JBList.this;
ListCellRenderer renderer = list.getCellRenderer();
if (renderer != null) {
for (int index : getSelectedIndices()) {
Object value = list.getModel().getElementAt(index);
//noinspection unchecked
Component c = renderer.getListCellRendererComponent(list, value, index, true, true);
SimpleColoredComponent coloredComponent = null;
if (c instanceof JComponent) {
coloredComponent = UIUtil.findComponentOfType((JComponent) c, SimpleColoredComponent.class);
}
if (coloredComponent != null) {
selected.add(coloredComponent.toString());
} else if (c instanceof JTextComponent) {
selected.add(((JTextComponent) c).getText());
} else if (value != null) {
selected.add(value.toString());
}
}
}
if (selected.size() > 0) {
String text = StringUtil.join(selected, " ");
CopyPasteManager.getInstance().setContents(new StringSelection(text));
}
}
};
getActionMap().put("copy", newCopy);
}
}
Aggregations