protected void addLabel(String name) {
   Label label = new Label(myResource.getString(name));
   label.setPrefWidth(myScene.getWidth() / 7);
   label.setBackground(
       new Background(new BackgroundFill(Color.CADETBLUE, new CornerRadii(0), new Insets(0))));
   getChildren().add(label);
 }
예제 #2
0
  @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();
  }
 protected PastCommandsAbstract(
     GUIManager guiManager, Scene scene, ResourceBundle resource, String label) {
   myScene = scene;
   myResource = resource;
   myGuiManager = guiManager;
   addLabel(label);
   myScroller.setPrefHeight(scene.getHeight() * 4 / 5);
   myScroller.setContent(myVbox);
   myScroller.setVbarPolicy(ScrollBarPolicy.ALWAYS);
   myScroller.setHbarPolicy(ScrollBarPolicy.ALWAYS);
   setPrefWidth(scene.getWidth() / 7);
   getChildren().add(myScroller);
   getChildren().add(myVbox);
 }
  @Test
  public void testLayoutWithConceptAdded() {
    int conceptCount = map.getConceptCount();

    Concept c =
        new Concept(
            new CollaborativeString(map.getExperiment().getParticipants().get(0), FIRST_CONCEPT));
    double x = 0.4;
    double y = 0.4;
    c.setPosition(x, y, 0);

    map.addConcept(c);

    // when
    super.interact(
        () -> {
          controller.setConceptMap(map);
          controller.layout();
        });

    // then

    Set<Node> concepts = conceptMapView.lookupAll(".concept");

    assertEquals(conceptCount + 1, concepts.size());
    assertEquals(conceptCount + 1, map.getConceptCount());
    Node addedConcept = concepts.iterator().next();

    double xScaled = addedConcept.getLayoutX() + addedConcept.getTranslateX();
    double yScaled = addedConcept.getLayoutY() + addedConcept.getTranslateY();

    assertEquals(x * scene.getWidth(), xScaled, 0.5);
    assertEquals(y * scene.getHeight(), yScaled, 0.5);

    Label caption = (Label) addedConcept.lookup("#caption");
    assertEquals(FIRST_CONCEPT, caption.getText());
  }
  public void loadCatalogs() {
    Button button;
    Catalog catalog;
    List<Item> items =
        ((CatalogCollection) (new CatalogModel()).getCollection()).loadByLibraryId(libraryId);
    int i = 1;

    for (Item item : items) {
      catalog = (Catalog) item;
      button = new Button(catalog.getName());
      int catalogId = catalog.getId();
      button.setId(String.valueOf(catalogId));
      button.getStyleClass().add("cake");
      button.setOnAction(
          (ActionEvent event) -> {
            try {
              Scene sceneCurrent = btnBack.getScene();
              Stage stage = (Stage) sceneCurrent.getWindow();

              FXMLLoader fxmlLoader =
                  new FXMLLoader(getClass().getResource("/view/template/book/BookList.fxml"));
              Parent sceneNew = fxmlLoader.load();

              BookListController controller = fxmlLoader.<BookListController>getController();
              controller.setCatalogId(catalogId);
              controller.setLibraryId(libraryId);
              controller.prepareData();

              stage.setScene(
                  new Scene(sceneNew, sceneCurrent.getWidth(), sceneCurrent.getHeight()));
            } catch (IOException e) {
              logger.log(Level.SEVERE, "Error configuring catalog buttons", e);
            }
          });
      catalogContainer.add(button, i++, 1);
    }
  }
예제 #6
0
    @Override
    public void handle(final MouseEvent mouseEvent) {
      final EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
      final Scene scene = this.stage.getScene();

      final double mouseEventX = mouseEvent.getSceneX(),
          mouseEventY = mouseEvent.getSceneY(),
          sceneWidth = scene.getWidth(),
          sceneHeight = scene.getHeight();

      if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) {
        if (mouseEventX < this.border && mouseEventY < this.border) {
          this.cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < this.border && mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border && mouseEventY < this.border) {
          this.cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border
            && mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < this.border) {
          this.cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - this.border) {
          this.cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < this.border) {
          this.cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - this.border) {
          this.cursorEvent = Cursor.S_RESIZE;
        } else {
          this.cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(this.cursorEvent);
      } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType) == true) {
        this.startX = this.stage.getWidth() - mouseEventX;
        this.startY = this.stage.getHeight() - mouseEventY;
      } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) {
        this.resizing = false;
        if (Cursor.DEFAULT.equals(this.cursorEvent) == false) {
          if (Cursor.W_RESIZE.equals(this.cursorEvent) == false
              && Cursor.E_RESIZE.equals(this.cursorEvent) == false) {
            final double minHeight =
                this.stage.getMinHeight() > (this.border * 2)
                    ? this.stage.getMinHeight()
                    : (this.border * 2);
            if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true
                || Cursor.N_RESIZE.equals(this.cursorEvent) == true
                || Cursor.NE_RESIZE.equals(this.cursorEvent) == true) {
              if (this.stage.getHeight() > minHeight || mouseEventY < 0) {
                this.resizing = true;
                this.stage.setHeight(
                    this.stage.getY() - mouseEvent.getScreenY() + this.stage.getHeight());
                this.stage.setY(mouseEvent.getScreenY());
              }
            } else {
              if (this.stage.getHeight() > minHeight
                  || mouseEventY + this.startY - this.stage.getHeight() > 0) {
                this.resizing = true;
                this.stage.setHeight(mouseEventY + this.startY);
              }
            }
          }

          if (Cursor.N_RESIZE.equals(this.cursorEvent) == false
              && Cursor.S_RESIZE.equals(this.cursorEvent) == false) {
            final double minWidth =
                this.stage.getMinWidth() > (this.border * 2)
                    ? this.stage.getMinWidth()
                    : (this.border * 2);
            if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true
                || Cursor.W_RESIZE.equals(this.cursorEvent) == true
                || Cursor.SW_RESIZE.equals(this.cursorEvent) == true) {
              if (this.stage.getWidth() > minWidth || mouseEventX < 0) {
                this.resizing = true;
                this.stage.setWidth(
                    this.stage.getX() - mouseEvent.getScreenX() + this.stage.getWidth());
                this.stage.setX(mouseEvent.getScreenX());
              }
            } else {
              if (this.stage.getWidth() > minWidth
                  || mouseEventX + this.startX - this.stage.getWidth() > 0) {
                this.resizing = true;
                this.stage.setWidth(mouseEventX + this.startX);
              }
            }
          }
        }
      }
    }
예제 #7
0
  // for shots created with the space bar, trigonometry is
  // used to find the angle that the user's mouse was to the
  // origin and to extend the shot past the user's click to
  // the edge of the screen.
  private void initializeShot() {

    double miniHypot;
    double largeHypot;
    double edgePoint;
    double distance;
    TranslateTransition translate;

    // four different quadrants of the screen mean that the angles
    // must be processed four different ways, and that the
    // transitions must be added to the shots in four different ways.
    // the algebra is different in each if statement; the first is
    // commented as an example

    // if the click was on the left of Earth
    if (_mouse.getXCoord() < Constants.ORIGIN) {
      // if the click was above Earth
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        // get the distance of the mini hypoteneuse made with the click
        miniHypot =
            Math.sqrt(
                Math.pow((Constants.ORIGIN - _mouse.getXCoord()), 2)
                    + Math.pow((Constants.ORIGIN - _mouse.getYCoord()), 2));
        // extend that distance to the edge of the screen
        largeHypot = ((Constants.ORIGIN / (Constants.ORIGIN - _mouse.getXCoord())) * miniHypot);
        // calculate the y point based on that distance
        edgePoint = Math.sqrt(Math.pow(largeHypot, 2) - Math.pow(Constants.ORIGIN, 2));

        // get the distance between the new point and the origin
        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((-edgePoint), 2)));

        // create a translation with a constant rate for almost all angles
        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        // send the shot all the way to the left
        translate.setToX(-Constants.ORIGIN);
        // send the shot up to the right point
        translate.setToY(-edgePoint);
      } else {
        miniHypot =
            Math.sqrt(
                Math.pow((Constants.ORIGIN - _mouse.getXCoord()), 2)
                    + Math.pow((_mouse.getYCoord() - Constants.ORIGIN), 2));
        largeHypot = ((Constants.ORIGIN / (Constants.ORIGIN - _mouse.getXCoord())) * miniHypot);
        edgePoint = Math.sqrt(Math.pow(largeHypot, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    } else if (_mouse.getXCoord() > Constants.ORIGIN) {
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        miniHypot =
            Math.sqrt(
                Math.pow((_mouse.getXCoord() - Constants.ORIGIN), 2)
                    + Math.pow((Constants.ORIGIN - _mouse.getYCoord()), 2));
        largeHypot =
            (((_scene.getWidth() - Constants.ORIGIN) / (_mouse.getXCoord() - Constants.ORIGIN))
                * miniHypot);
        edgePoint =
            Math.sqrt(
                Math.pow(largeHypot, 2) - Math.pow((_scene.getWidth() - Constants.ORIGIN), 2));

        distance =
            (Math.sqrt(
                Math.pow((_scene.getWidth() - Constants.ORIGIN), 2) + Math.pow((-edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(_scene.getWidth() - Constants.ORIGIN);
        translate.setToY(-edgePoint);
      } else {
        miniHypot =
            Math.sqrt(
                Math.pow((_mouse.getXCoord() - Constants.ORIGIN), 2)
                    + Math.pow((_mouse.getYCoord() - Constants.ORIGIN), 2));
        largeHypot =
            (((_scene.getWidth() - Constants.ORIGIN) / (_mouse.getXCoord() - Constants.ORIGIN))
                * miniHypot);
        edgePoint =
            Math.sqrt(
                Math.pow(largeHypot, 2) - Math.pow((_scene.getWidth() - Constants.ORIGIN), 2));

        distance =
            (Math.sqrt(
                Math.pow((_scene.getWidth() - Constants.ORIGIN), 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(_scene.getWidth() - Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    }
    // the case if the X coordinate of the mouse is equal to the origin
    // prevents a divide by zero error by substituting in a fake edgepoint calculation
    else {
      if (_mouse.getYCoord() <= Constants.ORIGIN) {
        edgePoint =
            Math.sqrt(Math.pow(Constants.DIVIDE_BY_ZERO_CATCH, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(-edgePoint);
      } else {
        edgePoint =
            Math.sqrt(Math.pow(Constants.DIVIDE_BY_ZERO_CATCH, 2) - Math.pow(Constants.ORIGIN, 2));

        distance = (Math.sqrt(Math.pow(-Constants.ORIGIN, 2) + Math.pow((edgePoint), 2)));

        translate =
            new TranslateTransition(
                Duration.millis(
                    Constants.SHOT_RATE_CONSTANT
                        * ((distance % Constants.SHOT_RATE_UPPER_BOUND)
                            + Constants.SHOT_RATE_LOWER_BOUND)));
        translate.setToX(-Constants.ORIGIN);
        translate.setToY(edgePoint);
      }
    }

    ArrayList<Transition> animations = new ArrayList<Transition>();
    animations.add(translate);

    this.setAnimations(animations);
  }
예제 #8
0
 /** Bounds of Scene in Window. */
 public static Bounds bounds(Scene scene) {
   return bounds(scene.getX(), scene.getY(), scene.getWidth(), scene.getHeight());
 }
예제 #9
0
 private static Bounds makeSceneBounds(Scene scene) {
   return new BoundingBox(0, 0, scene.getWidth(), scene.getHeight());
 }
예제 #10
0
 public <T extends Object> void revealElement(
     final T element, final EntryCall<? super T> entryCall, final IEditorPart editor) {
   final Runnable _function =
       () -> {
         try {
           Scene _scene = this.canvas.getScene();
           double _width = _scene.getWidth();
           boolean _equals = (_width == 0);
           if (_equals) {
             Scene _scene_1 = this.canvas.getScene();
             ReadOnlyDoubleProperty _widthProperty = _scene_1.widthProperty();
             final ChangeListener<Number> _function_1 =
                 new ChangeListener<Number>() {
                   @Override
                   public void changed(
                       final ObservableValue<? extends Number> p, final Number o, final Number n) {
                     Scene _scene = FXDiagramTab.this.canvas.getScene();
                     ReadOnlyDoubleProperty _widthProperty = _scene.widthProperty();
                     _widthProperty.removeListener(this);
                     FXDiagramTab.this.<T>revealElement(element, entryCall, editor);
                   }
                 };
             _widthProperty.addListener(_function_1);
           } else {
             Scene _scene_2 = this.canvas.getScene();
             double _height = _scene_2.getHeight();
             boolean _equals_1 = (_height == 0);
             if (_equals_1) {
               Scene _scene_3 = this.canvas.getScene();
               ReadOnlyDoubleProperty _heightProperty = _scene_3.heightProperty();
               final ChangeListener<Number> _function_2 =
                   new ChangeListener<Number>() {
                     @Override
                     public void changed(
                         final ObservableValue<? extends Number> p,
                         final Number o,
                         final Number n) {
                       Scene _scene = FXDiagramTab.this.canvas.getScene();
                       ReadOnlyDoubleProperty _heightProperty = _scene.heightProperty();
                       _heightProperty.removeListener(this);
                       FXDiagramTab.this.<T>revealElement(element, entryCall, editor);
                     }
                   };
               _heightProperty.addListener(_function_2);
             } else {
               this.<T>doRevealElement(element, entryCall, editor);
             }
           }
         } catch (final Throwable _t) {
           if (_t instanceof Exception) {
             final Exception exc = (Exception) _t;
             exc.printStackTrace();
             Display _current = Display.getCurrent();
             Shell _activeShell = _current.getActiveShell();
             StringConcatenation _builder = new StringConcatenation();
             _builder.append("Error showing element in FXDiagram:");
             _builder.newLine();
             String _message = exc.getMessage();
             _builder.append(_message, "");
             _builder.newLineIfNotEmpty();
             _builder.append("See log for details.");
             _builder.newLine();
             MessageDialog.openError(_activeShell, "Error", _builder.toString());
           } else {
             throw Exceptions.sneakyThrow(_t);
           }
         }
       };
   Platform.runLater(_function);
 }
예제 #11
0
  @Override
  public void start(Stage primaryStage) {

    /*
     * Es recomendable usar un grupo de nodos como raiz de la escena.
     * El tamaño del grupo depende del tamaño de los nodos.
     */
    Group root = new Group();
    // Pinto una escena negra de 800 * 600
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    primaryStage.setScene(scene);

    // A continuacion vamos a pintar 30 circulos
    Group circles = new Group();

    for (int i = 0; i < 30; i++) {

      // Creo un criculo con un radio de 150, color blanco y opacidad del 5%
      Circle circle = new Circle(150, Color.web("white", 0.05));

      // Creo un borde alrededor del circulo
      circle.setStrokeType(StrokeType.OUTSIDE);

      // Color del borde del circulo y opacidad
      circle.setStroke(Color.web("white", 0.16));

      // ancho del borde exterior del circulo
      circle.setStrokeWidth(4);

      // Añado el grupo de circulos a la raiz (root)
      circles.getChildren().add(circle);
    }

    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());

    Group blendModeGroup =
        new Group(
            new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles),
            colors);

    colors.setBlendMode(BlendMode.OVERLAY);

    root.getChildren().add(blendModeGroup);

    // Añadimos un efecto de desenfocado a los circulos
    circles.setEffect(new BoxBlur(10, 10, 3));

    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.show();
  }