Exemplo n.º 1
0
 public MyCanvas(int width, int height) {
   isReplay = false;
   isRender = true;
   ct = Controller.getInstance();
   experimentParmTab = ExperimentParameterTab.getInstance();
   canvasWidth = width;
   canvasHeight = height;
   setPreferredSize(new Dimension(canvasWidth, canvasHeight));
 }
Exemplo n.º 2
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    /*
    	if(agentManager.getAgentListDirty()) {
    		ArrayList<Agent> agentList = new ArrayList<Agent>();
    		agentList.addAll(agentManager.getAgentList());
    		agentManager.setAgentListDirty(false);
    	}
    */

    if (isRender) {
      gridManager.paintAllGrids(g2);
      agentManager.paintAllAgents(g2);
      obManager.paintAllObstacles(g2);

      if (dragPoint != null && groupManager.isDrawTemplate()) {
        groupManager.paintGroupTemplate(dragPoint, ct.getDiameterTFieldValue(), g2);
      }

      goalManager.paintAllGoals(g2);

      /** ********************** for drawing infoBoard ********************** */
      if (selectedAgent != null) {
        selectedAgent.paint(g2);
      }
    }

    g2.setFont(font);
    g2.setColor(Color.blue);
    g2.drawString(String.valueOf(frameCounter), 10, canvasHeight - 10);

    if (isShowText) {
      g2.setColor(Color.BLACK);

      int x_Leaver = canvasWidth - 150;
      int y_Leaver = 20;

      int x_Victim = x_Leaver;
      int y_Victim = y_Leaver + 30;

      int xMargin = 60;
      int xRange = 30;

      g2.drawString("Victims:", x_Leaver, y_Leaver);
      g2.drawString("Leavers:", x_Victim, y_Victim);

      int v[] = AgentManager.partyInfo[AgentManager.VICTIM_INFO];
      int l[] = AgentManager.partyInfo[AgentManager.LEAVER_INFO];

      int cnt = 0;
      boolean flag;

      for (int i = 0; i < v.length; i++) {
        flag = false;

        if (v[i] != 0) {
          flag = true;
          g2.setColor(AgentTab.COLOR_ARRAY[i]);
          g2.drawString(String.valueOf(v[i]), x_Leaver + xMargin + cnt * xRange, y_Leaver);
        }

        if (l[i] != 0) {
          flag = true;
          g2.setColor(AgentTab.COLOR_ARRAY[i]);
          g2.drawString(String.valueOf(l[i]), x_Victim + xMargin + cnt * xRange, y_Victim);
        }

        if (flag == true) cnt++;
      }
    }

    //		float frameRate = frameCounter
    // graph.drawEdges(g2);
  }