Search in sources :

Example 16 with Polygon

use of java.awt.Polygon in project darkFunction-Editor by darkFunction.

the class GraphicPanel method mouseReleased.

public void mouseReleased(MouseEvent evt) {
    setCursor(Cursor.DEFAULT_CURSOR);
    _mouseButtonPressed = MouseEvent.NOBUTTON;
    if (!_bAllowsEditing)
        return;
    switch(evt.getButton()) {
        case SELECT_BUTTON:
            {
                if (!_bAllowsEditing)
                    break;
                if (_resizingGraphic != null && _resizeDirection != Compass.NONE)
                    break;
                if ((evt.getModifiers() & ActionEvent.CTRL_MASK) == 0) {
                    if (_movingGraphic == null || !_movingGraphic.hasMoved()) {
                        for (int i = 0; i < _drawStack.size(); ++i) {
                            GraphicObject graphic = _drawStack.get(i);
                            if (graphic != _movingGraphic)
                                this.selectGraphic(graphic, false);
                        }
                    } else {
                        GraphicObject topGraphic = topGraphicAtPosition(evt.getPoint());
                        if (topGraphic != null && topGraphic.isSelected() && !topGraphic.hasMoved())
                            unselectGraphic(topGraphic);
                    }
                }
                if (_multiSelectRect != null && _multiSelectRect.width > 0 && _multiSelectRect.height > 0) {
                    // select all graphics in rect
                    Rectangle convertedRect = this.convertViewRectToRect(_multiSelectRect);
                    for (int i = 0; i < _drawStack.size(); ++i) {
                        GraphicObject go = _drawStack.get(i);
                        Rectangle r = go.getRect();
                        float angle = go.getAngle();
                        Point[] p = new Point[4];
                        p[0] = MathUtil.rotatePoint2D(new Point(-r.width / 2, -r.height / 2), angle);
                        p[1] = MathUtil.rotatePoint2D(new Point(-r.width / 2, r.height / 2), angle);
                        p[2] = MathUtil.rotatePoint2D(new Point(r.width / 2, r.height / 2), angle);
                        p[3] = MathUtil.rotatePoint2D(new Point(r.width / 2, -r.height / 2), angle);
                        for (int j = 0; j < p.length; j++) {
                            p[j].x += r.x + r.width / 2;
                            p[j].y += r.y + r.height / 2;
                        }
                        int[] x = new int[p.length];
                        int[] y = new int[p.length];
                        for (int j = 0; j < p.length; ++j) {
                            x[j] = p[j].x;
                            y[j] = p[j].y;
                        }
                        Polygon poly = new Polygon(x, y, 4);
                        if (poly.intersects(convertedRect)) {
                            selectGraphic(go);
                        }
                    }
                }
            }
            break;
    }
    dropAllGraphicsUndoable();
    _multiSelectRect = null;
    repaint();
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) Polygon(java.awt.Polygon)

Example 17 with Polygon

use of java.awt.Polygon in project hackpad by dropbox.

the class RunProxy method paint.

/**
     * Paints the component.
     */
@Override
public void paint(Graphics g) {
    super.paint(g);
    FileTextArea textArea = fileWindow.textArea;
    Font font = textArea.getFont();
    g.setFont(font);
    FontMetrics metrics = getFontMetrics(font);
    Rectangle clip = g.getClipBounds();
    g.setColor(getBackground());
    g.fillRect(clip.x, clip.y, clip.width, clip.height);
    int ascent = metrics.getMaxAscent();
    int h = metrics.getHeight();
    int lineCount = textArea.getLineCount() + 1;
    String dummy = Integer.toString(lineCount);
    if (dummy.length() < 2) {
        dummy = "99";
    }
    int startLine = clip.y / h;
    int endLine = (clip.y + clip.height) / h + 1;
    int width = getWidth();
    if (endLine > lineCount)
        endLine = lineCount;
    for (int i = startLine; i < endLine; i++) {
        String text;
        int pos = -2;
        try {
            pos = textArea.getLineStartOffset(i);
        } catch (BadLocationException ignored) {
        }
        boolean isBreakPoint = fileWindow.isBreakPoint(i + 1);
        text = Integer.toString(i + 1) + " ";
        int y = i * h;
        g.setColor(Color.blue);
        g.drawString(text, 0, y + ascent);
        int x = width - ascent;
        if (isBreakPoint) {
            g.setColor(new Color(0x80, 0x00, 0x00));
            int dy = y + ascent - 9;
            g.fillOval(x, dy, 9, 9);
            g.drawOval(x, dy, 8, 8);
            g.drawOval(x, dy, 9, 9);
        }
        if (pos == fileWindow.currentPos) {
            Polygon arrow = new Polygon();
            int dx = x;
            y += ascent - 10;
            int dy = y;
            arrow.addPoint(dx, dy + 3);
            arrow.addPoint(dx + 5, dy + 3);
            for (x = dx + 5; x <= dx + 10; x++, y++) {
                arrow.addPoint(x, y);
            }
            for (x = dx + 9; x >= dx + 5; x--, y++) {
                arrow.addPoint(x, y);
            }
            arrow.addPoint(dx + 5, dy + 7);
            arrow.addPoint(dx, dy + 7);
            g.setColor(Color.yellow);
            g.fillPolygon(arrow);
            g.setColor(Color.black);
            g.drawPolygon(arrow);
        }
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Polygon(java.awt.Polygon) Font(java.awt.Font) Point(java.awt.Point)

Example 18 with Polygon

use of java.awt.Polygon in project hudson-2.x by hudson.

the class StackedAreaRenderer2 method drawItem.

// Mostly copied from the base class.
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    // plot non-null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    double previousHeightx1 = getPreviousHeight(dataset, row, column);
    double y1 = value + previousHeightx1;
    RectangleEdge location = plot.getRangeAxisEdge();
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    // and this is done in the second pass...
    if (column == 0) {
        if (pass == 1) {
            // draw item labels, if visible
            if (isItemLabelVisible(row, column)) {
                drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
            }
        }
    } else {
        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {
            double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
            double y0 = previousValue.doubleValue();
            // Get the previous height, but this will be different for both
            // y0 and y1 as the previous series values could differ.
            double previousHeightx0 = getPreviousHeight(dataset, row, column - 1);
            // Now stack the current y values on top of the previous values.
            y0 += previousHeightx0;
            // Now translate the previous heights
            double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location);
            double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location);
            // Now translate the current y values.
            double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
            if (pass == 0) {
                // left half
                Polygon p = new Polygon();
                p.addPoint((int) xx0, (int) yy0);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx0, (int) previousHeightxx0);
                g2.setPaint(getItemPaint(row, column - 1));
                g2.setStroke(getItemStroke(row, column - 1));
                g2.fill(p);
                if (entities != null)
                    addItemEntity(entities, dataset, row, column - 1, p);
                // right half
                p = new Polygon();
                p.addPoint((int) xx1, (int) yy1);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx1, (int) previousHeightxx1);
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.fill(p);
                if (entities != null)
                    addItemEntity(entities, dataset, row, column, p);
            } else {
                if (isItemLabelVisible(row, column)) {
                    drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
                }
            }
        }
    }
}
Also used : EntityCollection(org.jfree.chart.entity.EntityCollection) Polygon(java.awt.Polygon) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 19 with Polygon

use of java.awt.Polygon in project OpenNotebook by jaltekruse.

the class PolygonObjectGUI method getCollisionAndSelectionPolygon.

public Polygon getCollisionAndSelectionPolygon(PolygonObject pObject, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPosition(pObject, pageOrigin, zoomLevel);
    GridPoint[] pts = pObject.getAdjustedVertices();
    int[] xVals = new int[pts.length];
    int[] yVals = new int[pts.length];
    int i = 0;
    for (GridPoint pt : pts) {
        xVals[i] = (int) (pt.getx() * sap.getWidth()) + sap.getxOrigin();
        yVals[i] = (int) (pt.gety() * sap.getHeight()) + sap.getyOrigin();
        i++;
    }
    return new Polygon(xVals, yVals, pts.length);
}
Also used : GridPoint(doc.GridPoint) Polygon(java.awt.Polygon) GridPoint(doc.GridPoint) Point(java.awt.Point)

Example 20 with Polygon

use of java.awt.Polygon in project OpenNotebook by jaltekruse.

the class ConeObjectGUI method drawMathObject.

public void drawMathObject(ConeObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    g.setColor(Color.BLACK);
    ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
    Graphics2D g2d = (Graphics2D) g;
    Color fillColor = object.getColor();
    Polygon fillShape;
    GridPoint[] translated = new GridPoint[3];
    int i = 0;
    for (GridPoint p : object.getTrianglePts()) {
        if (object.isFlippedVertically()) {
            translated[i] = object.flipPointVertically(p);
        } else {
            translated[i] = p.clone();
        }
        i++;
    }
    if (fillColor != null) {
        fillShape = new Polygon();
        fillShape.addPoint((int) (translated[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[0].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin());
        fillShape.addPoint((int) (translated[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[2].gety() * sap.getHeight()) + sap.getyOrigin());
        g2d.setColor(fillColor);
        g2d.fillPolygon(fillShape);
        g2d.setColor(MathObjectGUI.brightenColor(fillColor));
        if (object.isFlippedVertically()) {
            g2d.fillOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getInsideEdgeOfDisk().gety() * sap.getHeight()));
        } else {
            g2d.fillOval(sap.getxOrigin(), (int) (object.getPointBehindCone().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
        }
    }
    g2d.setStroke(new BasicStroke(sap.getLineThickness(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2d.setColor(Color.BLACK);
    g.drawLine((int) (translated[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[0].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin());
    g.drawLine((int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (translated[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[2].gety() * sap.getHeight()) + sap.getyOrigin());
    if (object.isFlippedVertically()) {
        g.drawOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
    } else {
        g.drawOval(sap.getxOrigin(), (int) (object.getPointBehindCone().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
    }
    g2d.setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) GridPoint(doc.GridPoint) Color(java.awt.Color) Polygon(java.awt.Polygon) GridPoint(doc.GridPoint) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

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