Skip to content
Snippets Groups Projects
Commit cde28e7a authored by Florian Hölzl's avatar Florian Hölzl
Browse files

More cleanup of spiderchart code.

refs 2589
parent c4d5b363
No related branches found
No related tags found
No related merge requests found
......@@ -734,39 +734,41 @@ public final class SpiderChart {
this.offsetY, this.getWidth() + this.offsetX, this.getHeight() + this.offsetY);
}
if(this.plotters[0].getxScale() != null) {
this.plotters[0].getxScale().setScreenMax(this.plotters[0].x + this.plotters[0].width);
this.plotters[0].getxScale().setScreenMax(
this.plotters[0].getX() + this.plotters[0].getWidth());
this.plotters[0].getxScale().setScreenMaxMargin(
(int)(this.plotters[0].getxScale().getScreenMax() * (1.0D - this.axisMargin)));
if(this.fullXAxis) {
this.plotters[0].getxScale().setScreenMaxMargin(
this.plotters[0].getxScale().getScreenMax());
}
this.plotters[0].getxScale().setScreenMin(this.plotters[0].x);
this.plotters[0].getxScale().setScreenMin(this.plotters[0].getX());
}
if(this.plotters[0].getyScale() != null) {
this.plotters[0].getyScale().setScreenMax(this.plotters[0].y + this.plotters[0].height);
this.plotters[0].getyScale().setScreenMax(
this.plotters[0].getY() + this.plotters[0].getHeight());
this.plotters[0].getyScale().setScreenMaxMargin(
(int)(this.plotters[0].getyScale().getScreenMax() * (1.0D - this.axisMargin)));
this.plotters[0].getyScale().setScreenMin(this.plotters[0].y);
this.plotters[0].getyScale().setScreenMin(this.plotters[0].getY());
}
if(this.repaintAll) {
final int plotterBackWidth = this.plotters[0].width;
final int plotterBackHeight = this.plotters[0].height;
final int plotterBackWidth = this.plotters[0].getWidth();
final int plotterBackHeight = this.plotters[0].getHeight();
this.plotters[0].plotBackground(gScroll, plotterBackWidth, plotterBackHeight,
this.offsetX, this.offsetY);
}
this.title.chart = this;
this.title.setChart(this);
this.title.draw(g);
if(this.legend == null) {
this.legend = new SpiderChartLegend();
}
if(this.legend != null) {
this.legend.chart = this;
this.legend.setChart(this);
this.legend.draw(g);
}
if(this.repaintAll) {
for(int i = 0; i < this.plottersCount; i++) {
this.plotters[i].chart = this;
this.plotters[i].setChart(this);
this.plotters[i].plot(gScroll);
}
}
......@@ -774,14 +776,14 @@ public final class SpiderChart {
this.border.drawRect(g, 0, 0, this.getWidth() - 1, this.getHeight() - 1);
}
if(this.chartImage != null) {
final int x1 = this.plotters[0].x;
final int x1 = this.plotters[0].getX();
final int x2 = this.plotters[0].x + this.plotters[0].getVisibleWidth();
final int x2 = this.plotters[0].getX() + this.plotters[0].getVisibleWidth();
final int y1 = this.plotters[0].y - this.plotters[0].getDepth();
final int y1 = this.plotters[0].getY() - this.plotters[0].getDepth();
final int y2 =
this.plotters[0].y - this.plotters[0].getDepth() +
this.plotters[0].getY() - this.plotters[0].getDepth() +
this.plotters[0].getVisibleHeight();
g.drawImage(this.chartImage, x1, y1, x2, y2, x1 + this.offsetX, y1 + this.offsetY, x2 +
......@@ -886,22 +888,23 @@ public final class SpiderChart {
.setVisibleWidth((int)(myWidth * (1.0D - (this.legendMargin + this.leftMargin))));
this.plotters[0]
.setVisibleHeight((int)(myHeight * (1.0D - (this.topMargin + this.bottomMargin))));
this.plotters[0].setX((int)(myWidth * this.leftMargin));
this.plotters[0].setY((int)(myHeight * this.topMargin));
this.plotters[0].setWidth(this.virtualWidth -
(myWidth - this.plotters[0].getVisibleWidth()));
this.plotters[0].setHeight(this.virtualHeight -
(myHeight - this.plotters[0].getVisibleHeight()));
this.title.setX(0);
this.title.setY(0);
this.title.setHeight((int)(myHeight * this.topMargin));
this.title.setWidth(myWidth);
this.plotters[0].x = (int)(myWidth * this.leftMargin);
this.plotters[0].y = (int)(myHeight * this.topMargin);
this.plotters[0].width = this.virtualWidth - (myWidth - this.plotters[0].getVisibleWidth());
this.plotters[0].height =
this.virtualHeight - (myHeight - this.plotters[0].getVisibleHeight());
this.title.x = 0;
this.title.y = 0;
this.title.height = (int)(myHeight * this.topMargin);
this.title.width = myWidth;
if(this.legend != null) {
this.legend.x = (int)(myWidth * (1.0D - this.legendMargin));
this.legend.width = (int)(myWidth * this.legendMargin);
this.legend.y = (int)(myHeight * this.topMargin);
this.legend.height = (int)(myHeight * 0.5D);
this.legend.setX((int)(myWidth * (1.0D - this.legendMargin)));
this.legend.setY((int)(myHeight * this.topMargin));
this.legend.setWidth((int)(myWidth * this.legendMargin));
this.legend.setHeight((int)(myHeight * 0.5D));
}
this.setPlotterSize();
}
......@@ -1057,10 +1060,10 @@ public final class SpiderChart {
/** */
private void setPlotterSize() {
for(int i = 1; i < this.plottersCount; i++) {
this.plotters[i].x = this.plotters[0].x;
this.plotters[i].y = this.plotters[0].y;
this.plotters[i].width = this.plotters[0].width;
this.plotters[i].height = this.plotters[0].height;
this.plotters[i].setX(this.plotters[0].getX());
this.plotters[i].setY(this.plotters[0].getY());
this.plotters[i].setWidth(this.plotters[0].getWidth());
this.plotters[i].setHeight(this.plotters[0].getHeight());
}
}
......
/*--------------------------------------------------------------------------+
$Id$
| |
| 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;
/**
* Every Spider Chart Canvas must extend this class to adapt to the Spider Chart
* Component Description
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public abstract class SpiderChartComponent {
/** The Actual Spider Chart Diagram */
protected SpiderChart chart;
/** The height of the component */
protected int height;
/** the width of the component */
protected int width;
/** the screen x-axis value */
protected int x;
/** the screen y-axis value */
protected int y;
}
......@@ -20,7 +20,6 @@ package org.fortiss.tooling.spiderchart.model;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.tooling.spiderchart.SpiderChartComponent;
import org.fortiss.tooling.spiderchart.gc.AbstractChartGraphics;
import org.fortiss.tooling.spiderchart.gc.AbstractChartImage;
import org.fortiss.tooling.spiderchart.scale.SpiderChartScale;
......@@ -35,7 +34,7 @@ import org.fortiss.tooling.spiderchart.style.FillStyle;
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public abstract class AbstractPlotter extends SpiderChartComponent {
public abstract class AbstractPlotter extends SpiderChartComponentBase {
/** Spider Chart Background Image */
private AbstractChartImage backgroundImage;
......
......@@ -15,59 +15,125 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.gc.swt;
package org.fortiss.tooling.spiderchart.model;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.gc.Fonts;
import org.fortiss.tooling.spiderchart.SpiderChart;
/**
* Represents a font to be used in SWT
* Base class for elements (title, axes, legend, data plots) of the spider chart.
*
* @author mondal
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartSwtFont {
/** name of the font */
private String fontName = "";
/** size of the font */
private int fontSize = 10;
/** style of the font */
private int fontStyle = SWT.NORMAL;
/** Constructor */
public SpiderChartSwtFont(Font f) {
this.fontName = f.getFontData()[0].getName();
final int s = f.getFontData()[0].getStyle();
this.fontStyle = SWT.NORMAL;
if((s & 0x1) == 1) {
this.fontStyle = SWT.BOLD;
}
if((s & 0x2) == 2) {
this.fontStyle = SWT.ITALIC;
}
if((s & 0x3) == 3) {
this.fontStyle = SWT.BOLD | SWT.ITALIC;
}
// Font system returns at least one font data on each platform
this.fontSize = f.getFontData()[0].getHeight();
public abstract class SpiderChartComponentBase {
/** The spider chart this component belongs to. */
protected SpiderChart chart;
/** The height of the component. */
protected int height;
/** The width of the component. */
protected int width;
/** The screen x-axis value. */
protected int x;
/** The screen y-axis value. */
protected int y;
/** The {@link SWT} foreground system color. */
private int swtForegroundColor;
/** The {@link SWT} background system color. */
private int swtBackgroundColor;
/** The font data. */
private FontData fontData = new FontData("Verdana", 10, SWT.NORMAL);
/** Sets the background color. */
public final void setSwtBackgroundColor(int swtBackgroundColor) {
this.swtBackgroundColor = swtBackgroundColor;
}
/** Sets the foreground color. */
public final void setSwtForegroundColor(int swtForegroundColor) {
this.swtForegroundColor = swtForegroundColor;
}
/** Sets font parameters. */
public final void setFontName(String fontName, int fontSize, int swtFontStyle) {
fontData.setName(fontName);
fontData.setHeight(fontSize);
fontData.setStyle(swtFontStyle);
}
/** Sets chart. */
@Deprecated
public void setChart(SpiderChart chart) {
this.chart = chart;
}
/** Sets x. */
public void setX(int x) {
this.x = x;
}
/** Sets y. */
public void setY(int y) {
this.y = y;
}
/** Sets width. */
public void setWidth(int width) {
this.width = width;
}
/** Sets height. */
public void setHeight(int height) {
this.height = height;
}
/** Returns the {@link Color} of the foreground. NEVER dispose this color object. */
public final Color getForegroundColor() {
return Display.getCurrent().getSystemColor(swtForegroundColor);
}
/** Returns the {@link Color} of the background. NEVER dispose this color object. */
public final Color getBackgroundColor() {
return Display.getCurrent().getSystemColor(swtBackgroundColor);
}
/** Creates a new font instance. ALWAYS dispose this afterwards. */
public Font createFont() {
return new Font(Display.getCurrent(), fontData);
}
/** Returns x. */
public final int getX() {
return x;
}
/** Returns y. */
public final int getY() {
return y;
}
/** Constructor */
public SpiderChartSwtFont(Fonts f, int style, int size) {
this.fontName = f.getFontName();
this.fontSize = size;
this.fontStyle = style;
/** Returns width. */
public final int getWidth() {
return width;
}
/** getter for the font object used */
public Font getFont() {
return new Font(Display.getCurrent(), fontName, fontSize, fontStyle);
/** Returns height. */
public final int getHeight() {
return height;
}
}
......@@ -28,7 +28,6 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.SpiderChartComponent;
import org.fortiss.tooling.spiderchart.gc.AbstractChartGraphics;
import org.fortiss.tooling.spiderchart.gc.AbstractChartImage;
import org.fortiss.tooling.spiderchart.label.SpiderChartLabel;
......@@ -43,7 +42,7 @@ import org.fortiss.tooling.spiderchart.style.LineStyle;
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartLegend extends SpiderChartComponent {
public final class SpiderChartLegend extends SpiderChartComponentBase {
/** Legend Background Style */
private FillStyle background;
......
......@@ -17,42 +17,35 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.model;
import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.SpiderChartComponent;
import org.eclipse.swt.graphics.Font;
import org.fortiss.tooling.spiderchart.gc.AbstractChartGraphics;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtFont;
/**
* Used to represent Spider Chart Title
* Class representing the spider charts title.
*
* @author mondal
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartTitle extends SpiderChartComponent {
/** Title Color */
private Color color = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
public final class SpiderChartTitle extends SpiderChartComponentBase {
/** Title Font */
private SpiderChartSwtFont font = new SpiderChartSwtFont(VERDANA, SWT.NORMAL, 14);
/** Title Text */
/** The title text. */
private String text;
/** Constructor */
public SpiderChartTitle() {
setSwtForegroundColor(SWT.COLOR_BLACK);
setFontName("Verdana", 14, SWT.NORMAL);
}
/** Used to draw the title */
public void draw(final AbstractChartGraphics g) {
g.setColor(this.color);
g.setFont(font.getFont());
public void draw(AbstractChartGraphics g) {
g.setColor(getForegroundColor());
Font f = createFont();
g.setFont(f);
final String[] txt = new String[3];
txt[0] = this.text;
......@@ -70,36 +63,11 @@ public final class SpiderChartTitle extends SpiderChartComponent {
(i + 1));
}
}
g.getFont().dispose();
}
/** Getter for color */
public Color getChartColor() {
return this.color;
}
/** Getter for chart font */
public SpiderChartSwtFont getChartFont() {
return this.font;
}
/** Getter for chart text */
public String getText() {
return this.text;
}
/** Setter for color */
public void setColor(Color color) {
this.color = color;
}
/** Setter for chart font */
public void setFont(SpiderChartSwtFont font) {
this.font = font;
f.dispose();
}
/** Setter for chart text */
public void setText(final String text) {
/** Sets the chart title text. */
public final void setText(final String text) {
this.text = text;
}
}
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