diff options
| author | Daniel Rolka | 2014-01-08 10:54:01 +0000 |
|---|---|---|
| committer | Gerrit Code Review @ Eclipse.org | 2014-01-13 14:31:54 +0000 |
| commit | 946c6d54de1d199bb882124673f4ede122a00f89 (patch) | |
| tree | 53cc8446c73cbd6bf37a8873a875c8be5b78b823 | |
| parent | c61f1fb3ef7f4df6e23b73f1499a8235e430ae12 (diff) | |
| download | eclipse.platform.ui-946c6d54de1d199bb882124673f4ede122a00f89.tar.gz eclipse.platform.ui-946c6d54de1d199bb882124673f4ede122a00f89.tar.xz eclipse.platform.ui-946c6d54de1d199bb882124673f4ede122a00f89.zip | |
Bug 423813 - [CSS] Improvement of the CSS theme switching and applyingI20140114-0800
the new stylesheet in runtime
Change-Id: I1c90e9f7f84ab963518982329791e2317a6055ac
Signed-off-by: Daniel Rolka <daniel.rolka@pl.ibm.com>
23 files changed, 416 insertions, 200 deletions
diff --git a/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java b/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java index 407d23d31af..b4fddda09f6 100644 --- a/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java +++ b/bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 Tom Schindl and others. + * Copyright (c) 2010, 2014 Tom Schindl and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Brian de Alwis - added support for multiple CSS engines * Lars Vogel <Lars.Vogel@gmail.com> - Bug 422702 + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.internal.theme; @@ -39,18 +40,12 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.ui.css.core.engine.CSSElementContext; import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry; import org.eclipse.e4.ui.css.core.util.impl.resources.FileResourcesLocatorImpl; import org.eclipse.e4.ui.css.core.util.impl.resources.OSGiResourceLocator; import org.eclipse.e4.ui.css.core.util.resources.IResourceLocator; -import org.eclipse.e4.ui.css.swt.resources.SWTResourcesRegistry; import org.eclipse.e4.ui.css.swt.theme.ITheme; import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; import org.eclipse.osgi.service.datalocation.Location; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -403,7 +398,6 @@ public class ThemeEngine implements IThemeEngine { this.currentTheme = theme; for (CSSEngine engine : cssEngines) { - removeSWTResourceFromCache(engine.getResourcesRegistry()); engine.reset(); } @@ -466,15 +460,6 @@ public class ThemeEngine implements IThemeEngine { sendThemeChangeEvent(restore); } - @SuppressWarnings("restriction") - private void removeSWTResourceFromCache(IResourcesRegistry registry) { - if (registry instanceof SWTResourcesRegistry) { - ((SWTResourcesRegistry) registry) - .removeResourcesByKeyTypeAndType(Object.class, Font.class, - Color.class, Image.class, Cursor.class); - } - } - /** * Broadcast theme-change event using OSGi Event Admin. */ diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ButtonElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ButtonElement.java index 1f8db119fb3..777071aa958 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ButtonElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ButtonElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Angelo Zerr and others. + * Copyright (c) 2009, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.dom; @@ -26,6 +27,7 @@ public class ButtonElement extends ControlElement { private boolean isSelected = false;; private SelectionListener selectionListener = new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { if (!e.widget.isDisposed()) { ButtonElement.this.isSelected = getButton().getSelection(); @@ -39,29 +41,36 @@ public class ButtonElement extends ControlElement { this.isSelected = button.getSelection(); } + @Override public void initialize() { super.initialize(); - if (!dynamicEnabled) return; - - + if (!dynamicEnabled) { + return; + } + + Button button = getButton(); button.addSelectionListener(selectionListener); } + @Override public void dispose() { super.dispose(); - if (!dynamicEnabled) return; - + if (!dynamicEnabled) { + return; + } + Button button = getButton(); if (!button.isDisposed()) { button.removeSelectionListener(selectionListener); } } - public boolean isPseudoInstanceOf(String s) { + @Override + public boolean isPseudoInstanceOf(String s) { if ("checked".equals(s)) { return this.isSelected; } @@ -72,4 +81,11 @@ public class ButtonElement extends ControlElement { return (Button) getNativeWidget(); } + @Override + public void reset() { + super.reset(); + Button button = getButton(); + button.setImage(null); + } + } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabFolderElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabFolderElement.java index 4c49b7b7bd6..2aefdb8accd 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabFolderElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabFolderElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Angelo Zerr and others. + * Copyright (c) 2009, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,15 @@ * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.dom; import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Widget; import org.w3c.dom.Node; @@ -22,7 +25,7 @@ import org.w3c.dom.Node; * */ public class CTabFolderElement extends CompositeElement { - + public CTabFolderElement(CTabFolder tabFolder, CSSEngine engine) { super(tabFolder, engine); } @@ -31,6 +34,7 @@ public class CTabFolderElement extends CompositeElement { * Compute static pseudo instances. * */ + @Override protected void computeStaticPseudoInstances() { super.computeStaticPseudoInstances(); // it's CTabFolder. Set selected as static pseudo instance. @@ -40,7 +44,8 @@ public class CTabFolderElement extends CompositeElement { super.addStaticPseudoInstance("selected"); } - + + @Override public Node item(int index) { Widget widget = getWidget(); // retrieve the child control or child item depending on the @@ -54,15 +59,16 @@ public class CTabFolderElement extends CompositeElement { Widget w = folder.getChildren()[index]; return getElement(w); } - + } - + + @Override public int getLength() { Widget widget = getWidget(); int childCount = 0; if (widget instanceof Composite) { childCount = ((Composite) widget).getChildren().length; - + if (widget instanceof CTabFolder) { // if it's a CTabFolder, include the child items in the count childCount += ((CTabFolder) widget).getItemCount(); @@ -70,5 +76,27 @@ public class CTabFolderElement extends CompositeElement { } return childCount; } - + + @Override + public void reset() { + super.reset(); + CTabFolder folder = (CTabFolder) getWidget(); + folder.setSelectionBackground((Color) null); + folder.setSelectionForeground((Color) null); + folder.setBackground(null, null); + + if (folder.getRenderer() instanceof ICTabRendering) { + ICTabRendering renderer = (ICTabRendering) folder + .getRenderer(); + folder.setRenderer(null); + renderer.setSelectedTabFill(null); + renderer.setTabOutline(null); + renderer.setInnerKeyline(null); + renderer.setOuterKeyline(null); + renderer.setShadowColor(null); + renderer.setActiveToolbarGradient(null, null); + renderer.setInactiveToolbarGradient(null, null); + } + } } + diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabItemElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabItemElement.java index 2003a05f489..33bd28aa513 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabItemElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabItemElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,7 @@ public class CTabItemElement extends ItemElement { super(item, engine); } + @Override protected void computeStaticPseudoInstances() { super.computeStaticPseudoInstances(); // it's CTabFolder. Set selected as static pseudo instance. @@ -32,6 +33,7 @@ public class CTabItemElement extends ItemElement { super.addStaticPseudoInstance("selected"); } + @Override public Node getParentNode() { CTabItem item = getItem(); CTabFolder parent = item.getParent(); @@ -46,4 +48,12 @@ public class CTabItemElement extends ItemElement { return (CTabItem) getNativeWidget(); } + @Override + public void reset() { + super.reset(); + CTabItem item = getItem(); + item.setImage(null); + item.setFont(null); // in such case the parent's font will be taken + } + } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ControlElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ControlElement.java index fa5801f193d..b1b83b98bac 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ControlElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ControlElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Angelo Zerr and others. + * Copyright (c) 2009, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,11 +7,14 @@ * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.dom; import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.eclipse.e4.ui.css.swt.properties.GradientBackgroundListener; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; @@ -28,17 +31,20 @@ import org.w3c.dom.Node; * */ public class ControlElement extends WidgetElement { + private static final String WEBSITE_CLASS = "org.eclipse.swt.browser.WebSite"; protected boolean hasFocus = false; protected boolean hasMouseHover = false; private FocusListener focusListener = new FocusAdapter() { + @Override public void focusGained(FocusEvent e) { ControlElement.this.hasFocus = true; doApplyStyles(); } + @Override public void focusLost(FocusEvent e) { ControlElement.this.hasFocus = false; doApplyStyles(); @@ -47,6 +53,7 @@ public class ControlElement extends WidgetElement { // Create SWT MouseTrack listener private MouseTrackListener mouseHoverListener = new MouseTrackAdapter() { + @Override public void mouseEnter(MouseEvent e) { // mouse hover, apply styles // into the SWT control @@ -54,6 +61,7 @@ public class ControlElement extends WidgetElement { doApplyStyles(); } + @Override public void mouseExit(MouseEvent e) { // mouse hover, apply styles ControlElement.this.hasMouseHover = false; @@ -66,11 +74,14 @@ public class ControlElement extends WidgetElement { super(control, engine); } + @Override public void initialize() { super.initialize(); - if (!dynamicEnabled) return; - + if (!dynamicEnabled) { + return; + } + Control control = getControl(); // Add focus listener @@ -80,11 +91,14 @@ public class ControlElement extends WidgetElement { } + @Override public void dispose() { super.dispose(); - - if (!dynamicEnabled) return; - + + if (!dynamicEnabled) { + return; + } + Control control = getControl(); if (!control.isDisposed()) { control.removeFocusListener(focusListener); @@ -92,6 +106,7 @@ public class ControlElement extends WidgetElement { } } + @Override public boolean isPseudoInstanceOf(String s) { if ("focus".equals(s)) { return this.hasFocus; @@ -111,6 +126,7 @@ public class ControlElement extends WidgetElement { return super.isPseudoInstanceOf(s); } + @Override public Node getParentNode() { Control control = getControl(); Composite parent = control.getParent(); @@ -125,4 +141,25 @@ public class ControlElement extends WidgetElement { return (Control) getNativeWidget(); } + @Override + public void reset() { + super.reset(); + Control control = getControl(); + control.setFont(control.getDisplay().getSystemFont()); + control.setCursor(control.getDisplay() + .getSystemCursor(SWT.CURSOR_ARROW)); + control.setBackgroundImage(null); + GradientBackgroundListener.remove(control); + + if (WEBSITE_CLASS.equals(control.getClass().getName())) { + control.setBackground(control.getDisplay().getSystemColor( + SWT.COLOR_LIST_BACKGROUND)); + control.setForeground(control.getDisplay().getSystemColor( + SWT.COLOR_LINK_FOREGROUND)); + } else { + control.setBackground(null); + control.setForeground(null); + } + } + } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ShellElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ShellElement.java index d8cb6e3d95d..e6c8d10930b 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ShellElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ShellElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Angelo Zerr and others. + * Copyright (c) 2009, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.dom; @@ -23,7 +24,7 @@ import org.w3c.dom.Node; * */ public class ShellElement extends CompositeElement { - + protected boolean isActive; // Create SWT Shell Listener @@ -54,19 +55,23 @@ public class ShellElement extends CompositeElement { super(shell, engine); } + @Override public void initialize() { super.initialize(); Shell shell = getShell(); - if (!dynamicEnabled) return; - + if (!dynamicEnabled) { + return; + } + // Add Shell listener shell.addShellListener(shellListener); } + @Override public Node getParentNode() { - // Shells are considered as root notes; see bug 375069 + // Shells are considered as root notes; see bug 375069 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375069 return null; } @@ -75,17 +80,21 @@ public class ShellElement extends CompositeElement { return (Shell) getNativeWidget(); } + @Override public void dispose() { super.dispose(); - - if (!dynamicEnabled) return; - + + if (!dynamicEnabled) { + return; + } + Shell shell = getShell(); if (!shell.isDisposed()) { shell.removeShellListener(shellListener); } } + @Override public boolean isPseudoInstanceOf(String s) { if ("active".equals(s)) { return this.isActive; @@ -123,4 +132,11 @@ public class ShellElement extends CompositeElement { } return super.getAttribute(attr); } + + @Override + public void reset() { + super.reset(); + Shell shell = getShell(); + shell.setImage(null); + } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/TableItemElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/TableItemElement.java index 159e32ccfb3..9094f0a77ba 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/TableItemElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/TableItemElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Angelo Zerr and others. + * Copyright (c) 2009, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,11 +7,14 @@ * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.e4.ui.css.swt.dom; import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; @@ -20,11 +23,12 @@ import org.eclipse.swt.widgets.TableItem; * */ public class TableItemElement extends ItemElement { - + public TableItemElement(TableItem tableItem, CSSEngine engine) { super(tableItem, engine); } + @Override public boolean isPseudoInstanceOf(String s) { if ("odd".equals(s)) { TableItem tableItem = getTableItem(); @@ -43,4 +47,19 @@ public class TableItemElement extends ItemElement { protected TableItem getTableItem() { return (TableItem) getNativeWidget(); } + + @Override + public void reset() { + super.reset(); + TableItem tableItem = getTableItem(); + tableItem.setForeground(null); + tableItem.setBackground(null); + tableItem.setImage((Image) null); + tableItem.setFont(null); // in such case the parent's font will be taken + + Table parent = tableItem.getParent(); + parent.setForeground(null); + parent.setBackground(null); + parent.setFont(parent.getDisplay().getSystemFont()); + } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ToolItemElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ToolItemElement.java index c46cc0fb3bc..157d5361b0f 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ToolItemElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ToolItemElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.e4.ui.css.swt.dom; import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; @@ -24,15 +25,18 @@ import org.w3c.dom.Node; * */ public class ToolItemElement extends ItemElement { + private static final String DEFAULT_IMAGE = "defaultImage"; public ToolItemElement(ToolItem toolItem, CSSEngine engine) { super(toolItem, engine); + toolItem.setData(DEFAULT_IMAGE, toolItem.getImage()); } public ToolItem getToolItem() { return (ToolItem) getNativeWidget(); } + @Override public Node getParentNode() { ToolItem item = getToolItem(); ToolBar parent = item.getParent(); @@ -43,6 +47,7 @@ public class ToolItemElement extends ItemElement { return null; } + @Override public Node item(int index) { ToolItem item = getToolItem(); if ((item.getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR) { @@ -54,9 +59,20 @@ public class ToolItemElement extends ItemElement { return null; } + @Override public int getLength() { ToolItem item = getToolItem(); return (item.getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR && item.getControl() != null ? 1 : 0; } + + @Override + public void reset() { + super.reset(); + ToolItem item = getToolItem(); + Image defaultImage = (Image) item.getData(DEFAULT_IMAGE); + if (item.getImage() != defaultImage) { + item.setImage(defaultImage); + } + } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java index df170a7de62..ede91601e53 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 Angelo Zerr and others. + * Copyright (c) 2008, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,10 +27,10 @@ import org.w3c.dom.NodeList; * */ public class WidgetElement extends ElementAdapter implements NodeList { - + boolean dynamicEnabled = Boolean .getBoolean("org.eclipse.e4.ui.css.dynamic"); - + /** * Convenience method for getting the CSS class of a widget. * @@ -76,7 +76,7 @@ public class WidgetElement extends ElementAdapter implements NodeList { public static void setID(Widget widget, String id) { widget.setData(CSSSWTConstants.CSS_ID_KEY, id); } - + /** * Convenience method for getting the CSS engine responsible for a widget. * @param widget SWT widget which is styled by an engine @@ -158,7 +158,7 @@ public class WidgetElement extends ElementAdapter implements NodeList { * */ protected void computeStaticPseudoInstances() { - + } /** @@ -177,6 +177,7 @@ public class WidgetElement extends ElementAdapter implements NodeList { * org.eclipse.e4.ui.css.core.dom.ElementAdapter#getAttribute(java.lang. * String) */ + @Override public String getAttribute(String attr) { Widget widget = getWidget(); if (attr.equals("style")) { @@ -198,21 +199,23 @@ public class WidgetElement extends ElementAdapter implements NodeList { return sb.toString(); } Object o = widget.getData(attr.toLowerCase()); - if (o != null) + if (o != null) { return o.toString(); + } // FIXME: Commented out dead code. Filed https://bugs.eclipse.org/415442 to review this part of the code. -// try { -// //o = PropertyUtils.getProperty(widget, attr); -// if (o != null) -// return o.toString(); -// } catch (Exception e) { -// // e.printStackTrace(); -// } + // try { + // //o = PropertyUtils.getProperty(widget, attr); + // if (o != null) + // return o.toString(); + // } catch (Exception e) { + // // e.printStackTrace(); + // } return ""; } + @Override public String getLocalName() { return localName; } @@ -221,7 +224,7 @@ public class WidgetElement extends ElementAdapter implements NodeList { return namespaceURI; } - public Node getParentNode() { + public Node getParentNode() { return null; } @@ -229,7 +232,7 @@ public class WidgetElement extends ElementAdapter implements NodeList { return this; } - public int getLength() { + public int getLength() { return 0; } @@ -244,8 +247,9 @@ public class WidgetElement extends ElementAdapter implements NodeList { public String getCSSId() { Widget widget = getWidget(); Object id = getID(widget); - if (id != null) + if (id != null) { return id.toString(); + } return null; } @@ -257,8 +261,9 @@ public class WidgetElement extends ElementAdapter implements NodeList { public String getCSSClass() { Widget widget = getWidget(); Object id = getCSSClass(widget); - if (id != null) + if (id != null) { return id.toString(); + } return null; } @@ -271,10 +276,12 @@ public class WidgetElement extends ElementAdapter implements NodeList { Widget widget = getWidget(); // TODO should have key in CSSSWT Object id = widget.getData("style"); - if (id != null) + if (id != null) { return id.toString(); + } return null; } - + public void reset() { + } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/AbstractCSSSWTEngineImpl.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/AbstractCSSSWTEngineImpl.java index 9a2a5ef5ac3..8a2d35f14a0 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/AbstractCSSSWTEngineImpl.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/AbstractCSSSWTEngineImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Angelo Zerr and others. + * Copyright (c) 2008, 2014 Angelo Zerr and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,8 +11,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.engine; +import org.eclipse.e4.ui.css.core.engine.CSSElementContext; import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl; import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry; +import org.eclipse.e4.ui.css.swt.dom.WidgetElement; import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTColorConverterImpl; import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTCursorConverterImpl; import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTFontConverterImpl; @@ -23,6 +25,7 @@ import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTRGBConverterIm import org.eclipse.e4.ui.css.swt.resources.SWTResourceRegistryKeyFactory; import org.eclipse.e4.ui.css.swt.resources.SWTResourcesRegistry; import org.eclipse.swt.widgets.Display; +import org.w3c.dom.Element; /** * CSS SWT Engine implementation which configure CSSEngineImpl to apply styles @@ -79,4 +82,18 @@ public abstract class AbstractCSSSWTEngineImpl extends CSSEngineImpl { } return super.getResourcesRegistry(); } + + @Override + public void reset() { + for (CSSElementContext elementContext : getElementsContext().values()) { + Element element = elementContext.getElement(); + if (element instanceof WidgetElement) { + ((WidgetElement) element).reset(); + } + } + + getResourcesRegistry().dispose(); + super.reset(); + } + } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java index 9a23942a69b..1eb84b77ccc 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.widgets.Control; @@ -21,23 +21,24 @@ import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; public class CSSPropertyCornerRadiusSWTHandler extends AbstractCSSPropertySWTHandler { - - public static final ICSSPropertyHandler INSTANCE = new CSSPropertyCornerRadiusSWTHandler(); - + + @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { int radiusValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - try { - Method m = renderer.getClass().getMethod("setCornerRadius", new Class[]{int.class}); - m.invoke(renderer, radiusValue); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setCornerRadius(radiusValue); + } } } - + + @Override protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception { return null; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java index dd33652db83..0d7514f7fcb 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -21,25 +21,23 @@ import org.eclipse.swt.widgets.Control; import org.w3c.dom.css.CSSValue; public class CSSPropertyInnerKeylineSWTHandler extends AbstractCSSPropertySWTHandler { - - public static final ICSSPropertyHandler INSTANCE = new CSSPropertyInnerKeylineSWTHandler(); - + @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - Method m = renderer.getClass().getMethod("setInnerKeyline", new Class[]{Color.class}); - m.invoke(renderer, newColor); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setInnerKeyline(newColor); + } } } - + @Override protected String retrieveCSSProperty(Control control, String property, diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java index 8f80eae09ab..52e51219a57 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -23,22 +23,22 @@ import org.w3c.dom.css.CSSValue; public class CSSPropertyOuterKeylineSWTHandler extends AbstractCSSPropertySWTHandler { public static final ICSSPropertyHandler INSTANCE = new CSSPropertyOuterKeylineSWTHandler(); - + @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - Method m = renderer.getClass().getMethod("setOuterKeyline", new Class[]{Color.class}); - m.invoke(renderer, newColor); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setOuterKeyline(newColor); + } } } - + @Override protected String retrieveCSSProperty(Control control, String property, diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowColorHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowColorHandler.java index 708d7185c30..90fe4d407fa 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowColorHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowColorHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -24,15 +24,15 @@ public class CSSPropertyShadowColorHandler extends AbstractCSSPropertySWTHandler @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - Method m = renderer.getClass().getMethod("setShadowColor", new Class[]{Color.class}); - m.invoke(renderer, newColor); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setShadowColor(newColor); + } } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java index 3a24ce8285b..0511540969a 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.widgets.Control; @@ -21,20 +21,23 @@ import org.w3c.dom.css.CSSValue; public class CSSPropertyShadowVisibleSWTHandler extends AbstractCSSPropertySWTHandler { - + public static final ICSSPropertyHandler INSTANCE = new CSSPropertyShadowVisibleSWTHandler(); - + + @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } boolean shadowVisible = (Boolean) engine.convert(value, Boolean.class, null); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - try { - Method m = renderer.getClass().getMethod("setShadowVisible", new Class[]{boolean.class}); - m.invoke(renderer, shadowVisible); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setShadowVisible(shadowVisible); + } } - + + @Override protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception { return null; diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java index c607e878324..a503769d9a6 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2010, 2014 IBM Corporation and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -8,12 +8,12 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.dom.properties.Gradient; import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -22,34 +22,35 @@ import org.w3c.dom.css.CSSValue; public class CSSPropertyUnselectedTabsSWTHandler extends AbstractCSSPropertySWTHandler { - + public static final ICSSPropertyHandler INSTANCE = new CSSPropertyUnselectedTabsSWTHandler(); - + @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { Gradient grad = (Gradient) engine.convert(value, Gradient.class, control.getDisplay()); CTabFolder folder = ((CTabFolder) control); Color[] colors = CSSSWTColorHelper.getSWTColors(grad, folder.getDisplay(), engine); int[] percents = CSSSWTColorHelper.getPercents(grad); folder.setBackground(colors, percents, true); - + CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - if (pseudo != null && pseudo.equals("selected")) { - Method m = renderer.getClass().getMethod("setActiveToolbarGradient", new Class[]{Color[].class, int[].class}); - m.invoke(renderer, colors, percents); + if (renderer instanceof ICTabRendering) { + if ("selected".equals(pseudo)) { + ((ICTabRendering) renderer).setActiveToolbarGradient( + colors, percents); } else { - Method m = renderer.getClass().getMethod("setInactiveToolbarGradient", new Class[]{Color[].class, int[].class}); - m.invoke(renderer, colors, percents); + ((ICTabRendering) renderer) + .setInactiveToolbarGradient(colors, percents); } - } catch(NoSuchMethodException e) {/*IGNORED*/} + } } } - + @Override protected String retrieveCSSProperty(Control control, String property, diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java index e3bc3507cb8..b5df60a113a 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4SelectedTabFillHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -25,15 +25,15 @@ public class CSSPropertye4SelectedTabFillHandler extends @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - Method m = renderer.getClass().getMethod("setSelectedTabFill", new Class[]{Color.class}); - m.invoke(renderer, newColor); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setSelectedTabFill(newColor); + } } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java index 9acaa8cf3c1..dfa2518de6d 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertye4TabOutline.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.e4.ui.css.swt.properties.custom; -import java.lang.reflect.Method; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler; +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; import org.eclipse.swt.graphics.Color; @@ -24,15 +24,15 @@ public class CSSPropertye4TabOutline extends AbstractCSSPropertySWTHandler { @Override protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { - if (!(control instanceof CTabFolder)) return; + if (!(control instanceof CTabFolder)) { + return; + } if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay()); CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer(); - if (renderer == null) return; - try { - Method m = renderer.getClass().getMethod("setTabOutline", new Class[]{Color.class}); - m.invoke(renderer, newColor); - } catch(NoSuchMethodException e) {/*IGNORED*/} + if (renderer instanceof ICTabRendering) { + ((ICTabRendering) renderer).setTabOutline(newColor); + } } } diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/ICTabRendering.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/ICTabRendering.java new file mode 100644 index 00000000000..380856d4e61 --- /dev/null +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/ICTabRendering.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.ui.internal.css.swt; + +import org.eclipse.swt.graphics.Color; + +public interface ICTabRendering { + void setSelectedTabFill(Color color); + + void setTabOutline(Color color); + + void setInnerKeyline(Color color); + + void setOuterKeyline(Color color); + + void setShadowColor(Color color); + + void setActiveToolbarGradient(Color[] color, int[] percents); + + void setInactiveToolbarGradient(Color[] color, int[] percents); + + void setCornerRadius(int radius); + + void setShadowVisible(boolean visible); +} diff --git a/bundles/org.eclipse.e4.ui.widgets/src/org/eclipse/e4/ui/widgets/ImageBasedFrame.java b/bundles/org.eclipse.e4.ui.widgets/src/org/eclipse/e4/ui/widgets/ImageBasedFrame.java index 44f3e364720..01a719b091d 100644 --- a/bundles/org.eclipse.e4.ui.widgets/src/org/eclipse/e4/ui/widgets/ImageBasedFrame.java +++ b/bundles/org.eclipse.e4.ui.widgets/src/org/eclipse/e4/ui/widgets/ImageBasedFrame.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others.
+ * Copyright (c) 2012, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -110,7 +110,7 @@ public class ImageBasedFrame extends Canvas { public Rectangle getHandleRect() {
Rectangle handleRect = new Rectangle(0, 0, 0, 0);
- if (!draggable)
+ if (!draggable || handle.isDisposed())
return handleRect;
if (vertical) {
@@ -141,6 +141,10 @@ public class ImageBasedFrame extends Canvas { }
protected void drawFrame(PaintEvent e) {
+ if (handle.isDisposed()) {
+ return;
+ }
+
Point inner = framedControl.getSize();
int handleWidth = (handle != null && !vertical) ? handle.getBounds().width
: 0;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java index 361efe6580c..9976097f5aa 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,7 +11,7 @@ package org.eclipse.e4.ui.workbench.renderers.swt; import javax.inject.Inject; - +import org.eclipse.e4.ui.internal.css.swt.ICTabRendering; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabFolderRenderer; @@ -27,7 +27,9 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Display; -public class CTabRendering extends CTabFolderRenderer { +@SuppressWarnings("restriction") +public class CTabRendering extends CTabFolderRenderer implements + ICTabRendering { // Constants for circle drawing final static int LEFT_TOP = 0; @@ -81,8 +83,10 @@ public class CTabRendering extends CTabFolderRenderer { protected Rectangle computeTrim(int part, int state, int x, int y, int width, int height) { boolean onBottom = parent.getTabPosition() == SWT.BOTTOM; - int borderTop = onBottom ? INNER_KEYLINE + OUTER_KEYLINE : TOP_KEYLINE + OUTER_KEYLINE ; - int borderBottom = onBottom ? TOP_KEYLINE + OUTER_KEYLINE : INNER_KEYLINE + OUTER_KEYLINE; + int borderTop = onBottom ? INNER_KEYLINE + OUTER_KEYLINE : TOP_KEYLINE + + OUTER_KEYLINE; + int borderBottom = onBottom ? TOP_KEYLINE + OUTER_KEYLINE + : INNER_KEYLINE + OUTER_KEYLINE; int marginWidth = parent.marginWidth; int marginHeight = parent.marginHeight; int sideDropWidth = shadowEnabled ? SIDE_DROP_WIDTH : 0; @@ -91,9 +95,9 @@ public class CTabRendering extends CTabFolderRenderer { if (state == SWT.FILL) { x = -1 - paddingLeft; int tabHeight = parent.getTabHeight() + 1; - y = onBottom ? y - paddingTop - marginHeight - borderTop - - (cornerSize / 4) : y - paddingTop - marginHeight - tabHeight - borderTop - - (cornerSize / 4); + y = onBottom ? y - paddingTop - marginHeight - borderTop + - (cornerSize / 4) : y - paddingTop - marginHeight + - tabHeight - borderTop - (cornerSize / 4); width = 2 + paddingLeft + paddingRight; height += paddingTop + paddingBottom; height += tabHeight + (cornerSize / 4) + borderBottom @@ -109,7 +113,7 @@ public class CTabRendering extends CTabFolderRenderer { // +1 // TODO: Fix if (parent.getMinimized()) { - y = onBottom ? y - borderTop - 5 : y - tabHeight + y = onBottom ? y - borderTop - 5 : y - tabHeight - borderTop - 5; height = borderTop + borderBottom + tabHeight; } else { @@ -118,9 +122,9 @@ public class CTabRendering extends CTabFolderRenderer { // - borderTop: y - marginHeight - highlight_header - // tabHeight // - borderTop; - y = onBottom ? y - marginHeight - borderTop - - (cornerSize / 4) : y - marginHeight - tabHeight - borderTop - - (cornerSize / 4); + y = onBottom ? y - marginHeight - borderTop + - (cornerSize / 4) : y - marginHeight - tabHeight + - borderTop - (cornerSize / 4); height = height + borderBottom + borderTop + 2 * marginHeight + tabHeight + cornerSize / 2 + cornerSize / 4 @@ -131,7 +135,7 @@ public class CTabRendering extends CTabFolderRenderer { case PART_HEADER: x = x - (INNER_KEYLINE + OUTER_KEYLINE) - sideDropWidth; width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE + sideDropWidth); - + break; case PART_BORDER: x = x - INNER_KEYLINE - OUTER_KEYLINE - sideDropWidth @@ -143,9 +147,9 @@ public class CTabRendering extends CTabFolderRenderer { if (onBottom) { if (shadowEnabled) { height += 3; - } + } } - + break; default: if (0 <= part && part < parent.getItemCount()) { @@ -240,13 +244,16 @@ public class CTabRendering extends CTabFolderRenderer { region.intersect(clipping); gc.setClipping(region); - int header = shadowEnabled ? onBottom ? 6 : 3 : 1; // TODO: this needs to be added to computeTrim for - // HEADER + int header = shadowEnabled ? onBottom ? 6 : 3 : 1; // TODO: this needs + // to be added to + // computeTrim for + // HEADER Rectangle trim = computeTrim(PART_HEADER, state, 0, 0, 0, 0); trim.width = bounds.width - trim.width; trim.height = (parent.getTabHeight() + 1 + header) - trim.height; trim.x = -trim.x; - trim.y = onBottom ? bounds.height - parent.getTabHeight() - 1 - header : -trim.y; + trim.y = onBottom ? bounds.height - parent.getTabHeight() - 1 - header + : -trim.y; draw(PART_BACKGROUND, SWT.NONE, trim, gc); gc.setClipping(clipping); @@ -360,13 +367,14 @@ public class CTabRendering extends CTabFolderRenderer { return; boolean onBottom = parent.getTabPosition() == SWT.BOTTOM; - int header = shadowEnabled? 2 : 0; + int header = shadowEnabled ? 2 : 0; int width = bounds.width; int[] points = new int[1024]; int index = 0; int radius = cornerSize / 2; int circX = bounds.x + radius; - int circY = onBottom ? bounds.y + bounds.height + 1 - header - radius : bounds.y - 1 + radius; + int circY = onBottom ? bounds.y + bounds.height + 1 - header - radius + : bounds.y - 1 + radius; int selectionX1, selectionY1, selectionX2, selectionY2; int bottomY = onBottom ? bounds.y - header : bounds.y + bounds.height; if (itemIndex == 0 @@ -441,10 +449,12 @@ public class CTabRendering extends CTabFolderRenderer { + OUTER_KEYLINE); points[index++] = bottomY; } - gc.setClipping(0, onBottom ? bounds.y - header : bounds.y, parent.getSize().x - - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE - + OUTER_KEYLINE), bounds.y + bounds.height);// bounds.height - // + 4); + gc.setClipping(0, onBottom ? bounds.y - header : bounds.y, + parent.getSize().x + - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + + OUTER_KEYLINE), bounds.y + bounds.height);// bounds.height + // + + // 4); if (selectedTabFillColor == null) selectedTabFillColor = gc.getDevice().getSystemColor( SWT.COLOR_WHITE); @@ -472,7 +482,7 @@ public class CTabRendering extends CTabFolderRenderer { gc.setForeground(tabOutlineColor); Color gradientLineTop = null; Pattern foregroundPattern = null; - if (!active && !onBottom) { + if (!active && !onBottom) { RGB blendColor = gc.getDevice() .getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW).getRGB(); RGB topGradient = blend(blendColor, tabOutlineColor.getRGB(), 40); @@ -517,9 +527,11 @@ public class CTabRendering extends CTabFolderRenderer { int index = 0, inactive_index = 0; int radius = cornerSize / 2; int circX = bounds.x + radius; - int circY = onBottom ? bounds.y + bounds.height + 1 - header - radius : bounds.y - 1 + radius; - int bottomY = onBottom ? bounds.y - header : bounds.y + bounds.height; - + int circY = onBottom ? bounds.y + bounds.height + 1 - header + - radius : bounds.y - 1 + radius; + int bottomY = onBottom ? bounds.y - header : bounds.y + + bounds.height; + int leftIndex = circX; if (itemIndex == 0) { if (parent.getSelectionIndex() != 0) @@ -530,12 +542,12 @@ public class CTabRendering extends CTabFolderRenderer { points[index++] = bounds.x; points[index++] = bottomY; } - + if (!active) { System.arraycopy(points, 0, inactive, 0, index); inactive_index += 2; } - + int rightIndex = circX - 1; if (!onBottom) { int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_TOP); @@ -549,12 +561,12 @@ public class CTabRendering extends CTabFolderRenderer { } System.arraycopy(ltt, 0, points, index, ltt.length); index += ltt.length; - + if (!active) { System.arraycopy(ltt, 0, inactive, inactive_index, 2); inactive_index += 2; } - + int[] rt = drawCircle(rightIndex + width - (radius * 2), circY, radius, RIGHT_TOP); for (int i = 0; i < rt.length / 2; i += 2) { @@ -568,7 +580,8 @@ public class CTabRendering extends CTabFolderRenderer { System.arraycopy(rt, 0, points, index, rt.length); index += rt.length; if (!active) { - System.arraycopy(rt, rt.length - 4, inactive, inactive_index, 2); + System.arraycopy(rt, rt.length - 4, inactive, + inactive_index, 2); inactive[inactive_index] -= 1; inactive_index += 2; } @@ -576,22 +589,23 @@ public class CTabRendering extends CTabFolderRenderer { int[] ltt = drawCircle(leftIndex, circY, radius, LEFT_BOTTOM); System.arraycopy(ltt, 0, points, index, ltt.length); index += ltt.length; - + if (!active) { System.arraycopy(ltt, 0, inactive, inactive_index, 2); inactive_index += 2; } - + int[] rt = drawCircle(rightIndex + width - (radius * 2), circY, radius, RIGHT_BOTTOM); System.arraycopy(rt, 0, points, index, rt.length); index += rt.length; if (!active) { - System.arraycopy(rt, rt.length - 4, inactive, inactive_index, 2); + System.arraycopy(rt, rt.length - 4, inactive, + inactive_index, 2); inactive[inactive_index] -= 1; inactive_index += 2; } - + } points[index++] = bounds.width + rightIndex - radius; @@ -602,10 +616,12 @@ public class CTabRendering extends CTabFolderRenderer { inactive[inactive_index] -= 1; inactive_index += 2; } - gc.setClipping(points[0], onBottom ? bounds.y - header : bounds.y, parent.getSize().x - - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE - + OUTER_KEYLINE), bounds.y + bounds.height); - + gc.setClipping(points[0], onBottom ? bounds.y - header : bounds.y, + parent.getSize().x + - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + + INNER_KEYLINE + OUTER_KEYLINE), bounds.y + + bounds.height); + gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); int[] tmpPoints = new int[index]; System.arraycopy(points, 0, tmpPoints, 0, index); @@ -941,8 +957,10 @@ public class CTabRendering extends CTabFolderRenderer { public void setOuterKeyline(Color color) { this.outerKeyline = color; // TODO: HACK! Should be set based on pseudo-state. - setActive(!(color.getRed() == 255 && color.getGreen() == 255 && color - .getBlue() == 255)); + if (color != null) { + setActive(!(color.getRed() == 255 && color.getGreen() == 255 && color + .getBlue() == 255)); + } parent.redraw(); } @@ -975,4 +993,3 @@ public class CTabRendering extends CTabFolderRenderer { this.active = active; } } - diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java index a90490e5e30..b6479ab0b1f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -319,8 +319,9 @@ public class PerspectiveSwitcher { toolParent.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { - if (borderColor == null) + if (borderColor == null || borderColor.isDisposed()) { borderColor = e.display.getSystemColor(SWT.COLOR_BLACK); + } e.gc.setForeground(borderColor); Rectangle bounds = ((Control) e.widget).getBounds(); e.gc.drawLine(0, bounds.height - 1, bounds.width, bounds.height - 1); @@ -824,8 +825,9 @@ public class PerspectiveSwitcher { void paint(PaintEvent e) { GC gc = e.gc; Point size = comp.getSize(); - if (curveColor == null) + if (curveColor == null || curveColor.isDisposed()) { curveColor = e.display.getSystemColor(SWT.COLOR_BLACK); + } int h = size.y; int[] simpleCurve = new int[] { 0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0 }; // draw border diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcherCSSHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcherCSSHandler.java index 124ca08e35e..50e7e060f15 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcherCSSHandler.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcherCSSHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,6 +35,8 @@ public class PerspectiveSwitcherCSSHandler extends AbstractCSSPropertySWTHandler Color curveColor = null; if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { borderColor = (Color) engine.convert(value, Color.class, control.getDisplay()); + borderColor = borderColor.isDisposed() ? null : borderColor; + ((PerspectiveSwitcher) bar).setKeylineColor(borderColor, borderColor); } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { CSSValueList list = (CSSValueList) value; @@ -43,8 +45,12 @@ public class PerspectiveSwitcherCSSHandler extends AbstractCSSPropertySWTHandler CSSValue curve = list.item(1); borderColor = (Color) engine.convert(border, Color.class, control.getDisplay()); + borderColor = borderColor.isDisposed() ? null : borderColor; + curveColor = (Color) engine.convert(curve, Color.class, control.getDisplay()); + curveColor = curveColor.isDisposed() ? null : curveColor; + ((PerspectiveSwitcher) bar).setKeylineColor(borderColor, curveColor); } } |
