aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rolka2014-01-16 07:23:52 (EST)
committerGerrit Code Review @ Eclipse.org2014-01-16 15:57:15 (EST)
commit2e0e17f76c55abcab0e3a30bb4d72a65314df2b6 (patch)
tree3849e6a83f1aca1275ce0b30d0f8f2379166bb0c
parent8f34b54a6719eba7782f465f6a206ea342cd80ec (diff)
downloadeclipse.platform.ui-2e0e17f76c55abcab0e3a30bb4d72a65314df2b6.zip
eclipse.platform.ui-2e0e17f76c55abcab0e3a30bb4d72a65314df2b6.tar.gz
eclipse.platform.ui-2e0e17f76c55abcab0e3a30bb4d72a65314df2b6.tar.bz2
Bug 423813 - [CSS] Improvement of the CSS theme switching and applyingrefs/changes/06/20706/2
the new stylesheet in runtime Change-Id: I5601e98a7e3033f348a3d848b55a7ff69547cf64 Signed-off-by: Daniel Rolka <daniel.rolka@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ButtonElement.java6
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/CTabItemElement.java3
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ControlElement.java9
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ShellElement.java6
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/TableItemElement.java9
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/ToolItemElement.java13
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java75
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java84
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java79
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java53
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java26
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java4
12 files changed, 265 insertions, 102 deletions
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 777071a..1c09ced 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
@@ -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.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -20,7 +21,7 @@ import org.eclipse.swt.widgets.Button;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link Button}.
- *
+ *
*/
public class ButtonElement extends ControlElement {
@@ -84,8 +85,7 @@ public class ButtonElement extends ControlElement {
@Override
public void reset() {
super.reset();
- Button button = getButton();
- button.setImage(null);
+ CSSSWTImageHelper.restoreDefaultImage(getButton());
}
}
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 33bd28a..4a2df14 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
@@ -11,6 +11,7 @@
package org.eclipse.e4.ui.css.swt.dom;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Item;
@@ -52,7 +53,7 @@ public class CTabItemElement extends ItemElement {
public void reset() {
super.reset();
CTabItem item = getItem();
- item.setImage(null);
+ CSSSWTImageHelper.restoreDefaultImage(item);
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 b1b83b9..77d3b09 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
@@ -13,6 +13,8 @@ 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.helpers.CSSSWTCursorHelper;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTFontHelper;
import org.eclipse.e4.ui.css.swt.properties.GradientBackgroundListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
@@ -28,7 +30,7 @@ import org.w3c.dom.Node;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link Control}.
- *
+ *
*/
public class ControlElement extends WidgetElement {
private static final String WEBSITE_CLASS = "org.eclipse.swt.browser.WebSite";
@@ -145,9 +147,8 @@ public class ControlElement extends WidgetElement {
public void reset() {
super.reset();
Control control = getControl();
- control.setFont(control.getDisplay().getSystemFont());
- control.setCursor(control.getDisplay()
- .getSystemCursor(SWT.CURSOR_ARROW));
+ CSSSWTFontHelper.restoreDefaultFont(control);
+ CSSSWTCursorHelper.restoreDefaultCursor(control);
control.setBackgroundImage(null);
GradientBackgroundListener.remove(control);
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 e6c8d10..479dc4c 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
@@ -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.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.widgets.Composite;
@@ -21,7 +22,7 @@ import org.w3c.dom.Node;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link Shell}.
- *
+ *
*/
public class ShellElement extends CompositeElement {
@@ -136,7 +137,6 @@ public class ShellElement extends CompositeElement {
@Override
public void reset() {
super.reset();
- Shell shell = getShell();
- shell.setImage(null);
+ CSSSWTImageHelper.restoreDefaultImage(getShell());
}
}
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 9094f0a..5b1018c 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
@@ -13,14 +13,15 @@ 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.e4.ui.css.swt.helpers.CSSSWTFontHelper;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link TableItem}.
- *
+ *
*/
public class TableItemElement extends ItemElement {
@@ -54,12 +55,12 @@ public class TableItemElement extends ItemElement {
TableItem tableItem = getTableItem();
tableItem.setForeground(null);
tableItem.setBackground(null);
- tableItem.setImage((Image) null);
+ CSSSWTImageHelper.restoreDefaultImage(tableItem);
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());
+ CSSSWTFontHelper.restoreDefaultFont(parent);
}
}
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 157d536..a08368a 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
@@ -12,8 +12,8 @@ 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.helpers.CSSSWTImageHelper;
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;
@@ -22,14 +22,11 @@ import org.w3c.dom.Node;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link TableItem}.
- *
+ *
*/
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() {
@@ -69,10 +66,6 @@ public class ToolItemElement extends ItemElement {
@Override
public void reset() {
super.reset();
- ToolItem item = getToolItem();
- Image defaultImage = (Image) item.getData(DEFAULT_IMAGE);
- if (item.getImage() != defaultImage) {
- item.setImage(defaultImage);
- }
+ CSSSWTImageHelper.restoreDefaultImage(getToolItem());
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java
index f64eeea..86a3fd7 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTCursorHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 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
@@ -7,34 +7,40 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
+ * IBM Corporation
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
public class CSSSWTCursorHelper {
+ private static final String DEFAULT_CURSOR = "defaultCursor";
/**
* @see http://www.w3schools.com/css/pr_class_cursor.asp
*/
public static Cursor getSWTCursor(CSSValue value, Display display) {
- if (!(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE))
+ if (!(value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
return null;
+ }
int i = getSWTCursorId((CSSPrimitiveValue) value);
- if (i == SWT.NONE)
+ if (i == SWT.NONE) {
return null;
+ }
Cursor cursor = new Cursor(display, i);
return cursor;
}
public static String getCSSCursor(Cursor cursor) {
- if (cursor == null)
+ if (cursor == null) {
return "auto";
+ }
// switch (cursor.getType()) {
// case Cursor.DEFAULT_CURSOR:
// // The default cursor (often an arrow)
@@ -94,66 +100,95 @@ public class CSSSWTCursorHelper {
public static int getSWTCursorId(CSSPrimitiveValue value) {
String cursorName = value.getStringValue();
- if ("default".equals(cursorName))
+ if ("default".equals(cursorName)) {
// The default cursor (often an arrow)
return SWT.NONE;
- if ("auto".equals(cursorName))
+ }
+ if ("auto".equals(cursorName)) {
// TODO : manage auto
// Default. The browser sets a cursor
return SWT.NONE;
- if ("crosshair".equals(cursorName))
+ }
+ if ("crosshair".equals(cursorName)) {
// The cursor render as a crosshair
return SWT.CURSOR_CROSS;
- if ("pointer".equals(cursorName))
+ }
+ if ("pointer".equals(cursorName)) {
// The cursor render as a pointer (a hand) that indicates a link
return SWT.CURSOR_HAND;
- if ("move".equals(cursorName))
+ }
+ if ("move".equals(cursorName)) {
// The cursor indicates something that should be moved
return SWT.CURSOR_UPARROW;
- if ("e-resize".equals(cursorName))
+ }
+ if ("e-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved right
// (east)
return SWT.CURSOR_SIZEE;
- if ("ne-resize".equals(cursorName))
+ }
+ if ("ne-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved up and
// right (north/east)
return SWT.CURSOR_SIZENE;
- if ("nw-resize".equals(cursorName))
+ }
+ if ("nw-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved up and
// left (north/west)
return SWT.CURSOR_SIZENW;
- if ("n-resize".equals(cursorName))
+ }
+ if ("n-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved up
// (north)
return SWT.CURSOR_SIZEN;
- if ("se-resize".equals(cursorName))
+ }
+ if ("se-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved down
// and right (south/east)
return SWT.CURSOR_SIZESE;
- if ("sw-resize".equals(cursorName))
+ }
+ if ("sw-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved down
// and left (south/west)
return SWT.CURSOR_SIZESW;
- if ("s-resize".equals(cursorName))
+ }
+ if ("s-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved down
// (south)
return SWT.CURSOR_SIZES;
- if ("w-resize".equals(cursorName))
+ }
+ if ("w-resize".equals(cursorName)) {
// The cursor indicates that an edge of a box is to be moved left
// (west)
return SWT.CURSOR_SIZEW;
- if ("text".equals(cursorName))
+ }
+ if ("text".equals(cursorName)) {
// The cursor indicates text
return SWT.CURSOR_UPARROW;
- if ("wait".equals(cursorName))
+ }
+ if ("wait".equals(cursorName)) {
// The cursor indicates that the program is busy (often a watch or
// an hourglass)
return SWT.CURSOR_WAIT;
- if ("help".equals(cursorName))
+ }
+ if ("help".equals(cursorName)) {
// The cursor indicates that help is available (often a question
// mark or a balloon)
return SWT.CURSOR_HELP;
+ }
return SWT.NONE;
}
+ public static void storeDefaultCursor(Control control) {
+ if (control.getData(DEFAULT_CURSOR) == null) {
+ control.setData(DEFAULT_CURSOR, control.getCursor());
+ }
+ }
+
+ public static void restoreDefaultCursor(Control control) {
+ Cursor defaultCursor = (Cursor) control.getData(DEFAULT_CURSOR);
+ if (defaultCursor != null) {
+ control.setCursor(defaultCursor.isDisposed() ? control.getDisplay()
+ .getSystemCursor(SWT.ARROW) : defaultCursor);
+ }
+ }
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java
index f586b8b..59d99d1 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTFontHelper.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
@@ -42,11 +42,13 @@ import org.w3c.dom.css.CSSValue;
public class CSSSWTFontHelper {
public static final String FONT_DEFINITION_MARKER = "#";
+ private static final String DEFAULT_FONT = "defaultFont";
+
/**
* Get CSS2FontProperties from Control stored into Data of Control. If
* CSS2FontProperties doesn't exist, create it from Font of Control and
* store it into Data of Control.
- *
+ *
* @param control
* @return
*/
@@ -66,12 +68,14 @@ public class CSSSWTFontHelper {
}
/**
- * Get CSS2FontProperties from the widget. If
- * CSS2FontProperties doesn't exist, create it from the widget's font, if it
- * has one, and then store it in the widget's data if applicable.
- *
- * @param widget the widget to retrieve CSS2 font properties from
- * @return the font properties of the specified widget, or <code>null</code> if none
+ * Get CSS2FontProperties from the widget. If CSS2FontProperties doesn't
+ * exist, create it from the widget's font, if it has one, and then store it
+ * in the widget's data if applicable.
+ *
+ * @param widget
+ * the widget to retrieve CSS2 font properties from
+ * @return the font properties of the specified widget, or <code>null</code>
+ * if none
*/
public static CSS2FontProperties getCSS2FontProperties(Widget widget,
CSSElementContext context) {
@@ -95,7 +99,7 @@ public class CSSSWTFontHelper {
/**
* Build CSS2FontProperties from SWT Font.
- *
+ *
* @param font
* @return
*/
@@ -123,7 +127,7 @@ public class CSSSWTFontHelper {
/**
* Get CSS2FontProperties from Font of JComponent and store
* CSS2FontProperties instance into ClientProperty of JComponent.
- *
+ *
* @param component
* @return
*/
@@ -141,7 +145,7 @@ public class CSSSWTFontHelper {
/**
* Return FontData from {@link CSS2FontProperties}.
- *
+ *
* @param fontProperties
* @param control
* @return
@@ -221,7 +225,7 @@ public class CSSSWTFontHelper {
/**
* Return SWT style Font from {@link CSS2FontProperties}.
- *
+ *
* @param fontProperties
* @param control
* @return
@@ -262,7 +266,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-family from the widget's font, if it has a font
- *
+ *
* @param widget
* @return
*/
@@ -272,7 +276,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-family from SWT Font
- *
+ *
* @param font
* @return
*/
@@ -291,7 +295,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-size the widget's font, if it has a font
- *
+ *
* @param widget
* @return
*/
@@ -301,7 +305,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-size from SWT Font
- *
+ *
* @param font
* @return
*/
@@ -319,7 +323,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-style from the widget's font, if it has a font
- *
+ *
* @param widget
* @return
*/
@@ -329,7 +333,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-style from SWT Font
- *
+ *
* @param font
* @return
*/
@@ -353,7 +357,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-weight from the widget's font, if it has a font
- *
+ *
* @param widget
* @return
*/
@@ -363,7 +367,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-weight from Control Font
- *
+ *
* @param font
* @return
*/
@@ -387,7 +391,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-family from Control Font
- *
+ *
* @param control
* @return
*/
@@ -397,7 +401,7 @@ public class CSSSWTFontHelper {
/**
* Return CSS Value font-family from SWT Font
- *
+ *
* @param font
* @return
*/
@@ -427,7 +431,7 @@ public class CSSSWTFontHelper {
/**
* Return first FontData from Control Font.
- *
+ *
* @param control
* @return
*/
@@ -440,9 +444,9 @@ public class CSSSWTFontHelper {
}
/**
- *
+ *
* Return first FontData from SWT Font.
- *
+ *
* @param font
* @return
*/
@@ -463,4 +467,34 @@ public class CSSSWTFontHelper {
return null;
}
}
+
+ public static void storeDefaultFont(Control control) {
+ storeDefaultFont(control, control.getFont());
+ }
+
+ public static void storeDefaultFont(CTabItem item) {
+ storeDefaultFont(item, item.getFont());
+ }
+
+ private static void storeDefaultFont(Widget widget, Font font) {
+ if (widget.getData(DEFAULT_FONT) == null) {
+ widget.setData(DEFAULT_FONT, font);
+ }
+ }
+
+ public static void restoreDefaultFont(Control control) {
+ Font defaultFont = (Font) control.getData(DEFAULT_FONT);
+ if (defaultFont != null) {
+ control.setFont(defaultFont.isDisposed() ? control.getDisplay()
+ .getSystemFont() : defaultFont);
+ }
+ }
+
+ public static void restoreDefaultFont(CTabItem item) {
+ Font defaultFont = (Font) item.getData(DEFAULT_FONT);
+ if (defaultFont != null) {
+ item.setFont(defaultFont.isDisposed() ? item.getDisplay()
+ .getSystemFont() : defaultFont);
+ }
+ }
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java
index 463a3ec..f4129b3 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTImageHelper.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
@@ -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.helpers;
@@ -15,16 +16,27 @@ import java.io.InputStream;
import org.eclipse.e4.ui.css.core.util.resources.IResourcesLocatorManager;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Widget;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
public class CSSSWTImageHelper {
+ private static final String DEFAULT_IMAGE = "defaultImage";
+
+ private static final String DEFAULT_HOT_IMAGE = "defaultHotImage";
+
+ private static final String DEFAULT_DISABLE_IMAGE = "defaultDisableImage";
public static Image getImage(CSSValue value,
IResourcesLocatorManager manager, Display display) throws Exception {
- if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE)
+ if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) {
return null;
+ }
CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
switch (primitiveValue.getPrimitiveType()) {
case CSSPrimitiveValue.CSS_URI:
@@ -53,8 +65,9 @@ public class CSSSWTImageHelper {
// }
} finally {
try {
- if (in != null)
+ if (in != null) {
in.close();
+ }
} catch (IOException e) {
// e.printStackTrace();
throw e;
@@ -63,5 +76,65 @@ public class CSSSWTImageHelper {
return result;
}
+ public static void storeDefaultImage(Shell shell) {
+ storeDefaultImage(shell, DEFAULT_IMAGE, shell.getImage());
+ }
+
+ public static void storeDefaultImage(Item item) {
+ storeDefaultImage(item, DEFAULT_IMAGE, item.getImage());
+ }
+
+ public static void storeDefaultImage(ToolItem item) {
+ storeDefaultImage((Item) item);
+ storeDefaultImage(item, DEFAULT_HOT_IMAGE, item.getHotImage());
+ storeDefaultImage(item, DEFAULT_DISABLE_IMAGE, item.getDisabledImage());
+ }
+
+ public static void storeDefaultImage(Button button) {
+ storeDefaultImage(button, DEFAULT_IMAGE, button.getImage());
+ }
+
+ public static void restoreDefaultImage(Shell shell) {
+ Image defaultImage = (Image) shell.getData(DEFAULT_IMAGE);
+ if (defaultImage != null) {
+ shell.setImage(defaultImage.isDisposed() ? null : defaultImage);
+ }
+ }
+
+ public static void restoreDefaultImage(Item item) {
+ Image defaultImage = (Image) item.getData(DEFAULT_IMAGE);
+ if (defaultImage != null) {
+ item.setImage(defaultImage.isDisposed() ? null : defaultImage);
+ }
+ }
+
+ public static void restoreDefaultImage(ToolItem item) {
+ restoreDefaultImage((Item) item);
+
+ Image defaultImage = (Image) item.getData(DEFAULT_HOT_IMAGE);
+ if (defaultImage != null) {
+ item.setHotImage(defaultImage.isDisposed() ? null : defaultImage);
+ }
+
+ defaultImage = (Image) item.getData(DEFAULT_DISABLE_IMAGE);
+ if (defaultImage != null) {
+ item.setDisabledImage(defaultImage.isDisposed() ? null
+ : defaultImage);
+ }
+ }
+
+ public static void restoreDefaultImage(Button button) {
+ Image defaultImage = (Image) button.getData(DEFAULT_IMAGE);
+ if (defaultImage != null) {
+ button.setImage(defaultImage.isDisposed() ? null : defaultImage);
+ }
+ }
+
+ private static void storeDefaultImage(Widget widget, String imageName,
+ Image image) {
+ if (widget.getData(imageName) == null) {
+ widget.setData(imageName, image);
+ }
+ }
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java
index b7b420e..a27c77a 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyBackgroundSWTHandler.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
@@ -7,7 +7,7 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
- * IBM Corporation
+ * IBM Corporation
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.css2;
@@ -17,6 +17,7 @@ import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyBackgroundHand
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.e4.ui.css.swt.helpers.CSSSWTColorHelper;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTImageHelper;
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
import org.eclipse.e4.ui.css.swt.properties.GradientBackgroundListener;
import org.eclipse.swt.custom.CTabFolder;
@@ -29,15 +30,16 @@ import org.eclipse.swt.widgets.Widget;
import org.w3c.dom.css.CSSValue;
public class CSSPropertyBackgroundSWTHandler extends
- AbstractCSSPropertyBackgroundHandler {
+AbstractCSSPropertyBackgroundHandler {
public final static ICSSPropertyBackgroundHandler INSTANCE = new CSSPropertyBackgroundSWTHandler();
+ @Override
public boolean applyCSSProperty(Object element, String property,
CSSValue value, String pseudo, CSSEngine engine) throws Exception {
Widget widget = SWTElementHelpers.getWidget(element);
if (widget != null) {
-// super.applyCSSProperty(widget, property, value, pseudo, engine);
+ // super.applyCSSProperty(widget, property, value, pseudo, engine);
super.applyCSSProperty(element, property, value, pseudo, engine);
return true;
}
@@ -45,6 +47,7 @@ public class CSSPropertyBackgroundSWTHandler extends
}
+ @Override
public String retrieveCSSProperty(Object element, String property,
String pseudo, CSSEngine engine) throws Exception {
Widget widget = SWTElementHelpers.getWidget(element);
@@ -56,11 +59,14 @@ public class CSSPropertyBackgroundSWTHandler extends
/*
* (non-Javadoc)
- *
- * @see org.eclipse.e4.ui.core.css.dom.properties.css2.AbstractCSSPropertyBackgroundHandler#applyCSSPropertyBackgroundColor(java.lang.Object,
- * org.w3c.dom.css.CSSValue, java.lang.String,
- * org.eclipse.e4.ui.core.css.engine.CSSEngine)
+ *
+ * @see org.eclipse.e4.ui.core.css.dom.properties.css2.
+ * AbstractCSSPropertyBackgroundHandler
+ * #applyCSSPropertyBackgroundColor(java.lang.Object,
+ * org.w3c.dom.css.CSSValue, java.lang.String,
+ * org.eclipse.e4.ui.core.css.engine.CSSEngine)
*/
+ @Override
public void applyCSSPropertyBackgroundColor(Object element, CSSValue value,
String pseudo, CSSEngine engine) throws Exception {
Widget widget = (Widget) ((WidgetElement) element).getNativeWidget();
@@ -96,14 +102,17 @@ public class CSSPropertyBackgroundSWTHandler extends
/*
* (non-Javadoc)
- *
- * @see org.eclipse.e4.ui.core.css.dom.properties.css2.AbstractCSSPropertyBackgroundHandler#applyCSSPropertyBackgroundImage(java.lang.Object,
- * org.w3c.dom.css.CSSValue, java.lang.String,
- * org.eclipse.e4.ui.core.css.engine.CSSEngine)
+ *
+ * @see org.eclipse.e4.ui.core.css.dom.properties.css2.
+ * AbstractCSSPropertyBackgroundHandler
+ * #applyCSSPropertyBackgroundImage(java.lang.Object,
+ * org.w3c.dom.css.CSSValue, java.lang.String,
+ * org.eclipse.e4.ui.core.css.engine.CSSEngine)
*/
+ @Override
public void applyCSSPropertyBackgroundImage(Object element, CSSValue value,
String pseudo, CSSEngine engine) throws Exception {
-// Widget control = (Widget) element;
+ // Widget control = (Widget) element;
Widget control = (Widget) ((WidgetElement) element).getNativeWidget();
Image image = (Image) engine.convert(value, Image.class, control
.getDisplay());
@@ -114,16 +123,19 @@ public class CSSPropertyBackgroundSWTHandler extends
// Image oldImage = button.getImage();
// if (oldImage != null)
// oldImage.dispose();
+ CSSSWTImageHelper.storeDefaultImage(button);
button.setImage(image);
+
} else {
try {
- if(control instanceof Control)
+ if (control instanceof Control) {
((Control) control).setBackgroundImage(image);
+ }
} catch (Throwable e) {
//TODO replace with eclipse logging
-// if (logger.isWarnEnabled())
-// logger
-// .warn("Impossible to manage backround-image, This SWT version doesn't support control.setBackgroundImage(Image image) Method");
+ // if (logger.isWarnEnabled())
+ // logger
+ // .warn("Impossible to manage backround-image, This SWT version doesn't support control.setBackgroundImage(Image image) Method");
}
}
}
@@ -139,12 +151,13 @@ public class CSSPropertyBackgroundSWTHandler extends
Color color = null;
if (widget instanceof CTabItem) {
if ("selected".equals(pseudo)) {
- color = ((CTabItem) widget).getParent().getSelectionBackground();
+ color = ((CTabItem) widget).getParent()
+ .getSelectionBackground();
} else {
- color = ((CTabItem) widget).getParent().getBackground();
+ color = ((CTabItem) widget).getParent().getBackground();
}
} else if (widget instanceof Control) {
- color = ((Control) widget).getBackground();
+ color = ((Control) widget).getBackground();
}
return engine.convert(color, Color.class, null);
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java
index d2ea085..0703aaf 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyClassificationSWTHandler.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
@@ -7,12 +7,14 @@
*
* Contributors:
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
+ * IBM Corporation
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.css2;
import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyClassificationHandler;
import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyClassificationHandler;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.helpers.CSSSWTCursorHelper;
import org.eclipse.e4.ui.css.swt.helpers.SWTElementHelpers;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.widgets.Control;
@@ -20,10 +22,11 @@ import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
public class CSSPropertyClassificationSWTHandler extends
- AbstractCSSPropertyClassificationHandler {
+AbstractCSSPropertyClassificationHandler {
public final static ICSSPropertyClassificationHandler INSTANCE = new CSSPropertyClassificationSWTHandler();
+ @Override
public boolean applyCSSProperty(Object element, String property,
CSSValue value, String pseudo, CSSEngine engine) throws Exception {
Control control = SWTElementHelpers.getControl(element);
@@ -35,6 +38,7 @@ public class CSSPropertyClassificationSWTHandler extends
}
+ @Override
public String retrieveCSSProperty(Object element, String property,
String pseudo, CSSEngine engine) throws Exception {
Control control = SWTElementHelpers.getControl(element);
@@ -44,32 +48,37 @@ public class CSSPropertyClassificationSWTHandler extends
return null;
}
+ @Override
public void applyCSSPropertyCursor(Object element, CSSValue value,
String pseudo, CSSEngine engine) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
final Control control = (Control) element;
Cursor cursor = (Cursor) engine.convert(value, Cursor.class,
control.getDisplay());
+ CSSSWTCursorHelper.storeDefaultCursor(control);
control.setCursor(cursor);
}
}
+ @Override
public void applyCSSPropertyVisibility(Object element, CSSValue value,
String pseudo, CSSEngine engine) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
Control control = (Control) element;
CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
String visibility = primitiveValue.getStringValue();
- if ("hidden".equals(visibility))
+ if ("hidden".equals(visibility)) {
control.setVisible(false);
- else if ("collapse".equals(visibility)) {
+ } else if ("collapse".equals(visibility)) {
// TODO : manage collapse
control.setVisible(false);
- } else
+ } else {
control.setVisible(true);
+ }
}
}
+ @Override
public String retrieveCSSPropertyCursor(Object element, String pseudo,
CSSEngine engine) throws Exception {
Control control = (Control) element;
@@ -78,13 +87,14 @@ public class CSSPropertyClassificationSWTHandler extends
cursor = control.getCursor();
} catch (Throwable e) {
//TODO replace with eclipse logging
-// if (logger.isWarnEnabled())
-// logger
-// .warn("Impossible to manage cursor, This SWT version doesn't support control.getCursor() Method");
+ // if (logger.isWarnEnabled())
+ // logger
+ // .warn("Impossible to manage cursor, This SWT version doesn't support control.getCursor() Method");
}
return engine.convert(cursor, Cursor.class, null);
}
+ @Override
public String retrieveCSSPropertyVisibility(Object element, String pseudo,
CSSEngine engine) throws Exception {
// Control control = (Control) element;
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java
index d20ea94..8b77a83 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/css2/CSSPropertyFontSWTHandler.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
@@ -49,9 +49,11 @@ implements ICSSPropertyHandler2 {
private static void setFont(Widget widget, Font font) {
if (widget instanceof CTabItem) {
+ CSSSWTFontHelper.storeDefaultFont((CTabItem) widget);
((CTabItem) widget).setFont(font);
} else if (widget instanceof Control) {
Control control = (Control) widget;
+ CSSSWTFontHelper.storeDefaultFont(control);
try {
control.setRedraw(false);
control.setFont(font);