private void openSample(Project project, Editor editor) { EditorTextField field = new EditorTextField(editor.getDocument(), project, WeexFileType.INSTANCE, true, false) { @Override protected EditorEx createEditor() { EditorEx editor1 = super.createEditor(); editor1.setVerticalScrollbarVisible(true); editor1.setHorizontalScrollbarVisible(true); return editor1; } }; field.setFont(editor.getContentComponent().getFont()); JBPopup jbPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(field, null) .createPopup(); jbPopup.setSize(new Dimension(500, 500)); jbPopup.showInBestPositionFor(editor); }
private void createUIComponents() { testTargetTextField = new EditorTextField("", getProject(), FileTypes.PLAIN_TEXT); namespaceComboBox = new PhpNamespaceComboBox(getProject(), "", getDisposable()); directoryComboBox = new PhpPsrDirectoryComboBox(getProject()) { @Override public void init(@NotNull VirtualFile baseDir, @NotNull String namespace) { super.init(baseDir, namespace); ProjectFileIndex index = ProjectRootManager.getInstance(TesterNewTestCaseDialog.this.getProject()).getFileIndex(); this.setDirectoriesFilter(index::isInTestSourceContent); this.updateDirectories(TesterNewTestCaseDialog.this.getNamespace()); } }; classToTestLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.classToTest")); testClassLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.testClass")); namespaceLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.namespace")); fileNameLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.fileName")); directoryLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.directory")); testTargetCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI); namespaceCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI); directoryCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI); }
private void createViews() { etfName = new EditorTextField(Localizer.get("ExampleName")); btnTry = new JButton(Localizer.get("TryIt")); jlResult = new JBLabel(Localizer.get("ResultWillBeHere")); etfName.setAlignmentX(Component.CENTER_ALIGNMENT); etfName.setAlignmentY(Component.CENTER_ALIGNMENT); btnTry.setAlignmentX(Component.CENTER_ALIGNMENT); btnTry.setAlignmentY(Component.CENTER_ALIGNMENT); jlResult.setAlignmentX(Component.CENTER_ALIGNMENT); jlResult.setAlignmentY(Component.CENTER_ALIGNMENT); btnTry.addMouseListener(new ClickListener() { @Override public void mouseClicked(MouseEvent e) { jlResult.setText(ScriptExecutor.runScript(etfCode.getText(), etfName.getText())); } }); }
public void installCompletion(EditorTextField field) { new TextFieldCompletionProvider() { @Override protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) { final String className = getClassName(); if (className.trim().length() == 0) { return; } final PsiClass testClass = getModuleSelector().findClass(className); if (testClass == null) return; final Condition<PsiMethod> filter = getFilter(testClass); for (PsiMethod psiMethod : testClass.getAllMethods()) { if (filter.value(psiMethod)) { result.addElement(LookupElementBuilder.create(psiMethod.getName())); } } } }.apply(field); }
private void setupPathComponent(final JPanel northPanel) { northPanel.add(new TextFieldAction() { @Override public void linkSelected(LinkLabel aSource, Object aLinkData) { toggleShowPathComponent(northPanel, this); } }, BorderLayout.EAST); myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA); myPathEditor.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { myAlarm.cancelAllRequests(); myAlarm.addRequest(new Runnable() { @Override public void run() { updateTreeFromPath(); } }, 300); } }); myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); northPanel.add(myPathEditor, BorderLayout.SOUTH); }
@Nullable private JPanel createParametersPanel () { myThisClassesMap = MoveInstanceMembersUtil.getThisClassesToMembers(myMethod); myOldClassParameterNameFields = new HashMap<PsiClass, EditorTextField>(); if (myThisClassesMap.size() == 0) return null; JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true)); for (PsiClass aClass : myThisClassesMap.keySet()) { final String text = RefactoringBundle.message("move.method.this.parameter.label", aClass.getName()); panel.add(new TitledSeparator(text, null)); String suggestedName = MoveInstanceMethodHandler.suggestParameterNameForThisClass(aClass); final EditorTextField field = new EditorTextField(suggestedName, getProject(), StdFileTypes.JAVA); field.setMinimumSize(new Dimension(field.getPreferredSize())); myOldClassParameterNameFields.put(aClass, field); panel.add(field); } panel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); return panel; }
protected void doAction() { Map<PsiClass, String> parameterNames = new LinkedHashMap<PsiClass, String>(); for (final PsiClass aClass : myThisClassesMap.keySet()) { EditorTextField field = myOldClassParameterNameFields.get(aClass); if (field.isEnabled()) { String parameterName = field.getText().trim(); if (!PsiNameHelper.getInstance(myMethod.getProject()).isIdentifier(parameterName)) { Messages .showErrorDialog(getProject(), RefactoringBundle.message("move.method.enter.a.valid.name.for.parameter"), myRefactoringName); return; } parameterNames.put(aClass, parameterName); } } final PsiVariable targetVariable = (PsiVariable)myList.getSelectedValue(); if (targetVariable == null) return; final MoveInstanceMethodProcessor processor = new MoveInstanceMethodProcessor(myMethod.getProject(), myMethod, targetVariable, myVisibilityPanel.getVisibility(), isOpenInEditor(), parameterNames); if (!verifyTargetClass(processor.getTargetClass())) return; saveOpenInEditorOption(); invokeRefactoring(processor); }
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) { final EditorTextField textField = (EditorTextField)super.getTableCellEditorComponent(table, value, isSelected, row, column); textField.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { PsiType type = getRowType(table, row); if (type != null) { completeVariable(textField, type); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW); textField.setBorder(new LineBorder(table.getSelectionBackground())); return textField; }
public static void adjustComponentsOnMac(@Nullable JLabel label, @Nullable JComponent component) { if (component == null) return; if (!UIUtil.isUnderAquaLookAndFeel()) return; if (component instanceof JComboBox) { UIUtil.addInsets(component, new Insets(0,-2,0,0)); if (label != null) { UIUtil.addInsets(label, new Insets(0,2,0,0)); } } if (component instanceof JCheckBox) { UIUtil.addInsets(component, new Insets(0,-5,0,0)); } if (component instanceof JTextField || component instanceof EditorTextField) { if (label != null) { UIUtil.addInsets(label, new Insets(0,3,0,0)); } } }
@Override public void update(AnActionEvent e) { final LookupEx lookup; if (myInput instanceof EditorTextField) { lookup = LookupManager.getActiveLookup(((EditorTextField)myInput).getEditor()); } else if (myInput instanceof EditorComponentImpl) { lookup = LookupManager.getActiveLookup(((EditorComponentImpl)myInput).getEditor()); } else { lookup = null; } JComboBox comboBox = UIUtil.findComponentOfType(myInput, JComboBox.class); boolean popupMenuVisible = comboBox != null && comboBox.isPopupVisible(); e.getPresentation().setEnabled(lookup == null && !popupMenuVisible); }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final EditorTextField editorTextField = new EditorTextField((String) value, myProject, StdFileTypes.JAVA) { @Override protected boolean shouldHaveBorder() { return false; } }; myDocument = editorTextField.getDocument(); if (myDocument != null) { for (DocumentListener listener : myListeners) { editorTextField.addDocumentListener(listener); } } return editorTextField; }
public MyTableEditor(Project project, XDebuggerEditorsProvider debuggerEditorsProvider, @Nullable @NonNls String historyId, @Nullable XSourcePosition sourcePosition, @NotNull XExpression text, @NotNull final KeyAdapter actionAdapter) { super(project, debuggerEditorsProvider, EvaluationMode.CODE_FRAGMENT, historyId, sourcePosition); myExpression = XExpressionImpl.changeMode(text, getMode()); myEditorTextField = new EditorTextField(createDocument(myExpression), project, debuggerEditorsProvider.getFileType()) { @Override protected EditorEx createEditor() { final EditorEx editor = super.createEditor(); editor.setVerticalScrollbarVisible(false); editor.setOneLineMode(true); editor.getContentComponent().addKeyListener(actionAdapter); return editor; } @Override protected boolean isOneLineMode() { return true; } }; myEditorTextField.setFontInheritedFromLAF(false); }
private void configureStartingScriptPanel(final PyConsoleOptions.PyConsoleSettings optionsProvider) { myEditorTextField = new EditorTextField(createDocument(myProject, optionsProvider.myCustomStartScript), myProject, PythonFileType.INSTANCE) { @Override protected EditorEx createEditor() { final EditorEx editor = super.createEditor(); editor.setVerticalScrollbarVisible(true); return editor; } @Override protected boolean isOneLineMode() { return false; } }; myStartingScriptPanel.setLayout(new BorderLayout()); myStartingScriptPanel.add(myEditorTextField, BorderLayout.CENTER); myConsoleSettings = optionsProvider; }
private void createUIComponents() { final EditorTextField editorTextField = new LanguageTextField(PlainTextLanguage.INSTANCE, myProject, "") { @Override protected EditorEx createEditor() { final EditorEx editor = super.createEditor(); final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument()); if (file != null) { DaemonCodeAnalyzer.getInstance(myProject).setHighlightingEnabled(file, false); } editor.putUserData(ACTIVITY_CLASS_TEXT_FIELD_KEY, ApplicationRunParameters.this); return editor; } }; myActivityField = new ComponentWithBrowseButton<EditorTextField>(editorTextField, null); }
private static void collapseIfPossible(@NotNull EditorTextField editorTextField, @NotNull ProjectSystemId systemId, @NotNull Project project) { Editor editor = editorTextField.getEditor(); if (editor != null) { String rawText = editor.getDocument().getText(); if (StringUtil.isEmpty(rawText)) return; if (EMPTY_PARENT.equals(rawText)) { editorTextField.setEnabled(false); return; } final Collection<ExternalProjectInfo> projectsData = ProjectDataManager.getInstance().getExternalProjectsData(project, systemId); for (ExternalProjectInfo projectInfo : projectsData) { if (projectInfo.getExternalProjectStructure() != null && projectInfo.getExternalProjectPath().equals(rawText)) { editorTextField.setEnabled(true); ExternalProjectPathField.collapse( editorTextField.getEditor(), projectInfo.getExternalProjectStructure().getData().getExternalName()); return; } } } }
public SearchSupport(EditorTextField textField) { myTextField = textField; myTextField.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { onTextChanged(); } }); //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myTextField.addKeyListener(new KeyAdapter() { public void keyPressed(final KeyEvent e) { processListSelection(e); } }); } }); myList.setVisibleRowCount(10); myListModel = new SortedListModel<T>(null); myList.setModel(myListModel); }
public MyEditor(final Project project) { myProject = project; myEditorTextField = new EditorTextField("", project, StdFileTypes.JAVA) { protected boolean shouldHaveBorder() { return false; } }; myActionListener = new MyActionListener(); myTfWithButton = new ComponentWithBrowseButton<EditorTextField>(myEditorTextField, myActionListener); myEditorTextField.setBorder(null); new MyCancelEditingAction().registerCustomShortcutSet(CommonShortcuts.ESCAPE, myTfWithButton); /* myEditorTextField.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { fireValueCommitted(); } } ); */ }
public Component getTableCellEditorComponent(JTable ttable, Object value, boolean isSelected, int row, int col) { myExpression = (Expression)value; myDocument = PsiDocumentManager.getInstance(project).getDocument(myExpression.getFile()); return new EditorTextField(myDocument, project, myExpression.getFileType()) { protected boolean shouldHaveBorder() { return false; } public void addNotify() { super.addNotify(); Runnable runnable = new Runnable() { public void run() { final Editor editor = getEditor(); if (editor != null) { editor.getContentComponent().requestFocus(); } } }; SwingUtilities.invokeLater(runnable); } }; }
private void createUIComponents(Project project) { final EditorTextField editorTextField = new LanguageTextField(PlainTextLanguage.INSTANCE, project, "") { @Override protected EditorEx createEditor() { final EditorEx editor = super.createEditor(); final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file != null) { DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(file, false); } editor.putUserData( ACTIVITY_CLASS_TEXT_FIELD_KEY, BlazeAndroidBinaryRunConfigurationStateEditor.this); return editor; } }; activityField = new ComponentWithBrowseButton<EditorTextField>(editorTextField, null); }
BlazeAndroidTestRunConfigurationStateEditor( RunConfigurationStateEditor commonStateEditor, Project project) { this.commonStateEditor = commonStateEditor; setupUI(project); packageComponent.setComponent(new EditorTextField()); classComponent.setComponent(new EditorTextField()); runnerComponent.setComponent(new EditorTextField()); methodComponent.setComponent(new EditorTextField()); addTestingType(BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_TARGET, allInTargetButton); addTestingType(TEST_ALL_IN_PACKAGE, allInPackageButton); addTestingType(TEST_CLASS, classButton); addTestingType(TEST_METHOD, testMethodButton); }
protected void doAction() { Map<PsiClass, String> parameterNames = new LinkedHashMap<PsiClass, String>(); for (final PsiClass aClass : myThisClassesMap.keySet()) { EditorTextField field = myOldClassParameterNameFields.get(aClass); if (field.isEnabled()) { String parameterName = field.getText().trim(); if (!JavaPsiFacade.getInstance(myMethod.getProject()).getNameHelper().isIdentifier(parameterName)) { Messages .showErrorDialog(getProject(), RefactoringBundle.message("move.method.enter.a.valid.name.for.parameter"), myRefactoringName); return; } parameterNames.put(aClass, parameterName); } } final PsiVariable targetVariable = (PsiVariable)myList.getSelectedValue(); if (targetVariable == null) return; final MoveInstanceMethodProcessor processor = new MoveInstanceMethodProcessor(myMethod.getProject(), myMethod, targetVariable, myVisibilityPanel.getVisibility(), parameterNames); if (!verifyTargetClass(processor.getTargetClass())) return; invokeRefactoring(processor); }
public XDebuggerMultilineEditor(Project project, XDebuggerEditorsProvider debuggerEditorsProvider, @Nullable @NonNls String historyId, @Nullable XSourcePosition sourcePosition, @NotNull String text) { super(project, debuggerEditorsProvider, EvaluationMode.CODE_FRAGMENT, historyId, sourcePosition); myEditorTextField = new EditorTextField(createDocument(text), project, debuggerEditorsProvider.getFileType()) { @Override protected EditorEx createEditor() { final EditorEx editor = super.createEditor(); editor.setVerticalScrollbarVisible(true); return editor; } @Override protected boolean isOneLineMode() { return false; } }; }
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) { final Component editorComponent = inputComboBox.getEditor().getEditorComponent(); if (editorComponent instanceof EditorTextField) { boolean selected = myCbRegularExpressions.isSelectedWhenSelectable(); @NonNls final String s = selected ? "*.regexp" : "*.txt"; FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(s); if (selected && fileType == FileTypes.UNKNOWN) { fileType = FileTypeManager.getInstance().getFileTypeByFileName("*.txt"); // RegExp plugin is not installed } final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(s, fileType, ((EditorTextField)editorComponent).getText(), -1, true); ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file)); } }
private void createUIComponents() { //todo completion //todo completion without whitespace before cursor final ArrayList<String> completionList = ContainerUtil.newArrayList(SERVER_URL_PLACEHOLDER, USERNAME_PLACEHOLDER, PASSWORD_PLACEHOLDER); myLoginURLText = TextFieldWithAutoCompletion.create(myProject, completionList, null, false, myRepository.getLoginURL()); final ArrayList<String> completionList1 = ContainerUtil.newArrayList(SERVER_URL_PLACEHOLDER, QUERY_PLACEHOLDER, MAX_COUNT_PLACEHOLDER); myTasksListURLText = TextFieldWithAutoCompletion.create(myProject, completionList1, null, false, myRepository.getTasksListURL()); final Document document = EditorFactory.getInstance().createDocument(myRepository.getTaskPattern()); myTaskPatternText = new EditorTextField(document, myProject, myRepository.getResponseType().getFileType(), false, false); final ArrayList<String> completionList2 = ContainerUtil.newArrayList("({id}.+?)", "({summary}.+?)"); TextFieldWithAutoCompletionContributor .installCompletion(document, myProject, new TextFieldWithAutoCompletion.StringsCompletionProvider(completionList2, null), true); myTaskPatternText.setFontInheritedFromLAF(false); }
@Override public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) { final EditorTextField textField = (EditorTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); /*textField.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PsiType type = getRowType(table, row); if(type != null) { completeVariable(textField, type); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);*/ textField.setBorder(new LineBorder(table.getSelectionBackground())); return textField; }
private static TextComponentAccessor<EditorTextField> getTextComponentAccessor() { return new TextComponentAccessor<EditorTextField>() { @Override public String getText(EditorTextField component) { String text = component.getText(); final VirtualFile file = VirtualFileManager.getInstance() .findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/'))); if (file != null && !file.isDirectory()) { final VirtualFile parent = file.getParent(); assert parent != null; return parent.getPresentableUrl(); } return text; } @Override public void setText(EditorTextField component, String text) { component.setText(text); } }; }
private void init() { this.field = new EditorTextField("", project, com.jetbrains.php.lang.PhpFileType.INSTANCE); PhpCompletionUtil.installClassCompletion(this.field, null, getDisposable()); this.field.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { String text = field.getText(); if (StringUtil.isEmpty(text) || StringUtil.endsWith(text, "\\")) { return; } addUpdateRequest(250, () -> consumer.consume(field.getText())); } }); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.fill = 1; gbConstraints.weightx = 1.0D; gbConstraints.gridx = 1; gbConstraints.gridy = 1; panel.add(field, gbConstraints); }
public MyEditor(final Project project) { myProject = project; myEditorTextField = new EditorTextField("", project, JavaFileType.INSTANCE) { protected boolean shouldHaveBorder() { return false; } }; myActionListener = new MyActionListener(); myTfWithButton = new ComponentWithBrowseButton<EditorTextField>(myEditorTextField, myActionListener); myEditorTextField.setBorder(null); new MyCancelEditingAction().registerCustomShortcutSet(CommonShortcuts.ESCAPE, myTfWithButton); /* myEditorTextField.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { fireValueCommitted(); } } ); */ }
@Nonnull private static EditorTextField createTextField(@Nonnull Project project, Collection<String> values, boolean supportsNegativeValues, @Nonnull String initialValue) { TextFieldWithCompletion textField = new TextFieldWithCompletion(project, new MyCompletionProvider(values, supportsNegativeValues), initialValue, false, true, false) { @Override protected EditorEx createEditor() { EditorEx editor = super.createEditor(); SoftWrapsEditorCustomization.ENABLED.customize(editor); return editor; } }; textField.setBorder(new CompoundBorder(JBUI.Borders.empty(2), textField.getBorder())); return textField; }
@Nonnull private static EditorTextField createEditorField(@Nonnull String text, @Nullable TextRange rangeToSelect) { Document document = EditorFactory.getInstance().createDocument(text); EditorTextField field = new EditorTextField(document, null, PlainTextFileType.INSTANCE, false, false); field.setPreferredSize(new Dimension(200, 350)); field.addSettingsProvider(editor -> { editor.setVerticalScrollbarVisible(true); editor.setHorizontalScrollbarVisible(true); editor.getSettings().setAdditionalLinesCount(2); if (rangeToSelect != null) { editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset()); editor.getScrollingModel().scrollVertically(document.getTextLength() - 1); editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset()); } }); return field; }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final EditorTextField editorTextField = new EditorTextField((String) value, myProject, InternalStdFileTypes.JAVA) { @Override protected boolean shouldHaveBorder() { return false; } }; myDocument = editorTextField.getDocument(); if (myDocument != null) { for (DocumentListener listener : myListeners) { editorTextField.addDocumentListener(listener); } } return editorTextField; }