コード例 #1
0
 private void drawerAnimation() {
   Timeline animation;
   if (drawerOpened) {
     toggleLayer.setVisible(true);
     animation =
         new Timeline(
             new KeyFrame(
                 DEFAULT_TIME_ANIM,
                 new KeyValue(nav.translateXProperty(), 0, Interpolator.EASE_OUT),
                 new KeyValue(toggleLayer.opacityProperty(), 0.3)));
   } else {
     animation =
         new Timeline(
             new KeyFrame(
                 DEFAULT_TIME_ANIM,
                 new KeyValue(nav.translateXProperty(), -DEFAULT_WIDTH_NAV, Interpolator.EASE_IN),
                 new KeyValue(toggleLayer.opacityProperty(), 0)));
     animation.setOnFinished(
         evt -> {
           toggleLayer.setOpacity(0);
           toggleLayer.setVisible(false);
         });
   }
   animation.play();
 }
コード例 #2
0
ファイル: Clock.java プロジェクト: ArfaaShariff/javafx-gradle
  public void play() {
    // wait till start of next second then start a timeline to call refreshClocks() every second
    delayTimeline = new Timeline();
    delayTimeline
        .getKeyFrames()
        .add(
            new KeyFrame(
                new Duration(1000 - (System.currentTimeMillis() % 1000)),
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                    if (secondTimeline != null) {
                      secondTimeline.stop();
                    }
                    secondTimeline = new Timeline();
                    secondTimeline.setCycleCount(Timeline.INDEFINITE);
                    secondTimeline
                        .getKeyFrames()
                        .add(
                            new KeyFrame(
                                Duration.seconds(1),
                                new EventHandler<ActionEvent>() {

                                  @Override
                                  public void handle(ActionEvent event) {
                                    refreshClocks();
                                  }
                                }));
                    secondTimeline.play();
                  }
                }));
    delayTimeline.play();
  }
コード例 #3
0
ファイル: FinalGame.java プロジェクト: NihalPandit/Work
  public void gameTimer() {

    if (level == 1) {
      timer = 1000;
    } else if (level == 2) {
      timer = 900;
    } else if (level == 3) {
      timer = 800;
    } else if (level == 4) {
      timer = 700;
    } else if (level == 5) {
      timer = 600;
    } else if (level == 6) {
      timer = 500;
    } else if (level == 7) {
      timer = 400;
    } else if (level == 8) {
      timer = 300;
    } else if (level == 9) {
      timer = 200;
    } else if (level == 10) {
      timer = 100;
    }

    timeline = new Timeline(new KeyFrame(Duration.millis(1000), e -> timer()));
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();
  }
コード例 #4
0
  private void runProcessingAnimation(double duration) {
    timeline.setAutoReverse(true);
    timeline.setCycleCount(2);

    //        transitionRect = new TranslateTransition(Duration.millis(duration), rectangle);
    //        transitionCircle = new TranslateTransition(Duration.millis(duration), circle);
    transitionCircle.setDuration(Duration.millis(duration));
    transitionCircle.setNode(circle);
    transitionCircle.setAutoReverse(false);
    transitionCircle.setByX(150);
    transitionCircle.setFromX(0);

    transitionRect.setAutoReverse(false);
    transitionRect.setDuration(Duration.millis(duration));
    transitionRect.setNode(rectangle);
    transitionRect.setByX(150);
    transitionRect.setFromX(0);

    KeyValue keyValue = new KeyValue(imageViewTop.translateYProperty(), 90);
    KeyFrame keyFrame =
        new KeyFrame(
            Duration.millis(duration),
            (ActionEvent) -> {
              toggleHide(rectangle);
              transitionRect.play();
              transitionCircle.play();
              stackProducts(rectangle, imageViewRightStorage, this);
            },
            keyValue);

    timeline.getKeyFrames().clear();
    timeline.getKeyFrames().add(keyFrame);
    timeline.play();
  }
コード例 #5
0
  @Ignore // RT-26710: javafx.scene.web.LeakTest hangs
  @Test
  public void testOleg() throws InterruptedException {
    final String URL =
        new File("src/test/resources/html/guimark2-vector.html").toURI().toASCIIString();
    final int CYCLE_COUNT = 16;
    final int CYCLE_LENGTH = 5;
    final CountDownLatch latch = new CountDownLatch(CYCLE_COUNT);

    Timeline time = new Timeline();
    time.setCycleCount(CYCLE_LENGTH * CYCLE_COUNT);
    time.getKeyFrames()
        .add(
            new KeyFrame(
                Duration.millis(1000),
                new EventHandler<ActionEvent>() {
                  int counter = -1;

                  @Override
                  public void handle(final ActionEvent e) {
                    ++counter;
                    if (counter == 0) {
                      WebEngine engine = new WebEngine();
                      engine.load(URL);
                    } else if (counter == CYCLE_LENGTH - 1) {
                      counter = -1;
                      latch.countDown();
                    }
                  }
                }));
    time.play();
    latch.await();
  }
コード例 #6
0
ファイル: TagTweets.java プロジェクト: siggi12/TweetwallFX
 private Timeline fadeIn(Text word) {
   word.setOpacity(0.1);
   Timeline timeline = new Timeline();
   KeyFrame key =
       new KeyFrame(
           Duration.millis(1000), new KeyValue(word.opacityProperty(), 1, Interpolator.EASE_IN));
   timeline.getKeyFrames().add(key);
   return timeline;
 }
コード例 #7
0
ファイル: Main.java プロジェクト: tommykw/JavaFXSandbox
  @Override
  public void start(Stage primaryStage) throws Exception {
    Group root = new Group();
    Group circles = new Group();
    for (int i = 0; i < 30; i++) {
      Circle circle = new Circle(150, Color.web("white", 0.05));
      circle.setStrokeType(StrokeType.OUTSIDE);
      circle.setStroke(Color.web("white", 0.16));
      circle.setStrokeWidth(4);
      circles.getChildren().add(circle);
    }
    root.getChildren().add(circles);
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    Rectangle colors =
        new Rectangle(
            scene.getWidth(),
            scene.getHeight(),
            new LinearGradient(
                0f,
                1f,
                1f,
                0f,
                true,
                CycleMethod.NO_CYCLE,
                new Stop[] {
                  new Stop(0, Color.web("#f8bd55")),
                  new Stop(0.14, Color.web("#c0fe56")),
                  new Stop(0.28, Color.web("#5dfbc1")),
                  new Stop(0.43, Color.web("#64c2f8")),
                  new Stop(0.57, Color.web("#be4af7")),
                  new Stop(0.71, Color.web("#ed5fc2")),
                  new Stop(0.85, Color.web("#ef504c")),
                  new Stop(1, Color.web("#f2660f")),
                }));
    colors.widthProperty().bind(scene.widthProperty());
    colors.heightProperty().bind(scene.heightProperty());
    root.getChildren().add(colors);

    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
      timeline
          .getKeyFrames()
          .addAll(
              new KeyFrame(
                  Duration.ZERO, // set start position at 0
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)),
              new KeyFrame(
                  new Duration(40000), // set end position at 40s
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)));
    }
    timeline.play();
    primaryStage.setScene(scene);
    primaryStage.show();
  }
コード例 #8
0
ファイル: Watch.java プロジェクト: zxiaofan/JDK
 private void configureTimeline() {
   time.setCycleCount(Timeline.INDEFINITE);
   KeyFrame keyFrame =
       new KeyFrame(
           Duration.millis(47),
           (ActionEvent event) -> {
             calculate();
           });
   time.getKeyFrames().add(keyFrame);
 }
コード例 #9
0
 public void startStop() {
   if (time.getStatus() != Status.STOPPED) {
     // if started, stop it
     time.stop();
     lastClockTime = 0;
   } else {
     // if stopped, restart
     time.play();
   }
 }
コード例 #10
0
ファイル: Piczke.java プロジェクト: codingSloth/walkingPiczke
  @Override
  public void start(Stage stage) {
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.setAlwaysOnTop(true);
    VBox box = new VBox();
    imageView = new ImageView(sprites[currentFrame]);

    box.getChildren().add(imageView);
    final Scene scene = new Scene(box, 0, 0);
    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    stage.setX(currentX);
    stage.setY(currentY);
    scene.setFill(null);
    stage.setScene(scene);
    mainLoop = new Timeline();
    mainLoop.setCycleCount(Animation.INDEFINITE);
    renderFrame =
        new KeyFrame(
            frameDuration,
            new EventHandler<ActionEvent>() {
              public void handle(ActionEvent event) {
                Double currentFrameWidth = sprites[currentFrame].getWidth();
                Double currentFrameHeight = sprites[currentFrame].getHeight();
                stage.setWidth(currentFrameWidth);
                stage.setHeight(currentFrameHeight);
                currentY = screenBounds.getMinY() + screenBounds.getHeight() - currentFrameHeight;

                Double minLimitX = 0.0;
                Double maxLimitX =
                    screenBounds.getMinX() + screenBounds.getWidth() - currentFrameWidth;
                if (currentX >= maxLimitX || currentX <= minLimitX) {
                  velocity = -1 * velocity;
                  currentX = currentX >= maxLimitX ? maxLimitX - 1 : minLimitX + 1;
                  currentWalkingFrame = 0;
                } else {
                  currentX += velocity;
                }

                if (velocity > 0) {
                  currentFrame = walking_right_indexes[currentWalkingFrame];
                } else {
                  currentFrame = walking_left_indexes[currentWalkingFrame];
                }

                stage.setX(currentX);
                stage.setY(currentY);
                imageView.setImage(sprites[currentFrame]);
                currentWalkingFrame = (++currentWalkingFrame) % walking_right_indexes.length;
              }
            });
    mainLoop.getKeyFrames().add(renderFrame);
    stage.show();
    mainLoop.play();
  }
コード例 #11
0
  void animateRoute(List<Path> path, Circle entranceMarker, GraphicsContext gc) {
    double entranceX = entranceMarker.getCenterX();
    double entranceY = entranceMarker.getCenterY();

    int currentKeyFrameTimeInMs = 0, keyframeTimeInMs = 50;

    List<KeyFrame> keyFrames = new ArrayList<>();
    List<AnimationTimer> timers = new ArrayList<>();

    for (int i = 0; i < path.size(); i++) {
      Path pathEntry = path.get(i);
      DoubleProperty opacity = new SimpleDoubleProperty();
      keyFrames.add(
          new KeyFrame(Duration.millis(currentKeyFrameTimeInMs), new KeyValue(opacity, 0)));
      keyFrames.add(
          new KeyFrame(
              Duration.millis(currentKeyFrameTimeInMs + keyframeTimeInMs),
              new KeyValue(opacity, 0.3)));

      timeline.setAutoReverse(true);
      timeline.setCycleCount(1);

      currentKeyFrameTimeInMs += keyframeTimeInMs;

      timers.add(
          new AnimationTimer() {
            @Override
            public void handle(long now) {
              gc.setFill(Color.FORESTGREEN.deriveColor(0, 1, 1, opacity.get()));
              if (maze.representation().length > 24) {
                gc.fillRect(
                    entranceX + calculateNextPosX(pathEntry.x, 2) - 20,
                    entranceY + calculateNextPosY(pathEntry.y, 2) - 176,
                    CELL_LENGTH,
                    CELL_LENGTH);
              } else {
                gc.fillRect(
                    entranceX + calculateNextPosX(pathEntry.x, 5) - 23,
                    entranceY + calculateNextPosY(pathEntry.y, 5) - 178,
                    CELL_LENGTH,
                    CELL_LENGTH);
              }
            }
          });
    }

    timeline.getKeyFrames().addAll(keyFrames);

    for (int i = 0; i < path.size(); i++) {
      timers.get(i).start();
    }
    timeline.play();
  }
コード例 #12
0
  @Override
  public void start(Stage stage) throws Exception {
    game = GameImpl.INSTANCE;

    LocalEndpoint.client = this;

    final BorderPane root = new BorderPane();
    root.setStyle("-fx-padding: 20");
    //		root.setCenter(rows);

    Timeline fiveSecondsWonder =
        new Timeline(
            new KeyFrame(
                Duration.seconds(1),
                new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {

                    final Sprite[][] grille = game.getGrille();
                    // *
                    //						final Sprite[][] grille = new Sprite[][] {
                    //								{ Sprite.MUR, Sprite.SOL, Sprite.FANTOME },
                    //								{ Sprite.MUR, Sprite.SOL, Sprite.FANTOME },
                    //								{ Sprite.MUR, Sprite.SOL, Sprite.FANTOME } };
                    // */
                    if (grille.length == 0) {
                      System.out.println("Grille vide");
                    } else {
                      System.out.println(
                          "Grille de taille : (" + grille.length + " x " + grille[0].length + ")");
                    }
                    VBox rows = prepareBoard(grille);

                    root.setCenter(rows);
                  }
                }));
    fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
    fiveSecondsWonder.play();

    Scene scene = new Scene(root);
    scene.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent event) {
            System.out.println(
                "AmiEnnemisClient.start(...).new EventHandler() {...}.handle()" + event.getCode());
            doMove(event);
          }
        });
    stage.setScene(scene);
    stage.show();
  }
コード例 #13
0
 public void stopReset() {
   if (time.getStatus() != Status.STOPPED) {
     // if started, stop it
     time.stop();
     lastClockTime = 0;
   } else {
     // if stopped, reset it
     lastClockTime = 0;
     elapsedMillis = 0;
     refreshTimeDisplay(0, 0, 0);
   }
 }
コード例 #14
0
ファイル: FinalGame.java プロジェクト: NihalPandit/Work
 private void stopGame() {
   timeline.pause();
   done = true;
   sp.setOnMouseClicked(
       e -> {
         timeline.play();
         done = false;
         mediaPlayer.stop();
         mediaPlayer.play();
         sp.setOnMouseClicked(null);
       });
 }
コード例 #15
0
 public void levelUp() {
   level = (numberOfLines / 10) + 1;
   shoftDropTimer.stop();
   shoftDropTimer.getKeyFrames().clear();
   shoftDropTimer
       .getKeyFrames()
       .add(
           new KeyFrame(
               Duration.millis((double) 1000 * framesPerSecond[level - 1] / 60),
               new TimerHandler()));
   shoftDropTimer.play();
 }
コード例 #16
0
  @Override
  public void start(Stage stage) throws Exception {
    Point[] sample =
        new Point[] {
          new Point(20, 10), new Point(50, 50),
          new Point(10, 20), new Point(100, 30),
          new Point(100, 200), new Point(30, 30),
        };

    ArrayList<Point> result = convexHull(sample);
    System.out.println("Left with: " + result.toString());

    // for animated spawning of dots
    Circle[] sampleDots = new Circle[sample.length];
    for (int i = 0; i < sampleDots.length; i++) {
      sampleDots[i] = new Circle(sample[i].x, sample[i].y, 3);
      sampleDots[i].setFill(Color.RED);
      sampleDots[i].opacityProperty().set(0);
      if (result.contains(sample[i])) sampleDots[i].setFill(Color.DARKCYAN);
      bp.getChildren().add(sampleDots[i]);
      sampleDots[i].toFront();
    }

    // polygon of result
    Polygon p = new Polygon();
    p.setFill(Color.TRANSPARENT);
    p.setStroke(Color.BLACK);
    p.setStrokeWidth(3);
    for (Point pt : result) {
      p.getPoints().addAll(Double.valueOf(pt.x), Double.valueOf(pt.y));
    }
    bp.getChildren().add(p);

    // scene & stage related
    Scene scene = new Scene(bp, 250, 250);
    stage.setScene(scene);
    stage.setResizable(false);
    stage.setTitle("Sample Convex Hull");
    stage.show();

    // animated spawning of dots
    p.toBack();
    Timeline tl = new Timeline();
    for (int i = 0; i < sampleDots.length; i++) {
      tl.getKeyFrames()
          .add(
              new KeyFrame(
                  Duration.seconds(1), new KeyValue(sampleDots[i].opacityProperty(), 1.0)));
    }
    tl.setCycleCount(1);
    tl.play();
  }
コード例 #17
0
    private void configureTimeline() {
      time.setCycleCount(Timeline.INDEFINITE);
      KeyFrame keyFrame =
          new KeyFrame(
              Duration.millis(47),
              new EventHandler<ActionEvent>() {

                public void handle(ActionEvent event) {
                  calculate();
                }
              });
      time.getKeyFrames().add(keyFrame);
    }
コード例 #18
0
  public void createNodes(Graph graph, double[][] coordinates) {
    nodeArray = new ArrayList<>();
    double radius = graph.getNumberOfNodes() < 25 ? 100 / graph.getNumberOfNodes() : 4;
    for (int i = 0; i < coordinates.length; i++) {
      Circle nodeI = new Circle(radius);
      nodeI.setTranslateX(coordinates[i][0]);
      nodeI.setTranslateY(coordinates[i][1]);
      Tooltip tip =
          new Tooltip("node number " + (i + 1) + ", \"" + root.sequence.getText().charAt(i) + "\"");
      Tooltip.install(nodeI, tip);
      nodeI.setId(root.sequence.getText().substring(i, i + 1));
      Timeline timeline = new Timeline();

      nodeI.setOnMouseDragged(
          event -> {
            nodeI.setTranslateX(event.getSceneX() - root.nodes.getLayoutX());
            nodeI.setTranslateY(event.getSceneY() - root.nodes.getLayoutY());
          });
      final int finalI = i;
      nodeI.setOnMouseReleased(
          event -> {
            double[][] newCoordinates =
                SpringEmbedder.computeSpringEmbedding(
                    100, graph.getNumberOfNodes(), graph.getEdges(), null);
            SpringEmbedder.centerCoordinates(
                newCoordinates,
                0,
                (int) root.getWidth(),
                20,
                (int) (root.getHeight() - root.vbox.getHeight() * 1.5));
            timeline
                .getKeyFrames()
                .add(
                    new KeyFrame(
                        Duration.millis(200),
                        new KeyValue(nodeI.translateXProperty(), coordinates[finalI][0])));
            timeline
                .getKeyFrames()
                .add(
                    new KeyFrame(
                        Duration.millis(200),
                        new KeyValue(nodeI.translateYProperty(), coordinates[finalI][1])));
            timeline.play();
          });

      nodeI.disableProperty().bind(Bindings.not(root.animate.selectedProperty()));
      root.nodes.getChildren().add(nodeI);
      nodeArray.add(nodeI);
    }
  }
コード例 #19
0
 public void startGame(MouseEvent e) {
   if (e.getButton().equals(MouseButton.PRIMARY)) {
     stage.close();
     EscapeNewPangea game = new EscapeNewPangea();
     Scene scene = game.initialize();
     stage.setScene(scene);
     stage.show();
     KeyFrame frame = game.start();
     Timeline animation = new Timeline();
     animation.setCycleCount(Animation.INDEFINITE);
     animation.getKeyFrames().add(frame);
     animation.play();
   }
 }
コード例 #20
0
  /** Sets up the timeline for the room. */
  public void createRoomLoop() {

    final Duration oneFrameAmt = Duration.millis(30);
    final KeyFrame oneFrame =
        new KeyFrame(
            oneFrameAmt,
            e -> {
              step();
            });

    Timeline animation = new Timeline();
    animation.setCycleCount(Timeline.INDEFINITE);
    animation.getKeyFrames().add(oneFrame);
    myGameLoop = animation;
  }
コード例 #21
0
ファイル: MainViewController.java プロジェクト: Zopo/RoBro
  public void initialize(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    try {
      ClientCommunicationManager.getInstance().subscribeAll();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    btn_refresh.setOnAction(
        event -> {
          try {
            ClientCommunicationManager.getInstance().subscribeAll();
            updateRobotList();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        });

    list_robots
        .getSelectionModel()
        .selectedIndexProperty()
        .addListener((obervable, oldValue, newValue) -> loadSelected());

    ClientCommunicationManager clientCommunicationManager =
        ClientCommunicationManager.getInstance();
    updateRobotList();
    Timeline updateTimer =
        new Timeline(
            new KeyFrame(
                Duration.millis(50),
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                    Collection<String> oldRobots =
                        RobotRepository.getInstance().getRobots().keySet();
                    clientCommunicationManager.processIncomingObjects();
                    Collection<String> newRobots =
                        RobotRepository.getInstance().getRobots().keySet();
                    if (!oldRobots.equals(newRobots)) {
                      updateRobotList();
                    }
                  }
                }));
    updateTimer.setCycleCount(Timeline.INDEFINITE);
    updateTimer.play();
  }
コード例 #22
0
  @Override
  public void start(Stage primaryStage) throws Exception {
    shoftDropTimer.setCycleCount(Animation.INDEFINITE);
    shoftDropTimer
        .getKeyFrames()
        .add(
            new KeyFrame(
                Duration.millis((double) 1000 * framesPerSecond[level - 1] / 60),
                new TimerHandler()));
    // shoftDropTimer.setDelay(Duration.millis(500));

    stage3D = primaryStage;
    primaryStage.setTitle("Java Tetris");
    primaryStage.setScene(createMainTetrisScene());
    primaryStage.show();
  }
コード例 #23
0
  private void animateTransitionToLabel(Label newLabel) {
    final Bounds newLabelBounds = newLabel.getBoundsInParent();

    final double newX = newLabelBounds.getMinX();
    final double newWidth = newLabelBounds.getWidth();

    animation.getKeyFrames().clear();
    animation
        .getKeyFrames()
        .add(
            new KeyFrame(
                TRANSITION_DURATION,
                new KeyValue(selectedBackground.xProperty(), newX),
                new KeyValue(selectedBackground.widthProperty(), newWidth)));

    animation.play();
  }
コード例 #24
0
 public void win() {
   Text t = new Text("You Win");
   t.setFont(Font.font("Impact", 45));
   t.setFill(Color.BLACK);
   root.getChildren().add(t);
   timeline =
       new Timeline(
           new KeyFrame(
               Duration.millis(100),
               new EventHandler() {
                 public void handle(Event e) {}
               }));
   timeline.setCycleCount(10);
   timeline.play();
   curClan.inventory.addAll(m.spoils);
   curClan.gold += m.gold;
   curClan.completed.add(m);
 }
コード例 #25
0
ファイル: Dock.java プロジェクト: ludup/hypersocket-client
 private void maybeHideDock(long time) {
   if (hiding) {
     return;
   }
   if (popOver != null && popOver.isShowing()) return;
   stopDockHiderTrigger();
   dockHiderTrigger = new Timeline(new KeyFrame(Duration.millis(time), ae -> hideDock(true)));
   dockHiderTrigger.play();
 }
コード例 #26
0
 public void animate() {
   Timeline timeline =
       new Timeline(
           new KeyFrame(
               Duration.seconds(0),
               new KeyValue(translateZ.zProperty(), -20),
               new KeyValue(rotateX.angleProperty(), 90),
               new KeyValue(rotateY.angleProperty(), 90),
               new KeyValue(rotateZ.angleProperty(), 90)),
           new KeyFrame(
               Duration.seconds(5),
               new KeyValue(translateZ.zProperty(), -80),
               new KeyValue(rotateX.angleProperty(), -90),
               new KeyValue(rotateY.angleProperty(), -90),
               new KeyValue(rotateZ.angleProperty(), -90)));
   timeline.setCycleCount(Animation.INDEFINITE);
   timeline.play();
 }
コード例 #27
0
ファイル: Optimizer.java プロジェクト: thiagodemoura/JCSG
  private void cleanUpRepeatingFramesAndValues() {
    ObservableList<KeyFrame> timelineKeyFrames =
        timeline.getKeyFrames().sorted(new KeyFrameComparator());
    //        Timeline timeline;
    int kfTotal = timelineKeyFrames.size(), kfRemoved = 0;
    int kvTotal = 0, kvRemoved = 0;
    Map<Duration, KeyFrame> kfUnique = new HashMap<>();
    Map<WritableValue, KeyValue> kvUnique = new HashMap<>();
    MapOfLists<KeyFrame, KeyFrame> duplicates = new MapOfLists<>();
    Iterator<KeyFrame> iterator = timelineKeyFrames.iterator();
    while (iterator.hasNext()) {
      KeyFrame duplicate = iterator.next();
      KeyFrame original = kfUnique.put(duplicate.getTime(), duplicate);
      if (original != null) {
        kfRemoved++;
        iterator.remove(); // removing duplicate keyFrame
        duplicates.add(original, duplicate);

        kfUnique.put(duplicate.getTime(), original);
      }
      kvUnique.clear();
      for (KeyValue kvDup : duplicate.getValues()) {
        kvTotal++;
        KeyValue kvOrig = kvUnique.put(kvDup.getTarget(), kvDup);
        if (kvOrig != null) {
          kvRemoved++;
          if (!kvOrig.getEndValue().equals(kvDup.getEndValue())
              && kvOrig.getTarget() == kvDup.getTarget()) {
            System.err.println(
                "KeyValues set different values for KeyFrame "
                    + duplicate.getTime()
                    + ":"
                    + "\n kvOrig = "
                    + kvOrig
                    + ", \nkvDup = "
                    + kvDup);
          }
        }
      }
    }
    for (KeyFrame orig : duplicates.keySet()) {
      List<KeyValue> keyValues = new ArrayList<>();
      for (KeyFrame dup : duplicates.get(orig)) {
        keyValues.addAll(dup.getValues());
      }
      timelineKeyFrames.set(
          timelineKeyFrames.indexOf(orig),
          new KeyFrame(orig.getTime(), keyValues.toArray(new KeyValue[keyValues.size()])));
    }
    System.out.printf(
        "Removed %d (%.2f%%) duplicate KeyFrames out of total %d.\n",
        kfRemoved, 100d * kfRemoved / kfTotal, kfTotal);
    System.out.printf(
        "Identified %d (%.2f%%) duplicate KeyValues out of total %d.\n",
        kvRemoved, 100d * kvRemoved / kvTotal, kvTotal);
  }
コード例 #28
0
ファイル: Main.java プロジェクト: battlesm/game_MJB81
  @Override
  public void start(Stage s) {
    myGame = new Game();
    s.setTitle(myGame.getTitle());

    Scene scene = myGame.init(WIDTH, HEIGHT);
    s.setScene(scene);

    s.show();

    KeyFrame frame =
        new KeyFrame(Duration.millis(MILLISECOND_DELAY), e -> myGame.step(SECOND_DELAY));
    Timeline animation = new Timeline();
    animation.setCycleCount(Timeline.INDEFINITE);
    animation.getKeyFrames().add(frame);
    animation.play();

    s.setResizable(false);
  }
コード例 #29
0
  public JFXToggleButtonSkin(JFXToggleButton toggleButton) {
    super(toggleButton);
    // hide the togg	le button
    toggleButton.setStyle("-fx-background-color:TRANSPARENT");

    line = new Line(startX, startY, endX, startY);
    line.setStroke(unToggledColor);
    line.setStrokeWidth(1);

    circle = new Circle(startX - circleRadius, startY, circleRadius);
    circle.setFill(Color.TRANSPARENT);
    circle.setStroke(unToggledColor);
    circle.setStrokeWidth(strokeWidth);

    innerCircle = new Circle(startX - circleRadius, startY, 0);
    innerCircle.setStrokeWidth(0);

    StackPane circlePane = new StackPane();
    circlePane.getChildren().add(circle);
    circlePane.getChildren().add(innerCircle);
    circlePane.setPadding(new Insets(15));
    rippler = new JFXRippler(circlePane, RipplerMask.CIRCLE, RipplerPos.BACK);

    circles.getChildren().add(rippler);

    main.getChildren().add(line);
    main.getChildren().add(circles);
    main.setCursor(Cursor.HAND);
    AnchorPane.setTopAnchor(circles, -12.0);
    AnchorPane.setLeftAnchor(circles, -15.0);

    getSkinnable()
        .selectedProperty()
        .addListener(
            (o, oldVal, newVal) -> {
              rippler.setRipplerFill(newVal ? unToggledColor : toggledColor);
              transition.setRate(newVal ? 1 : -1);
              transition.play();
            });

    updateChildren();
  }
コード例 #30
0
ファイル: FinalGame.java プロジェクト: NihalPandit/Work
 public void timer() {
   timer--;
   if (timer != 0) {
     clock.setText(" Time left : " + timer + " Seconds");
   }
   if (timer == 0) {
     timeline.stop();
     clock.setText(" Time left : " + timer + " Seconds");
     check();
   }
 }