From b81cd9f590a29ebaca62794f04c6cecfd66819ca Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Tue, 13 Mar 2018 14:19:14 +0000 Subject: [PATCH] - Move GCStateManager to separate file - Remove unneeded class GCUtils refs 2490 --- .../fortiss/tooling/base/ui/utils/.ratings | 1 + .../tooling/base/ui/utils/GCStateManager.java | 123 ++++++++++++++++ .../tooling/base/ui/utils/GCUtils.java | 139 ------------------ .../tooling/spiderchart/style/.ratings | 2 +- .../tooling/spiderchart/style/LineStyle.java | 2 +- .../tooling/spiderchart/widget/.ratings | 8 +- .../widget/SpiderChartLegendWidget.java | 2 +- .../widget/SpiderChartSWTCanvas.java | 6 +- .../widget/SpiderChartTitleWidget.java | 2 +- .../spiderchart/widget/SpiderChartWidget.java | 2 +- 10 files changed, 135 insertions(+), 152 deletions(-) create mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCStateManager.java delete mode 100644 org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/.ratings index dbbcef18e..82112defd 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/.ratings @@ -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 diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCStateManager.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCStateManager.java new file mode 100644 index 000000000..5de59dcb0 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCStateManager.java @@ -0,0 +1,123 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2016 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.utils; + +import java.util.Deque; +import java.util.LinkedList; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +/** + * 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. + * + * @author hoelzl + */ +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; + } + + /** 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; + } + + /** 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; + } + + /** 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; + } + + /** 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; + } + + /** 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; + } + + /** Restores the line width and style. */ + public GCStateManager lineRestore() { + gc.setLineStyle((Integer)state.pop()); + gc.setLineWidth((Integer)state.pop()); + return this; + } +} diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java deleted file mode 100644 index 4aa5fff75..000000000 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/utils/GCUtils.java +++ /dev/null @@ -1,139 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.base.ui.utils; - -import java.util.Deque; -import java.util.LinkedList; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.GC; -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. - * <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. - * - * @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); - } - - /** - * 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; - } - - /** 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; - } - - /** 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; - } - - /** 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; - } - - /** 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; - } - - /** 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; - } - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/.ratings b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/.ratings index 08226265c..0ffe37fc5 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/.ratings +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/.ratings @@ -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 diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/LineStyle.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/LineStyle.java index 639553e0c..bc3df608b 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/LineStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/LineStyle.java @@ -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. diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/.ratings b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/.ratings index 731bb5205..89a499aff 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/.ratings +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/.ratings @@ -1,6 +1,6 @@ -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 diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java index 10c39d70a..405f96321 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java @@ -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; diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java index 03498d28b..3f65376b9 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java @@ -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); } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java index ffaf3e332..d822c18e4 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java @@ -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; diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java index 6a43a97dd..70dd3b8b8 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java @@ -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; -- GitLab