本文整理汇总了Java中edu.umd.cs.piccolo.PNode.setOffset方法的典型用法代码示例。如果您正苦于以下问题:Java PNode.setOffset方法的具体用法?Java PNode.setOffset怎么用?Java PNode.setOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.piccolo.PNode
的用法示例。
在下文中一共展示了PNode.setOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCoilGraphics
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Creates the graphics for the coils
*
* @param bounds
*/
private void createCoilGraphics( Rectangle2D bounds ) {
double baseDim = magnet.getOrientation() == GradientElectromagnet.HORIZONTAL ? bounds.getWidth() : bounds.getHeight();
double coilWidth = baseDim / numSegments;
for( int i = 0; i < coilsGraphics.length; i++ ) {
PNode coilGraphic = null;
double xLoc = i * coilWidth;
if( magnet.getOrientation() == GradientElectromagnet.HORIZONTAL ) {
coilGraphic = PImageFactory.create( MriResources.getImage( MriConfig.COIL_IMAGE ), new Dimension( (int)coilWidth, (int)bounds.getHeight() ) );
coilGraphic.setOffset( xLoc, 0 );
}
else {
coilGraphic = PImageFactory.create( MriResources.getImage( MriConfig.COIL_IMAGE ), new Dimension( (int)coilWidth, (int)bounds.getWidth() ) );
coilGraphic.rotate( Math.PI / 2 );
coilGraphic.translate( xLoc, -bounds.getWidth() );
}
addChild( coilGraphic );
coilsGraphics[i] = coilGraphic;
}
}
示例2: ControlChart
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public ControlChart( PNode controlPanel, PNode sliderNode, TemporalChart chartNode, ChartZoomControlNode zoomButtonNode ) {
this.controlPanel = controlPanel;
this.sliderNode = sliderNode;
this.chartNode = chartNode;
this.zoomButtonNode = zoomButtonNode;
addChild( controlPanel );
addChild( sliderNode );
addChild( chartNode );
addChild( zoomButtonNode );
controlPanel.setOffset( 0, 0 );
sliderNode.setOffset( controlPanel.getFullBounds().getMaxX(), 0 );
chartNode.setOffset( sliderNode.getFullBounds().getMaxX(), 0 );
zoomButtonNode.setOffset( chartNode.getFullBounds().getMaxX(), 0 );
}
示例3: createStateNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private static PNode createStateNode( int state ) {
PNode lineNode = createStateLineNode();
PNode labelNode = createStateLabelNode( state );
PComposite parentNode = new PComposite();
parentNode.addChild( lineNode );
parentNode.addChild( labelNode );
// vertically align centers of label and line
lineNode.setOffset( 0, 0 );
double x = lineNode.getWidth() + LINE_LABEL_SPACING;
double y = -( ( lineNode.getHeight() / 2 ) + ( labelNode.getHeight() / 2 ) );
if ( state == 6 ) {
// HACK requested by Sam McKagan: for n=6, move label up a bit to prevent overlap with n=5
labelNode.setOffset( x, y - 3.5 );
}
else {
labelNode.setOffset( x, y );
}
return parentNode;
}
示例4: LightBulbNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public LightBulbNode() {
PNode baseNode = new PImage( LIGHT_BULB_BASE );
glassNode = new PImage( LIGHT_BULB_GLASS );
maskNode = new PImage( LIGHT_BULB_GLASS_MASK );
// rendering order
addChild( maskNode );
addChild( glassNode );
addChild( baseNode );
// layout
double x = -baseNode.getFullBoundsReference().getWidth() / 2;
double y = -baseNode.getFullBoundsReference().getHeight();
baseNode.setOffset( x, y );
x = baseNode.getFullBoundsReference().getCenterX() - ( glassNode.getFullBoundsReference().getWidth() / 2 );
y = baseNode.getFullBoundsReference().getMinY() - glassNode.getFullBoundsReference().getHeight();
glassNode.setOffset( x, y );
maskNode.setOffset( glassNode.getOffset() );
}
示例5: updateLayout
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void updateLayout() {
iconChildNode.removeAllChildren();
for ( int i = 0; i < getter.get(); i++ ) {
PNode newicon = nodeFactory.createNode();
newicon.setPickable( false );
newicon.setChildrenPickable( false );
newicon.scale( 1.3 );//Make it look a bit bigger
iconChildNode.addChild( newicon );
//put next to the previous one
newicon.setOffset( ( MAX_PARTICLE_WIDTH + HORIZONTAL_SPACING ) * i, 0 );
}
iconChildNode.setOffset( iconX, textNode.getFullBounds().getCenterY() );
}
示例6: createAtomPile
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private static PNode createAtomPile( int numberOfAtoms, Element element ) {
PComposite parent = new PComposite();
int atomsInRow = ATOMS_IN_PILE_BASE;
int row = 0;
int pile = 0;
double x = 0;
double y = 0;
for ( int i = 0; i < numberOfAtoms; i++ ) {
PNode atomNode = new AtomNode( element );
parent.addChild( atomNode );
atomNode.setOffset( x + ( atomNode.getFullBoundsReference().getWidth() / 2 ), y - ( atomNode.getFullBoundsReference().getHeight() / 2 ) );
atomsInRow--;
if ( atomsInRow > 0 ) {
// continue with current row
x = atomNode.getFullBoundsReference().getMaxX();
}
else if ( row < ATOMS_IN_PILE_BASE - 1 ) {
// move to next row in current triangular pile
row++;
atomsInRow = ATOMS_IN_PILE_BASE - row;
x = (double) ( pile + row ) * ( atomNode.getFullBoundsReference().getWidth() / 2 );
y = -( row * 0.85 * atomNode.getFullBoundsReference().getHeight() );
}
else {
// start a new pile, offset from the previous pile
row = 0;
pile++;
atomsInRow = ATOMS_IN_PILE_BASE;
x = (double) pile * ( atomNode.getFullBoundsReference().getWidth() / 2 );
y = 0;
}
}
return parent;
}
示例7: addPreExistingItems
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void addPreExistingItems() {
for ( int i = 0; i < calorieSet.getItemCount(); i++ ) {
final PNode node = calorieDragStrip.addItemNode( calorieSet.getItem( i ) );
dropTarget.addPropertyChangeListener( PNode.PROPERTY_FULL_BOUNDS, new PropertyChangeListener() {
public void propertyChange( PropertyChangeEvent evt ) {
node.setOffset( dropTarget.getFullBounds().getCenterX() - node.getFullBounds().getWidth() / 2 + node.getFullBounds().getWidth(),
dropTarget.getFullBounds().getY() - node.getFullBounds().getHeight() * 1.1 );
}
} );
node.setOffset( dropTarget.getFullBounds().getCenterX() - node.getFullBounds().getWidth() / 2 + node.getFullBounds().getWidth(),
dropTarget.getFullBounds().getY() - node.getFullBounds().getHeight() * 1.1 );
}
}
示例8: SquaresLayer
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public SquaresLayer() {
super();
for ( int i = 0; i < NUMBER_OF_SQUARES; i++ ) {
PNode node = new SquareNode();
addChild( node );
node.setOffset( getRandomPosition() );
}
}
示例9: PlayAreaNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public PlayAreaNode() {
final PhetPPath area = new PhetPPath( new Rectangle2D.Double( STAGE_SIZE.width / 2, 0, STAGE_SIZE.width / 2, STAGE_SIZE.height / 2 ), Color.white, new BasicStroke( 1 ), Color.black );
addChild( area );
PNode faceNode = Scenes.createFaceNode();
faceNode.setOffset( area.getFullBounds().getCenterX() - faceNode.getFullBounds().getWidth() / 2, area.getFullBounds().getCenterY() - faceNode.getFullBounds().getHeight() / 2 );
addChild( faceNode );
}
示例10: addBandDivider
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Add a "band divider" at the given frequency. A band divider is
* a dotted line that spans the spectrum strip in the vertical
* direction.
*/
private void addBandDivider( double frequency ) {
DoubleGeneralPath path = new DoubleGeneralPath();
path.moveTo( 0, 0 );
path.lineTo( 0, STRIP_HEIGHT );
PNode bandDividerNode = new PhetPPath( path.getGeneralPath(), BAND_DIVIDER_STROKE, Color.BLACK );
bandDividerNode.setOffset( getOffsetFromFrequency( frequency ), 0 );
spectrumRootNode.addChild( bandDividerNode );
}
示例11: positionNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void positionNode(final PNode node, final double x, final double y, final double w, final double h) {
node.setOffset(centerX(node, x, w), north(node, y, h));
}
示例12: nodeDemo
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void nodeDemo() {
final PLayer layer = getCanvas().getLayer();
final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
// A node needs to be a descendent of the root to be displayed on the
// screen.
layer.addChild(aNode);
// The default color for a node is blue, but you can change that with
// the setPaint method.
aNode.setPaint(Color.red);
// A node can have children nodes added to it.
aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
// The base bounds of a node is easy to change. Note that changing the
// base bounds of a node will not change it's children.
aNode.setBounds(-10, -10, 200, 110);
// Each node has a transform that can be used to transform the node, and
// all its children on the screen.
aNode.translate(100, 100);
aNode.scale(1.5);
aNode.rotate(45);
// The transparency of any node can be set, this transparency will be
// applied to any of the nodes children as well.
aNode.setTransparency(0.75f);
// Its easy to copy nodes.
final PNode aCopy = (PNode) aNode.clone();
// Make is so that the copies children are not pickable. For this
// example that means you will not be able to grab the child and remove
// it from its parent.
aNode.setChildrenPickable(false);
// Change the look of the copy
aNode.setPaint(Color.GREEN);
aNode.setTransparency(1.0f);
// Let's add the copy to the root, and translate it so that it does not
// cover the original node.
layer.addChild(aCopy);
aCopy.setOffset(0, 0);
aCopy.rotate(-45);
}
示例13: ChannelControlButtonIcon
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
ChannelControlButtonIcon( MembraneChannelTypes channelType, boolean open ) {
// Create the various pieces that make up the icon.
String channelImageName;
final PNode particleNode;
String directionText;
ModelViewTransform mvt = ModelViewTransform.createSinglePointScaleMapping( new Point2D.Double( 0, 0 ), new Point2D.Double( 0, 0 ), 7 );
if ( channelType == MembraneChannelTypes.POTASSIUM_GATED_CHANNEL ) {
particleNode = new ParticleNode( new PotassiumIon(), mvt );
if ( open ) {
channelImageName = "blue_gate_close_icon.png";
directionText = MembraneChannelsStrings.CLOSE;
}
else {
channelImageName = "blue_gate_open_icon.png";
directionText = MembraneChannelsStrings.OPEN;
}
}
else {
// Assume sodium.
particleNode = new ParticleNode( new SodiumIon(), mvt );
if ( open ) {
channelImageName = "green_gate_close_icon.png";
directionText = MembraneChannelsStrings.CLOSE;
}
else {
channelImageName = "green_gate_open_icon.png";
directionText = MembraneChannelsStrings.OPEN;
}
}
final PNode channelImageNode = new PImage( MembraneChannelsResources.getImage( channelImageName ) );
final PNode directionTextNode = new PText( directionText ) {{
setFont( new PhetFont( 12 ) );
}};
final PNode channelTextNode = new PText( MembraneChannelsStrings.CHANNELS ) {{
setFont( new PhetFont( 12 ) );
}};
PNode container = new PNode() {{
// Put all the pieces together in one place. There are some
// "tweak factors" in here, adjust as needed for optimal look.
addChild( channelImageNode );
directionTextNode.setOffset(
channelImageNode.getFullBoundsReference().getMaxX() + 4,
channelImageNode.getFullBoundsReference().getCenterY() - directionTextNode.getFullBoundsReference().height / 2 );
addChild( directionTextNode );
particleNode.setOffset(
directionTextNode.getFullBoundsReference().getMaxX() + 10,
channelImageNode.getFullBoundsReference().getCenterY() );
addChild( particleNode );
channelTextNode.setOffset(
particleNode.getFullBoundsReference().getMaxX() + 4,
channelImageNode.getFullBoundsReference().getCenterY() - channelTextNode.getFullBoundsReference().height / 2 );
addChild( channelTextNode );
}};
setImage( container.toImage() );
}
示例14: ViewOptionsPanel
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public ViewOptionsPanel( final Property<Boolean> showLabels,
final boolean containsWaterOption,
final Property<Boolean> showWater,
final Property<Boolean> showWaterEnabled,
final Property<ColorMode> colorMode ) {
final PNode title = new PText( PlateTectonicsResources.Strings.OPTIONS ) {{
setFont( PANEL_TITLE_FONT );
}};
addChild( title );
final Property<Double> maxWidth = new Property<Double>( title.getFullBounds().getWidth() );
final Property<Double> y = new Property<Double>( title.getFullBounds().getMaxY() );
// "Density" radio button
final PSwing densityMode = new PSwing( new GLSimSharingPropertyRadioButton<ColorMode>( UserComponents.densityView, Strings.DENSITY_VIEW, colorMode, ColorMode.DENSITY ) ) {{
setOffset( 0, y.get() + 5 );
y.set( getFullBounds().getMaxY() );
maxWidth.set( Math.max( maxWidth.get(), getFullBounds().getWidth() ) );
}};
addChild( densityMode );
// "Temperature" radio button
final PSwing temperatureMode = new PSwing( new GLSimSharingPropertyRadioButton<ColorMode>( UserComponents.temperatureView, Strings.TEMPERATURE_VIEW, colorMode, ColorMode.TEMPERATURE ) ) {{
setOffset( 0, y.get() );
y.set( getFullBounds().getMaxY() );
maxWidth.set( Math.max( maxWidth.get(), getFullBounds().getWidth() ) );
}};
addChild( temperatureMode );
// "Both" radio button
final PSwing combinedMode = new PSwing( new GLSimSharingPropertyRadioButton<ColorMode>( UserComponents.bothView, Strings.BOTH_VIEW, colorMode, ColorMode.COMBINED ) ) {{
setOffset( 0, y.get() );
y.set( getFullBounds().getMaxY() );
maxWidth.set( Math.max( maxWidth.get(), getFullBounds().getWidth() ) );
}};
addChild( combinedMode );
y.set( y.get() + 5 );
// "Show Labels" check box
final PSwing showLabelCheckBox = new PSwing( new GLSimSharingPropertyCheckBox( UserComponents.showLabels, Strings.SHOW_LABELS, showLabels ) ) {{
setOffset( 0, y.get() );
y.set( getFullBounds().getMaxY() );
maxWidth.set( Math.max( maxWidth.get(), getFullBounds().getWidth() ) );
}};
addChild( showLabelCheckBox );
// "Show Seawater" check box
if ( containsWaterOption ) {
addChild( new PSwing( new GLSimSharingPropertyCheckBox( UserComponents.showWater, Strings.SHOW_SEAWATER, showWater ) {{
showWaterEnabled.addObserver( new SimpleObserver() {
public void update() {
// access property in the LWJGL thread
final Boolean enabled = showWaterEnabled.get();
// and set the swing property in the Swing EDT
SwingUtilities.invokeLater( new Runnable() {
public void run() {
setEnabled( enabled );
}
} );
}
} );
}} ) {{
setOffset( 0, y.get() );
y.set( getFullBounds().getMaxY() );
maxWidth.set( Math.max( maxWidth.get(), getFullBounds().getWidth() ) );
}} );
}
// this prevents panel resizing when the button bounds change (like when they are pressed)
addChild( new Spacer( 0, y.get(), 1, 1 ) );
// horizontally center title
title.setOffset( ( maxWidth.get() - title.getFullBounds().getWidth() ) / 2, title.getYOffset() );
}
示例15: main
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public static void main( String[] args ) {
final int WIDTH = 640;
JFrame frame = new JFrame( "Test" );
PCanvas contentPane = new PCanvas();
contentPane.setPreferredSize( new Dimension( WIDTH, 480 ) );
final PNode rootNode = new PNode();
contentPane.getLayer().addChild( rootNode );
PhetPPath blueBox = new PhetPPath( new Rectangle( -25, 0, 50, 50 ), Color.blue );
rootNode.addChild( blueBox );
JPanel panel = new JPanel( new GridBagLayout() );
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
panel.add( contentPane, c );
final JScrollBar horizBar = new JScrollBar( JScrollBar.HORIZONTAL );
c.gridy = 1;
c.fill = GridBagConstraints.BOTH;
panel.add( horizBar, c );
frame.setContentPane( panel );
//frame.setSize( 400, 500 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.pack();
frame.setVisible( true );
System.out.println( "rootNode bounds: " + rootNode.computeFullBounds( null ) );
System.out.println( "rootNode bounds: " + rootNode.computeFullBounds( null ) );
rootNode.setOffset( WIDTH / 2, 0 );
horizBar.setMaximum( 1000 );
horizBar.setMinimum( -1000 );
horizBar.setValue( 0 );
horizBar.addAdjustmentListener( new AdjustmentListener() {
public void adjustmentValueChanged( AdjustmentEvent adjustmentEvent ) {
rootNode.setOffset( WIDTH / 2 + horizBar.getValue(), 0 );
}
} );
}