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


Java PBounds类代码示例

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


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

示例1: updateElectronPosition

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
private void updateElectronPosition() {
    
    ElectronNode electronNode = getElectronNode();
    PBounds electronBounds = electronNode.getFullBounds();
    Rectangle2D drawingArea = getDrawingArea();

    final double x = drawingArea.getX() + ( electronBounds.getWidth() / 2 ) + X_MARGIN;
    
    double y = Double.MAX_VALUE; // off the chart
    final double r = _atom.getElectronDistanceFromCenter();
    final double minEnergy = -1 / ( MIN_RADIUS * MIN_RADIUS );
    if ( r > 0 ) {
        final double energy = -1 / ( r * r );
        if ( energy >= minEnergy ) {
            double h = drawingArea.getHeight() - Y_MARGIN; // height of energy axis
            double d = h * energy / minEnergy; // how far down the energy axis is this energy value?
            y = drawingArea.getY() + Y_MARGIN + d;
        }
    }

    electronNode.setOffset( x, y );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:SolarSystemEnergyDiagram.java

示例2: updateLayout

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
private void updateLayout() {
    //Find the size (width or height) of the biggest child node so far
    final PNode biggestNode = max( getChildren(), new Comparator<PNode>() {
        public int compare( PNode o1, PNode o2 ) {
            return Double.compare( getMaxDimension.apply( o1.getFullBounds() ), getMaxDimension.apply( o2.getFullBounds() ) );
        }
    } );
    final double maxSize = getMaxDimension.apply( biggestNode.getFullBounds() );

    //Position each child, adding space between it and the previous child.
    double position = 0; //X or Y coordinate, depending on implementation of getNodeDimension
    for ( PNode child : getChildren() ) {
        final PBounds bounds = child.getFullBounds();

        //Subtract out any local translation in the node
        double childOriginX = bounds.getX() - child.getOffset().getX();
        double childOriginY = bounds.getY() - child.getOffset().getY();

        //Determine where to put the node and do so
        Point2D relativePosition = positionStrategy.getRelativePosition( child, maxSize, position );
        child.setOffset( relativePosition.getX() - childOriginX, relativePosition.getY() - childOriginY );

        //Move the position accumulator to the next space for the next node
        position += getNodeDimension.apply( bounds ) + spacing;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:Box.java

示例3: transformBoundsToStage

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
public Rectangle2D transformBoundsToStage( Rectangle2D localBounds ) {
        // TODO: verify this code!
        // get the translation of the control panel
        float offsetX = (float) position.get().getX();
        float offsetY = (float) position.get().getY();

        // convert these to stage-offset from the lower-left, since the control panel itself is translated
        double localLeft = localBounds.getMinX() + offsetX;
        double localRight = localBounds.getMaxX() + offsetX;
//        double localTop = getComponentHeight() - localBounds.getMinY() + offsetY; // remember, Y is flipped here
//        double localBottom = getComponentHeight() - localBounds.getMaxY() + offsetY; // remember, Y is flipped here
        double localTop = localBounds.getMaxY() + offsetY; // remember, Y is flipped here
        double localBottom = localBounds.getMinY() + offsetY; // remember, Y is flipped here

        return new PBounds( localLeft, localBottom, localRight - localLeft, localTop - localBottom );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:OrthoSwingNode.java

示例4: addRandomNode

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
private void addRandomNode() {

        // choose a random motion delta
        int delta = (int) Math.max( 1, Math.random() * motionDelta );

        // choose a random image
        int index = (int) ( Math.random() * imagePool.size() );
        MovingImageNode imageNode = new MovingImageNode( imagePool.get( index ), delta );
        addChild( imageNode );

        // set a random location within the bounds
        PBounds bounds = getBoundsReference();
        Point2D location = getRandomPoint( bounds );
        double x = location.getX() - ( imageNode.getFullBoundsReference().getWidth() / 2 );
        double y = location.getY() - ( imageNode.getFullBoundsReference().getHeight() / 2 );
        imageNode.setOffset( x, y );
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:RewardNode.java

示例5: LayoutBounds

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/**
 * Construct the necessary layout. If wide is true, the collectionAreaModelWidth is ignored
 */
public LayoutBounds() {
    double availableWidth = MODEL_SIZE.getWidth() - 2 * ChemicalReactionsConstants.MODEL_PADDING; // minus padding
    double halfWidth = availableWidth / 2;

    double kitTop = MODEL_SIZE.getHeight() / 2 - MODEL_PADDING; // Y is up, so this is the top (max y) value for the rectangle
    double kitHeight = 550;
    double kitBottom = kitTop - kitHeight;

    availableKitBounds = new PBounds( -halfWidth, kitBottom, availableWidth, kitHeight );

    availablePlayAreaBounds = new PBounds(
            -MODEL_SIZE.getWidth() / 2 + MODEL_PADDING + LEFT_EXTRA_PADDING, // far left part of model
            -MODEL_SIZE.getHeight() / 2 + MODEL_PADDING + BOTTOM_PADDING, // top of kit
            availableKitBounds.width - LEFT_EXTRA_PADDING - RIGHT_EXTRA_PADDING, // add in padding, since there is padding in-between the kit and collection area
            kitBottom + MODEL_SIZE.getHeight() / 2 - MODEL_PADDING * 2 - BOTTOM_PADDING );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:20,代码来源:LayoutBounds.java

示例6: ControlPanelNode

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
public ControlPanelNode( final PNode content, Color backgroundColor, BasicStroke borderStroke, Color borderColor, final int inset, final int arc, boolean transparifySwing ) {
    //Make sure the background resizes when the content resizes
    background = new PhetPPath( backgroundColor, borderStroke, borderColor ) {{
        final PropertyChangeListener updateSize = new PropertyChangeListener() {
            public void propertyChange( PropertyChangeEvent evt ) {
                final PBounds layoutSize = getControlPanelBounds( content );
                //Set the size of the border, subtracting out any local offset of the content node
                setPathTo( new RoundRectangle2D.Double( 0, 0, layoutSize.width + inset * 2, layoutSize.height + inset * 2, arc, arc ) );
            }
        };
        content.addPropertyChangeListener( PROPERTY_FULL_BOUNDS, updateSize );
        updateSize.propertyChange( null );
    }};
    // Create a node that puts the contents at the inset location
    // regardless of its initial offset.
    PNode insetContentNode = new ZeroOffsetNode( content ) {{
        setOffset( inset, inset );
    }};
    addChild( background );
    background.addChild( insetContentNode );
    if ( transparifySwing ) {
        transparifySwing( this );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:ControlPanelNode.java

示例7: handleReturnBeadButton

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/**
 * When the "Return Bead" button is clicked,
 * move the bead to the button's position and hide the button.
 */
private void handleReturnBeadButton() {

    // Determine the button's coordinates
    PBounds b = _returnBeadButtonWrapper.getFullBoundsReference();
    double x = b.getX() + ( b.getWidth() / 2 );
    double y = b.getY() + ( b.getHeight() / 2 );
    OTModelViewTransform modelViewTransform = _model.getModelViewTransform();
    Point2D p = modelViewTransform.viewToModel( x, y );

    // Move the bead to the button's position
    Bead bead = _model.getBead();
    bead.setMotionEnabled( false );
    bead.setPosition( p );
    bead.setMotionEnabled( true );

    // Hide the button
    _returnBeadButtonWrapper.setVisible( false );
    _returnBeadButtonWrapper.setPickable( false );
    _returnBeadButtonWrapper.setChildrenPickable( false );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:DNACanvas.java

示例8: Shaker

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
public Shaker( Vector2D location, double orientation, PBounds dragBounds, Property<Solute> solute, double maxDispensingRate ) {
    super( location, dragBounds );
    assert ( dragBounds.contains( location.toPoint2D() ) );

    this.orientation = orientation;
    this.solute = solute;
    this.visible = new Property<Boolean>( true );
    this.empty = new Property<Boolean>( false );
    this.maxDispensingRate = maxDispensingRate;
    this.dispensingRate = new Property<Double>( 0d );
    this.previousLocation = location;

    // set the dispensing rate to zero when the shaker becomes empty or invisible
    RichSimpleObserver rateObserver = new RichSimpleObserver() {
        public void update() {
            if ( empty.get() || !visible.get() ) {
                dispensingRate.set( 0d );
            }
        }
    };
    rateObserver.observe( empty, visible );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:Shaker.java

示例9: testCreateRectangleReturnsValidPPath

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
public void testCreateRectangleReturnsValidPPath() {
    final PPath path = PPath.createRectangle(0, 0, 100, 50);
    assertNotNull(path);

    // Seems like rounding is affecting the bounds greatly
    PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50), path.getBounds(), 2.0d);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:8,代码来源:PPathTest.java

示例10: repaint

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/**
 * Flags the bounds provided as needing to be redrawn.
 * 
 * @param bounds the bounds that should be repainted
 */
public void repaint(final PBounds bounds) {
    bounds.expandNearestIntegerDimensions();
    bounds.inset(-1, -1);

    redraw((int) bounds.x, (int) bounds.y, (int) bounds.width, (int) bounds.height, true);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:12,代码来源:PSWTCanvas.java

示例11: testAnimateViewToPanToBoundsIsImmediateWhenDurationIsZero

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
public void testAnimateViewToPanToBoundsIsImmediateWhenDurationIsZero() {
    camera.setViewBounds(new PBounds(0, 0, 10, 10));
    final PActivity activity = camera.animateViewToPanToBounds(new PBounds(10, 10, 10, 10), 0);

    assertNull(activity);
    assertEquals(AffineTransform.getTranslateInstance(-15, -15), camera.getViewTransform());
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:8,代码来源:PCameraTest.java

示例12: shouldRevalidateScrollPane

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/**
 * Should the ScrollPane be revalidated. This occurs when either the scroll
 * bars are showing and should be remove or are not showing and should be
 * added.
 * 
 * @return Whether the scroll pane should be revalidated
 */
public boolean shouldRevalidateScrollPane() {
    if (camera != null) {
        if (scrollPane.getHorizontalScrollBarPolicy() != ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
                && scrollPane.getVerticalScrollBarPolicy() != ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED) {
            return false;
        }

        // Get the union of all the layers' bounds
        final PBounds layerBounds = new PBounds();
        final List layers = camera.getLayersReference();
        for (final Iterator i = layers.iterator(); i.hasNext();) {
            final PLayer layer = (PLayer) i.next();
            layerBounds.add(layer.getFullBoundsReference());
        }

        // Put into camera coordinates
        camera.viewToLocal(layerBounds);

        // And union with the camera bounds
        final PBounds cameraBounds = camera.getBoundsReference();
        layerBounds.add(cameraBounds);

        // Truncate these to ints before comparing since
        // that's what the ScrollPane uses
        final int layerWidth = (int) (layerBounds.getWidth() + 0.5);
        final int layerHeight = (int) (layerBounds.getHeight() + 0.5);
        final int cameraWidth = (int) (cameraBounds.getWidth() + 0.5);
        final int cameraHeight = (int) (cameraBounds.getHeight() + 0.5);

        if (scrollPane.getHorizontalScrollBar().isShowing() && layerWidth <= cameraWidth
                || !scrollPane.getHorizontalScrollBar().isShowing() && layerWidth > cameraWidth
                || scrollPane.getVerticalScrollBar().isShowing() && layerHeight <= cameraHeight
                || !scrollPane.getVerticalScrollBar().isShowing() && layerHeight > cameraHeight) {
            return true;
        }
    }
    return false;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:46,代码来源:PDefaultScrollDirector.java

示例13: centerNode

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
protected void centerNode( PNode node ) {
    if ( node != null ) {
        Dimension2D worldSize = getWorldSize();
        PBounds b = node.getFullBoundsReference();
        double xOffset = ( worldSize.getWidth() - b.getWidth() - PNodeLayoutUtils.getOriginXOffset( node ) ) / 2;
        double yOffset = ( worldSize.getHeight() - b.getHeight() - PNodeLayoutUtils.getOriginYOffset( node ) ) / 2;
        node.setOffset( xOffset, yOffset );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:10,代码来源:BCECanvas.java

示例14: relocateHandle

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/**
 * Force this handle to relocate itself using its locator.
 */
public void relocateHandle() {
    if (locator == null) {
        return;
    }

    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);
    }

}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:PHandle.java

示例15: getMarqueeBounds

import edu.umd.cs.piccolo.util.PBounds; //导入依赖的package包/类
/** {@inheritDoc} */
protected PBounds getMarqueeBounds() {
    if (marquee != null) {
        return marquee.getBounds();
    }
    return new PBounds();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:8,代码来源:PSWTSelectionEventHandler.java


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