Commit b81cd9f5 authored by Simon Barner's avatar Simon Barner
Browse files

- Move GCStateManager to separate file

- Remove unneeded class GCUtils
refs 2490
parent 5220c5dd
......@@ -4,6 +4,7 @@ ConstraintsBaseUIUtils.java d52255cb76e1152e233dba67b9d764b443157054 GREEN
DecorationIconUtils.java 77c435bc970b7ca2774a9eab9fc102f0f46698b3 GREEN
DragAndDropBaseUtils.java c88f397ca7aa034247b3508ca0f70c24cde53a47 GREEN
EllipseLayoutUIUtils.java d007669f0f284392345d94d3b17009bebd53e2ee GREEN
GCStateManager.java 58303cf3c9bb0f9178659c8baabad81c6d96e9a7 YELLOW
GCUtils.java d348bfe783889dff742b99ed3c4a5396eaa6fdfd RED
LayoutDataUIUtils.java 0b2d3d1f47eef070c11b56fb7b332e0e49fa5a52 GREEN
PropertiesViewUtils.java 009d390b8aa41bb79b45b1e09a3375d0374fa139 GREEN
......
......@@ -26,114 +26,98 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
/**
* Utility class for handling of {@link GC SWT graphics context} state and data.
* Utility class managing SWT graphics context state by storing and restoring state attributes
* of the underlying graphics context using the provided public methods.
* <P>
* TODO(VA) What is it useful for? What does that bring? How do we use it?
*
* Currently, this class only encapsulates the {@link GCStateManager} class, which can be used to
* store and restore attributes of the graphics context.
* Note that it is the obligation of the user of this class to ensure that methods are called in
* order of the stack principle. Otherwise, {@link ClassCastException}s will occur.
*
* @author hoelzl
*/
public final class GCUtils {
/** Creates the state manager for the given graphics context. */
public static GCUtils.GCStateManager createGraphicsContextManager(GC gc) {
return new GCUtils.GCStateManager(gc);
public final class GCStateManager {
/** The graphics context to be managed. */
private final GC gc;
/** The stack used to store the current gc state attributes. */
private final Deque<Object> state = new LinkedList<Object>();
/** Constructor. */
public GCStateManager(GC gc) {
this.gc = gc;
}
/**
* Utility class managing SWT graphics context state by storing and restoring state attributes
* of the underlying graphics context using the provided public methods.
* <P>
* Note that it is the obligation of the user of this class to ensure that methods are called in
* order of the stack principle. Otherwise, {@link ClassCastException}s will occur.
*/
public static final class GCStateManager {
/** The graphics context to be managed. */
private final GC gc;
/** The stack used to store the current gc state attributes. */
private final Deque<Object> state = new LinkedList<Object>();
/** Constructor. */
public GCStateManager(GC gc) {
this.gc = gc;
}
/** Returns the graphics context. */
public GC GC() {
return gc;
}
/** Returns the graphics context. */
public GC GC() {
return gc;
}
/** Stores the alpha value. */
public GCStateManager alphaStoreAndSet(int alpha) {
state.push(new Integer(gc.getAlpha()));
gc.setAlpha(alpha);
return this;
}
/** Stores the alpha value. */
public GCStateManager alphaStoreAndSet(int alpha) {
state.push(new Integer(gc.getAlpha()));
gc.setAlpha(alpha);
return this;
}
/** Restores the alpha value. */
public GCStateManager alphaRestore() {
gc.setAlpha((Integer)state.pop());
return this;
}
/** Restores the alpha value. */
public GCStateManager alphaRestore() {
gc.setAlpha((Integer)state.pop());
return this;
}
/** Stores the current foreground color and creates and activates the given color. */
public GCStateManager foregroundStoreAndCreate(RGB rgb) {
state.push(gc.getForeground());
gc.setForeground(new Color(Display.getCurrent(), rgb));
return this;
}
/** Stores the current foreground color and creates and activates the given color. */
public GCStateManager foregroundStoreAndCreate(RGB rgb) {
state.push(gc.getForeground());
gc.setForeground(new Color(Display.getCurrent(), rgb));
return this;
}
/** Restores the previous foreground color and disposes the current one. */
public GCStateManager foregroundRestoreAndDispose() {
gc.getForeground().dispose();
gc.setForeground((Color)state.pop());
return this;
}
/** Restores the previous foreground color and disposes the current one. */
public GCStateManager foregroundRestoreAndDispose() {
gc.getForeground().dispose();
gc.setForeground((Color)state.pop());
return this;
}
/** Stores the current background color and creates and activates the given color. */
public GCStateManager backgroundStoreAndCreate(RGB rgb) {
state.push(gc.getBackground());
gc.setBackground(new Color(Display.getCurrent(), rgb));
return this;
}
/** Stores the current background color and creates and activates the given color. */
public GCStateManager backgroundStoreAndCreate(RGB rgb) {
state.push(gc.getBackground());
gc.setBackground(new Color(Display.getCurrent(), rgb));
return this;
}
/** Restores the previous background color and disposes the current one. */
public GCStateManager backgroundRestoreAndDispose() {
gc.getBackground().dispose();
gc.setBackground((Color)state.pop());
return this;
}
/** Restores the previous background color and disposes the current one. */
public GCStateManager backgroundRestoreAndDispose() {
gc.getBackground().dispose();
gc.setBackground((Color)state.pop());
return this;
}
/** Stores the current font and creates and activates the given font. */
public GCStateManager fontStoreAndCreate(FontData fontData) {
state.push(gc.getFont());
gc.setFont(new Font(Display.getCurrent(), fontData));
return this;
}
/** Stores the current font and creates and activates the given font. */
public GCStateManager fontStoreAndCreate(FontData fontData) {
state.push(gc.getFont());
gc.setFont(new Font(Display.getCurrent(), fontData));
return this;
}
/** Restores the previous font and disposes the current one. */
public GCStateManager fontRestoreAndDispose() {
gc.getFont().dispose();
gc.setFont((Font)state.pop());
return this;
}
/** Restores the previous font and disposes the current one. */
public GCStateManager fontRestoreAndDispose() {
gc.getFont().dispose();
gc.setFont((Font)state.pop());
return this;
}
/** Stores the line width and style and activates the given ones. */
public GCStateManager lineStoreAndSet(int width, int style) {
state.push(gc.getLineWidth());
gc.setLineWidth(width);
state.push(gc.getLineStyle());
gc.setLineStyle(style);
return this;
}
/** Stores the line width and style and activates the given ones. */
public GCStateManager lineStoreAndSet(int width, int style) {
state.push(gc.getLineWidth());
gc.setLineWidth(width);
state.push(gc.getLineStyle());
gc.setLineStyle(style);
return this;
}
/** Restores the line width and style. */
public GCStateManager lineRestore() {
gc.setLineStyle((Integer)state.pop());
gc.setLineWidth((Integer)state.pop());
return this;
}
/** Restores the line width and style. */
public GCStateManager lineRestore() {
gc.setLineStyle((Integer)state.pop());
gc.setLineWidth((Integer)state.pop());
return this;
}
}
......@@ -5,4 +5,4 @@ DataSeriesStyle.java facb27bc839a83057499b1ee982fd18ae1939ece GREEN
FillStyle.java b3951ca3b29aa8c67ff01eccbaaa138e434c9382 GREEN
FontStyle.java 24c20e5f4038855eb419d6f690e3c25f18b208bc GREEN
LegendStyle.java 5d88e06816e6c0eddcef351a7ed252656bfc326c GREEN
LineStyle.java 7a46948158377d61206be512a5d00b2d56cfe036 GREEN
LineStyle.java edf78465a89926be27a434b1e717dd15aba3f2ab YELLOW
......@@ -19,7 +19,7 @@ import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLACK;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.fortiss.tooling.base.ui.utils.GCUtils.GCStateManager;
import org.fortiss.tooling.base.ui.utils.GCStateManager;
/**
* Represents a style to be used in SWT spider chart graphics.
......
SpiderChartLegendWidget.java 0632c5f136ba61e62e7d9d0873fb16ce69e958e6 GREEN
SpiderChartSWTCanvas.java 225a38b35e10d004f8847ebd02dd852ffacc3324 GREEN
SpiderChartTitleWidget.java 2c79e6b411dbe8692a1069e5a5f2cacf80a22931 GREEN
SpiderChartLegendWidget.java 1dfd9101d7ff0638e92d947b0ce082ef953156f6 YELLOW
SpiderChartSWTCanvas.java 9eb4dad94df2474f313545f8c4a4f9d72a3b0954 YELLOW
SpiderChartTitleWidget.java 786c25ce0177c6dd6d9906f61938b707cfbff009 YELLOW
SpiderChartViewer.java bec0ce4a17f2cb04e32004ddbe019548a949926d GREEN
SpiderChartWidget.java 1e4ae2f9c4191ab71001349d620d66f68afa6639 GREEN
SpiderChartWidget.java 850637ccf4437de0843499a900158cc147708532 YELLOW
SpiderChartWidgetBase.java 7b950140131e319495ba0f5b3c711c00c28ac898 GREEN
......@@ -21,7 +21,7 @@ import java.util.Map;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.fortiss.tooling.base.ui.utils.GCUtils.GCStateManager;
import org.fortiss.tooling.base.ui.utils.GCStateManager;
import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
......
......@@ -15,8 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.widget;
import static org.fortiss.tooling.base.ui.utils.GCUtils.createGraphicsContextManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
......@@ -24,7 +22,7 @@ import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.base.ui.utils.GCUtils;
import org.fortiss.tooling.base.ui.utils.GCStateManager;
import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
......@@ -104,7 +102,7 @@ final class SpiderChartSWTCanvas extends Canvas {
/** Draws the spider chart. */
private void drawChart(PaintEvent e) {
GCUtils.GCStateManager gcState = createGraphicsContextManager(e.gc);
GCStateManager gcState = new GCStateManager(e.gc);
if(style.isShowTitle()) {
titleWidget.draw(gcState);
}
......
......@@ -16,7 +16,7 @@
package org.fortiss.tooling.spiderchart.widget;
import org.eclipse.swt.graphics.Point;
import org.fortiss.tooling.base.ui.utils.GCUtils.GCStateManager;
import org.fortiss.tooling.base.ui.utils.GCStateManager;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
......
......@@ -26,7 +26,7 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.base.ui.utils.GCUtils.GCStateManager;
import org.fortiss.tooling.base.ui.utils.GCStateManager;
import org.fortiss.tooling.spiderchart.model.AxisBase;
import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.DoubleAxis;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment