/**
*
*/
package cu.repsystestbed.gui;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Set;
import javax.swing.JTextArea;
import com.mxgraph.model.mxCell;
import cu.repsystestbed.entities.Agent;
import cu.repsystestbed.graphs.FeedbackHistoryGraphEdge;
import cu.repsystestbed.graphs.ReputationEdge;
import cu.repsystestbed.graphs.TestbedEdge;
import cu.repsystestbed.util.Util;
import cu.repsystestbed.view.JGraphXView;
/**
* @author partheinstein
* This class has classes to deal with mouse events on a jgraphx
*
*/
public class GraphMouseAdapter extends MouseAdapter
{
private JGraphXView m_viewer;
JTextArea m_infoTextBox;
public GraphMouseAdapter(JGraphXView viewer, JTextArea infoTextBox)
{
m_viewer = viewer;
m_infoTextBox = infoTextBox;
}
public void mouseReleased(MouseEvent event)
{
mxCell cell = (mxCell) m_viewer.m_graphComponent.getCellAt(event.getX(), event.getY());
if (cell != null)
{
System.out.println("cell: " + m_viewer.m_graph.getLabel(cell));
if(event.getButton() == MouseEvent.BUTTON3)
{
if(cell.isVertex())
{
System.out.println(cell.getValue());
String display = null;
display = "Agent: " + cell.getValue();
String agentIdString = (String) cell.getValue();
try
{
int agentId = new Integer(agentIdString);
Util.assertNotNull(m_viewer.m_graphModel);
Set<TestbedEdge> edges = m_viewer.m_graphModel.incomingEdgesOf(new Agent(agentId));
Util.assertNotNull(edges);
if(edges.size() > 0)
{
display += "\n" + "Incoming Edges:" + "\n";
}
for(TestbedEdge e : edges)
{
display += e.src + "\n";
if(e instanceof FeedbackHistoryGraphEdge)
{
FeedbackHistoryGraphEdge fhe = (FeedbackHistoryGraphEdge) e;
display += "Feedbacks: " + fhe.toString3() + "\n";
}
else if(e instanceof ReputationEdge)
{
ReputationEdge re = (ReputationEdge) e;
display += "Reputation: " + re.getReputation() + "\n";
}
}
display += "--";
edges = m_viewer.m_graphModel.outgoingEdgesOf(new Agent(agentId));
Util.assertNotNull(edges);
if(edges.size() > 0)
{
display += "\n" + "Outgoing Edges:" + "\n";
}
for(TestbedEdge e : edges)
{
display += e.sink + "\n";
if(e instanceof FeedbackHistoryGraphEdge)
{
FeedbackHistoryGraphEdge fhe = (FeedbackHistoryGraphEdge) e;
display += "Feedbacks: " + fhe.toString3() + "\n";
}
else if(e instanceof ReputationEdge)
{
ReputationEdge re = (ReputationEdge) e;
display += "Reputation: " + re.getReputation() + "\n";
}
}
m_infoTextBox.setText(display);
}catch(Exception e)
{
e.printStackTrace();
}
}
}
}
}
}