Beispiel #1
0
 /** Return the first object on the free list or null if none. */
 public FactoryObject getFree() {
   Head head = getHead();
   FactoryObject obj = head.next;
   if (obj != null) {
     head.next = obj.next();
     obj.next(null);
   }
   return obj;
 }
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   bg.paintIcon(this, g2, 0, 0);
   TreeMap<Integer, FactoryObject> to = (TreeMap<Integer, FactoryObject>) fos.clone();
   for (Integer i : to.keySet()) {
     FactoryObject t = to.get(i);
     if (t.getIsLine()) {
       g2.setColor(Color.WHITE);
       g2.drawLine(t.getPositionX(), t.getPositionY(), t.getPositionXF(), t.getPositionYF());
     } else {
       if (t.getImageIndex() >= 0) {
         ImageIcon tmp = images.getIcon(t.getImageIndex());
         tmp.paintIcon(this, g2, t.getPositionX(), t.getPositionY());
       }
     }
   }
 }
  public void update(double deltaTime) {

    totalTime += deltaTime;
    if (isDone) {
      return;
    }
    // Update all the objects in the factor that need updating each tick
    for (FactoryObject object : mFWorkers) object.update(deltaTime);

    if (mTaskBoard.isDone()) {
      isDone = true;
      Timestamp timestamp = new Timestamp(System.currentTimeMillis());
      String outFileName = "reports/" + timestamp;
      outFileName = outFileName.replaceAll("[-:.]", "_");
      File file = null;
      FileWriter fw = null;
      try {
        file = new File(outFileName);
        file.createNewFile();
        fw = new FileWriter(outFileName, true);
        for (FactoryObject object : mFObjects) {
          if (object instanceof FactoryReporter) {
            ((FactoryReporter) object).report(fw);
          }
        }
      } catch (IOException e) {
        System.out.println("Error occured during file write: " + outFileName);
        if (file != null) file.delete();
      } finally {
        if (fw != null) {
          try {
            fw.close();
          } catch (IOException e) {
            System.out.println("Error: failed to close FileWriter");
          }
        }

        DecimalFormat threePlaces = new DecimalFormat(".###");
        JOptionPane.showMessageDialog(
            null,
            "Total time: " + threePlaces.format(totalTime) + "s",
            "Simulation Over!",
            JOptionPane.INFORMATION_MESSAGE);
      }
    }
  }
Beispiel #4
0
 /** Add an object to the free list. */
 public void setFree(FactoryObject obj) {
   Head head = getHead();
   obj.next(head.next);
   head.next = obj;
 }