Java Code Examples for javafx.geometry.Point2D#getX()

The following examples show how to use javafx.geometry.Point2D#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilitiesPoint2D.java    From JavaFXSmartGraph with MIT License 6 votes vote down vote up
/**
 * Rotate a point around a pivot point by a specific degrees amount
 * @param point point to rotate
 * @param pivot pivot point
 * @param angle_degrees rotation degrees
 * @return rotated point
 */
public static Point2D rotate(final Point2D point, final Point2D pivot, double angle_degrees) {
    double angle = Math.toRadians(angle_degrees); //angle_degrees * (Math.PI/180); //to radians
    
    double sin = Math.sin(angle);
    double cos = Math.cos(angle);

    //translate to origin
    Point2D result = point.subtract(pivot);
    
    // rotate point
    Point2D rotatedOrigin = new Point2D(
            result.getX() * cos - result.getY() * sin,
            result.getX() * sin + result.getY() * cos);

    // translate point back
    result = rotatedOrigin.add(pivot);

    return result;
}
 
Example 2
Source File: Regulator.java    From regulators with Apache License 2.0 6 votes vote down vote up
private void touchRotate(final double X, final double Y) {
    Point2D p      = sceneToLocal(X, Y);
    double  deltaX = p.getX() - (pane.getLayoutX() + size * 0.5);
    double  deltaY = p.getY() - (pane.getLayoutY() + size * 0.5);
    double  radius = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
    double  nx     = deltaX / radius;
    double  ny     = deltaY / radius;
    double  theta  = Math.atan2(ny, nx);
    theta         = Double.compare(theta, 0.0) >= 0 ? Math.toDegrees(theta) : Math.toDegrees((theta)) + 360.0;
    double angle  = (theta + 230) % 360;
    if (angle > 320 && angle < 360) {
        angle = 0;
    } else if (angle <= 320 && angle > ANGLE_RANGE) {
        angle = ANGLE_RANGE;
    }
    setTargetValue(angle / angleStep + minValue.get());
}
 
Example 3
Source File: FridayFunSkin.java    From WorkbenchFX with Apache License 2.0 6 votes vote down vote up
private Group createTicks(double cx, double cy, int numberOfTicks, double overallAngle, double tickLength, double indent, double startingAngle, String styleClass) {
  Group group = new Group();

  double degreesBetweenTicks = overallAngle == 360 ?
      overallAngle / numberOfTicks :
      overallAngle / (numberOfTicks - 1);
  double outerRadius = Math.min(cx, cy) - indent;
  double innerRadius = Math.min(cx, cy) - indent - tickLength;

  for (int i = 0; i < numberOfTicks; i++) {
    double angle = 180 + startingAngle + i * degreesBetweenTicks;

    Point2D startPoint = pointOnCircle(cx, cy, outerRadius, angle);
    Point2D endPoint = pointOnCircle(cx, cy, innerRadius, angle);

    Line tick = new Line(startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY());
    tick.getStyleClass().add(styleClass);
    group.getChildren().add(tick);
  }

  return group;
}
 
Example 4
Source File: RunnerComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
private void checkScreenBounds() {
    if (runner.getX() < 0
            || runner.getY() < 0
            || runner.getRightX() >= screenWidth
            || runner.getBottomY() >= screenHeight) {

        Point2D newDirectionVector = new Point2D(screenWidth / 2, screenHeight / 2)
                .subtract(runner.getCenter());

        double angle = Math.toDegrees(Math.atan(newDirectionVector.getY() / newDirectionVector.getX()));
        directionAngle = newDirectionVector.getX() > 0 ? angle : 180 + angle;
    }
}
 
Example 5
Source File: JavaFXListViewItemElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((ListCell<?>) cell);
    Point2D targetXY = node.localToScene(xoffset, yoffset);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
Example 6
Source File: JavaFXTreeViewNodeElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((TreeCell<?>) cell);
    Point2D targetXY = node.localToScene(xoffset, yoffset);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
Example 7
Source File: WSRecorder.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void recordClick2(final RFXComponent r, MouseEvent e, boolean withCellInfo) {
    final JSONObject event = new JSONObject();
    event.put("type", "click");
    int button = e.getButton() == MouseButton.PRIMARY ? java.awt.event.MouseEvent.BUTTON1 : java.awt.event.MouseEvent.BUTTON3;
    event.put("button", button);
    event.put("clickCount", e.getClickCount());
    event.put("modifiersEx", buildModifiersText(e));
    double x = e.getX();
    double y = e.getY();
    Node source = (Node) e.getSource();
    Node target = r.getComponent();
    Point2D sts = source.localToScreen(new Point2D(0, 0));
    Point2D tts = target.localToScreen(new Point2D(0, 0));
    x = e.getX() - tts.getX() + sts.getX();
    y = e.getY() - tts.getY() + sts.getY();
    event.put("x", x);
    event.put("y", y);
    if (withCellInfo) {
        event.put("cellinfo", r.getCellInfo());
    }
    final JSONObject o = new JSONObject();
    o.put("event", event);
    fill(r, o);
    if (e.getClickCount() == 1) {
        clickTimer = new Timer();
        clickTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                sendRecordMessage(o);
            }
        }, timerinterval.intValue());
    } else if (e.getClickCount() == 2) {
        if (clickTimer != null) {
            clickTimer.cancel();
            clickTimer = null;
        }
        sendRecordMessage(o);
    }
}
 
Example 8
Source File: TreeConnectionSkin.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Draws the 'selection halo' that indicates that the connection is selected.
 */
private void drawSelectionHalo() {

    final Point2D arrowStart = arrow.getStart();
    final Point2D arrowEnd = arrow.getEnd();

    final double deltaX = arrowEnd.getX() - arrowStart.getX();
    final double deltaY = arrowEnd.getY() - arrowStart.getY();

    final double angle = Math.atan2(deltaX, deltaY);

    final double breadthOffsetX = HALO_BREADTH_OFFSET * Math.cos(angle);
    final double breadthOffsetY = HALO_BREADTH_OFFSET * Math.sin(angle);

    final double lengthOffsetStartX = HALO_LENGTH_OFFSET_START * Math.sin(angle);
    final double lengthOffsetStartY = HALO_LENGTH_OFFSET_START * Math.cos(angle);

    final double lengthOffsetEndX = HALO_LENGTH_OFFSET_END * Math.sin(angle);
    final double lengthOffsetEndY = HALO_LENGTH_OFFSET_END * Math.cos(angle);

    haloFirstSide.setStartX(GeometryUtils.moveOffPixel(arrowStart.getX() - breadthOffsetX + lengthOffsetStartX));
    haloFirstSide.setStartY(GeometryUtils.moveOffPixel(arrowStart.getY() + breadthOffsetY + lengthOffsetStartY));

    haloSecondSide.setStartX(GeometryUtils.moveOffPixel(arrowStart.getX() + breadthOffsetX + lengthOffsetStartX));
    haloSecondSide.setStartY(GeometryUtils.moveOffPixel(arrowStart.getY() - breadthOffsetY + lengthOffsetStartY));

    haloFirstSide.setEndX(GeometryUtils.moveOffPixel(arrowEnd.getX() - breadthOffsetX - lengthOffsetEndX));
    haloFirstSide.setEndY(GeometryUtils.moveOffPixel(arrowEnd.getY() + breadthOffsetY - lengthOffsetEndY));

    haloSecondSide.setEndX(GeometryUtils.moveOffPixel(arrowEnd.getX() + breadthOffsetX - lengthOffsetEndX));
    haloSecondSide.setEndY(GeometryUtils.moveOffPixel(arrowEnd.getY() - breadthOffsetY - lengthOffsetEndY));
}
 
Example 9
Source File: UICanvas.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	MouseButton btn = event.getButton();
	if (!(event.getTarget() instanceof Canvas)) {
		return;
	}

	Canvas c = (Canvas) event.getTarget();
	Point2D p = c.sceneToLocal(event.getSceneX(), event.getSceneY());
	int mousex = (int) p.getX();
	int mousey = (int) p.getY();

	if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
		canvas.mouseMoved(mousex, mousey);
		canvas.setLastMousePosition(mousex, mousey);
		if (mouseDown) {
			this.canvas.requestPaint();
		}
	} else {
		if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
			mouseDown = true;
			canvas.mousePressed(mousex, mousey, btn);
		} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
			canvas.mouseReleased(mousex, mousey, btn);
			mouseDown = false;
			canvas.requestPaint();
		}
	}

}
 
Example 10
Source File: AnimatedTableRow.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private Point2D computeAnimationEndPoint(
		final TableView<Person> destinationTable) {
	// End animation at first row (bottom of table header)
	final Node toTableHeader = destinationTable.lookup(".column-header-background");
	if (toTableHeader != null) {
		final Bounds tableHeaderBounds = toTableHeader.localToScene(toTableHeader.getBoundsInLocal()); // relative to Scene
		Point2D animationEndPoint = new Point2D(tableHeaderBounds.getMinX(), tableHeaderBounds.getMaxY());
		return animationEndPoint;
	} else { // fallback in case lookup fails for some reason
	    // just approximate at 24 pixels below top of table:
	    Point2D tableLocation = destinationTable.localToScene(new Point2D(0,0));
	    return new Point2D(tableLocation.getX(), tableLocation.getY() + 24);
	}
}
 
Example 11
Source File: WebEventDispatcher.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {

	if (event instanceof MouseEvent){
        MouseEvent m = (MouseEvent)event;
        if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED) ||
            event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
            Point2D origin = new Point2D(m.getX(),m.getY());
            if (limit != null)
            	allowDrag = !(origin.getX() < limit.getX() && origin.getY() < limit.getY());
        }

        // avoid selection with mouse dragging, allowing dragging the scrollbars
        if (event.getEventType().equals(MouseEvent.MOUSE_DRAGGED)) {
            if(!allowDrag){
                event.consume();
            }
        }
        // Avoid selection of word, line, paragraph with mouse click
        if(m.getClickCount() > 1){
            event.consume();
        }
    }

    if (event instanceof KeyEvent && event.getEventType().equals(KeyEvent.KEY_PRESSED)){
        KeyEvent k = (KeyEvent)event;
        // Avoid copy with Ctrl+C or Ctrl+Insert
        if((k.getCode().equals(KeyCode.C) || k.getCode().equals(KeyCode.INSERT)) && k.isControlDown()){
            event.consume();
        }
        // Avoid selection with shift+Arrow
        if(k.isShiftDown() && (k.getCode().equals(KeyCode.RIGHT) || k.getCode().equals(KeyCode.LEFT) ||
            k.getCode().equals(KeyCode.UP) || k.getCode().equals(KeyCode.DOWN))){
            event.consume();
        }
    }
    return oldDispatcher.dispatchEvent(event, tail);
}
 
Example 12
Source File: SmartGraphPanel.java    From JavaFXSmartGraph with MIT License 5 votes vote down vote up
private void computeForces() {
    for (SmartGraphVertexNode<V> v : vertexNodes.values()) {
        for (SmartGraphVertexNode<V> other : vertexNodes.values()) {
            if (v == other) {
                continue; //NOP
            }

            //double k = Math.sqrt(getWidth() * getHeight() / graphVertexMap.size());
            Point2D repellingForce = repellingForce(v.getUpdatedPosition(), other.getUpdatedPosition(), this.repulsionForce);

            double deltaForceX = 0, deltaForceY = 0;

            //compute attractive and reppeling forces
            //opt to use internal areAdjacent check, because a vertex can be removed from
            //the underlying graph before we have the chance to remove it from our
            //internal data structure
            if (areAdjacent(v, other)) {

                Point2D attractiveForce = attractiveForce(v.getUpdatedPosition(), other.getUpdatedPosition(),
                        vertexNodes.size(), this.attractionForce, this.attractionScale);

                deltaForceX = attractiveForce.getX() + repellingForce.getX();
                deltaForceY = attractiveForce.getY() + repellingForce.getY();
            } else {
                deltaForceX = repellingForce.getX();
                deltaForceY = repellingForce.getY();
            }

            v.addForceVector(deltaForceX, deltaForceY);
        }
    }
}
 
Example 13
Source File: PlainClockSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void drawTicks() {
    double  sinValue;
    double  cosValue;
    double  startAngle             = 180;
    double  angleStep              = 360 / 60;
    Point2D center                 = new Point2D(size * 0.5, size * 0.5);
    Color   hourTickMarkColor      = clock.getHourTickMarkColor();
    Color   minuteTickMarkColor    = clock.getMinuteTickMarkColor();
    boolean hourTickMarksVisible   = clock.isHourTickMarksVisible();
    boolean minuteTickMarksVisible = clock.isMinuteTickMarksVisible();
    tickCtx.clearRect(0, 0, size, size);
    tickCtx.setLineCap(StrokeLineCap.BUTT);
    tickCtx.setLineWidth(size * 0.00539811);
    for (double angle = 0, counter = 0 ; Double.compare(counter, 59) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint       = new Point2D(center.getX() + size * 0.40350877 * sinValue, center.getY() + size * 0.40350877 * cosValue);
        Point2D innerMinutePoint = new Point2D(center.getX() + size * 0.451417 * sinValue, center.getY() + size * 0.451417 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + size * 0.47435897 * sinValue, center.getY() + size * 0.47435897 * cosValue);

        if (counter % 5 == 0) {
            tickCtx.setStroke(hourTickMarkColor);
            if (hourTickMarksVisible) {
                tickCtx.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());
            } else if (minuteTickMarksVisible) {
                tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
            }
        } else if (counter % 1 == 0 && minuteTickMarksVisible) {
            tickCtx.setStroke(minuteTickMarkColor);
            tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 14
Source File: TimerControlTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void drawTicks() {
    minuteTickMarks.setCache(false);
    hourTickMarks.setCache(false);
    minuteTickMarks.getElements().clear();
    hourTickMarks.getElements().clear();
    double  sinValue;
    double  cosValue;
    double  startAngle             = 180;
    double  angleStep              = 360 / 60;
    Point2D center                 = new Point2D(clockSize * 0.5, clockSize * 0.5);
    boolean hourTickMarksVisible   = tile.isHourTickMarksVisible();
    boolean minuteTickMarksVisible = tile.isMinuteTickMarksVisible();
    for (double angle = 0, counter = 0 ; Double.compare(counter, 59) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerPoint       = new Point2D(center.getX() + clockSize * 0.405 * sinValue, center.getY() + clockSize * 0.405 * cosValue);
        Point2D innerMinutePoint = new Point2D(center.getX() + clockSize * 0.435 * sinValue, center.getY() + clockSize * 0.435 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + clockSize * 0.465 * sinValue, center.getY() + clockSize * 0.465 * cosValue);

        if (counter % 5 == 0) {
            // Draw hour tickmark
            if (hourTickMarksVisible) {
                hourTickMarks.setStrokeWidth(clockSize * 0.01);
                hourTickMarks.getElements().add(new MoveTo(innerPoint.getX(), innerPoint.getY()));
                hourTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
            } else if (minuteTickMarksVisible) {
                minuteTickMarks.setStrokeWidth(clockSize * 0.005);
                minuteTickMarks.getElements().add(new MoveTo(innerMinutePoint.getX(), innerMinutePoint.getY()));
                minuteTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
            }
        } else if (counter % 1 == 0 && minuteTickMarksVisible) {
            // Draw minute tickmark
            minuteTickMarks.setStrokeWidth(clockSize * 0.005);
            minuteTickMarks.getElements().add(new MoveTo(innerMinutePoint.getX(), innerMinutePoint.getY()));
            minuteTickMarks.getElements().add(new LineTo(outerPoint.getX(), outerPoint.getY()));
        }
    }
    minuteTickMarks.setCache(true);
    minuteTickMarks.setCacheHint(CacheHint.QUALITY);
    hourTickMarks.setCache(true);
    hourTickMarks.setCacheHint(CacheHint.QUALITY);
}
 
Example 15
Source File: RunPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
public void handleAttributeMoved(double sceneX, double sceneY) {
    if (draggingAttributeNode != null) {
        final Point2D location = sceneToLocal(sceneX, sceneY);

        double x = location.getX() - draggingOffset.getX();
        if (x < 0) {
            x = 0;
        }
        if (x > RunPane.this.getWidth() - draggingAttributeNode.getWidth()) {
            x = RunPane.this.getWidth() - draggingAttributeNode.getWidth();
        }

        double y = location.getY() - draggingOffset.getY();
        if (y < 0) {
            y = 0;
        }
        if (y > RunPane.this.getHeight() - draggingAttributeNode.getHeight()) {
            y = RunPane.this.getHeight() - draggingAttributeNode.getHeight();
        }

        draggingAttributeNode.setLayoutX(x);
        draggingAttributeNode.setLayoutY(y);

        final Point2D tableLocation = sampleDataView.sceneToLocal(sceneX, sceneY);

        double offset = 0;
        Set<Node> nodes = sampleDataView.lookupAll(".scroll-bar");
        for (final Node node : nodes) {
            if (node instanceof ScrollBar) {
                final ScrollBar scrollBar = (ScrollBar) node;
                if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
                    offset = scrollBar.getValue();
                    break;
                }
            }
        }

        double totalWidth = 0;
        mouseOverColumn = null;

        final double cellPadding = 0.5; // ?
        if (tableLocation.getX() >= 0 && tableLocation.getX() <= sampleDataView.getWidth() && tableLocation.getY() >= 0 && tableLocation.getY() <= sampleDataView.getHeight()) {
            double columnLocation = tableLocation.getX() + offset;
            for (TableColumn<TableRow, ?> column : sampleDataView.getColumns()) {
                totalWidth += column.getWidth() + cellPadding;
                if (columnLocation < totalWidth) {
                    mouseOverColumn = (ImportTableColumn) column;
                    break;
                }
            }
        }

        if (mouseOverColumn != null) {
            // Allow for the SplitPane left side inset+padding (1+1 hard-coded).
            final double edge = 2;

            columnRectangle.setLayoutX(edge + sampleDataView.getLayoutX() + totalWidth - mouseOverColumn.getWidth() - offset);
            columnRectangle.setLayoutY(sampleDataView.getLayoutY());
            columnRectangle.setWidth(mouseOverColumn.getWidth());
            columnRectangle.setHeight(sampleDataView.getHeight());
            columnRectangle.setVisible(true);
        } else {
            columnRectangle.setVisible(false);
        }
    }
}
 
Example 16
Source File: GridComponent.java    From FXGLGames with MIT License 4 votes vote down vote up
public GridComponent(GraphicsContext g) {
    this.g = g;

    Point2D spacing = new Point2D(38.8, 40);

    int numColumns = (int) (getAppWidth() / spacing.getX()) + 2;
    int numRows = (int) (getAppHeight() / spacing.getY()) + 2;
    points = new PointMass[numColumns][numRows];

    PointMass[][] fixedPoints = new PointMass[numColumns][numRows];

    // create the point masses
    float xCoord = 0, yCoord = 0;
    for (int row = 0; row < numRows; row++) {
        for (int column = 0; column < numColumns; column++) {
            points[column][row] = new PointMass(new Vec2(xCoord, yCoord), POINT_MASS_DAMPING, 1);
            fixedPoints[column][row] = new PointMass(new Vec2(xCoord, yCoord), POINT_MASS_DAMPING, 0);
            xCoord += spacing.getX();
        }
        yCoord += spacing.getY();
        xCoord = 0;
    }

    // link the point masses with springs
    for (int y = 0; y < numRows; y++) {
        for (int x = 0; x < numColumns; x++) {
            if (x == 0 || y == 0 || x == numColumns - 1 || y == numRows - 1) {
                springs.add(new Spring(fixedPoints[x][y], points[x][y], 0.5, 0.1));
            } else if (x % 3 == 0 && y % 3 == 0) {
                springs.add(new Spring(fixedPoints[x][y], points[x][y], 0.005, 0.02));
            }

            if (x > 0) {
                springs.add(new Spring(points[x - 1][y], points[x][y], SPRING_STIFFNESS, SPRING_DAMPING));

                addLine(points[x - 1][y], points[x][y]);
            }

            if (y > 0) {
                springs.add(new Spring(points[x][y - 1], points[x][y], SPRING_STIFFNESS, SPRING_DAMPING));

                addLine(points[x][y - 1], points[x][y]);
            }

            // add additional lines
            if (x > 0 && y > 0) {
                addExtraLine(
                        points[x - 1][y], points[x][y],
                        points[x - 1][y - 1], points[x][y - 1]);

                addExtraLine(
                        points[x][y - 1], points[x][y],
                        points[x - 1][y - 1], points[x - 1][y]);
            }
        }
    }
}
 
Example 17
Source File: MapView.java    From maps with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center point of this map
 * @return the center point
 */
public MapPoint getCenter() {
    Point2D center = baseMap.getCenter();
    return new MapPoint(center.getX(), center.getY());
}
 
Example 18
Source File: DBClockSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTicks() {
    double  sinValue;
    double  cosValue;
    double  startAngle             = 180;
    double  angleStep              = 360 / 60;
    Point2D center                 = new Point2D(size * 0.5, size * 0.5);
    Color   hourTickMarkColor      = clock.getHourTickMarkColor();
    Color   minuteTickMarkColor    = clock.getMinuteTickMarkColor();
    boolean hourTickMarksVisible   = clock.isHourTickMarksVisible();
    boolean minuteTickMarksVisible = clock.isMinuteTickMarksVisible();
    tickCtx.clearRect(0, 0, size, size);
    tickCtx.setLineCap(StrokeLineCap.BUTT);
    for (double angle = 0, counter = 0 ; Double.compare(counter, 59) <= 0 ; angle -= angleStep, counter++) {
        sinValue = Math.sin(Math.toRadians(angle + startAngle));
        cosValue = Math.cos(Math.toRadians(angle + startAngle));

        Point2D innerMainPoint   = new Point2D(center.getX() + size * 0.335 * sinValue, center.getY() + size * 0.335 * cosValue);
        Point2D innerPoint       = new Point2D(center.getX() + size * 0.365 * sinValue, center.getY() + size * 0.365 * cosValue);
        Point2D innerMinutePoint = new Point2D(center.getX() + size * 0.425 * sinValue, center.getY() + size * 0.425 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + size * 0.465 * sinValue, center.getY() + size * 0.465 * cosValue);

        if (counter % 5 == 0 && counter % 3 == 0) {
            // Draw 12, 3, 6, 9 hour tickmark
            tickCtx.setStroke(hourTickMarkColor);
            if (hourTickMarksVisible) {
                tickCtx.setLineWidth(size * 0.0375);
                tickCtx.strokeLine(innerMainPoint.getX(), innerMainPoint.getY(), outerPoint.getX(), outerPoint.getY());
            } else if (minuteTickMarksVisible) {
                tickCtx.setLineWidth(size * 0.02);
                tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
            }
        } else if (counter % 5 == 0) {
            // Draw hour tickmark
            tickCtx.setStroke(hourTickMarkColor);
            if (hourTickMarksVisible) {
                tickCtx.setLineWidth(size * 0.0375);
                tickCtx.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());
            } else if (minuteTickMarksVisible){
                tickCtx.setLineWidth(size * 0.02);
                tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
            }
        } else if (counter % 1 == 0 && minuteTickMarksVisible) {
            // Draw minute tickmark
            tickCtx.setStroke(minuteTickMarkColor);
            tickCtx.setLineWidth(size * 0.02);
            tickCtx.strokeLine(innerMinutePoint.getX(), innerMinutePoint.getY(), outerPoint.getX(), outerPoint.getY());
        }
    }
}
 
Example 19
Source File: FX2Geometry.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Converts the given JavaFX {@link Point2D} to a {@link Point}.
 * 
 * @param point
 *            The {@link Point2D} to convert.
 * @return The new {@link Point}.
 */
public static final Point toPoint(Point2D point) {
	return new Point(point.getX(), point.getY());
}
 
Example 20
Source File: TailManager.java    From graph-editor with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Corrects the cursor position in the case where scale transforms are applied.
 * 
 * @param cursorPosition the cursor position calculated assuming scale factor of 1
 * 
 * @return the corrected cursor position
 */
private Point2D getScaledPosition(final Point2D cursorPosition) {

    final double scale = view.getLocalToSceneTransform().getMxx();
    return new Point2D(cursorPosition.getX() / scale, cursorPosition.getY() / scale);
}