From 784f40fcf95e4bbaa32dfcb21bd4508a32d4a994 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Fri, 26 Apr 2013 23:42:13 +0200 Subject: [PATCH] Rectangle to Rectangle2D --- .../xeiam/xchart/internal/chartpart/Axis.java | 5 ++-- .../xchart/internal/chartpart/AxisTick.java | 18 +++++++-------- .../internal/chartpart/AxisTickLabels.java | 23 +++++++++---------- .../internal/chartpart/AxisTickMarks.java | 20 ++++++---------- .../xchart/internal/chartpart/AxisTitle.java | 19 ++++++++------- .../xchart/internal/chartpart/ChartTitle.java | 1 - .../xchart/internal/chartpart/Legend.java | 3 +-- .../xeiam/xchart/internal/chartpart/Plot.java | 15 ++++++------ 8 files changed, 45 insertions(+), 59 deletions(-) diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index 39fd0e0d..49ac9f0f 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; @@ -149,8 +148,8 @@ public class Axis implements ChartPart { @Override public void paint(Graphics2D g) { - paintZone = new Rectangle(); - bounds = new Rectangle(); + paintZone = new Rectangle2D.Double(); + bounds = new Rectangle2D.Double(); // determine Axis bounds if (direction == Direction.Y) { // Y-Axis diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 86174fa9..83f547b6 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.util.List; @@ -38,7 +37,7 @@ public class AxisTick implements ChartPart { private AxisTickMarks axisTickMarks; /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(0, 0, 0, 0); + private Rectangle2D bounds = new Rectangle2D.Double(); AxisTickCalculator gridStep = null; @@ -99,15 +98,15 @@ public class AxisTick implements ChartPart { axisTickLabels.paint(g); axisTickMarks.paint(g); - bounds = new Rectangle( + bounds = new Rectangle2D.Double( - (int) axisTickLabels.getBounds().getX(), + axisTickLabels.getBounds().getX(), - (int) (axisTickLabels.getBounds().getY()), + axisTickLabels.getBounds().getY(), - (int) (axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()), + axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(), - (int) (axisTickMarks.getBounds().getHeight()) + axisTickMarks.getBounds().getHeight() ); @@ -119,9 +118,8 @@ public class AxisTick implements ChartPart { axisTickLabels.paint(g); axisTickMarks.paint(g); - bounds = new Rectangle((int) axisTickMarks.getBounds().getX(), (int) (axisTickMarks.getBounds().getY()), (int) axisTickLabels.getBounds().getWidth(), (int) (axisTickMarks.getBounds() - .getHeight() - + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight())); + bounds = new Rectangle2D.Double(axisTickMarks.getBounds().getX(), axisTickMarks.getBounds().getY(), axisTickLabels.getBounds().getWidth(), axisTickMarks.getBounds().getHeight() + + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight()); // g.setColor(Color.red); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index 7c16c821..d91f18a3 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; @@ -30,7 +29,7 @@ public class AxisTickLabels implements ChartPart { private final AxisTick axisTick; /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(0, 0, 0, 0); + private Rectangle2D bounds = new Rectangle2D.Double(); /** * Constructor @@ -57,9 +56,9 @@ public class AxisTickLabels implements ChartPart { if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis - int xOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getX() + axisTick.getAxis().getAxisTitle().getBounds().getWidth()); - int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); - int maxTickLabelWidth = 0; + double xOffset = axisTick.getAxis().getAxisTitle().getBounds().getX() + axisTick.getAxis().getAxisTitle().getBounds().getWidth(); + double yOffset = axisTick.getAxis().getPaintZone().getY(); + double maxTickLabelWidth = 0; for (int i = 0; i < axisTick.getTickLabels().size(); i++) { String tickLabel = axisTick.getTickLabels().get(i); @@ -71,7 +70,7 @@ public class AxisTickLabels implements ChartPart { // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); TextLayout layout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle2D tickLabelBounds = layout.getBounds(); - layout.draw(g, xOffset, (int) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); + layout.draw(g, (float) xOffset, (float) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); if (tickLabelBounds.getWidth() > maxTickLabelWidth) { maxTickLabelWidth = (int) tickLabelBounds.getWidth(); @@ -80,15 +79,15 @@ public class AxisTickLabels implements ChartPart { } // bounds - bounds = new Rectangle(xOffset, yOffset, maxTickLabelWidth, (int) axisTick.getAxis().getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(xOffset, yOffset, maxTickLabelWidth, (int) axisTick.getAxis().getPaintZone().getHeight()); // g.setColor(Color.blue); // g.draw(bounds); } else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis - int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); - int yOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getY()); - int maxTickLabelHeight = 0; + double xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); + double yOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getY()); + double maxTickLabelHeight = 0; for (int i = 0; i < axisTick.getTickLabels().size(); i++) { String tickLabel = axisTick.getTickLabels().get(i); @@ -98,7 +97,7 @@ public class AxisTickLabels implements ChartPart { FontRenderContext frc = g.getFontRenderContext(); TextLayout layout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle2D tickLabelBounds = layout.getBounds(); - layout.draw(g, (int) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), yOffset); + layout.draw(g, (float) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), (float) yOffset); if (tickLabelBounds.getHeight() > maxTickLabelHeight) { maxTickLabelHeight = (int) tickLabelBounds.getHeight(); @@ -107,7 +106,7 @@ public class AxisTickLabels implements ChartPart { } // bounds - bounds = new Rectangle(xOffset, yOffset - maxTickLabelHeight, (int) axisTick.getAxis().getPaintZone().getWidth(), maxTickLabelHeight); + bounds = new Rectangle2D.Double(xOffset, yOffset - maxTickLabelHeight, axisTick.getAxis().getPaintZone().getWidth(), maxTickLabelHeight); // g.setColor(Color.blue); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java index 3b512125..e876d4ca 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; @@ -30,7 +29,7 @@ public class AxisTickMarks implements ChartPart { private AxisTick axisTick; /** the bounds */ - private Rectangle2D bounds = new Rectangle2D.Double(0, 0, 0, 0); + private Rectangle2D bounds = new Rectangle2D.Double(); /** * Constructor @@ -56,8 +55,8 @@ public class AxisTickMarks implements ChartPart { if (axisTick.getAxis().getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { // Y-Axis - int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding()); - int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); + double xOffset = axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding(); + double yOffset = axisTick.getAxis().getPaintZone().getY(); // tick marks if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { @@ -89,15 +88,15 @@ public class AxisTickMarks implements ChartPart { } // bounds - bounds = new Rectangle(xOffset, yOffset, getChartPainter().getStyleManager().getAxisTickMarkLength(), (int) axisTick.getAxis().getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(xOffset, yOffset, getChartPainter().getStyleManager().getAxisTickMarkLength(), (int) axisTick.getAxis().getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); } else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis - int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); + double xOffset = axisTick.getAxis().getPaintZone().getX(); // int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); - int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChartPainter().getStyleManager().getAxisTickPadding()); + double yOffset = axisTick.getAxisTickLabels().getBounds().getY() - getChartPainter().getStyleManager().getAxisTickPadding(); // tick marks if (getChartPainter().getStyleManager().isAxisTicksMarksVisible()) { @@ -106,11 +105,8 @@ public class AxisTickMarks implements ChartPart { int tickLocation = axisTick.getTickLocations().get(i); - // g.setColor(getChart().getStyleManager().getChartBordersColor()); - // g.setStroke(stroke); Shape line = new Line2D.Double(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); g.draw(line); - // g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); } } // Line @@ -119,12 +115,10 @@ public class AxisTickMarks implements ChartPart { Shape line = new Line2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), xOffset + axisTick.getAxis().getPaintZone().getWidth(), yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength()); g.draw(line); - // g.drawLine(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.getAxis().getPaintZone().getWidth(), yOffset - // - getChartPainter().getStyleManager().getAxisTickMarkLength()); } // bounds - bounds = new Rectangle(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), (int) axisTick.getAxis().getPaintZone().getWidth(), getChartPainter().getStyleManager() + bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartPainter().getStyleManager() .getAxisTickMarkLength()); // g.setColor(Color.yellow); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java index 1af0d40a..ac58fc3f 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; @@ -55,7 +54,7 @@ public class AxisTitle implements ChartPart { @Override public void paint(Graphics2D g) { - bounds = new Rectangle(); + bounds = new Rectangle2D.Double(); g.setColor(getChartPainter().getStyleManager().getChartFontColor()); g.setFont(getChartPainter().getStyleManager().getAxisTitleFont()); @@ -81,12 +80,12 @@ public class AxisTitle implements ChartPart { // System.out.println(nonRotatedRectangle.getHeight()); // bounds - bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() - + getChartPainter().getStyleManager().getAxisTitlePadding(), (int) nonRotatedRectangle.getWidth()); + bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight() + + getChartPainter().getStyleManager().getAxisTitlePadding(), nonRotatedRectangle.getWidth()); // g.setColor(Color.blue); // g.draw(bounds); } else { - bounds = new Rectangle((int) axis.getPaintZone().getX(), (int) axis.getPaintZone().getY(), 0, (int) axis.getPaintZone().getHeight()); + bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY(), 0, axis.getPaintZone().getHeight()); } } else { @@ -98,18 +97,18 @@ public class AxisTitle implements ChartPart { Rectangle2D rectangle = textLayout.getBounds(); // System.out.println(rectangle); - int xOffset = (int) (axis.getPaintZone().getX() + (axis.getPaintZone().getWidth() - rectangle.getWidth()) / 2.0); - int yOffset = (int) (axis.getPaintZone().getY() + axis.getPaintZone().getHeight() - rectangle.getHeight()); + double xOffset = axis.getPaintZone().getX() + (axis.getPaintZone().getWidth() - rectangle.getWidth()) / 2.0; + double yOffset = axis.getPaintZone().getY() + axis.getPaintZone().getHeight() - rectangle.getHeight(); - textLayout.draw(g, xOffset, (float) (yOffset - rectangle.getY())); + textLayout.draw(g, (float) xOffset, (float) (yOffset - rectangle.getY())); - bounds = new Rectangle(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTitlePadding(), (int) rectangle.getWidth(), (int) rectangle.getHeight() + bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding()); // g.setColor(Color.blue); // g.draw(bounds); } else { - bounds = new Rectangle((int) axis.getPaintZone().getX(), (int) (axis.getPaintZone().getY() + axis.getPaintZone().getHeight()), (int) axis.getPaintZone().getWidth(), 0); + bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY() + axis.getPaintZone().getHeight(), axis.getPaintZone().getWidth(), 0); // g.setColor(Color.blue); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index ca676d8f..77ca627a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -82,7 +82,6 @@ public class ChartTitle implements ChartPart { @Override public void paint(Graphics2D g) { - // bounds = new Rectangle(); g.setFont(chartPainter.getStyleManager().getChartTitleFont()); if (chartPainter.getStyleManager().isChartTitleVisible()) { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java index b175c603..89de73a8 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java @@ -17,7 +17,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.BasicStroke; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; @@ -109,7 +108,7 @@ public class Legend implements ChartPart { @Override public void paint(Graphics2D g) { - bounds = new Rectangle(); + bounds = new Rectangle2D.Double(); g.setFont(chartPainter.getStyleManager().getLegendFont()); if (chartPainter.getStyleManager().isLegendVisible()) { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java index 7bd3e766..bf49f65c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java @@ -16,7 +16,6 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import com.xeiam.xchart.StyleManager.ChartType; @@ -57,21 +56,21 @@ public class Plot implements ChartPart { @Override public void paint(Graphics2D g) { - bounds = new Rectangle(); + bounds = new Rectangle2D.Double(); // calculate bounds - int xOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getX() + double xOffset = chartPainter.getAxisPair().getyAxis().getBounds().getX() + chartPainter.getAxisPair().getyAxis().getBounds().getWidth() + (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding() + 1) : 0) - ); + ; - int yOffset = (int) (chartPainter.getAxisPair().getyAxis().getBounds().getY()); - int width = (int) chartPainter.getAxisPair().getxAxis().getBounds().getWidth(); - int height = (int) chartPainter.getAxisPair().getyAxis().getBounds().getHeight(); - bounds = new Rectangle(xOffset, yOffset, width, height); + double yOffset = chartPainter.getAxisPair().getyAxis().getBounds().getY(); + double width = chartPainter.getAxisPair().getxAxis().getBounds().getWidth(); + double height = chartPainter.getAxisPair().getyAxis().getBounds().getHeight(); + bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); // g.setColor(Color.green); // g.draw(bounds); -- GitLab