本文整理汇总了Java中org.piccolo2d.util.PBounds.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PBounds.getWidth方法的具体用法?Java PBounds.getWidth怎么用?Java PBounds.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.piccolo2d.util.PBounds
的用法示例。
在下文中一共展示了PBounds.getWidth方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fullPaint
import org.piccolo2d.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: fillViewWhiteSpace
import org.piccolo2d.util.PBounds; //导入方法依赖的package包/类
/**
* Instantaneously transforms the provided camera so that it does not
* contain any extra white space.
*
* @param camera the camera to be transformed
*/
protected void fillViewWhiteSpace(final PCamera camera) {
final PBounds rootBounds = camera.getRoot().getFullBoundsReference();
if (rootBounds.contains(camera.getViewBounds())) {
return;
}
camera.animateViewToPanToBounds(rootBounds, 0);
camera.animateViewToPanToBounds(focusNode.getGlobalFullBounds(), 0);
// center content.
double dx = 0;
double dy = 0;
PBounds viewBounds = camera.getViewBounds();
if (viewBounds.getWidth() > rootBounds.getWidth()) {
// then center along x axis.
dx = rootBounds.getCenterX() - viewBounds.getCenterX();
}
if (viewBounds.getHeight() > rootBounds.getHeight()) {
// then center along y axis.
dy = rootBounds.getCenterX() - viewBounds.getCenterX();
}
camera.translateView(dx, dy);
}
示例3: shouldRevalidateScrollPane
import org.piccolo2d.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;
}
示例4: print
import org.piccolo2d.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;
}
示例5: printAll
import org.piccolo2d.util.PBounds; //导入方法依赖的package包/类
/**
* Prints the entire scene regardless of what the viewable area is.
*
* @param graphics Graphics context onto which to paint the scene for printing
*/
public void printAll(final Graphics graphics) {
if (!(graphics instanceof Graphics2D)) {
throw new IllegalArgumentException("Provided graphics context is not a Graphics2D object");
}
final Graphics2D g2 = (Graphics2D) graphics;
final PBounds clippingRect = new PBounds(graphics.getClipBounds());
clippingRect.expandNearestIntegerDimensions();
final PBounds originalCameraBounds = getCamera().getBounds();
final PBounds layerBounds = getCamera().getUnionOfLayerFullBounds();
getCamera().setBounds(layerBounds);
final double clipRatio = clippingRect.getWidth() / clippingRect.getHeight();
final double nodeRatio = ((double) getWidth()) / ((double) getHeight());
final double scale;
if (nodeRatio <= clipRatio) {
scale = clippingRect.getHeight() / getCamera().getHeight();
}
else {
scale = clippingRect.getWidth() / getCamera().getWidth();
}
g2.scale(scale, scale);
g2.translate(-clippingRect.x, -clippingRect.y);
final PPaintContext pc = new PPaintContext(g2);
pc.setRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING);
getCamera().fullPaint(pc);
getCamera().setBounds(originalCameraBounds);
}
示例6: setViewPosition
import org.piccolo2d.util.PBounds; //导入方法依赖的package包/类
/**
* We do the same thing we did in getViewPosition above to flip the
* document-window position relationship
*
* @param x The new x position
* @param y The new y position
*/
public void setViewPosition(final double x, final double y) {
if (camera == null)
return;
// If a scroll is in progress - we ignore new scrolls - if we
// didn't, since the scrollbars depend on the camera location
// we can end up with an infinite loop
if (scrollInProgress)
return;
scrollInProgress = true;
// 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());
}
final PAffineTransform at = camera.getViewTransform();
at.transform(layerBounds, layerBounds);
// Union the camera view bounds
final PBounds viewBounds = camera.getBoundsReference();
layerBounds.add(viewBounds);
// Now find the new view position in view coordinates -
// This is basically the distance from the lower right
// corner of the window to the upper left corner of the
// document
// We then measure the offset from the lower right corner
// of the document
final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- (y + viewBounds.getHeight()));
// Now transform the new view position into global coords
camera.localToView(newPoint);
// Compute the new matrix values to put the camera at the
// correct location
final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
// Now actually set the camera's transform
camera.setViewTransform(at);
scrollInProgress = false;
}
示例7: setViewPosition
import org.piccolo2d.util.PBounds; //导入方法依赖的package包/类
/**
* We do the same thing we did in getViewPosition above to flip the
* document-window position relationship
*
* @param x The new x position
* @param y The new y position
*/
public void setViewPosition(final double x, final double y) {
if (camera == null)
return;
// If a scroll is in progress - we ignore new scrolls - if we
// didn't, since the scrollbars depend on the camera
// location we can end up with an infinite loop
if (scrollInProgress)
return;
scrollInProgress = true;
// Get the union of all the layers' bounds
final PBounds layerBounds = new PBounds();
final java.util.List layers = camera.getLayersReference();
for (final Iterator i = layers.iterator(); i.hasNext();) {
final PLayer layer = (PLayer) i.next();
layerBounds.add(layer.getFullBoundsReference());
}
final PAffineTransform at = camera.getViewTransform();
at.transform(layerBounds, layerBounds);
// Union the camera view bounds
final PBounds viewBounds = camera.getBoundsReference();
layerBounds.add(viewBounds);
// Now find the new view position in view coordinates -
// This is basically the distance from the lower right
// corner of the window to the upper left corner of the
// document. We then measure the offset from the lower right corner
// of the document
final Point2D newPoint = new Point2D.Double(layerBounds.getX() + layerBounds.getWidth()
- (x + viewBounds.getWidth()), layerBounds.getY() + layerBounds.getHeight()
- (y + viewBounds.getHeight()));
// Now transform the new view position into global coords
camera.localToView(newPoint);
// Compute the new matrix values to put the camera at the
// correct location
final double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY());
final double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY());
at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY);
// Now actually set the camera's transform
camera.setViewTransform(at);
scrollInProgress = false;
}
示例8: isBufferSmallerThanBounds
import org.piccolo2d.util.PBounds; //导入方法依赖的package包/类
private boolean isBufferSmallerThanBounds(final PBounds bounds) {
return paintBuffer.getWidth() < bounds.getWidth() || paintBuffer.getHeight() < bounds.getHeight();
}
示例9: toImage
import org.piccolo2d.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;
}