Java Code Examples for java.awt.GradientPaint#getColor1()

The following examples show how to use java.awt.GradientPaint#getColor1() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CCSystem.java    From FCMFrame with Apache License 2.0 5 votes vote down vote up
private GradientPaint translateGradientPaint(GradientPaint gp) {
    Point p1 = translate(gp.getPoint1());
    Point p2 = translate(gp.getPoint2());

    Color c1 = gp.getColor1();
    Color c2 = gp.getColor2();

    return new GradientPaint(p1, c1, p2, c2);
}
 
Example 2
Source File: MovieScheme.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
/**
 * calculates a color along the gradient
 * this is essentially a re-located function that tyler wrote
 * 
 * @param colorGradient the color gradient
 * @param gradientValue the location along the gradient (on 0 to 1)
 * @return the intermediate color
 */
private static MovieAppearance getIntermediateAppearance(
		GradientPaint colorGradient, double gradientValue, 
		Boolean opacityState, Boolean sizeState, String cellType) {
	
	Color startColor = null, endColor = null;
	
	if (colorGradient != null) {
		
		startColor = colorGradient.getColor1();
		endColor = colorGradient.getColor2();
	}
		
	Double startOpacity = 0.025;
	Double endOpacity = 0.75;
	Double startSize = 1.0;
	Double endSize = GlobalConstants.DEFAULT_COMPONENT_WIDTH + 20.0;
	
	if (cellType.equals(GlobalConstants.SPECIES)) {
		
		endSize = GlobalConstants.DEFAULT_SPECIES_WIDTH + 20.0;
	}
	
	MovieAppearance newAppearance = new MovieAppearance();
	
	if (gradientValue <= 0.0) {
		newAppearance.color = startColor;
		if (opacityState == true) newAppearance.opacity = startOpacity;
		if (sizeState == true) newAppearance.size = startSize;
	}
	else if (gradientValue >= 1.0) {
		newAppearance.color = endColor;
		if (opacityState == true) newAppearance.opacity = endOpacity;
		if (sizeState == true) newAppearance.size = endSize;
	}
	else{
		
		float oneMinusRatio = (float)1.0 - (float)gradientValue;
		
		//COLOR
		if(startColor != null && endColor != null) {
			
			int newRed = (int)Math.round(startColor.getRed() * oneMinusRatio + 
					endColor.getRed() * gradientValue);
			if (newRed > 255) newRed = 255;
			
			int newGreen = (int)Math.round(startColor.getGreen() * oneMinusRatio + 
					endColor.getGreen() * gradientValue);
			if (newGreen > 255) newGreen = 255;
			
			int newBlue = (int)Math.round(startColor.getBlue() * oneMinusRatio + 
					endColor.getBlue() * gradientValue);
			if (newBlue > 255) newBlue = 255;
			
			newAppearance.color = new Color(newRed, newGreen, newBlue);
		}
		else newAppearance.color = endColor;
		
		//OPACITY
		if(opacityState == true)
			newAppearance.opacity = startOpacity * oneMinusRatio + endOpacity * gradientValue;
		
		//SIZE
		if(sizeState == true)
			newAppearance.size = startSize * oneMinusRatio + endSize * gradientValue;		
	}
	
	return newAppearance;
}
 
Example 3
Source File: CustomStackedBarRenderer.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for a series.
 * 
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

	CategoryPlot cp = getPlot();
	if (cp == null) {
		return null;
	}

	CategoryDataset dataset;
	dataset = cp.getDataset(datasetIndex);
	String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
	String description = label;
	String toolTipText = null;
	if (getLegendItemToolTipGenerator() != null) {
		toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
	}
	String urlText = null;
	if (getLegendItemURLGenerator() != null) {
		urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
	}
	Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
	Paint paint = getSeriesPaint(series);
	Paint outlinePaint = getSeriesOutlinePaint(series);
	Stroke outlineStroke = getSeriesOutlineStroke(series);

	// This is the fix for bug #2695
	if (paint instanceof java.awt.GradientPaint) {
		// When the paintstyle is "shade" use the lighter
		// color while with "light" use the darker color
		// NOTE: if we take the lighter color (Color2) and make it darker
		// and it equals the darker color (Color1) then the paintstyle
		// is "shade".
		GradientPaint gp = ((GradientPaint) paint);
		if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
			paint = gp.getColor2(); // the lighter color
		else
			paint = gp.getColor1(); // the darker color
	}

	return new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
}
 
Example 4
Source File: CustomBarRenderer.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for a series.
 * 
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

	CategoryPlot cp = getPlot();
	if (cp == null) {
		return null;
	}

	CategoryDataset dataset;
	dataset = cp.getDataset(datasetIndex);
	String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
	String description = label;
	String toolTipText = null;
	if (getLegendItemToolTipGenerator() != null) {
		toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
	}
	String urlText = null;
	if (getLegendItemURLGenerator() != null) {
		urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
	}
	Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
	Paint paint = getSeriesPaint(series);
	Paint outlinePaint = getSeriesOutlinePaint(series);
	Stroke outlineStroke = getSeriesOutlineStroke(series);

	// This is the fix for bug #2695
	if (paint instanceof java.awt.GradientPaint) {
		// When the paintstyle is "shade" use the lighter
		// color while with "light" use the darker color
		// NOTE: if we take the lighter color (Color2) and make it darker
		// and it equals the darker color (Color1) then the paintstyle
		// is "shade".
		GradientPaint gp = ((GradientPaint) paint);
		if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
			paint = gp.getColor2(); // the lighter color
		else
			paint = gp.getColor1(); // the darker color
	}

	return new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
}
 
Example 5
Source File: CustomBarRenderer3D.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for a series.
 * 
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

	CategoryPlot cp = getPlot();
	if (cp == null) {
		return null;
	}

	CategoryDataset dataset;
	dataset = cp.getDataset(datasetIndex);
	String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
	String description = label;
	String toolTipText = null;
	if (getLegendItemToolTipGenerator() != null) {
		toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
	}
	String urlText = null;
	if (getLegendItemURLGenerator() != null) {
		urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
	}
	Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
	Paint paint = getSeriesPaint(series);
	Paint outlinePaint = getSeriesOutlinePaint(series);
	Stroke outlineStroke = getSeriesOutlineStroke(series);

	// This is the fix for bug #2695
	if (paint instanceof java.awt.GradientPaint) {
		// When the paintstyle is "shade" use the lighter
		// color while with "light" use the darker color
		// NOTE: if we take the lighter color (Color2) and make it darker
		// and it equals the darker color (Color1) then the paintstyle
		// is "shade".
		GradientPaint gp = ((GradientPaint) paint);
		if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
			paint = gp.getColor2(); // the lighter color
		else
			paint = gp.getColor1(); // the darker color
	}

	return new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
}
 
Example 6
Source File: CustomStackedBarRenderer3D.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for a series.
 * 
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

	CategoryPlot cp = getPlot();
	if (cp == null) {
		return null;
	}

	CategoryDataset dataset;
	dataset = cp.getDataset(datasetIndex);
	String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
	String description = label;
	String toolTipText = null;
	if (getLegendItemToolTipGenerator() != null) {
		toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
	}
	String urlText = null;
	if (getLegendItemURLGenerator() != null) {
		urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
	}
	Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
	Paint paint = getSeriesPaint(series);
	Paint outlinePaint = getSeriesOutlinePaint(series);
	Stroke outlineStroke = getSeriesOutlineStroke(series);

	// This is the fix for bug #2695
	if (paint instanceof java.awt.GradientPaint) {
		// When the paintstyle is "shade" use the lighter
		// color while with "light" use the darker color
		// NOTE: if we take the lighter color (Color2) and make it darker
		// and it equals the darker color (Color1) then the paintstyle
		// is "shade".
		GradientPaint gp = ((GradientPaint) paint);
		if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
			paint = gp.getColor2(); // the lighter color
		else
			paint = gp.getColor1(); // the darker color
	}

	return new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
}
 
Example 7
Source File: SVGGradientPaint.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param arg0
 * @param arg1
 * @param arg2
 * @param arg3
 * @param arg4
 * @param arg5
 * @param gradientPaint
 */
public SVGGradientPaint(GradientPaint gradientPaint) {
	super(gradientPaint.getPoint1(), gradientPaint.getColor1(), gradientPaint.getPoint2(), gradientPaint.getColor2(), gradientPaint.isCyclic());
	this.gradientPaint = gradientPaint;
}