Skip to content
Snippets Groups Projects
Commit d4c0c8f5 authored by Johannes Eder's avatar Johannes Eder
Browse files

Merge remote-tracking branch 'origin/master' into 4018_ErrorViewJavaFX

parents c7834450 f4429a9d
No related branches found
No related tags found
1 merge request!1244018 error view java fx
Showing
with 799 additions and 15 deletions
AnnotationLabelProvider.java 27d5bbb02d122e603abd158fa5a1fb39e79b0dc5 GREEN
CheckBoxLabelProvider.java 4030bef65a3b919cb087828b4616e5c966380e3e GREEN
CheckBoxLabelProvider.java 894ef9b2ae1a86d8916c8872da1d94b9e3eeb7bf GREEN
ElementCommentLabelProvider.java 76aa6e9b930ce5680607852fd776172942c89ce5 GREEN
ElementLabelProviderBase.java f33502f73033ebdf30316df627e8a9c87e7d1b28 GREEN
ElementNameLabelProvider.java 897296ac8318b6dfdea9c50fc73aaeea23c2fffa GREEN
......
......@@ -14,7 +14,9 @@
*******************************************************************************/
package org.fortiss.tooling.base.ui.annotation.labelprovider;
import static org.fortiss.tooling.base.utils.SystemUtils.isMacOSXPlatform;
import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.CHECKED_LABEL;
import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.UNCHECKED_LABEL;
import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.useTextIcon;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
......@@ -48,10 +50,9 @@ public class CheckBoxLabelProvider extends AnnotationLabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
// See #2443
if(isMacOSXPlatform() && element instanceof AnnotationEntry &&
if(useTextIcon() && element instanceof AnnotationEntry &&
((AnnotationEntry)element).canEdit(clazz)) {
return isChecked(element) ? "[X]" : "[ ]";
return isChecked(element) ? CHECKED_LABEL : UNCHECKED_LABEL;
}
return null;
......
AbstractIntegerSpinnerEditingSupport.java 7391e5b0d8e10baf5ab2c7f9543ed732a23bbd9d GREEN
CheckBoxEditingSupport.java 173a63ee86dc396946ddb625a41d48ffad23982f GREEN
CheckBoxLabelProvider.java 4eb2a54a17225da5a0f4f3a4212cde0c23d50d11 GREEN
CheckBoxLabelProvider.java e197c4a87261e130877d9b8d5d477a9f86e92b52 GREEN
IconNameLabelProvider.java 19eaf843b4b6059c1dc49dca8ede15d07deb30d5 GREEN
......@@ -17,6 +17,7 @@ package org.fortiss.tooling.base.ui.viewers;
import static org.eclipse.core.runtime.Platform.getBundle;
import static org.eclipse.jface.resource.JFaceResources.getImageRegistry;
import static org.fortiss.tooling.base.utils.SystemUtils.isLinuxPlatform;
import static org.fortiss.tooling.base.utils.SystemUtils.isMacOSXPlatform;
import org.eclipse.jface.resource.ImageRegistry;
......@@ -53,6 +54,17 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider {
/** {@link JFaceResources} id for disabled, checked image. */
private static final String DISABLED_CHECKED_KEY = "DISABLED_CHECKED";
/** Predicate whether to use a text-based icon (see #4032 and #2443). */
public static boolean useTextIcon() {
return isMacOSXPlatform() || isLinuxPlatform();
}
/** Text label for unchecked checkboxes when {@link #useTextIcon()} returns {@code true}. */
public static final String UNCHECKED_LABEL = "\u25A1";
/** Text label for checked checkboxes when {@link #useTextIcon()} returns {@code true}. */
public static final String CHECKED_LABEL = "\u2612";
/** Creates an image of checkbox SWT control. */
private static Image makeShot(boolean selected, boolean enabled) {
Shell shell = new Shell(SWT.NO_TRIM);
......@@ -119,10 +131,10 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider {
* @return {@link Image} representing the checkbox.
*/
public static Image getImage(boolean checked, boolean enabled) {
// See #2443
if(isMacOSXPlatform()) {
if(useTextIcon()) {
return null;
}
ImageRegistry imgReg = getImageRegistry();
if(imgReg.getDescriptor(CHECKED_KEY) == null) {
imgReg.put(UNCHECKED_KEY, makeShot(false, true));
......@@ -147,9 +159,8 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
// See #2443
if(isMacOSXPlatform() && isEnabled(element)) {
return isChecked(element) ? "[X]" : "[ ]";
if(useTextIcon() && isEnabled(element)) {
return isChecked(element) ? CHECKED_LABEL : UNCHECKED_LABEL;
}
return null;
}
......
......@@ -80,6 +80,7 @@ Export-Package: aerofx,
org.fortiss.tooling.common.ui.javafx,
org.fortiss.tooling.common.ui.javafx.control.treetableview,
org.fortiss.tooling.common.ui.javafx.layout,
org.fortiss.tooling.common.ui.javafx.style,
org.fortiss.tooling.common.ui.javafx.lwfxef,
org.fortiss.tooling.common.ui.javafx.lwfxef.change,
org.fortiss.tooling.common.ui.javafx.lwfxef.controller,
......
ColorStyleBase.java e9af86785db1e20ba812494f05eebc64205437b9 GREEN
FillStyle.java 6acb49d026b93145b32522dcb05e6e5410ae590e GREEN
FontStyle.java be4253fb2f2186d01e2de3faf26477efb634e137 GREEN
LineStyle.java f83241e40e434267876a26cebc1c9a8b131512d2 GREEN
StrokeStyle.java c30b6e901dbc8b853be659cfd411905ddb76da3c GREEN
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.style;
import javafx.scene.paint.Color;
/**
* Base class for styles with a single {@link Color}.
*
* @author hoelzl
*/
abstract class ColorStyleBase {
/** The RGBA color. */
private final Color rgbaColor;
/** Constructor. */
public ColorStyleBase(Color rgbaColor) {
this.rgbaColor = rgbaColor;
}
/** Returns the RGBA color. */
public final Color getColor() {
return rgbaColor;
}
}
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.style;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
/**
* Represents a style to be used in for filling areas.
*
* @author hoelzl
*/
public final class FillStyle extends ColorStyleBase {
/** Alpha transparency value (default is opaque 1.0). */
private final double alpha;
/** Constructor */
public FillStyle(Color rgbColor) {
this(rgbColor, 1);
}
/** Constructor */
public FillStyle(Color c, double alpha) {
super(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha));
this.alpha = alpha;
}
/** Returns alpha value. */
public double getAlpha() {
return alpha;
}
/** Applies the style to the given graphics context. */
public void applyStyle(GraphicsContext gc) {
gc.setFill(getColor());
}
}
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.style;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.text.Font.font;
import static javafx.scene.text.FontSmoothingType.LCD;
import javafx.geometry.Bounds;
import javafx.geometry.Dimension2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
/**
* Represents style attributes of fonts and provides a corresponding
* {@link #drawText(GraphicsContext, String, double, double) drawText} method.
*
* @author hoelzl
*/
public final class FontStyle extends ColorStyleBase {
/** Black Verdana 18 point. */
public static final FontStyle BLACK_VERDANA_18PT = new FontStyle("Verdana", 18, BLACK);
/** Black Verdana 16 point. */
public static final FontStyle BLACK_VERDANA_16PT = new FontStyle("Verdana", 16, BLACK);
/** Black Verdana 14 point. */
public static final FontStyle BLACK_VERDANA_14PT = new FontStyle("Verdana", 14, BLACK);
/** Black Verdana 12 point. */
public static final FontStyle BLACK_VERDANA_12PT = new FontStyle("Verdana", 12, BLACK);
/** Black Verdana 10 point. */
public static final FontStyle BLACK_VERDANA_10PT = new FontStyle("Verdana", 10, BLACK);
/** Black Verdana 8 point. */
public static final FontStyle BLACK_VERDANA_8PT = new FontStyle("Verdana", 8, BLACK);
/** The font data. */
private final Font font;
/** Constructor. */
public FontStyle(String fontFamily, double size, Color rgbColor) {
super(rgbColor);
this.font = font(fontFamily, size);
}
/** Applies the font style to the given graphics context. */
public void applyStyle(GraphicsContext gc) {
gc.setStroke(getColor());
gc.setFill(getColor());
gc.setFont(font);
gc.setFontSmoothingType(LCD);
}
/** Draws the given text at the given location. */
public void drawText(GraphicsContext gc, String text, double x, double y) {
gc.save();
applyStyle(gc);
gc.fillText(text, x, y);
gc.restore();
}
/** Returns the dimensions of the text when drawn with this style. */
public Dimension2D getTextBounds(String text) {
Text t = new Text(text);
t.setFont(font);
Bounds b = t.getBoundsInLocal();
Dimension2D dim = new Dimension2D(b.getWidth(), b.getHeight());
return dim;
}
}
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.style;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
/**
* Represents a style to be used for lines and provides a corresponding
* {@link #drawLine(GraphicsContext, double, double, double, double) drawLine} method.
*
* @author hoelzl
*/
public final class LineStyle extends ColorStyleBase {
/** Solid, black line with width of one point. */
public static final LineStyle SOLID_BLACK_1PT =
new LineStyle(Color.BLACK, 1, StrokeStyle.SOLID);
/** The style of the stroke of the line. */
private final StrokeStyle strokeStyle;
/** The width of the line. */
private final double width;
/** Constructor. */
public LineStyle(Color rgbColor, double width, StrokeStyle strokeStyle) {
super(rgbColor);
this.width = width;
this.strokeStyle = strokeStyle;
}
/** Constructor. */
public LineStyle(Color rgbColor) {
this(rgbColor, 1, StrokeStyle.SOLID);
}
/** Applies the line style to the given graphics context. */
public void applyStyle(GraphicsContext gc) {
gc.setStroke(getColor());
gc.setLineWidth(width);
strokeStyle.applyStyle(gc);
}
/** Draws a line */
public void drawLine(GraphicsContext gc, double x1, double y1, double x2, double y2) {
applyStyle(gc);
gc.strokeLine(x1, y1, x2, y2);
}
}
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.style;
import javafx.scene.canvas.GraphicsContext;
/**
* Represents the style of the stroke of a line.
*
* @author hoelzl
*/
public final class StrokeStyle {
/** Stroke style of the solid line. */
public static final StrokeStyle SOLID = new StrokeStyle(0, null);
/** The line dash offset. */
private final double offset;
/** The dashes array. */
private final double[] dashes;
/** Constructor. */
public StrokeStyle(double offset, double[] dashes) {
this.offset = offset;
this.dashes = dashes;
}
/** Set the stroke style for the given graphics context. */
public void applyStyle(GraphicsContext gc) {
gc.setLineDashOffset(offset);
gc.setLineDashes(dashes);
}
}
......@@ -8,5 +8,6 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test-src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="output" path="build"/>
</classpath>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spider Chart
Bundle-SymbolicName: org.fortiss.tooling.spiderchart.ui
Bundle-SymbolicName: org.fortiss.tooling.spiderchart.ui;singleton:=true
Bundle-Version: 2.17.0.qualifier
Bundle-Vendor: fortiss GmbH
Bundle-RequiredExecutionEnvironment: JavaSE-11
......@@ -10,8 +10,9 @@ Github-Project-Url: https://github.com/amitjoy/Spider-Chart-SWT.git
Export-Package: org.fortiss.tooling.spiderchart.model,
org.fortiss.tooling.spiderchart.style,
org.fortiss.tooling.spiderchart.util,
org.fortiss.tooling.spiderchart.widget
org.fortiss.tooling.spiderchart.control
Require-Bundle: org.eclipse.swt,
org.fortiss.tooling.base.ui;bundle-version="2.17.0";visibility:=reexport
org.fortiss.tooling.base.ui,
org.fortiss.tooling.common.ui
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: org.fortiss.tooling.spiderchart.ui
# (c) 2016 fortiss GmbH
source.. = src/,\
source.. = res/,\
src/,\
test-src/
output.. = build/
bin.includes = META-INF/,\
plugin.xml,\
.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!-- (c) 2017 fortiss GmbH -->
<plugin>
<extension point="org.eclipse.ui.views">
<view
class="test.org.fortiss.tooling.spiderchart.SpiderChartExampleFXViewPart"
id="test.org.fortiss.tooling.spiderchart.SpiderChartExampleFXViewPart"
name="SpiderChartExample"
restorable="true">
</view>
</extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="anchorPane" prefHeight="216.0" prefWidth="345.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" />
SpiderChartCanvas.java fcb6bf9c05b5e459de3282996f8d1fdc7dba919c GREEN
SpiderChartControl.java f8eab27397e782217754971ee7e54eab1931b82d GREEN
SpiderChartControlBase.java 83657aa8d923b6f8150b28a3f9f85d78b7435093 GREEN
SpiderChartLegendControl.java c77162dc8aa1233acc84ac042452755071b69076 GREEN
SpiderChartTitleControl.java ce3f7623c82e98e611de99fcc566c5363431f209 GREEN
SpiderChartViewer.java 9d697a5c19f93fe658bed5117ca4218ebc6660bc GREEN
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.spiderchart.control;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
/**
* Represents a {@link Canvas} on which chart will be drawn.
*
* @author hoelzl
*/
final class SpiderChartCanvas {
/** The canvas. */
private final Canvas canvas;
/** The chart style. */
private final ChartStyle style;
/** The chart widget. */
private final SpiderChartControl chartControl;
/** The title widget. */
private final SpiderChartTitleControl titleControl;
/** The legend widget. */
private final SpiderChartLegendControl legendControl;
/** Constructor */
public SpiderChartCanvas(SpiderChart chart, ChartStyle style) {
this.style = style;
this.chartControl = new SpiderChartControl(chart, style);
this.titleControl = new SpiderChartTitleControl(chart, style);
this.legendControl = new SpiderChartLegendControl(chart, style);
this.canvas = new Canvas();
canvas.widthProperty().addListener(evt -> {
layoutAndPaint();
});
canvas.heightProperty().addListener(evt -> {
layoutAndPaint();
});
}
/** Returns canvas. */
public Canvas getCanvasControl() {
return canvas;
}
/** Paints the spider chart. */
private void layoutAndPaint() {
double width = canvas.getWidth();
double height = canvas.getHeight();
layoutChart(width, height);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.clearRect(0, 0, width, height);
drawChart(gc);
}
/** Computes the bounding boxes of the chart components. */
private void layoutChart(double width, double height) {
double chartMarginPercent = style.getRelativeMargin();
double widthMargin = width * chartMarginPercent;
double heightMargin = height * chartMarginPercent;
double chartY = 0;
double widthRemaining = width;
double heightRemaining = height;
if(style.isShowTitle()) {
titleControl.setBounds(0, 0, width - 1, heightMargin - 1);
heightRemaining -= heightMargin;
chartY = heightMargin;
}
if(style.isShowLegend()) {
if(style.getLegendStyle().isVerticalLayout()) {
legendControl.setBounds(width - widthMargin, height - heightRemaining,
widthMargin - 1, heightRemaining - 1);
widthRemaining -= widthMargin;
} else {
legendControl.setBounds(0, height - heightMargin, width - 1, heightMargin - 1);
heightRemaining -= heightMargin;
}
}
chartControl.setBounds(0, chartY, widthRemaining, heightRemaining);
}
/** Draws the spider chart. */
private void drawChart(GraphicsContext gc) {
if(style.isShowTitle()) {
titleControl.draw(gc);
}
chartControl.draw(gc);
if(style.isShowLegend()) {
legendControl.draw(gc);
}
}
}
/*-------------------------------------------------------------------------+
| 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.spiderchart.widget;
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.spiderchart.control;
import static org.fortiss.tooling.spiderchart.util.AxisUtils.getSegmentPoint;
......@@ -21,12 +15,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.graphics.FontData;
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.GCStateManager;
import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
import org.fortiss.tooling.spiderchart.model.AxisBase;
import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.DoubleAxis;
......@@ -35,43 +24,44 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.AxisStyle;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
import org.fortiss.tooling.spiderchart.style.DataSeriesStyle;
import org.fortiss.tooling.spiderchart.style.FillStyle;
import org.fortiss.tooling.spiderchart.style.FontStyle;
import javafx.geometry.Dimension2D;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
/**
* Class for drawing the spider chart.
*
* @author mondal
*
* @author hoelzl
*/
public final class SpiderChartWidget extends SpiderChartWidgetBase {
public final class SpiderChartControl extends SpiderChartControlBase {
/** The center point of the chart. */
private Point center = new Point(0, 0);
private Point2D center = new Point2D(0, 0);
/** The end points of the axes. */
private Map<AxisBase, Point> axesEnds = new HashMap<AxisBase, Point>();
private Map<AxisBase, Point2D> axesEnds = new HashMap<>();
/** The angle in degree between two axes. */
private double segmentDegree = 0.0;
/** Constructor. */
public SpiderChartWidget(SpiderChart chart, ChartStyle style) {
public SpiderChartControl(SpiderChart chart, ChartStyle style) {
super(chart, style);
}
/** Draws the spider chart. */
public void draw(GCStateManager gcState) {
public void draw(GraphicsContext gc) {
if(!style.isUseIndividualAxisSegments()) {
drawBackground(gcState);
drawWebLines(gcState);
drawBackground(gc);
drawWebLines(gc);
}
drawAxes(gcState);
drawAxes(gc);
for(DataSeries data : chart.getDataSeries()) {
drawDataSeries(gcState, data);
drawDataSeries(gc, data);
}
}
/** {@inheritDoc} */
@Override
public void setBounds(int x, int y, int w, int h) {
public void setBounds(double x, double y, double w, double h) {
super.setBounds(x, y, w, h);
computeAxisEndPoints();
}
......@@ -84,10 +74,9 @@ public final class SpiderChartWidget extends SpiderChartWidgetBase {
segmentDegree = 360.0 / size;
double currentAngleDegree = style.getStartAngleDegree();
int halfWidth = getWidth() / 2;
int halfHeight = getHeight() / 2;
center.x = getX() + halfWidth;
center.y = getY() + halfHeight;
double halfWidth = getWidth() / 2;
double halfHeight = getHeight() / 2;
center = new Point2D(getX() + halfWidth, getY() + halfHeight);
double relativeMargin = 1.0 - style.getRelativeMargin();
int wExtent = (int)(relativeMargin * halfWidth);
......@@ -100,139 +89,126 @@ public final class SpiderChartWidget extends SpiderChartWidgetBase {
double startAngleRad = Math.PI * currentAngleDegree / 180.0;
int extentX = (int)(Math.cos(startAngleRad) * extent);
int extentY = (int)(Math.sin(startAngleRad) * extent);
Point outer = new Point(center.x + extentX, center.y + extentY);
Point2D outer = new Point2D(center.getX() + extentX, center.getY() + extentY);
axesEnds.put(axis, outer);
currentAngleDegree = (currentAngleDegree + segmentDegree) % 360.0;
}
}
/** Draws the background if style requires all axes to have equal number of segments. */
private void drawBackground(GCStateManager gcState) {
Path path = new Path(Display.getCurrent());
private void drawBackground(GraphicsContext gc) {
gc.save();
if(chart.getAxes().isEmpty()) {
return;
}
gc.beginPath();
boolean first = true;
for(AxisBase axis : chart.getAxes()) {
Point p = axesEnds.get(axis);
Point2D p = axesEnds.get(axis);
if(first) {
path.moveTo(p.x, p.y);
gc.moveTo(p.getX(), p.getY());
first = false;
} else {
path.lineTo(p.x, p.y);
gc.lineTo(p.getX(), p.getY());
}
}
path.close();
gcState.backgroundStoreAndCreate(style.getBackgroundFillStyle().getRGBColor());
gcState.GC().fillPath(path);
gcState.backgroundRestoreAndDispose();
path.dispose();
gc.closePath();
style.getBackgroundFillStyle().applyStyle(gc);
gc.fill();
gc.restore();
}
/** Draws the web lines of the background if all axes have equal number of segments. */
private void drawWebLines(GCStateManager gcState) {
gcState.foregroundStoreAndCreate(style.getBackgroundLineStyle().getRGBColor());
private void drawWebLines(GraphicsContext gc) {
style.getBackgroundLineStyle().applyStyle(gc);
for(int i = 1; i <= style.getAxisSegments(); i++) {
Path p = computePath(i);
gcState.GC().drawPath(p);
p.dispose();
computeAndDrawPath(i, gc);
}
gcState.foregroundRestoreAndDispose();
}
/** Computes the i-th web line path. */
private Path computePath(int i) {
private void computeAndDrawPath(int i, GraphicsContext gc) {
double ratio = (double)i / (double)style.getAxisSegments();
boolean first = true;
Path p = new Path(Display.getCurrent());
gc.save();
gc.beginPath();
for(AxisBase axis : chart.getAxes()) {
Point outer = axesEnds.get(axis);
int xExtent = outer.x - center.x;
int yExtent = outer.y - center.y;
int x = center.x + (int)(ratio * xExtent);
int y = center.y + (int)(ratio * yExtent);
Point2D outer = axesEnds.get(axis);
double xExtent = outer.getX() - center.getX();
double yExtent = outer.getY() - center.getY();
double x = center.getX() + ratio * xExtent;
double y = center.getY() + ratio * yExtent;
if(first) {
p.moveTo(x, y);
gc.moveTo(x, y);
first = false;
} else {
p.lineTo(x, y);
gc.lineTo(x, y);
}
}
p.close();
return p;
gc.closePath();
gc.restore();
}
/** Draws the data series. */
private void drawDataSeries(GCStateManager gcState, DataSeries data) {
private void drawDataSeries(GraphicsContext gc, DataSeries data) {
DataSeriesStyle dStyle = style.getDataSeriesStyle(data);
Path path = new Path(Display.getCurrent());
boolean first = true;
gc.save();
gc.beginPath();
for(AxisBase axis : chart.getAxes()) {
Point p = computeDataPoint(axis, data);
Point2D p = computeDataPoint(axis, data);
if(first) {
path.moveTo(p.x, p.y);
gc.moveTo(p.getX(), p.getY());
first = false;
} else {
path.lineTo(p.x, p.y);
gc.lineTo(p.getX(), p.getY());
}
if(dStyle.isShowIndicators()) {
drawIndicator(gcState, dStyle, p);
drawIndicator(gc, dStyle, p);
}
if(dStyle.isShowIndicatorLabels()) {
drawIndicatorLabel(gcState, dStyle, p, axis, data.getAxisValue(axis));
drawIndicatorLabel(gc, dStyle, p, axis, data.getAxisValue(axis));
}
}
path.close();
// draw the filled area with alpha value.
FillStyle fStyle = dStyle.getFillStyle();
gcState.alphaStoreAndSet(fStyle.getAlpha());
gcState.backgroundStoreAndCreate(fStyle.getRGBColor());
gcState.GC().fillPath(path);
gcState.backgroundRestoreAndDispose().alphaRestore();
// draw the outline without alpha value
gcState.foregroundStoreAndCreate(dStyle.getLineStyle().getRGBColor());
gcState.GC().drawPath(path);
gcState.foregroundRestoreAndDispose();
path.dispose();
gc.closePath();
dStyle.getFillStyle().applyStyle(gc);
gc.fill();
dStyle.getLineStyle().applyStyle(gc);
gc.stroke();
gc.restore();
}
/** Draws the indicator labels next to the chart point. */
private void drawIndicatorLabel(GCStateManager gcState, DataSeriesStyle dStyle, Point p,
private void drawIndicatorLabel(GraphicsContext gc, DataSeriesStyle dStyle, Point2D p,
AxisBase axis, Object value) {
gcState.fontStoreAndCreate(dStyle.getIndicatorLabelStyle().getFontData());
gcState.foregroundStoreAndCreate(dStyle.getIndicatorLabelStyle().getRGBColor());
GC gc = gcState.GC();
FontStyle fontStyle = dStyle.getIndicatorLabelStyle();
String label = dStyle.getFormattedLabel(axis, value);
Point textExtent = gc.textExtent(label);
Dimension2D textExtent = fontStyle.getTextBounds(label);
// data series indicator labels are always to the right of the point
int x = p.x + 4;
int y = p.y;
if(y > center.y) {
y = y + 4;
} else if(y < center.y) {
y = y - 4 - textExtent.y;
int offset = 5;
double x = p.getX() + offset;
double y = p.getY();
if(y > center.getY()) {
y = y + offset + textExtent.getHeight() / 2;
} else if(y < center.getY()) {
y = y - offset;
} else {
y = y - textExtent.y / 2;
y = y - textExtent.getHeight() / 2;
}
gc.drawString(label, x, y, true);
gcState.foregroundRestoreAndDispose().fontRestoreAndDispose();
fontStyle.drawText(gc, label, x, y);
}
/** Draws the filled indicator rectangle. */
private void drawIndicator(GCStateManager gcState, DataSeriesStyle dStyle, Point p) {
int size = dStyle.getIndicatorSize();
gcState.backgroundStoreAndCreate(dStyle.getLineStyle().getRGBColor());
gcState.GC().fillRectangle(p.x - size / 2, p.y - size / 2, size, size);
gcState.backgroundRestoreAndDispose();
private void drawIndicator(GraphicsContext gc, DataSeriesStyle dStyle, Point2D p) {
double size = dStyle.getIndicatorSize();
dStyle.getLineStyle().applyStyle(gc);
gc.fillRect(p.getX() - size / 2, p.getY() - size / 2, size, size);
}
/** Computes the point on the given axis for the given data. */
@SuppressWarnings("unchecked")
private Point computeDataPoint(AxisBase axis, DataSeries data) {
private Point2D computeDataPoint(AxisBase axis, DataSeries data) {
Double ratio = 0.0;
if(axis instanceof DoubleAxis) {
DoubleAxis da = (DoubleAxis)axis;
......@@ -245,35 +221,35 @@ public final class SpiderChartWidget extends SpiderChartWidgetBase {
int index = Math.max(0, ea.indexOfEnumerationMember(data.getAxisValue(ea)));
ratio = (double)index / (double)segments;
}
Point outer = axesEnds.get(axis);
int deltaX = (int)(ratio * (outer.x - center.x));
int deltaY = (int)(ratio * (outer.y - center.y));
return new Point(center.x + deltaX, center.y + deltaY);
Point2D outer = axesEnds.get(axis);
int deltaX = (int)(ratio * (outer.getX() - center.getX()));
int deltaY = (int)(ratio * (outer.getY() - center.getY()));
return new Point2D(center.getX() + deltaX, center.getY() + deltaY);
}
/** Draws the axes of the spider chart. */
private Map<AxisBase, Point> drawAxes(GCStateManager gcState) {
private Map<AxisBase, Point2D> drawAxes(GraphicsContext gc) {
List<AxisBase> axes = chart.getAxes();
int size = axes.size();
double segmentDegree = 360.0 / size;
double angleDegree = 90.0;
int halfWidth = getWidth() / 2;
int halfHeight = getHeight() / 2;
int centerX = getX() + halfWidth;
int centerY = getY() + halfHeight;
double halfWidth = getWidth() / 2;
double halfHeight = getHeight() / 2;
double centerX = getX() + halfWidth;
double centerY = getY() + halfHeight;
for(int i = 0; i < size; i++) {
AxisBase axis = axes.get(i);
Point outer = axesEnds.get(axis);
Point2D outer = axesEnds.get(axis);
// draw line
AxisStyle aStyle = style.getAxisStyle(axis);
aStyle.getLineStyle().draw(gcState, centerX, centerY, outer.x, outer.y);
aStyle.getLineStyle().drawLine(gc, centerX, centerY, outer.getX(), outer.getY());
// draw label
drawAxisLabel(gcState, axis, aStyle, centerX, centerY, outer.x, outer.y);
drawAxisLabel(gc, axis, aStyle, centerX, centerY, outer.getX(), outer.getY());
if(aStyle.isUseSegmentIndicators()) {
drawSegmentIndicators(gcState, centerX, centerY, axis, outer, aStyle);
drawSegmentIndicators(gc, centerX, centerY, axis, outer, aStyle);
}
angleDegree = (angleDegree + segmentDegree) % 360.0;
}
......@@ -281,8 +257,8 @@ public final class SpiderChartWidget extends SpiderChartWidgetBase {
}
/** Draws the indicators of the given axis. */
private void drawSegmentIndicators(GCStateManager gcState, int centerX, int centerY,
AxisBase axis, Point outer, AxisStyle aStyle) {
private void drawSegmentIndicators(GraphicsContext gc, double centerX, double centerY,
AxisBase axis, Point2D outer, AxisStyle aStyle) {
// draw segment indicators
int segments = style.isUseIndividualAxisSegments() ? aStyle.getSegments()
: style.getAxisSegments();
......@@ -298,54 +274,42 @@ public final class SpiderChartWidget extends SpiderChartWidgetBase {
lbl = value.toString();
}
}
Point segmentPoint =
getSegmentPoint(segments, s, outer.x - center.x, outer.y - center.y);
drawSegmentIndicator(gcState, lbl, aStyle, centerX, centerY, segmentPoint);
Point2D segmentPoint = getSegmentPoint(segments, s, outer.getX() - center.getX(),
outer.getY() - center.getY());
drawSegmentIndicator(gc, lbl, aStyle, centerX, centerY, segmentPoint);
}
}
/** Draws the indicator on the axis. */
private void drawSegmentIndicator(GCStateManager gcState, String lbl, AxisStyle axisStyle,
int centerX, int centerY, Point segment) {
private void drawSegmentIndicator(GraphicsContext gc, String lbl, AxisStyle axisStyle,
double centerX, double centerY, Point2D segment) {
FontStyle segmentStyle = axisStyle.getSegmentStyle();
gcState.fontStoreAndCreate(segmentStyle.getFontData());
gcState.foregroundStoreAndCreate(segmentStyle.getRGBColor());
GC gc = gcState.GC();
// segment indicator labels are always to the left of the axis
int posX = centerX + segment.x - gc.textExtent(lbl).x - 4;
int posY = centerY + segment.y + 4;
gc.drawText(lbl, posX, posY, true);
gcState.foregroundRestoreAndDispose().fontRestoreAndDispose();
double textWidth = segmentStyle.getTextBounds(lbl).getWidth();
double posX = centerX + segment.getX() - textWidth - 4;
double posY = centerY + segment.getY() + 4;
segmentStyle.drawText(gc, lbl, posX, posY);
}
/** Draws the axis label at the correct position. */
private void drawAxisLabel(GCStateManager gcState, AxisBase axis, AxisStyle style, int centerX,
int centerY, int outerX, int outerY) {
private void drawAxisLabel(GraphicsContext gc, AxisBase axis, AxisStyle style, double centerX,
double centerY, double outerX, double outerY) {
String axisLabel = axis.getName();
FontData fontData = style.getLabelStyle().getFontData();
gcState.fontStoreAndCreate(fontData);
gcState.foregroundStoreAndCreate(style.getLabelStyle().getRGBColor());
int textExtent = gcState.GC().textExtent(axisLabel).x;
FontStyle labelStyle = style.getLabelStyle();
Dimension2D tb = labelStyle.getTextBounds(axisLabel);
int offset = 20;
if(outerX > centerX) {
outerX += 5;
outerX += offset;
} else if(outerX < centerX) {
outerX = outerX - 5 - textExtent;
outerX = outerX - offset - tb.getWidth();
} else {
outerX = outerX - textExtent / 2;
outerX = outerX - tb.getWidth() / 2;
}
if(outerY > centerY) {
outerY = outerY + 5;
outerY = outerY + offset + tb.getHeight() / 2;
} else if(outerY < centerY) {
outerY = outerY - 5 - fontData.getHeight();
} else {
outerY = outerY - fontData.getHeight() / 2;
outerY = outerY - offset;
}
gcState.GC().drawString(axisLabel, outerX, outerY, true);
gcState.foregroundRestoreAndDispose().fontRestoreAndDispose();
labelStyle.drawText(gc, axisLabel, outerX, outerY);
}
}
/*-------------------------------------------------------------------------+
| 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.spiderchart.widget;
/*******************************************************************************
* Copyright (c) 2017, 2018 fortiss GmbH.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0, which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.fortiss.tooling.spiderchart.control;
import org.eclipse.swt.graphics.Rectangle;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
import javafx.geometry.Rectangle2D;
/**
* Base class for elements of the spider chart.
*
* @author mondal
*
* @author hoelzl
*/
public abstract class SpiderChartWidgetBase {
public abstract class SpiderChartControlBase {
/** The spider chart this component belongs to. */
protected final SpiderChart chart;
/** The spider chart style information. */
protected final ChartStyle style;
/** The height of the component. */
protected int height;
protected double height;
/** The width of the component. */
protected int width;
protected double width;
/** The x location. */
protected int x;
protected double x;
/** The y location. */
protected int y;
protected double y;
/** Constructor. */
public SpiderChartWidgetBase(SpiderChart chart, ChartStyle style) {
public SpiderChartControlBase(SpiderChart chart, ChartStyle style) {
this.chart = chart;
this.style = style;
}
/** Sets the bounding rectangle area of this widget. */
public void setBounds(int x, int y, int width, int height) {
public void setBounds(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
......@@ -54,27 +48,27 @@ public abstract class SpiderChartWidgetBase {
}
/** Returns x. */
public final int getX() {
public final double getX() {
return x;
}
/** Returns y. */
public final int getY() {
public final double getY() {
return y;
}
/** Returns width. */
public final int getWidth() {
public final double getWidth() {
return width;
}
/** Returns height. */
public final int getHeight() {
public final double getHeight() {
return height;
}
/** Returns the bounding rectangle. */
public final Rectangle getBounds() {
return new Rectangle(x, y, width, height);
public final Rectangle2D getBounds() {
return new Rectangle2D(x, y, width, height);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment