Unverified Commit 53f76f45 authored by Neil C Smith's avatar Neil C Smith Committed by GitHub
Browse files

Merge pull request #2719 from KacerCZ/netbeans-5301-fix-html-completion-colors

[NETBEANS-5301] Fixed readability of HTML code completion items
parents 818d41ab bf0e82d0
...@@ -62,7 +62,8 @@ import org.openide.xml.XMLUtil; ...@@ -62,7 +62,8 @@ import org.openide.xml.XMLUtil;
public class HtmlCompletionItem implements CompletionItem { public class HtmlCompletionItem implements CompletionItem {
protected static final int DEFAULT_SORT_PRIORITY = 20; protected static final int DEFAULT_SORT_PRIORITY = 20;
private static final String END_FONT = "</font>"; // NOI18N
//----------- Factory methods -------------- //----------- Factory methods --------------
public static HtmlCompletionItem createTag(HtmlTag tag, String name, int substitutionOffset, String helpId, boolean possible) { public static HtmlCompletionItem createTag(HtmlTag tag, String name, int substitutionOffset, String helpId, boolean possible) {
return new Tag(tag, name, substitutionOffset, helpId, possible); return new Tag(tag, name, substitutionOffset, helpId, possible);
...@@ -110,7 +111,8 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -110,7 +111,8 @@ public class HtmlCompletionItem implements CompletionItem {
public static HtmlCompletionItem createFileCompletionItem(FileObject file, int substitutionOffset) { public static HtmlCompletionItem createFileCompletionItem(FileObject file, int substitutionOffset) {
boolean folder = file.isFolder(); boolean folder = file.isFolder();
String name = new StringBuilder().append(file.getNameExt()).append(folder ? '/' : "").toString(); String name = new StringBuilder().append(file.getNameExt()).append(folder ? '/' : "").toString();
Color color = folder ? Color.BLUE : null; // Should match color in o.n.m.web.common.ui.api.FileReferenceCompletion.getItems()
Color color = folder ? new Color(224, 160, 65) : null;
ImageIcon icon = FileReferenceCompletion.getIcon(file); ImageIcon icon = FileReferenceCompletion.getIcon(file);
return new FileAttributeValue(folder, name, substitutionOffset, color, icon); return new FileAttributeValue(folder, name, substitutionOffset, color, icon);
...@@ -422,7 +424,7 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -422,7 +424,7 @@ public class HtmlCompletionItem implements CompletionItem {
= ImageUtilities.loadImageIcon("org/netbeans/modules/html/editor/resources/mathml.png", false); // NOI18N = ImageUtilities.loadImageIcon("org/netbeans/modules/html/editor/resources/mathml.png", false); // NOI18N
private static final Color GRAY_COLOR = Color.GRAY; private static final Color GRAY_COLOR = Color.GRAY;
private static final Color DEFAULT_FG_COLOR = new Color(0, 0, 0xFF); private static final Color DEFAULT_FG_COLOR = new Color(64, 64, 217);
private boolean possible; private boolean possible;
private HtmlTag tag; private HtmlTag tag;
...@@ -455,19 +457,19 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -455,19 +457,19 @@ public class HtmlCompletionItem implements CompletionItem {
@Override @Override
protected String getLeftHtmlText() { protected String getLeftHtmlText() {
Color tagColor = possible ? DEFAULT_FG_COLOR : GRAY_COLOR;
boolean isPossibleHtmlTag = possible && tag != null && tag.getTagClass() == HtmlTagType.HTML;
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
if (possible) { if (isPossibleHtmlTag) {
b.append("<font color=#"); b.append("<b>");
b.append(hexColorCode(DEFAULT_FG_COLOR)); }
b.append(">&lt;"); b.append(getHtmlColor(tagColor));
b.append(getItemText()); b.append("&lt;"); // NO18N
b.append("&gt;</font>"); b.append(getItemText());
} else { b.append("&gt;"); // NOI18N
b.append("<font color=#"); b.append(END_FONT);
b.append(hexColorCode(GRAY_COLOR)); if (isPossibleHtmlTag) {
b.append(">&lt;"); b.append("</b>");
b.append(getItemText());
b.append("&gt;</font>");
} }
return b.toString(); return b.toString();
} }
...@@ -570,7 +572,7 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -570,7 +572,7 @@ public class HtmlCompletionItem implements CompletionItem {
@Override @Override
protected String getLeftHtmlText() { protected String getLeftHtmlText() {
return (type.bold ? "<b>" : "") + //NOI18N return (type.bold ? "<b>" : "") + //NOI18N
"<font color=#" + hexColorCode(type.color) + ">&lt;/" + getItemText() + "&gt;</font>" + //NOI18N getHtmlColor(type.color) + "&lt;/" + getItemText() + "&gt;" + END_FONT + //NOI18N
(type.bold ? "</b>" : ""); //NOI18N (type.bold ? "</b>" : ""); //NOI18N
} }
...@@ -634,11 +636,11 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -634,11 +636,11 @@ public class HtmlCompletionItem implements CompletionItem {
strVal = Character.toString(value); strVal = Character.toString(value);
} }
return new StringBuilder() return new StringBuilder()
.append("<b><font color=#") .append("<b>") // NOI18N
.append(hexColorCode(FG)) .append(getHtmlColor(FG))
.append(">")
.append(strVal) .append(strVal)
.append("</font></b>").toString(); //NOI18N .append(END_FONT)
.append("</b>").toString(); // NOI18N
} }
} }
...@@ -738,11 +740,9 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -738,11 +740,9 @@ public class HtmlCompletionItem implements CompletionItem {
if (required) { if (required) {
sb.append("<b>"); //NOI18N sb.append("<b>"); //NOI18N
} }
sb.append("<font color=#"); //NOI18N sb.append(getHtmlColor(getAttributeColor()));
sb.append(hexColorCode(getAttributeColor()));
sb.append(">"); //NOI18N
sb.append(getItemText()); sb.append(getItemText());
sb.append("</font>"); //NOI18N sb.append(END_FONT);
if (required) { if (required) {
sb.append("</b>"); //NOI18N sb.append("</b>"); //NOI18N
} }
...@@ -772,11 +772,9 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -772,11 +772,9 @@ public class HtmlCompletionItem implements CompletionItem {
if (required) { if (required) {
sb.append("<b>"); //NOI18N sb.append("<b>"); //NOI18N
} }
sb.append("<font color=#"); //NOI18N sb.append(getHtmlColor(ATTR_NAME_COLOR));
sb.append(hexColorCode(ATTR_NAME_COLOR));
sb.append(">"); //NOI18N
sb.append(getItemText()); sb.append(getItemText());
sb.append("</font>"); //NOI18N sb.append(END_FONT);
if (required) { if (required) {
sb.append("</b>"); //NOI18N sb.append("</b>"); //NOI18N
} }
...@@ -813,11 +811,9 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -813,11 +811,9 @@ public class HtmlCompletionItem implements CompletionItem {
return getItemText(); return getItemText();
} else { } else {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<font color=#"); //NOI18N sb.append(getHtmlColor(color));
sb.append(hexColorCode(color));
sb.append(">"); //NOI18N
sb.append(getItemText()); sb.append(getItemText());
sb.append("</font>"); //NOI18N sb.append(END_FONT);
return sb.toString(); return sb.toString();
} }
} }
...@@ -895,4 +891,8 @@ public class HtmlCompletionItem implements CompletionItem { ...@@ -895,4 +891,8 @@ public class HtmlCompletionItem implements CompletionItem {
} }
return s; return s;
} }
private static String getHtmlColor(Color c) {
return "<font color=#" + hexColorCode(c) + ">"; // NOI18N
}
} }
...@@ -111,7 +111,8 @@ public abstract class FileReferenceCompletion<T> implements ValueCompletion<T> { ...@@ -111,7 +111,8 @@ public abstract class FileReferenceCompletion<T> implements ValueCompletion<T> {
|| fileNamePart.equals(".") // ../.| case || fileNamePart.equals(".") // ../.| case
|| fileNamePart.equals("..")) //../..| case || fileNamePart.equals("..")) //../..| case
) { // NOI18N ) { // NOI18N
result.add(createGoUpItem(anchor, Color.BLUE, PACKAGE_ICON)); // NOI18N // Should match color in o.n.m.html.editor.api.completion.HtmlCompletionItem.createFileCompletionItem()
result.add(createGoUpItem(anchor, new Color(224, 160, 65), PACKAGE_ICON));
} }
} }
} catch (FileStateInvalidException | IllegalArgumentException ex) { } catch (FileStateInvalidException | IllegalArgumentException ex) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment