package etomica.graphics;

import java.awt.Color;
import java.awt.Graphics;

import etomica.atom.AtomLeaf;
import etomica.lattice.RectangularLattice;
import etomica.nbr.site.AtomSite;
import etomica.nbr.site.NeighborSiteManager;


/**
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 *
 * @author David Kofke
 *
 */

/*
 * History
 * Created on May 23, 2005 by kofke
 */
public class DisplayPhaseSpin2D extends DisplayPhaseCanvas2D {

    /**
     * @param phase
     */
    public DisplayPhaseSpin2D(DisplayPhase _phase, NeighborSiteManager neighborSiteManager) {
        super(_phase);
        latticeIndex = new int[displayPhase.getPhase().space().D()];
        spinWidth = 5;
        this.neighborSiteManager = neighborSiteManager;
    }
    
    protected void drawAtom(Graphics g, int origin[], AtomLeaf atom) {
        AtomSite site = neighborSiteManager.getSite(atom);
        if (site == null) return;
        RectangularLattice lattice = neighborSiteManager.getLattice();
        lattice.latticeIndex(site.getLatticeArrayIndex(),latticeIndex);
            
        //color central site red
//        ((MySite)lattice.site(iterator.centralSite)).color = Color.RED;
        int nx = 5; //number of planes to draw before moving down to another line of planes
        int k = latticeIndex.length < 3 ? 0 : latticeIndex[2];
        int ox = origin[0] + k % nx;       //set origin for drawing each lattice plane
        int oy = origin[1] + (k - ox)/nx;
        ox = 3 + ox*spinWidth*(lattice.getSize()[0]+2);
        oy = 3 + oy*spinWidth*(lattice.getSize()[1]+2);
        //draw lattice plane
        g.setColor(atom.coord.position().x(0) > 0 ? Color.green : Color.white);
        g.fillRect(ox+latticeIndex[0]*spinWidth,oy+latticeIndex[1]*spinWidth,spinWidth,spinWidth);
//        g.setColor(Color.black);
//        g.drawRect(ox+latticeIndex[0]*spinWidth,oy+latticeIndex[1]*spinWidth,spinWidth,spinWidth);
    }

    private int spinWidth;
    private final int[] latticeIndex;
    private final NeighborSiteManager neighborSiteManager;
}

@@ -1424,20 +1424,8 @@
 ox =
- origin%5B0%5D +
  k %25
@@ -1499,20 +1499,8 @@
 oy =
- origin%5B1%5D +
  (k 
@@ -1521,16 +1521,28 @@
     ox =
+ origin%5B0%5D +
  3 + ox*
@@ -1589,16 +1589,28 @@
     oy =
+ origin%5B1%5D +
  3 + oy*

fix origin offset for boundary moving (center = 0)