mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-82135 Missing images in Quick Documentation Java Doc loaded from jars
fixed new test
This commit is contained in:
+43
-15
@@ -31,7 +31,9 @@ import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -39,12 +41,14 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -77,6 +81,7 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
editor.getCaretModel().moveToOffset(document.getText().indexOf("Test"));
|
||||
DocumentationManager documentationManager = DocumentationManager.getInstance(myProject);
|
||||
documentationManager.showJavaDocInfo(editor, psiFile, false);
|
||||
waitTillDone(documentationManager.getLastAction());
|
||||
JBPopup popup = documentationManager.getDocInfoHint();
|
||||
assertNotNull(popup);
|
||||
DocumentationComponent documentationComponent = (DocumentationComponent)popup.getContent().getComponent(0);
|
||||
@@ -92,7 +97,18 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void waitTillDone(ActionCallback actionCallback) throws InterruptedException {
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start < 300000) {
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(100);
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
if (actionCallback.isProcessed()) return;
|
||||
}
|
||||
fail("Timed out waiting for documentation to show");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static VirtualFile getJarFile(String name) {
|
||||
VirtualFile file = getVirtualFile(new File(JavaTestUtil.getJavaTestDataPath() + "/codeInsight/documentation/" + name));
|
||||
@@ -104,20 +120,32 @@ public class JavaExternalDocumentationTest extends PlatformTestCase {
|
||||
|
||||
private static byte[] getImageDataFromDocumentationComponent(DocumentationComponent documentationComponent) throws Exception {
|
||||
JEditorPane editorPane = (JEditorPane)documentationComponent.getComponent();
|
||||
HTMLDocument document = (HTMLDocument)editorPane.getDocument();
|
||||
HTMLDocument.Iterator it = document.getIterator(HTML.Tag.IMG);
|
||||
assertTrue(it.isValid());
|
||||
String relativeUrl = (String)it.getAttributes().getAttribute(HTML.Attribute.SRC);
|
||||
it.next();
|
||||
assertFalse(it.isValid());
|
||||
URL imageUrl = new URL(document.getBase(), relativeUrl);
|
||||
InputStream stream = imageUrl.openStream();
|
||||
try {
|
||||
return FileUtil.loadBytes(stream);
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
final HTMLDocument document = (HTMLDocument)editorPane.getDocument();
|
||||
final Ref<byte[]> result = new Ref<byte[]>();
|
||||
document.render(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
HTMLDocument.Iterator it = document.getIterator(HTML.Tag.IMG);
|
||||
assertTrue(it.isValid());
|
||||
String relativeUrl = (String)it.getAttributes().getAttribute(HTML.Attribute.SRC);
|
||||
it.next();
|
||||
assertFalse(it.isValid());
|
||||
URL imageUrl = new URL(document.getBase(), relativeUrl);
|
||||
InputStream stream = imageUrl.openStream();
|
||||
try {
|
||||
result.set(FileUtil.loadBytes(stream));
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-15
@@ -92,7 +92,7 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
|
||||
private volatile boolean myIsEmpty;
|
||||
private boolean myIsShown;
|
||||
private final JLabel myElementLabel;
|
||||
private Style myFontSizeStyle;
|
||||
private final MutableAttributeSet myFontSizeStyle = new SimpleAttributeSet();
|
||||
private JSlider myFontSizeSlider;
|
||||
private final JComponent mySettingsPanel;
|
||||
private final MyShowSettingsButton myShowSettingsButton;
|
||||
@@ -552,17 +552,12 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
|
||||
private void setDataInternal(SmartPsiElementPointer element, String text, final Rectangle viewRect, boolean skip) {
|
||||
setElement(element);
|
||||
|
||||
boolean justShown = false;
|
||||
myEditorPane.setText(text);
|
||||
applyFontSize();
|
||||
|
||||
if (!myIsShown && myHint != null && !ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
myEditorPane.setText(text);
|
||||
applyFontSize();
|
||||
myManager.showHint(myHint);
|
||||
myIsShown = justShown = true;
|
||||
}
|
||||
|
||||
if (!justShown) {
|
||||
myEditorPane.setText(text);
|
||||
applyFontSize();
|
||||
myIsShown = true;
|
||||
}
|
||||
|
||||
if (!skip) {
|
||||
@@ -585,9 +580,6 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
|
||||
}
|
||||
|
||||
final StyledDocument styledDocument = (StyledDocument)document;
|
||||
if (myFontSizeStyle == null) {
|
||||
myFontSizeStyle = styledDocument.addStyle("active", null);
|
||||
}
|
||||
|
||||
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
|
||||
EditorColorsScheme scheme = colorsManager.getGlobalScheme();
|
||||
@@ -596,11 +588,10 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
|
||||
StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName());
|
||||
}
|
||||
|
||||
final Style sizeStyle = myFontSizeStyle;
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
styledDocument.setCharacterAttributes(0, styledDocument.getLength(), sizeStyle, false);
|
||||
styledDocument.setCharacterAttributes(0, styledDocument.getLength(), myFontSizeStyle, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+9
@@ -71,6 +71,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -101,6 +102,8 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
|
||||
private static final int ourFlagsForTargetElements = TargetElementUtilBase.getInstance().getAllAccepted();
|
||||
|
||||
private boolean myCloseOnSneeze;
|
||||
|
||||
private ActionCallback myLastAction;
|
||||
|
||||
@Override
|
||||
protected String getToolwindowId() {
|
||||
@@ -671,6 +674,7 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
|
||||
|
||||
private ActionCallback doFetchDocInfo(final DocumentationComponent component, final DocumentationCollector provider, final boolean cancelRequests, final boolean clearHistory) {
|
||||
final ActionCallback callback = new ActionCallback();
|
||||
myLastAction = callback;
|
||||
boolean wasEmpty = component.isEmpty();
|
||||
component.startWait();
|
||||
if (cancelRequests) {
|
||||
@@ -1030,6 +1034,11 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public ActionCallback getLastAction() {
|
||||
return myLastAction;
|
||||
}
|
||||
|
||||
private interface DocumentationCollector {
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user