use of java.awt.Polygon in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method drawArrowHead.
public void drawArrowHead(Line2D.Double line, double scaleFactor) {
int doubleArrowWidth = (int) (2 * ARROW_WIDTH / scaleFactor);
if (doubleArrowWidth == 0) {
doubleArrowWidth = 2;
}
Polygon arrowHead = new Polygon();
arrowHead.addPoint(0, 0);
int arrowHeadPoint = (int) (-ARROW_WIDTH / scaleFactor);
if (arrowHeadPoint == 0) {
arrowHeadPoint = -1;
}
arrowHead.addPoint(arrowHeadPoint, -doubleArrowWidth);
arrowHeadPoint = (int) (ARROW_WIDTH / scaleFactor);
if (arrowHeadPoint == 0) {
arrowHeadPoint = 1;
}
arrowHead.addPoint(arrowHeadPoint, -doubleArrowWidth);
AffineTransform transformation = new AffineTransform();
transformation.setToIdentity();
double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
transformation.translate(line.x2, line.y2);
transformation.rotate((angle - Math.PI / 2d));
AffineTransform originalTransformation = g.getTransform();
g.setTransform(transformation);
g.fill(arrowHead);
g.setTransform(originalTransformation);
}
use of java.awt.Polygon in project DistributedFractalNetwork by Budder21.
the class ArrowButton method isClicked.
/**
* Used to determine whether or not the button was clicked
* @param p a point on the screen that was clicked
* @return whether or not the arrow contains the point
*/
public boolean isClicked(Point p) {
if (down) {
int[] xPoints = { location.x, location.x - 6, location.x + 6 };
int[] yPoints = { location.y, location.y - 9, location.y - 9 };
Polygon poly = new Polygon(xPoints, yPoints, 3);
Rectangle r = new Rectangle(location.x - 6, location.y - 12 - 9, 13, 12);
return poly.contains(p) || r.contains(p);
}
int[] xPoints = { location.x, location.x - 6, location.x + 6 };
int[] yPoints = { location.y, location.y + 9, location.y + 9 };
Polygon poly = new Polygon(xPoints, yPoints, 3);
Rectangle r = new Rectangle(location.x - 6, location.y + 9, 13, 12);
return poly.contains(p) || r.contains(p);
}
use of java.awt.Polygon in project GDSC-SMLM by aherbert.
the class PSFCreator method getSpots.
/**
* @return Extract all the ROI points that are not within twice the box radius of any other spot
*/
private BasePoint[] getSpots() {
Roi roi = imp.getRoi();
if (roi != null && roi.getType() == Roi.POINT) {
Polygon p = ((PolygonRoi) roi).getNonSplineCoordinates();
int n = p.npoints;
Rectangle bounds = roi.getBounds();
BasePoint[] roiPoints = new BasePoint[n];
for (int i = 0; i < n; i++) {
roiPoints[i] = new BasePoint(bounds.x + p.xpoints[i], bounds.y + p.ypoints[i], 0);
}
// All vs all distance matrix
double[][] d = new double[n][n];
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) d[i][j] = d[j][i] = roiPoints[i].distanceXY2(roiPoints[j]);
// Spots must be twice as far apart to have no overlap of the extracted box region
double d2 = boxRadius * boxRadius * 4;
int ok = 0;
for (int i = 0; i < n; i++) {
if (noNeighbours(d, n, i, d2))
roiPoints[ok++] = roiPoints[i];
}
return Arrays.copyOf(roiPoints, ok);
}
return new BasePoint[0];
}
use of java.awt.Polygon in project adempiere by adempiere.
the class CompiereTabbedPaneUI method paintTabBackground.
// paint
/**************************************************************************
* Paint the actual Tab Background.
* Called from Basic.PaintTab (<- Basic.paintTabArea <- Basic.paint)
* <p>
* Based on MetalTabbedPaneUI.paintTabBackground:
* Differences:
* - Color based on primary Background of Tab
* - Selected Tab is painted
* <pre>
* selected not sel
* top ////////// ////////// (lighter)
* ++++++++++ (flat/darker)
*
* bottom ////////// (flat/lighter)
* ++++++++++ ++++++++++ (darker)
*
* sides ////////// (flat/ligher)
* ++++++++++ (flat/darker)
* </pre>
* @param g graphics
* @param tabPlacement tab placement
* @param tabIndex tab index
* @param x x
* @param y y
* @param w width
* @param h height
* @param isSelected selected
*/
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
Graphics2D g2D = (Graphics2D) g;
// Get Background color of Tab
Component comp = tabPane.getComponentAt(tabIndex);
// System.out.println("Tab " + tabIndex + " Comp=" + comp.getName() + " " + comp.getClass().getName() + " x=" + x + ", y=" + y + ", w=" +w + ", h=" + h);
g2D.setPaint(comp.getBackground());
CompiereColor bg = CompiereColor.getDefaultBackground();
if (comp instanceof JPanel) {
JPanel jp = (JPanel) comp;
try {
bg = (CompiereColor) jp.getClientProperty(CompiereLookAndFeel.BACKGROUND);
} catch (Exception e) {
System.err.println("AdempiereTabbedPaneUI - ClientProperty: " + e.getMessage());
}
}
if (// No Background
bg == null) {
if (CompiereUtils.isLeftToRight(tabPane)) {
switch(tabPlacement) {
case LEFT:
g2D.fillRect(x + 5, y + 1, w - 5, h - 1);
g2D.fillRect(x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
g2D.fillRect(x + 2, y, w - 2, h - 4);
g2D.fillRect(x + 5, y + (h - 1) - 3, w - 5, 3);
break;
case RIGHT:
g2D.fillRect(x + 1, y + 1, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
g2D.fillRect(x + 4, y + 2, (w - 1) - 3, (h - 1) - 1);
g2D.fillRect(x + 2, y + 5, 2, h - 5);
}
} else {
switch(tabPlacement) {
case LEFT:
g2D.fillRect(x + 5, y + 1, w - 5, h - 1);
g2D.fillRect(x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
g2D.fillRect(x, y, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 4, y, 4, h - 5);
g2D.fillRect(x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
g2D.fillRect(x + 1, y + 1, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
g2D.fillRect(x, y + 2, (w - 1) - 3, (h - 1) - 1);
g2D.fillRect(x + (w - 1) - 3, y + 4, 3, h - 4);
}
}
} else // we have a background
{
if (CompiereUtils.isLeftToRight(tabPane)) {
switch(tabPlacement) {
case LEFT:
bg.paintRect(g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
bg.paintRect(g2D, tabPane, x + 2, y, w - 2, h - 4);
bg.paintRect(g2D, tabPane, x + 5, y + (h - 1) - 3, w - 5, 3);
break;
case RIGHT:
// bg.paintRect (g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
// changed
bg.paintRect(g2D, tabPane, x, y + 2, w - 4, h - 2);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
bg.paintRect(g2D, tabPane, x + 4, y + 2, (w - 1) - 3, (h - 1) - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 5, 2, h - 5);
}
} else {
switch(tabPlacement) {
case LEFT:
bg.paintRect(g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
bg.paintRect(g2D, tabPane, x, y, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 4, y, 4, h - 5);
bg.paintRect(g2D, tabPane, x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
bg.paintRect(g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
bg.paintRect(g2D, tabPane, x, y + 2, (w - 1) - 3, (h - 1) - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 4, 3, h - 4);
}
}
}
// Upper Part - not when selected and R/L/B
if (!(isSelected && (tabPlacement == RIGHT || tabPlacement == LEFT || tabPlacement == BOTTOM))) {
// upper half
Shape top = new Rectangle(x, y, w, h / 2);
if (tabPlacement == TOP || tabPlacement == LEFT)
top = new // top left triangle
Polygon(new int[] { x + 6, x + w, x + w, x, x }, new int[] { y, y, y + (h / 2), y + (h / 2), y + 6 }, 5);
else if (tabPlacement == RIGHT)
top = new // top right triangle
Polygon(new int[] { x, x + w - 6, x + w, x + w, x }, new int[] { y, y, y + 6, y + (h / 2), y + (h / 2) }, 5);
// lighter
GradientPaint paint = new GradientPaint(x, y, CompiereUtils.COL_1TOP, x, y + (h / 2), CompiereUtils.COL_1END);
g2D.setPaint(paint);
g2D.fill(top);
}
// Lower part - not when selected and T/R/L
if (!(isSelected && (tabPlacement == TOP || tabPlacement == RIGHT || tabPlacement == LEFT))) {
// lower half
Shape end = new Rectangle(x, y + (h / 2), w, h / 2);
if (tabPlacement == BOTTOM)
end = new // bottom left triangle
Polygon(new int[] { x, x + w, x + w, x + 6, x }, new int[] { y + (h / 2), y + (h / 2), y + h, y + h, y + h - 6 }, 5);
// darker
GradientPaint paint = new GradientPaint(x, y + (h / 2), CompiereUtils.COL_2TOP, x, y + h, CompiereUtils.COL_2END);
g2D.setPaint(paint);
g2D.fill(end);
}
}
use of java.awt.Polygon in project adempiere by adempiere.
the class WFLine method paint.
/**************************************************************************
* Paint it.
* Coordinates based on WFContentPanel.
* @param g Graph
*/
public void paint(Graphics g) {
if (m_from == null || m_to == null)
return;
Polygon arrow = new Polygon();
Point from = null;
Point to = null;
//
if (isRightTop()) {
from = addPoint(arrow, m_from, SwingConstants.RIGHT, true);
to = addPoint(arrow, m_to, SwingConstants.TOP, false);
} else if (isBottomTop()) {
from = addPoint(arrow, m_from, SwingConstants.BOTTOM, true);
to = addPoint(arrow, m_to, SwingConstants.TOP, false);
} else //
if (isTopBottom()) {
from = addPoint(arrow, m_from, SwingConstants.TOP, true);
to = addPoint(arrow, m_to, SwingConstants.BOTTOM, false);
} else if (isLeftRight()) {
from = addPoint(arrow, m_from, SwingConstants.LEFT, true);
to = addPoint(arrow, m_to, SwingConstants.RIGHT, false);
} else // if (isRightLeft())
{
from = addPoint(arrow, m_from, SwingConstants.RIGHT, true);
to = addPoint(arrow, m_to, SwingConstants.LEFT, false);
}
/**
* Paint Arrow:
* Unconditional: no fill - black text
* Conditional: red fill - red text
* Visited: green line
* NotVisited: black line
* Split/Join: AND: Magenta Dot -- XOR: -
*/
if (!m_next.isUnconditional()) {
g.setColor(Color.red);
// fill
g.fillPolygon(arrow);
}
if (m_visited)
g.setColor(Color.green);
else
g.setColor(Color.black);
// line
g.drawPolygon(arrow);
// Paint Dot for AND From
if (m_next.isFromSplitAnd()) {
g.setColor(Color.magenta);
g.fillOval(from.x - 3, from.y - 3, 6, 6);
}
// Paint Dot for AND To
if (m_next.isToJoinAnd()) {
g.setColor(Color.magenta);
g.fillOval(to.x - 3, to.y - 3, 6, 6);
}
// Paint Description in red
if (m_description != null) {
Graphics2D g2D = (Graphics2D) g;
Font font = new Font("Dialog", Font.PLAIN, 9);
if (m_next.isUnconditional())
g2D.setColor(Color.black);
else
g2D.setColor(Color.red);
TextLayout layout = new TextLayout(m_description, font, g2D.getFontRenderContext());
// Mid Point
int x = 0;
if (from.x < to.x)
x = from.x + ((to.x - from.x) / 2);
else
x = to.x + ((from.x - to.x) / 2);
int y = 0;
if (from.y < to.y)
y = from.y + ((to.y - from.y) / 2);
else
y = to.y + ((from.y - to.y) / 2);
// Adjust |
// above center
y -= (layout.getAscent() - 3);
// Adjust -
// center
x -= (layout.getAdvance() / 2);
if (x < 2)
x = 2;
layout.draw(g2D, x, y);
}
}
Aggregations