Exemplo n.º 1
0
  private Region generateClosedDoorPane(int n, int e, int s, int w) {
    Region closedDoor = new Region();
    closedDoor.setPrefHeight(CELL_SIZE);
    closedDoor.setPrefWidth(CELL_SIZE);

    int north_gap = BORDER_WIDTH,
        east_gap = BORDER_WIDTH,
        south_gap = BORDER_WIDTH,
        west_gap = BORDER_WIDTH;

    if (n == 3) {
      north_gap = 0;
    }
    if (e == 3) {
      east_gap = 0;
    }
    if (s == 3) {
      south_gap = 0;
    }
    if (w == 3) {
      west_gap = 0;
    }

    Insets gap = new Insets(north_gap, east_gap, south_gap, west_gap);
    closedDoor.setBackground(
        new Background(new BackgroundFill(CLOSED_DOOR_COLOR, CornerRadii.EMPTY, gap)));

    return closedDoor;
  }
Exemplo n.º 2
0
  /**
   * Write a canvas to writer in SVG format.
   *
   * @param canvas The canvas.
   * @param writer The writer.
   * @throws IOException If writing failed.
   */
  public static void write(Region canvas, Writer writer) throws IOException {

    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
    Region viewport = (Region) canvas.getParent();
    writer.write(
        String.format(
            "<svg xmlns=\"http://www.w3.org/2000/svg\""
                + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=\"%f\""
                + " height=\"%f\">\n",
            viewport.getWidth(), viewport.getHeight()));

    for (Node node : canvas.getChildrenUnmodifiable()) {
      if (node instanceof Line) {
        write((Line) node, writer);
      } else if (node instanceof Rectangle) {
        write((Rectangle) node, writer);
      } else if (node instanceof Ellipse) {
        write((Ellipse) node, writer);
      } else if (node instanceof Text) {
        write((Text) node, writer);
      }
    }

    writer.write("</svg>\n");

    writer.flush();
  }
Exemplo n.º 3
0
  public SQLHistorySearchCtrl(
      SQLTextAreaServices sqlTextAreaServices,
      Session session,
      ObservableList<SQLHistoryEntry> items) {
    _sqlTextAreaServices = sqlTextAreaServices;

    FxmlHelper<SQLHistorySearchView> fxmlHelper = new FxmlHelper<>(SQLHistorySearchView.class);
    _view = fxmlHelper.getView();

    _dialog = new Stage();
    _dialog.setTitle(
        new I18n(getClass())
            .t("SQLHistorySearchCtrl.title", session.getMainTabContext().getSessionTabTitle()));
    _dialog.initModality(Modality.WINDOW_MODAL);
    _dialog.initOwner(AppState.get().getPrimaryStage());
    Region region = fxmlHelper.getRegion();
    _dialog.setScene(new Scene(region));

    GuiUtils.makeEscapeClosable(region);

    new StageDimensionSaver(
        "sqlhistorysearch",
        _dialog,
        new Pref(getClass()),
        region.getPrefWidth(),
        region.getPrefHeight(),
        _dialog.getOwner());

    _view.cboFilterType.setItems(
        FXCollections.observableList(Arrays.asList(SqlHistoryFilterType.values())));
    _view.cboFilterType.getSelectionModel().selectFirst();

    _view.btnApply.setOnAction(e -> onApply());
    _view.chkFiltered.setOnAction(e -> onChkFiltered());

    _view.split.getItems().add(_tblHistory);
    _view.split.getItems().add(_txtSqlPreview);

    _originalTableLoader = new RowObjectTableLoader<>();
    _originalTableLoader.initColsByAnnotations(SQLHistoryEntry.class);
    _originalTableLoader.addRowObjects(items);
    _currentLoader = _originalTableLoader.cloneLoader();
    _currentLoader.load(_tblHistory);

    _tblHistory
        .getSelectionModel()
        .selectedItemProperty()
        .addListener((observable, oldValue, newValue) -> onTableSelectionChanged());

    _tblHistory.setOnMouseClicked(e -> onTblHistoryClicked(e));

    _txtSqlPreview.setEditable(false);

    _dialog.setOnCloseRequest(e -> close());

    _view.txtFilter.requestFocus();

    _splitPositionSaver.apply(_view.split);
    _dialog.showAndWait();
  }
Exemplo n.º 4
0
  public void setLayoutBounds(Bounds layoutBounds) {

    // Setup layoutX/layoutY on the image view and the region (1)
    region.setLayoutX(layoutBounds.getMinX());
    region.setLayoutY(layoutBounds.getMinY());
    region.setPrefWidth(layoutBounds.getWidth());
    region.setPrefHeight(layoutBounds.getHeight());
  }
 private Node wrapAndStyle(Region node, int rowNumber) {
   Pane p = new Pane(node);
   node.setPadding(new Insets(5.0));
   GridPane.setFillWidth(p, true);
   p.minHeightProperty().bind(node.heightProperty());
   // Hack - wrapped labels don't seem to fire their height property changes at the right time -
   // leaving the surrounding Pane node too small.
   // this seems to help...
   Platform.runLater(() -> p.autosize());
   p.getStyleClass().add(((rowNumber % 2 == 0) ? "evenGridRow" : "oddGridRow"));
   return p;
 }
 @Override
 protected void layoutChildren() {
   final double top = snappedTopInset();
   final double left = snappedLeftInset();
   final double bottom = snappedBottomInset();
   final double right = snappedRightInset();
   final double aw = snapSize(arrow.prefWidth(-1));
   final double ah = snapSize(arrow.prefHeight(-1));
   final double yPos = snapPosition((getHeight() - (top + bottom + ah)) / 2.0);
   final double xPos = snapPosition((getWidth() - (left + right + aw)) / 2.0);
   arrow.resizeRelocate(xPos + left, yPos + top, aw, ah);
 }
 public void update(
     double closeOffset, double highOffset, double lowOffset, double candleWidth) {
   openAboveClose = closeOffset > 0;
   updateStyleClasses();
   highLowLine.setStartY(highOffset);
   highLowLine.setEndY(lowOffset);
   if (candleWidth == -1) {
     candleWidth = bar.prefWidth(-1);
   }
   if (openAboveClose) {
     bar.resizeRelocate(-candleWidth / 2, 0, candleWidth, closeOffset);
   } else {
     bar.resizeRelocate(-candleWidth / 2, closeOffset, candleWidth, closeOffset * -1);
   }
 }
 @Override
 protected double computePrefHeight(double width) {
   double h = 0;
   for (Node child : getChildren()) {
     if (child instanceof Region) {
       Region region = (Region) child;
       if (region.getShape() != null) {
         h = Math.max(h, region.getShape().getLayoutBounds().getMaxY());
       } else {
         h = Math.max(h, region.prefHeight(width));
       }
     }
   }
   return h;
 }
 @Override
 protected double computePrefWidth(double height) {
   double w = 0;
   for (Node child : getChildren()) {
     if (child instanceof Region) {
       Region region = (Region) child;
       if (region.getShape() != null) {
         w = Math.max(w, region.getShape().getLayoutBounds().getMaxX());
       } else {
         w = Math.max(w, region.prefWidth(height));
       }
     }
   }
   return w;
 }
 private EndButton(String styleClass, String arrowStyleClass) {
   getStyleClass().setAll(styleClass);
   arrow = new Region();
   arrow.getStyleClass().setAll(arrowStyleClass);
   getChildren().setAll(arrow);
   requestLayout();
 }
  @Override
  protected void layoutChildren() {
    super.layoutChildren();

    mainIcon.relocate(getPadding().getLeft(), getPadding().getTop());
    mainIcon.resize(mainIcon.prefWidth(-1), mainIcon.prefHeight(-1));

    double titleX = mainIcon.getLayoutX() + mainIcon.getWidth() + 12;
    double titleY =
        mainIcon.getLayoutY() + (mainIcon.getHeight() - currentTitle.prefHeight(-1)) / 2;
    double titleWidth = getWidth() - titleX * 2;
    double titleHeight = currentTitle.prefHeight(-1);

    currentTitle.relocate(titleX, titleY);
    currentTitle.resize(titleWidth, titleHeight);

    actionBox.relocate(
        getWidth() - getPadding().getRight() - actionBox.prefWidth(-1), getPadding().getTop());
    actionBox.resize(actionBox.prefWidth(-1), actionBox.prefHeight(-1));

    changeViewAnimationTitle.relocate(titleX, titleY);
    changeViewAnimationTitle.resize(titleWidth, titleHeight);

    Insets borderInsets =
        Optional.ofNullable(getBorder()).map(border -> border.getInsets()).orElse(Insets.EMPTY);
    background.setX(borderInsets.getLeft());
    background.setY(borderInsets.getTop());
    background.setWidth(getWidth() - borderInsets.getLeft() - borderInsets.getRight());
    background.setHeight(getHeight() - borderInsets.getTop() - borderInsets.getBottom());

    changeViewAnimationCircle.setCenterX(mainIcon.getLayoutX() + mainIcon.getWidth() / 2);
    changeViewAnimationCircle.setCenterY(mainIcon.getLayoutY() + mainIcon.getHeight() / 2);
  }
 @Override
 protected double computePrefWidth(double height) {
   final double left = snappedLeftInset();
   final double right = snappedRightInset();
   final double aw = snapSize(arrow.prefWidth(-1));
   return left + aw + right;
 }
 @Override
 protected double computePrefHeight(double width) {
   final double top = snappedTopInset();
   final double bottom = snappedBottomInset();
   final double ah = snapSize(arrow.prefHeight(-1));
   return top + ah + bottom;
 }
 private void rebuild() {
   // update indeterminate indicator
   final int segments = skin.indeterminateSegmentCount.get();
   opacities.clear();
   pathsG.getChildren().clear();
   final double step = 0.8 / (segments - 1);
   for (int i = 0; i < segments; i++) {
     Region region = new Region();
     region.setScaleShape(false);
     region.setCenterShape(false);
     region.getStyleClass().addAll("segment", "segment" + i);
     if (fillOverride instanceof Color) {
       Color c = (Color) fillOverride;
       region.setStyle(
           "-fx-background-color: rgba("
               + ((int) (255 * c.getRed()))
               + ","
               + ""
               + ((int) (255 * c.getGreen()))
               + ","
               + ((int) (255 * c.getBlue()))
               + ","
               + ""
               + c.getOpacity()
               + ");");
     } else {
       region.setStyle(null);
     }
     double opacity = Math.min(1, i * step);
     opacities.add(opacity);
     region.setOpacity(opacity);
     pathsG.getChildren().add(region);
   }
 }
Exemplo n.º 15
0
  private Region generateFloorSurfacePane(int t, int n, int e, int s, int w) {
    Region floor = new Region();
    floor.setPrefHeight(CELL_SIZE);
    floor.setPrefWidth(CELL_SIZE);

    Color floorSurface = Color.web("fff");
    switch (t) {
      case (0):
        floorSurface = BARE_FLOOR_COLOR;
        break;
      case (1):
        floorSurface = LOW_PILE_COLOR;
        break;
      case (2):
        floorSurface = HIGH_PILE_COLOR;
        break;
      case (3):
        // TODO: replace with stair color
        floorSurface = Color.web("f00");
        break;
      default:
        System.out.println("Unsupported floor type");
        break;
    }

    int floor_n = 0, floor_e = 0, floor_s = 0, floor_w = 0;
    if (n > 0) {
      floor_n = BORDER_WIDTH;
    }
    if (e > 0) {
      floor_e = BORDER_WIDTH;
    }
    if (s > 0) {
      floor_s = BORDER_WIDTH;
    }
    if (w > 0) {
      floor_w = BORDER_WIDTH;
    }
    Insets floorGap = new Insets(floor_n, floor_e, floor_s, floor_w);
    floor.setBackground(
        new Background(new BackgroundFill(floorSurface, CornerRadii.EMPTY, floorGap)));

    return floor;
  }
Exemplo n.º 16
0
 private void updateStyleClasses() {
   getStyleClass().setAll("candlestick-candle", seriesStyleClass, dataStyleClass);
   highLowLine
       .getStyleClass()
       .setAll(
           "candlestick-line",
           seriesStyleClass,
           dataStyleClass,
           openAboveClose ? "open-above-close" : "close-above-open");
   bar.getStyleClass()
       .setAll(
           "candlestick-bar",
           seriesStyleClass,
           dataStyleClass,
           openAboveClose ? "open-above-close" : "close-above-open");
 }
 @Override
 protected void layoutChildren() {
   // calculate scale
   double scale = getWidth() / computePrefWidth(-1);
   getChildren()
       .stream()
       .filter(child -> child instanceof Region)
       .forEach(
           child -> {
             Region region = (Region) child;
             if (region.getShape() != null) {
               region.resize(
                   region.getShape().getLayoutBounds().getMaxX(),
                   region.getShape().getLayoutBounds().getMaxY());
               region.getTransforms().setAll(new Scale(scale, scale, 0, 0));
             } else {
               region.autosize();
             }
           });
 }
Exemplo n.º 18
0
  @Override
  protected void layoutChildren() {
    super.layoutChildren();

    if (_nodeByPosition.isEmpty()) {
      adjustLineCount(0);

      setPrefWidth(0);
      setPrefHeight(0);

      return;
    }

    // Calculate width per position based on layout bounds
    Map<NodePosition, Double> widthByPosition = new HashMap<>();
    Map<Integer, Double> levelHeight = new HashMap<>();

    Map<Integer, Set<NodePosition>> positionsByLevel = new HashMap<>();
    Map<NodePosition, Set<NodePosition>> positionsByParentPosition = new HashMap<>();

    int maxLevel = Collections.max(_nodeByLevel.keySet());

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      levelHeight.put(curLevel, 0.0);

      positionsByLevel.put(curLevel, new HashSet<NodePosition>());
    }

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      // Get bounds of nodes on current level
      Set<Node> curLevelNodes = _nodeByLevel.get(curLevel);

      if (curLevelNodes != null) {
        // Get node bounds
        for (Node node : curLevelNodes) {
          // Node data
          NodePosition nodePosition = _positionByNode.get(node);
          Bounds nodeBounds = node.getLayoutBounds();

          // Get bounds
          widthByPosition.put(nodePosition, nodeBounds.getWidth() + this.getXAxisSpacing());
          levelHeight.put(
              curLevel,
              Math.max(levelHeight.get(curLevel), nodeBounds.getHeight() + this.getYAxisSpacing()));

          // Register positions
          positionsByLevel.get(curLevel).add(nodePosition);

          if (curLevel > 0) {
            positionsByLevel.get(curLevel - 1).add(nodePosition.getParent());
          }
        }
      }

      // Calculate position widths of current level
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        // Register positions
        if (position.getLevel() > 0) {
          NodePosition parentPosition = position.getParent();

          positionsByLevel.get(position.getLevel() - 1).add(parentPosition);

          if (positionsByParentPosition.containsKey(parentPosition) == false) {
            positionsByParentPosition.put(parentPosition, new HashSet<NodePosition>());
          }

          positionsByParentPosition.get(parentPosition).add(position);
        }

        // Get width of children
        double widthOfChildren = 0;

        Set<NodePosition> parentPositions = positionsByParentPosition.get(position);

        if (parentPositions != null) {
          for (NodePosition childPosition : parentPositions) {
            if (widthByPosition.containsKey(childPosition) == true) {
              widthOfChildren += widthByPosition.get(childPosition);
            }
          }
        }

        // Get maximum of node bound and sum of child node bounds
        if (widthByPosition.containsKey(position) == false) {
          widthByPosition.put(position, widthOfChildren);
        } else {
          widthByPosition.put(position, Math.max(widthByPosition.get(position), widthOfChildren));
        }
      }
    }

    // Calculate position boxes
    Map<NodePosition, Rectangle2D> boxesByPosition = new HashMap<>();

    if (positionsByLevel.containsKey(0) == false || positionsByLevel.get(0).size() != 1) {
      throw new IllegalStateException();
    }

    boxesByPosition.put(
        NodePosition.ROOT,
        new Rectangle2D(0, 0, widthByPosition.get(NodePosition.ROOT), levelHeight.get(0)));

    for (int curLevel = 0; curLevel <= maxLevel; ++curLevel) {
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        Rectangle2D positionBox = boxesByPosition.get(position);

        List<NodePosition> childPositions = new ArrayList<>();

        if (positionsByParentPosition.containsKey(position)) {
          childPositions.addAll(positionsByParentPosition.get(position));
        }

        Collections.sort(childPositions);

        double childX = positionBox.getMinX();

        for (NodePosition childPosition : childPositions) {
          double childWidth = widthByPosition.get(childPosition);

          boxesByPosition.put(
              childPosition,
              new Rectangle2D(
                  childX,
                  positionBox.getMaxY(),
                  childWidth,
                  levelHeight.get(childPosition.getLevel())));

          childX += childWidth;
        }
      }
    }

    // Position nodes
    Map<NodePosition, Double> xCenterHintByPosition = new HashMap<>();
    Map<NodePosition, Double> yCenterHintByPosition = new HashMap<>();

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        // Calculate center hints
        Rectangle2D positionBox = boxesByPosition.get(position);

        double xCenterHint = (positionBox.getMinX() + positionBox.getMaxX()) / 2;

        if (xCenterHintByPosition.containsKey(position) == true) {
          xCenterHint = xCenterHintByPosition.get(position);
        }

        double yCenterHint = (positionBox.getMinY() + positionBox.getMaxY()) / 2;

        xCenterHintByPosition.put(position, xCenterHint);
        yCenterHintByPosition.put(position, yCenterHint);

        // Position node
        if (_nodeByPosition.containsKey(position)) {
          Node node = _nodeByPosition.get(position);
          Bounds nodeBounds = node.getLayoutBounds();

          node.relocate(
              xCenterHint - nodeBounds.getWidth() / 2, yCenterHint - nodeBounds.getHeight() / 2);
        }

        // Update parent node position hint
        NodePosition parentPosition = position.getParent();

        if (xCenterHintByPosition.containsKey(parentPosition)) {
          xCenterHintByPosition.put(
              parentPosition, (xCenterHintByPosition.get(parentPosition) + xCenterHint) / 2);
        } else {
          xCenterHintByPosition.put(parentPosition, xCenterHint);
        }
      }
    }

    // Update lines
    if (this.getShowLines() == true) {
      adjustLineCount(boxesByPosition.size() - 1);

      int currentLine = 0;

      for (NodePosition position : boxesByPosition.keySet()) {
        if (positionsByParentPosition.containsKey(position) == false) {
          continue;
        }

        for (NodePosition childPosition : positionsByParentPosition.get(position)) {
          Bounds fromBounds =
              _nodeByPosition.containsKey(position)
                  ? _nodeByPosition.get(position).getLayoutBounds()
                  : null;
          Bounds toBounds =
              _nodeByPosition.containsKey(childPosition)
                  ? _nodeByPosition.get(childPosition).getLayoutBounds()
                  : null;

          Point2D lineFrom =
              new Point2D(
                  xCenterHintByPosition.get(position),
                  yCenterHintByPosition.get(position)
                      + (fromBounds != null ? (fromBounds.getHeight() / 2) : 0)
                      + this.getLineSpacing());

          Point2D lineTo =
              new Point2D(
                  xCenterHintByPosition.get(childPosition),
                  yCenterHintByPosition.get(childPosition)
                      - (toBounds != null ? (toBounds.getHeight() / 2) : 0)
                      - this.getLineSpacing());

          Line l = _lines.get(currentLine);

          l.setStartX(lineFrom.getX());
          l.setStartY(lineFrom.getY());

          l.setEndX(lineTo.getX());
          l.setEndY(lineTo.getY());

          ++currentLine;
        }
      }
    } else {
      adjustLineCount(0);
    }

    // Update preferred size
    double totalHeight = 0;
    for (Double h : levelHeight.values()) {
      totalHeight += h;
    }

    setPrefWidth(widthByPosition.get(NodePosition.ROOT));
    setPrefHeight(totalHeight);
  }
Exemplo n.º 19
0
  private Parent createContent() throws IOException {
    dealer = new Hand(dealerCards.getChildren());
    player = new Hand(playerCards.getChildren());

    Pane root = new Pane();
    root.setPrefSize(windowWidth, windowHeight);

    Region background = new Region();
    background.setPrefSize(windowWidth, windowHeight);
    background.setStyle("-fx-background-image: url('res/images/casino.jpg')");

    HBox rootLayout = new HBox(5);
    rootLayout.setPadding(new Insets(5, 5, 5, 5));
    //        Rectangle leftBG = new Rectangle(550, 560);
    //        leftBG.setArcWidth(50);
    //        leftBG.setArcHeight(50);
    //        leftBG.setFill(Color.GREEN);
    //
    Canvas canvas = new Canvas(560, 560);

    BufferedImage imgi;
    GraphicsContext gcfx = canvas.getGraphicsContext2D();
    // Graphics gc = canvas.getGraphics();
    Image zbyszek = new Image("/res/images/table.png", 560, 560, true, false);

    gcfx.setFill(DARKSLATEGRAY);
    gcfx.fillRoundRect(0, 0, 550, 300, 10, 100);
    gcfx.setFill(BLACK);
    gcfx.drawImage(zbyszek, 0, 280);

    //        try {
    //            imgi = ImageIO.read(Card.class.getResource("/res/images/table.png"));
    //
    //            gcfx.drawImage(imgi, 300, 300, null);
    //            canvas.setVisible(true);
    //        } catch (Exception e) {
    //        }

    Rectangle rightBG = new Rectangle(230, 560);
    rightBG.setArcWidth(50);
    rightBG.setArcHeight(50);
    rightBG.setFill(Color.ORANGE);

    // LEFT
    VBox leftVBox = new VBox(50);
    leftVBox.setAlignment(Pos.TOP_CENTER);

    Text dealerScore = new Text("Dealer: ");
    Text playerScore = new Text("Player: ");

    leftVBox.getChildren().addAll(dealerScore, dealerCards, message, playerCards, playerScore);

    // RIGHT
    VBox rightVBox = new VBox(20);
    rightVBox.setAlignment(Pos.CENTER);

    // final TextField bet = new TextField("BET");
    // bet.setDisable(true);
    // bet.setMaxWidth(50);
    // Text money = new Text("MONEY");
    Button btnPlay = new Button("PLAY");
    Button btnHit = new Button("HIT");
    Button btnStand = new Button("STAND");

    HBox buttonsHBox = new HBox(15, btnHit, btnStand);
    buttonsHBox.setAlignment(Pos.CENTER);

    // rightVBox.getChildren().addAll(bet, btnPlay, money, buttonsHBox);
    rightVBox.getChildren().addAll(btnPlay, buttonsHBox);

    // ADD BOTH STACKS TO ROOT LAYOUT
    rootLayout
        .getChildren()
        .addAll(new StackPane(canvas, leftVBox), new StackPane(rightBG, rightVBox));
    root.getChildren().addAll(background, rootLayout);

    // BIND PROPERTIES
    btnPlay.disableProperty().bind(playable);
    btnHit.disableProperty().bind(playable.not());
    btnStand.disableProperty().bind(playable.not());

    playerScore
        .textProperty()
        .bind(new SimpleStringProperty("Player: ").concat(player.valueProperty().asString()));
    dealerScore
        .textProperty()
        .bind(new SimpleStringProperty("Dealer: ").concat(dealer.valueProperty().asString()));

    player
        .valueProperty()
        .addListener(
            (obs, old, newValue) -> {
              if (newValue.intValue() >= 21) {
                endGame();
              }
            });

    dealer
        .valueProperty()
        .addListener(
            (obs, old, newValue) -> {
              if (newValue.intValue() >= 21) {
                endGame();
              }
            });

    // INIT BUTTONS
    btnPlay.setOnAction(
        event -> {
          startNewGame();
        });

    btnHit.setOnAction(
        event -> {
          player.takeCard(deck.drawCard());
        });

    btnStand.setOnAction(
        event -> {
          while (dealer.valueProperty().get() < 17) {
            dealer.takeCard(deck.drawCard());
          }

          endGame();
        });

    return root;
  }
Exemplo n.º 20
0
 @Override
 protected void layoutChildren() {
   super.layoutChildren();
   container.resizeRelocate(0, 0, getWidth(), getHeight());
 }