1 6 7 package com.thoughtriver.open.vectorvisuals.meta.arranger; 8 9 import java.awt.geom.*; 10 import java.util.*; 11 12 import com.thoughtriver.open.vectorvisuals.*; 13 14 24 public class GridArranger extends Arranger { 25 26 30 private double spacing; 31 32 36 private int objectsPerRow; 37 38 43 public GridArranger() { 44 setSpacing(10.0); 45 setObjectsPerRow(10); 46 } 47 48 55 public double getSpacing() { 56 return spacing; 57 } 58 59 66 public void setSpacing(final double spacing) { 67 this.spacing = spacing; 68 } 69 70 77 public int getObjectsPerRow() { 78 return objectsPerRow; 79 } 80 81 88 public void setObjectsPerRow(final int objectsPerRow) { 89 this.objectsPerRow = objectsPerRow; 90 } 91 92 95 @Override 96 public Map<VisualObject, AffineTransform> getArrangedPositions() { 97 98 Map<VisualObject, AffineTransform> positions = new HashMap<VisualObject, AffineTransform>(); 100 int curRow = 0; 101 int curCol = 0; 102 for (VisualObject obj : getObjects()) { 103 positions.put(obj, AffineTransform.getTranslateInstance(getSpacing() 104 * curCol, getSpacing() * curRow)); 105 106 curCol++; 107 if (curCol == getObjectsPerRow()) { 108 curCol = 0; 109 curRow++; 110 } 111 } 112 113 return positions; 114 } 115 116 } 117 | Popular Tags |