use of java.awt.geom.Dimension2D in project jdk8u_jdk by JetBrains.
the class CImage method toImage.
/** @return A MultiResolution image created from nsImagePtr, or null. */
private Image toImage() {
if (ptr == 0)
return null;
Dimension2D size = nativeGetNSImageSize(ptr);
final int baseWidth = (int) size.getWidth();
final int baseHeight = (int) size.getHeight();
Dimension2D[] sizes = nativeGetNSImageRepresentationSizes(ptr, size.getWidth(), size.getHeight());
// Check if a single represenation has a bigger size and in that case use it as the dest size.
if (sizes != null && sizes.length == 1 && (sizes[0].getWidth() > baseWidth && sizes[0].getHeight() > baseHeight)) {
size = sizes[0];
}
final int dstWidth = (int) size.getWidth();
final int dstHeight = (int) size.getHeight();
return sizes == null || sizes.length < 2 ? new MultiResolutionCachedImage(baseWidth, baseHeight, (width, height) -> toImage(dstWidth, dstHeight)) : new MultiResolutionCachedImage(baseWidth, baseHeight, sizes, (width, height) -> toImage(width, height));
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class MindMapPanel method calculateSizeOfMapInPixels.
@Nullable
public static Dimension2D calculateSizeOfMapInPixels(@Nonnull final MindMap model, @Nullable final Graphics2D graphicsContext, @Nonnull final MindMapPanelConfig cfg, final boolean expandAll, @Nonnull final RenderQuality quality) {
final MindMap workMap = new MindMap(model, null);
workMap.resetPayload();
Graphics2D g = graphicsContext;
if (g == null) {
BufferedImage img = new BufferedImage(32, 32, cfg.isDrawBackground() ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB);
g = img.createGraphics();
}
final MMGraphics gfx = new MMGraphics2DWrapper(g);
quality.prepare(g);
Dimension2D blockSize = null;
try {
if (calculateElementSizes(gfx, workMap, cfg)) {
if (expandAll) {
final AbstractElement root = assertNotNull((AbstractElement) assertNotNull(workMap.getRoot()).getPayload());
root.collapseOrExpandAllChildren(false);
calculateElementSizes(gfx, workMap, cfg);
}
blockSize = assertNotNull(layoutModelElements(workMap, cfg));
final double paperMargin = cfg.getPaperMargins() * cfg.getScale();
blockSize.setSize(blockSize.getWidth() + paperMargin * 2, blockSize.getHeight() + paperMargin * 2);
}
} finally {
gfx.dispose();
}
return blockSize;
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class AbstractCollapsableElement method alignElementAndChildren.
@Override
public void alignElementAndChildren(@Nonnull final MindMapPanelConfig cfg, final boolean leftSide, final double leftX, final double topY) {
super.alignElementAndChildren(cfg, leftSide, leftX, topY);
final double horzInset = cfg.getOtherLevelHorizontalInset() * cfg.getScale();
double childrenX;
final double COLLAPSATORSIZE = cfg.getCollapsatorSize() * cfg.getScale();
final double COLLAPSATORDISTANCE = cfg.getCollapsatorSize() * 0.1d * cfg.getScale();
final double collapsatorX;
if (leftSide) {
childrenX = leftX + this.blockSize.getWidth() - this.bounds.getWidth();
this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
childrenX -= horzInset;
collapsatorX = -COLLAPSATORSIZE - COLLAPSATORDISTANCE;
} else {
childrenX = leftX;
this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
childrenX += this.bounds.getWidth() + horzInset;
collapsatorX = this.bounds.getWidth() + COLLAPSATORDISTANCE;
}
this.collapsatorZone.setRect(collapsatorX, (this.bounds.getHeight() - COLLAPSATORSIZE) / 2, COLLAPSATORSIZE, COLLAPSATORSIZE);
if (!this.isCollapsed()) {
final double vertInset = cfg.getOtherLevelVerticalInset() * cfg.getScale();
final Dimension2D childBlockSize = calcBlockSize(cfg, null, true);
double currentY = topY + (this.blockSize.getHeight() - childBlockSize.getHeight()) / 2.0d;
boolean notFirstChild = false;
for (final Topic t : this.model.getChildren()) {
if (notFirstChild) {
currentY += vertInset;
} else {
notFirstChild = true;
}
final AbstractElement w = (AbstractElement) assertNotNull(t.getPayload());
w.alignElementAndChildren(cfg, leftSide, leftSide ? childrenX - w.getBlockSize().getWidth() : childrenX, currentY);
currentY += w.getBlockSize().getHeight();
}
}
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class AbstractCollapsableElement method calcBlockSize.
@Override
@Nonnull
public Dimension2D calcBlockSize(@Nonnull final MindMapPanelConfig cfg, @Nullable final Dimension2D size, final boolean childrenOnly) {
final Dimension2D result = size == null ? new Dimension() : size;
final double scaledVInset = cfg.getScale() * cfg.getOtherLevelVerticalInset();
final double scaledHInset = cfg.getScale() * cfg.getOtherLevelHorizontalInset();
double width = childrenOnly ? 0.0d : this.bounds.getWidth();
double height = childrenOnly ? 0.0d : this.bounds.getHeight();
if (this.hasChildren()) {
if (!this.isCollapsed()) {
width += childrenOnly ? 0.0d : scaledHInset;
final double baseWidth = childrenOnly ? 0.0d : width;
double childrenHeight = 0.0d;
boolean notFirstChiild = false;
for (final Topic t : this.model.getChildren()) {
if (notFirstChiild) {
childrenHeight += scaledVInset;
} else {
notFirstChiild = true;
}
((AbstractElement) assertNotNull(t.getPayload())).calcBlockSize(cfg, result, false);
width = Math.max(baseWidth + result.getWidth(), width);
childrenHeight += result.getHeight();
}
height = Math.max(height, childrenHeight);
} else if (!childrenOnly) {
width += cfg.getCollapsatorSize() * cfg.getScale();
}
}
result.setSize(width, height);
return result;
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class MindMapPanel method layoutFullDiagramWithCenteringToPaper.
@Nullable
public static Dimension layoutFullDiagramWithCenteringToPaper(@Nonnull final MMGraphics gfx, @Nonnull final MindMap map, @Nonnull final MindMapPanelConfig cfg, @Nonnull final Dimension2D paperSize) {
Dimension resultSize = null;
if (calculateElementSizes(gfx, map, cfg)) {
Dimension2D rootBlockSize = layoutModelElements(map, cfg);
final double paperMargin = cfg.getPaperMargins() * cfg.getScale();
if (rootBlockSize != null) {
final ElementRoot rootElement = assertNotNull((ElementRoot) assertNotNull(map.getRoot()).getPayload());
double rootOffsetXInBlock = rootElement.getLeftBlockSize().getWidth();
double rootOffsetYInBlock = (rootBlockSize.getHeight() - rootElement.getBounds().getHeight()) / 2;
rootOffsetXInBlock += (paperSize.getWidth() - rootBlockSize.getWidth()) <= paperMargin ? paperMargin : (paperSize.getWidth() - rootBlockSize.getWidth()) / 2;
rootOffsetYInBlock += (paperSize.getHeight() - rootBlockSize.getHeight()) <= paperMargin ? paperMargin : (paperSize.getHeight() - rootBlockSize.getHeight()) / 2;
moveDiagram(map, rootOffsetXInBlock, rootOffsetYInBlock);
resultSize = new Dimension((int) Math.round(rootBlockSize.getWidth() + paperMargin * 2), (int) Math.round(rootBlockSize.getHeight() + paperMargin * 2));
}
}
return resultSize;
}
Aggregations