Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

selectionGrid finished for the P2PAgent

  • Loading branch information...
commit e60b6b14aa1a60427ab1d469fc9a175dfc83417b 1 parent 6dae896
Guillaume authored
View
8 src/P2PAgent/EnvironmentP2P.java
@@ -1,8 +1,12 @@
package P2PAgent;
+import java.util.ArrayList;
+
+import graphics.AbstractGridViewerWhitoutLocation;
import logging.Logger;
import scenario.P2PScenario;
import KCAAgent.KCAAgent;
+import agent.AbstractAgent;
import agent.AgentID;
import agent.Location;
import base.Environment;
@@ -16,7 +20,7 @@ public EnvironmentP2P(SimulationP2P parent, P2PScenario scenario)
{
this.parent=parent;
logger = new Logger();
-
+ selected = new ArrayList<AbstractAgent>();
agents= scenario.getAgents();
this.x=0;
this.y=0;
@@ -64,7 +68,7 @@ public P2PAgent cellAt(double x, double y)
P2PAgent res = null;
double minDist = Double.POSITIVE_INFINITY;
for (P2PAgent cell : agents.values()) {
- double dist = loc.getDistance(new Location(cell.getId().id.doubleValue(),cell.getId().id.doubleValue()));
+ double dist = loc.getDistance(AbstractGridViewerWhitoutLocation.getLocationOnTheGrid().get(cell));
if (dist < minDist) {
minDist = dist;
res = cell;
View
2  src/P2PAgent/P2PAgent.java
@@ -66,7 +66,7 @@ public P2PAgent(EnvironmentP2P parent, AgentID id) {
this.waitingMessage = new ArrayList<MessageP2P<?>>();
this.parent = parent;
this.log = new Log(this);
- this.selected=true;
+ this.selected=false;
if (directory == null) {
directory = new HashMap<AgentID, P2PAgent>();
View
7 src/P2PAgent/SimulationP2P.java
@@ -83,12 +83,6 @@ public SimulationP2P()
viewers = ViewerFactoryP2P.createViewers(environment, layout.toCollection());
environment.check();
- Iterator<P2PAgent> test=environment.getAgents().iterator();
- while(test.hasNext())
- {
- P2PAgent agent= test.next();
- agent.toggleSelected();
- }
init2();
}
@@ -118,7 +112,6 @@ private void init2()
for(ControllableView<EnvironmentP2P> viewer : viewers)
if(viewer != null)
viewer.relink(environment);
-
environment.doUpdate();
}
View
4 src/base/Environment.java
@@ -46,12 +46,12 @@ public void step() throws Exception {
public void addSelected(AbstractAgent agent) {
selected.add(agent);
-// logger.addLog(agent.getLog());
+ logger.addLog(agent.getLog());
}
public void removeSelected(AbstractAgent agent) {
selected.remove(agent);
-// logger.removeLog(agent.getLog());
+ logger.removeLog(agent.getLog());
}
public List<AbstractAgent> getSelected() {
View
24 src/graphics/AbstractGridViewerWhitoutLocation.java
@@ -4,25 +4,31 @@
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
+import java.util.HashMap;
+import java.util.Map;
import agent.AbstractAgent;
-import agent.LocationAgent;
import base.Environment;
+import agent.Location;
public abstract class AbstractGridViewerWhitoutLocation<ENVIRONMENT extends Environment<?,?>> extends AbstractViewer2D<ENVIRONMENT> implements MouseListener {
int w;
int h;
+ private static Map<AbstractAgent, Location> LocationOnTheGrid;
+
protected AbstractGridViewerWhitoutLocation(ENVIRONMENT cm, Object data)
{
super(cm, data);
setSize(120, 150);
+ LocationOnTheGrid = new HashMap<AbstractAgent, Location>();
addMouseListener(this);
+
}
protected AbstractGridViewerWhitoutLocation(ENVIRONMENT cm)
{
- super(cm,null);
+ this(cm,null);
}
public abstract Color getColor(AbstractAgent cell);
@@ -40,16 +46,19 @@ protected void draw(Graphics2D g)
g.clearRect(0, 0, w, h);
int nbRow=0;
int nbCol=0;
+ int number=5;
for (AbstractAgent cell : cm.getAgents()) {
- if((nbRow+1/5)*cm.getAgents().size()<cell.getId().id.intValue())
+ if((cell.getId().id.intValue())/number==1)
{
nbRow++;
nbCol=0;
+ number=number+5;
}
double x = (nbRow - cm.x) * w / cm.width;
double y = (nbCol - cm.y) * h / cm.height;
- System.out.println(x+" "+y);
+ //System.out.println(x+" "+y);
nbCol++;
+ LocationOnTheGrid.put(cell, new Location(nbRow, nbCol));
Color color = getColor(cell);
g.setColor(color);
g.fillRect((int)x, (int)y, (int)dw, (int)dh);
@@ -103,7 +112,12 @@ public void mousePressed(MouseEvent arg0)
public void mouseReleased(MouseEvent arg0)
{
// TODO Auto-generated method stub
-
+
+ }
+
+ public static Map<AbstractAgent, Location> getLocationOnTheGrid()
+ {
+ return LocationOnTheGrid;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.