下面列出了怎么用java.awt.geom.RectangularShape的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(renderer.getShadowPaint());
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(renderer.getShadowPaint());
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param selected is the data item selected?
* @param bar the bar.
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*
* @since 1.2.0
*/
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, boolean selected, RectangularShape bar,
RectangleEdge base, boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column, selected);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double x0 = bar.getMinX();
double x1 = Math.rint(x0 + (bar.getWidth() * a));
double x2 = Math.rint(x0 + (bar.getWidth() * b));
double x3 = Math.rint(x0 + (bar.getWidth() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
x1 - x0, bar.getHeight());
result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1,
bar.getHeight());
result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2,
bar.getHeight());
result[3] = new Rectangle2D.Double(x3, bar.getMinY(),
bar.getMaxX() - x3, bar.getHeight());
return result;
}
/**
* Draws the component background.
*
* @param g
* the graphics context
*/
public void paintComponent(Graphics g) {
RectangularShape rectangle;
int radius = RapidLookAndFeel.CORNER_DEFAULT_RADIUS;
switch (position) {
case SwingConstants.LEFT:
rectangle = new RoundRectangle2D.Double(0, 0, button.getWidth() + radius, button.getHeight(), radius,
radius);
break;
case SwingConstants.CENTER:
rectangle = new Rectangle2D.Double(0, 0, button.getWidth(), button.getHeight());
break;
default:
rectangle = new RoundRectangle2D.Double(-radius, 0, button.getWidth() + radius, button.getHeight(), radius,
radius);
break;
}
RapidLookTools.drawButton(button, g, rectangle);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double x0 = bar.getMinX();
double x1 = Math.rint(x0 + (bar.getWidth() * a));
double x2 = Math.rint(x0 + (bar.getWidth() * b));
double x3 = Math.rint(x0 + (bar.getWidth() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
x1 - x0, bar.getHeight());
result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1,
bar.getHeight());
result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2,
bar.getHeight());
result[3] = new Rectangle2D.Double(x3, bar.getMinY(),
bar.getMaxX() - x3, bar.getHeight());
return result;
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double x0 = bar.getMinX();
double x1 = Math.rint(x0 + (bar.getWidth() * a));
double x2 = Math.rint(x0 + (bar.getWidth() * b));
double x3 = Math.rint(x0 + (bar.getWidth() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
x1 - x0, bar.getHeight());
result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1,
bar.getHeight());
result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2,
bar.getHeight());
result[3] = new Rectangle2D.Double(x3, bar.getMinY(),
bar.getMaxX() - x3, bar.getHeight());
return result;
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double x0 = bar.getMinX();
double x1 = Math.rint(x0 + (bar.getWidth() * a));
double x2 = Math.rint(x0 + (bar.getWidth() * b));
double x3 = Math.rint(x0 + (bar.getWidth() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
x1 - x0, bar.getHeight());
result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1,
bar.getHeight());
result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2,
bar.getHeight());
result[3] = new Rectangle2D.Double(x3, bar.getMinY(),
bar.getMaxX() - x3, bar.getHeight());
return result;
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
public PseudoSpectraRenderer(Color color, boolean isTransparent) {
this.isTransparent = isTransparent;
// Set painting color
setDefaultPaint(color);
// Shadow makes fake peaks
setShadowVisible(false);
// Set the tooltip generator
SpectraToolTipGenerator tooltipGenerator = new SpectraToolTipGenerator();
setDefaultToolTipGenerator(tooltipGenerator);
// We want to paint the peaks using simple color without any gradient
// effects
setBarPainter(new StandardXYBarPainter() {
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column,
RectangularShape bar, RectangleEdge base) {
super.paintBar(g2, renderer, row, column, new Rectangle2D.Double(
bar.getX() + (bar.getWidth() - 1.5) / 2, bar.getY(), 1.5, bar.getHeight()), base);
}
});
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(Color.gray);
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(renderer.getShadowPaint());
g2.fill(shadow);
}
/**
* Splits a bar into subregions (elsewhere, these subregions will have
* different gradients applied to them).
*
* @param bar the bar shape.
* @param a the first division.
* @param b the second division.
* @param c the third division.
*
* @return An array containing four subregions.
*/
private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a,
double b, double c) {
Rectangle2D[] result = new Rectangle2D[4];
double y0 = bar.getMinY();
double y1 = Math.rint(y0 + (bar.getHeight() * a));
double y2 = Math.rint(y0 + (bar.getHeight() * b));
double y3 = Math.rint(y0 + (bar.getHeight() * c));
result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(),
bar.getWidth(), y1 - y0);
result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(),
y2 - y1);
result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(),
y3 - y2);
result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(),
bar.getMaxY() - y3);
return result;
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
* @param pegShadow peg the shadow to the base of the bar?
*/
@Override
public void paintBarShadow(Graphics2D g2, BarRenderer renderer, int row,
int column, RectangularShape bar, RectangleEdge base,
boolean pegShadow) {
// handle a special case - if the bar colour has alpha == 0, it is
// invisible so we shouldn't draw any shadow
Paint itemPaint = renderer.getItemPaint(row, column);
if (itemPaint instanceof Color) {
Color c = (Color) itemPaint;
if (c.getAlpha() == 0) {
return;
}
}
RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
renderer.getShadowYOffset(), base, pegShadow);
g2.setPaint(renderer.getShadowPaint());
g2.fill(shadow);
}
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param selected is the item selected?
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
public void paintBar(Graphics2D g2, BarRenderer renderer, int row,
int column, boolean selected, RectangularShape bar,
RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column, selected);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column,
selected);
Paint paint = renderer.getItemOutlinePaint(row, column, selected);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
private void paintCalloutCircularImage(Graphics2D g, CalloutComponentInfo calloutInfo,
RectangularShape shape) {
//
// First draw the background circle that will sit beneath the image, to create a
// ring around the image
//
g.setColor(CALLOUT_SHAPE_COLOR);
g.fill(shape);
//
// Now, make the image a bit smaller, so that the background is a ring around the image
//
int offset = 3;
Rectangle sr = shape.getBounds(); // shape rectangle
Rectangle ir = new Rectangle(); // image rectangle
ir.x = sr.x + offset;
ir.y = sr.y + offset;
ir.width = sr.width - (2 * offset);
ir.height = sr.height - (2 * offset);
shape.setFrame(ir); // change the size for the image
Dimension imageSize = ir.getSize();
Image foregroundImage =
createMagnifiedImage(g.getDeviceConfiguration(), imageSize, calloutInfo, shape);
shape.setFrame(sr); // restore
g.drawImage(foregroundImage, ir.x, ir.y, null);
}