diff options
| author | Stephan Wahlbrink | 2021-08-03 18:21:53 +0000 |
|---|---|---|
| committer | Stephan Wahlbrink | 2021-08-04 11:20:15 +0000 |
| commit | 110c06042dc6932065a25c674154235c94e1cd62 (patch) | |
| tree | 88f8ec423312530a98357fc63bb65f1f226a787a | |
| parent | a52790179cf521153db1cbfa2cb6f31d468795b9 (diff) | |
| download | org.eclipse.statet-r-110c06042dc6932065a25c674154235c94e1cd62.tar.gz org.eclipse.statet-r-110c06042dc6932065a25c674154235c94e1cd62.tar.xz org.eclipse.statet-r-110c06042dc6932065a25c674154235c94e1cd62.zip | |
Bug 575176: [R-Help] Improve rendering for dark theme
Change-Id: I52574dab612bd310663d7833080054adc75a1097
4 files changed, 332 insertions, 168 deletions
diff --git a/r/org.eclipse.statet.r.ui/META-INF/MANIFEST.MF b/r/org.eclipse.statet.r.ui/META-INF/MANIFEST.MF index 0483cb38..83fc3432 100644 --- a/r/org.eclipse.statet.r.ui/META-INF/MANIFEST.MF +++ b/r/org.eclipse.statet.r.ui/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Require-Bundle: org.eclipse.statet.ecommons.runtime.core;bundle-version="[4.5.0, org.eclipse.core.databinding.beans, org.eclipse.jface.databinding, org.eclipse.ui.forms, + org.eclipse.e4.ui.services, org.eclipse.ui.views, org.eclipse.ui.ide, org.eclipse.compare, diff --git a/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpInfoHoverCreator.java b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpInfoHoverCreator.java index b946c37d..6e8ade27 100644 --- a/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpInfoHoverCreator.java +++ b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpInfoHoverCreator.java @@ -304,8 +304,8 @@ class RHelpInfoControl extends AbstractInformationControl implements IInformatio public void keyReleased(final KeyEvent e) {} }); - setBackgroundColor(RHelpUIServlet.getDocBackgroundColor()); - setForegroundColor(RHelpUIServlet.getDocForegroundColor()); + setBackgroundColor(RHelpWorkbenchStyle.getDocBackgroundColor()); + setForegroundColor(RHelpWorkbenchStyle.getDocForegroundColor()); if ((this.mode & MODE_FOCUS) != 0) { initActions(this.handlerCollection); diff --git a/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpUIServlet.java b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpUIServlet.java index 72259341..a15649e1 100644 --- a/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpUIServlet.java +++ b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpUIServlet.java @@ -14,7 +14,7 @@ package org.eclipse.statet.internal.r.ui.rhelp; -import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; +import static org.eclipse.statet.internal.r.ui.rhelp.RHelpWorkbenchStyle.appendCssColor; import java.io.PrintWriter; import java.nio.file.Path; @@ -30,22 +30,15 @@ import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.JFacePreferences; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.FontDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.internal.editors.text.EditorsPlugin; import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.jcommons.lang.Nullable; @@ -76,139 +69,57 @@ public class RHelpUIServlet extends RHelpHttpServlet implements IPropertyChangeL static final String HOVER_STYLE= "hover"; //$NON-NLS-1$ - private static final String[] DEFAULT_MATCH_COLORS= new String[] { - ".SMATCH-A { background: #ceccf7; }\n", - ".SMATCH-B { background: #ffffcf; }\n", - ".SMATCH-C { background: aquamarine; }\n", - ".SMATCH-D { background: palegreen; }\n", - ".SMATCH-E { background: coral; }\n", - ".SMATCH-F { background: wheat; }\n", - ".SMATCH-G { background: khaki; }\n", - ".SMATCH-H { background: lime; }\n", - ".SMATCH-I { background: deepskyblue; }\n", - ".SMATCH-J { background: plum; }\n", - }; - - static Color getDocBackgroundColor() { - return nonNullAssert(JFaceResources.getColorRegistry() - .get("org.eclipse.statet.workbench.themes.DocViewBackgroundColor") ); //$NON-NLS-1$ - } - - static Color getDocForegroundColor() { - return nonNullAssert(JFaceResources.getColorRegistry() - .get("org.eclipse.statet.workbench.themes.DocViewColor") ); //$NON-NLS-1$ - } - - - private static void appendCssColor(final StringBuilder sb, final RGB color) { - sb.append('#'); - String s= Integer.toHexString(color.red); - if (s.length() == 1) { - sb.append('0'); - } - sb.append(s); - s= Integer.toHexString(color.green); - if (s.length() == 1) { - sb.append('0'); - } - sb.append(s); - s= Integer.toHexString(color.blue); - if (s.length() == 1) { - sb.append('0'); - } - sb.append(s); - } - - private static void appendELinkColors(final StringBuilder sb, final RGB foregroundColor) { - final RGB hyperlinkColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB(JFacePreferences.HYPERLINK_COLOR) ); - final RGB hyperlinkActiveColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB(JFacePreferences.ACTIVE_HYPERLINK_COLOR) ); - sb.append("a { color: "); //$NON-NLS-1$ - appendCssColor(sb, hyperlinkColor); - sb.append("; }\n");//$NON-NLS-1$ - sb.append("a:hover, a:active, a:focus { color: "); //$NON-NLS-1$ - appendCssColor(sb, hyperlinkActiveColor); - sb.append("; }\n"); //$NON-NLS-1$ - sb.append("a:visited { color: "); //$NON-NLS-1$ - appendCssColor(sb, new RGB( - (hyperlinkColor.red + ((hyperlinkColor.red <= 127) ? +64 : -64)), - (hyperlinkColor.green + foregroundColor.green) / 2, - (hyperlinkColor.blue + ((hyperlinkColor.blue > 32) ? -32 : +32) + foregroundColor.blue ) / 2 )); - sb.append("; }\n"); //$NON-NLS-1$ - } - - private static void appendMatchColors(final StringBuilder sb) { - int i= 0; - final RGB rgb= PreferenceConverter.getColor( - EditorsPlugin.getDefault().getPreferenceStore(), - "searchResultIndicationColor"); //$NON-NLS-1$ - if (rgb != null) { - sb.append(".SMATCH-A { background: "); - appendCssColor(sb, rgb); - sb.append("; }\n"); //$NON-NLS-1$ - i++; - } - while (i < DEFAULT_MATCH_COLORS.length) { - sb.append(DEFAULT_MATCH_COLORS[i++]); - } - } - - public static class Browse extends RHelpUIServlet { private static final long serialVersionUID= 1L; @Override protected void collectCss(final StringBuilder sb) { - final RGB docBackgroundColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB("org.eclipse.statet.workbench.themes.DocViewBackgroundColor") ); //$NON-NLS-1$ - final RGB docForegroundColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB("org.eclipse.statet.workbench.themes.DocViewColor") ); //$NON-NLS-1$ - final RGB borderColor= Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).getRGB(); + final var style= new RHelpWorkbenchStyle(); - { final FontDescriptor docFontDescr= JFaceResources - .getFontDescriptor("org.eclipse.statet.workbench.themes.DocViewFont"); //$NON-NLS-1$ - final FontData fontData= docFontDescr.getFontData()[0]; - - sb.append("body { font-family: '"); //$NON-NLS-1$ - sb.append(fontData.getName()); - sb.append("'; font-size:"); //$NON-NLS-1$ - sb.append(fontData.getHeight()); - sb.append("pt; color:"); //$NON-NLS-1$ - appendCssColor(sb, docForegroundColor); - sb.append("; background:"); //$NON-NLS-1$ - appendCssColor(sb, docBackgroundColor); - sb.append("; }\n"); //$NON-NLS-1$ - } + sb.append("body { "); //$NON-NLS-1$ + style.appendFont(sb, style.getDocFontDescr()); + sb.append("}\n"); //$NON-NLS-1$ - appendELinkColors(sb, docForegroundColor); + sb.append("@media only screen {\n"); //$NON-NLS-1$ - sb.append("div.toc a, div.toc a:visited { color: "); //$NON-NLS-1$ - appendCssColor(sb, docForegroundColor); - sb.append("; }\n"); //$NON-NLS-1$ + sb.append("html {"); //$NON-NLS-1$ + style.appendRootColors(sb); + sb.append("}\n"); //$NON-NLS-1$ + sb.append("body { " //$NON-NLS-1$ + + "margin: "); //$NON-NLS-1$ + sb.append(LayoutUtils.defaultVSpacing()).append("px "); //$NON-NLS-1$ + sb.append(LayoutUtils.defaultHSpacing()).append("px; "); //$NON-NLS-1$ + style.appendScreenColors(sb); + sb.append("}\n"); //$NON-NLS-1$ - sb.append("@media screen {\n"); //$NON-NLS-1$ + style.appendELinkColors(sb); - sb.append("body { margin: "); //$NON-NLS-1$ - sb.append(LayoutUtils.defaultVSpacing()); - sb.append("px "); //$NON-NLS-1$ - sb.append(LayoutUtils.defaultHSpacing()); - sb.append("px; }\n"); //$NON-NLS-1$ + sb.append("div.toc { " //$NON-NLS-1$ + + "display: inline; " //$NON-NLS-1$ + + "float: right; " //$NON-NLS-1$ + + "border: 1px solid "); //$NON-NLS-1$ + appendCssColor(sb, style.getDocBorderColorRGB()).append("; "); //$NON-NLS-1$ + sb.append("}\n"); //$NON-NLS-1$ - sb.append("div.toc { display: inline; float: right; border: 1px solid "); //$NON-NLS-1$ - appendCssColor(sb, borderColor); + sb.append("div.toc a, div.toc a:visited { " //$NON-NLS-1$ + + "color: "); //$NON-NLS-1$ + appendCssColor(sb, style.getDocForegroundColorRGB()).append("; "); //$NON-NLS-1$ sb.append("; }\n"); //$NON-NLS-1$ - sb.append("span.mnemonic, div.toc a.mnemonic { text-decoration: underline; }\n"); //$NON-NLS-1$ - sb.append("hr { border: 0; height: 1px; background: " ); //$NON-NLS-1$ - appendCssColor(sb, borderColor); - sb.append("; }\n"); //$NON-NLS-1$ + sb.append("span.mnemonic, div.toc a.mnemonic { " //$NON-NLS-1$ + + "text-decoration: underline; " //$NON-NLS-1$ + + "}\n" ); //$NON-NLS-1$ + sb.append("hr { " //$NON-NLS-1$ + + "border: 0; " //$NON-NLS-1$ + + "height: 1px; " //$NON-NLS-1$ + + "background: " ); //$NON-NLS-1$ + appendCssColor(sb, style.getDocBorderColorRGB()).append("; "); //$NON-NLS-1$ + sb.append("}\n"); //$NON-NLS-1$ - sb.append("}\n" ); // @media //$NON-NLS-1$ + sb.append("}\n"); // @media //$NON-NLS-1$ - appendMatchColors(sb); + style.appendMatchColors(sb); super.collectCss(sb); } @@ -221,37 +132,39 @@ public class RHelpUIServlet extends RHelpHttpServlet implements IPropertyChangeL @Override protected void collectCss(final StringBuilder sb) { - final Display display= Display.getCurrent(); - final RGB docBackgroundColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB("org.eclipse.statet.workbench.themes.DocViewBackgroundColor") ); //$NON-NLS-1$ - final RGB docForegroundColor= nonNullAssert(JFaceResources.getColorRegistry() - .getRGB("org.eclipse.statet.workbench.themes.DocViewColor") ); //$NON-NLS-1$ + final var style= new RHelpWorkbenchStyle(); + final int vIndent= Math.max(1, LayoutUtils.defaultVSpacing() / 4); final int hIndent= Math.max(3, LayoutUtils.defaultHSpacing() / 2); - { final FontDescriptor docFontDescr= JFaceResources.getDialogFontDescriptor(); - final FontData fontData= docFontDescr.getFontData()[0]; - sb.append("body { font-family: '"); //$NON-NLS-1$ - sb.append(fontData.getName()); - sb.append("'; font-size: "); //$NON-NLS-1$ - sb.append(fontData.getHeight()); - sb.append("pt; color: "); //$NON-NLS-1$ - appendCssColor(sb, docForegroundColor); - sb.append("; background: "); //$NON-NLS-1$ - appendCssColor(sb, docBackgroundColor); - sb.append("; margin: 0 "); //$NON-NLS-1$ - sb.append(hIndent); - sb.append("px "); //$NON-NLS-1$ - sb.append(vIndent); - sb.append("px; }\n"); //$NON-NLS-1$ - } - appendELinkColors(sb, docForegroundColor); + sb.append("html { "); //$NON-NLS-1$ + style.appendFont(sb, JFaceResources.getDialogFontDescriptor()); + style.appendRootColors(sb); + sb.append("}\n"); //$NON-NLS-1$ + sb.append("body { "); //$NON-NLS-1$ + sb.append("margin: 0 ") //$NON-NLS-1$ + .append(hIndent).append("px ") //$NON-NLS-1$ + .append(vIndent).append("px; "); //$NON-NLS-1$ + style.appendScreenColors(sb); + sb.append("}\n"); //$NON-NLS-1$ - sb.append("h2, h3#description { display: none; }\n"); //$NON-NLS-1$ - sb.append("h3 { font-size: 90%; margin-bottom: 0.4em; }\n"); //$NON-NLS-1$ - sb.append("p, pre { margin-top: 0.4em; margin-bottom: 0.4em; }\n" ); //$NON-NLS-1$ + style.appendELinkColors(sb); - sb.append("hr { visibility: hidden; }\n"); //$NON-NLS-1$ + sb.append("h2, h3#description { " //$NON-NLS-1$ + + "display: none; " //$NON-NLS-1$ + + "}\n"); //$NON-NLS-1$ + sb.append("h3 { " //$NON-NLS-1$ + + "font-size: 90%; " //$NON-NLS-1$ + + "margin-bottom: 0.4em; " //$NON-NLS-1$ + + "}\n"); //$NON-NLS-1$ + sb.append("p, pre { " //$NON-NLS-1$ + + "margin-top: 0.4em; " //$NON-NLS-1$ + + "margin-bottom: 0.4em; " //$NON-NLS-1$ + + "}\n" ); //$NON-NLS-1$ + + sb.append("hr { " //$NON-NLS-1$ + + "visibility: hidden; " //$NON-NLS-1$ + + "}\n"); //$NON-NLS-1$ super.collectCss(sb); } @@ -263,6 +176,9 @@ public class RHelpUIServlet extends RHelpHttpServlet implements IPropertyChangeL private RHelpRCodeScanner rCodeScanner; + private final Runnable updateStyles= this::updateStyles; + private boolean updateStyleScheduled; + @SuppressWarnings("null") public RHelpUIServlet() { @@ -283,19 +199,23 @@ public class RHelpUIServlet extends RHelpHttpServlet implements IPropertyChangeL JFaceResources.getFontRegistry().addListener(this); JFaceResources.getColorRegistry().addListener(this); PreferencesUtil.getSettingsChangeNotifier().addChangeListener(this); - updateStyles(); + + this.updateStyleScheduled= true; + Display.getDefault().syncExec(this.updateStyles); } @Override public void propertyChange(final PropertyChangeEvent event) { - if (event.getProperty().equals("org.eclipse.statet.workbench.themes.DocViewFont") //$NON-NLS-1$ - || event.getProperty().equals("org.eclipse.statet.workbench.themes.DocViewBackgroundColor") //$NON-NLS-1$ - || event.getProperty().equals("org.eclipse.statet.workbench.themes.DocViewColor") //$NON-NLS-1$ - || event.getProperty().equals(JFaceResources.DIALOG_FONT) - || event.getProperty().equals(JFacePreferences.HYPERLINK_COLOR) - || event.getProperty().equals(JFacePreferences.ACTIVE_HYPERLINK_COLOR) - || event.getProperty().equals("searchResultIndicationColor") ) { //$NON-NLS-1$ - updateStyles(); + if (!this.updateStyleScheduled + && (event.getProperty().equals(RHelpWorkbenchStyle.DOC_BACKGROUND_COLOR_KEY) + || event.getProperty().equals(RHelpWorkbenchStyle.DOC_FOREGROUND_COLOR_KEY) + || event.getProperty().equals(RHelpWorkbenchStyle.DOC_FONT_KEY) + || event.getProperty().equals(JFaceResources.DIALOG_FONT) + || event.getProperty().equals(JFacePreferences.HYPERLINK_COLOR) + || event.getProperty().equals(JFacePreferences.ACTIVE_HYPERLINK_COLOR) + || event.getProperty().equals("searchResultIndicationColor") )) { //$NON-NLS-1$ + this.updateStyleScheduled= true; + Display.getDefault().asyncExec(this.updateStyles); } } @@ -355,13 +275,10 @@ public class RHelpUIServlet extends RHelpHttpServlet implements IPropertyChangeL private void updateStyles() { + this.updateStyleScheduled= false; + final StringBuilder sb= new StringBuilder(1024); - UIAccess.getDisplay().syncExec(new Runnable() { - @Override - public void run() { - collectCss(sb); - } - }); + collectCss(sb); sb.append(".header { display: none; }"); //$NON-NLS-1$ this.cssStyle= sb.toString(); } diff --git a/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpWorkbenchStyle.java b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpWorkbenchStyle.java new file mode 100644 index 00000000..558ac056 --- /dev/null +++ b/r/org.eclipse.statet.r.ui/src/org/eclipse/statet/internal/r/ui/rhelp/RHelpWorkbenchStyle.java @@ -0,0 +1,246 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.internal.r.ui.rhelp; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; + +import org.eclipse.jface.preference.JFacePreferences; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.ui.swt.ColorUtils; +import org.eclipse.statet.ecommons.ui.workbench.StylingUtils; + + +@NonNullByDefault +public class RHelpWorkbenchStyle { + + + static final String DOC_BACKGROUND_COLOR_KEY= "org.eclipse.statet.workbench.themes.DocViewBackgroundColor"; //$NON-NLS-1$ + static final String DOC_FOREGROUND_COLOR_KEY= "org.eclipse.statet.workbench.themes.DocViewColor"; //$NON-NLS-1$ + static final String DOC_FONT_KEY= "org.eclipse.statet.workbench.themes.DocViewFont"; //$NON-NLS-1$ + + + static Color getDocBackgroundColor() { + return nonNullAssert(JFaceResources.getColorRegistry().get(DOC_BACKGROUND_COLOR_KEY)); + } + + static Color getDocForegroundColor() { + return nonNullAssert(JFaceResources.getColorRegistry().get(DOC_FOREGROUND_COLOR_KEY)); + } + + + static StringBuilder appendCssColor(final StringBuilder sb, final RGB color) { + sb.append('#'); + String s= Integer.toHexString(color.red); + if (s.length() == 1) { + sb.append('0'); + } + sb.append(s); + s= Integer.toHexString(color.green); + if (s.length() == 1) { + sb.append('0'); + } + sb.append(s); + s= Integer.toHexString(color.blue); + if (s.length() == 1) { + sb.append('0'); + } + sb.append(s); + return sb; + } + + + private static final String[] DEFAULT_MATCH_COLORS= new String[] { + ".SMATCH-A { background: #ceccf7; }\n", //$NON-NLS-1$ + ".SMATCH-B { background: #ffffcf; }\n", //$NON-NLS-1$ + ".SMATCH-C { background: aquamarine; }\n", //$NON-NLS-1$ + ".SMATCH-D { background: palegreen; }\n", //$NON-NLS-1$ + ".SMATCH-E { background: coral; }\n", //$NON-NLS-1$ + ".SMATCH-F { background: wheat; }\n", //$NON-NLS-1$ + ".SMATCH-G { background: khaki; }\n", //$NON-NLS-1$ + ".SMATCH-H { background: lime; }\n", //$NON-NLS-1$ + ".SMATCH-I { background: deepskyblue; }\n", //$NON-NLS-1$ + ".SMATCH-J { background: plum; }\n", //$NON-NLS-1$ + }; + + + private final boolean isThemeStylingRequired; + + private RGB dialogBackgroundColor; + private RGB dialogForegroundColor; + + private RGB scrollbarBackgroundColor; + private RGB scrollbarForegroundColor; + private RGB scrollbarArrowColor; + + private final FontDescriptor docFontDescr; + + private final RGB docBackgroundColor; + private final RGB docForegroundColor; + private final RGB docBorderColor; + + + public RHelpWorkbenchStyle() { + final Display display= nonNullAssert(Display.getCurrent()); + this.isThemeStylingRequired= (StylingUtils.isStylingSupported() + && !StylingUtils.isCurrentThemeMatchingSystem(display) ); + + if (this.isThemeStylingRequired) { + final var stylingEngine= StylingUtils.getStylingEngine(); + final var shell= new Shell(display); + try { + final var composite= new ScrolledComposite(shell, SWT.V_SCROLL); + stylingEngine.style(composite); + this.dialogBackgroundColor= composite.getBackground().getRGB(); + this.dialogForegroundColor= composite.getForeground().getRGB(); + } + finally { + shell.dispose(); + } + } + if (this.dialogBackgroundColor == null || this.dialogForegroundColor == null) { + this.dialogBackgroundColor= display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB(); + this.dialogForegroundColor= display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND).getRGB(); + } + if (this.isThemeStylingRequired) { + switch (StylingUtils.getCurrentThemeType(display)) { + case DARK: + this.scrollbarBackgroundColor= new RGB(23, 23, 23); + this.scrollbarForegroundColor= new RGB(77, 77, 77); + this.scrollbarArrowColor= new RGB(103, 103, 103); + break; + default: + this.scrollbarBackgroundColor= this.dialogBackgroundColor; + this.scrollbarForegroundColor= ColorUtils.blend(this.dialogForegroundColor, this.dialogBackgroundColor, 0.15f); + this.scrollbarArrowColor= ColorUtils.blend(this.dialogForegroundColor, this.dialogBackgroundColor, 0.5f); + break; + } + } + + this.docFontDescr= nonNullAssert(JFaceResources.getFontDescriptor(DOC_FONT_KEY)); + + this.docBackgroundColor= nonNullAssert(JFaceResources.getColorRegistry() + .getRGB(DOC_BACKGROUND_COLOR_KEY) ); + this.docForegroundColor= nonNullAssert(JFaceResources.getColorRegistry() + .getRGB(DOC_FOREGROUND_COLOR_KEY) ); + this.docBorderColor= Display.getCurrent() + .getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).getRGB(); + } + + + public FontDescriptor getDocFontDescr() { + return this.docFontDescr; + } + + public RGB getDocBackgroundColorRGB() { + return this.docBackgroundColor; + } + + public RGB getDocForegroundColorRGB() { + return this.docForegroundColor; + } + + public RGB getDocBorderColorRGB() { + return this.docBorderColor; + } + + + public void appendELinkColors(final StringBuilder sb) { + final RGB hyperlinkColor= nonNullAssert(JFaceResources.getColorRegistry() + .getRGB(JFacePreferences.HYPERLINK_COLOR) ); + final RGB hyperlinkActiveColor= nonNullAssert(JFaceResources.getColorRegistry() + .getRGB(JFacePreferences.ACTIVE_HYPERLINK_COLOR) ); + sb.append("a { color: "); //$NON-NLS-1$ + appendCssColor(sb, hyperlinkColor); + sb.append("; }\n");//$NON-NLS-1$ + sb.append("a:hover, a:active, a:focus { color: "); //$NON-NLS-1$ + appendCssColor(sb, hyperlinkActiveColor); + sb.append("; }\n"); //$NON-NLS-1$ + sb.append("a:visited { color: "); //$NON-NLS-1$ + appendCssColor(sb, new RGB( + (hyperlinkColor.red + ((hyperlinkColor.red <= 127) ? +64 : -64)), + (hyperlinkColor.green + this.docForegroundColor.green) / 2, + (hyperlinkColor.blue + ((hyperlinkColor.blue > 32) ? -32 : +32) + this.docForegroundColor.blue ) / 2 )); + sb.append("; }\n"); //$NON-NLS-1$ + } + + void appendMatchColors(final StringBuilder sb) { + int i= 0; + final RGB rgb= PreferenceConverter.getColor(EditorsPlugin.getDefault().getPreferenceStore(), + "searchResultIndicationColor" ); //$NON-NLS-1$ + if (rgb != null) { + sb.append(".SMATCH-A { background: "); //$NON-NLS-1$ + appendCssColor(sb, rgb); + sb.append("; }\n"); //$NON-NLS-1$ + i++; + } + while (i < DEFAULT_MATCH_COLORS.length) { + sb.append(DEFAULT_MATCH_COLORS[i++]); + } + } + + void appendRootColors(final StringBuilder sb) { + sb.append("color: "); //$NON-NLS-1$ + appendCssColor(sb, this.docForegroundColor).append("; "); //$NON-NLS-1$ + + if (this.isThemeStylingRequired) { + sb.append("scrollbar-color: "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarForegroundColor).append(" "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarBackgroundColor).append(" ;"); //$NON-NLS-1$ + // IE + sb.append("scrollbar-track-color: "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarBackgroundColor).append("; "); //$NON-NLS-1$ + sb.append("scrollbar-base-color: "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarBackgroundColor).append("; "); //$NON-NLS-1$ + sb.append("scrollbar-face-color: "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarForegroundColor).append("; "); //$NON-NLS-1$ + sb.append("scrollbar-arrow-color: "); //$NON-NLS-1$ + appendCssColor(sb, this.scrollbarArrowColor).append("; "); //$NON-NLS-1$ + } + } + + void appendScreenColors(final StringBuilder sb) { + sb.append("color: "); //$NON-NLS-1$ + appendCssColor(sb, this.docForegroundColor).append("; "); //$NON-NLS-1$ + sb.append("background: "); //$NON-NLS-1$ + appendCssColor(sb, this.docBackgroundColor).append("; "); //$NON-NLS-1$ + } + + void appendDialogColors(final StringBuilder sb) { + sb.append("background: "); //$NON-NLS-1$ + appendCssColor(sb, this.dialogBackgroundColor).append("; "); //$NON-NLS-1$ + sb.append("color: "); //$NON-NLS-1$ + appendCssColor(sb, this.dialogForegroundColor).append("; "); //$NON-NLS-1$ + } + + void appendFont(final StringBuilder sb, final FontDescriptor fontDescription) { + final FontData fontData= fontDescription.getFontData()[0]; + sb.append("font-family: '").append(fontData.getName()).append("'; "); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append("font-size: ").append(fontData.getHeight()).append("pt; "); //$NON-NLS-1$ //$NON-NLS-2$ + } + +} |
