当前位置: 首页>>代码示例>>Java>>正文


Java PInputEvent.getPickedNode方法代码示例

本文整理汇总了Java中edu.umd.cs.piccolo.event.PInputEvent.getPickedNode方法的典型用法代码示例。如果您正苦于以下问题:Java PInputEvent.getPickedNode方法的具体用法?Java PInputEvent.getPickedNode怎么用?Java PInputEvent.getPickedNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.umd.cs.piccolo.event.PInputEvent的用法示例。


在下文中一共展示了PInputEvent.getPickedNode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleMouseDragEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
/**
 * Handle and event indicating that the user has dragged the mouse,
 * intending to move the marker.  This updates the position of the
 * marker and the values displayed.
 *
 * @param event
 */
private void handleMouseDragEvent( PInputEvent event ) {
    PNode draggedNode = event.getPickedNode();
    PDimension d = event.getDeltaRelativeTo( draggedNode );
    draggedNode.localToParent( d );
    double newXPos = _readoutRect.getOffset().getX() + d.width;
    double newCenterXPos = newXPos + ( _readoutRect.getFullBoundsReference().width / 2 );
    if ( newCenterXPos < _chart.getGraphOriginPos().getX() ) {
        // Limit the position from going too far to the left.
        newXPos = _chart.getGraphOriginPos().getX() - ( _readoutRect.getFullBoundsReference().width / 2 );
    }
    else if ( newCenterXPos > _chart.getGraphMaxX() ) {
        // Limit the position from going too far to the right.
        newXPos = _chart.getGraphMaxX() - ( _readoutRect.getFullBoundsReference().width / 2 );
    }
    _readoutRect.setOffset( newXPos, _readoutRect.getOffset().getY() );
    updateReadoutText();
    _indicatorHandle.setOffset( newXPos + _readoutRect.getWidth() / 2 - _indicatorHandle.getWidth() / 2,
                                _indicatorHandle.getOffset().getY() );
    _indicatorLine.setOffset( newXPos + _readoutRect.getWidth() / 2 - _indicatorLine.getWidth() / 2,
                              _readoutRect.getOffset().getY() + _readoutRect.getHeight() );

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:30,代码来源:NuclearDecayProportionChart.java

示例2: handleMouseDragEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void handleMouseDragEvent( PInputEvent event ) {

        // Only allow the user to move unbonded atoms.
        if ( m_model.getBondingState() != DualAtomModel.BONDING_STATE_UNBONDED ) {
            // Need to release the bond before we can move the atom.
            m_model.releaseBond();
        }

        // Determine the amount of motion indicated by the drag event.
        PNode draggedNode = event.getPickedNode();
        PDimension d = event.getDeltaRelativeTo( draggedNode );
        draggedNode.localToParent( d );

        // Make sure we don't exceed the positional limits.
        double newPosX = m_particle.getX() + d.width;
        if ( newPosX > m_maxX ) {
            newPosX = m_maxX;
        }
        else if ( newPosX < m_minX ) {
            newPosX = m_minX;
        }

        // Move the particle based on the amount of mouse movement.
        m_particle.setPosition( newPosX, m_particle.getY() );

    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:GrabbableParticleNode.java

示例3: drag

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
public void drag(final PInputEvent e) {
    final PNode node = e.getPickedNode();
    node.translate(e.getDelta().width, e.getDelta().height);

    final ArrayList edges = (ArrayList) e.getPickedNode().getAttribute("edges");

    int i;
    for (i = 0; i < edges.size(); i++) {
        final PPath edge = (PPath) edges.get(i);
        final ArrayList nodes = (ArrayList) edge.getAttribute("nodes");
        final PNode node1 = (PNode) nodes.get(0);
        final PNode node2 = (PNode) nodes.get(1);

        edge.reset();
        // Note that the node's "FullBounds" must be used (instead of
        // just the "Bound") because the nodes have non-identity
        // transforms which must be included when determining their
        // position.
        final Point2D.Double bound1 = (Point2D.Double) node1.getFullBounds().getCenter2D();
        final Point2D.Double bound2 = (Point2D.Double) node2.getFullBounds().getCenter2D();

        edge.moveTo((float) bound1.getX(), (float) bound1.getY());
        edge.lineTo((float) bound2.getX(), (float) bound2.getY());
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:GraphEditorExample.java

示例4: mousePressed

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
/**
 * A callback that is invoked any time the mouse is pressed on the canvas.
 * If the press occurs directly on the canvas, it create a new PStyledText
 * instance and puts it in editing mode. If the click is on a node, it marks
 * changes it to editing mode.
 * 
 * @param event mouse click event that can be queried
 */
public void mousePressed(final PInputEvent event) {
    final PNode pickedNode = event.getPickedNode();

    stopEditing(event);

    if (event.getButton() != MouseEvent.BUTTON1) {
        return;
    }

    if (pickedNode instanceof PStyledText) {
        startEditing(event, (PStyledText) pickedNode);
    }
    else if (pickedNode instanceof PCamera) {
        final PStyledText newText = createText();
        final Insets pInsets = newText.getInsets();
        newText.translate(event.getPosition().getX() - pInsets.left, event.getPosition().getY() - pInsets.top);
        startEditing(event, newText);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:28,代码来源:PStyledTextEventHandler.java

示例5: handleMouseDragEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void handleMouseDragEvent(PInputEvent event){
	// Move the node as indicated by the drag event.
    PNode draggedNode = event.getPickedNode();
    PDimension d = event.getDeltaRelativeTo(draggedNode);
    draggedNode.localToParent(d);
    AtomicNucleus nucleus = getNucleusRef();
    double newPosX = nucleus.getPositionReference().getX() + d.getWidth();
    double newPosY = nucleus.getPositionReference().getY() + d.getHeight();
    nucleus.setPosition(newPosX, newPosY);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:11,代码来源:GrabbableNucleusImageNode.java

示例6: handleMouseDragEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void handleMouseDragEvent( PInputEvent event ) {

        PNode draggedNode = event.getPickedNode();
        PDimension d = event.getDeltaRelativeTo( draggedNode );
        draggedNode.localToParent( d );
        m_mouseMovementAmount += d.getHeight();

        // Resize the container based on the amount that the node has moved.
        m_model.setTargetParticleContainerHeight( m_containerSizeAtDragStart - m_mouseMovementAmount );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:11,代码来源:PointingHandNode.java

示例7: mousePressed

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
public void mousePressed( PInputEvent event ) {

        _isDragging = true;

        Point2D mousePosition = event.getPosition();
        PNode node = event.getPickedNode();
        Rectangle2D nodeBounds = getNodeBounds( node );

        // Determine where we pressed relative to the node's upper left corner.
        double x = mousePosition.getX() - nodeBounds.getX();
        double y = mousePosition.getY() - nodeBounds.getY();
        _pressedOffset.setLocation( x, y );

        event.setHandled( _markAsHandled );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:ConstrainedDragHandler.java

示例8: moveFocusToMouseOver

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
/**
 * Moves the focus to the mouse under the mouse. Animating the camera
 * appropriately.
 * 
 * @param event mouse event
 */
public void moveFocusToMouseOver(final PInputEvent event) {
    final PNode focus = event.getPickedNode();
    if (!(focus instanceof PCamera)) {
        focusNode = focus;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:13,代码来源:PNavigationEventHandler.java

示例9: zoomTo

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
/**
 * Zooms the camera to the picked node of the event.
 * @param event Event from which to extract the zoom target
 */
protected void zoomTo(final PInputEvent event) {
    PBounds zoomToBounds;
    final PNode picked = event.getPickedNode();

    if (picked instanceof PCamera) {
        final PCamera c = (PCamera) picked;
        zoomToBounds = c.getUnionOfLayerFullBounds();
    }
    else {
        zoomToBounds = picked.getGlobalFullBounds();
    }

    event.getCamera().animateViewToCenterBounds(zoomToBounds, true, ZOOM_SPEED);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:PZoomToEventHandler.java

示例10: handleSliderKnobDragEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void handleSliderKnobDragEvent( PInputEvent event ) {

        PNode draggedNode = event.getPickedNode();
        PDimension d = event.getDeltaRelativeTo( draggedNode );
        draggedNode.localToParent( d );
        double movementAmount = d.getHeight();

        double knobMovementRange = zoomOutButton.getFullBoundsReference().getMinY()
                                   - zoomInButton.getFullBoundsReference().getMaxY();

        double zoomDelta = -movementAmount / knobMovementRange * ( maxZoom - minZoom );

        double newZoomValue = zoomable.getZoomFactor() + zoomDelta;

        newZoomValue = MathUtil.clamp( minZoom, newZoomValue, maxZoom );

        zoomable.setZoomFactor( newZoomValue );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:ZoomControl.java

示例11: mouseDragged

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
public void mouseDragged( PInputEvent event ) {
    PNode pickedNode = event.getPickedNode();
    if ( pickedNode != _startButton && pickedNode != _stopButton && pickedNode != _sliderWrapper && pickedNode != _textFieldWrapper ) {
        super.mouseDragged( event );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:7,代码来源:LaserControlPanel.java

示例12: EpsilonControlInteractionPotentialDiagram

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
/**
 * Constructor.
 *
 * @param sigma
 * @param epsilon
 * @param wide    - True if the widescreen version of the graph is needed, false if not.
 */
public EpsilonControlInteractionPotentialDiagram( double sigma, double epsilon, boolean wide,
                                                  final MultipleParticleModel model ) {

    super( sigma, epsilon, wide, true );

    this.m_model = model;
    model.addListener( new MultipleParticleModel.Adapter() {
        public void interactionStrengthChanged() {
            setLjPotentialParameters( m_model.getSigma(), m_model.getEpsilon() );
        }

        public void moleculeTypeChanged() {
            updateInteractivityState();
            drawPotentialCurve();
        }
    } );

    // Create the handler for events that indicate that the user is
    // changing the value of epsilon.
    PBasicInputEventHandler epsilonChangeHandler = new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            PNode draggedNode = event.getPickedNode();
            PDimension d = event.getDeltaRelativeTo( draggedNode );
            draggedNode.localToParent( d );
            double scaleFactor = StatesOfMatterConstants.MAX_EPSILON / ( getGraphHeight() / 2 );
            m_model.setEpsilon( m_model.getEpsilon() + d.getHeight() * scaleFactor );
        }
    };

    // Add the line that will indicate the value of epsilon.
    double epsilonLineLength = EPSILON_HANDLE_OFFSET_PROPORTION * m_width * 2.2;
    m_epsilonLine = new PPath( new Line2D.Double( -epsilonLineLength / 3, 0, epsilonLineLength / 2, 0 ) );
    m_epsilonLine.setStroke( EPSILON_LINE_STROKE );
    m_epsilonLine.setStrokePaint( EPSILON_LINE_COLOR );
    m_epsilonLine.addInputEventListener( new CursorHandler( Cursor.N_RESIZE_CURSOR ) );
    m_epsilonLine.addInputEventListener( epsilonChangeHandler );
    m_ljPotentialGraph.addChild( m_epsilonLine );

    // Add the arrow node that will allow the user to control the value of
    // the epsilon parameter.
    m_epsilonResizeHandle = new ResizeArrowNode( RESIZE_HANDLE_SIZE_PROPORTION * m_width, Math.PI / 2,
                                                 RESIZE_HANDLE_NORMAL_COLOR, RESIZE_HANDLE_HIGHLIGHTED_COLOR );
    m_ljPotentialGraph.addChild( m_epsilonResizeHandle );
    m_epsilonResizeHandle.addInputEventListener( epsilonChangeHandler );

    // Update interactivity state.
    updateInteractivityState();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:56,代码来源:EpsilonControlInteractionPotentialDiagram.java

示例13: dragConstrainPoint

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void dragConstrainPoint( PInputEvent event ) {

        Point2D mousePosition = event.getPosition();
        PNode node = event.getPickedNode();
        Rectangle2D nodeBounds = getNodeBounds( node );

        /*
         * Adjust the mouse location to account for where we clicked 
         * relative to the node's center point. We want the center 
         * of the node to remain in the bounds.
         */
        double x = mousePosition.getX() - _pressedOffset.getX() + _nodeCenter.getX();
        double y = mousePosition.getY() - _pressedOffset.getY() + _nodeCenter.getY();
        _adjustedMousePosition.setLocation( x, y );

        // Calculate dx
        double dx = 0;
        if ( _horizontalLockEnabled ) {
            dx = 0;
        }
        else if ( _adjustedMousePosition.getX() < _dragBounds.getX() ) {
            // move to far left
            dx = _dragBounds.getX() - nodeBounds.getX() - _nodeCenter.getX();
        }
        else if ( _adjustedMousePosition.getX() > _dragBounds.getX() + _dragBounds.getWidth() ) {
            // move to far right
            dx = ( _dragBounds.getX() + _dragBounds.getWidth() ) - nodeBounds.getX() - _nodeCenter.getX();
        }
        else {
            // follow mouse
            dx = mousePosition.getX() - nodeBounds.getX() - _pressedOffset.getX();
        }

        // Calculate dy
        double dy = 0;
        if ( _verticalLockEnabled ) {
            dy = 0;
        }
        else if ( _adjustedMousePosition.getY() < _dragBounds.getY() ) {
            // move to top
            dy = _dragBounds.getY() - nodeBounds.getY() - _nodeCenter.getY();
        }
        else if ( _adjustedMousePosition.getY() > _dragBounds.getY() + _dragBounds.getHeight() ) {
            // move to bottom 
            dy = ( _dragBounds.getY() + _dragBounds.getHeight() ) - nodeBounds.getY() - _nodeCenter.getY();
        }
        else {
            // follow mouse
            dy = mousePosition.getY() - nodeBounds.getY() - _pressedOffset.getY();
        }

        // Perform the drag
        if ( dx != 0 || dy != 0 ) {
            node.translate( dx, dy );
        }
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:57,代码来源:ConstrainedDragHandler.java

示例14: dragConstrainBounds

import edu.umd.cs.piccolo.event.PInputEvent; //导入方法依赖的package包/类
private void dragConstrainBounds( PInputEvent event ) {

        Point2D mousePosition = event.getPosition();
        PNode node = event.getPickedNode();
        Rectangle2D nodeBounds = getNodeBounds( node );

        /*
        * Adjust the mouse location to account for where we clicked
        * relative to the node's upper left corner.
        */
        double x = mousePosition.getX() - _pressedOffset.getX();
        double y = mousePosition.getY() - _pressedOffset.getY();
        _adjustedMousePosition.setLocation( x, y );

        // Calculate dx
        double dx = 0;
        if ( _horizontalLockEnabled ) {
            dx = 0;
        }
        else if ( _adjustedMousePosition.getX() < _dragBounds.getX() ) {
            // move to far left
            dx = _dragBounds.getX() - nodeBounds.getX();
        }
        else if ( _adjustedMousePosition.getX() + nodeBounds.getWidth() > _dragBounds.getX() + _dragBounds.getWidth() ) {
            // move to far right
            dx = ( _dragBounds.getX() + _dragBounds.getWidth() - nodeBounds.getWidth() ) - nodeBounds.getX();
        }
        else {
            // follow mouse
            dx = mousePosition.getX() - nodeBounds.getX() - _pressedOffset.getX();
        }

        // Calculate dy
        double dy = 0;
        if ( _verticalLockEnabled ) {
            dy = 0;
        }
        else if ( _adjustedMousePosition.getY() < _dragBounds.getY() ) {
            // move to top
            dy = _dragBounds.getY() - nodeBounds.getY();
        }
        else if ( _adjustedMousePosition.getY() + nodeBounds.getHeight() > _dragBounds.getY() + _dragBounds.getHeight() ) {
            // move to bottom 
            dy = ( _dragBounds.getY() + _dragBounds.getHeight() - nodeBounds.getHeight() ) - nodeBounds.getY();
        }
        else {
            // follow mouse
            dy = mousePosition.getY() - nodeBounds.getY() - _pressedOffset.getY();
        }

        // Perform the drag
        if ( dx != 0 || dy != 0 ) {
            node.translate( dx, dy );
        }
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:56,代码来源:ConstrainedDragHandler.java


注:本文中的edu.umd.cs.piccolo.event.PInputEvent.getPickedNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。