package etomica.graphics;

import java.awt.Color;

import etomica.api.IAtom;
import etomica.api.IAtomList;
import etomica.api.IBox;
import etomica.api.ISimulation;
import etomica.nbr.cell.Api1ACell;
import etomica.nbr.list.PotentialMasterList;

public class ColorSchemeNeighbor extends ColorSchemeCollectiveAgent {
    
    public ColorSchemeNeighbor(ISimulation sim, PotentialMasterList potentialMaster, IBox box, int dim) {
        super(box);
        typeColorScheme = new ColorSchemeByType(sim);
        leafList = box.getLeafList();
        nbrIterator = new Api1ACell(dim, 1.0, potentialMaster.getCellAgentManager());
        nbrIterator.setDirection(null);
        nbrIterator.setBox(box);
    }
    
    public void colorAllAtoms() {
		//color all atoms according to their type
        int nLeaf = leafList.getAtomCount();
        for (int iLeaf=0; iLeaf<nLeaf; iLeaf++) {
            IAtom atom = leafList.getAtom(iLeaf);
            agentManager.setAgent(atom, typeColorScheme.getAtomColor(atom));
        }
        if (referenceAtom == null) {
            return;
        }
        //color blue the neighbor atoms in same group
        nbrIterator.reset();
        for (IAtomList pair = nbrIterator.next(); pair != null;
             pair = nbrIterator.next()) {
            IAtom atom = pair.getAtom(1);
            if(atom.getType() == referenceAtom.getType()) {
                agentManager.setAgent(atom, Color.blue);
            } else {
                agentManager.setAgent(atom, Color.yellow);
            }
        }
        //color green the target atom 
        agentManager.setAgent(referenceAtom, Color.green);
    }
    
    public void setAtom(IAtom a) {
        referenceAtom = a;
        nbrIterator.setTarget(a);
    }

    public IAtom getAtom() {
        return referenceAtom;
    }
    
    private static final long serialVersionUID = 1L;
    private IAtom referenceAtom;
    private final Api1ACell nbrIterator;
    private final IAtomList leafList;
    private final ColorSchemeByType typeColorScheme;
}
@@ -180,22 +180,32 @@
 nbr.
-cell.Api1ACell
+list.NeighborListManager
 ;%0Aim
@@ -248,16 +248,115 @@
 rList;%0A%0A
+/**%0A * Color atoms based on being neighbors of the reference atom%0A *%0A * @author Andrew Schultz%0A */%0A
 public c
@@ -653,151 +653,59 @@
    n
-brIterator = new Api1ACell(dim, 1.0, potentialMaster.getCellAgentManager());%0A        nbrIterator.setDirection(null);%0A        nbrIterator.setBox
+eighborManager = potentialMaster.getNeighborManager
 (box
@@ -1161,131 +1161,323 @@
     
-nbrIterator.reset();%0A        for (IAtomList pair = nbrIterator.next(); pair != null;%0A             pair = nbrIterator.next()
+IAtomList%5B%5D list = neighborManager.getDownList(referenceAtom);%0A        for (int foo=0; foo%3C2; foo++) %7B%0A            if (foo==1) %7B%0A                list = neighborManager.getUpList(referenceAtom);%0A            %7D%0A            for (int i=0; i%3Clist.length; i++) %7B%0A                for (int j=0; j%3Clist%5Bi%5D.getAtomCount(); j++
 ) %7B%0A
@@ -1480,32 +1480,40 @@
 ) %7B%0A            
+        
 IAtom atom = pai
@@ -1513,12 +1513,15 @@
 m = 
-pair
+list%5Bi%5D
 .get
@@ -1525,17 +1525,17 @@
 getAtom(
-1
+j
 );%0A     
@@ -1541,16 +1541,24 @@
         
+    
+    
 if(atom.
@@ -1593,24 +1593,32 @@
 etType()) %7B%0A
+        
             
@@ -1674,16 +1674,24 @@
         
+        
 %7D else %7B
@@ -1699,32 +1699,40 @@
                 
+   
+     
 agentManager.set
@@ -1758,16 +1758,56 @@
 ellow);%0A
+                    %7D%0A                %7D%0A
         
@@ -1997,42 +1997,8 @@
  a;%0A
-        nbrIterator.setTarget(a);%0A
     
@@ -2178,28 +2178,42 @@
 nal 
-Api1ACell nbrIterato
+NeighborListManager neighborManage
 r;%0A 

fix Neighbor to actually look at neighbors