本文整理汇总了Java中edu.umd.cs.piccolo.PNode类的典型用法代码示例。如果您正苦于以下问题:Java PNode类的具体用法?Java PNode怎么用?Java PNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PNode类属于edu.umd.cs.piccolo包,在下文中一共展示了PNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LabeledNucleusNode
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
public LabeledNucleusNode( String isotopeNumber, String chemicalSymbol, Color labelColor ){
// Create the "layers" where the representation and the label will reside.
_representationLayer = new PNode();
addChild(_representationLayer);
_labelLayer = new PNode();
addChild(_labelLayer);
// 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);
}
示例2: PieSetNode
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
protected PieSetNode( final SettableProperty<PieSet> model, final PNode rootNode, final F<SliceNodeArgs, PNode> createSliceNode, final F<PieSet, PNode> createEmptyCellsNode, final F<PieSet, PNode> createBucketIcon,
//Text is on the right for intro, on the left for equality lab
final boolean iconTextOnTheRight ) {
bucketView = new BucketView( model.get().sliceFactory.bucket, createSinglePointScaleInvertedYMapping( new Point(), new Point(), 1 ) );
final SimpleObserver observer = new SimpleObserver() {
public void update() {
//Only update when visible, thus saving time since all models update at the same time
removeAllChildren();
if ( getVisible() ) {
addChild( new PieSetContentNode( bucketView, model, createSliceNode, rootNode, createEmptyCellsNode, createBucketIcon, iconTextOnTheRight ) );
}
}
};
model.addObserver( observer );
addPropertyChangeListener( PROPERTY_VISIBLE, new PropertyChangeListener() {
public void propertyChange( final PropertyChangeEvent evt ) {
observer.update();
}
} );
}
示例3: addWavelengthTickMark
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Add a tick mark for the specified frequency. Frequency tick marks
* go on top of the strip.
*/
private void addWavelengthTickMark( double wavelength, boolean addLabel ) {
// Create and add the tick mark line.
DoubleGeneralPath path = new DoubleGeneralPath();
path.moveTo( 0, 0 );
path.lineTo( 0, TICK_MARK_HEIGHT );
PNode tickMarkNode = new PhetPPath( path.getGeneralPath(), TICK_MARK_STROKE, Color.BLACK );
tickMarkNode.setOffset( getOffsetFromWavelength( wavelength ), STRIP_HEIGHT );
spectrumRootNode.addChild( tickMarkNode );
if ( addLabel ) {
// Create and add the label.
PNode label = createExponentialLabel( wavelength );
label.setOffset(
tickMarkNode.getFullBoundsReference().getCenterX() - label.getFullBoundsReference().width / 2,
tickMarkNode.getFullBoundsReference().getMaxY() );
spectrumRootNode.addChild( label );
}
}
示例4: listenForCanvas
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Attaches a listener to the specified node and all its parents to listen
* for a change in the PSwingCanvas. Only PROPERTY_PARENT listeners are
* added so this code wouldn't handle if a PLayer were viewed by a different
* PCamera since that constitutes a child change.
*
* @param node The child node at which to begin a parent-based traversal for
* adding listeners.
*/
private void listenForCanvas(final PNode node) {
// need to get the full tree for this node
PNode p = node;
while (p != null) {
listenToNode(p);
final PNode parent = p;
// System.out.println( "parent = " + parent.getClass() );
if (parent instanceof PLayer) {
final PLayer player = (PLayer) parent;
// System.out.println( "Found player: with " +
// player.getCameraCount() + " cameras" );
for (int i = 0; i < player.getCameraCount(); i++) {
final PCamera cam = player.getCamera(i);
if (cam.getComponent() instanceof PSwingCanvas) {
updateCanvas((PSwingCanvas) cam.getComponent());
break;
}
}
}
p = p.getParent();
}
}
示例5: handleMouseDragEvent
import edu.umd.cs.piccolo.PNode; //导入依赖的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() );
}
示例6: updateNucleusNodesScale
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Update the scale settings for the nucleus nodes. This is generally
* done if and when the chart is resized.
*/
private void updateNucleusNodesScale() {
if ( _nucleusNodeRadius > 0 ) {
if ( _undecayedNucleusNode != null ) {
_undecayedNucleusNode.setScale( 1 );
_undecayedNucleusNode.setScale( ( _nucleusNodeRadius * 2 ) / _undecayedNucleusNode.getFullBoundsReference().height );
}
Iterator it = _decayedNucleusNodes.iterator();
while ( it.hasNext() ) {
PNode nucleusNode = (PNode) it.next();
nucleusNode.setScale( 1 );
nucleusNode.setScale( ( _nucleusNodeRadius * 2 ) / nucleusNode.getFullBoundsReference().height );
}
}
}
示例7: relayout
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
private void relayout() {
double x = 0;
for ( int i = 0; i < controlLayer.getChildrenCount(); i++ ) {
PNode child = controlLayer.getChild( i );
child.setOffset( x, getControlLayerHeight() / 2 - child.getFullBounds().getHeight() / 2 ); //assumes controls are origined at 0,0
double insetDX = 2.0;//distance between controls
x = x + child.getFullBounds().getWidth() + insetDX;
}//TODO: center so that play button is in the very middle
double playButtonCenter = playPause.getFullBounds().getCenterX();
controlLayer.setOffset( simPanel.getWidth() / 2 - playButtonCenter, timelineNode.getVisible() ? timelineNode.getFullBounds().getHeight() : 0.0 );
backgroundNode.setSize( (int) controlLayer.getFullBounds().getWidth() + 4, (int) controlLayer.getFullBounds().getHeight() + 2 );
backgroundNode.setOffset( controlLayer.getOffset().getX() - 2, controlLayer.getOffset().getY() - 1 );
if ( simPanel.getWidth() > 0 ) {
Dimension pref = new Dimension( simPanel.getWidth(), (int) getLayer().getFullBounds().getHeight() + 1 );
setPreferredSize( pref );
if ( getParent() != null ) {
getParent().doLayout(); //This is necessary to solve this problem: 6/10/2010 Fixed: Record and playback timeline doesn't synchronize size at the right time (seems one behind); When switching back and forth tabs in moving man, the playback timeline changes size.
}
}
}
示例8: updateTickMarks
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
private void updateTickMarks( PNode tickMarkLayer, Plank plank, ModelViewTransform mvt ) {
// Update the tick marks by removing them and redrawing them.
tickMarkLayer.removeAllChildren();
for ( int i = 0; i < plank.getTickMarks().size(); i++ ) {
Stroke tickMarkStroke = NORMAL_TICK_MARK_STROKE;
Stroke highlightStroke = NORMAL_HIGHLIGHT_STROKE;
if ( i % 2 == 0 ) {
// Make some marks bold for easier placement of masses.
// The 'if' clause can be tweaked to put marks in
// different places.
tickMarkStroke = BOLD_TICK_MARK_STROKE;
highlightStroke = BOLD_HIGHLIGHT_STROKE;
}
if ( plank.isTickMarkOccupied( plank.getTickMarks().get( i ) ) ) {
tickMarkLayer.addChild( new PhetPPath( mvt.modelToView( plank.getTickMarks().get( i ) ), highlightStroke, HIGHLIGHT_COLOR ) );
}
tickMarkLayer.addChild( new PhetPPath( mvt.modelToView( plank.getTickMarks().get( i ) ), tickMarkStroke, Color.BLACK ) );
}
}
示例9: installHandleEventHandlers
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Installs the handler that notify its subclasses of handle interaction.
*/
protected void installHandleEventHandlers() {
handleDragger = new HandleDragHandler();
addPropertyChangeListener(PNode.PROPERTY_TRANSFORM, new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
relocateHandle();
}
});
handleDragger.setEventFilter(new PInputEventFilter(InputEvent.BUTTON1_MASK));
handleDragger.getEventFilter().setMarksAcceptedEventsAsHandled(true);
handleDragger.getEventFilter().setAcceptsMouseEntered(false);
handleDragger.getEventFilter().setAcceptsMouseExited(false);
// no need for moved events for handle interaction,
handleDragger.getEventFilter().setAcceptsMouseMoved(false);
// so reject them so we don't consume them
addInputEventListener(handleDragger);
}
示例10: HeadNode
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
public HeadNode( final Human human, Color fill, BasicStroke basicStroke, Color stroke ) {
this.human = human;
headPath = new PhetPPath( fill, basicStroke, stroke );
addChild( headPath );
eyeGraphics = new PNode();
float STROKE_WIDTH = 0.015f;
leftEye = new PhetPPath( createEyePath(), new BasicStroke( STROKE_WIDTH ), Color.black );
rightEye = new PhetPPath( createEyePath(), new BasicStroke( STROKE_WIDTH ), Color.black );
human.addListener( new Human.Adapter() {
public void aliveChanged() {
updateEyesVisible();
}
} );
updateEyesVisible();
eyeGraphics.addChild( leftEye );
eyeGraphics.addChild( rightEye );
addChild( eyeGraphics );
}
示例11: relocateHandle
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Force this handle to relocate itself using its locator.
*/
public void relocateHandle() {
if (locator != null) {
final PBounds b = getBoundsReference();
final Point2D aPoint = locator.locatePoint(null);
if (locator instanceof PNodeLocator) {
final PNode located = ((PNodeLocator) locator).getNode();
final PNode parent = getParent();
located.localToGlobal(aPoint);
globalToLocal(aPoint);
if (parent != located && parent instanceof PCamera) {
((PCamera) parent).viewToLocal(aPoint);
}
}
final double newCenterX = aPoint.getX();
final double newCenterY = aPoint.getY();
if (newCenterX != b.getCenterX() || newCenterY != b.getCenterY()) {
centerBoundsOnPoint(newCenterX, newCenterY);
}
}
}
示例12: ElectronSetNode
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
public ElectronSetNode( final CircuitNode circuitNode, CCKModel model ) {
this.circuitNode = circuitNode;
this.model = model;
model.getParticleSet().addListener( new ElectronSet.Listener() {
public void particlesRemoved( Electron[] electrons ) {
for ( int k = 0; k < electrons.length; k++ ) {
Electron electron = electrons[k];
for ( int i = 0; i < getChildrenCount(); i++ ) {
PNode child = getChild( i );
if ( child instanceof ElectronNode && ( (ElectronNode) child ).getElectron() == electron ) {
removeChild( child );
i--;
}
}
}
}
public void particleAdded( Electron e ) {
ElectronNode node = new ElectronNode( e, circuitNode.getClipFactory() );
addChild( node );
}
} );
}
示例13: mapLocation
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
/**
* Maps the location (upper-left corner) of a PNode on a specified PCanvas to
* the coordinate system of the parent help pane.
*
* @param node
* @param canvas
* @return
*/
public Point2D mapLocation( PNode node, PCanvas canvas ) {
// Determine the node's location in canvas coordinates...
int x = 0;
int y = 0;
{
// Get the node's full bounds (union of its bounds and all children) in parent node's local coordinates
Rectangle2D fullBounds = node.getFullBounds();
// Get the node's global bounds - above the root node's transform, but below the canvas's view transform.
Rectangle2D globalFullBounds = node.getParent().localToGlobal( fullBounds );
//TODO: perhaps this code should transform this.globalToLocal(globalFullBounds) to identify the correct location.
// Apply the canvas' view transform to get bounds in the canvas' coordinate system.
PCamera camera = canvas.getCamera();
PAffineTransform transform = camera.getViewTransformReference();
Rectangle2D bounds = transform.transform( globalFullBounds, null );
x = (int) bounds.getX();
y = (int) bounds.getY();
}
// Convert the canvas location to a location in the help pane.
Point2D helpPanePoint = SwingUtilities.convertPoint( canvas, x, y, _helpPane );
return helpPanePoint;
}
示例14: removeLineNode
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
private static void removeLineNode( Line line, PNode parent ) {
for ( int i = 0; i < parent.getChildrenCount(); i++ ) {
PNode node = parent.getChild( i );
if ( node instanceof LineNode ) {
LineNode lineNode = (LineNode) node;
if ( lineNode.line == line ) {
parent.removeChild( node );
break;
}
}
}
}
示例15: toShape
import edu.umd.cs.piccolo.PNode; //导入依赖的package包/类
public PNode toShape( Rectangle2D screenRect ) {
PPath path = new PPath( screenRect );
path.setPaint( BARRIER_FILL );
path.setStroke( BARRIER_STROKE );
path.setStrokePaint( BARRIER_STROKE_PAINT );
path.addInputEventListener( horizontalDragHandler );
path.addInputEventListener( new CursorHandler() );
return path;
}