From ffe34bbf5edc8723ced61619753966a2cb202abc Mon Sep 17 00:00:00 2001 From: Philip Wenig Date: Fri, 1 Sep 2023 13:20:21 +0200 Subject: [PATCH] Fixed #367 - Custom Series - add support for rectangle and line --- .../extensions/model/AbstractElement.java | 100 ++++++++++++++++++ .../extensions/model/CustomSeries.java | 7 ++ .../extensions/model/ElementLine.java | 63 +++++++++++ .../extensions/model/ElementRectangle.java | 39 +++++++ .../extensions/model/ICustomSeries.java | 2 + .../swtchart/extensions/model/IElement.java | 41 +++++++ .../extensions/model/IGraphicElement.java | 2 +- .../extensions/model/ITextElement.java | 18 +--- .../extensions/model/TextElement.java | 72 +------------ 9 files changed, 256 insertions(+), 88 deletions(-) create mode 100644 org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/AbstractElement.java create mode 100644 org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementLine.java create mode 100644 org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementRectangle.java create mode 100644 org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IElement.java diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/AbstractElement.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/AbstractElement.java new file mode 100644 index 00000000..b06814d5 --- /dev/null +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/AbstractElement.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2023 Lablicate GmbH. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.swtchart.extensions.model; + +import java.util.Objects; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +public abstract class AbstractElement implements IElement { + + private double x = 0.0d; + private double y = 0.0d; + private Color color = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + private int alpha = 255; + + @Override + public double getX() { + + return x; + } + + @Override + public void setX(double x) { + + this.x = x; + } + + @Override + public double getY() { + + return y; + } + + @Override + public void setY(double y) { + + this.y = y; + } + + @Override + public Color getColor() { + + return color; + } + + @Override + public void setColor(Color color) { + + this.color = color; + } + + @Override + public int getAlpha() { + + return alpha; + } + + @Override + public void setAlpha(int alpha) { + + this.alpha = alpha; + } + + @Override + public int hashCode() { + + return Objects.hash(color, x, y); + } + + @Override + public boolean equals(Object obj) { + + if(this == obj) + return true; + if(obj == null) + return false; + if(getClass() != obj.getClass()) + return false; + AbstractElement other = (AbstractElement)obj; + return Objects.equals(color, other.color) && Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x) && Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y); + } + + @Override + public String toString() { + + return "AbstractElement [x=" + x + ", y=" + y + ", color=" + color + "]"; + } +} \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/CustomSeries.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/CustomSeries.java index f7fb2a0b..939880f9 100644 --- a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/CustomSeries.java +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/CustomSeries.java @@ -69,6 +69,13 @@ public void setDraw(boolean draw) { this.draw = draw; } + @Override + public void clear() { + + textElements.clear(); + graphicElements.clear(); + } + @Override public Set getTextElements() { diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementLine.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementLine.java new file mode 100644 index 00000000..3930a06f --- /dev/null +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementLine.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2023 Lablicate GmbH. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.swtchart.extensions.model; + +import org.eclipse.swtchart.LineStyle; + +public class ElementLine extends AbstractElement implements IGraphicElement { + + private double x2 = 0.0d; + private double y2 = 0.0d; + private LineStyle lineStyle = LineStyle.SOLID; + private int lineWidth = 1; + + public double getX2() { + + return x2; + } + + public void setX2(double x2) { + + this.x2 = x2; + } + + public double getY2() { + + return y2; + } + + public void setY2(double y2) { + + this.y2 = y2; + } + + public LineStyle getLineStyle() { + + return lineStyle; + } + + public void setLineStyle(LineStyle lineStyle) { + + this.lineStyle = lineStyle; + } + + public int getLineWidth() { + + return lineWidth; + } + + public void setLineWidth(int lineWidth) { + + this.lineWidth = lineWidth; + } +} \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementRectangle.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementRectangle.java new file mode 100644 index 00000000..670758cc --- /dev/null +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ElementRectangle.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2023 Lablicate GmbH. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.swtchart.extensions.model; + +public class ElementRectangle extends AbstractElement implements IGraphicElement { + + private double width = 0.0d; + private double height = 0.0d; + + public double getWidth() { + + return width; + } + + public void setWidth(double width) { + + this.width = width; + } + + public double getHeight() { + + return height; + } + + public void setHeight(double height) { + + this.height = height; + } +} \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ICustomSeries.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ICustomSeries.java index 067749d8..033bdcff 100644 --- a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ICustomSeries.java +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ICustomSeries.java @@ -30,6 +30,8 @@ public interface ICustomSeries { void setDraw(boolean draw); + void clear(); + Set getTextElements(); Set getGraphicElements(); diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IElement.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IElement.java new file mode 100644 index 00000000..3d4b5455 --- /dev/null +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IElement.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2023 Lablicate GmbH. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.swtchart.extensions.model; + +import org.eclipse.swt.graphics.Color; + +public interface IElement { + + double POSITION_TOP_Y = Double.NEGATIVE_INFINITY; + double POSITION_BOTTOM_Y = Double.POSITIVE_INFINITY; + double POSITION_LEFT_X = Double.NEGATIVE_INFINITY; + double POSITION_RIGHT_X = Double.POSITIVE_INFINITY; + double MAX_HEIGHT = Double.POSITIVE_INFINITY; + double MAX_WIDTH = Double.POSITIVE_INFINITY; + + double getX(); + + void setX(double x); + + double getY(); + + void setY(double y); + + Color getColor(); + + void setColor(Color color); + + int getAlpha(); + + void setAlpha(int alpha); +} \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IGraphicElement.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IGraphicElement.java index 05791956..3d612e01 100644 --- a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IGraphicElement.java +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/IGraphicElement.java @@ -12,5 +12,5 @@ *******************************************************************************/ package org.eclipse.swtchart.extensions.model; -public interface IGraphicElement { +public interface IGraphicElement extends IElement { } \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ITextElement.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ITextElement.java index b3271125..757af9e9 100644 --- a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ITextElement.java +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/ITextElement.java @@ -12,27 +12,13 @@ *******************************************************************************/ package org.eclipse.swtchart.extensions.model; -import org.eclipse.swt.graphics.Color; - -public interface ITextElement { +public interface ITextElement extends IElement { String getLabel(); void setLabel(String label); - - Color getColor(); - - void setColor(Color color); - + int getRotation(); void setRotation(int rotation); - - double getX(); - - void setX(double x); - - double getY(); - - void setY(double y); } \ No newline at end of file diff --git a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/TextElement.java b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/TextElement.java index 2f9a7008..478f7a42 100644 --- a/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/TextElement.java +++ b/org.eclipse.swtchart.extensions/src/org/eclipse/swtchart/extensions/model/TextElement.java @@ -12,19 +12,10 @@ *******************************************************************************/ package org.eclipse.swtchart.extensions.model; -import java.util.Objects; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - -public class TextElement implements ITextElement { +public class TextElement extends AbstractElement implements ITextElement { private String label = ""; - private Color color = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); private int rotation = -90; - private double x = 0.0d; - private double y = 0.0d; @Override public String getLabel() { @@ -38,18 +29,6 @@ public void setLabel(String label) { this.label = label; } - @Override - public Color getColor() { - - return color; - } - - @Override - public void setColor(Color color) { - - this.color = color; - } - @Override public int getRotation() { @@ -61,53 +40,4 @@ public void setRotation(int rotation) { this.rotation = rotation; } - - @Override - public double getX() { - - return x; - } - - @Override - public void setX(double x) { - - this.x = x; - } - - @Override - public double getY() { - - return y; - } - - @Override - public void setY(double y) { - - this.y = y; - } - - @Override - public int hashCode() { - - return Objects.hash(label, x, y); - } - - @Override - public boolean equals(Object obj) { - - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - TextElement other = (TextElement)obj; - return Objects.equals(label, other.label) && Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x) && Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y); - } - - @Override - public String toString() { - - return "TextLabel [label=" + label + ", color=" + color + ", x=" + x + ", y=" + y + ", rotation=" + rotation + "]"; - } } \ No newline at end of file