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


Java PInputEvent类代码示例

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


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

示例1: SimSharingDragHandler

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public SimSharingDragHandler( IUserComponent userComponent, IUserComponentType componentType, final boolean sendDragMessages ) {

        this.userComponent = userComponent;
        this.componentType = componentType;
        this.dragPoints = new SimSharingDragPoints();

        // default functions
        this.startDragFunction = new DragFunction() {
            public void apply( IUserComponent userComponent, IUserComponentType componentType, IUserAction action, ParameterSet parameterSet, PInputEvent event ) {
                SimSharingManager.sendUserMessage( userComponent, componentType, action, parameterSet );
            }
        };
        this.dragFunction = new DragFunction() {
            public void apply( IUserComponent userComponent, IUserComponentType componentType, IUserAction action, ParameterSet parameterSet, PInputEvent event ) {
                if ( sendDragMessages ) {
                    SimSharingManager.sendUserMessage( userComponent, componentType, action, parameterSet );
                }
            }
        };
        this.endDragFunction = new DragFunction() {
            public void apply( IUserComponent userComponent, IUserComponentType componentType, IUserAction action, ParameterSet parameterSet, PInputEvent event ) {
                SimSharingManager.sendUserMessage( userComponent, componentType, action, parameterSet );
            }
        };
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:SimSharingDragHandler.java

示例2: main

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public static void main( String[] args ) {
    new JFrame( "Test" ) {{
        setContentPane( new PCanvas() {{
            setPreferredSize( new Dimension( 800, 600 ) );
            setPanEventHandler( null );
            for ( int i = 0; i < 1000; i++ ) {
                final int finalI = i;
                getLayer().addChild( new PPath( new Ellipse2D.Double( 0, 0, 10, 10 ), null ) {{
                    setPaint( new Color( finalI % 255, 0, 0 ) );
                    translate( finalI / 10, finalI / 10 );
                }} );
            }
            getLayer().addChild( new PPath( new Ellipse2D.Double( 0, 0, 200, 200 ), null ) {{
                setPaint( Color.blue );
                addInputEventListener( new PBasicInputEventHandler() {
                    @Override public void mouseDragged( final PInputEvent event ) {
                        translate( event.getCanvasDelta().width, event.getCanvasDelta().height );
                    }
                } );
            }} );
        }} );
        pack();
        setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
    }}.setVisible( true );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:ComparePiccolo.java

示例3: EvaporationControlNode

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public EvaporationControlNode( final Evaporator evaporator ) {
    super( new HBox(

            // Label
            new PText( Strings.EVAPORATION ) {{
                setFont( new PhetFont( BLLConstants.CONTROL_FONT_SIZE ) );
            }},

            // Slider
            new HSliderNode( UserComponents.evaporationSlider, 0, evaporator.maxEvaporationRate, evaporator.evaporationRate, evaporator.enabled ) {{

                // Tick labels
                PhetFont tickFont = new PhetFont( BLLConstants.TICK_LABEL_FONT_SIZE );
                addLabel( 0, new PhetPText( Strings.NONE, tickFont ) );
                addLabel( evaporator.maxEvaporationRate, new PhetPText( Strings.LOTS, tickFont ) );

                // Set rate to zero when slider is released.
                this.addInputEventListener( new PBasicInputEventHandler() {
                    @Override public void mouseReleased( PInputEvent event ) {
                        evaporator.evaporationRate.set( 0.0 );
                    }
                } );
            }}
    ) );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:EvaporationControlNode.java

示例4: createMouseEvent

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
/**
 * Creates and returns a new PMouse event from a Java MouseEvent.
 * 
 * @param id The event type (MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED,
 *            MOUSE_ENTERED, MOUSE_EXITED, MOUSE_MOVED, MOUSE_DRAGGED)
 * @param swingEvent The original swing mouse event when in
 *            MOUSE_DRAGGED and MOUSE_RELEASED events.
 * @param pEvent used to query about the event's Piccolo2d context
 * 
 * @return the constructed PSwingEvent
 */
public static PSwingEvent createMouseEvent(final int id, final MouseEvent swingEvent, final PInputEvent pEvent) {
    if (pEvent == null) {
        throw new IllegalArgumentException("PInputEvent associated with PSwingEvent may not be null");
    }
    
    if (id == MouseEvent.MOUSE_MOVED || id == MouseEvent.MOUSE_DRAGGED) {
        return new PSwingMouseMotionEvent(id, swingEvent, pEvent);
    }
    else if (id == MouseEvent.MOUSE_WHEEL) {
        return new PSwingMouseWheelEvent(id, (MouseWheelEvent) swingEvent, pEvent);
    }
    else {
        return new PSwingMouseEvent(id, swingEvent, pEvent);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:PSwingMouseEvent.java

示例5: handleHighlight

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
private void handleHighlight( PInputEvent event ) {
    
    // Map the mouse position to an energy value...
    Point2D localPosition = event.getPositionRelativeTo( this );
    Point2D globalPosition = localToGlobal( localPosition );
    Point2D chartPosition = _chartNode.globalToLocal( globalPosition );
    Point2D energyPosition = _chartNode.nodeToEnergy( chartPosition );
    final double energy = energyPosition.getY();

    // Find the closest eigenstate...
    int hiliteIndex = _model.getClosestEigenstateIndex( energy, BSConstants.HILITE_ENERGY_THRESHOLD );

    // Update the model...
    _model.setHilitedEigenstateIndex( hiliteIndex );
    
    // Set the mouse cursor...
    setCursor( hiliteIndex );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:BSEigenstatesNode.java

示例6: 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

示例7: 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

示例8: TrackButton

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public TrackButton( final EnergySkateParkBasicsModule module, final String trackName, final Vector2D offset ) {
    PImage image = new PImage( createIcon( module, trackName, offset ) );
    addChild( image );
    final PPath selectedIndicator = new PhetPPath( image.getFullBoundsReference().getBounds2D(), new BasicStroke( 3 ), INVISIBLE_COLOR );
    addChild( selectedIndicator );

    //When pressed, load the track
    addInputEventListener( new CursorHandler() );
    addInputEventListener( new PBasicInputEventHandler() {

        @Override public void mousePressed( PInputEvent event ) {
            SimSharingManager.sendUserMessage( chain( trackButton, trackName ), UserComponentTypes.button, pressed, ParameterSet.parameterSet( EnergySkateParkSimSharing.ParameterKeys.trackName, trackName ) );
            module.loadTrack( trackName, offset );
        }
    } );

    //When selected, turn on highlight.
    module.currentTrackFileName.addObserver( new VoidFunction1<String>() {
        public void apply( String fileName ) {
            selectedIndicator.setStrokePaint( fileName.equalsIgnoreCase( trackName ) ? Color.YELLOW : INVISIBLE_COLOR );
        }
    } );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:TrackButton.java

示例9: SpatialSimpleMoleculeGraphic

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
/**
 * @param molecule
 * @param profile
 */
public SpatialSimpleMoleculeGraphic( SimpleMolecule molecule, EnergyProfile profile ) {
    super( molecule, profile );

    this.molecule = molecule;
    this.profile = profile;

    // Catch mouse clicks that select this graphic's molecule
    if( molecule instanceof MoleculeA || molecule instanceof MoleculeC ) {
        this.addInputEventListener( new PBasicInputEventHandler() {
            public void mouseClicked( PInputEvent event ) {
                super.mouseClicked( event );
                getMolecule().setSelectionStatus( Selectable.SELECTED );
            }
        } );
    }

    if( DebugFlags.SHOW_BOUNDING_BOX ) {
        boundingBox = new PPath();
        boundingBox.setStrokePaint( Color.red );
        addChild( boundingBox );
        update();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:28,代码来源:SpatialSimpleMoleculeGraphic.java

示例10: CNode

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public CNode( final CModelElement modelElement ) {
    super( modelElement.getSize(), modelElement.getColor() );
    
    _modelElement = modelElement;
    _modelElement.addListener( this );

    addInputEventListener( new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            PDimension delta = event.getDeltaRelativeTo( CNode.this.getParent() );
            Point2D p = _modelElement.getPosition();
            Point2D pNew = new Point2D.Double( p.getX() + delta.getWidth(), p.getY() + delta.getHeight() );
            modelElement.setPosition( pNew );
        }
    } );
    
    positionChanged();
    orientationChanged();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:CNode.java

示例11: dragSpline

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
private void dragSpline( PInputEvent event, Point2D.Double tx ) {
    double dy = tx.getY();
    double dx = tx.getX();

    //Make it so the spline can't be dragged out of the screen, tricky since the visible screen changes depending on the aspect ratio
    if ( dy < 0 && spline.getMinControlPointY() < 0 ||
         dy > 0 && spline.getMaxControlPointY() > splineEnvironment.getMaxDragY() ||
         dx < 0 && spline.getMinControlPointX() < splineEnvironment.getMinDragX() ||
         dx > 0 && spline.getMaxControlPointX() > splineEnvironment.getMaxDragX() ) {
        return;
    }

    translateAll( tx );
    if ( isAttachAllowed( event ) ) {
        proposeMatchesTrunk();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:SplineNode.java

示例12: EndGraphic

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public EndGraphic() {
    Ellipse2D.Double shape = new Ellipse2D.Double( 0, 0, 15, 15 );

    phetShapeGraphic = new PPath( shape );
    phetShapeGraphic.setPaint( Color.black );
    addChild( phetShapeGraphic );
    addInputEventListener( new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            Dimension2D dx = getDelta( event );
            MeasuringTape.this.translateEndPoint( dx.getWidth(), dx.getHeight() );
        }
    } );
    addInputEventListener( new CursorHandler( Cursor.HAND_CURSOR ) );

    int crossHairSize = 10;
    CrossHairGraphic crossHairGraphic = new CrossHairGraphic( crossHairSize );
    crossHairGraphic.setPaint( Color.yellow );
    addChild( crossHairGraphic );

    crossHairGraphic.setOffset( phetShapeGraphic.getWidth() / 2 - crossHairSize / 2, phetShapeGraphic.getHeight() / 2 - crossHairSize / 2 );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:MeasuringTape.java

示例13: CalendarNode

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public CalendarNode() {
    for (int week = 0; week < numWeeks; week++) {
        for (int day = 0; day < numDays; day++) {
            addChild(new DayNode(week, day));
        }
    }

    CalendarNode.this.addInputEventListener(new PBasicInputEventHandler() {
        public void mouseReleased(PInputEvent event) {
            DayNode pickedDay = (DayNode) event.getPickedNode();
            if (pickedDay.hasWidthFocus && pickedDay.hasHeightFocus) {
                setFocusDay(null, true);
            }
            else {
                setFocusDay(pickedDay, true);
            }
        }
    });
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:20,代码来源:CalendarNode.java

示例14: handleButton

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
private void handleButton(final PSwingEvent e1, final PInputEvent aEvent, final ButtonData buttonData) {
    final MouseEvent m1 = e1.asMouseEvent();
    if (involvesSceneNode(buttonData)) {
        // TODO: this probably won't handle viewing through multiple
        // cameras.

        final Point2D pt = new Point2D.Double(m1.getX(), m1.getY());
        cameraToLocal(e1.getPath().getTopCamera(), pt, buttonData.getPNode());
        final MouseEvent tempEvent = new MouseEvent(buttonData.getFocusedComponent(), m1.getID(), m1.getWhen(), m1
                .getModifiers(), (int) pt.getX() - buttonData.getOffsetX(), (int) pt.getY()
                - buttonData.getOffsetY(), m1.getClickCount(), m1.isPopupTrigger());

        final PSwingEvent e2 = PSwingMouseEvent.createMouseEvent(tempEvent.getID(), tempEvent, aEvent);
        dispatchEvent(buttonData.getFocusedComponent(), e2);
    }
    else {
        dispatchEvent(buttonData.getFocusedComponent(), e1);
    }
    // buttonData.getPSwing().repaint(); //Experiment with SliderExample
    // (from Martin) suggests this line is unnecessary, and a serious
    // problem in performance.
    m1.consume();
    if (e1.getID() == MouseEvent.MOUSE_RELEASED) {
        buttonData.mouseReleased();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:PSwingEventHandler.java

示例15: mouseDragged

import edu.umd.cs.piccolo.event.PInputEvent; //导入依赖的package包/类
public void mouseDragged( PInputEvent e ) {
    if( startLocation == null ) {
        mousePressed( e );
    }
    else {
        Point2D fin = e.getPosition();

        Point2D.Double rel = new Point2D.Double( fin.getX() - startLocation.x, fin.getY() - startLocation.y );
        double dx = rel.x;
        double dy = rel.y;

        int modelDX = (int)( dx / getColorGrid().getCellWidth() );
        int modelDY = (int)( dy / getColorGrid().getCellHeight() );
        int newWidth = origDim.width + modelDX;
        int newHeight = origDim.height + modelDY;
        newWidth = Math.max( newWidth, 0 );
        newHeight = Math.max( newHeight, 0 );
        rectangularObject.setSize( newWidth, newHeight );
    }

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


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