Package net.wigis.graph.dnv.utilities

Examples of net.wigis.graph.dnv.utilities.Vector2D


    {
      if( hasStoredPosition && startInterpolation )
      {
//        System.out.println( "interpolation has[" + hasStoredPosition + "] start[" + startInterpolation + "] reverse[" + reverseInterpolation
//            + "] display[" + displayStoredPosition + "]" );
        Vector2D originalPosition;
        Vector2D displayPosition;
        Vector2D finalPosition;
        float x_diff;
        float y_diff;

        // float frames = 50;
        float seconds;
        // if( currentFrame == 0 )
        // {
        // storedPositionTimer.setStart();
        // }

        seconds = storedPositionTimer.getTimeSinceStart( Timer.SECONDS );

        float ratio = seconds / totalSeconds;
        // System.out.println( "currentFrame : " + currentFrame );
        // System.out.println( "seconds : " + seconds );
        // System.out.println( "ratio : " + ratio );
        if( ratio >= 1 )
        {
          startInterpolation = false;
          if( !reverseInterpolation )
          {
            removeStoredPosition( level );
          }
          currentFrame = 0;
        }
        else
        {
          List<DNVNode> nodes = getNodes( level );
          // int i = 0;
          for( DNVNode node : nodes )
          {
            if( !reverseInterpolation )
            {
              finalPosition = node.getPosition( false );
              displayPosition = node.getPosition( true );
              originalPosition = node.getOriginalPosition();
            }
            else
            {
              finalPosition = node.getOriginalPosition();
              displayPosition = node.getPosition( true );
              originalPosition = node.getPosition( false );
            }
            x_diff = finalPosition.getX() - originalPosition.getX();
            y_diff = finalPosition.getY() - originalPosition.getY();
            x_diff *= ratio;
            y_diff *= ratio;
            x_diff += originalPosition.getX();
            y_diff += originalPosition.getY();

View Full Code Here


      {
        currentLine = currentChunk.get( j );
        currentLineArray = parseLine( currentLine, delim );
        if( currentChunkType.equals( "@NODES" ) )
        {
          DNVNode dnvNode = new DNVNode( new Vector2D( (float)Math.random(), (float)Math.random() ), dnvGraph );
          dnvNode.setLevel( 0 );
          dnvNode.setId( Integer.parseInt( currentLineArray.get( 0 ) ) );
          dnvNode.setLabel( currentLineArray.get( 1 ) );
          dnvNode.setColor( currentColor );
          dnvNode.setRadius( (float)currentSize );
View Full Code Here

  @Override
  public void paint( Graphics g, PaintBean pb )
  {
    if( !hasCompleted() )
    {
      Vector2D screenPos;
      if( screenPosition )
      {
        screenPos = node.getPosition( true );
      }
      else
      {
        screenPos = ImageRenderer.transformPosition( pb.getGlobalMinX(), pb.getGlobalMaxX(), pb.getGlobalMinY(), pb.getGlobalMaxY(), pb.getMinX(), pb.getMaxX(), pb.getMinY(), pb.getMaxY(), pb.getWidth(), pb.getHeight(), node.getPosition( true ) );
      }
     
      currentRadius += radiusIncrement;
      currentAlpha -= 1.0f / (float)numberOfFrames;
      if( currentAlpha < 0 )
      {
        currentAlpha = 0;
      }
      g.setColor( new Color(color.getX(), color.getY(), color.getZ(), currentAlpha ) );
      ((Graphics2D)g).setStroke( new BasicStroke( strokeWidth ) );
      g.drawArc( (int)screenPos.getX()-currentRadius, (int)screenPos.getY()-currentRadius, currentRadius*2, currentRadius*2, 0, 360 );
//      StarPolygon p = new StarPolygon( (int)screenPos.getX(), (int)screenPos.getY(), currentRadius*2, currentRadius, 5 );
//      ((Graphics2D)g).draw( p );
     
      if( geometric != null )
      {
View Full Code Here

   * @see net.wigis.graph.dnv.animations.Animation#paint(java.awt.Graphics, net.wigis.graph.PaintBean)
   */
  @Override
  public void paint( Graphics g, PaintBean pb )
  {
    Vector2D startPos;
    Vector2D endPos;
    Vector2D currentPos = new Vector2D();
    DNVNode endNode;
    if( this.edge.getFrom().equals( startingNode ) )
    {
      startPos = this.edge.getFrom().getPosition( true );
      endPos = this.edge.getTo().getPosition( true );
      endNode = this.edge.getTo();
    }
    else
    {
      startPos = this.edge.getTo().getPosition( true );
      endPos = this.edge.getFrom().getPosition( true );
      endNode = this.edge.getFrom();
    }
    handledEntities.put( endNode.getId(), endNode );
    currentPos.setX( startPos.getX() + ((endPos.getX() - startPos.getX()) * shownFrames / (float)numberOfFrames) );
    currentPos.setY( startPos.getY() + ((endPos.getY() - startPos.getY()) * shownFrames / (float)numberOfFrames) );
   
    Vector2D screenPos = ImageRenderer.transformPosition( pb.getGlobalMinX(), pb.getGlobalMaxX(), pb.getGlobalMinY(), pb.getGlobalMaxY(), pb.getMinX(), pb.getMaxX(), pb.getMinY(), pb.getMaxY(), pb.getWidth(), pb.getHeight(), currentPos );
    if( edge.isSelected() || ( (pb.isHighlightEdges() || pb.isHighlightNeighbors()) && ( edge.getFrom().isSelected() || edge.getTo().isSelected() ) ) )
    {
      g.setColor( Color.red );
    }
    else if( edge.getColor() != null && edge.hasSetColor() && !edge.getColor().equals( DNVEntity.NO_COLOR) )
    {
      g.setColor( new Color( edge.getColor().getX(), edge.getColor().getY(), edge.getColor().getZ() ) );
    }
    else
    {
      g.setColor( new Color( (float)pb.getEdgeColor(), (float)pb.getEdgeColor(), (float)pb.getEdgeColor() ) );
    }
   
    float size = edge.getThickness() * 8;
    g.fillOval( Math.round( screenPos.getX() - (size/2f) ), Math.round( screenPos.getY() - (size/2f) ), Math.round( size ), Math.round( size ) );
   
    shownFrames++;
   
    if( this.hasCompleted() )
    {
      Vector3D color = endNode.getColor();
      if( endNode.isSelected() )
      {
        color = new Vector3D( 1, 0, 0 );
      }
      if( color == null )
      {
        color = new Vector3D( 0, 0, 0 );
      }
      int radius = pb.getNodeWidthOnScreen( endNode ) / 2;
      Text t = null;
      boolean playSound = false;
      synchronized( handledDistances )
      {
        if( handledDistances.get( currentDistance ) == null )
        {
          handledDistances.put( currentDistance, true );
          t = new Text( "Dist " + currentDistance, new Vector2D( 45, pb.getHeightInt() - 30 ), new Vector3D(1,1,1), endNode.getColor(), 15, true, true, true, false, false, false, true );
          Animation a = new NodeGlowAnimation( 10, color, t.getNode(), radius, radius + 40, 2, true, t );
          endNode.getGraph().addAnimation( a );
          if( pb.isPlaySound() )
          {
            try
View Full Code Here

    {
      SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
      Collections.sort( nodes, sbls );
    }
    DNVNode node = null;
    Vector2D screenPosition;
    double distance;
    double minDistance = Integer.MAX_VALUE;
    int nodeI = -1;
    int distX = 0; // dist b/w this node and mouse click
    int distY = 0;

    // Check if user clicked on a solid node label
    for( int i = nodes.size() - 1; i >= 0; i-- )
    {
      node = nodes.get( i );
      if( node.isVisible() && (node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
      {
        screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY, width, height, node.getPosition( true ) );
        ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null, (int)Math.round(pb.getNodeSize()*node.getRadius()), node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb.getLabelSize(),
            minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), nodes.size() > 1000, false );
        if( mouseDownX >= boundingRectangle.left() &&
          mouseDownX <= boundingRectangle.right() &&
          mouseDownY <= boundingRectangle.bottom() &&
          mouseDownY >= boundingRectangle.top() )
        {
          distX = (int)( mouseDownX - screenPosition.getX() );
          distY = (int)( mouseDownY - screenPosition.getY() );
          node.setProperty( "distX", "" + distX );
          node.setProperty( "distY", "" + distY );
          minDistance = 0;
          nodeI = i;
          break;
        }
      }
    }
   
    if( nodeI == -1 )
    {
      // loop thru all nodes to find closest node
      for( int i = nodes.size() - 1; i >= 0; i-- )
      {
        node = nodes.get( i );
        if( node.isVisible() )
        {
          screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY,
              globalMaxY, minX, maxX, minY, maxY, width, height, node.getPosition( true ) );

          // find node closest to mouseDown
          distX = (int)( mouseDownX - screenPosition.getX() );
          distY = (int)( mouseDownY - screenPosition.getY() );
         
          distance = distX * distX + distY * distY;

          if( distance < minDistance )
          {
            node.setProperty( "distX", "" + distX );
            node.setProperty( "distY", "" + distY );

            minDistance = distance;
            nodeI = i;
          }
        }
      }
    }
   
   
    if( nodes.size() > 0 )
    {
      node = nodes.get( nodeI );

      double nodeWidth;
      nodeWidth = GraphServlet.getNodeWidth( pb, width, minX, maxX, node.getRadius() ) + selectionBuffer;
      // check if selected node is close enough to mouseDown
      if( Settings.DEBUG )
        System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
     
      if( Math.sqrt( minDistance ) >= nodeWidth )
      {
        // Still no node selected so check nodes with faded labels
        for( int i = nodes.size() - 1; i >= 0; i-- )
        {
          node = nodes.get( i );
          if( node.isVisible() && (node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null && Float.parseFloat( node.getProperty( "faded" ) ) > 0.1  )
          {
            screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY, width, height, node.getPosition( true ) );
            ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null, (int)Math.round(pb.getNodeSize()*node.getRadius()), node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb.getLabelSize(),
                minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), nodes.size() > 1000, false );
            if( mouseDownX >= boundingRectangle.left() &&
              mouseDownX <= boundingRectangle.right() &&
              mouseDownY <= boundingRectangle.bottom() &&
              mouseDownY >= boundingRectangle.top() )
            {
              distX = (int)( mouseDownX - screenPosition.getX() );
              distY = (int)( mouseDownY - screenPosition.getY() );
              node.setProperty( "distX", "" + distX );
              node.setProperty( "distY", "" + distY );
              minDistance = 0;
              nodeI = i;
              break;
View Full Code Here

   *            the max y
   * @return true, if is node within
   */
  public static boolean isNodeWithin( DNVNode tempNode, double minX, double minY, double maxX, double maxY )
  {
    Vector2D position = tempNode.getPosition();

    if( position.getY() >= minY && position.getY() <= maxY && position.getX() >= minX && position.getX() <= maxX )
    {
      return true;
    }

    return false;
View Full Code Here

        double movementX = (previousMovePos.getX() - e.getPoint().x) * xRatio;
        double movementY = (previousMovePos.getY() - e.getPoint().y) * yRatio;
        handler.performPanning( movementX, movementY );
      }

      previousMovePos = new Vector2D( e.getPoint().x, e.getPoint().y );
    }
  }
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.utilities.Vector2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.