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


Java PBasicInputEventHandler类代码示例

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


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

示例1: main

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的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

示例2: WorkEnergyRulerNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param transform        - Model view transform.
 * @param rulerModelOrigin - Origin point for the ruler - the ruler will be positioned such that the 0 tick
 *                         mark on the right side is at this location in model space.
 */
public WorkEnergyRulerNode( final Property<Boolean> visibleProperty, ModelViewTransform2D transform, Point2D rulerModelOrigin ) {
    visibleProperty.addObserver( new SimpleObserver() {
        public void update() {
            setVisible( visibleProperty.get() );
        }
    } );

    final RulerNode rulerNode = new RulerNode( Math.abs( transform.modelToViewDifferentialYDouble( 5 ) ),
                                               50, new String[] { "0", "1", "2", "3", "4", "5" }, "m", 4, 18 );
    rulerNode.rotate( -Math.PI / 2 );
    rulerNode.setOffset( transform.modelToViewXDouble( rulerModelOrigin.getX() ) - rulerNode.getFullBoundsReference().width - WorkEnergyObjectNode.AMOUNT_LINE_EXTENDS_BEYOND_OBJECT,
                         transform.modelToViewYDouble( rulerModelOrigin.getY() ) + rulerNode.getInsetWidth() );
    addChild( rulerNode );

    addInputEventListener( new CursorHandler() );
    addInputEventListener( new PBasicInputEventHandler() {
        @Override
        public void mouseDragged( PInputEvent event ) {
            PDimension delta = event.getDeltaRelativeTo( getParent() );
            translate( delta.width, delta.height );
        }
    } );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:WorkEnergyRulerNode.java

示例3: RampGraphic

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public RampGraphic( RampPanel rampPanel, Surface ramp ) {
    super( rampPanel, ramp );
    arrowGraphic = createArrowGraphic();
    addChild( arrowGraphic );

    getSurfaceGraphic().addInputEventListener( new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            arrowGraphic.setVisible( false );
        }
    } );
    getSurface().addObserver( new SimpleObserver() {
        public void update() {
            arrowGraphic.setVisible( false );
        }
    } );

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

示例4: BodyGraphic

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public BodyGraphic() {
    try {
        imageGraphic = new PImage( ImageLoader.loadBufferedImage( "the-ramp/images/tape.gif" ) );
    }
    catch ( IOException e ) {
        e.printStackTrace();
    }
    addChild( imageGraphic );

    addInputEventListener( new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            Dimension2D dx = getDelta( event );
            translateAll( dx.getWidth(), dx.getHeight() );
        }
    } );

    int crossHairLength = 10;
    CrossHairGraphic crossHairGraphic = new CrossHairGraphic( crossHairLength );
    addChild( crossHairGraphic );
    crossHairGraphic.setOffset( imageGraphic.getWidth() - crossHairLength / 2, imageGraphic.getHeight() - crossHairLength / 2 );
    addInputEventListener( new CursorHandler( Cursor.HAND_CURSOR ) );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:MeasuringTape.java

示例5: EndGraphic

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的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

示例6: SimSharingTestModule

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public SimSharingTestModule() {
    super( "Test", new ConstantDtClock( 30 ) );
    setSimulationPanel( new PhetPCanvas() {{
        addScreenChild( new PhetPPath( new Rectangle2D.Double( 0, 0, 100, 100 ), Color.yellow, new BasicStroke( 2 ), Color.blue ) {{
            addInputEventListener( new CursorHandler() );
            addInputEventListener( new PBasicInputEventHandler() {
                @Override public void mouseDragged( PInputEvent event ) {
                    position.set( position.get().plus( event.getDeltaRelativeTo( getParent() ) ) );
                }
            } );
            position.addObserver( new VoidFunction1<Vector2D>() {
                public void apply( Vector2D immutableVector2D ) {
                    setOffset( immutableVector2D.toPoint2D() );
                }
            } );
        }} );
    }} );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:SimSharingTestModule.java

示例7: StoveControlSliderNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public StoveControlSliderNode( final SettableProperty<Double> value ) {
    super( UserComponents.stoveSlider, -1, 1, 6, 75, value, new BooleanProperty( true ) );

    // Show labels for add, zero, and remove.
    addLabel( +1, new PhetPText( StatesOfMatterStrings.STOVE_CONTROL_PANEL_HEAT_LABEL, LABEL_FONT ) );
    addLabel( 0.0, new TickMark() );
    addLabel( -1, new PhetPText( StatesOfMatterStrings.STOVE_CONTROL_PANEL_COOL_LABEL, LABEL_FONT ) );

    // Return to 0 when the user releases the slider.
    addInputEventListener( new PBasicInputEventHandler() {
        @Override public void mouseReleased( PInputEvent event ) {
            value.set( 0.0 );
        }
    } );


    // Show a gradient in the track that goes from orange to light blue to
    // indicate the heat/coolness setting.
    setTrackFillPaint( new GradientPaint( 0, 0, TOP_SIDE_TRACK_COLOR, 0, (float) trackLength, BOTTOM_SIDE_TRACK_COLOR, false ) );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:21,代码来源:StoveControlSliderNode.java

示例8: EvaporationControlNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的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

示例9: CNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的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

示例10: circle

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
private PhetPPath circle( final IntegerProperty selectedPage, final int circleDiameter, final int index ) {
    return new PhetPPath( new Ellipse2D.Double( 0, 0, circleDiameter, circleDiameter ), new BasicStroke( 2 ), Color.gray ) {{
        selectedPage.addObserver( new VoidFunction1<Integer>() {
            public void apply( final Integer integer ) {
                setPaint( integer == index ? Color.black : BuildAFractionCanvas.TRANSPARENT );
            }
        } );

        addInputEventListener( new CursorHandler() );
        addInputEventListener( new PBasicInputEventHandler() {
            @Override public void mouseReleased( final PInputEvent event ) {
                SimSharingManager.sendButtonPressed( chain( carouselRadioButton, index ) );
                selectedPage.set( index );
            }
        } );
    }};
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:CarouselDotComponent.java

示例11: text

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
private PhetPText text( final String levelName, final IntegerProperty selectedPage, final int index ) {
    return new PhetPText( levelName, SettingsOnOffPanel.FONT ) {{
        selectedPage.addObserver( new VoidFunction1<Integer>() {
            public void apply( final Integer integer ) {
                setTextPaint( integer == index ? Color.black : Color.gray );
            }
        } );
        addInputEventListener( new CursorHandler() );
        addInputEventListener( new PBasicInputEventHandler() {
            @Override public void mouseReleased( final PInputEvent event ) {
                SimSharingManager.sendButtonPressed( chain( carouselRadioButtonLabel, index ) );
                selectedPage.set( index );
            }
        } );
    }};
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:CarouselDotComponent.java

示例12: onNewBunny

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
/**
 * Handles a new bunny
 *
 * @param bunny The bunny
 */
public void onNewBunny( final Bunny bunny ) {
    if ( !bunny.isAlive() ) {
        // don't instantiate a dead bunny (loading config, etc)
        return;
    }
    // create a bunny node with the correct visual appearance
    BunnyNode bunnyNode = new BunnyNode( model, bunny.getColorPhenotype(), bunny.getTeethPhenotype(), bunny.getTailPhenotype(), this, bunny.getPosition() );

    // randomly position the bunny
    bunnyNode.setFlipped( !bunny.isMovingRight() );

    // add the bunny
    addSprite( bunnyNode );
    bunny.addListener( bunnyNode );
    sprites.add( bunnyNode );
    bunnies.add( bunnyNode );

    bunnyNode.addInputEventListener( new PBasicInputEventHandler() {
        @Override
        public void mouseClicked( PInputEvent event ) {
            bunny.setSelected( true );
            notifyBunnySelected( bunny );
        }
    } );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:LandscapeNode.java

示例13: RotationRulerNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public RotationRulerNode( double distanceBetweenFirstAndLastTick, double height, String[] majorTickLabels, String units, int numMinorTicksBetweenMajors, int fontSize ) {
    super( distanceBetweenFirstAndLastTick, 14 * 3.0 / 200.0, height, majorTickLabels, new PhetFont( 14 ), units, new PhetFont( 14 ), numMinorTicksBetweenMajors, height * 0.4 / 2, height * 0.2 / 2 );
    setBackgroundPaint( new Color( 236, 225, 113, 150 ) );
    setBackgroundStroke( new BasicStroke( (float) RotationPlayAreaNode.SCALE ) );
    setTickStroke( new BasicStroke( (float) RotationPlayAreaNode.SCALE ) );
    setUnitsSpacing( 3 * RotationPlayAreaNode.SCALE );
    setFontScale( RotationPlayAreaNode.SCALE );

    addInputEventListener( new CursorHandler() );
    addInputEventListener( new PBasicInputEventHandler() {
        public void mouseDragged( PInputEvent event ) {
            PDimension delta = event.getDeltaRelativeTo( getParent() );
            translate( delta.width,
                       -delta.height );//Y-axis is inverted
        }
    } );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:RotationRulerNode.java

示例14: LimbNode

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
public LimbNode( String imageLoc, Point pivot ) {
    imageNode = PImageFactory.create( imageLoc );
    addChild( imageNode );
    highlight = new HighlightNode( imageNode.getImage() );
    addChild( highlight );
    addInputEventListener( new PBasicInputEventHandler() {
        public void mousePressed( PInputEvent event ) {
            super.mousePressed( event );
            if ( highlight.getVisible() ) {
                highlight.setVisible( false );
                removeChild( highlight );
            }
        }
    } );
    this.pivot = pivot;
    addInputEventListener( new RotationHandler( this ) );
    addInputEventListener( new CursorHandler() );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:LimbNode.java

示例15: addWiggleMe

import edu.umd.cs.piccolo.event.PBasicInputEventHandler; //导入依赖的package包/类
private void addWiggleMe() {
    if ( _wiggleMe == null ) {
        // Wiggle Me that points at the eigenstates
        String wiggleMeString = BSResources.getString( "wiggleMe.eigenstates" );
        _wiggleMe = new DefaultWiggleMe( _canvas, wiggleMeString );
        _parentNode.addChild( _wiggleMe );
        _wiggleMe.setOffset( 250, -50 );
        _wiggleMe.animateTo( 250, 250 );
        _wiggleMe.addInputEventListener( new PBasicInputEventHandler() {
            // Clicking on the wiggle me makes it go away.
            public void mousePressed( PInputEvent event ) {
                disableWiggleMe();
            }
        } );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:BSAbstractModule.java


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