package org.mwc.debrief.dis.listeners.impl;

import java.awt.Color;

import org.mwc.debrief.dis.listeners.IDISCollisionListener;

import Debrief.ReaderWriter.Replay.ImportReplay;
import Debrief.Wrappers.LabelWrapper;
import Debrief.Wrappers.NarrativeWrapper;
import MWC.GUI.BaseLayer;
import MWC.GUI.Layer;
import MWC.GUI.Plottable;
import MWC.GenericData.HiResDate;
import MWC.GenericData.WorldLocation;
import MWC.TacticalData.NarrativeEntry;

public class DebriefCollisionListener  extends DebriefCoreListener implements IDISCollisionListener
{

  final private String COLLISIONS_LAYER = "Collisions";

  public DebriefCollisionListener(IDISContext context)
  {
    super(context);
  }

  @Override
  public void add(final long time, final short eid, int movingId, final String movingName,
      int recipientId, final String recipientName, final double dLat, final double dLong, final double depthM)
  {
    final String message = "Collision between platform:" + movingName + " and " + recipientName;

    // and the narrative entry
    addNewItem(eid, ImportReplay.NARRATIVE_LAYER, new ListenerHelper()
    {

      @Override
      public Layer createLayer()
      {
        return new NarrativeWrapper(ImportReplay.NARRATIVE_LAYER);
      }

      @Override
      public Plottable createItem()
      {
        NarrativeEntry newE =
            new NarrativeEntry(movingName, "COLLISION", new HiResDate(time),
                message);
        Color theColor = colorFor(eid, movingName);
        newE.setColor(theColor);
        return newE;
      }
    });
    
    // create the text marker
    addNewItem(eid, COLLISIONS_LAYER, new ListenerHelper()
    {

      @Override
      public Layer createLayer()
      {
        Layer newB = new BaseLayer();
        newB.setName(COLLISIONS_LAYER);
        return newB;
      }

      @Override
      public Plottable createItem()
      {
        WorldLocation newLoc = new WorldLocation(dLat, dLong, depthM);
        Color theColor = colorFor(eid, movingName);
        return new LabelWrapper(message, newLoc, theColor);
      }
    });

    
    
  }

}

@@ -774,17 +774,20 @@
  String 
-m
+rawM
 ovingNam
@@ -826,16 +826,19 @@
 String r
+awR
 ecipient
@@ -903,24 +903,421 @@
 depthM)%0A  %7B%0A
+    final String recipientName;%0A    %0A    // special handling - and ID of -1 means the environment%0A    if(recipientId == -1)%0A    %7B%0A      recipientName = %22Environment%22;%0A    %7D%0A    else%0A    %7B%0A      recipientName = rawRecipientName;%0A    %7D%0A    %0A    final String movingName;%0A    if(movingId == -1)%0A    %7B%0A      movingName = %22Environment%22;%0A    %7D%0A    else%0A    %7B%0A      movingName = rawMovingName;%0A    %7D%0A    %0A
     final St

handle instance when environment is part of collision