push/pop gc state
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/graphics/GraphicsContext.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/graphics/GraphicsContext.xtend
index 15e61cd..b680226 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/graphics/GraphicsContext.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/graphics/GraphicsContext.xtend
@@ -12,8 +12,24 @@
*/
interface GraphicsContext {
+ // State
+
+ /**
+ * Saves the current graphics context property state and pushes it onto a stack.
+ */
+ def void pushState()
+
+ /**
+ * Pops the last saved graphics context state and restores all properties back to what they were when that state was saved.
+ */
+ def void popState()
+
+ // Properties
+
def void setForegroundColor(Color foregroundColor)
+ // Drawing operations
+
/**
* Draws the specified text at the position specified by x and y coordinates.
* Ensure that drawing the text doesn't draw a background and line delimiters
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
index bdaa41e..483d197 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
@@ -36,8 +36,8 @@
//
def drawGridLines(Layer layer, GraphicsContext gc) {
- // Save state
-// val originalForeground = gc.foregroundColor
+ gc.pushState
+
gc.foregroundColor = new Color(0, 0, 255, 0)
// Draw
@@ -63,8 +63,7 @@
}
}
- // Restore state
-// gc.foregroundColor = originalForeground
+ gc.popState
}
}
\ No newline at end of file
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/javafx/graphics/JavaFXGraphicsContext.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/javafx/graphics/JavaFXGraphicsContext.xtend
index 031d538..aaae36d 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/javafx/graphics/JavaFXGraphicsContext.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/javafx/graphics/JavaFXGraphicsContext.xtend
@@ -12,6 +12,14 @@
this.gc = gc
}
+ override pushState() {
+ gc.save
+ }
+
+ override popState() {
+ gc.restore
+ }
+
override setForegroundColor(Color foregroundColor) {
gc.stroke = new javafx.scene.paint.Color(
foregroundColor.red as double / 255,
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/graphics/SWTGraphicsContext.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/graphics/SWTGraphicsContext.xtend
index 0ee4a04..78b9792 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/graphics/SWTGraphicsContext.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/graphics/SWTGraphicsContext.xtend
@@ -1,5 +1,8 @@
package org.eclipse.nebula.widgets.nattable.renderer.swt.graphics
+import java.util.HashMap
+import java.util.Map
+import java.util.Stack
import org.eclipse.nebula.widgets.nattable.core.graphics.Color
import org.eclipse.nebula.widgets.nattable.core.graphics.GraphicsContext
import org.eclipse.swt.SWT
@@ -18,6 +21,9 @@
* The SWT {@link GC} which is proxied by this implementation.
*/
val GC gc
+ val stateStack = new Stack<Map<String, Object>>
+
+ var Map<String, Object> originalState = newHashMap
/**
* Create a new proxy instance for the specified {@link GC}.
@@ -28,7 +34,22 @@
this.gc = gc
}
+ override pushState() {
+ stateStack.push(originalState)
+ originalState = new HashMap<String, Object>
+ }
+
+ override popState() {
+ for (property : originalState.keySet) {
+ switch (property) {
+ case "foregroundColor": gc.foreground = originalState.get(property) as org.eclipse.swt.graphics.Color
+ }
+ }
+ originalState = stateStack.pop
+ }
+
override setForegroundColor(Color foregroundColor) {
+ originalState.put("foregroundColor", gc.foreground)
gc.foreground = new org.eclipse.swt.graphics.Color(
gc.device,
foregroundColor.red,