Example usage for javafx.geometry Point2D Point2D

List of usage examples for javafx.geometry Point2D Point2D

Introduction

In this page you can find the example usage for javafx.geometry Point2D Point2D.

Prototype

public Point2D(@NamedArg("x") double x, @NamedArg("y") double y) 

Source Link

Document

Creates a new instance of Point2D .

Usage

From source file:de.pixida.logtest.designer.automaton.LineIntersector.java

static boolean checkIfPointIsOnTheLine(final Point2D point, final Line line) {
    final Point2D lineStart = new Point2D(line.getStartX(), line.getStartY());
    final Point2D lineEnd = new Point2D(line.getEndX(), line.getEndY());
    final Point2D vecEndToStart = lineEnd.subtract(lineStart);
    final Point2D vecStartToEnd = lineStart.subtract(lineEnd);
    final Point2D vecEndToStartRotated = ROATE_90_DEGREES_COUNTERCLOCKWISE.transform(vecEndToStart);
    final Point2D vecStartToEndRotated = ROATE_90_DEGREES_COUNTERCLOCKWISE.transform(vecStartToEnd);
    if (getPointSideOfLine(point, lineEnd,
            lineEnd.add(vecEndToStartRotated)) == PointPosition.LEFT_OF_THE_LINE) {
        return false;
    }/*w w w . j av  a  2s  .  c om*/
    if (getPointSideOfLine(point, lineStart,
            lineStart.add(vecStartToEndRotated)) == PointPosition.LEFT_OF_THE_LINE) {
        return false;
    }
    return true;
}

From source file:de.pixida.logtest.designer.automaton.AutomatonEditor.java

@Override
protected void createNewDocument() {
    this.automaton = new EditorAutomaton(this.graph);
    this.automaton.setDescription("<describe the goal of your automaton here>");
    this.initView();

    // Create some existing items not to start on an empty canvas...
    final AutomatonNode newNode = new AutomatonNode(this.graph);
    final double initialNodeX = 30d;
    final double initialNodeY = 70d;
    newNode.setPosition(new Point2D(initialNodeX, initialNodeY));
    newNode.setName("Start");
    newNode.setType(INodeDefinition.Type.INITIAL);
    this.graph.addObject(newNode);
}

From source file:net.rptools.image.listeners.DrawHandler.java

@Override
public boolean handle(final SystemEvent ev, final String[] params) {
    final Point2D drag = new Point2D(Double.parseDouble(params[X]), Double.parseDouble(params[Y]));
    Platform.runLater(new Runnable() {
        @Override//from   ww w. j  a va 2  s  .c o m
        public void run() {
            draw(params[PHASE], drag, params[PEN], params[FILL], Integer.parseInt(params[RADIUS]));
        }
    });
    return true;
}

From source file:net.rptools.image.listeners.TransformHandler.java

@Override
public boolean handle(final SystemEvent ev, final String[] params) {
    final Point2D fix = new Point2D(Double.parseDouble(params[FIX_X]), Double.parseDouble(params[FIX_Y]));
    final Point2D drag = new Point2D(Double.parseDouble(params[DRAG_X]), Double.parseDouble(params[DRAG_Y]));
    transform(params[PHASE], fix, params[TRANSFORM], params[CONSTRAINT], drag);
    return true;//from w  w w. ja v  a 2 s.c  o  m
}

From source file:org.eclipse.jubula.rc.javafx.tester.TreeTableViewTester.java

@Override
protected Object getNodeAtMousePosition() throws StepExecutionException {
    Point awtPoint = getRobot().getCurrentMousePosition();
    final Point2D point = new Point2D(awtPoint.x, awtPoint.y);
    Object result = EventThreadQueuerJavaFXImpl.invokeAndWait("getNodeAtMousePosition", new Callable<Object>() { //$NON-NLS-1$
        @Override//from  w  w  w.  j  a v a 2s .c  o m
        public Object call() throws Exception {
            // Update the layout coordinates otherwise
            // we would get old position values
            ((TreeTableView<?>) getRealComponent()).layout();

            List<TreeTableCell> tCells = new NodeTraverseHelper<TreeTableCell>()
                    .getInstancesOf((Parent) getRealComponent(), TreeTableCell.class);
            for (TreeTableCell cell : tCells) {
                if (NodeBounds.checkIfContains(point, cell)) {
                    return cell;
                }
            }
            throw new StepExecutionException("No tree node found at mouse position: " //$NON-NLS-1$
                    + "X: " + point.getX() //$NON-NLS-1$
                    + "Y: " + point.getY(), //$NON-NLS-1$
                    EventFactory.createActionError(TestErrorEvent.NOT_FOUND));
        }
    });
    return result;
}

From source file:de.pixida.logtest.designer.automaton.Graph.java

Graph(final IAutomatonEditor aAutomatonEditor) {
    Validate.notNull(aAutomatonEditor);/*  www. j a v a 2 s . co m*/
    this.automatonEditor = aAutomatonEditor;

    this.pane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
    final double minSizeX = 800.0;
    final double minSizeY = 600.0;
    this.pane.setMinSize(minSizeX, minSizeY);
    final double paddingRightBottom = 8.0;
    this.pane.setPadding(new Insets(0.0, paddingRightBottom, paddingRightBottom, 0.0));
    this.pane.setOnMouseMoved(event -> this.mouseMovedOnPane(event));
    this.pane.setOnMouseClicked(event -> this.mouseClickedOnPane(event));
    final MenuItem mi = new MenuItem("Create new state");
    mi.setGraphic(Icons.getIconGraphics("pencil_add"));
    mi.setOnAction(event -> {
        // The following code does not really belong here as the class is designed only to handle business belongings... it should be
        // moved somewhere else!?
        final AutomatonNode newNode = new AutomatonNode(Graph.this);
        newNode.setPosition(new Point2D(this.lastMousePositionOnPaneX, this.lastMousePositionOnPaneY));
        newNode.setName("New state");
        Graph.this.addObject(newNode);
        Graph.this.handleChange();
        Graph.this.showConfigFrameOfObject(newNode);
    });
    this.contextMenu.getItems().add(mi);
}

From source file:de.pixida.logtest.designer.automaton.LineIntersector.java

static Point2D calculateIntersection(final Point2D point, final Point2D vec, final Line line) {
    final Point2D q = new Point2D(line.getStartX(), line.getStartY());
    final Point2D w = new Point2D(line.getEndX(), line.getEndY()).subtract(q);

    // q + t1 * w = point + t2 * vec => q - point = (vec w) (t2 -t1)^T
    final double det = det2x2LineWiseDefined(vec.getX(), w.getX(), vec.getY(), w.getY());
    final double epsilon = 1E-5;
    if (Math.abs(det) < epsilon) {
        return null;
    }/*from ww  w  .  ja va2 s .  com*/
    final double detInv = 1.0 / det;
    final double t2 = det2x2LineWiseDefined(q.getX() - point.getX(), w.getX(), q.getY() - point.getY(),
            w.getY()) * detInv;

    final Point2D intersection = vec.multiply(t2).add(point);
    return intersection;
}

From source file:org.beryx.viewreka.fxapp.codearea.ViewrekaCodeArea.java

public ViewrekaCodeArea() {
    applyConfiguration(CONFIG);/*ww  w. ja va  2 s . c  om*/

    ContextMenu cm = new ContextMenu();
    setPopupWindow(cm);
    setPopupAlignment(PopupAlignment.CARET_BOTTOM);
    setPopupAnchorOffset(new Point2D(-20, 1));
    cm.setOnShown(ev -> codeTemplatesCoordinates = new double[] { cm.getX(), cm.getY() });

    EventHandler<? super KeyEvent> tabHandler = EventHandlerHelper
            .on(EventPattern.keyPressed(KeyCode.SPACE, KeyCombination.CONTROL_DOWN))
            .act(ev -> showContextMenu(cm)).create();
    EventHandlerHelper.install(onKeyPressedProperty(), tabHandler);
}

From source file:eu.hansolo.fx.weatherfx.GeoCode.java

/**
 * Returns a JavaFX Point2D object that contains latitude (y) and longitude(x) of the given
 * Address.//from   w  w w.  j a  va 2  s . c  o m
 * Example format for STREET_CITY_COUNTRY: "1060 W. Addison St., Chicago IL, 60613"
 * @param STREET_CITY_COUNTRY
 * @return a JavaFX Point2D object that contains latitude(y) and longitude(x) of given address
 */
public static Point2D geoCode(final String STREET_CITY_COUNTRY) throws UnsupportedEncodingException {
    String URL_STRING = new StringBuilder(GEO_CODE_URL).append(URLEncoder.encode(STREET_CITY_COUNTRY, "UTF-8"))
            .append("&thumbMaps=false").toString();

    StringBuilder response = new StringBuilder();
    try {
        final HttpsURLConnection CONNECTION = (HttpsURLConnection) new URL(URL_STRING).openConnection();
        final BufferedReader IN = new BufferedReader(new InputStreamReader(CONNECTION.getInputStream()));
        String inputLine;
        while ((inputLine = IN.readLine()) != null) {
            response.append(inputLine).append("\n");
        }
        IN.close();

        Object obj = JSONValue.parse(response.toString());
        JSONObject jsonObj = (JSONObject) obj;

        JSONArray results = (JSONArray) jsonObj.get("results");
        JSONObject firstResult = (JSONObject) results.get(0);
        JSONArray locations = (JSONArray) firstResult.get("locations");
        JSONObject firstLocation = (JSONObject) locations.get(0);
        JSONObject latLng = (JSONObject) firstLocation.get("latLng");
        return new Point2D(Double.parseDouble(latLng.get("lng").toString()),
                Double.parseDouble(latLng.get("lat").toString()));
    } catch (IOException ex) {
        System.out.println(ex);
        return new Point2D(0, 0);
    }
}

From source file:ua.com.ecotep.debtprevention.VnaklController.java

@FXML
private void handleDocSelectorAction(ActionEvent event) {
    if (selCl == null) {
        AlertDialog.showSimpleMessage("?    .",
                AlertDialog.ICON_INFO, parentInterface.getCurrentWindow());
        return;/*from   w ww. j av a2  s.c  o m*/
    }
    Task<Object> task = DPSession.getInstance().getTask();
    if ((task != null) && (task.isRunning())) {
        AlertDialog.showSimpleMessage(
                "?    ?, -? .",
                AlertDialog.ICON_FORBIDDEN, parentInterface.getCurrentWindow());
        return;
    }
    Scene sceneParent = parentInterface.getCurrentWindow().getScene();
    final Point2D windowCoord = new Point2D(sceneParent.getWindow().getX(), sceneParent.getWindow().getY());
    final Point2D sceneCoord = new Point2D(sceneParent.getX(), sceneParent.getY());
    final Point2D nodeCoord = addDocButton.localToScene(0.0, 0.0);
    final double coordX = Math.round(windowCoord.getX() + sceneCoord.getX() + nodeCoord.getX());
    final double coordY = Math
            .round(windowCoord.getY() + sceneCoord.getY() + nodeCoord.getY() + addDocButton.getHeight() + 6);

    try {
        selectorPopup = new Popup();
        selectorPopup.setAutoHide(true);
        selectorPopup.setAutoFix(true);
        selectorPopup.setHideOnEscape(true);

        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("/fxml/DocSelectScene.fxml"));

        AnchorPane root = (AnchorPane) loader.load();
        DocSelectController controller = loader.getController();
        controller.setParentInterface(this);
        Scene scene = new Scene(root);
        scene.setFill(null);
        selectorPopup.getContent().add(root);

        selectorPopup.setX(coordX);
        selectorPopup.setY(coordY);
        selectorPopup.show(parentInterface.getCurrentWindow());

    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
        AlertDialog.showSimpleMessage(
                "? ?    !",
                AlertDialog.ICON_ERROR, parentInterface.getCurrentWindow());
    }
}