예제 #1
0
 private static void displayPhoneBooks(ArrayList<String> phoneBooks)
     throws IOException, ParseException {
   if (phoneBooks.size() == 0) {
     System.out.println("\nNO PHONEBOOK AVAILABLE.CREATE A NEW PHONEBOOK.\n");
     return;
   } else {
     System.out.println("FOLLOWING ARE THE AVAILABLE PHONEBOOKS.");
     System.out.println("----------------------------------------\n");
     Scanner sc = new Scanner(System.in);
     for (int i = 0; i < phoneBooks.size(); i++) {
       String s = phoneBooks.get(i);
       System.out.println(s + "\t->PRESS " + (i + 1) + " LOAD THIS.");
     }
     System.out.println("TO GO BACK TO THE PREVIOUS MENU->PRESS " + (phoneBooks.size() + 1));
     int ch = 0;
     while (ch < 1 || ch > (phoneBooks.size() + 1)) {
       while (!sc.hasNextInt()) {
         System.out.println("\nONLY NUMBERS LISTED ABOVE SHOULD BE ENTERED..RETRY..");
         sc.nextLine();
       }
       ch = sc.nextInt();
       if (ch < 1 || ch > phoneBooks.size())
         System.out.println("\nONLY NUMBERS LISTED ABOVE SHOULD BE ENTERED..RETRY..");
     }
     if (ch == (phoneBooks.size() + 1)) return;
     contactBookOperations(phoneBooks.get(ch - 1) + ".txt");
   }
 }
    public void trace(float x, float y) {

      println(x);

      if (frameCounter > 2 && mousePressed) {
        coords.add(new PVector(x, y));
        frameCounter = 0;
        if (coordCounter > 0) {
          PVector tempCoord = (PVector) coords.get(coordCounter - 1);
          line(x, y, tempCoord.x, tempCoord.y);
        }
        coordCounter++;
      }
      // println(coordCounter);

      for (int i = 0; i < coords.size(); i++) {
        PVector tempCoordnear = (PVector) coords.get(i);
        float coordDist = dist(x, y, tempCoordnear.x, tempCoordnear.y);
        if (coordDist < distance) {
          stroke(255, 0, 0);
          line(x, y, tempCoordnear.x, tempCoordnear.y);
        }
      }
      frameCounter++;
    }
예제 #3
0
 public void drawOrbits(ArrayList alObjectsArchive) {
   //  println("SIZE:" + alObjectsArchive.size());
   //  ArrayList alObjectsArchive = timeline.getObjectStateArchive();
   ArrayList alPrevPos = new ArrayList();
   ArrayList alColors = new ArrayList();
   alColors.add(color(255, 0, 0));
   alColors.add(color(255, 255, 0));
   alColors.add(color(255, 0, 255));
   //  for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--)
   for (int i = 0; i < alObjectsArchive.size(); i++) {
     ArrayList objects = (ArrayList) alObjectsArchive.get(i);
     for (int j = 0; j < objects.size(); j++) {
       CelestialObject obj = (CelestialObject) objects.get(j);
       //      CelestialObject obj = (CelestialObject)objects.get(1);
       PVector pos = obj.getPosition();
       //      stroke(0, 0, 255);
       stroke((Integer) alColors.get(j));
       if (alPrevPos.size() == objects.size()) {
         PVector prevPos = (PVector) alPrevPos.get(j);
         line(prevPos.x, prevPos.y, pos.x, pos.y);
         alPrevPos.set(j, pos);
       } else alPrevPos.add(pos);
     }
   }
 }
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
  public void draw() {
    background(255);

    // Turn off highlighting for all obstalces
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.highlight(false);
    }

    // Act on all boids
    for (int i = 0; i < boids.size(); i++) {
      Boid b = (Boid) boids.get(i);
      b.avoid(obstacles);
      b.run();
    }

    // Display the obstacles
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.display();
    }

    // Instructions
    textFont(f);
    fill(0);
    text(
        "Hit space bar to toggle debugging lines.\nClick the mouse to generate a new boids.",
        10,
        height - 30);
  }
예제 #6
0
파일: Model.java 프로젝트: Jankish/GRAB
 private void extractInfo(File filename) {
   checkpoint = false;
   String line;
   try {
     ArrayList<String> order = new ArrayList<String>();
     BufferedReader input =
         new BufferedReader(new InputStreamReader(new FileInputStream(filename), "iso-8859-1"));
     while ((line = input.readLine()) != null) {
       if (line.equalsIgnoreCase("hämtas")) checkpoint = true;
       if (checkpoint) order.add(new String(line));
     }
     //	printList(order);
     int quant = Integer.parseInt(order.get(2));
     int rows = 9;
     int outer = (quant * rows);
     double price;
     double total;
     // DecimalFormat decimal = (DecimalFormat) format;
     Number number;
     for (int i = 4; i <= outer; i += 9) {
       Data d =
           new Data(
               order.get(i + 1),
               order.get(i + 3),
               order.get(i + 4),
               order.get(i + 5),
               order.get(i + 7));
       dataList.add(d);
       /*	try {
       System.out.println(order.get(i+5));
       number = format.parse(order.get(i+5));
       System.out.println("Number is " + number);
       price = number.doubleValue();
       System.out.println("Price is " + price);
       number = format.parse(order.get(i+7));
       total = number.doubleValue();
       Data d = new Data(order.get(i), Integer.parseInt(order.get(i+1)), Integer.parseInt(order.get(i+2)), order.get(i+3), order.get(i+4), price, total);
       dataList.add(d);
       } catch (ParseException numExcep) {
       numExcep.printStackTrace();
       System.exit(1);
       }
       **/
     }
     //	printDataList(dataList);
   } catch (FileNotFoundException found) {
     found.printStackTrace();
     System.exit(1);
   } catch (UnsupportedEncodingException encode) {
     encode.printStackTrace();
     System.exit(1);
   } catch (IOException ioexcep) {
     ioexcep.printStackTrace();
     System.exit(1);
   }
 }
예제 #7
0
  private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) {
    String s_List = "";
    ArrayList aSubFolders = new ArrayList();

    File file = new File(s_Dir);
    File[] filelist = file.listFiles();

    if (filelist != null && filelist.length > 0) {
      for (int i = 0; i < filelist.length; i++) {
        if (filelist[i].isDirectory()) {
          aSubFolders.add(filelist[i].getName());
        }
      }

      int n_Count = aSubFolders.size();
      String s_LastFlag = "";
      String s_Folder = "";
      for (int i = 1; i <= n_Count; i++) {
        if (i < n_Count) {
          s_LastFlag = "0";
        } else {
          s_LastFlag = "1";
        }

        s_Folder = aSubFolders.get(i - 1).toString();
        s_List =
            s_List
                + "arr"
                + s_Flag
                + "["
                + String.valueOf(n_TreeIndex)
                + "]=new Array(\""
                + s_Folder
                + "\","
                + String.valueOf(n_Indent)
                + ", "
                + s_LastFlag
                + ");\n";
        n_TreeIndex = n_TreeIndex + 1;
        ArrayList a_Temp =
            GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex);
        s_List = s_List + a_Temp.get(0).toString();
        n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue();
      }
    }

    ArrayList a_Return = new ArrayList();
    a_Return.add(s_List);
    a_Return.add(String.valueOf(n_TreeIndex));
    return a_Return;
  }
예제 #8
0
    public void calculateForces(ArrayList objects) {
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        ArrayList forces = obj.getForces();
        float totalForceX = 0;
        float totalForceY = 0;

        for (int j = 0; j < forces.size(); j++) {
          totalForceX += ((PVector) forces.get(j)).x;
          totalForceY += ((PVector) forces.get(j)).y;
        }

        PVector newAccel = new PVector(totalForceX / obj.getMass(), totalForceY / obj.getMass());

        obj.setAcceleration(newAccel);
      }

      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj1 = (CelestialObject) objects.get(i);
        float forceX = 0;
        float forceY = 0;
        obj1.clearForces();

        if (obj1.getClass() == Star.class) {
          println(obj1.getVelocity());
          continue;
        }

        for (int j = 0; j < objects.size(); j++) {
          CelestialObject obj2 = (CelestialObject) objects.get(j);

          if (i == j) continue;

          PVector pvDistance = PVector.sub(obj2.getPosition(), obj1.getPosition());
          //    println("distance: x:" + pvDistance.x + " y:" + pvDistance.y);
          float distance = sqrt(sq(pvDistance.y) + sq(pvDistance.x));
          float angle = degrees(atan2(pvDistance.y, pvDistance.x));

          float force = (G * obj1.getMass() * obj2.getMass()) / sq(distance);
          forceX = force * cos(radians(angle));
          forceY = force * sin(radians(angle));
          //        println("FORCES on " + obj1.getName() + ":" + forceX + "," + forceY);
          obj1.addForce(new PVector(forceX, forceY));

          println();
        }
      }
    }
  public void setup() {
    size(600, 400);
    smooth();
    f = createFont("Georgia", 12, true);

    obstacles = new ArrayList();
    boids = new ArrayList();

    // A little algorithm to pick a bunch of random obstacles that don't overlap
    for (int i = 0; i < 100; i++) {
      float x = random(width);
      float y = random(height);
      float r = random(50 - i / 2, 50);
      boolean ok = true;
      for (int j = 0; j < obstacles.size(); j++) {
        Obstacle o = (Obstacle) obstacles.get(j);
        if (dist(x, y, o.loc.x, o.loc.y) < o.radius + r + 20) {
          ok = false;
        }
      }
      if (ok) obstacles.add(new Obstacle(x, y, r));
    }

    // Starting with three boids
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.2f));
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.1f));
    boids.add(new Boid(new PVector(random(width), random(height)), 2f, 0.05f));
  }
예제 #10
0
  /**
   * 从表保存操作
   *
   * @param request 网页的请求对象
   * @param response 网页的响应对象
   * @return 返回HTML或javascipt的语句
   * @throws Exception 异常
   */
  private final void putDetailInfo(HttpServletRequest request) {
    RowMap rowInfo = getMasterRowinfo();
    // 保存网页的所有信息
    rowInfo.put(request);
    int rownum = d_RowInfos.size();
    RowMap detailRow = null;
    for (int i = 0; i < rownum; i++) {
      detailRow = (RowMap) d_RowInfos.get(i);
      detailRow.put("wzdjid", rowInfo.get("wzdjid_" + i));
      detailRow.put("dmsxid", rowInfo.get("dmsxid_" + i));
      detailRow.put("hssl", formatNumber(rowInfo.get("hssl_" + i), qtyFormat)); //
      detailRow.put("sl", formatNumber(rowInfo.get("sl_" + i), qtyFormat)); //

      detailRow.put("zk", formatNumber(rowInfo.get("zk_" + i), priceFormat)); //
      detailRow.put("dj", formatNumber(rowInfo.get("dj_" + i), priceFormat)); // 含税单价

      detailRow.put("xsje", formatNumber(rowInfo.get("xsje_" + i), sumFormat));
      detailRow.put("jje", formatNumber(rowInfo.get("jje_" + i), sumFormat)); // 无税单价
      detailRow.put("jzj", formatNumber(rowInfo.get("jzj_" + i), sumFormat)); // 基准价
      detailRow.put("cjtcl", formatNumber(rowInfo.get("cjtcl_" + i), sumFormat)); // 差价提成率
      detailRow.put("jxts", formatNumber(rowInfo.get("jxts_" + i), qtyFormat)); // 计息天数
      detailRow.put("hlts", formatNumber(rowInfo.get("hlts_" + i), qtyFormat)); // 回笼天数
      detailRow.put("hltcl", formatNumber(rowInfo.get("hltcl_" + i), sumFormat)); // 回笼提成率
      detailRow.put("bz", rowInfo.get("bz_" + i)); // 备注
      detailRow.put("jhrq", rowInfo.get("jhrq_" + i)); //
      detailRow.put("xsj", rowInfo.get("xsj_" + i)); //
      // 保存用户自定义的字段
      FieldInfo[] fields = detailProducer.getBakFieldCodes();
      for (int j = 0; j < fields.length; j++) {
        String fieldCode = fields[j].getFieldcode();
        detailRow.put(fieldCode, rowInfo.get(fieldCode + "_" + i));
      }
    }
  }
예제 #11
0
  // Executes the given action
  public void executeAction(Action a) {

    // For each state variable, retrieve the DD for it, evaluate it
    // w.r.t. the current state and build a new state.
    ArrayList new_state = new ArrayList();
    int c;
    for (c = 0; c < (_nVars << 1); c++) {
      new_state.add("-");
    }
    for (c = 0; c < (_nVars << 1); c++) {
      Object cur_assign = _state.get(c);
      if (cur_assign instanceof Boolean) {
        // System.out.println(a._tmID2DD);
        int nonprime_id = c + 1;
        int prime_id = nonprime_id - _nVars;
        Object DD = a._tmID2DD.get(new Integer(prime_id));
        _state.set(prime_id - 1, TRUE);
        double p_true = _mdp._context.evaluate(DD, _state);
        // System.out.println("ID: " + nonprime_id + ", " + prime_id + ": " +
        //		   _mdp._context.printNode(DD) + " -> " +
        //		   _mdp._df.format(p_true));
        new_state.set(c, (_r.nextFloat() < p_true) ? TRUE : FALSE);
      }
    }

    _state = new_state;
  }
예제 #12
0
파일: Model.java 프로젝트: Jankish/GRAB
 public void process(ArrayList<ListData> files) {
   for (int i = 0; i < files.size(); i++) {
     System.out.println("File " + (i + 1));
     dataList = new ArrayList<Data>();
     extractInfo(files.get(i).getFilePath());
     createExcel(files.get(i).getFileName());
   }
 }
예제 #13
0
    // Does a deepcopy of an array list
    public static ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        alNew.add(((CelestialObject) al.get(i)).clone());
      }

      return alNew;
    }
예제 #14
0
 public double getInvoiceTotal() {
   double invoiceTotal = 0.0;
   for (int i = 0; i < lineItems.size(); i++) {
     LineItem item = lineItems.get(i);
     invoiceTotal += item.getTotal();
   }
   return invoiceTotal;
 }
예제 #15
0
    // Does a deepcopy of an array list
    public ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        PVector pv = (PVector) al.get(i);
        alNew.add(new PVector(pv.x, pv.y));
      }

      return alNew;
    }
    public void avoid(ArrayList obstacles) {

      // Make a vector that will be the position of the object
      // relative to the Boid rotated in the direction of boid's velocity
      PVector closestRotated = new PVector(sight + 1, sight + 1);
      float closestDistance = 99999;
      Obstacle avoid = null;

      // Let's look at each obstacle
      for (int i = 0; i < obstacles.size(); i++) {
        Obstacle o = (Obstacle) obstacles.get(i);

        float d = PVector.dist(loc, o.loc);
        PVector dir = vel.get();
        dir.normalize();
        PVector diff = PVector.sub(o.loc, loc);

        // Now we use the dot product to rotate the vector that points from boid to obstacle
        // Velocity is the new x-axis
        PVector rotated = new PVector(diff.dot(dir), diff.dot(getNormal(dir)));

        // Is the obstacle in our path?
        if (PApplet.abs(rotated.y) < (o.radius + r)) {
          // Is it the closest obstacle?
          if ((rotated.x > 0) && (rotated.x < closestRotated.x)) {
            closestRotated = rotated;
            avoid = o;
          }
        }
      }

      // Can we actually see the closest one?
      if (PApplet.abs(closestRotated.x) < sight) {

        // The desired vector should point away from the obstacle
        // The closer to the obstacle, the more it should steer
        PVector desired =
            new PVector(closestRotated.x, -closestRotated.y * sight / closestRotated.x);
        desired.normalize();
        desired.mult(closestDistance);
        desired.limit(maxspeed);
        // Rotate back to the regular coordinate system
        rotateVector(desired, vel.heading2D());

        // Draw some debugging stuff
        if (debug) {
          stroke(0);
          line(loc.x, loc.y, loc.x + desired.x * 10, loc.y + desired.y * 10);
          avoid.highlight(true);
        }

        // Apply Reynolds steering rules
        desired.sub(vel);
        desired.limit(maxforce);
        acc.add(desired);
      }
    }
예제 #17
0
  public double evalBasisState(ArrayList state, double wb1, double wb2) {

    int sum_basis_1 = 0;
    int sum_basis_2 = 0;

    // TODO: Code to get connection links... use current state to get status
    // System.out.print(", Eval: " + state);
    Action a = (Action) _mdp._hmName2Action.get("noreboot");
    for (int c = 0; c < (_nVars << 1); c++) {
      Object cur_assign = state.get(c);
      if (cur_assign instanceof Boolean && ((Boolean) cur_assign).booleanValue()) {

        sum_basis_1++;

        // System.out.println(a._tmID2DD);
        int nonprime_id = c + 1;
        int prime_id = nonprime_id - _nVars;
        Object DD = a._tmID2DD.get(new Integer(prime_id));
        Set IDs = _mdp._context.getGIDs(DD);
        // System.out.print(IDs + ": ");
        Iterator it = IDs.iterator();
        // System.out.print("[" + prime_id + " - ");
        while (it.hasNext()) {
          int c_id = ((Integer) it.next()).intValue() - 1; // nonprime array index
          if (c_id < _nVars || c_id == c) { // Skip prime/np this var
            continue;
          }
          // System.out.print(c_id + " ");
          Object c_id_assign = state.get(c_id);
          if (c_id_assign instanceof Boolean && ((Boolean) c_id_assign).booleanValue()) {
            sum_basis_2++;
            break;
          }
        }
        // System.out.println("]");
      }
    }
    double val = wb1 * sum_basis_1 + wb2 * sum_basis_2;
    // System.out.println(state + ", b1: " + sum_basis_1 +
    //		   ", b2: " + sum_basis_2 + ", total: " +
    //		   _mdp._df.format(val));

    return val;
  }
예제 #18
0
 public void mouseClicked() {
   ArrayList objects = timeline.getStatefulObjects();
   for (int i = 0; i < objects.size(); i++) {
     CelestialObject obj = (CelestialObject) objects.get(i);
     if (obj.isMouseOver()) {
       println(obj.getName() + " clicked!");
       break;
     }
   }
 }
  public void draw() {

    background(255);

    for (int i = 0; i < balls.size(); i++) {
      Ball ball = (Ball) balls.get(i);
      ball.calc();
      ball.display();
    }
  }
예제 #20
0
  /** Update all of the Ball's and draw them */
  public void update() {

    if (balls.size() != 0) {

      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.update();
        b.attract = kelly;
        b.drawBall();
      }
    }
  }
예제 #21
0
  private static void generateKML(boolean isHighway) {
    System.out.println("generate link kml...");
    try {
      FileWriter fstream =
          new FileWriter(root + "/" + (isHighway ? highwayKmlFile : arterialKmlFile));
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("<kml><Document>");
      ArrayList<LinkInfo> linkList = isHighway ? highwayLinkList : arterialLinkList;
      for (int i = 0; i < linkList.size(); i++) {
        LinkInfo link = linkList.get(i);
        int linkId = link.getLinkId();
        int funcClass = link.getFuncClass();
        String streetName = link.getStreetName();
        if (streetName.contains("&")) streetName = streetName.replaceAll("&", " and ");
        ArrayList<PairInfo> nodeList = link.getNodeList();

        String kmlStr = "<Placemark><name>Link:" + linkId + "</name>";
        kmlStr += "<description>";
        kmlStr += "Class:" + funcClass + "\r\n";
        kmlStr += "Name:" + streetName + "\r\n";
        kmlStr += "</description>";
        kmlStr += "<LineString><tessellate>1</tessellate><coordinates>";
        for (int j = 0; j < nodeList.size(); j++) {
          PairInfo node = nodeList.get(j);
          kmlStr += node.getLongi() + "," + node.getLati() + ",0 ";
        }
        kmlStr += "</coordinates></LineString></Placemark>\n";

        out.write(kmlStr);
      }
      out.write("</Document></kml>");
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("generate link kml finish!");
  }
  public static void main(String[] args) {
    try {
      BufferedReader br = new BufferedReader(new FileReader(args[0]));
      int tIndex = 0;
      int pIndex = 0;

      // This will probably change soon (name and implementation)
      NgramParser tnp = new NgramParser(args[1]);

      ArrayList<String> triplet = tnp.getTriplet();
      ArrayList<String> polarity = tnp.getPolarity();

      FileWriter sw = new FileWriter(args[2]);
      String line = null;

      while (((line = br.readLine()) != null)
          && (tIndex < triplet.size())
          && (pIndex < polarity.size())) {
        if (line.matches("^[\\d]*:")) {
          // System.out.println(line);
          sw.write(line + "\n");
        } else {
          Scanner sc = new Scanner(line);
          String trip = sc.findInLine(Pattern.compile("[a-zA-Z]+#[a-z]+[#]?[0-9]*"));
          // if (trip != null && trip.equals(triplet.get(tIndex))) {
          System.out.println(trip);
          if (trip != null && !trip.toLowerCase().contains("no#cl")) {
            // System.out.println(triplet.get(tIndex) + ":" +polarity.get(pIndex));
            String pol = polarity.get(pIndex);
            sw.write(line + " " + pol + "\n");
            sc.close();
            tIndex++;
            pIndex++;
          } else {
            String pol = "neg";
            sw.write("no#a#1" + " " + pol + "\n");
            sc.close();
          }
        }

        // sw.flush();
      }

      sw.close();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public void draw() {
    // background(255);
    fill(255);
    rect(-4, -4, width + 4, height + 4);

    for (int i = skaters.size() - 1; i >= 0; i--) {

      Skater skater = (Skater) skaters.get(i);

      // if (mousePressed) {
      skater.trace(mouseX, mouseY); // blob[i].x etc.

      println(i);
    }
  }
예제 #24
0
  public void draw() {
    background(0);
    fill(255);

    if (!paused) timeline.moveForward();

    if (dragging) drawOrbits(timeline.getFutureObjectStates());
    else drawOrbits(timeline.getPastObjectStates());

    ArrayList objects = timeline.getStatefulObjects();
    for (int i = 0; i < objects.size(); i++) {
      CelestialObject obj = (CelestialObject) objects.get(i);
      obj.display();
    }
  }
예제 #25
0
  /** If a key is pressed perform the respective actions */
  public void keyPressed() {

    // Add 'stems' to the balls
    if (keyCode == SHIFT) {
      stems = !stems;
      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.STEM = stems;
      }
    }
    // toggle repaint background
    else if (key == 'b') REPAINT = !REPAINT;
    // Empty the ArrayList of Balls
    else if (key == 'x') balls.clear();
    // Add a ball
    else if (key == 'f') addBall();
  }
예제 #26
0
    public int moveBackward() {
      intTimeIdx--;

      if (intTimeIdx < 0) {
        intTimeIdx = 0;
      } else {
        //      println("before:" + ((CelestialObject)alStatefulObjects.get(0)).getPosition().x +
        // "," + ((CelestialObject)alStatefulObjects.get(0)).getPosition().y);
        setCurrentState(cloneArrayList((ArrayList) alObjectStateArchive.get(intTimeIdx)));
        //      println("before:" + ((CelestialObject)alStatefulObjects.get(0)).getPosition().x +
        // "," + ((CelestialObject)alStatefulObjects.get(0)).getPosition().y);
      }

      sliderTimeline.setValue(intTimeIdx);

      return intTimeIdx;
    }
예제 #27
0
    public int moveForward() {
      //    println("forward!");
      intTimeIdx++;

      // if the future values have already been calculated, just fetch them instead of calculating
      // them again
      if (alObjectStateArchive.size() > intTimeIdx)
        setCurrentState(cloneArrayList((ArrayList) alObjectStateArchive.get(intTimeIdx)));
      else {
        //      println("calculating...");
        sim.calculateForces(alStatefulObjects);
        alObjectStateArchive.add(cloneArrayList(alStatefulObjects));
      }

      sliderTimeline.setValue(intTimeIdx);

      return intTimeIdx;
    }
예제 #28
0
 public void run() {
   System.out.println("ReminderServiceOld: Starting at " + new Date());
   while (!l.isEmpty()) {
     Date d = new Date();
     Item i = (Item) l.get(0);
     long interval = i.due.getTime() - d.getTime();
     if (interval > 0) {
       System.out.println("Sleeping until " + i.due);
       try {
         Thread.sleep(interval);
       } catch (InterruptedException e) {
         System.exit(1); // unexpected intr
       }
       message(i.due + ": " + i.message);
     } else message("MISSED " + i.message + " at " + i.due);
     l.remove(0);
   }
   System.exit(0);
 }
예제 #29
0
  public void mouseDragged() {
    if (paused) {
      ArrayList objects = timeline.getStatefulObjects();
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        if (obj.isMouseOver()) {
          dragging = true;
          PVector pos = obj.getPosition();
          pos.x = mouseX;
          pos.y = mouseY;

          timeline.reset();
          timeline.setCurrentState(objects);
          sliderTimeline.setValue(0);
          break;
        }
      }
    }
  }
예제 #30
0
  /**
   * Add the given file name to the list of recent files in the given Properties object, trimming
   * the length of the list to 10. If the given name is already in the list, move it to the top.
   */
  public static void addRecentFile(Properties preferences, String newName) {

    // - if newName isn't already in the list, we add it to the top of the list.
    // - if it's already in the list, we move it to the top.
    ArrayList<String> list = MiscUtilities.parseRecentFiles(preferences);
    if (list.contains(newName)) {
      // move it to the top :
      list.remove(newName);
      list.add(0, newName);
    } else {
      list.add(0, newName);
    }
    // store to preferences :
    for (int i = 0; i < MAX_RECENT_FILES && i < list.size(); i++) {
      String key = KEY_RECENT_FILE + "." + Integer.toString(i + 1); // starts from 1
      String val = list.get(i);
      preferences.setProperty(key, val);
    }
  }