2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
2008-03-02 17:02:37 +00:00
|
|
|
import java.awt.LinearGradientPaint;
|
|
|
|
import java.awt.MultipleGradientPaint.CycleMethod;
|
2007-12-23 19:28:04 +00:00
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
import java.awt.geom.RectangularShape;
|
|
|
|
|
|
|
|
|
|
|
|
public enum GradientStyle {
|
2008-03-02 17:02:37 +00:00
|
|
|
TOP_TO_BOTTOM,
|
|
|
|
BOTTOM_TO_TOP,
|
|
|
|
LEFT_TO_RIGHT,
|
|
|
|
RIGHT_TO_LEFT,
|
|
|
|
TOP_LEFT_TO_BOTTOM_RIGHT,
|
|
|
|
BOTTOM_RIGHT_TO_TOP_LEFT,
|
|
|
|
TOP_RIGHT_TO_BOTTOM_LEFT,
|
|
|
|
BOTTOM_LEFT_TO_TOP_RIGHT;
|
2007-12-23 19:28:04 +00:00
|
|
|
|
2008-03-02 17:02:37 +00:00
|
|
|
public LinearGradientPaint getGradientPaint(RectangularShape shape, Color gradientBeginColor, Color gradientEndColor) {
|
2007-12-23 19:28:04 +00:00
|
|
|
Point2D start = null;
|
|
|
|
Point2D end = null;
|
|
|
|
|
|
|
|
switch (this) {
|
|
|
|
case BOTTOM_TO_TOP:
|
|
|
|
start = new Point2D.Double(shape.getCenterX(), shape.getMaxY());
|
|
|
|
end = new Point2D.Double(shape.getCenterX(), shape.getMinY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_TO_BOTTOM:
|
|
|
|
end = new Point2D.Double(shape.getCenterX(), shape.getMaxY());
|
|
|
|
start = new Point2D.Double(shape.getCenterX(), shape.getMinY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFT_TO_RIGHT:
|
|
|
|
start = new Point2D.Double(shape.getMinX(), shape.getCenterY());
|
|
|
|
end = new Point2D.Double(shape.getMaxX(), shape.getCenterY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIGHT_TO_LEFT:
|
|
|
|
end = new Point2D.Double(shape.getMinX(), shape.getCenterY());
|
|
|
|
start = new Point2D.Double(shape.getMaxX(), shape.getCenterY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_LEFT_TO_BOTTOM_RIGHT:
|
|
|
|
start = new Point2D.Double(shape.getMinX(), shape.getMinY());
|
|
|
|
end = new Point2D.Double(shape.getMaxX(), shape.getMaxY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOTTOM_RIGHT_TO_TOP_LEFT:
|
|
|
|
end = new Point2D.Double(shape.getMinX(), shape.getMinY());
|
|
|
|
start = new Point2D.Double(shape.getMaxX(), shape.getMaxY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOP_RIGHT_TO_BOTTOM_LEFT:
|
|
|
|
start = new Point2D.Double(shape.getMaxX(), shape.getMinY());
|
|
|
|
end = new Point2D.Double(shape.getMinX(), shape.getMaxY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOTTOM_LEFT_TO_TOP_RIGHT:
|
|
|
|
end = new Point2D.Double(shape.getMaxX(), shape.getMinY());
|
|
|
|
start = new Point2D.Double(shape.getMinX(), shape.getMaxY());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2008-03-02 17:02:37 +00:00
|
|
|
Color[] colors = { gradientBeginColor, gradientEndColor };
|
|
|
|
float[] fractions = { 0.0f, 1.0f };
|
|
|
|
return new LinearGradientPaint(start, end, fractions, colors, CycleMethod.NO_CYCLE);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|