use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class MolecularTypeSmallShape method paintSpecies.
// --------------------------------------------------------------------------------------
// paintComponent is being overridden in the renderer
//
private void paintSpecies(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Color primaryColor = null;
Color border = Color.black;
int finalHeight = baseHeight;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (mt == null && mtp == null) {
if (shapeManager == null) {
primaryColor = Color.green.darker().darker();
} else {
primaryColor = shapeManager.isEditable() ? Color.green.darker().darker() : Color.gray;
}
finalHeight = baseHeight + 3;
Point2D center = new Point2D.Float(xPos + finalHeight / 3, yPos + finalHeight / 3);
float radius = finalHeight * 0.5f;
Point2D focus = new Point2D.Float(xPos + finalHeight / 3 - 1, yPos + finalHeight / 3 - 1);
float[] dist = { 0.1f, 1.0f };
Color[] colors = { Color.white, primaryColor };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, finalHeight, finalHeight);
g2.fill(circle);
Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, finalHeight, finalHeight);
g2.setPaint(getDefaultColor(Color.darkGray));
g2.draw(circle2);
g.setColor(colorOld);
return;
} else {
// molecular type, species pattern, observable
if (mt == null || mt.getModel() == null) {
primaryColor = Color.blue.darker().darker();
} else {
if (shapeManager != null) {
if (shapeManager.isShowMoleculeColor()) {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = MolecularTypeLargeShape.colorTable[index].darker().darker();
} else {
primaryColor = Color.gray;
}
border = shapeManager.isEditable() ? Color.black : LargeShapeCanvas.uneditableShape;
} else {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = MolecularTypeLargeShape.colorTable[index].darker().darker();
}
}
if (owner instanceof MolecularType && hasErrorIssues(owner, mt)) {
primaryColor = Color.red;
}
}
GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + finalHeight / 2, Color.WHITE, true);
g2.setPaint(p);
RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, finalHeight, cornerArc, cornerArc);
g2.fill(rect);
RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, finalHeight - 2, cornerArc - 3, cornerArc - 3);
g2.setPaint(border);
g2.draw(rect);
g.setColor(colorOld);
for (MolecularComponentSmallShape mcss : componentShapes) {
mcss.paintSelf(g);
}
g.setColor(colorOld);
}
use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class VisItShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Stroke strokeOld = g2.getStroke();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// (diameter-circleDiameter) / 2
int xx = 1;
int yy = 1;
Color out2, out1, exterior, middle, interior, pole;
if (state == State.enabled) {
out2 = Color.red.darker();
out1 = Color.red;
exterior = Color.orange;
middle = Color.yellow;
interior = Color.green;
pole = Color.cyan.darker();
xx += x;
yy += y;
} else {
out2 = Color.darkGray;
out1 = Color.gray;
exterior = Color.lightGray;
middle = Color.gray;
interior = Color.gray;
pole = Color.darkGray;
xx += x;
yy += y;
}
Ellipse2D e = new Ellipse2D.Double(xx, yy, circleDiameter, circleDiameter);
Point2D center = new Point2D.Float(xx + circleDiameter / 2, yy + circleDiameter / 2);
// *0.7f;
float radius = circleDiameter + 2;
Point2D focus = new Point2D.Float(xx + circleDiameter / 2 + 7, yy + circleDiameter / 2 + 5);
float[] dist = { 0.1f, 0.15f, 0.25f, 0.35f, 0.45f, 0.6f };
Color[] colors = { pole, interior, middle, exterior, out1, out2 };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
g2.fill(e);
g.setColor(Color.gray);
g2.draw(e);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.RadialGradientPaint in project jdk8u_jdk by JetBrains.
the class BufferedPaints method setRadialGradientPaint.
/********************** RadialGradientPaint support *************************/
/**
* This method calculates six m** values and a focusX value that
* are used by the native fragment shader. These techniques are
* based on a whitepaper by Daniel Rice on radial gradient performance
* (attached to the bug report for 6521533). One can refer to that
* document for the complete set of formulas and calculations, but
* the basic goal is to compose a transform that will convert an
* (x,y) position in device space into a "u" value that represents
* the relative distance to the gradient focus point. The resulting
* value can be used to look up the appropriate color by linearly
* interpolating between the two nearest colors in the gradient.
*/
private static void setRadialGradientPaint(RenderQueue rq, SunGraphics2D sg2d, RadialGradientPaint paint, boolean useMask) {
boolean linear = (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
int cycleMethod = paint.getCycleMethod().ordinal();
float[] fractions = paint.getFractions();
Color[] colors = paint.getColors();
int numStops = colors.length;
int[] pixels = convertToIntArgbPrePixels(colors, linear);
Point2D center = paint.getCenterPoint();
Point2D focus = paint.getFocusPoint();
float radius = paint.getRadius();
// save original (untransformed) center and focus points
double cx = center.getX();
double cy = center.getY();
double fx = focus.getX();
double fy = focus.getY();
// transform from gradient coords to device coords
AffineTransform at = paint.getTransform();
at.preConcatenate(sg2d.transform);
focus = at.transform(focus, focus);
// transform unit circle to gradient coords; we start with the
// unit circle (center=(0,0), focus on positive x-axis, radius=1)
// and then transform into gradient space
at.translate(cx, cy);
at.rotate(fx - cx, fy - cy);
at.scale(radius, radius);
// invert to get mapping from device coords to unit circle
try {
at.invert();
} catch (Exception e) {
at.setToScale(0.0, 0.0);
}
focus = at.transform(focus, focus);
// clamp the focus point so that it does not rest on, or outside
// of, the circumference of the gradient circle
fx = Math.min(focus.getX(), 0.99);
// assert rq.lock.isHeldByCurrentThread();
rq.ensureCapacity(20 + 28 + (numStops * 4 * 2));
RenderBuffer buf = rq.getBuffer();
buf.putInt(SET_RADIAL_GRADIENT_PAINT);
buf.putInt(useMask ? 1 : 0);
buf.putInt(linear ? 1 : 0);
buf.putInt(numStops);
buf.putInt(cycleMethod);
buf.putFloat((float) at.getScaleX());
buf.putFloat((float) at.getShearX());
buf.putFloat((float) at.getTranslateX());
buf.putFloat((float) at.getShearY());
buf.putFloat((float) at.getScaleY());
buf.putFloat((float) at.getTranslateY());
buf.putFloat((float) fx);
buf.put(fractions);
buf.put(pixels);
}
use of java.awt.RadialGradientPaint in project gephi-plugins-bootcamp by gephi.
the class GlowRenderer method renderJava2D.
public void renderJava2D(Item item, G2DTarget target, PreviewProperties properties) {
//Params
Float x = item.getData(NodeItem.X);
Float y = item.getData(NodeItem.Y);
Float size = item.getData(NodeItem.SIZE);
Color color = item.getData(NodeItem.COLOR);
Color startColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 32);
Color endColor = new Color(startColor.getRed(), startColor.getGreen(), startColor.getBlue(), 0);
float radius = size * 6;
//Get Java2D canvas
Graphics2D g2 = target.getGraphics();
RadialGradientPaint p = new RadialGradientPaint(new Point2D.Double(x, y), radius, new float[] { 0.0f, 1.0f }, new Color[] { startColor, endColor });
g2.setPaint(p);
g2.fillOval((int) (x - radius), (int) (y - radius), (int) (radius * 2), (int) (radius * 2));
}
use of java.awt.RadialGradientPaint in project jdk8u_jdk by JetBrains.
the class ReadingInterruptionTest method createTestFile.
private static void createTestFile() {
int w = 1280;
int h = 1024;
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
Color[] colors = { Color.red, Color.green, Color.blue };
float[] dist = { 0.0f, 0.5f, 1.0f };
Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
g.setPaint(p);
g.fillRect(0, 0, w, h);
g.dispose();
try {
System.out.println("Create test image " + file.getAbsolutePath());
boolean b = ImageIO.write(img, "JPEG", file);
if (!b) {
throw new RuntimeException("Failed to create test image.");
}
} catch (IOException e) {
throw new RuntimeException("Test failed", e);
}
}
Aggregations