Search in sources :

Example 36 with Polygon

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);
    }
}
Also used : JPanel(javax.swing.JPanel) Shape(java.awt.Shape) Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint) JComponent(javax.swing.JComponent) Component(java.awt.Component) Polygon(java.awt.Polygon) Graphics2D(java.awt.Graphics2D)

Example 37 with Polygon

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);
    }
}
Also used : Point(java.awt.Point) Polygon(java.awt.Polygon) Font(java.awt.Font) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 38 with Polygon

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];
}
Also used : PolygonRoi(ij.gui.PolygonRoi) BasePoint(gdsc.core.match.BasePoint) Rectangle(java.awt.Rectangle) Polygon(java.awt.Polygon) Roi(ij.gui.Roi) PolygonRoi(ij.gui.PolygonRoi) Point(java.awt.Point) BasePoint(gdsc.core.match.BasePoint)

Example 39 with Polygon

use of java.awt.Polygon in project processdash by dtuma.

the class RangeXYItemRenderer method drawItemRangeGradient.

private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2, double x3, double y3) {
    Line2D edge1, edge2, mainLine;
    Polygon fillArea;
    Stroke mainLineStroke, edgeLineStroke;
    Paint mainLinePaint, edgeLinePaint, fillPaint;
    double x0 = line.getX1();
    double y0 = line.getY1();
    double x1 = line.getX2();
    double y1 = line.getY2();
    mainLine = new Line2D.Double(x0, y0, x1, y1);
    edge1 = new Line2D.Double(x0, y0, x2, y2);
    edge2 = new Line2D.Double(x0, y0, x3, y3);
    fillArea = new Polygon();
    fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0));
    fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2));
    fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3));
    mainLinePaint = paint;
    if (mainLinePaint instanceof Color) {
        Color c = (Color) mainLinePaint;
        Color dark = transp(c, calcAlpha(c));
        Color light = transp(c, 0.01);
        edgeLinePaint = fillPaint = c;
        try {
            fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light, new Point2D.Double(x1, y1), dark, true);
        } catch (Exception e) {
        }
    } else {
        edgeLinePaint = fillPaint = mainLinePaint;
    }
    if (stroke instanceof BasicStroke) {
        float lineWidth = ((BasicStroke) stroke).getLineWidth();
        edgeLineStroke = new BasicStroke(lineWidth / 4);
        mainLineStroke = new BasicStroke(lineWidth * 2);
    } else {
        mainLineStroke = edgeLineStroke = stroke;
    }
    g2.setPaint(fillPaint);
    g2.fill(fillArea);
    g2.fill(fillArea);
    g2.setStroke(edgeLineStroke);
    g2.setPaint(edgeLinePaint);
    g2.draw(edge1);
    g2.draw(edge2);
    g2.setStroke(mainLineStroke);
    g2.setPaint(mainLinePaint);
    g2.draw(mainLine);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Polygon(java.awt.Polygon) Line2D(java.awt.geom.Line2D)

Aggregations

Polygon (java.awt.Polygon)39 Point (java.awt.Point)15 Graphics2D (java.awt.Graphics2D)11 Color (java.awt.Color)6 Rectangle (java.awt.Rectangle)6 GridPoint (doc.GridPoint)5 BasicStroke (java.awt.BasicStroke)5 Font (java.awt.Font)5 Paint (java.awt.Paint)5 FontMetrics (java.awt.FontMetrics)4 AffineTransform (java.awt.geom.AffineTransform)4 GradientPaint (java.awt.GradientPaint)2 Shape (java.awt.Shape)2 ShapeSpanIterator (sun.java2d.pipe.ShapeSpanIterator)2 BasePoint (gdsc.core.match.BasePoint)1 PolygonRoi (ij.gui.PolygonRoi)1 Roi (ij.gui.Roi)1 AlphaComposite (java.awt.AlphaComposite)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1