Java 类javafx.scene.input.TouchPoint 实例源码

项目:Augendiagnose    文件:SizableImageView.java   
/**
 * Handle a touch event.
 *
 * @param event
 *            The touch event.
 */
private void handleTouchEvent(final TouchEvent event) {
    if (event.getEventType().equals(TouchEvent.TOUCH_PRESSED)) {
        mTouchCount = event.getTouchCount();
    }
    else if (event.getEventType().equals(TouchEvent.TOUCH_RELEASED)) {
        // getTouchCount gives the number of touch points before the release.
        mTouchCount = event.getTouchCount() - 1;
    }

    if (mTouchCount > 1) {
        List<TouchPoint> touchPoints = event.getTouchPoints();
        double sumX = 0;
        double sumY = 0;
        for (TouchPoint point : touchPoints) {
            sumX += point.getX();
            sumY += point.getY();
        }
        mTouchXProperty.set(sumX / touchPoints.size());
        mTouchYProperty.set(sumY / touchPoints.size());
    }
}
项目:viskell    文件:FunctionMenu.java   
private void addDraggedBlock(TouchPoint touchPoint, Block block) {
    Point2D pos = parent.sceneToLocal(touchPoint.getSceneX(), touchPoint.getSceneY());
    parent.addBlock(block);
    block.relocate(pos.getX(), pos.getY());
    touchPoint.grab(block);
    block.initiateConnectionChanges();
}
项目:viskell    文件:TouchContext.java   
/**
 * @param touchPoint that is the center of new active touch area.
 */
private TouchArea(TouchPoint touchPoint) {
    super();
    this.toplevel = TouchContext.this.container.getToplevel();
    this.touchID = touchPoint.getId();
    this.dragStarted = false;
    this.menuCreated = false;

    Point2D pos = this.toplevel.sceneToLocal(touchPoint.getSceneX(), touchPoint.getSceneY());
    this.setCenterX(pos.getX());
    this.setCenterY(pos.getY());
    this.setRadius(100);
    this.setFill(Color.TRANSPARENT);

    this.removeDelay = new Timeline(new KeyFrame(Duration.millis(250), this::remove));
    this.menuDelay = new Timeline(new KeyFrame(Duration.millis(200), this::finishMenu));

    this.wireCutter = new Line(pos.getX(), pos.getY(), pos.getX(), pos.getY());
    this.wireCutter.setStroke(Color.YELLOW);
    this.wireCutter.setStrokeWidth(3);
    this.wireCutter.setVisible(false);
    this.toplevel.addUpperTouchArea(this.wireCutter);

    touchPoint.grab(this);
    this.addEventHandler(TouchEvent.TOUCH_RELEASED, this::handleRelease);
    this.addEventHandler(TouchEvent.TOUCH_PRESSED, this::handlePress);
    this.addEventHandler(TouchEvent.TOUCH_MOVED, this::handleDrag);
}
项目:viskell    文件:TouchContext.java   
private void handleDrag(TouchEvent event) {
    TouchPoint touchPoint = event.getTouchPoint();

    if (event.getTouchPoint().getId() != this.touchID) {
        // we use only primary finger for drag movement
    } else if (event.getTouchPoints().stream().filter(tp -> tp.belongsTo(this)).count() < 2) {
        // not a multi finger drag
        this.updateCutter(this.toplevel.sceneToLocal(touchPoint.getSceneX(), touchPoint.getSceneY()));
    } else {
        double deltaX = touchPoint.getX() - this.getCenterX();
        double deltaY = touchPoint.getY() - this.getCenterY();

        if (Math.abs(deltaX) + Math.abs(deltaY) < 2) {
            // ignore very small movements
        } else if ((deltaX*deltaX + deltaY*deltaY) > 10000) {
            // FIXME: ignore too large movements
        } else if (this.dragStarted || (deltaX*deltaX + deltaY*deltaY) > 63) {
            this.dragStarted = true;
            if (TouchContext.this.panningAction != null) {
                TouchContext.this.panningAction.accept(deltaX, deltaY);
                if (!TouchContext.this.willPanTouchArea) {
                    this.setLayoutX(this.getLayoutX() + deltaX);
                    this.setLayoutY(this.getLayoutY() + deltaY);
                }
            }
        }
    }

    event.consume();
}
项目:viskell    文件:DrawWire.java   
/**
 * @param anchor the connected side of this new wire.
 * @param startingPoint the position where this wire was initiated from.
 * @param touchPoint that initiated this wire, or null if it was by mouse. 
 */
private DrawWire(ConnectionAnchor anchor, Point2D startingPoint, TouchPoint touchPoint) {
    this.setMouseTransparent(true);
    this.anchor = anchor;
    this.anchor.setWireInProgress(this);

    ToplevelPane pane = anchor.getPane();
    pane.addWire(this);
    this.setFreePosition(startingPoint);
    anchor.localToSceneTransformProperty().addListener(this);

    this.toucharea = new TouchArea(touchPoint);
    pane.addUpperTouchArea(this.toucharea);
}
项目:viskell    文件:DrawWire.java   
/**
 * @param touchPoint that is the center of new active touch area, or null if the mouse
 */
private TouchArea(TouchPoint touchPoint) {
    super();
    this.setLayoutX(DrawWire.this.getEndX());
    this.setLayoutY(DrawWire.this.getEndY());

    this.touchID = touchPoint == null ? -1 : touchPoint.getId();
    this.dragStarted = true;
    this.nearbyAnchors = new ArrayList<>();
    this.lastNearbyUpdate = Point2D.ZERO;

    this.disapperance = new Timeline(new KeyFrame(Duration.millis(2000),
            e -> DrawWire.this.remove(),
            new KeyValue(this.opacityProperty(), 0.3),
            new KeyValue(DrawWire.this.opacityProperty(), 0.2)));

    // a circle with hole is built from a path of round arcs with a very thick stroke
    ArcTo arc1 = new ArcTo(100, 100, 0, 100, 0, true, true);
    ArcTo arc2 = new ArcTo(100, 100, 0, -100, 0, true, true);
    this.getElements().addAll(new MoveTo(-100, 0), arc1, arc2, new ClosePath());
    this.setStroke(Color.web("#0066FF"));
    this.setStrokeType(StrokeType.INSIDE);
    this.setStrokeWidth(90);
    this.setStroke(Color.web("#0066FF"));
    this.setStrokeType(StrokeType.INSIDE);
    this.setOpacity(0);

    if (touchPoint != null) { 
        touchPoint.grab(this);
    }

    this.addEventHandler(TouchEvent.TOUCH_PRESSED, this::handleTouchPress);
    this.addEventHandler(TouchEvent.TOUCH_MOVED, this::handleTouchDrag);
    this.addEventHandler(TouchEvent.TOUCH_RELEASED, this::handleTouchRelease);
    this.addEventHandler(MouseEvent.MOUSE_PRESSED, this::handleMousePress);
    this.addEventHandler(MouseEvent.MOUSE_DRAGGED, this::handleMouseDrag);
    this.addEventHandler(MouseEvent.MOUSE_RELEASED, this::handleMouseRelease);
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:BoxList.java   
@Override
public void setMultiTouchPosition(List<TouchPoint> touchList) {
    this.touchPointList = touchList;
    System.out.println();
    for (int i = 0; i < touchList.size(); i++) {
        if (touchList.get(i).getId() == 1) {
            mouseX = touchList.get(i).getSceneX();
            mouseY = touchList.get(i).getSceneY();
        }
    }
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:BoxList.java   
@Override
// マルチタッチを受け付けたくないので、1点だけをとるようにしている。
public void setMultiTouchPosition(List<TouchPoint> touchList) {
    this.touchPointList = touchList;
    System.out.println();
    for (int i = 0; i < touchList.size(); i++) {
        if (touchList.get(i).getId() == 1) {
            mouseX = touchList.get(i).getSceneX();
            mouseY = touchList.get(i).getSceneY();
        }
    }
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:WorkSpace.java   
@Override
    public void setMultiTouchPosition(List<TouchPoint> touchList) {
//        for (int i = 0; i < touchList.size(); i++) {
//            System.out.println("Programming Environment -> Touched : " 
//                    + touchList.get(i).getId() + " : " + touchList.get(i).getX() + "," + touchList.get(i).getY());
//        }
        // これはboxEventに書く?
        // 2本指でタッチされたらボックスの接続を行います。
        // このあと、二本指でタッチして、ある程度近づけたらーって感じにする。
        if (touchList.size() == 2) {
            if (testConnectFlag) {
                int counter = 0;
                Box[] connectBox = new Box[2];
                for (int i = 0; i < touchList.size(); i++) {
                    System.out.println("Programming Environment -> Touched : "
                            + touchList.get(i).getId() + " : "
                            + touchList.get(i).getX() + "," + touchList.get(i).getY());
                    for (int j = 0; j < boxList.size(); j++) {
                        for (int k = 0; k < boxList.get(j).size(); k++) {
                            if (touchList.get(i).getId() == boxList.get(j).get(k).getTouchID()) {
                                connectBox[counter] = boxList.get(j).get(k);
                                counter++;
                            }
                        }
                    }
                }
                if (counter == 2) {
                    System.out.println("Touch!!!!!!!!!! ----- 0: " + connectBox[0].getY() + " 1:" + connectBox[1].getY());
                    // 2点間の距離を計算(タッチされた時点での点と現在の点)
                    double x1 = connectBox[0].getX();
                    double x2 = connectBox[1].getX();
                    double y1 = connectBox[0].getY();
                    double y2 = connectBox[1].getY();
                    if (testConnectFlag2) {
                        // どのくらい近づくか?
//                        td1 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) * 2 / 3;
                        td1 = connectBox[0].getSizeY() + 10; // 正方形だし、これでいいや! + 10 は斜めから来る時とかの保険分
                        testConnectFlag2 = false;
                    }
                    td2 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
                    System.out.println("-----WorkSpace : td1 = " + td1 + ", td2 = " + td2);
                    if (td2 < td1) {
                        if (connectBox[0].getY() > connectBox[1].getY()) {
//                            System.out.println("-----");
                            connectBox(connectBox[1], connectBox[0]);
                        } else {
//                            System.out.println("+++++");
                            connectBox(connectBox[0], connectBox[1]);
                        }
                        testConnectFlag = false;
                    }
                }
            }
        } else {
            testConnectFlag = true;
            testConnectFlag2 = true;
        }
        this.touchPointList = touchList;
    }
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:ProgrammingEnvironment.java   
public void setMultiTouchPosition(List<TouchPoint> touchList) {
    this.touchPointList = touchList;
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:HomeProgrammingEnvironment.java   
public void setMultiTouchPositon(List<TouchPoint> list) {
//                System.out.println("testtttttttttt----------------"+list.size());        
        workSpace.setMultiTouchPosition(list);
        boxList.setMultiTouchPosition(list);
    }
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:WorkSpace.java   
@Override
    public void setMultiTouchPosition(List<TouchPoint> touchList) {
        // 2本指でタッチされたらボックスの接続を行います。
        // このあと、二本指でタッチして、ある程度近づけたらーって感じにする。
        if (touchList.size() == 2) {
            if (testConnectFlag) {
                int counter = 0;
                Box[] connectBox = new Box[2];
                for (int i = 0; i < touchList.size(); i++) {
                    System.out.println("Programming Environment -> Touched : "
                            + touchList.get(i).getId() + " : "
                            + touchList.get(i).getX() + "," + touchList.get(i).getY());
                    for (int j = 0; j < boxList.size(); j++) {
                        for (int k = 0; k < boxList.get(j).size(); k++) {
                            if (touchList.get(i).getId() == boxList.get(j).get(k).getTouchID()) {
                                connectBox[counter] = boxList.get(j).get(k);
                                counter++;
                            }
                        }
                    }
                }
                if (counter == 2) {
                    System.out.println("Touch!!!!!!!!!! ----- 0: " + connectBox[0].getY() + " 1:" + connectBox[1].getY());
                    // 2点間の距離を計算(タッチされた時点での点と現在の点)
                    double x1 = connectBox[0].getX();
                    double x2 = connectBox[1].getX();
                    double y1 = connectBox[0].getY();
                    double y2 = connectBox[1].getY();
                    if (testConnectFlag2) {
                        // どのくらい近づくか?
//                        td1 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) * 2 / 3;
                        td1 = connectBox[0].getSizeY() + 10; // とりあえず、これでいいや!(ごめんなさい)
                        testConnectFlag2 = false;
                    }
                    td2 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
                    System.out.println("-----WorkSpace : td1 = " + td1 + ", td2 = " + td2);
                    if (td2 < td1) {
                        // 接続
                        if (connectBox[0].getY() > connectBox[1].getY()) {
                            connectBox(connectBox[1], connectBox[0]);
                        } else {
                            connectBox(connectBox[0], connectBox[1]);
                        }
                        testConnectFlag = false;
                    }
                }
            }
        } else {
            testConnectFlag = true;
            testConnectFlag2 = true;
        }
        this.touchPointList = touchList;
    }
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:ProgrammingEnvironment.java   
public void setMultiTouchPosition(List<TouchPoint> touchList) {
    this.touchPointList = touchList;
}
项目:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House    文件:HomeProgrammingEnvironment.java   
public void setMultiTouchPositon(List<TouchPoint> list) {
    workSpace.setMultiTouchPosition(list);
    boxList.setMultiTouchPosition(list);
}