public GCMStructureViewModel(@NotNull PsiFile psiFile, @NotNull final GCMStructureViewRootElement root, Editor editor) { super(psiFile, root); withSorters(typeSorter, Sorter.ALPHA_SORTER); editor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { synchronized (needRefresh) { needRefresh = true; } } }); executor.scheduleAtFixedRate(new Runnable() { @Override public void run() { GCMStructureViewModel.this.refreshView(); } }, 15, 5, TimeUnit.SECONDS); }
private Editor createEditor() { PsiFile myFile = null; EditorFactory editorFactory = EditorFactory.getInstance(); Document doc = myFile == null ? editorFactory.createDocument("") : PsiDocumentManager.getInstance(mProject).getDocument(myFile); Editor editor = editorFactory.createEditor(doc, mProject); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setFoldingOutlineShown(true); editorSettings.setAdditionalColumnsCount(3); editorSettings.setAdditionalLinesCount(3); editorSettings.setLineNumbersShown(true); editorSettings.setCaretRowShown(true); editor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { } }); ((EditorEx) editor).setHighlighter(createHighlighter(FileTypes.PLAIN_TEXT)); return editor; }
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); }
public void testDocSynchronizerPrefersLineBoundaryChanges() throws Exception { String text = "import java.awt.List;\n" + "[import java.util.ArrayList;\n]" + "import java.util.HashMap;\n" + "import java.util.Map;"; RangeMarker marker = createMarker(text); synchronizer.startTransaction(getProject(), document, psiFile); String newText = StringUtil.replaceSubstring(document.getText(), TextRange.create(marker), ""); synchronizer.replaceString(document, 0, document.getTextLength(), newText); final List<DocumentEvent> events = new ArrayList<DocumentEvent>(); document.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { events.add(e); } }); synchronizer.commitTransaction(document); assertEquals(newText, document.getText()); DocumentEvent event = assertOneElement(events); assertEquals("DocumentEventImpl[myOffset=22, myOldLength=28, myNewLength=0, myOldString='import java.util.ArrayList;\n', myNewString=''].", event.toString()); }
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); }
private Editor createEditorInPanel(String string) { EditorFactory editorFactory = EditorFactory.getInstance(); Editor editor = editorFactory.createEditor(editorFactory.createDocument(string)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); editorSettings.setAdditionalColumnsCount(3); editorSettings.setAdditionalLinesCount(3); editor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onTextChanged(); } }); ((EditorEx) editor).setHighlighter(getEditorHighlighter()); addEditorToPanel(editor); return editor; }
public LazyRangeMarkerFactory(@NotNull Project project, @NotNull final FileDocumentManager fileDocumentManager) { super(project); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() { @Override public void beforeDocumentChange(DocumentEvent e) { VirtualFile docFile = fileDocumentManager.getFile(e.getDocument()); if (docFile == null) return; WeakList<LazyMarker> lazyMarkers = myMarkers.get(docFile); if (lazyMarkers == null) return; List<LazyMarker> markers = lazyMarkers.toStrongList(); List<LazyMarker> markersToRemove = new ArrayList<LazyMarker>(); for (final LazyMarker marker : markers) { if (Comparing.equal(marker.getFile(), docFile)) { marker.getOrCreateDelegate(); markersToRemove.add(marker); } } lazyMarkers.removeAll(markersToRemove); } }, project); }
public void testDocSynchronizerPrefersLineBoundaryChanges() throws Exception { RangeMarker marker = createMarker("import java.awt.List;\n" + "[import java.util.ArrayList;\n]" + "import java.util.HashMap;\n" + "import java.util.Map;"); PsiToDocumentSynchronizer synchronizer = ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(getProject())).getSynchronizer(); Document document = marker.getDocument(); synchronizer.startTransaction(getProject(), document, null); String newText = StringUtil.replaceSubstring(document.getText(), TextRange.create(marker), ""); synchronizer.replaceString(document, 0, document.getTextLength(), newText); final List<DocumentEvent> events = new ArrayList<DocumentEvent>(); document.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { events.add(e); } }); synchronizer.doCommitTransaction(document); assertEquals(newText, document.getText()); DocumentEvent event = assertOneElement(events); assertEquals("DocumentEventImpl[myOffset=22, myOldLength=28, myNewLength=0, myOldString='import java.util.ArrayList;\n', myNewString=''].", event.toString()); }
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 void createManualInputPreviewEditor(final PreviewState previewState) { final EditorFactory factory = EditorFactory.getInstance(); Document doc = factory.createDocument(previewState.manualInputText); doc.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { previewState.manualInputText = e.getDocument().getCharsSequence(); } } ); Editor editor = createPreviewEditor(previewState.grammarFile, doc); setEditorComponent(editor.getComponent()); // do before setting state previewState.setInputEditor(editor); }
public EncodingManagerImpl(@Nonnull EditorFactory editorFactory) { editorFactory.getEventMulticaster().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { Document document = e.getDocument(); if (isEditorOpenedFor(document)) { queueUpdateEncodingFromContent(document); } } }, this); editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorCreated(@Nonnull EditorFactoryEvent event) { queueUpdateEncodingFromContent(event.getEditor().getDocument()); } }, this); }
private void createUIComponents() { List<Language> languages = getBaseLanguagesWithProviders(); Language selected = myInitiallySelectedLanguage; if (selected == null) { selected = languages.get(0); } String text = getLanguageBlackList(selected); myEditorTextField = createEditor(text, myNewPreselectedItem); myEditorTextField.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { updateOkEnabled(); } }); myDoNotShowIfParameterNameContainedInMethodName = new JBCheckBox(); myShowWhenMultipleParamsWithSameType = new JBCheckBox(); ParameterNameHintsSettings settings = ParameterNameHintsSettings.getInstance(); myDoNotShowIfParameterNameContainedInMethodName.setSelected(settings.isDoNotShowIfMethodNameContainsParameterName()); myShowWhenMultipleParamsWithSameType.setSelected(settings.isShowForParamsWithSameType()); initLanguageCombo(languages, selected); }
ActionTracker(Editor editor, Disposable parentDisposable) { myEditor = editor; myProject = editor.getProject(); ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() { @Override public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { myActionsHappened = true; } }, parentDisposable); myEditor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { if (!myIgnoreDocumentChanges) { myActionsHappened = true; } } }, parentDisposable); }
@NotNull private static DocumentAdapter createDocumentListener(final ItemInfo itemInfo, final JBDebuggerFormTable table) { return new DocumentAdapter() { @Override public void documentChanged(DocumentEvent documentEvent) { if (table.getRowCount() == table.getEditingRow() + 1) { itemInfo.enabled = true; itemInfo.checked = true; table.getListTableModel().addRow(new ItemInfo()); } } }; }
protected JComponent createNorthPanel() { JPanel panel = new JPanel(new BorderLayout()); JPanel _panel; Box box = Box.createVerticalBox(); _panel = new JPanel(new BorderLayout()); JTextField sourceClassField = new JTextField(); sourceClassField.setText(mySourceClassName); sourceClassField.setEditable(false); _panel.add(new JLabel(RefactoringBundle.message("move.members.move.members.from.label")), BorderLayout.NORTH); _panel.add(sourceClassField, BorderLayout.CENTER); box.add(_panel); box.add(Box.createVerticalStrut(10)); _panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(RefactoringBundle.message("move.members.to.fully.qualified.name.label")); label.setLabelFor(myTfTargetClassName); _panel.add(label, BorderLayout.NORTH); _panel.add(myTfTargetClassName, BorderLayout.CENTER); _panel.add(myIntroduceEnumConstants, BorderLayout.SOUTH); box.add(_panel); myTfTargetClassName.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { myMemberInfoModel.updateTargetClass(); validateButtons(); } }); panel.add(box, BorderLayout.CENTER); panel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); validateButtons(); return panel; }
private void createUIComponents() { myMainPanel = new JPanel(); myWithBrowseButtonReference = createPackageChooser(); myClassPackageChooser = createPackageChooser(); GlobalSearchScope scope = JavaProjectRootsUtil.getScopeWithoutGeneratedSources(ProjectScope.getProjectScope(myProject), myProject); myInnerClassChooser = new ClassNameReferenceEditor(myProject, null, scope); myInnerClassChooser.addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { validateButtons(); } }); // override CardLayout sizing behavior myCardPanel = new JPanel() { public Dimension getMinimumSize() { return myHavePackages ? myMovePackagePanel.getMinimumSize() : myMoveClassPanel.getMinimumSize(); } public Dimension getPreferredSize() { return myHavePackages ? myMovePackagePanel.getPreferredSize() : myMoveClassPanel.getPreferredSize(); } }; myDestinationFolderCB = new DestinationFolderComboBox() { @Override public String getTargetPackage() { return MoveClassesOrPackagesDialog.this.getTargetPackage(); } }; }
private ReferenceEditorComboWithBrowseButton createPackageChooser() { final ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package")); final Document document = packageChooser.getChildComponent().getDocument(); document.addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { validateButtons(); } }); return packageChooser; }
public EncodingManagerImpl(@NotNull EditorFactory editorFactory) { editorFactory.getEventMulticaster().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { queueUpdateEncodingFromContent(e.getDocument()); } }, this); editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorCreated(@NotNull EditorFactoryEvent event) { queueUpdateEncodingFromContent(event.getEditor().getDocument()); } }, this); }
public FileStatusManagerImpl(Project project, StartupManager startupManager, EditorColorsManager colorsManager, @SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) { myProject = project; colorsManager.addEditorColorsListener(new EditorColorsListener() { @Override public void globalSchemeChange(EditorColorsScheme scheme) { fileStatusesChanged(); } }, myProject); startupManager.registerPreStartupActivity(new Runnable() { @Override public void run() { DocumentAdapter documentListener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument()); if (file != null) { refreshFileStatusFromDocument(file, event.getDocument()); } } }; final EditorFactory factory = EditorFactory.getInstance(); if (factory != null) { factory.getEventMulticaster().addDocumentListener(documentListener, myProject); } } }); startupManager.registerPostStartupActivity(new DumbAwareRunnable() { @Override public void run() { fileStatusesChanged(); } }); }
public ScrollingModelImpl(EditorImpl editor) { myEditor = editor; myEditor.getScrollPane().getViewport().addChangeListener(new ChangeListener() { private Rectangle myLastViewRect; @Override public void stateChanged(ChangeEvent event) { Rectangle viewRect = getVisibleArea(); VisibleAreaEvent visibleAreaEvent = new VisibleAreaEvent(myEditor, myLastViewRect, viewRect); if (!myViewportPositioned && viewRect.height > 0) { myViewportPositioned = true; if (adjustVerticalOffsetIfNecessary()) { return; } } myLastViewRect = viewRect; for (VisibleAreaListener listener : myVisibleAreaListeners) { listener.visibleAreaChanged(visibleAreaEvent); } } }); myDocumentListener = new DocumentAdapter() { @Override public void beforeDocumentChange(DocumentEvent e) { cancelAnimatedScrolling(true); } }; myEditor.getDocument().addDocumentListener(myDocumentListener); }
@Override protected void dispose() { finishPreviousPreviewSearch(); if (mySearchRescheduleOnCancellationsAlarm != null) Disposer.dispose(mySearchRescheduleOnCancellationsAlarm); if (myUsagePreviewPanel != null) Disposer.dispose(myUsagePreviewPanel); for(Map.Entry<EditorTextField, DocumentAdapter> e: myComboBoxListeners.entrySet()) { e.getKey().removeDocumentListener(e.getValue()); } myComboBoxListeners.clear(); if (myScopePanel != null) myPreviousResultsExpandedState = myScopePanel.isExpanded(); super.dispose(); }
private void addJBDocumentListener(com.intellij.openapi.editor.Document doc, final JComponent textField) { DocumentAdapter listener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent event) { saveState(textField); } }; Disposable disposable = getDisposable(); if (disposable != null) { doc.addDocumentListener(listener, disposable); } else { doc.addDocumentListener(listener); } }
@Override public void addTargetEditorListener(@NotNull final PushTargetEditorListener listener) { myDestTargetPanel.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { super.documentChanged(e); listener.onTargetInEditModeChanged(myDestTargetPanel.getText()); } }); }
public void createUIComponents() { myRepositoryURL = new EditorComboBox(""); myRepositoryURL.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onChangePullSource(); } }); }
@Override protected JComponent getComponent() { JPanel previewPanel = new JPanel(new BorderLayout()); previewPanel.add(getPreviewEditor().getComponent(), BorderLayout.CENTER); previewPanel.setBorder(new EmptyBorder(2, 2, 6, 2)); DocumentAdapter documentAdapter = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { final TextResult value = templateState.getVariableValue(InplaceRefactoring.PRIMARY_VARIABLE_NAME); if (value != null) { updateTitle(getVariable(), value.getText()); } } } }; myEditor.getDocument().addDocumentListener(documentAdapter); myDelegateCB = new JBCheckBox("Delegate via overloading method"); myDelegateCB.setMnemonic('l'); myDelegateCB.setFocusable(false); JPanel panel = new JPanel(new BorderLayout()); panel.add(previewPanel, BorderLayout.CENTER); panel.add(myDelegateCB, BorderLayout.SOUTH); return panel; }
/** Invalidate tree upon doc change */ public void registerStructureViewModel(final Editor editor, final STGroupStructureViewModel model) { final Document doc = editor.getDocument(); final DocumentListener listener = new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { model.invalidate(); } }; DocumentListener oldListener = doc.getUserData(EDITOR_STRUCTVIEW_LISTENER_KEY); if ( oldListener!=null ) { doc.removeDocumentListener(oldListener); } doc.putUserData(EDITOR_STRUCTVIEW_LISTENER_KEY, listener); doc.addDocumentListener(listener); }
private void createUIComponents() { myMainPanel = new JPanel(); myWithBrowseButtonReference = createPackageChooser(); myClassPackageChooser = createPackageChooser(); myInnerClassChooser = new ClassNameReferenceEditor(myProject, null, ProjectScope.getProjectScope(myProject)); myInnerClassChooser.addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { validateButtons(); } }); // override CardLayout sizing behavior myCardPanel = new JPanel() { public Dimension getMinimumSize() { return myHavePackages ? myMovePackagePanel.getMinimumSize() : myMoveClassPanel.getMinimumSize(); } public Dimension getPreferredSize() { return myHavePackages ? myMovePackagePanel.getPreferredSize() : myMoveClassPanel.getPreferredSize(); } }; myDestinationFolderCB = new DestinationFolderComboBox() { @Override public String getTargetPackage() { return MoveClassesOrPackagesDialog.this.getTargetPackage(); } }; }
protected JComponent createNorthPanel() { final JPanel main = new JPanel(new BorderLayout()); final JPanel namePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 2, true, false)); final JLabel nameLabel = new JLabel(); nameLabel.setText(RefactoringBundle.message("changeSignature.name.prompt")); namePanel.add(nameLabel); namePanel.add(myNameField); nameLabel.setLabelFor(myNameField); myNameField.getDocument().addDocumentListener(new DocumentAdapter() { public void documentChanged(DocumentEvent e) { update(); } }); myVisibilityPanel = createVisibilityPanel(); final JPanel visibilityAndName = new JPanel(new BorderLayout(2, 0)); visibilityAndName.add(myVisibilityPanel, BorderLayout.WEST); visibilityAndName.add(namePanel, BorderLayout.CENTER); main.add(visibilityAndName, BorderLayout.CENTER); setOKActionEnabled(false); setOKActionEnabled(JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(myNameField.getText())); final JPanel options = new JPanel(new BorderLayout()); options.add(createOptionsPanel(), BorderLayout.WEST); main.add(options, BorderLayout.SOUTH); return main; }
public FileStatusManagerImpl(Project project, StartupManager startupManager, @SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) { myProject = project; startupManager.registerPreStartupActivity(new Runnable() { @Override public void run() { DocumentAdapter documentListener = new DocumentAdapter() { public void documentChanged(DocumentEvent event) { VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument()); if (file != null) { refreshFileStatusFromDocument(file, event.getDocument()); } } }; final EditorFactory factory = EditorFactory.getInstance(); if (factory != null) { factory.getEventMulticaster().addDocumentListener(documentListener, myProject); } } }); startupManager.registerPostStartupActivity(new DumbAwareRunnable() { public void run() { fileStatusesChanged(); } }); }
@Override protected void dispose() { for(Map.Entry<EditorTextField, DocumentAdapter> e: myComboBoxListeners.entrySet()) { e.getKey().removeDocumentListener(e.getValue()); } myComboBoxListeners.clear(); super.dispose(); }
private Editor createEditor() { EditorFactory editorFactory = EditorFactory.getInstance(); Document doc = myFile == null ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText()) : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile); Editor editor = myProject == null ? editorFactory.createEditor(doc) : editorFactory.createEditor(doc, myProject); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); editorSettings.setAdditionalColumnsCount(3); editorSettings.setAdditionalLinesCount(3); EditorColorsScheme scheme = editor.getColorsScheme(); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); editor.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onTextChanged(); } }); ((EditorEx)editor).setHighlighter(createHighlighter()); mySplitter.setFirstComponent(editor.getComponent()); return editor; }
public void createUIComponents() { myRepositoryURL = new EditorComboBox(""); final HgRememberedInputs rememberedInputs = HgRememberedInputs.getInstance(project); myRepositoryURL.setHistory(ArrayUtil.toObjectArray(rememberedInputs.getRepositoryUrls(), String.class)); myRepositoryURL.addDocumentListener(new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { onChangePullSource(); } }); }