Package project.gluebooster.graphics

Examples of project.gluebooster.graphics.RectangleWithRef


      for (Vertex vertex : graph.getVertices())
      {
         Point2D point = layout.transform(vertex);
         System.out.println("point of " + vertex + " is " + point);
         Dimension size = vertexDimensionGetter.get(vertex);
         shapes.add(new RectangleWithRef(new Rectangle2D.Double(point.getX(),
               point.getY(), size.width, size.height), vertex));
      }
     

      boolean optimize = true;
      // Optimize layout
      if (optimize)
      {
         // Sort by X-Coordinates
         for (RectangleWithRef rect : shapes)
         {
            rect.setSortType(RectangleWithRef.Sorting.X);
         }
         Collections.sort(shapes);

         // Part1 translate overlapping recangles

         int size = shapes.size();
         for (int i = 0; i < size; i++)
         {
            RectangleWithRef rectangle = shapes.get(i);

            int xTranslation = 0;
            for (int j = i + 1; j < size; j++)
            {
               RectangleWithRef rectangle2 = shapes.get(j);
               if (rectangle2.x > rectangle.getRightX())
               {
                  break;
               } else if (rectangle2.intersects(rectangle))
               {
                  // move all followin components to the right
                  for (int k = j; k < size; k++)
                  {
                     shapes.get(k).translateRight(rectangle.width);
                  }

                  break;
               }
            }
         }

         int vertexDistance = 40;// distance between vertices
         int lineDistance = 5;// distance between lines and other objects

         // Part2 compress X

         RectangleWithRef rectangle0 = shapes.get(0);
         if (rectangle0.x > vertexDistance)
            rectangle0.x = vertexDistance;

         for (int i = 1; i < size; i++)
         {
            RectangleWithRef rectangle = shapes.get(i - 1);
            RectangleWithRef rectangle2 = shapes.get(i);

            if (rectangle2.x > rectangle.getRightX() + vertexDistance)
            {
               if (rectangle2.y > rectangle.y + rectangle.height
                     + vertexDistance)
                  rectangle2.x = rectangle.x;
               else if (rectangle2.getBottomY() < rectangle.y - vertexDistance)
                  rectangle2.x = rectangle.x;
               else
                  rectangle2.x = rectangle.getRightX() + vertexDistance;
            }
         }

         // Part3 compress Y

         if (rectangle0.y > vertexDistance)
            rectangle0.y = vertexDistance;

         for (int i = 1; i < size; i++)
         {
            RectangleWithRef rectangle = shapes.get(i - 1);
            RectangleWithRef rectangle2 = shapes.get(i);

            if (rectangle2.y > rectangle.getBottomY() + vertexDistance)
            {
               rectangle2.y = rectangle.getBottomY() + vertexDistance;
            }
View Full Code Here


                  compressedGraph.addVertex(vertex);
              }
              else
              {
                didSomething = true;
                RectangleWithRef<Pair<RectangleWithRef<?,?>, RectangleWithRef<?,?>>,?> newVertex = new RectangleWithRef(new Pair<RectangleWithRef<?,?>, RectangleWithRef<?,?>>(vertex, neighbour));
                Collection subelements = newVertex.getRef();
                newVertex.setSubelements(subelements); //use the pair as subelements, so that the translation is done automatically
                newVertex.width = vertex.width + vertexDistance + neighbour.width;
                newVertex.height = vertex.height + vertexDistance + neighbour.height;
               
                //arrange the vertices from left to right (this should be changed based on the result layout below)
                vertex.setUpperLeftCorner(0,0);
View Full Code Here

TOP

Related Classes of project.gluebooster.graphics.RectangleWithRef

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.