use of java.awt.geom.Arc2D in project vcell by virtualcell.
the class ReactionToolShapeIcon method main.
public static void main(String[] args) {
try {
Frame frame = new Frame();
Icon iconNormal = new ReactionToolShapeIcon(State.normal, Mode.plain);
int diameter = 20;
int x = 50;
int y = 80;
JPanel panel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
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);
g2.setStroke(new BasicStroke(5f));
g2.setColor(Color.black);
Color c1, c2;
// -16
int xx = x - 16;
// -15
int yy = y - 15;
// 8
int w = diameter * 8;
int h = diameter * 8;
c1 = Color.black;
c2 = Color.lightGray;
Arc2D arc = new // Line2D
Arc2D.Double(// Line2D
xx, // Line2D
yy, // Line2D
w, // Line2D
h, 0, 300, Arc2D.OPEN);
GradientPaint gp = new GradientPaint(50, 50 + 200, c1, 50 + 5, 50 + 200 - 5, c2, true);
g2.setPaint(gp);
g2.draw(arc);
// -------------------------------------------------------------
g2.setPaint(paintOld);
int a = 0;
float[] dash = { 10.0f };
Stroke dashed = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash, 0);
g2.setStroke(dashed);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 10;
float[] dash1 = { 5.0f };
Stroke dashed1 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash1, 0);
g2.setStroke(dashed1);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 20;
float[] dash2 = { 12.0f, 10.0f, 8.0f };
Stroke dashed2 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash2, 0);
g2.setStroke(dashed2);
g2.drawLine(10, 10 + a, 150, 10 + a);
a = 30;
float[] dash3 = { 12.0f, 10.0f, 8.0f };
Stroke dashed3 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash3, 50);
g2.setStroke(dashed3);
g2.drawLine(10, 10 + a, 150, 10 + a);
// ----------------------------------------------------------------------------------
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
};
panel.setSize(500, 400);
frame.add("Center", panel);
frame.setSize(panel.getSize());
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.awt.Panel");
exception.printStackTrace(System.out);
}
}
use of java.awt.geom.Arc2D in project vcell by virtualcell.
the class ReactionToolShapeIcon method paintIcon.
@Override
public void paintIcon(Component comp, Graphics g, int x, int y) {
if (comp == null) {
return;
}
if (!(comp instanceof JToolBarToggleButton)) {
return;
}
JToolBarToggleButton button = (JToolBarToggleButton) comp;
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);
g2.setStroke(new BasicStroke(2f));
Color c1, c2, c3, c4;
// for the arrowhead
float x1, x2, y1, y2;
int xx = x - 16;
int yy = y - 15;
// we'll paint a small arc from the upper left part of a very large circle
int w = diameter * 8;
int h = diameter * 8;
// the start and end coordinates of the membrane (for the flux button)
float m1 = 9f;
float m2 = 14f;
if (state == State.normal) {
// paint yellow arc
c1 = Color.yellow.darker();
c2 = Color.yellow;
c3 = Color.black;
c4 = Color.yellow.darker();
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
} else {
c1 = Color.yellow.darker();
c2 = Color.yellow.brighter();
c3 = Color.black;
c4 = Color.yellow.darker().darker();
xx += 1;
yy += 1;
x1 = 1;
x2 = 1;
y1 = 1;
y2 = 1;
m1 += 1.0f;
m2 += 1.0f;
}
Arc2D arc;
if (mode == Mode.catalyst) {
arc = new Arc2D.Double(xx, yy, w, h, 125, 18, Arc2D.OPEN);
} else {
arc = new Arc2D.Double(xx, yy, w, h, // starting angle
126, // angular extent
18, Arc2D.OPEN);
}
int a = 0;
int b = -10;
int c = 12;
// the wide yellow halo
g2.setStroke(new BasicStroke(4.0f));
GradientPaint gp = new GradientPaint(a, b, c1, a + c, b - c, c2, true);
g2.setPaint(gp);
g2.draw(arc);
if (mode == Mode.flux) {
// the "membrane" line, only for flux reactions
g2.setStroke(new BasicStroke(5.0f));
g2.setPaint(Color.orange.darker());
Line2D line = new Line2D.Float(m1, m1, m2, m2);
g2.draw(line);
}
if (mode == Mode.catalyst) {
// dashed black line for catalyst
float[] dash = { 6.2f, 3.6f };
Stroke dashed = new BasicStroke(1.6f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, dash, 0);
g2.setStroke(dashed);
g2.setPaint(Color.black);
// gp = new GradientPaint(a, b, c3, a+c, b-c, c4, true);
// g2.setPaint(gp);
g2.draw(arc);
} else {
// the continuous black line for plain and flux reactions
g2.setStroke(new BasicStroke(2f));
gp = new GradientPaint(a, b, c3, a + c, b - c, c4, true);
g2.setPaint(gp);
g2.draw(arc);
}
// TODO: draw arrow (maybe)
// g2.setStroke(new BasicStroke(1.4f, // Line width
// BasicStroke.CAP_ROUND, // End-cap style
// BasicStroke.JOIN_ROUND)); // Vertex join style
// Line2D l1 = new Line2D.Float(x1, y1, x2, y2);
// Line2D l2 = new Line2D.Float(x1, y1, x2, y2);
// g2.draw(l1);
// g2.draw(l2);
g2.setStroke(strokeOld);
g2.setColor(colorOld);
g2.setPaint(paintOld);
}
use of java.awt.geom.Arc2D 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);
}
use of java.awt.geom.Arc2D in project knime-core by knime.
the class PieSectionDataModel method setSubSection.
/**
* Calculates the size of all subsections of this section based on the
* size of the given arc.
* @param arc the arc of this section
* @param calculator the hilite calculator which provides implementation
* specific information
*/
private void setSubSection(final Arc2D arc, final PieHiliteCalculator calculator) {
final Collection<PieSubSectionDataModel> subSections = getElements();
if (subSections == null || subSections.size() < 1) {
return;
}
if (arc == null) {
// reset all subsections
for (final PieSubSectionDataModel subSection : subSections) {
subSection.setSubSection(null, calculator);
}
return;
}
final AggregationMethod method = calculator.getAggrMethod();
double startAngle = arc.getAngleStart();
final double totalValue;
if ((AggregationMethod.AVERAGE.equals(method) || AggregationMethod.SUM.equals(method))) {
double value = 0;
for (final PieSubSectionDataModel element : subSections) {
value += Math.abs(element.getAggregationValue(method));
}
totalValue = value;
} else {
totalValue = getAggregationValue(method);
}
for (final PieSubSectionDataModel subSection : subSections) {
final double value = Math.abs(subSection.getAggregationValue(method));
double fraction;
if (totalValue == 0) {
fraction = 0;
} else {
fraction = value / totalValue;
}
final double partialExtend = GeometryUtil.calculatePartialExtent(arc, fraction);
final Arc2D subArc = new Arc2D.Double(arc.getBounds(), startAngle, partialExtend, Arc2D.PIE);
subSection.setSubSection(subArc, calculator);
startAngle += partialExtend;
}
}
use of java.awt.geom.Arc2D in project knime-core by knime.
the class GeometryUtil method getArcBounds.
/**
* Returns a rectangle that can be used to create a pie section (taking
* into account the amount by which the pie section is 'exploded').
*
* @param unexploded the area inside which the unexploded pie sections are
* drawn.
* @param exploded the area inside which the exploded pie sections are
* drawn.
* @param angle the start angle.
* @param extent the extent of the arc.
* @param explodePercent the percent the new arc should reach into the
* explode area. 1.0 means the section should be shifted to the border of
* the explode area.
*
* @return A rectangle that can be used to create a pie section.
*/
public static Rectangle2D getArcBounds(final Rectangle2D unexploded, final Rectangle2D exploded, final double angle, final double extent, final double explodePercent) {
if (explodePercent == 0.0) {
return unexploded;
}
final Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, Arc2D.OPEN);
final Point2D point1 = arc1.getEndPoint();
final Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, Arc2D.OPEN);
final Point2D point2 = arc2.getEndPoint();
final double deltaX = (point1.getX() - point2.getX()) * explodePercent;
final double deltaY = (point1.getY() - point2.getY()) * explodePercent;
return new Rectangle2D.Double(unexploded.getX() - deltaX, unexploded.getY() - deltaY, unexploded.getWidth(), unexploded.getHeight());
}
Aggregations