use of java.awt.RadialGradientPaint in project cytoscape-impl by cytoscape.
the class RadialGradientLayer method getPaint.
// ==[ PUBLIC METHODS ]=============================================================================================
@Override
public Paint getPaint(final Rectangle2D bounds) {
// Assuming radius and center are of a unit circle, scale appropriately
double w = bounds.getWidth();
double h = bounds.getHeight();
double cx = w * center.getX() + bounds.getX();
double cy = h * center.getY() + bounds.getY();
final Point2D newCenter = new Point2D.Double(cx, cy);
double delta = newCenter.distance(new Point2D.Double(bounds.getCenterX(), bounds.getCenterY()));
final double r = Math.sqrt(w * w + h * h) / 2;
final double newRadius = delta + r * radius;
paint = new RadialGradientPaint(newCenter, (float) newRadius, fractionArray, colorArray);
return paint;
}
use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class ResizeCanvasShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
if (!(c instanceof JButton)) {
return;
}
JButton b = (JButton) c;
// button center
int cx = b.getWidth() / 2;
int cy = b.getHeight() / 2;
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);
// the nock (base end, towards the fletching) of the arrow shaft
Color interior;
// the spine (tip end, connecting to the arrow head) of the shaft
Color exterior;
// the arrow head
Color tip;
Color[] colors;
float[] dist;
Color c1, c2, c3;
if (sign == Sign.expand) {
c1 = SpeciesPatternLargeShape.componentGreen.darker();
c2 = SpeciesPatternLargeShape.componentGreen.darker().darker();
c3 = Color.green.darker().darker();
} else {
c1 = SpeciesPatternLargeShape.componentBad.darker();
c2 = SpeciesPatternLargeShape.componentBad.darker().darker();
c3 = Color.red.darker().darker();
}
Point2D center = new Point2D.Float(cx, cy);
float radius = side / 2 + 1;
// white mapped in the center
Point2D focus = new Point2D.Float(cx, cy);
if (b.isEnabled()) {
if (state == State.normal) {
// Color.cyan;
interior = c1;
// Color.blue;
exterior = c2;
// Color.blue.darker();
tip = c3.darker();
} else {
// pressed! same colors, brighter when button is pressed
// Color.cyan.brighter();
interior = c1.brighter();
// Color.blue.brighter();
exterior = c2.brighter();
// Color.blue;
tip = c3.brighter();
}
} else {
// disabled - uniform gray, regardless of pressed
interior = Color.lightGray;
exterior = Color.gray;
tip = Color.gray;
}
if (sign == Sign.expand) {
colors = new Color[] { interior, exterior };
dist = new float[] { 0.2f, 1.0f };
} else {
// arrow points the other way, so the arrow colors are inverted
colors = new Color[] { exterior, interior };
dist = new float[] { 0.9f, 1.0f };
}
RadialGradientPaint paint = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(paint);
// starting offset (how far away from center starts the shaft of the arrow)
int o;
// length of the 2 "wings" of the arrow head)
int d;
int xx = side / 2;
int yy = side / 2;
float strokeWidth;
if (sign == Sign.expand) {
o = 2;
d = 4;
strokeWidth = 2.0f;
} else {
// shrink
o = 2;
d = 4;
// xx++;
// yy++;
strokeWidth = 1.6f;
}
g2.setStroke(new // Line width
BasicStroke(// Line width
strokeWidth, // End-cap style
BasicStroke.CAP_ROUND, // Vertex join style
BasicStroke.JOIN_ROUND));
// upper left
g2.drawLine(cx - o, cy - o, cx - xx, cy - yy);
// upper right
g2.drawLine(cx + o, cy - o, cx + xx, cy - yy);
// lower left
g2.drawLine(cx - o, cy + o, cx - xx, cy + yy);
// lower right
g2.drawLine(cx + o, cy + o, cx + xx, cy + yy);
g2.setPaint(paintOld);
g2.setColor(tip);
if (sign == Sign.expand) {
// upper left
g2.drawLine(cx - xx, cy - yy, cx - xx + d, cy - yy);
g2.drawLine(cx - xx, cy - yy, cx - xx, cy - yy + d);
// upper right
g2.drawLine(cx + xx, cy - yy, cx + xx - d, cy - yy);
g2.drawLine(cx + xx, cy - yy, cx + xx, cy - yy + d);
// lower left
g2.drawLine(cx - xx, cy + yy, cx - xx + d, cy + yy);
g2.drawLine(cx - xx, cy + yy, cx - xx, cy + yy - d);
// lower right
g2.drawLine(cx + xx, cy + yy, cx + xx - d, cy + yy);
g2.drawLine(cx + xx, cy + yy, cx + xx, cy + yy - d);
} else {
// upper left
g2.drawLine(cx - o, cy - o, cx - o - d, cy - o);
g2.drawLine(cx - o, cy - o, cx - o, cy - o - d);
// upper right
g2.drawLine(cx + o, cy - o, cx + o + d, cy - o);
g2.drawLine(cx + o, cy - o, cx + o, cy - o - d);
// lower left
g2.drawLine(cx - o, cy + o, cx - o - d, cy + o);
g2.drawLine(cx - o, cy + o, cx - o, cy + o + d);
// lower right
g2.drawLine(cx + o, cy + o, cx + o + d, cy + o);
g2.drawLine(cx + o, cy + o, cx + o, cy + o + d);
}
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class SpeciesToolShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
if (!(c instanceof JToolBarToggleButton)) {
return;
}
JToolBarToggleButton b = (JToolBarToggleButton) c;
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 = 2;
int yy = 2;
Color exterior, interior;
if (state == State.normal) {
exterior = Color.green.darker().darker();
interior = Color.white;
xx += x;
yy += y;
} else {
exterior = Color.green.darker();
interior = Color.white;
// button moves a little bit to simulate 3D pressing of a button
xx += x + 1;
yy += y + 1;
}
Ellipse2D e = new Ellipse2D.Double(xx, yy, circleDiameter, circleDiameter);
Point2D center = new Point2D.Float(xx + circleDiameter / 2, yy + circleDiameter / 2);
float radius = circleDiameter * 0.5f;
Point2D focus = new Point2D.Float(xx + circleDiameter / 2 - 2, yy + circleDiameter / 2 - 2);
float[] dist = { 0.1f, 1.0f };
Color[] colors = { interior, exterior };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
g2.fill(e);
g.setColor(Color.black);
g2.draw(e);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class ZoomShapeIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c == null) {
return;
}
if (!(c instanceof JButton)) {
return;
}
JButton b = (JButton) c;
int xPos = (b.getWidth() - diameter) / 2;
int yPos = (b.getHeight() - diameter) / 2 + 1;
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color interior = Color.white;
Color exterior;
Color signColor;
Color contour;
Color c1, c2;
if (sign == Sign.plus) {
c1 = SpeciesPatternLargeShape.componentGreen;
c2 = Color.green;
} else {
c1 = SpeciesPatternLargeShape.componentBad;
c2 = Color.red;
}
if (b.isEnabled()) {
if (state == State.normal) {
exterior = c1.darker();
signColor = c2.darker().darker().darker();
} else {
// same colors, brighter when button is pressed
exterior = c1;
signColor = c2.darker().darker();
}
contour = c1.darker().darker().darker();
} else {
// disabled
exterior = Color.lightGray;
signColor = Color.gray;
contour = Color.gray;
}
Point2D center = new Point2D.Float(xPos + diameter / 3, yPos + diameter / 3);
float radius = diameter * 0.5f;
Point2D focus = new Point2D.Float(xPos + diameter / 3 - 1, yPos + diameter / 3 - 1);
float[] dist = { 0.1f, 1.0f };
Color[] colors = { interior, exterior };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, diameter, diameter);
g2.fill(circle);
Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, diameter, diameter);
g2.setPaint(contour);
g2.draw(circle2);
// TODO: use diameter instead of hardcoded numbers for the horizontal and vertical lines
// offset left and right from center (for the vertical and orizontal lines)
int i = diameter / 4;
// center of circle
int cx = b.getWidth() / 2;
int cy = b.getHeight() / 2;
g2.setColor(signColor);
// horizontal bar of the '-' or '+' signs
g2.drawLine(cx - i - 1, cy - 1, cx + i - 1, cy - 1);
g2.drawLine(cx - i - 1, cy, cx + i - 1, cy);
g2.drawLine(cx - i - 1, cy + 1, cx + i - 1, cy + 1);
if (sign == Sign.plus) {
// draw the vertical bar of the '+' sign
// vertical
g2.drawLine(cx, cy - i, cx, cy + i);
g2.drawLine(cx - 1, cy - i, cx - 1, cy + i);
g2.drawLine(cx - 2, cy - i, cx - 2, cy + i);
}
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.RadialGradientPaint in project vcell by virtualcell.
the class MolecularTypeLargeShape method paintSpecies.
// --------------------------------------------------------------------------------------
private void paintSpecies(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Font fontOld = g2.getFont();
Color colorOld = g2.getColor();
Stroke strokeOld = g2.getStroke();
Color primaryColor = null;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (mt == null && mtp == null) {
// plain species context
Color exterior;
if (owner == null) {
// for plain species, we just draw a circle based on height!!! we ignore width!!!
// error
exterior = Color.red.darker();
} else {
if (!shapePanel.isShowMoleculeColor()) {
exterior = Color.GRAY;
} else {
// plain species
exterior = Color.green.darker().darker();
}
}
Point2D center = new Point2D.Float(xPos + baseHeight / 3, yPos + baseHeight / 3);
float radius = baseHeight * 0.5f;
Point2D focus = new Point2D.Float(xPos + baseHeight / 3 - 1, yPos + baseHeight / 3 - 1);
float[] dist = { 0.1f, 1.0f };
Color[] colors = { Color.white, exterior };
RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
g2.setPaint(p);
Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, baseHeight, baseHeight);
g2.fill(circle);
Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, baseHeight + 0.7, baseHeight + 0.7);
g2.setPaint(getDefaultColor(Color.DARK_GRAY));
int z = shapePanel.getZoomFactor();
g2.setStroke(new BasicStroke(2.0f + 0.14f * z));
g2.draw(circle2);
if (owner == null) {
Font font = fontOld.deriveFont(Font.BOLD);
g.setFont(font);
g.setColor(Color.red.darker().darker());
g2.drawString("Error parsing generated species!", xPos + baseHeight + 10, yPos + baseHeight - 9);
}
g2.setFont(fontOld);
g2.setColor(colorOld);
g2.setStroke(strokeOld);
return;
} else {
// molecular type, species pattern, observable
if (mt == null || mt.getModel() == null) {
primaryColor = Color.blue.darker().darker();
} else {
if (shapePanel.getDisplayMode() == DisplayMode.participantSignatures) {
if (!shapePanel.isShowMoleculeColor()) {
primaryColor = AbstractComponentShape.componentVeryLightGray;
} else {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = colorTable[index].darker().darker();
}
if (shapePanel.isShowDifferencesOnly()) {
ReactionRule reactionRule = (ReactionRule) owner;
switch(shapePanel.hasNoMatch(reactionRule.getName(), mtp)) {
case CHANGED:
primaryColor = AbstractComponentShape.deepOrange;
break;
case // keep whatever color we set above
UNCHANGED:
break;
case ANALYSISFAILED:
ArrayList<Issue> issueList = new ArrayList<Issue>();
reactionRule.gatherIssues(new IssueContext(), issueList);
boolean bRuleHasErrorIssues = false;
for (Issue issue : issueList) {
if (issue.getSeverity() == Severity.ERROR) {
bRuleHasErrorIssues = true;
break;
}
}
if (bRuleHasErrorIssues) {
primaryColor = AbstractComponentShape.componentHidden;
} else {
System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
primaryColor = Color.red.darker();
}
break;
default:
break;
}
}
} else if (shapePanel.getDisplayMode() == DisplayMode.rules) {
if (!shapePanel.isShowMoleculeColor()) {
primaryColor = AbstractComponentShape.componentVeryLightGray;
} else {
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
primaryColor = colorTable[index].darker().darker();
}
// if we show difference, we apply that now and override the color
if (shapePanel.isShowDifferencesOnly()) {
ReactionRule reactionRule = (ReactionRule) owner;
switch(shapePanel.hasNoMatch(mtp)) {
case CHANGED:
primaryColor = AbstractComponentShape.deepOrange;
break;
case // keep whatever color we set above
UNCHANGED:
break;
case ANALYSISFAILED:
ArrayList<Issue> issueList = new ArrayList<Issue>();
reactionRule.gatherIssues(new IssueContext(), issueList);
boolean bRuleHasErrorIssues = false;
for (Issue issue : issueList) {
if (issue.getSeverity() == Severity.ERROR) {
bRuleHasErrorIssues = true;
break;
}
}
if (bRuleHasErrorIssues) {
primaryColor = AbstractComponentShape.componentHidden;
} else {
System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
primaryColor = Color.red.darker();
}
break;
default:
break;
}
}
} else {
// TODO: do we ever get here legitimately? if not throw an exception!
RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
List<MolecularType> mtList = rbmmc.getMolecularTypeList();
int index = mtList.indexOf(mt);
index = index % 7;
if (!shapePanel.isShowMoleculeColor()) {
primaryColor = AbstractComponentShape.componentVeryLightGray;
} else {
primaryColor = isHighlighted() == true ? Color.white : colorTable[index].darker().darker();
}
if (hasErrorIssues(owner, mt)) {
primaryColor = isHighlighted() ? Color.white : Color.red;
}
}
}
}
// paint the structure contour if applicable (only for anchored molecules!)
if (structure != null && mt != null && !mt.isAnchorAll() && mt.getAnchors().size() > 0) {
paintNarrowCompartmentRight(g);
} else if (owner instanceof MolecularType && !mt.isAnchorAll()) {
paintNarrowCompartmentRight(g);
}
// paint the shape of the molecule and fill it with color
GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + baseHeight / 2, Color.WHITE, true);
g2.setPaint(p);
RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, baseHeight, cornerArc, cornerArc);
g2.fill(rect);
RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, baseHeight - 2, cornerArc - 3, cornerArc - 3);
if (isHighlighted()) {
if (hasErrorIssues(owner, mt)) {
g2.setPaint(Color.red);
} else {
g2.setPaint(getDefaultColor(Color.BLACK));
}
g2.draw(inner);
if (hasErrorIssues(owner, mt)) {
g2.setPaint(Color.red);
} else {
g2.setPaint(getDefaultColor(Color.BLACK));
}
g2.draw(rect);
} else {
if (hasErrorIssues(owner, mt)) {
g2.setPaint(Color.red.darker());
} else {
g2.setPaint(getDefaultColor(Color.GRAY));
}
g2.draw(inner);
if (hasErrorIssues(owner, mt)) {
g2.setPaint(Color.red.darker());
} else {
g2.setPaint(getDefaultColor(Color.DARK_GRAY));
}
g2.draw(rect);
}
// paint the anchor glyph
Rectangle r = getAnchorHotspot();
if (r != null) {
// g2.drawRect(r.x, r.y, r.width, r.height); // anchor tooltip hotspot area
int z = shapePanel.getZoomFactor();
int w = r.width;
int x = r.x + w / 2;
int y = r.y;
int h = 12 + z / 2;
h = z < -2 ? h - 1 : h;
h = z < -4 ? h - 1 : h;
Line2D line = new Line2D.Float(x, y, x, y + h);
g2.setPaint(getDefaultColor(Color.RED.darker().darker()));
g2.setStroke(new BasicStroke(2.6f + 0.13f * z));
g2.draw(line);
// TODO: adjust the arc at deep zoom!
double a1 = z < -3 ? 245 : 240;
// 60
double a2 = z < -3 ? 52 : 59;
Arc2D arc = new Arc2D.Double(x - h, y - h, 2 * h, 2 * h, a1, a2, Arc2D.OPEN);
g2.setStroke(new BasicStroke(2.6f + 0.20f * z));
g2.draw(arc);
g2.setPaint(colorOld);
g2.setStroke(strokeOld);
}
// the text inside the molecule shape
if (mt == null && mtp == null) {
// plain species context
// don't write any text inside
} else {
// molecular type, species pattern
Graphics gc = shapePanel.getGraphics();
Font font = deriveMoleculeFontBold(g, shapePanel);
g.setFont(font);
// font color
g.setColor(getDefaultColor(Color.BLACK));
int fontSize = font.getSize();
int textX = xPos + 11;
int textY = yPos + baseHeight - (baseHeight - fontSize) / 2;
g2.drawString(name, textX, textY);
if (owner instanceof ReactionRule && mtp != null && mtp.hasExplicitParticipantMatch()) {
int z = shapePanel.getZoomFactor();
if (z >= LargeShapeCanvas.SmallestZoomFactorWithText) {
// hide the matching too when we don't display the name
FontMetrics fm = gc.getFontMetrics(font);
int stringWidth = fm.stringWidth(name);
Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
g.setFont(smallerFont);
g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
}
}
}
g.setFont(fontOld);
g.setColor(colorOld);
g2.setStroke(strokeOld);
for (MolecularComponentLargeShape mcls : componentShapes) {
// paint the components
mcls.paintSelf(g);
}
g2.setFont(fontOld);
g2.setColor(colorOld);
g2.setStroke(strokeOld);
}
Aggregations