This commit is contained in:
Alexey Kudravtsev
2013-10-23 12:56:29 +04:00
parent c7622f7675
commit 745f73c535
5 changed files with 42 additions and 12 deletions
@@ -47,10 +47,12 @@ import java.util.List;
// TODO[pegov]: should extend ComboBox not JComboBox!
public class EditorComboBox extends JComboBox implements DocumentListener {
public static TextComponentAccessor<EditorComboBox> COMPONENT_ACCESSOR = new TextComponentAccessor<EditorComboBox>() {
@Override
public String getText(EditorComboBox component) {
return component.getText();
}
@Override
public void setText(EditorComboBox component, String text) {
component.setText(text);
}
@@ -86,6 +88,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
enableEvents(AWTEvent.KEY_EVENT_MASK);
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Editor editor = myEditorField != null ? myEditorField.getEditor() : null;
if (editor != null) {
@@ -116,12 +119,14 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
uninstallDocumentListener(false);
}
@Override
public void beforeDocumentChange(DocumentEvent event) {
for (DocumentListener documentListener : myDocumentListeners) {
documentListener.beforeDocumentChange(event);
}
}
@Override
public void documentChanged(DocumentEvent event) {
for (DocumentListener documentListener : myDocumentListeners) {
documentListener.documentChanged(event);
@@ -171,8 +176,10 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
public void setText(final String text) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
myDocument.replaceString(0, myDocument.getTextLength(), text);
if (myEditorField != null && myEditorField.getEditor() != null) {
@@ -231,20 +238,25 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
}
private class MyEditor implements ComboBoxEditor {
@Override
public void addActionListener(ActionListener l) {
}
@Override
public Component getEditorComponent() {
return myEditorField;
}
@Override
public Object getItem() {
return myDocument.getText();
}
@Override
public void removeActionListener(ActionListener l) {
}
@Override
public void selectAll() {
if (myEditorField != null) {
final Editor editor = myEditorField.getEditor();
@@ -254,6 +266,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
}
}
@Override
public void setItem(Object anObject) {
if (anObject != null) {
EditorComboBox.this.setText((String)anObject);
@@ -263,6 +276,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
}
}
@Override
public void addNotify() {
releaseEditor();
setEditor();
@@ -298,6 +312,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
return new ComboboxEditorTextField(document, project, fileType, isViewer);
}
@Override
public void removeNotify() {
super.removeNotify();
if (myEditorField != null) {
@@ -315,6 +330,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
}
}
@Override
public void setFont(Font font) {
super.setFont(font);
if (myEditorField != null && myEditorField.getEditor() != null) {
@@ -333,6 +349,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
return true;
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (myEditorField == null) {
@@ -341,6 +358,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
myEditorField.setEnabled(enabled);
}
@Override
public Dimension getPreferredSize() {
if (UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula()) {
return super.getPreferredSize();
@@ -361,6 +379,7 @@ public class EditorComboBox extends JComboBox implements DocumentListener {
return new Dimension(100, UIUtil.fixComboBoxHeight(20));
}
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
if (!((EditorEx)myEditorField.getEditor()).processKeyTyped(e)) {
return super.processKeyBinding(ks, e, condition, pressed);
@@ -312,7 +312,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener,
return super.isFocusOwner();
}
void releaseEditor(final Editor editor) {
void releaseEditor(@NotNull final Editor editor) {
if (myProject != null && myIsViewer) {
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
if (psiFile != null) {
@@ -333,7 +333,8 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener,
if (application.isUnitTestMode() || application.isDispatchThread()) {
runnable.run();
} else {
}
else {
application.invokeLater(runnable);
}
}
@@ -599,13 +600,12 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener,
if (isEnabled() != enabled) {
super.setEnabled(enabled);
myIsViewer = !enabled;
if (myEditor == null) {
EditorEx editor = myEditor;
if (editor == null) {
return;
}
Editor editor = myEditor;
releaseEditor(editor);
myEditor = createEditor();
add(myEditor.getComponent(), BorderLayout.CENTER);
initEditor();
revalidate();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ public class ConvertingIterator <Domain, Range> implements Iterator<Range> {
private final Convertor<Domain, Range> myConvertor;
public static class IdConvertor <T> implements Convertor<T, T> {
@Override
public T convert(T object) {
return object;
}
@@ -35,14 +36,17 @@ public class ConvertingIterator <Domain, Range> implements Iterator<Range> {
myConvertor = convertor;
}
@Override
public boolean hasNext() {
return myBaseIterator.hasNext();
}
@Override
public Range next() {
return myConvertor.convert(myBaseIterator.next());
}
@Override
public void remove() {
myBaseIterator.remove();
}
@@ -50,6 +54,7 @@ public class ConvertingIterator <Domain, Range> implements Iterator<Range> {
public static <Domain, Intermediate, Range> Convertor<Domain, Range> composition(final Convertor<Domain, Intermediate> convertor1,
final Convertor<Intermediate, Range> convertor2) {
return new Convertor<Domain, Range>() {
@Override
public Range convert(Domain domain) {
return convertor2.convert(convertor1.convert(domain));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.intellij.util.containers;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Conditions;
import com.intellij.util.ReflectionCache;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -35,12 +36,13 @@ public class FilteringIterator<Dom, E extends Dom> implements Iterator<E> {
private Dom myCurrent;
private Boolean myCurrentPassedFilter = null;
public static final Condition NOT_NULL = new Condition() {
@Override
public boolean value(Object t) {
return t != null;
}
};
public FilteringIterator(Iterator<Dom> baseIterator, Condition<Dom> filter) {
public FilteringIterator(@NotNull Iterator<Dom> baseIterator, @NotNull Condition<Dom> filter) {
myBaseIterator = baseIterator;
myFilter = filter;
}
@@ -54,6 +56,7 @@ public class FilteringIterator<Dom, E extends Dom> implements Iterator<E> {
myNextObtained = true;
}
@Override
public boolean hasNext() {
obtainNext();
if (!myCurrentIsValid) return false;
@@ -78,6 +81,7 @@ public class FilteringIterator<Dom, E extends Dom> implements Iterator<E> {
return passed;
}
@Override
public E next() {
if (!hasNext()) throw new NoSuchElementException();
E result = (E)myCurrent;
@@ -89,6 +93,7 @@ public class FilteringIterator<Dom, E extends Dom> implements Iterator<E> {
* Works after call {@link #next} until call {@link #hasNext}
* @throws IllegalStateException if {@link #hasNext} called
*/
@Override
public void remove() {
if (myNextObtained) throw new IllegalStateException();
myBaseIterator.remove();
@@ -121,6 +126,7 @@ public class FilteringIterator<Dom, E extends Dom> implements Iterator<E> {
myInstancesClass = instancesClass;
}
@Override
public boolean value(Object object) {
return myInstancesClass.isInstance(object);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ public class WeakReferenceArray<T> {
return doCompress(myReferences, trackIndex);
}
private int doCompress(MyWeakReference[] references, int trackIndex) {
private int doCompress(MyWeakReference[] newReferences, int trackIndex) {
myCorpseCounter = 0;
int validIndex = 0;
int newIndex = -1;
@@ -141,7 +141,7 @@ public class WeakReferenceArray<T> {
else {
LOG.assertTrue(validIndex == i);
}
aliveReference.moveTo(myReferences, references, validIndex);
aliveReference.moveTo(myReferences, newReferences, validIndex);
validIndex++;
}