本文整理汇总了Java中edu.umd.cs.piccolo.PNode.addInputEventListener方法的典型用法代码示例。如果您正苦于以下问题:Java PNode.addInputEventListener方法的具体用法?Java PNode.addInputEventListener怎么用?Java PNode.addInputEventListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.piccolo.PNode
的用法示例。
在下文中一共展示了PNode.addInputEventListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createZoomButton
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Create a zoom button. This was created to avoid duplicated code, since
* two of these are needed.
*
* @param size - Size of the button, only one dimension because it is assumed to be square.
* @param labelCharacter - Single character label.
* @return - The button.
*/
private PNode createZoomButton( double size, char labelCharacter ) {
Shape zoomButtonShape = new RoundRectangle2D.Double( 0, 0, size, size, 4, 4 );
PNode zoomButton = new PhetPPath( zoomButtonShape, FILL_COLOR, STROKE, STROKE_COLOR );
zoomButton.addInputEventListener( new CursorHandler( Cursor.HAND_CURSOR ) );
PText zoomButtonLabel = new PText( String.valueOf( labelCharacter ) );
zoomButtonLabel.setPickable( false );
zoomButtonLabel.setFont( SYMBOL_FONT );
zoomButtonLabel.setTextPaint( SYMBOL_COLOR );
zoomButtonLabel.setScale( size * 0.5 / zoomButtonLabel.getFullBoundsReference().width );
zoomButtonLabel.setOffset( size / 2 - zoomButtonLabel.getFullBoundsReference().width / 2,
size / 2 - zoomButtonLabel.getFullBoundsReference().height / 2 );
zoomButton.addChild( zoomButtonLabel );
return zoomButton;
}
示例2: addTiltHandles
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Add the "tilt handles" that allow the user to tilt the plank. The tilt
* handles are not visible to the
*/
private void addTiltHandles() {
final PNode handleLayer = new PNode();
addChild( handleLayer );
// Use a fully transparent color to make the handles invisible. This
// can be made opaque for debugging if needed.
Color handleColor = new Color( 255, 255, 255, 0 );
// Only put the handles on the ends of the plank, otherwise things get
// weird. Note that the handles are invisible.
Rectangle2D plankBounds = plank.getShape().getBounds2D();
final PNode rightHandle = new PhetPPath( new Rectangle2D.Double( mvt.modelToViewDeltaX( plankBounds.getWidth() / 6 ),
-mvt.modelToViewDeltaY( plankBounds.getHeight() ),
mvt.modelToViewDeltaX( plankBounds.getWidth() / 3 ),
-mvt.modelToViewDeltaY( plankBounds.getHeight() ) ),
handleColor );
rightHandle.setOffset( mvt.modelToView( plank.getPivotPoint() ) );
rightHandle.addInputEventListener( new CursorHandler( Cursor.N_RESIZE_CURSOR ) );
handleLayer.addChild( rightHandle );
final PNode leftHandle = new PhetPPath( new Rectangle2D.Double( -mvt.modelToViewDeltaX( plankBounds.getWidth() / 2 ),
-mvt.modelToViewDeltaY( plankBounds.getHeight() ),
mvt.modelToViewDeltaX( plankBounds.getWidth() / 3 ),
-mvt.modelToViewDeltaY( plankBounds.getHeight() ) ),
handleColor );
leftHandle.setOffset( mvt.modelToView( plank.getPivotPoint() ) );
leftHandle.addInputEventListener( new CursorHandler( Cursor.N_RESIZE_CURSOR ) );
handleLayer.addChild( leftHandle );
plank.addShapeObserver( new VoidFunction1<Shape>() {
public void apply( Shape rotatedPlankShape ) {
// Rotate the handles to match the plank's angle.
rightHandle.setRotation( -plank.getTiltAngle() );
leftHandle.setRotation( -plank.getTiltAngle() );
}
} );
rightHandle.addInputEventListener( new TiltHandleDragHandler( plank, canvas, mvt ) );
leftHandle.addInputEventListener( new TiltHandleDragHandler( plank, canvas, mvt ) );
}
示例3: PropertyTogglingImageNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public PropertyTogglingImageNode( final IUserComponent userComponent, Image image, final BooleanProperty property ) {
// Create and add the image node.
PNode imageNode = new PImage( image );
addChild( imageNode );
// Hook up the image node to toggle the property.
imageNode.addInputEventListener( new PBasicInputEventHandler() {
@Override public void mouseReleased( PInputEvent event ) {
SimSharingManager.sendUserMessage( userComponent, UserComponentTypes.icon, pressed, ParameterSet.parameterSet( ParameterKeys.isSelected, !property.get() ) );
property.set( !property.get() );
}
} );
}
示例4: MyWidgetNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public MyWidgetNode() {
// chart
PNode chartNode = new MyChartNode();
addChild( chartNode );
chartNode.addInputEventListener( new PDragEventHandler() );
chartNode.addInputEventListener( new CursorHandler() );
// circle
PNode circleNode = new MyCircleNode();
addChild( circleNode );
circleNode.addInputEventListener( new PDragEventHandler() );
circleNode.addInputEventListener( new CursorHandler() );
// layout: circle to left of chart, vertically aligned
circleNode.setOffset( chartNode.getFullBoundsReference().getMaxX() + 10,
( chartNode.getFullBoundsReference().getHeight() - circleNode.getFullBoundsReference().getHeight() ) / 2 );
}
示例5: TiltPredictionSelectionPanel
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private TiltPredictionSelectionPanel( final IUserComponent userComponent, Image image, final TiltPrediction correspondingPrediction, final Property<TiltPrediction> tiltPredictionProperty,
final Property<BalanceGameModel.GameState> gameStateProperty ) {
// Create and add the panel that represents this tilt prediction choice.
PNode panel = new PImage( image );
panel.setScale( PANEL_WIDTH / panel.getFullBoundsReference().width );
addChild( panel );
// Set up mouse listener that watches to see if the user has
// selected this option.
panel.addInputEventListener( new PBasicInputEventHandler() {
@Override public void mouseReleased( PInputEvent event ) {
tiltPredictionProperty.set( correspondingPrediction );
// Send up a sim-sharing message indicating that this panel
// was selected. Portray it as a radio button, since that
// is essentially how it functions.
SimSharingManager.sendUserMessage( userComponent, radioButton, pressed );
}
} );
// Set up the listener that will highlight or un-highlight the panel.
outline = new PhetPPath( panel.getFullBoundsReference().getBounds2D(), NON_HIGHLIGHT_STROKE, NON_HIGHLIGHT_COLOR );
addChild( outline );
// Add listener for changes to the tilt prediction.
tiltPredictionProperty.addObserver( new VoidFunction1<TiltPrediction>() {
public void apply( TiltPrediction predictionValue ) {
// Turn the highlight on or off.
updateHighlightState( predictionValue == correspondingPrediction, gameStateProperty.get() == BalanceGameModel.GameState.DISPLAYING_CORRECT_ANSWER );
}
} );
// Add listener for changes to the game state.
gameStateProperty.addObserver( new VoidFunction1<BalanceGameModel.GameState>() {
public void apply( BalanceGameModel.GameState gameState ) {
updateHighlightState( tiltPredictionProperty.get() == correspondingPrediction, gameState == BalanceGameModel.GameState.DISPLAYING_CORRECT_ANSWER );
}
} );
// Set the cursor to look different when the user mouses over it.
panel.addInputEventListener( new CursorHandler( CursorHandler.HAND ) );
}
示例6: BondTypeControlNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public BondTypeControlNode( final MoleculeShapesTab module, final PNode graphic, final int bondOrder, final Property<Boolean> enabled ) {
this.module = module;
this.graphic = graphic;
this.bondOrder = bondOrder;
this.enabled = enabled;
addChild( graphic );
// add a blank background that will allow the user to click on this
graphic.addChild( 0, new Spacer( graphic.getFullBounds() ) );
removeButton = new PImage( Images.REMOVE );
removeButton.setOffset( MoleculeShapesControlPanel.INNER_WIDTH - removeButton.getFullBounds().getWidth(),
( graphic.getFullBounds().getHeight() - removeButton.getFullBounds().getHeight() ) / 2 );
addChild( removeButton );
graphic.setOffset( ( MoleculeShapesControlPanel.INNER_WIDTH - removeButton.getFullBounds().getWidth() - graphic.getFullBounds().getWidth() ) / 2, 0 );
removeButton.addInputEventListener( new PBasicInputEventHandler() {
@Override public void mouseClicked( PInputEvent event ) {
LWJGLUtils.invoke( new Runnable() {
public void run() {
PairGroup candidate = getLastMatchingGroup();
// if it exists, remove it
if ( candidate != null ) {
module.getMolecule().removeGroup( candidate );
sendUserMessage( MoleculeShapesSimSharing.UserComponents.bond, UserComponentTypes.sprite, Actions.removed, ParameterSet.parameterSet( ParamKeys.bondOrder, bondOrder ) );
//System response for electron and molecule geometry names, copied from code in GeometryNameNode
systemResponseForGeometries( module.getMolecule() );
}
}
} );
}
} );
module.getMolecule().onBondChanged.addUpdateListener(
new UpdateListener() {
public void update() {
updateState();
}
}, true );
// custom cursor handler for only showing hand when it is enabled
graphic.addInputEventListener( new LWJGLCursorHandler() {
@Override public boolean isEnabled() {
return enabled.get();
}
} );
removeButton.addInputEventListener( new LWJGLCursorHandler() {
@Override public boolean isEnabled() {
return showingRemoveButton;
}
} );
addDragEvent( new Runnable() {
public void run() {
module.startNewInstanceDrag( bondOrder );
sendUserMessage( MoleculeShapesSimSharing.UserComponents.bond, UserComponentTypes.sprite, Actions.created, ParameterSet.parameterSet( ParamKeys.bondOrder, bondOrder ) );
//System response for electron and molecule geometry names, copied from code in GeometryNameNode
systemResponseForGeometries( module.getMolecule() );
}
} );
}