本文整理汇总了Java中edu.umd.cs.piccolo.PNode.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java PNode.addChild方法的具体用法?Java PNode.addChild怎么用?Java PNode.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.piccolo.PNode
的用法示例。
在下文中一共展示了PNode.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMoleculeNodes
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void updateMoleculeNodes( PNode parent, Molecule molecule, int count ) {
// remove nodes
while ( count < parent.getChildrenCount() && count >= 0 ) {
parent.removeChild( parent.getChildrenCount() - 1 );
}
// add nodes
while ( count > parent.getChildrenCount() ) {
// create node
PImage node = new PImage( molecule.getImage() );
node.setScale( MOLECULE_IMAGE_SCALE );
parent.addChild( node );
// move to a random location
Point2D p = getRandomPoint();
double x = p.getX() - ( node.getFullBoundsReference().getWidth() / 2 );
double y = p.getY() - ( node.getFullBoundsReference().getHeight() / 2 );
node.setOffset( x, y );
}
assert( count == parent.getChildrenCount() );
}
示例2: WolfNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public WolfNode( LandscapeNode landscapeNode, Point3D position ) {
super( landscapeNode, position );
PNode wolfHolder = new PNode();
wolfGraphic = new PNode();
wolfImage = NaturalSelectionResources.getImageNode( NaturalSelectionConstants.IMAGE_WOLF );
wolfGraphic.addChild( wolfImage );
wolfHolder.addChild( wolfGraphic );
addChild( wolfHolder );
wolfHolder.setOffset( -wolfImage.getWidth() / 2, -wolfImage.getHeight() );
rescale();
setPickable( false );
}
示例3: LabeledNucleusNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public LabeledNucleusNode( NucleusDisplayInfo displayInfo ){
// Create the "layers" where the representation and the label will reside.
_representationLayer = new PNode();
addChild(_representationLayer);
_labelLayer = new PNode();
addChild(_labelLayer);
// Get shorthand references to the needed display information.
String isotopeNumber = displayInfo.getIsotopeNumberString();
String chemicalSymbol = displayInfo.getChemicalSymbol();
Color labelColor = displayInfo.getLabelColor();
// Create and add the shadowed label.
String labelText = "<html><sup><font size=-2>" + isotopeNumber + " </font></sup>" + chemicalSymbol + "</html>";
_label = new ShadowHTMLNode( labelText );
_label.setColor( labelColor );
_label.setShadowColor( labelColor == Color.BLACK ? Color.WHITE : Color.BLACK );
_label.setShadowOffset( 0.5, 0.5 );
_labelLayer.addChild(_label);
// Make sure we aren't pickable since we don't handle any mouse events.
setPickable(false);
setChildrenPickable(false);
}
示例4: ModelElementGraphicManager
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Constructor
*
* @param phetPCanvas
* @param canvas
*/
public ModelElementGraphicManager( AbstractMriModule module, PhetPCanvas phetPCanvas, PNode canvas ) {
this.module = module;
this.phetPCanvas = phetPCanvas;
this.canvas = canvas;
model = (MriModel)module.getModel();
model.addListener( new MriModel.ChangeAdapter() {
public void sampleMaterialChanged( SampleMaterial sampleMaterial ) {
updateDipoleGraphics();
}
} );
// Add composite nodes in the layer order we want to maintain
canvas.addChild( magnetCoilLayer );
canvas.addChild( headLayer );
canvas.addChild( sampleChamberLayer );
canvas.addChild( dipolesLayer );
canvas.addChild( rfLayer );
// canvas.addChild( headLayer );
canvas.addChild( controlLayer );
}
示例5: BalancedNotSimplifiedNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private BalancedNotSimplifiedNode( boolean closeButtonVisible, boolean titleBarVisible ) {
super( false /* smile */, closeButtonVisible, titleBarVisible, new Function1<PhetFont, PNode>() {
public PNode apply( PhetFont font ) {
PNode parentNode = new PNode();
PImage checkNode = new PImage( BCEResources.getImage( "Check-Mark-u2713.png" ) );
parentNode.addChild( checkNode );
PText balancedTextNode = new PText( BCEStrings.BALANCED );
balancedTextNode.setFont( font );
parentNode.addChild( balancedTextNode );
PImage xNode = new PImage( BCEResources.getImage( "Heavy-Ballot-X-u2718.png" ) );
parentNode.addChild( xNode );
PText notSimplifiedTextNode = new PText( BCEStrings.NOT_SIMPLIFIED );
notSimplifiedTextNode.setFont( font );
parentNode.addChild( notSimplifiedTextNode );
// layout: icons on left, text on right
final double maxImageWidth = Math.max( checkNode.getFullBoundsReference().getWidth(), xNode.getFullBoundsReference().getWidth() );
double x = maxImageWidth - checkNode.getFullBoundsReference().getWidth();
double y = 0;
checkNode.setOffset( x, y );
x = checkNode.getFullBoundsReference().getMaxX() + 2;
y = checkNode.getFullBoundsReference().getCenterY() - ( balancedTextNode.getFullBoundsReference().getHeight() / 2 );
balancedTextNode.setOffset( x, y );
x = maxImageWidth - xNode.getFullBoundsReference().getWidth();
y = Math.max( checkNode.getFullBoundsReference().getMaxY(), balancedTextNode.getFullBoundsReference().getMaxY() ) + 4;
xNode.setOffset( x, y );
x = balancedTextNode.getXOffset();
y = xNode.getFullBoundsReference().getCenterY() - ( notSimplifiedTextNode.getFullBoundsReference().getHeight() / 2 );
notSimplifiedTextNode.setOffset( x, y );
return parentNode;
}
} );
}
示例6: BufferedRotationPlatformNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public BufferedRotationPlatformNode( final RotationPlatform rotationPlatform ) {
this.rotationPlatform = rotationPlatform;
contentNode = new PNode();
horizontalCrossHair = new PhetPPath( getHorizontalCrossHairPath(), new BasicStroke( (float) ( 2 * RotationPlayAreaNode.SCALE ) ), Color.black );
contentNode.addChild( horizontalCrossHair );
outerBorder = new PhetPPath( getBorderStroke(), Color.black );
contentNode.addChild( outerBorder );
addChild( contentNode );
rotationPlatform.getPositionVariable().addListener( new ITemporalVariable.ListenerAdapter() {
public void valueChanged() {
doUpdateAngle();
}
} );
rotationPlatform.addListener( new RotationPlatform.Adapter() {
public void radiusChanged() {
updateRadius();
}
public void innerRadiusChanged() {
}
} );
RotationPlatformNode rotationPlatformNode = new RotationPlatformNode( rotationPlatform );
Image im = rotationPlatformNode.toImage( 500, 500, Color.white );
// PImage image = new PImage( new BufferedImage( 100, 100, BufferedImage.TYPE_INT_RGB ) );
PImage image = new PImage( im );
image.scale( RotationPlayAreaNode.SCALE );
image.translate( -image.getFullBounds().getWidth() / 2 / RotationPlayAreaNode.SCALE, -image.getFullBounds().getWidth() / 2 / RotationPlayAreaNode.SCALE );
// contentNode.addChild( image );
doUpdateAngle();
updateRadius();
}
示例7: composeOtherNodes
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void composeOtherNodes() {
final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
// create parts for the face.
final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
eye1.setPaint(Color.YELLOW);
final PNode eye2 = (PNode) eye1.clone();
final PNode mouth = PPath.createRectangle(0, 0, 40, 20);
mouth.setPaint(Color.BLACK);
// add the face parts
myCompositeFace.addChild(eye1);
myCompositeFace.addChild(eye2);
myCompositeFace.addChild(mouth);
// don't want anyone grabbing out our eye's.
myCompositeFace.setChildrenPickable(false);
// position the face parts.
eye2.translate(25, 0);
mouth.translate(0, 30);
// set the face bounds so that it neatly contains the face parts.
final PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
myCompositeFace.setBounds(b.inset(-5, -5));
// opps it to small, so scale it up.
myCompositeFace.scale(1.5);
getCanvas().getLayer().addChild(myCompositeFace);
}
示例8: addNeutron
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void addNeutron( PNode nucleus, double radius, double pixelsPerFm ) {
PNode neutron = new StandaloneNeutronNode();
neutron.scale( pixelsPerFm );
PImage neutronImage = new PImage( neutron.toImage() );
setParticlePosition( radius, neutronImage, pixelsPerFm );
nucleus.addChild( neutronImage );
}
示例9: createLactoseNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Generate an image of Lactose. This is necessary because Lactose exists
* as a combination of two simple model elements in the model, so there is
* no model element that can be created easily as can be done for the
* simple model elements.
*/
private PNode createLactoseNode(ModelViewTransform2D mvt){
PNode lactoseNode = new PNode();
PNode glucoseNode = new SimpleModelElementNode(new Glucose(), mvt, false);
glucoseNode.setOffset(-glucoseNode.getFullBoundsReference().width / 2, 0);
lactoseNode.addChild(glucoseNode);
PNode galactoseNode = new SimpleModelElementNode(new Galactose(), mvt, false);
galactoseNode.setOffset(galactoseNode.getFullBoundsReference().width / 2, 0);
lactoseNode.addChild(galactoseNode);
lactoseNode.setPickable(false);
lactoseNode.setChildrenPickable(false);
return lactoseNode;
}
示例10: NotBalancedVerboseNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private NotBalancedVerboseNode( final Equation equation, boolean closeButtonVisible, boolean titleBarVisible, final boolean whyButtonVisible,
final ActionListener whyButtonListener, final BalancedRepresentation balancedRepresentation, final HorizontalAligner aligner ) {
super( false /* smile */, closeButtonVisible, titleBarVisible, new Function1<PhetFont, PNode>() {
public PNode apply( PhetFont font ) {
PNode parentNode = new PNode();
// icon and text
PNode iconAndTextNode = new PNode();
parentNode.addChild( iconAndTextNode );
PImage iconNode = new PImage( BCEResources.getImage( "Heavy-Ballot-X-u2718.png" ) );
iconAndTextNode.addChild( iconNode );
PText textNode = new PText( BCEStrings.NOT_BALANCED );
textNode.setFont( font );
iconAndTextNode.addChild( textNode );
// "Hide Why" button
HTMLImageButtonNode hideWhyButton = null;
if ( whyButtonVisible ) {
hideWhyButton = new HTMLImageButtonNode( BCEStrings.HIDE_WHY, new PhetFont( Font.BOLD, 18 ), Color.WHITE );
hideWhyButton.addActionListener( whyButtonListener );
}
// representation of "balanced"
PNode balanceRepresentationNode = null;
if ( balancedRepresentation == BalancedRepresentation.BALANCE_SCALES ) {
balanceRepresentationNode = new BalanceScalesNode( new Property<Equation>( equation ), aligner );
}
else if ( balancedRepresentation == BalancedRepresentation.BAR_CHARTS ) {
balanceRepresentationNode = new BarChartsNode( new Property<Equation>( equation ), aligner );
}
else {
// BalancedRepresentation.NONE, show nothing
}
// layout
{
// icon to left of text
iconNode.setOffset( 0, 0 );
double x = iconNode.getFullBoundsReference().getMaxX() + 2;
double y = iconNode.getFullBoundsReference().getCenterY() - ( textNode.getFullBoundsReference().getHeight() / 2 );
textNode.setOffset( x, y );
// button centered under icon and text
if ( hideWhyButton != null ) {
x = iconAndTextNode.getFullBoundsReference().getCenterX() - ( hideWhyButton.getFullBoundsReference().getWidth() / 2 ) - PNodeLayoutUtils.getOriginXOffset( hideWhyButton );
y = parentNode.getFullBoundsReference().getMaxY() - PNodeLayoutUtils.getOriginYOffset( hideWhyButton ) + 25;
hideWhyButton.setOffset( x, y );
parentNode.addChild( hideWhyButton );
}
// balanced representation centered under button
if ( balanceRepresentationNode != null ) {
x = iconAndTextNode.getFullBoundsReference().getCenterX() - ( balanceRepresentationNode.getFullBoundsReference().getWidth() / 2 ) - PNodeLayoutUtils.getOriginXOffset( balanceRepresentationNode );
y = parentNode.getFullBoundsReference().getMaxY() - PNodeLayoutUtils.getOriginYOffset( balanceRepresentationNode ) + 25;
balanceRepresentationNode.setOffset( x, y );
parentNode.addChild( balanceRepresentationNode );
}
}
return parentNode;
}
} );
}
示例11: BoxOfAtomsNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Constructor.
* @param boxSize
* @param tinyBoxSize
*/
public BoxOfAtomsNode( Dimension boxSize, Dimension tinyBoxSize ) {
super();
setPickable( false );
setChildrenPickable( false );
// Box, origin in upper-left corner of bounds
PNode boxNode = new PNode();
{
final float w = (float)boxSize.width;
GeneralPath topPath = new GeneralPath();
topPath.moveTo( BACK_OFFSET * w, 0 );
topPath.lineTo( ( 1 - BACK_OFFSET ) * w, 0 );
topPath.lineTo( w, BACK_DEPTH );
topPath.lineTo( 0, BACK_DEPTH );
topPath.closePath();
PPath topNode = new PPath();
topNode.setPathTo( topPath );
topNode.setPaint( new GradientPaint( 0f, 0f, TOP_COLOR_BACK, 0f, BACK_DEPTH, TOP_COLOR_FRONT ) );
topNode.setStroke( STROKE );
topNode.setStrokePaint( STROKE_COLOR );
PPath frontNode = new PPath( new Rectangle2D.Double( 0, BACK_DEPTH, boxSize.width, boxSize.height ) );
frontNode.setPaint( BOX_FRONT_PAINT );
frontNode.setStroke( STROKE );
frontNode.setStrokePaint( STROKE_COLOR );
boxNode.addChild( frontNode );
boxNode.addChild( topNode );
}
boxNode.setOffset( 0, 0 );
addChild( boxNode );
// Tiny box
_tinyBoxNode = new PPath( new Rectangle2D.Double( 0, 0, tinyBoxSize.width, tinyBoxSize.height ) );
_tinyBoxNode.setPaint( TINY_BOX_FILL_COLOR );
_tinyBoxNode.setStrokePaint( TINY_BOX_STROKE_COLOR );
_tinyBoxNode.setStroke( TINY_BOX_STROKE );
// in upper right quadrant of box
double x = boxNode.getFullBounds().getX() + ( 0.6 * boxNode.getFullBounds().getWidth() );
double y = boxNode.getFullBounds().getY() + ( 0.5 * boxNode.getFullBounds().getHeight() );
_tinyBoxNode.setOffset( x, y );
addChild( _tinyBoxNode );
}
示例12: NotBalancedTerseNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private NotBalancedTerseNode( boolean closeButtonVisible, boolean titleBarVisible, final boolean whyButtonVisible, final ActionListener whyButtonListener ) {
super( false /* smile */, closeButtonVisible, titleBarVisible, new Function1<PhetFont, PNode>() {
public PNode apply( PhetFont font ) {
PNode parentNode = new PNode();
// icon and text
PNode iconAndTextNode = new PNode();
parentNode.addChild( iconAndTextNode );
PImage iconNode = new PImage( BCEResources.getImage( "Heavy-Ballot-X-u2718.png" ) );
iconAndTextNode.addChild( iconNode );
PText textNode = new PText( BCEStrings.NOT_BALANCED );
textNode.setFont( font );
iconAndTextNode.addChild( textNode );
// "Show Why" button
HTMLImageButtonNode showWhyButton = null;
if ( whyButtonVisible ) {
showWhyButton = new HTMLImageButtonNode( BCEStrings.SHOW_WHY, new PhetFont( Font.BOLD, 18 ), Color.WHITE );
showWhyButton.addActionListener( whyButtonListener );
}
// layout
{
// icon to left of text
iconNode.setOffset( 0, 0 );
double x = iconNode.getFullBoundsReference().getMaxX() + 2;
double y = iconNode.getFullBoundsReference().getCenterY() - ( textNode.getFullBoundsReference().getHeight() / 2 );
textNode.setOffset( x, y );
// button centered under icon and text
if ( showWhyButton != null ) {
x = iconAndTextNode.getFullBoundsReference().getCenterX() - ( showWhyButton.getFullBoundsReference().getWidth() / 2 ) - PNodeLayoutUtils.getOriginXOffset( showWhyButton );
y = parentNode.getFullBoundsReference().getMaxY() - PNodeLayoutUtils.getOriginYOffset( showWhyButton ) + 25;
showWhyButton.setOffset( x, y );
parentNode.addChild( showWhyButton );
}
}
return parentNode;
}
} );
}
示例13: PedigreeChartCanvas
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public PedigreeChartCanvas() {
super.setWorldTransformStrategy( new ConstantTransformStrategy( new AffineTransform() ) );
setBackground( NaturalSelectionApplication.accessibleColor( NaturalSelectionConstants.COLOR_GENERATION_CHART ) );
PNode rootNode = new PNode();
addWorldChild( rootNode );
pedigreeNode = new PedigreeNode();
rootNode.addChild( pedigreeNode );
pedigreeNode.setOffset( new Point2D.Double( 0, PEDIGREE_TOP_PADDING ) );
setCenterPoint( 0 );
}
示例14: InjectorNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public InjectorNode( double rotationAngle, final SimpleObserver inject ) {
this.inject = inject;
// Create the root node to which the various constituent parts can be
// added.
injectorNode = new PNode();
// Load the graphic images for this device. These are offset in order
// to make the center of rotation be the center of the bulb.
BufferedImage injectorBodyImage = RESOURCES.getImage( "squeezer_background.png" );
PNode injectorBodyImageNode = new PImage( injectorBodyImage );
Rectangle2D originalBodyBounds = injectorBodyImageNode.getFullBounds();
injectorBodyImageNode.setOffset( -originalBodyBounds.getWidth() / 2, -originalBodyBounds.getHeight() / 2 );
injectorNode.addChild( injectorBodyImageNode );
pressedButtonImage = RESOURCES.getImage( "button_pressed.png" );
unpressedButtonImage = RESOURCES.getImage( "button_unpressed.png" );
buttonImageNode = new PImage( unpressedButtonImage );
buttonImageNode.setOffset( BUTTON_OFFSET );
injectorNode.addChild( buttonImageNode );
// Rotate and scale the image node as a whole.
double scale = INJECTOR_HEIGHT / injectorBodyImageNode.getFullBoundsReference().height;
injectorNode.rotate( -rotationAngle );
injectorNode.scale( scale );
// Add the injector image node. Note that the position has to be
// tweaked in order to account for the rotation of the node image,
// since the rotation of the square image enlarges the bounds.
injectorNode.setOffset( -Math.abs( Math.sin( rotationAngle * 2 ) ) * 30, 0 );
addChild( injectorNode );
// Set up the injection point offset. This makes some assumptions
// about the nature of the image, and will need to be updated if the
// image is changed.
distanceCenterToTip = 0.7 * INJECTOR_HEIGHT;
final double centerOffsetX = 0.4 * INJECTOR_HEIGHT;
Dimension2D injectionPointOffset = new PDimension();
injectionPointOffset.setSize( distanceCenterToTip * Math.cos( rotationAngle ) + centerOffsetX,
distanceCenterToTip * Math.sin( -rotationAngle ) );
// Set up the button handling.
injectorBodyImageNode.setPickable( false );
buttonImageNode.setPickable( true );
}
示例15: CurvePane
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public CurvePane( final MRModule module, Dimension upperPaneSize ) {
super( new Rectangle2D.Double( 0,
0,
upperPaneSize.width - 1,
(int)( MRConfig.ENERGY_VIEW_SIZE.getHeight() )
- upperPaneSize.height
- MRConfig.ENERGY_VIEW_REACTION_LEGEND_SIZE.height
) );
mrModel = module.getMRModel();
curvePaneSize = new Dimension( upperPaneSize.width, (int)( MRConfig.ENERGY_VIEW_SIZE.getHeight() )
- upperPaneSize.height
- MRConfig.ENERGY_VIEW_REACTION_LEGEND_SIZE.height );
curveAreaSize = new Dimension( (int)curvePaneSize.getWidth() - curveAreaInsets.left - curveAreaInsets.right,
(int)curvePaneSize.getHeight() - curveAreaInsets.top - curveAreaInsets.bottom );
PNode totalEnergyLineLayer = new PNode();
totalEnergyLineLayer.setOffset( curveAreaInsets.left, curveAreaInsets.top );
PNode curveLayer = new PNode();
curveLayer.setOffset( curveAreaInsets.left, curveAreaInsets.top );
curveLayer.setWidth( curveAreaSize.getWidth() );
curveLayer.setHeight( curveAreaSize.getHeight() );
PNode cursorLayer = new PNode();
cursorLayer.setOffset( curveAreaInsets.left, curveAreaInsets.top );
// the -1 adjusts for a stroke width issue between this pane and the chart pane.
setOffset( 0, upperPaneSize.getHeight() );
setPaint( energyPaneBackgroundColor );
setStrokePaint( new Color( 0, 0, 0, 0 ) );
addChild( curveLayer );
addChild( cursorLayer );
addChild( totalEnergyLineLayer );
// Create the line that shows total energy, and a legend for it
energyLine = new EnergyLine( curveAreaSize, module, module.getClock() );
totalEnergyLineLayer.addChild( energyLine );
// Create the curve, and add a listener to the model that will update the curve if the
// model's energy profile changes
createCurve( mrModel, curveLayer );
curveCreatingModelListener = new CurveCreatingModelListener( mrModel, curveLayer );
mrModel.addListener( curveCreatingModelListener );
// Create the cursor
energyCursor = new EnergyCursor( curveAreaSize.getHeight(), 0, curveAreaSize.getWidth(), mrModel );
energyCursor.setVisible( false );
cursorLayer.addChild( energyCursor );
// Add axes
PNode xAxis = new AxisNode( MRConfig.RESOURCES.getLocalizedString( "EnergyView.ReactionCoordinate" ),
curveAreaSize.getWidth(),
MRConfig.ENERGY_PANE_TEXT_COLOR,
AxisNode.HORIZONTAL,
AxisNode.BOTTOM );
xAxis.setOffset( curveAreaInsets.left - 2,
this.getHeight() - 25 );
addChild( xAxis );
PNode yAxis = new AxisNode( "Energy", 200,
MRConfig.ENERGY_PANE_TEXT_COLOR,
AxisNode.VERTICAL,
AxisNode.TOP );
yAxis.setOffset( curveAreaInsets.left - 2, this.getHeight() - 25 );
addChild( yAxis );
}