Search in sources :

Example 36 with GeneralPath

use of java.awt.geom.GeneralPath in project beast-mcmc by beast-dev.

the class VisualizeKMLNumericalProbs method paintComponent.

public void paintComponent(Graphics g) {
    System.out.println("entering paintComponent()");
    computeScales();
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(1.5f));
    int sx = probs.x(start.getX());
    int sy = probs.y(start.getY());
    int t = 49;
    double maxCount1 = probs.maxCount[sx][sy][t];
    System.out.println("start max count = " + maxCount1);
    AffineTransform transform = getFullTransform();
    System.out.println("Painting lattice probs");
    for (int i = 0; i < probs.latticeWidth; i++) {
        for (int j = 0; j < probs.latticeHeight; j++) {
            float I1 = (float) probs.r(sx, sy, i, j, t);
            Rectangle2D rect = new Rectangle2D.Double(i * probs.dx + probs.minx, j * probs.dy + probs.miny, probs.dx, probs.dy);
            g.setColor(cf.getColor(I1));
            g2d.fill(transform.createTransformedShape(rect));
            g.setColor(Color.black);
            g2d.draw(transform.createTransformedShape(rect));
        }
    }
    System.out.println("Painting shapes");
    for (Shape s : shapes) {
        System.out.print(".");
        System.out.flush();
        GeneralPath path = new GeneralPath(s);
        path.transform(transform);
        g2d.setPaint(Color.BLACK);
        g2d.fill(path);
    }
    g2d.setColor(Color.yellow);
    SpaceTime.paintDot(new SpaceTime(0, start), 4, transform, g2d);
    g2d.setColor(Color.green);
    SpaceTime.paintDot(new SpaceTime(0, end), 4, transform, g2d);
    int ex = probs.x(end.getX());
    int ey = probs.y(end.getY());
    String message = "p=" + probs.p(sx, sy, ex, ey, t) + " r=" + probs.r(sx, sy, ex, ey, t) + " c=" + probs.counts[sx][sy][ex][ey][t];
    g2d.setColor(Color.yellow);
    g2d.drawString(message, 20, getHeight() - 20);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform)

Example 37 with GeneralPath

use of java.awt.geom.GeneralPath in project knime-core by knime.

the class ParallelCoordinateDrawingPane method drawCurve.

/**
 * Draws a quad curve between the mapped data points of one
 * {@link org.knime.base.node.viz.plotter.parcoord.LineInfo}.
 *
 * @param g graphics object
 * @param line one line / row
 */
private void drawCurve(final Graphics2D g, final LineInfo line) {
    // for each line
    GeneralPath path = null;
    Point ctrl = null;
    // Point newCtrl = null;
    if (m_fade && !line.isHilite()) {
        if (line.isSelected()) {
            g.setColor(ColorAttr.INACTIVE_SELECTED);
        } else {
            g.setColor(ColorAttr.INACTIVE);
        }
    } else if (!m_hide && !m_fade) {
        g.setColor(line.getColor().getColor(line.isSelected(), line.isHilite()));
    } else {
        // bugfix : 1278
        g.setColor(line.getColor().getColor(line.isSelected(), false));
    }
    int lineSize = getStrokeSize(line.getSize());
    Stroke selectionStroke = new BasicStroke(lineSize, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { DASH }, 0);
    ((Graphics2D) g).setStroke(new BasicStroke(lineSize));
    // for all points
    for (int i = 0; i < line.getPoints().size() - 1; i++) {
        Point p1 = line.getPoints().get(i);
        Point p2 = line.getPoints().get(i + 1);
        if (path == null) {
            path = new GeneralPath();
            path.moveTo(p1.x, p1.y);
            // first control Point with offset
            int x = p1.x + ((p2.x - p1.x) / 2);
            int y = p1.y + ((p2.y - p1.y) / 2) + 10;
            ctrl = new Point(x, y);
        }
        // create cubic curve
        int firstX = p1.x + ((p2.x - p1.x) / 3);
        int secondX = p1.x + ((p2.x - p1.x) / 2);
        Point firstCtrl = getNextControlPoint(ctrl, p1, firstX);
        Point secondCtrl = createAdditionalCtrlPoint(secondX, p2, firstCtrl);
        path.curveTo(firstCtrl.x, firstCtrl.y, secondCtrl.x, secondCtrl.y, p2.x, p2.y);
        ctrl = secondCtrl;
    }
    Color backupColor = g.getColor();
    if (line.isHilite() && !m_hide && !m_fade) {
        // draw additional "hilite" line
        g.setColor(ColorAttr.HILITE);
        Stroke backupStroke = g.getStroke();
        g.setStroke(new BasicStroke(2 * lineSize));
        g.draw(path);
        g.setColor(backupColor);
        g.setStroke(backupStroke);
    }
    g.draw(path);
    if (line.isSelected()) {
        // draw dotted line
        Stroke backupStroke = ((Graphics2D) g).getStroke();
        ((Graphics2D) g).setStroke(selectionStroke);
        g.setXORMode(Color.white);
        g.draw(path);
        ((Graphics2D) g).setStroke(backupStroke);
        g.setPaintMode();
    }
    if (m_showDots) {
        for (Point p : line.getPoints()) {
            int size = getStrokeSize(line.getSize());
            paintDot(g, p, line, size);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 38 with GeneralPath

use of java.awt.geom.GeneralPath in project knime-core by knime.

the class HierarchicalGraphView method paint.

/**
 * Paints the nodes, the connectors and the labels on the connectors to
 * the given graphics object. Nodes are painted with different background
 * or border whether they are selected or hilited.
 *
 * @param c the component to paint on
 * @param g the graphics object
 * @param x the x value of the top left corner
 * @param y the y value of the top left corner
 * @param width The width to be paint
 * @param height The height to be paint
 */
void paint(final Component c, final Graphics2D g, final int x, final int y, final int width, final int height) {
    if (null == m_root) {
        return;
    }
    // shared instance used to draw labels
    JLabel label = new JLabel();
    m_toolTips.clear();
    final Paint origPaint = g.getPaint();
    final Stroke origStroke = g.getStroke();
    final Font origFont = g.getFont();
    g.setFont(origFont.deriveFont(origFont.getSize() * m_scale));
    g.setColor(ColorAttr.BORDER);
    Enumeration<DefaultMutableTreeNode> breadthFirst = m_root.breadthFirstEnumeration();
    while (breadthFirst.hasMoreElements()) {
        DefaultMutableTreeNode curr = breadthFirst.nextElement();
        K currK = (K) curr.getUserObject();
        if (!getVisible().containsKey(currK)) {
            continue;
        }
        paintNode(c, curr, g);
        Rectangle bounds = getVisible().get(currK);
        List<Rectangle> visibleChilds = new ArrayList<Rectangle>();
        if (!curr.isLeaf()) {
            DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) curr.getChildAt(0);
            K firstChildK = (K) firstChild.getUserObject();
            if (getVisible().containsKey(firstChildK)) {
                for (int i = 0; i < curr.getChildCount(); i++) {
                    DefaultMutableTreeNode child = (DefaultMutableTreeNode) curr.getChildAt(i);
                    K childK = (K) child.getUserObject();
                    visibleChilds.add(getVisible().get(childK));
                }
            }
        }
        if (curr.isLeaf()) {
        // currently do nothing. It would be possible to draw a leaf
        // sign here.
        } else if (visibleChilds.isEmpty()) {
            // draw line to the plus sign
            int xx = bounds.x + bounds.width / 2;
            int yy = bounds.y + bounds.height + m_layoutSettings.getLevelGap() / 2;
            g.drawLine(xx, bounds.y + bounds.height, xx, yy);
        } else {
            // draw connections to the children
            int xx = bounds.x + bounds.width / 2;
            int yy = bounds.y + bounds.height + m_layoutSettings.getLevelGap() / 2;
            g.drawLine(xx, bounds.y + bounds.height, xx, yy);
            Rectangle firstChild = visibleChilds.get(0);
            if (firstChild.x != getVisible().get(currK).x) {
                GeneralPath path = new GeneralPath();
                path.moveTo(xx, yy);
                path.lineTo(firstChild.x + firstChild.width / 2 + 3, yy);
                path.quadTo(firstChild.x + firstChild.width / 2, yy, firstChild.x + firstChild.width / 2, yy + 3);
                path.lineTo(firstChild.x + firstChild.width / 2, firstChild.y);
                g.draw(path);
            } else {
                g.drawLine(xx, yy, xx, firstChild.y);
            }
            if (visibleChilds.size() > 1) {
                Rectangle lastChild = visibleChilds.get(visibleChilds.size() - 1);
                GeneralPath path = new GeneralPath();
                path.moveTo(xx, yy);
                path.lineTo(lastChild.x + lastChild.width / 2 - 3, yy);
                path.quadTo(lastChild.x + lastChild.width / 2, yy, lastChild.x + lastChild.width / 2, yy + 3);
                path.lineTo(lastChild.x + lastChild.width / 2, lastChild.y);
                g.draw(path);
            }
            if (visibleChilds.size() > 2) {
                for (int i = 1; i < visibleChilds.size() - 1; i++) {
                    Rectangle child = visibleChilds.get(i);
                    int xxx = child.x + child.width / 2;
                    g.drawLine(xxx, yy, xxx, child.y);
                }
            }
        }
        // draw text on the connectors
        NodeWidget<K> widget = getWidgets().get(currK);
        widget.setScaleFactor(m_scale);
        String labelAbove = widget.getConnectorLabelAbove();
        if (null != labelAbove && !labelAbove.isEmpty()) {
            label.setText(labelAbove);
            label.setOpaque(true);
            label.setBackground(ColorAttr.BACKGROUND);
            label.setFont(g.getFont().deriveFont(Font.BOLD | Font.ITALIC));
            int wOffset = Math.round(-10 * m_scale);
            int w = Math.min(m_layoutSettings.getNodeWidth() + wOffset, label.getPreferredSize().width);
            int h = label.getPreferredSize().height;
            int xx = bounds.x + (bounds.width - w) / 2;
            int yyOffset = Math.round(-18 * m_scale);
            int yy = bounds.y - h + yyOffset;
            Rectangle labelBounds = new Rectangle(xx, yy, w, h);
            m_toolTips.put(labelBounds, labelAbove);
            SwingUtilities.paintComponent(g, label, (Container) c, labelBounds);
        }
        String labelBelow = widget.getConnectorLabelBelow();
        if (null != labelBelow && !labelBelow.isEmpty() && !visibleChilds.isEmpty()) {
            label.setText(labelBelow);
            label.setOpaque(true);
            label.setBackground(ColorAttr.BACKGROUND);
            label.setFont(g.getFont().deriveFont(Font.BOLD | Font.ITALIC));
            int wOffset = Math.round(-10 * m_scale);
            int w = Math.min(m_layoutSettings.getNodeWidth() + wOffset, label.getPreferredSize().width);
            int h = label.getPreferredSize().height;
            int xx = bounds.x + (bounds.width - w) / 2;
            int yyOffset = Math.round(10 * m_scale);
            int yy = bounds.y + bounds.height + yyOffset;
            Rectangle labelBounds = new Rectangle(xx, yy, w, h);
            m_toolTips.put(labelBounds, labelBelow);
            SwingUtilities.paintComponent(g, label, (Container) c, labelBounds);
        }
    }
    for (Rectangle bounds : m_collapseSign.keySet()) {
        int yy = bounds.y + bounds.height / 2;
        int delta = 3;
        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
        g.drawLine(bounds.x + delta, yy, bounds.x + bounds.width - delta, yy);
    }
    for (Rectangle bounds : m_expandSign.keySet()) {
        int xx = bounds.x + bounds.width / 2;
        int yy = bounds.y + bounds.height / 2;
        int delta = 3;
        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
        g.drawLine(bounds.x + delta, yy, bounds.x + bounds.width - delta, yy);
        g.drawLine(xx, bounds.y + delta, xx, bounds.y + bounds.height - delta);
    }
    g.setPaint(origPaint);
    g.setStroke(origStroke);
    g.setFont(origFont);
    // notify listeners about the repaint
    for (GraphListener listener : m_graphListeners) {
        listener.graphRepaint();
    }
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) GeneralPath(java.awt.geom.GeneralPath) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) Paint(java.awt.Paint) Font(java.awt.Font) Point(java.awt.Point) Paint(java.awt.Paint)

Example 39 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class Plot2DPanel method getLinePlot.

/**
 * Insert the method's description here.
 * Creation date: (2/7/2001 2:22:29 AM)
 * @param plotData cbit.plot.PlotData
 * @param index int
 * @return java.awt.geom.GeneralPath
 */
private GeneralPath getLinePlot(PlotData plotData, int index) {
    if (plotData != null) {
        nodes[index].setPoints(mapPoints(plotData));
        GeneralPath path = new GeneralPath();
        for (int i = 0; i < plotData.getSize() - 1; i++) {
            Line2D.Double segment = new Line2D.Double(nodes[index].getPoints()[i], nodes[index].getPoints()[i + 1]);
            path.append(segment, true);
        }
        return path;
    } else {
        return null;
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Line2D(java.awt.geom.Line2D) Point(java.awt.Point) Paint(java.awt.Paint)

Example 40 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class ReactionParticipantShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int parentOffsetX, int parentOffsetY) {
    if (startShape.isSelected()) {
        forgroundColor = Color.red.darker();
    } else {
        forgroundColor = Color.black;
    }
    if (isSelected()) {
        forgroundColor = Color.red;
    }
    // draw cubic spline with horizontal reactant-end (p' = 0) at reaction
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CubicCurve2D.Double cubicCurve = getCurve();
    // render curve (make CatalystShapes draw with a dashed line)
    g2D.setColor(forgroundColor);
    if (getLineStyle() == LINE_STYLE_DASHED) {
        Stroke oldStroke = g2D.getStroke();
        g2D.setStroke(DASHED_STROKE);
        g2D.draw(cubicCurve);
        g2D.setStroke(oldStroke);
    } else {
        g2D.draw(cubicCurve);
    }
    int arrowDirection = 0;
    if (this instanceof ProductShape) {
        arrowDirection = 1;
    }
    if (this instanceof ReactantShape) {
        arrowDirection = -1;
    }
    if (arrowDirection == 1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    if (arrowDirection == -1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2 + 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    // draw label
    if (getLabel() != null && getLabel().length() > 0) {
        int x = start.x + (int) (start.x * correctionFactor);
        int y = start.y + (int) (start.y * correctionFactor);
        g2D.drawString(getLabel(), (x + end.x) / 2, (y + end.y) / 2);
    }
    return;
}
Also used : Stroke(java.awt.Stroke) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) CubicCurve2D(java.awt.geom.CubicCurve2D) Point(java.awt.Point)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1