Java 类javafx.geometry.Point2D 实例源码

项目:marathonv5    文件:JavaFXElementPropertyAccessor.java   
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
项目:marathonv5    文件:JavaFXTableViewElementScrollTest.java   
@Test public void scrollToRow() throws Throwable {
    Stage primaryStage = getPrimaryStage();
    primaryStage.setWidth(250);
    primaryStage.setHeight(250);
    TableView<?> tableViewNode = (TableView<?>) primaryStage.getScene().getRoot().lookup(".table-view");
    Platform.runLater(() -> {
        tableView.marathon_select("{\"rows\":[10]}");
    });
    new Wait("Wating for rows to be select.") {
        @Override public boolean until() {
            return tableViewNode.getSelectionModel().getSelectedIndex() == 10;
        }
    };
    new Wait("Waiting for the point to be in viewport") {
        @Override public boolean until() {
            Point2D point = getPoint(tableViewNode, 1, 10);
            return tableViewNode.getBoundsInLocal().contains(point);
        }
    };
}
项目:marathonv5    文件:RFXTableViewTextFieldTableCellTest.java   
@Test public void select() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        Point2D point = getPoint(tableView, 1, 1);
        TableCellFactorySample.EditingCell tf = (EditingCell) getCellAt(tableView, 1, 1);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        tf.startEdit();
        tf.updateItem("Cell Modified", false);
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Cell Modified", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeTableViewTest.java   
@SuppressWarnings("unchecked") @Test public void selectACell() {
    TreeTableView<?> treeTableView = (TreeTableView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        TreeTableViewSelectionModel<?> selectionModel = treeTableView.getSelectionModel();
        selectionModel.setCellSelectionEnabled(true);
        Point2D point = getPoint(treeTableView, 1, 0);
        RFXTreeTableView rfxTreeTableView = new RFXTreeTableView(treeTableView, null, point, lr);
        rfxTreeTableView.focusGained(null);
        @SuppressWarnings("rawtypes")
        TreeTableColumn column = getTreeTableColumnAt(treeTableView, 0);
        selectionModel.select(1, column);
        rfxTreeTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("{\"cells\":[[\"/Sales Department/Ethan Williams\",\"Employee\"]]}", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXButtonBaseTest.java   
@Test public void click() {
    Button button = (Button) getPrimaryStage().getScene().getRoot().lookup(".button");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            RFXButtonBase rfxButtonBase = new RFXButtonBase(button, null, null, lr);
            Point2D sceneXY = button.localToScene(new Point2D(3, 3));
            PickResult pickResult = new PickResult(button, sceneXY.getX(), sceneXY.getY());
            Point2D screenXY = button.localToScreen(new Point2D(3, 3));
            MouseEvent me = new MouseEvent(button, button, MouseEvent.MOUSE_PRESSED, 3, 3, sceneXY.getX(), screenXY.getY(),
                    MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, pickResult);
            rfxButtonBase.mouseButton1Pressed(me);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording select = recordings.get(0);
    AssertJUnit.assertEquals("click", select.getCall());
    AssertJUnit.assertEquals("", select.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeViewCheckBoxTreeCellTest.java   
@Test public void select() {
    TreeView<?> treeView = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            Point2D point = getPoint(treeView, 1);
            RFXTreeView rfxListView = new RFXTreeView(treeView, null, point, lr);
            rfxListView.focusGained(rfxListView);
            CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeView.getTreeItem(1);
            treeItem.setSelected(true);
            rfxListView.focusLost(rfxListView);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Child Node 1:checked", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeViewComboBoxListCellTest.java   
@Test public void selectEditable() {
    @SuppressWarnings("unchecked")
    TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        @SuppressWarnings("unchecked")
        ComboBoxTreeCell<String> cell = (ComboBoxTreeCell<String>) getCellAt(treeView, 1);
        cell.setComboBoxEditable(true);
        Point2D point = getPoint(treeView, 1);
        RFXTreeView rfxtreeView = new RFXTreeView(treeView, null, point, lr);
        rfxtreeView.focusGained(rfxtreeView);
        cell.startEdit();
        cell.updateItem("Option 5", false);
        cell.commitEdit("Option 5");
        rfxtreeView.focusLost(rfxtreeView);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Option 5", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeViewCheckBoxTreeCellTest.java   
@Test public void selectSelectedTreeItemCheckBox() {
    TreeView<?> treeView = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            Point2D point = getPoint(treeView, 1);
            RFXTreeView rfxListView = new RFXTreeView(treeView, null, point, lr);
            CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeView.getTreeItem(1);
            treeItem.setSelected(true);
            rfxListView.focusGained(rfxListView);
            treeItem.setSelected(false);
            rfxListView.focusLost(rfxListView);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Child Node 1:unchecked", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXListViewCheckBoxListCellTest.java   
@Test public void selectListItemCheckBox() {
    ListView<?> listView = (ListView<?>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override public void run() {
            Point2D point = getPoint(listView, 5);
            RFXListView rfxListView = new RFXListView(listView, null, point, lr);
            rfxListView.focusGained(rfxListView);
            Item x = (Item) listView.getItems().get(5);
            x.setOn(true);
            rfxListView.focusLost(rfxListView);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Item 6:checked", recording.getParameters()[0]);
}
项目:marathonv5    文件:JavaFXElementPropertyAccessor.java   
protected int getIndexAt(ListView<?> listView, Point2D point) {
    if (point == null) {
        return listView.getSelectionModel().getSelectedIndex();
    }
    point = listView.localToScene(point);
    Set<Node> lookupAll = getListCells(listView);
    ListCell<?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (ListCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
项目:voogasalad-ltub    文件:ImageTransformation.java   
@Override
public Set<Point2D> getMask(Image image, Color color) {
    PixelReader pixelReader = image.getPixelReader();
    Set<Point2D> mask = new HashSet<>();
    int pixel;
    boolean isTransparent, isBackgroundColor;
    for(int i =0; i < image.getWidth(); i++){
        for(int j = 0; j < image.getHeight(); j++){
            pixel = pixelReader.getArgb(i, j);
            //check the transparency of the pixel at (i,j)
            isTransparent = (pixel >> 24) == 0x00;              
            Color backgroundColor = pixelReader.getColor(i, j);
            isBackgroundColor = (color.equals(backgroundColor));
            if(!isTransparent && !isBackgroundColor){
                Point2D p = new Point2D(i,j);
                mask.add(p);
            }
        }
    }
    return mask;
}
项目:marathonv5    文件:JavaServer.java   
public void buttonup(JSONObject query, JSONObject uriParams, Session session) {
    int button = 0;
    if (query.has("button")) {
        button = query.getInt("button");
    }
    IJavaFXElement element = null;
    double xoffset;
    double yoffset;
    if (lastComponenet.element != null) {
        element = lastComponenet.element;
        xoffset = lastComponenet.x;
        yoffset = lastComponenet.y;
    } else {
        element = session.getActiveElement();
        Point2D p = element.getMidpoint();
        xoffset = p.getX();
        yoffset = p.getY();
    }
    element.buttonUp(button, xoffset, yoffset);
}
项目:DeskChan    文件:MovablePane.java   
protected void loadPositionFromStorage() {
    try {
        final String key = getCurrentPositionStorageKey();
        if (key != null) {
            final String value = Main.getProperties().getString(key);
            if (value != null) {
                String[] coords = value.split(";");
                if (coords.length == 2) {
                    double x = Double.parseDouble(coords[0]);
                    double y = Double.parseDouble(coords[1]);
                    Rectangle2D desktop = OverlayStage.getDesktopSize();
                    if(desktop.getWidth() == 0 || desktop.getHeight() == 0) return;
                    if (x + getHeight() > desktop.getMaxX() || x < -getHeight())
                        x = desktop.getMaxX() - getHeight();
                    if (y + getWidth() > desktop.getMaxY() || y < -getWidth()) y = desktop.getMaxY() - getWidth();
                    setPosition(new Point2D(x, y));
                    return;
                }
            }
        }
    } catch (Exception e){ Main.log(e); }
    setDefaultPosition();
}
项目:octoBubbles    文件:GraphTest.java   
@Test
public void testGraph() {
    Graph graph = new Graph();
    PackageNode packageNode = new PackageNode(0, 0 ,150, 150);
    ClassNode c1 = new ClassNode(0, 0, 25, 25);
    ClassNode c2 = new ClassNode(50, 50, 25, 25);
    EnumerationNode e1 = new EnumerationNode(100, 100, 25, 25);

    packageNode.addChild(c1);
    packageNode.addChild(c2);
    packageNode.addChild(e1);

    Point2D p1 = new Point2D(12, 12);
    Point2D p2 = new Point2D(70, 70);
    Point2D p3 = new Point2D(112, 112);
    Point2D p4 = new Point2D(140, 140);
    graph.addNode(packageNode, false);
    graph.addNode(c1, false);
    graph.addNode(c2, false);
    graph.addNode(e1, false);
    assertEquals(graph.findNode(p1), c1);
    assertEquals(graph.findNode(p2), c2);
    assertEquals(graph.findNode(p3), e1);
    assertEquals(graph.findNode(p4), packageNode);
}
项目:marathonv5    文件:RFXTableViewChoiceBoxTableCell.java   
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void select() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        Point2D point = getPoint(tableView, 2, 1);
        ChoiceBoxTableCell cell = (ChoiceBoxTableCell) getCellAt(tableView, 1, 2);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        cell.startEdit();
        tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
        Person person = (Person) tableView.getItems().get(1);
        person.setLastName("Jones");
        cell.commitEdit("Jones");
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
项目:voogasalad-ltub    文件:ScreenObjectHolder.java   
private void targetSetOnDragDropped(ScreenMap target, DragEvent e) {
    Dragboard db = e.getDragboard();
    boolean success = false;
    if (e.getDragboard().hasImage()) {
        String imageName = db.getString();
        Point2D point = target.sceneToLocal(e.getSceneX(), e.getSceneY());
        GamePoint gameCoords = new GamePoint(point.getX()/target.getScreenWidth(), point.getY()/target.getScreenHeight());
        for (Pair<String, Image> p : myScreenObjects.keySet()) {
            String iName = p.getKey();
            if (imageName.equals(iName)) {
                XStreamHandler xstream = new XStreamHandler();
                File tempSpriteFile = new File("data/tempSprites/tempSprite.xml");
                xstream.saveToFile(myScreenObjects.get(p), tempSpriteFile);
                SpriteMakerModel xmlSprite = (SpriteMakerModel) xstream.getAttributeFromFile(tempSpriteFile);
                xmlSprite.addComponent(new Position(gameCoords, 0)); //heading 0 because all sprites default to this
                myModel.addBackgroundTile(xmlSprite);
                break;
            }
        }
        success = true;
    }
    e.setDropCompleted(success);
    e.consume();
}
项目:DeskChan    文件:SingleImageSkin.java   
@Override
public void overridePreferredBalloonPosition(String imageName, Point2D position) {
    try {
        String key = "balloon_offset";
        String value = String.valueOf(position.getX()) + ";" +
                String.valueOf(position.getY());
        String oldValue = properties.getProperty(key);
        if ((oldValue != null) && oldValue.equals(value)) {
            return;
        }
        properties.setProperty(key, value);
        properties.store(Files.newBufferedWriter(propertiesPath), "Skin properties");
    } catch (Throwable e) {
        Main.log(e);
    }
}
项目:marathonv5    文件:RFXListViewComboBoxListCell.java   
@Test public void select() {
    @SuppressWarnings("unchecked")
    ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        @SuppressWarnings("unchecked")
        ComboBoxListCell<String> cell = (ComboBoxListCell<String>) getCellAt(listView, 3);
        Point2D point = getPoint(listView, 3);
        RFXListView rfxListView = new RFXListView(listView, null, point, lr);
        rfxListView.focusGained(rfxListView);
        cell.startEdit();
        cell.updateItem("Option 3", false);
        cell.commitEdit("Option 3");
        rfxListView.focusLost(rfxListView);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Option 3", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeViewTextFieldTreeCellTest.java   
@Test public void select() {
    @SuppressWarnings("unchecked")
    TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        @SuppressWarnings("unchecked")
        TextFieldTreeCell<String> cell = (TextFieldTreeCell<String>) getCellAt(treeView, 2);
        Point2D point = getPoint(treeView, 2);
        RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr);
        rfxTreeView.focusGained(rfxTreeView);
        cell.startEdit();
        cell.updateItem("Child node 4 Modified", false);
        cell.commitEdit("Child node 4 Modified");
        rfxTreeView.focusLost(rfxTreeView);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Child node 4 Modified", recording.getParameters()[0]);
}
项目:marathonv5    文件:RFXTreeViewChoiceBoxTreeCellTest.java   
@Test public void select() {
    @SuppressWarnings("unchecked")
    TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        @SuppressWarnings("unchecked")
        ChoiceBoxTreeCell<String> cell = (ChoiceBoxTreeCell<String>) getCellAt(treeView, 1);
        Point2D point = getPoint(treeView, 1);
        RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr);
        rfxTreeView.focusGained(rfxTreeView);
        cell.startEdit();
        cell.updateItem("Option 5", false);
        cell.commitEdit("Option 5");
        rfxTreeView.focusLost(rfxTreeView);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Option 5", recording.getParameters()[0]);
}
项目:octoBubbles    文件:PackageTest.java   
@Test
public void testModelPackage() {
    PackageNode pNode = new PackageNode(0, 0, 150, 150);
    ClassNode c1 = new ClassNode(0, 0, 25, 25);
    ClassNode c2 = new ClassNode(50, 50, 25, 25);
    EnumerationNode e1 = new EnumerationNode(100, 100, 25, 25);

    pNode.addChild(c1);
    pNode.addChild(c2);
    pNode.addChild(e1);

    Point2D p1 = new Point2D(12, 12);
    Point2D p2 = new Point2D(70, 70);
    Point2D p3 = new Point2D(112, 112);
    assertEquals(pNode.findNode(p1), c1);
    assertEquals(pNode.findNode(p2), c2);
    assertEquals(pNode.findNode(p3), e1);
}
项目:shuffleboard    文件:CurvedArrow.java   
/**
 * Generates the head of a straight arrow.
 */
private static Triangle straightHead(double startAngle, double size, double xOffset, double bodyLength) {
  final double base = size / 2;

  // Unit vector to the end of the shaft
  double ux = Math.cos(startAngle);
  double uy = Math.sin(startAngle);

  // Unit vector to the center of the base of the head
  double bx = Math.cos(startAngle + Math.PI / 2) * base; // ==  Math.sin(startAngle)
  double by = Math.sin(startAngle + Math.PI / 2) * base; // == -Math.cos(startAngle)

  Point2D basePoint1 = new Point2D(ux * bodyLength - bx + xOffset, uy * bodyLength - by);
  Point2D basePoint2 = new Point2D(ux * bodyLength + bx + xOffset, uy * bodyLength + by);
  Point2D tip = new Point2D(ux * (size + bodyLength) + xOffset, uy * (size + bodyLength));
  return new Triangle(basePoint1, basePoint2, tip);
}
项目:marathonv5    文件:RFXTableViewComboBoxTableCell.java   
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void selectEditable() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        Point2D point = getPoint(tableView, 2, 1);
        ComboBoxTableCell cell = (ComboBoxTableCell) getCellAt(tableView, 1, 2);
        cell.setEditable(true);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        cell.startEdit();
        tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
        Person person = (Person) tableView.getItems().get(1);
        person.setLastName("Jones");
        cell.commitEdit("Jones");
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
项目:GraphCreator    文件:LineGraph.java   
public void renderGraph(){
    //Calculate smooth curve
    //see: https://medium.com/@francoisromain/smooth-a-svg-path-with-cubic-bezier-curves-e37b49d46c74
    Point2D controlStart;
    Point2D controlEnd;
    path += "L"+points.get(0).getX()+","+points.get(0).getY();

    controlStart = getControlPoint(null, points.get(0), points.get(1), false);
    controlEnd = getControlPoint(points.get(0), points.get(1), points.get(2), true);

    path += "C"+controlStart.getX()+","+controlStart.getY()+","+controlEnd.getX()+","+controlEnd.getY()+","+
            points.get(1).getX()+","+points.get(1).getY();


    for(int i = 2; i<points.size()-1; i++) {
        controlStart = getControlPoint(points.get(i - 2), points.get(i - 1), points.get(i), false);
        controlEnd = getControlPoint(points.get(i - 1), points.get(i), points.get(i + 1), true);
        path += "C" + controlStart.getX() + "," + controlStart.getY() + "," + controlEnd.getX() + "," + controlEnd.getY() + "," +
                points.get(i).getX() + "," + points.get(i).getY();
    }

    int last = points.size() - 1;
    controlStart = getControlPoint(points.get(last - 1), points.get(last), null, false);
    controlEnd = getControlPoint(points.get(last), null , null, true);
    path += "C" + controlStart.getX() + "," + controlStart.getY() + "," + controlEnd.getX() + "," + controlEnd.getY() + "," +
            points.get(last).getX() + "," + points.get(last).getY();
}
项目:fxexperience2    文件:RotatorControl.java   
@FXML void rotatorMouseDragged(MouseEvent e) {
    final Parent p = rotator_dial.getParent();
    final Bounds b = rotator_dial.getLayoutBounds();
    final Double centerX = b.getMinX() + (b.getWidth() / 2);
    final Double centerY = b.getMinY() + (b.getHeight() / 2);
    final Point2D center = p.localToParent(centerX, centerY);
    final Point2D mouse = p.localToParent(e.getX(), e.getY());
    final Double deltaX = mouse.getX() - center.getX();
    final Double deltaY = mouse.getY() - center.getY();
    final Double radians = Math.atan2(deltaY, deltaX);
    rotate(Math.toDegrees(radians));
}
项目:CalendarFX    文件:MonthViewSkin.java   
public ZonedDateTime getZonedDateTimeAt(double x, double y) {
    Point2D location = getSkinnable().localToScreen(x, y);
    for (MonthDayView view : controlsMap.values()) {
        if (view.localToScreen(view.getLayoutBounds()).contains(location)) {
            return ZonedDateTime.of(view.getDate(), LocalTime.NOON, getSkinnable().getZoneId());
        }
    }

    return null;
}
项目:DeskChan    文件:MovablePane.java   
protected void storePositionToStorage() {
    final String key = getCurrentPositionStorageKey();
    if (key != null) {
        Point2D pos = getPosition();
        Main.getProperties().put(key, pos.getX() + ";" + pos.getY());
    }
}
项目:marathonv5    文件:JavaFXTargetLocator.java   
public Point2D getLocation() {
    return EventQueueWait.exec(new Callable<Point2D>() {
        @Override public Point2D call() throws Exception {
            return new Point2D(currentWindow.getX(), currentWindow.getY());
        }
    });
}
项目:marathonv5    文件:JavaFXElementPropertyAccessor.java   
public int getColumnAt(TableView<?> tableView, Point2D point) {
    TableCell<?, ?> selected = getTableCellAt(tableView, point);
    if (selected == null) {
        return -1;
    }
    return tableView.getColumns().indexOf(selected.getTableColumn());
}
项目:voogasalad-ltub    文件:PathCreator.java   
private void targetSetOnMouseDragged(ScreenMap target, MouseEvent e, Queue<GamePoint> newPath) {
    Point2D point = target.sceneToLocal(e.getSceneX(), e.getSceneY());
    double mouseX = point.getX();
    double mouseY = point.getY();
    GamePoint coords = target.getCoordOfMouseHover(mouseX, mouseY);
    GamePoint actualGameLocation = target.getActualLocationOfSprite(coords);
    if (!coordAlreadyInPath(actualGameLocation, newPath)) {
        newPath.add(actualGameLocation);
        target.addBorderToCoordinate(coords);
    }

    e.consume();
}
项目:marathonv5    文件:JavaFXElementPropertyAccessor.java   
public TreeTableCell<?, ?> getTreeTableCellAt(TreeTableView<?> treeTableView, Point2D point) {
    point = treeTableView.localToScene(point);
    Set<Node> lookupAll = getTreeTableCells(treeTableView);
    TreeTableCell<?, ?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (TreeTableCell<?, ?>) cellNode;
            break;
        }
    }
    return selected;
}
项目:javafx-3d-surface-chart    文件:MeshImageBuilder.java   
/**
 * method returns true, if point p is in the triangle. Method uses barycentric coordinate system.
 * https://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-triangle
 */
public static boolean isPointInTriangle(Point2D p, Point3D p0, Point3D p1, Point3D p2) {
    double area = 0.5 * (-p1.getZ() * p2.getX() + p0.getZ() * (-p1.getX() + p2.getX()) + p0.getX() * (p1.getZ() - p2.getZ()) + p1.getX() * p2.getZ());
    int sign = area < 0.0 ? -1 : 1;
    double s = (p0.getZ() * p2.getX() - p0.getX() * p2.getZ() + (p2.getZ() - p0.getZ()) * p.getX() + (p0.getX() - p2.getX()) * p.getY()) * sign;
    double t = (p0.getX() * p1.getZ() - p0.getZ() * p1.getX() + (p0.getZ() - p1.getZ()) * p.getX() + (p1.getX() - p0.getX()) * p.getY()) * sign;

    return s > 0.0 && t > 0.0 && (s + t) < 2.0 * area * sign;
}
项目:marathonv5    文件:JavaServer.java   
public void clickElement(JSONObject query, JSONObject uriParams, Session session, IJavaFXElement element) {
    if (lastComponenet.element != null && lastComponenet.element.equals(element)) {
        element.click(0, null, null, 1, lastComponenet.x, lastComponenet.y);
    } else {
        Point2D p = element.getMidpoint();
        element.click(0, null, null, 1, p.getX(), p.getY());
        lastComponenet.element = element;
        lastComponenet.x = p.getX();
        lastComponenet.y = p.getY();
    }
}
项目:jmonkeybuilder    文件:AbstractSceneFileEditor.java   
/**
 * Apply a new material from an asset tree.
 *
 * @param dragEvent the drag event.
 * @param file      the file.
 */
@FXThread
private void applyMaterial(@NotNull final DragEvent dragEvent, @NotNull final Path file) {

    final Path assetFile = notNull(getAssetFile(file), "Not found asset file for " + file);
    final String assetPath = toAssetPath(assetFile);

    final MA editor3DState = getEditor3DState();
    final MaterialKey materialKey = new MaterialKey(assetPath);
    final Camera camera = editor3DState.getCamera();

    final BorderPane area = get3DArea();
    final Point2D areaPoint = area.sceneToLocal(dragEvent.getSceneX(), dragEvent.getSceneY());

    EXECUTOR_MANAGER.addJMETask(() -> {

        final Geometry geometry = editor3DState.getGeometryByScreenPos((float) areaPoint.getX(),
                camera.getHeight() - (float) areaPoint.getY());

        if (geometry == null) return;
        final Object linkNode = findParent(geometry, AssetLinkNode.class::isInstance);
        if (linkNode != null) return;

        final AssetManager assetManager = EDITOR.getAssetManager();
        final Material material = assetManager.loadAsset(materialKey);

        final PropertyOperation<ChangeConsumer, Geometry, Material> operation =
                new PropertyOperation<>(geometry, Messages.MODEL_PROPERTY_MATERIAL, material, geometry.getMaterial());

        operation.setApplyHandler(Geometry::setMaterial);

        execute(operation);
    });
}
项目:marathonv5    文件:JavaFXElement.java   
@Override public void click() {
    verifyCanInteractWithElement();

    EventQueueWait.requestFocus(node);
    Point2D p = getMidpoint();
    click(0, null, null, 1, (int) p.getX(), (int) p.getY());
}
项目:smoothcharts    文件:CatmullRom.java   
public CatmullRom(final Point2D P0, final Point2D P1, final Point2D P2, final Point2D P3) {
    assert P0 != null : "p0 cannot be null";
    assert P1 != null : "p1 cannot be null";
    assert P2 != null : "p2 cannot be null";
    assert P3 != null : "p3 cannot be null";

    splineXValues = new CatmullRomSpline(P0.getX(), P1.getX(), P2.getX(), P3.getX());
    splineYValues = new CatmullRomSpline(P0.getY(), P1.getY(), P2.getY(), P3.getY());
}
项目:smoothcharts    文件:SmoothedChart.java   
private void smooth(ObservableList<PathElement> strokeElements, ObservableList<PathElement> fillElements, final double HEIGHT) {
    if (fillElements.isEmpty()) return;
    // as we do not have direct access to the data, first recreate the list of all the data points we have
    final Point2D[] dataPoints = new Point2D[strokeElements.size()];
    for (int i = 0; i < strokeElements.size(); i++) {
        final PathElement element = strokeElements.get(i);
        if (element instanceof MoveTo) {
            final MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point2D(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            final LineTo line = (LineTo) element;
            final double x = line.getX(), y = line.getY();
            dataPoints[i] = new Point2D(x, y);
        }
    }
    double firstX = dataPoints[0].getX();
    double lastX  = dataPoints[dataPoints.length - 1].getX();

    Point2D[] points = Helper.subdividePoints(dataPoints, getSubDivisions());

    fillElements.clear();
    fillElements.add(new MoveTo(firstX, HEIGHT));

    strokeElements.clear();
    strokeElements.add(new MoveTo(points[0].getX(), points[0].getY()));

    for (Point2D p : points) {
        if (Double.compare(p.getX(), firstX) >= 0) {
            fillElements.add(new LineTo(p.getX(), p.getY()));
            strokeElements.add(new LineTo(p.getX(), p.getY()));
        }
    }

    fillElements.add(new LineTo(lastX, HEIGHT));
    fillElements.add(new LineTo(0, HEIGHT));
    fillElements.add(new ClosePath());
}
项目:DeskChan    文件:ControlsPane.java   
Hint(String text){
    setText(" ❔ ");
    setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
    Tooltip tooltip = new Tooltip(text);
    tooltip.setAutoHide(true);
    setTooltip(tooltip);
    setOnMouseClicked(event -> {
        Point2D p = localToScene(0.0, 0.0);
        getTooltip().show(this, p.getX()
                + getScene().getX() + getScene().getWindow().getX(), p.getY()
                + getScene().getY() + getScene().getWindow().getY());
    });
}
项目:marathonv5    文件:JavaFXTabPaneTabJavaElement.java   
@Override public Point2D _getMidpoint() {
    StackPane tabRegion = getTabRegion();
    Bounds boundsInParent = tabRegion.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return tabRegion.localToParent(x, y);
}
项目:FlappySpaceShip    文件:Ship.java   
/**
 * Creates an instance of the {@code Ship} class and
 * sets the main propeties of the rectangle.
 */
public Ship() {
    logger.debug("Creating ship...");
    rect = new Rectangle(width, height);
    velocity = new Point2D(0,0);
    setTranslateX(100);
    setTranslateY(300);
    getChildren().add(rect);
    logger.debug("Ship created.");
}