From 1fd115a6b594a3da568fa8a0383d73b5634b99e8 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Sep 2012 21:15:58 +0400 Subject: [PATCH] inspections view: use editor font settings; borders (IDEA-91395; IDEA-55378) --- .../deadCode/DeadHTMLComposer.java | 11 +---- .../ex/HTMLJavaHTMLComposerImpl.java | 5 +-- .../intellij/codeInspection/HTMLComposer.java | 6 +-- .../codeInspection/ex/DescriptorComposer.java | 5 +-- .../codeInspection/ex/HTMLComposerImpl.java | 12 +---- .../intellij/codeInspection/ui/Browser.java | 44 +++++++++++++++---- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadHTMLComposer.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadHTMLComposer.java index f0e4c7b7651a..f748eae695ce 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadHTMLComposer.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/DeadHTMLComposer.java @@ -216,7 +216,7 @@ public class DeadHTMLComposer extends HTMLComposerImpl { } //noinspection HardCodedStringLiteral - buf.append("
"); + buf.append("
"); if (refElement instanceof RefClass) { RefClassImpl refClass = (RefClassImpl)refElement; if (refClass.isSuspicious()) { @@ -251,9 +251,6 @@ public class DeadHTMLComposer extends HTMLComposerImpl { buf.append(InspectionsBundle.message("inspection.dead.code.problem.synopsis6", nUsageCount)); } } - - //noinspection HardCodedStringLiteral - buf.append("
"); } private static int getDerivedRefsCount(RefMethod refMethod) { @@ -343,8 +340,6 @@ public class DeadHTMLComposer extends HTMLComposerImpl { if (possibleChildren.size() > 0) { if (appendCallees){ appendHeading(buf, InspectionsBundle.message("inspection.export.results.callees")); - @NonNls String font = ""; - buf.append(font); } @NonNls final String ul = ""; buf.append(closeUl); - if (appendCallees){ - @NonNls String closeFont = ""; - buf.append(closeFont); - } } } diff --git a/java/java-impl/src/com/intellij/codeInspection/ex/HTMLJavaHTMLComposerImpl.java b/java/java-impl/src/com/intellij/codeInspection/ex/HTMLJavaHTMLComposerImpl.java index 33c76303c1a0..603787268f81 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ex/HTMLJavaHTMLComposerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/ex/HTMLJavaHTMLComposerImpl.java @@ -324,11 +324,10 @@ public class HTMLJavaHTMLComposerImpl extends HTMLJavaHTMLComposer { myComposer.appendElementReference(buf, ((RefElement)refElement.getOwner()), isPackageIncluded); } else if (isPackageIncluded) { - @NonNls final String color = "color:#808080\">"; - buf.append(" ").append(HTMLComposerImpl.CODE_OPENING).append(HTMLComposerImpl.FONT_OPENING).append(color).append("("); + buf.append(" ").append(HTMLComposerImpl.CODE_OPENING).append("("); myComposer.appendQualifiedName(buf, refElement.getOwner()); // buf.append(RefUtil.getPackageName(refElement)); - buf.append(")").append(HTMLComposerImpl.FONT_CLOSING).append(HTMLComposerImpl.CODE_CLOSING); + buf.append(")").append(HTMLComposerImpl.CODE_CLOSING); } } diff --git a/platform/lang-api/src/com/intellij/codeInspection/HTMLComposer.java b/platform/lang-api/src/com/intellij/codeInspection/HTMLComposer.java index 46c7896baa5a..df4fa2e5b42f 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/HTMLComposer.java +++ b/platform/lang-api/src/com/intellij/codeInspection/HTMLComposer.java @@ -39,9 +39,9 @@ public abstract class HTMLComposer { public static void appendHeading(@NonNls StringBuffer buf, String name){ buf.append( - "     "); + "  "); buf.append(name); - buf.append(":"); + buf.append(""); } public abstract void appendElementReference(StringBuffer buf, RefElement refElement, boolean isPackageIncluded); @@ -55,7 +55,7 @@ public abstract class HTMLComposer { public abstract void startListItem(@NonNls StringBuffer buf); public static void appendAfterHeaderIndention(@NonNls StringBuffer buf) { - buf.append("          "); + buf.append("     "); } public abstract void appendNoProblems(StringBuffer buf); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorComposer.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorComposer.java index 8e3b053f0357..6a91d5396d13 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorComposer.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorComposer.java @@ -112,13 +112,12 @@ public class DescriptorComposer extends HTMLComposerImpl { int idx = 0; for (QuickFix fix : fixes) { //noinspection HardCodedStringLiteral - buf.append(""); buf.append(fix.getName()); //noinspection HardCodedStringLiteral - buf.append(""); + buf.append(""); //noinspection HardCodedStringLiteral buf.append("
"); appendAfterHeaderIndention(buf); @@ -156,7 +155,7 @@ public class DescriptorComposer extends HTMLComposerImpl { } else { //noinspection HardCodedStringLiteral - anchor.append(""); + anchor.append(""); anchor.append(InspectionsBundle.message("inspection.export.results.invalidated.item")); //noinspection HardCodedStringLiteral anchor.append(""); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/HTMLComposerImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/HTMLComposerImpl.java index 71639a3a8339..d48c53a4915a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/HTMLComposerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/HTMLComposerImpl.java @@ -56,10 +56,9 @@ public abstract class HTMLComposerImpl extends HTMLComposer { @NonNls protected static final String NBSP = " "; @NonNls protected static final String CODE_CLOSING = ""; @NonNls protected static final String CODE_OPENING = ""; - @NonNls protected static final String FONT_CLOSING = ""; @NonNls protected static final String B_OPENING = ""; @NonNls protected static final String B_CLOSING = ""; - @NonNls protected static final String FONT_OPENING = ""; @NonNls protected static final String A_HREF_OPENING = ""); buf.append(text); - buf.append(""); + buf.append(""); } } @@ -267,11 +261,9 @@ public abstract class HTMLComposerImpl extends HTMLComposer { public void appendListItem(StringBuffer buf, RefElement refElement) { startListItem(buf); - buf.append(FONT_OPENING); buf.append(CLOSE_TAG); appendElementReference(buf, refElement, true); appendAdditionalListItemInfo(buf, refElement); - buf.append(FONT_CLOSING); doneListItem(buf); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java index 9515d2bd03fb..a5404f14c6a6 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java @@ -26,6 +26,8 @@ import com.intellij.codeInspection.ui.actions.SuppressActionWrapper; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -35,7 +37,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.SideBorder; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -43,6 +44,10 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import javax.swing.text.Document; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLFrameHyperlinkEvent; import java.awt.*; @@ -123,6 +128,7 @@ class Browser extends JPanel { try { String html = generateHTML(newEntity, tool); myHTMLViewer.read(new StringReader(html), null); + setupStyle(); myHTMLViewer.setCaretPosition(0); } catch (Exception e) { @@ -140,6 +146,7 @@ class Browser extends JPanel { try { String html = generateHTML(refEntity, descriptor); myHTMLViewer.read(new StringReader(html), null); + setupStyle(); myHTMLViewer.setCaretPosition(0); } catch (Exception e) { @@ -253,7 +260,27 @@ class Browser extends JPanel { }; myHTMLViewer.addHyperlinkListener(myHyperLinkListener); - add(ScrollPaneFactory.createScrollPane(myHTMLViewer, SideBorder.LEFT), BorderLayout.CENTER); + final JScrollPane pane = ScrollPaneFactory.createScrollPane(myHTMLViewer); + pane.setBorder(null); + add(pane, BorderLayout.CENTER); + setupStyle(); + } + + private void setupStyle() { + Document document = myHTMLViewer.getDocument(); + if (!(document instanceof StyledDocument)) { + return; + } + + StyledDocument styledDocument = (StyledDocument)document; + + EditorColorsManager colorsManager = EditorColorsManager.getInstance(); + EditorColorsScheme scheme = colorsManager.getGlobalScheme(); + + Style style = styledDocument.addStyle("active", null); + StyleConstants.setFontFamily(style, scheme.getEditorFontName()); + StyleConstants.setFontSize(style, scheme.getEditorFontSize()); + styledDocument.setCharacterAttributes(0, document.getLength(), style, false); } public void addClickListener(ClickListener listener) { @@ -295,8 +322,8 @@ class Browser extends JPanel { @SuppressWarnings({"HardCodedStringLiteral"}) private static void insertHeaderFooter(final StringBuffer buf) { - buf.insert(0, ""); - buf.append(""); + buf.insert(0, ""); + buf.append(""); } private String generateHTML(final RefEntity refEntity, final CommonProblemDescriptor descriptor) { @@ -349,20 +376,19 @@ class Browser extends JPanel { } if (!activeSuppressActions.isEmpty()) { int idx = 0; - @NonNls String font = ""; - buf.append(font); @NonNls final String br = "
"; - buf.append(br).append(br); + buf.append(br); HTMLComposerImpl.appendHeading(buf, InspectionsBundle.message("inspection.export.results.suppress")); for (AnAction suppressAction : activeSuppressActions) { buf.append(br); + if (idx == activeSuppressActions.size() - 1) { + buf.append(br); + } HTMLComposer.appendAfterHeaderIndention(buf); @NonNls final String href = "" + suppressAction.getTemplatePresentation().getText() + ""; buf.append(href); idx++; } - @NonNls String closeFont = "
"; - buf.append(closeFont); } } }