本文整理汇总了Java中edu.umd.cs.piccolo.util.PBounds.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PBounds.getWidth方法的具体用法?Java PBounds.getWidth怎么用?Java PBounds.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.piccolo.util.PBounds
的用法示例。
在下文中一共展示了PBounds.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fullPaint
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
/**
* Overrides the camera's full paint method to do the fast rendering when
* possible.
*
* @param paintContext Paint Contex in which the painting is done
*/
public void fullPaint(final PPaintContext paintContext) {
if (imageAnimate) {
final PBounds fRef = getFullBoundsReference();
final PBounds viewBounds = getViewBounds();
final double scale = getFullBoundsReference().getWidth() / imageAnimateBounds.getWidth();
final double xOffset = (viewBounds.getX() - imageAnimateBounds.getX()) * scale;
final double yOffset = (viewBounds.getY() - imageAnimateBounds.getY()) * scale;
final double scaleW = viewBounds.getWidth() * scale;
final double scaleH = viewBounds.getHeight() * scale;
paintContext.getGraphics().drawImage(paintBuffer, 0, 0, (int) Math.ceil(fRef.getWidth()),
(int) Math.ceil(fRef.getHeight()), (int) Math.floor(xOffset), (int) Math.floor(yOffset),
(int) Math.ceil(xOffset + scaleW), (int) Math.ceil(yOffset + scaleH), null);
}
else {
super.fullPaint(paintContext);
}
}
示例2: DisplayNode
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
public DisplayNode() {
super();
valueNode = new PText();
valueNode.setFont( DISPLAY_FONT );
setValue( new Double( 15 ) ); // initialize before layout
PComposite parentNode = new PComposite();
parentNode.addChild( valueNode );
valueNode.setOffset( 0, 0 );
PBounds pb = parentNode.getFullBoundsReference();
Shape backgroundShape = new RoundRectangle2D.Double( 0, 0, pb.getWidth() + 2 * DISPLAY_BORDER_MARGIN, pb.getHeight() + 2 * DISPLAY_BORDER_MARGIN, 10, 10 );
PPath backgroundNode = new PPath( backgroundShape );
addChild( backgroundNode );
backgroundNode.setPaint( DISPLAY_BACKGROUND );
backgroundNode.setStroke( new BasicStroke( (float) DISPLAY_BORDER_WIDTH ) );
backgroundNode.setStrokePaint( DISPLAY_BORDER_COLOR );
backgroundNode.addChild( parentNode );
parentNode.setOffset( DISPLAY_BORDER_MARGIN, DISPLAY_BORDER_MARGIN );
}
示例3: updateLayout
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
private void updateLayout() {
final double horizMargin = 15;
final double vertMargin = 15;
PBounds chartBounds = _chartWrapper.getFullBoundsReference();
PBounds closeButtonBounds = _closeButtonNode.getFullBoundsReference();
final double maxWidth = chartBounds.getWidth();
double maxHeight = closeButtonBounds.getHeight() + vertMargin;
double x = 0;
double y = 0;
// chart: close button sits on chart
x = 0;
y = 0;
_chartWrapper.setOffset( x, y );
// close button: right edge, vertically centered
x = maxWidth - horizMargin - closeButtonBounds.getWidth();
y = ( maxHeight - closeButtonBounds.getHeight() ) / 2;
_closeButtonNode.setOffset( x, y );
}
示例4: 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 );
}
示例5: getLayoutBounds
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
public PBounds getLayoutBounds() {
PBounds bounds = getFullBounds();
return new PBounds( bounds.getX() - paddingLeft,
bounds.getY() - paddingTop,
bounds.getWidth() + paddingLeft + paddingRight,
bounds.getHeight() + paddingTop + paddingBottom );
}
示例6: 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;
}
示例7: updateUI
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
private void updateUI() {
final double bandwidth = maxWavelength - minWavelength;
PBounds trackBounds = track.getFullBounds();
final double valueDisplayWidth = valueDisplay.getFullBounds().getWidth();
final double valueDisplayHeight = valueDisplay.getFullBounds().getHeight();
// Knob color
Color wavelengthColor = getWavelengthColor();
thumb.setPaint( wavelengthColor );
// Knob position: below the track with tip positioned at wavelength
final double trackX = trackBounds.getX();
final double trackWidth = trackBounds.getWidth();
final double thumbX = trackX + ( trackWidth * ( ( wavelength - minWavelength ) / bandwidth ) );
final double thumbY = trackBounds.getHeight();
thumb.setOffset( thumbX, thumbY );
// Value display: above the track, centered above the thumb
valueDisplay.setValue( wavelength );
final double valueX = thumbX - ( valueDisplayWidth / 2 );
final double valueY = -( valueDisplayHeight + VALUE_Y_OFFSET );
valueDisplay.setOffset( valueX, valueY );
// Cursor position: inside the track, centered above the thumb
cursor.setOffset( thumbX, 0 );
}
示例8: update
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
private void update() {
PBounds b = _foregroundNode.getFullBoundsReference();
double x = b.getMinX() - _insets.left;
double y = b.getMinY() - _insets.top;
double w = b.getWidth() + _insets.left + _insets.right;
double h = b.getHeight() + _insets.top + _insets.bottom;
_rectangle.setRect( x, y, w, h );
_pathNode.setPathTo( _rectangle );
}
示例9: print
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
/**
* Prints the node into the given Graphics context using the specified
* format. The zero based index of the requested page is specified by
* pageIndex. If the requested page does not exist then this method returns
* NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. If the printable object
* aborts the print job then it throws a PrinterException.
*
* @param graphics the context into which the node is drawn
* @param pageFormat the size and orientation of the page
* @param pageIndex the zero based index of the page to be drawn
*
* @return Either NO_SUCH_PAGE or PAGE_EXISTS
*/
public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex) {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
if (!(graphics instanceof Graphics2D)) {
throw new IllegalArgumentException("Provided graphics context is not a Graphics2D object");
}
final Graphics2D g2 = (Graphics2D) graphics;
final PBounds imageBounds = getFullBounds();
imageBounds.expandNearestIntegerDimensions();
g2.setClip(0, 0, (int) pageFormat.getWidth(), (int) pageFormat.getHeight());
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// scale the graphics so node's full bounds fit in the imageable bounds.
double scale = pageFormat.getImageableWidth() / imageBounds.getWidth();
if (pageFormat.getImageableHeight() / imageBounds.getHeight() < scale) {
scale = pageFormat.getImageableHeight() / imageBounds.getHeight();
}
g2.scale(scale, scale);
g2.translate(-imageBounds.x, -imageBounds.y);
final PPaintContext pc = new PPaintContext(g2);
pc.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
fullPaint(pc);
return PAGE_EXISTS;
}
示例10: 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() ) / 2 ) - PNodeLayoutUtils.getOriginXOffset( node );
double yOffset = ( ( worldSize.getHeight() - b.getHeight() ) / 2 ) - PNodeLayoutUtils.getOriginYOffset( node );
node.setOffset( xOffset, yOffset );
}
}
示例11: setScale
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
@Override
public void setScale( double scale ) {
PBounds boundsBefore = getFullBounds();
super.setScale( scale );
PBounds boundsAfter = getFullBounds();
double xOffset = getXOffset() - ( ( boundsAfter.getWidth() - boundsBefore.getWidth() ) / 2 );
double yOffset = getYOffset() + ( ( boundsAfter.getHeight() - boundsBefore.getHeight() ) / 2 );
setOffset( xOffset, yOffset );
}
示例12: updateCharges
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
protected void updateCharges() {
Bead bead = getBead();
final double electricFieldX = bead.getElectricFieldX();
final double scale = getChargeScale( electricFieldX );
// if the scale is zero, hide the charges so we don't attempt to apply a zero scale
_positiveNode.setVisible( scale > 0 );
_negativeNode.setVisible( scale > 0 );
// position and scale the charges
if ( scale > 0 ) {
double x, y;
PBounds positiveBounds = _positiveNode.getFullBoundsReference();
PBounds negativeBounds = _negativeNode.getFullBoundsReference();
// positive charge
_positiveNode.setScale( scale );
if ( electricFieldX > 0 ) {
x = _viewBeadRadius - positiveBounds.getWidth() - _viewMargin;
}
else {
x = -_viewBeadRadius + _viewMargin;
}
y = -positiveBounds.getHeight() / 2;
_positiveNode.setOffset( x, y );
// negative charge
_negativeNode.setScale( scale );
if ( electricFieldX > 0 ) {
x = -_viewBeadRadius + _viewMargin;
}
else {
x = _viewBeadRadius - negativeBounds.getWidth() - _viewMargin;
}
y = -negativeBounds.getHeight() / 2;
_negativeNode.setOffset( x, y );
}
}
示例13: setScale
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
/**
* Terms scale about their center.
*/
public void setScale( double scale ) {
PBounds boundsBefore = getFullBounds();
super.setScale( scale );
PBounds boundsAfter = getFullBounds();
double xOffset = getXOffset() - ( ( boundsAfter.getWidth() - boundsBefore.getWidth() ) / 2 );
double yOffset = getYOffset() - ( ( boundsAfter.getHeight() - boundsBefore.getHeight() ) / 2 );
setOffset( xOffset, yOffset );
}
示例14: getRandomPoint
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
private Point2D getRandomPoint( PBounds bounds ) {
double x = bounds.getX() + ( Math.random() * bounds.getWidth() );
double y = bounds.getY() + ( Math.random() * bounds.getHeight() );
return new Point2D.Double( x, y );
}
示例15: toImage
import edu.umd.cs.piccolo.util.PBounds; //导入方法依赖的package包/类
/**
* Paint a representation of this node into the specified buffered image. If
* background, paint is null, then the image will not be filled with a color
* prior to rendering
*
* @since 1.3
* @param image Image onto which this node will be painted
* @param backGroundPaint will fill background of image with this. May be
* null.
* @param fillStrategy strategy to use regarding how node will cover the
* image
* @return a rendering of this image and its descendants onto the specified
* image
*/
public Image toImage(final BufferedImage image, final Paint backGroundPaint, final int fillStrategy) {
final int imageWidth = image.getWidth();
final int imageHeight = image.getHeight();
final Graphics2D g2 = image.createGraphics();
if (backGroundPaint != null) {
g2.setPaint(backGroundPaint);
g2.fillRect(0, 0, imageWidth, imageHeight);
}
g2.setClip(0, 0, imageWidth, imageHeight);
final PBounds nodeBounds = getFullBounds();
nodeBounds.expandNearestIntegerDimensions();
final double nodeWidth = nodeBounds.getWidth();
final double nodeHeight = nodeBounds.getHeight();
double imageRatio = imageWidth / (imageHeight * 1.0);
double nodeRatio = nodeWidth / nodeHeight;
double scale;
switch (fillStrategy) {
case FILL_STRATEGY_ASPECT_FIT:
// scale the graphics so node's full bounds fit in the imageable
// bounds but aspect ration is retained
if (nodeRatio <= imageRatio) {
scale = image.getHeight() / nodeHeight;
}
else {
scale = image.getWidth() / nodeWidth;
}
g2.scale(scale, scale);
g2.translate(-nodeBounds.x, -nodeBounds.y);
break;
case FILL_STRATEGY_ASPECT_COVER:
// scale the graphics so node completely covers the imageable
// area, but retains its aspect ratio.
if (nodeRatio <= imageRatio) {
scale = image.getWidth() / nodeWidth;
}
else {
scale = image.getHeight() / nodeHeight;
}
g2.scale(scale, scale);
break;
case FILL_STRATEGY_EXACT_FIT:
// scale the node so that it covers then entire image,
// distorting it if necessary.
g2.scale(image.getWidth() / nodeWidth, image.getHeight() / nodeHeight);
g2.translate(-nodeBounds.x, -nodeBounds.y);
break;
default:
throw new IllegalArgumentException("Fill strategy provided is invalid");
}
final PPaintContext pc = new PPaintContext(g2);
pc.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
fullPaint(pc);
return image;
}