Search in sources :

Example 96 with Point2D

use of java.awt.geom.Point2D in project openblocks by mikaelhg.

the class InfixBlockShape method makeBottomSide.

/**
     * Overrided from BlockShape.
     * Takes into account the need to resize the dimensions of an infix block for various cases.
     */
@Override
protected void makeBottomSide() {
    // Reset the maximum X-coordinate so the infix block can resize if you remove blocks within it
    maxX = 0;
    //start bottom-right
    setEndPoint(gpBottom, botLeftCorner, topLeftCorner, true);
    //curve down and right
    BlockShapeUtil.cornerTo(gpBottom, botLeftCorner, botRightCorner, blockCornerRadius);
    /// BOTTOM SOCKETS
    //for each socket in the iterator
    //need to use this to determine which socket we're on
    int socketCounter = 0;
    for (BlockConnector curSocket : block.getSockets()) {
        //if bottom socket
        if (curSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
            //move away from bottom left corner
            if (socketCounter > 0) {
                gpBottom.lineTo((float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER, (float) gpBottom.getCurrentPoint().getY());
            } else {
                gpBottom.lineTo((float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, (float) gpBottom.getCurrentPoint().getY());
            }
            //move down so bevel doesn't screw up from connecting infinitely sharp corner
            // as occurs from a curved port
            BlockShapeUtil.lineToRelative(gpBottom, 0, -0.1f);
            if (curSocket.getBlockID() == Block.NULL) {
                //draw first socket - up left side
                Point2D leftSocket = BCS.addDataSocketUp(gpBottom, curSocket.getKind(), true);
                rb.updateSocketPoint(curSocket, leftSocket);
                //System.out.println("socket poitn: "+rb.getSocketPoint(curSocket));
                //System.out.println("socket poitn leftsocket: "+leftSocket);
                //draw left standard empty socket space - top side
                gpBottom.lineTo((float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, (float) gpBottom.getCurrentPoint().getY());
                //draw first socket - down right side
                BCS.addDataSocket(gpBottom, curSocket.getKind(), false);
            //rb.updateSocketPoint(curSocket, rightSocket);
            } else {
                //there is a connected block
                Block connectedBlock = rb.getWorkspace().getEnv().getBlock(curSocket.getBlockID());
                RenderableBlock connectedRBlock = rb.getWorkspace().getEnv().getRenderableBlock(curSocket.getBlockID());
                //calculate and update the new socket point
                //update the socket point of this cursocket which should now adopt the plug socket point of its
                //connected block since we're also adopting the left side of its shape
                //Use coordinates when the zoom level is 1.0 to calculate socket point
                double unzoomX = connectedRBlock.getSocketPixelPoint(connectedBlock.getPlug()).getX() / connectedRBlock.getZoom();
                double unzoomY = connectedRBlock.getSocketPixelPoint(connectedBlock.getPlug()).getY() / connectedRBlock.getZoom();
                Point2D connectedBlockSocketPoint = new Point2D.Double(unzoomX, unzoomY);
                Point2D currentPoint = gpBottom.getCurrentPoint();
                double newX = connectedBlockSocketPoint.getX() + Math.abs(connectedBlockSocketPoint.getX() - currentPoint.getX());
                double newY = connectedBlockSocketPoint.getY() + Math.abs(connectedRBlock.getBlockHeight() / connectedRBlock.getZoom() - currentPoint.getY());
                rb.updateSocketPoint(curSocket, new Point2D.Double(newX, newY));
                BlockShape connectedBlockShape = rb.getWorkspace().getEnv().getRenderableBlock(curSocket.getBlockID()).getBlockShape();
                //append left side of connected block
                appendPath(gpBottom, connectedBlockShape.getLeftSide(), false);
                //append right side of connected block (more complicated)
                if (connectedBlock.getNumSockets() == 0 || connectedBlock.isInfix()) {
                    //                      append top side of connected block
                    appendPath(gpBottom, connectedBlockShape.getTopSide(), false);
                    appendPath(gpBottom, connectedBlockShape.getRightSide(), false);
                } else {
                    //iterate through the sockets of the connected block, checking if 
                    //it has blocks connected to them
                    appendRightSidePath(gpBottom, connectedBlock, connectedBlockShape);
                }
                // Updates the maximum X-coordinate and sets the current point to maxX 
                if (maxX < (float) gpBottom.getCurrentPoint().getX()) {
                    maxX = (float) gpBottom.getCurrentPoint().getX();
                }
                gpBottom.lineTo(maxX, (float) gpBottom.getCurrentPoint().getY());
            }
            //bump down so bevel doesn't screw up
            BlockShapeUtil.lineToRelative(gpBottom, 0, 0.1f);
            //// draw RIGHT to create divider ////
            if (socketCounter < block.getNumSockets() - 1) {
                //need to add the width of the block label.  warning: this assumes that there is only one block label
                gpBottom.lineTo((float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER + rb.accomodateLabelsWidth(), (float) gpBottom.getCurrentPoint().getY());
            } else {
                gpBottom.lineTo((float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, (float) gpBottom.getCurrentPoint().getY());
            }
            socketCounter++;
        }
    }
    //curve right and up
    BlockShapeUtil.cornerTo(gpBottom, botRightCorner, topRightCorner, blockCornerRadius);
    //end bottom
    setEndPoint(gpBottom, botRightCorner, topRightCorner, false);
}
Also used : RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) Point2D(java.awt.geom.Point2D) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock)

Example 97 with Point2D

use of java.awt.geom.Point2D in project CoreNLP by stanfordnlp.

the class TreeJPanel method paintTree.

private static double paintTree(Tree t, Point2D start, Graphics2D g2, FontMetrics fM) {
    if (t == null) {
        return 0.0;
    }
    String nodeStr = nodeToString(t);
    double nodeWidth = fM.stringWidth(nodeStr);
    double nodeHeight = fM.getHeight();
    double nodeAscent = fM.getAscent();
    WidthResult wr = widthResult(t, fM);
    double treeWidth = wr.width;
    double nodeTab = wr.nodeTab;
    double childTab = wr.childTab;
    double nodeCenter = wr.nodeCenter;
    //double treeHeight = height(t, fM);
    // draw root
    g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent));
    if (t.isLeaf()) {
        return nodeWidth;
    }
    double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip);
    double layerHeight = nodeHeight * layerMultiplier;
    double childStartX = start.getX() + childTab;
    double childStartY = start.getY() + layerHeight;
    double lineStartX = start.getX() + nodeCenter;
    double lineStartY = start.getY() + nodeHeight * (1.0 + belowLineSkip);
    double lineEndY = lineStartY + nodeHeight * parentSkip;
    // recursively draw children
    for (int i = 0; i < t.children().length; i++) {
        Tree child = t.children()[i];
        double cWidth = paintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM);
        // draw connectors
        wr = widthResult(child, fM);
        double lineEndX = childStartX + wr.nodeCenter;
        g2.draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY));
        childStartX += cWidth;
        if (i < t.children().length - 1) {
            childStartX += sisterSkip * fM.stringWidth(" ");
        }
    }
    return treeWidth;
}
Also used : Point2D(java.awt.geom.Point2D) Tree(edu.stanford.nlp.trees.Tree) Line2D(java.awt.geom.Line2D)

Example 98 with Point2D

use of java.awt.geom.Point2D in project CoreNLP by stanfordnlp.

the class ScrollableTreeJPanel method paintTree.

protected double paintTree(Tree t, Point2D start, Graphics2D g2, FontMetrics fM, Color paintColor) {
    if (t == null) {
        return 0.0;
    }
    String nodeStr = nodeToString(t);
    double nodeWidth = fM.stringWidth(nodeStr);
    double nodeHeight = fM.getHeight();
    double nodeAscent = fM.getAscent();
    WidthResult wr = widthResult(t, fM);
    double treeWidth = wr.width;
    double nodeTab = wr.nodeTab;
    double childTab = wr.childTab;
    double nodeCenter = wr.nodeCenter;
    //double treeHeight = height(t, fM);
    // draw root
    Color curColor = g2.getColor();
    g2.setColor(paintColor);
    g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent));
    g2.setColor(curColor);
    double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip);
    double layerHeight = nodeHeight * layerMultiplier;
    if (t.isLeaf()) {
        yieldOffsets[leafCtr++] = (float) (nodeTab + start.getX());
        return nodeWidth;
    }
    double childStartX = start.getX() + childTab;
    double childStartY = start.getY() + layerHeight;
    double lineStartX = start.getX() + nodeCenter;
    double lineStartY = start.getY() + nodeHeight * (1.0 + belowLineSkip);
    double lineEndY = lineStartY + nodeHeight * parentSkip;
    // recursively draw children
    for (int i = 0; i < t.children().length; i++) {
        Tree child = t.children()[i];
        double cWidth;
        if (matchedParts != null && matchedParts.contains(child)) {
            // Track where we've painted this matched child
            Point2D.Double coord = new Point2D.Double(childStartX, childStartY);
            matchedPartCoordinates.add(coord);
            cWidth = paintTree(child, coord, g2, fM, matchedColor);
        } else {
            Color col = defaultColor;
            if (((CoreLabel) child.label()).containsKey(CoreAnnotations.DoAnnotation.class))
                col = (((CoreLabel) child.label()).get(CoreAnnotations.DoAnnotation.class)) ? tdiffColor : defaultColor;
            cWidth = paintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM, col);
        }
        // draw connectors
        wr = widthResult(child, fM);
        double lineEndX = childStartX + wr.nodeCenter;
        g2.draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY));
        childStartX += cWidth;
        if (i < t.children().length - 1) {
            childStartX += sisterSkip * fM.stringWidth(" ");
        }
    }
    return treeWidth;
}
Also used : Line2D(java.awt.geom.Line2D) CoreLabel(edu.stanford.nlp.ling.CoreLabel) Point2D(java.awt.geom.Point2D) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) Tree(edu.stanford.nlp.trees.Tree)

Example 99 with Point2D

use of java.awt.geom.Point2D in project android_frameworks_base by AOSPA.

the class Path_Delegate method resetLastPointFromPath.

private void resetLastPointFromPath() {
    Point2D last = mPath.getCurrentPoint();
    mLastX = (float) last.getX();
    mLastY = (float) last.getY();
}
Also used : Point2D(java.awt.geom.Point2D)

Example 100 with Point2D

use of java.awt.geom.Point2D in project GNS by MobilityFirst.

the class EC2Runner method initAndUpdateEC2Host.

/**
   * This is called to initialize an EC2 host for use as A GNS server in a region. It starts the host, loads all the necessary
   * software and copies the JAR files over. We also collect info about this host, like it's IP address and geographic location.
   * When every host is initialized and we have collected all the IPs, phase two is called.
   *
   * @param region - the EC2 region where we are starting this host
   * @param runSetName - so we can terminate them all together
   * @param id - the GNS ID of this server
   * @param elasticIP
   * @param timeout
   */
public static void initAndUpdateEC2Host(RegionRecord region, String runSetName, String id, String elasticIP, int timeout) {
    String installScript;
    AMIRecord amiRecord = AMIRecord.getAMI(amiRecordType, region);
    if (amiRecord == null) {
        System.out.println("Invalid combination of " + amiRecordType + " and Region " + region.name());
        return;
    }
    switch(dataStoreType) {
        case CASSANDRA:
            installScript = cassandraInstallScript;
            break;
        default:
            // MONGO
            if (amiRecordType.toString().contains("Amazon_Linux")) {
                installScript = mongoInstallScript;
            } else {
                switch(amiRecordType) {
                    case MongoDB_2_4_8_with_1000_IOPS:
                        installScript = mongoShortInstallScript;
                        break;
                    case Mongo_2014_5_6:
                        installScript = null;
                        break;
                    case Mongo_2014_5_6_micro:
                        installScript = null;
                        break;
                    case Mongo_2015_6_25_vpc:
                        installScript = null;
                        break;
                    case Mongo_2016_6_16_micro:
                        installScript = null;
                        break;
                    default:
                        System.out.println("Invalid combination of " + amiRecordType + " and " + dataStoreType);
                        return;
                }
            }
    }
    String idString = id.toString();
    //    StatusModel.getInstance().queueUpdate(id, region.name() + ": [Unknown hostname]", null, null);
    try {
        AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
        //Create Amazon Client object
        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        String nodeName = "GNS Node " + idString;
        System.out.println("Starting install for " + nodeName + " in " + region.name() + " as part of run set " + runSetName);
        HashMap<String, String> tags = new HashMap<>();
        tags.put("runset", runSetName);
        tags.put("id", idString);
        //      StatusModel.getInstance().queueUpdate(id, "Creating instance");
        // create an instance
        Instance instance = AWSEC2.createAndInitInstance(ec2, region, amiRecord, nodeName, keyName, amiRecord.getSecurityGroup(), installScript, tags, elasticIP, timeout);
        if (instance != null) {
            //        StatusModel.getInstance().queueUpdate(id, "Instance created");
            //        StatusModel.getInstance().queueUpdate(id, StatusEntry.State.INITIALIZING);
            // toString our ip
            String hostname = instance.getPublicDnsName();
            InetAddress inetAddress = InetAddress.getByName(hostname);
            String ip = inetAddress.getHostAddress();
            // and take a guess at the location (lat, long) of this host
            Point2D location = GEOLocator.lookupIPLocation(ip);
            //        StatusModel.getInstance().queueUpdate(id, hostname, ip, location);
            // update our table of instance information
            hostTable.put(id, new HostInfo(id, hostname, location));
        // and we're done
        //        StatusModel.getInstance().queueUpdate(id, "Waiting for other servers");
        } else {
            System.out.println("EC2 Instance " + idString + " in " + region.name() + " did not in start.");
            //        StatusModel.getInstance().queueUpdate(id, StatusEntry.State.ERROR, "Did not start");
            hostsThatDidNotStart.put(id, id);
        }
    } catch (IOException e) {
        System.out.println("Problem creating EC2 instance " + idString + " in " + region.name() + ": " + e);
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        System.out.println("Problem creating EC2 instance " + idString + " in " + region.name() + ": " + e);
        e.printStackTrace();
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AMIRecord(edu.umass.cs.aws.support.AMIRecord) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Instance(com.amazonaws.services.ec2.model.Instance) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) Point2D(java.awt.geom.Point2D) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) File(java.io.File) InetAddress(java.net.InetAddress)

Aggregations

Point2D (java.awt.geom.Point2D)159 Rectangle2D (java.awt.geom.Rectangle2D)18 Color (java.awt.Color)12 RadialGradientPaint (java.awt.RadialGradientPaint)10 AffineTransform (java.awt.geom.AffineTransform)10 Line2D (java.awt.geom.Line2D)9 Paint (java.awt.Paint)8 Graphics2D (java.awt.Graphics2D)7 BufferedImage (java.awt.image.BufferedImage)7 Element (org.jdom2.Element)6 BasicStroke (java.awt.BasicStroke)5 IOException (java.io.IOException)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 Point (java.awt.Point)4 Rectangle (java.awt.Rectangle)4 NodeRef (dr.evolution.tree.NodeRef)3 RenderableBlock (edu.mit.blocks.renderable.RenderableBlock)3 Arc2D (java.awt.geom.Arc2D)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2