List of usage examples for java.awt Rectangle getSize
public Dimension getSize()
From source file:edu.stanford.epadd.launcher.Splash.java
public Splash() { final SplashScreen splash = (System.getProperty("nobrowseropen") == null) ? SplashScreen.getSplashScreen() : null;/*w w w . j a v a 2 s. co m*/ if (splash == null) { System.out.println("SplashScreen.getSplashScreen() returned null"); return; } Rectangle r = splash.getBounds(); g = splash.createGraphics(); if (g == null) { System.out.println("splash.createGraphics() returned null"); return; } /* code to prevent text from appearing too pixelated - https://stackoverflow.com/questions/31536952/how-to-fix-text-quality-in-java-graphics */ Map<?, ?> desktopHints = (Map<?, ?>) Toolkit.getDefaultToolkit() .getDesktopProperty("awt.font.desktophints"); if (desktopHints != null) { g.setRenderingHints(desktopHints); } System.out.println("splash url = " + splash.getImageURL() + " w=" + r.getWidth() + " h=" + r.getHeight() + " size=" + r.getSize() + " loc=" + r.getLocation()); // setVisible(true); // toFront(); }
From source file:org.apache.fop.render.afp.AFPImageHandlerRenderedImage.java
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { AFPRenderingContext afpContext = (AFPRenderingContext) context; AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo) createDataObjectInfo(); AFPPaintingState paintingState = afpContext.getPaintingState(); // set resource information setResourceInformation(imageObjectInfo, image.getInfo().getOriginalURI(), afpContext.getForeignAttributes()); setDefaultResourceLevel(imageObjectInfo, afpContext.getResourceManager()); // Positioning imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(paintingState, pos)); Dimension targetSize = pos.getSize(); // Image content ImageRendered imageRend = (ImageRendered) image; RenderedImageEncoder encoder = new RenderedImageEncoder(imageRend, targetSize); encoder.prepareEncoding(imageObjectInfo, paintingState); boolean included = afpContext.getResourceManager().tryIncludeObject(imageObjectInfo); if (!included) { long start = System.currentTimeMillis(); //encode only if the same image has not been encoded, yet encoder.encodeImage(imageObjectInfo, paintingState); if (log.isDebugEnabled()) { long duration = System.currentTimeMillis() - start; log.debug("Image encoding took " + duration + "ms."); }/* w ww . ja v a 2 s . c om*/ // Create image afpContext.getResourceManager().createObject(imageObjectInfo); } }
From source file:org.apache.fop.render.pcl.PCLDocumentHandler.java
/** {@inheritDoc} */ public void endPageContent() throws IFException { if (this.currentImage != null) { try {/*from w w w. ja v a 2 s . c o m*/ //ImageWriterUtil.saveAsPNG(this.currentImage, new java.io.File("D:/page.png")); Rectangle printArea = this.currentPageDefinition.getLogicalPageRect(); gen.setCursorPos(0, 0); gen.paintBitmap(this.currentImage, printArea.getSize(), true); } catch (IOException ioe) { throw new IFException("I/O error while encoding page image", ioe); } finally { this.currentImage = null; } } }
From source file:org.apache.fop.render.pcl.PCLPainter.java
/** {@inheritDoc} */ public void drawBorderRect(final Rectangle rect, final BorderProps before, final BorderProps after, final BorderProps start, final BorderProps end) throws IFException { if (isSpeedOptimized()) { super.drawBorderRect(rect, before, after, start, end); return;// ww w . j a v a2 s .c o m } if (before != null || after != null || start != null || end != null) { final Rectangle boundingBox = rect; final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(-rect.x, -rect.y); Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawBorderRect(rect, before, after, start, end); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting borders", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); } }
From source file:org.apache.fop.render.pcl.PCLPainter.java
/** {@inheritDoc} */ public void drawLine(final Point start, final Point end, final int width, final Color color, final RuleStyle style) throws IFException { if (isSpeedOptimized()) { super.drawLine(start, end, width, color, style); return;//from w w w .j a va 2 s .c o m } final Rectangle boundingBox = getLineBoundingBox(start, end, width); final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(-boundingBox.x, -boundingBox.y); Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawLine(start, end, width, color, style); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting a line", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); }
From source file:org.apache.fop.render.pcl.PCLPainter.java
private void drawTextAsBitmap(final int x, final int y, final int letterSpacing, final int wordSpacing, final int[] dx, final String text, FontTriplet triplet) throws IFException { //Use Java2D to paint different fonts via bitmap final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize()); //for cursive fonts, so the text isn't clipped final FontMetricsMapper mapper = (FontMetricsMapper) parent.getFontInfo().getMetricsFor(font.getFontName()); final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000; final int ascent = mapper.getAscender(font.getFontSize()) / 1000; final int descent = mapper.getDescender(font.getFontSize()) / 1000; int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize()); final int baselineOffset = maxAscent + safetyMargin; final Rectangle boundingBox = getTextBoundingBox(x, y, letterSpacing, wordSpacing, dx, text, font, mapper); final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { if (DEBUG) { g2d.setBackground(Color.LIGHT_GRAY); g2d.clearRect(0, 0, (int) area.getWidth(), (int) area.getHeight()); }/*ww w.jav a 2 s . c o m*/ g2d.translate(-x, -y + baselineOffset); if (DEBUG) { Rectangle rect = new Rectangle(x, y - maxAscent, 3000, maxAscent); g2d.draw(rect); rect = new Rectangle(x, y - ascent, 2000, ascent); g2d.draw(rect); rect = new Rectangle(x, y, 1000, -descent); g2d.draw(rect); } Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawText(x, y, letterSpacing, wordSpacing, dx, text); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting text", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * {@inheritDoc}/* ww w . j a va 2s. co m*/ */ protected void renderText(final TextArea text) { renderInlineAreaBackAndBorders(text); String fontname = getInternalFontNameForArea(text); final int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE); //Determine position int saveIP = currentIPPosition; final int rx = currentIPPosition + text.getBorderAndPaddingWidthStart(); int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset(); try { final Color col = (Color) text.getTrait(Trait.COLOR); boolean pclFont = pclUtil.isAllTextAsBitmaps() ? false : HardcodedFonts.setFont(gen, fontname, fontsize, text.getText()); if (pclFont) { //this.currentFill = col; if (col != null) { //useColor(ct); gen.setTransparencyMode(true, false); gen.selectGrayscale(col); } saveGraphicsState(); graphicContext.translate(rx, bl); setCursorPos(0, 0); gen.setTransparencyMode(true, true); if (text.hasUnderline()) { gen.writeCommand("&d0D"); } super.renderText(text); //Updates IPD and renders words and spaces if (text.hasUnderline()) { gen.writeCommand("&d@"); } restoreGraphicsState(); } else { //Use Java2D to paint different fonts via bitmap final Font font = getFontFromArea(text); final int baseline = text.getBaselineOffset(); //for cursive fonts, so the text isn't clipped int extraWidth = font.getFontSize() / 3; final FontMetricsMapper mapper = (FontMetricsMapper) fontInfo.getMetricsFor(font.getFontName()); int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000; final int additionalBPD = maxAscent - baseline; Graphics2DAdapter g2a = getGraphics2DAdapter(); final Rectangle paintRect = new Rectangle(rx, currentBPPosition + text.getOffset() - additionalBPD, text.getIPD() + extraWidth, text.getBPD() + additionalBPD); RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width, paintRect.height, null); Map atts = new java.util.HashMap(); atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); atts.put(SRC_TRANSPARENCY, "true"); rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.setFont(mapper.getFont(font.getFontSize())); g2d.translate(0, baseline + additionalBPD); g2d.scale(1000, 1000); g2d.setColor(col); Java2DRenderer.renderText(text, g2d, font); renderTextDecoration(g2d, mapper, fontsize, text, 0, 0); } public Dimension getImageSize() { return paintRect.getSize(); } }; g2a.paintImage(painter, rc, paintRect.x, paintRect.y, paintRect.width, paintRect.height); currentIPPosition = saveIP + text.getAllocIPD(); } } catch (IOException ioe) { handleIOTrouble(ioe); } }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Draws borders. Borders are drawn in-memory and painted as a bitmap. * @param borderRect the border rectangle * @param bpsBefore the border specification on the before side * @param bpsAfter the border specification on the after side * @param bpsStart the border specification on the start side * @param bpsEnd the border specification on the end side *///from w w w.ja va2 s .c o m protected void drawQualityBorders(Rectangle2D.Float borderRect, final BorderProps bpsBefore, final BorderProps bpsAfter, final BorderProps bpsStart, final BorderProps bpsEnd) { Graphics2DAdapter g2a = getGraphics2DAdapter(); final Rectangle.Float effBorderRect = new Rectangle2D.Float(0, 0, borderRect.width, borderRect.height); final Rectangle paintRect = new Rectangle(Math.round(borderRect.x * 1000f), Math.round(borderRect.y * 1000f), (int) Math.floor(borderRect.width * 1000f) + 1, (int) Math.floor(borderRect.height * 1000f) + 1); //Add one pixel wide safety margin around the paint area int pixelWidth = (int) Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution()); final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth; final int yoffset = pixelWidth; paintRect.x += xoffset; paintRect.y += yoffset; paintRect.width += 2 * pixelWidth; paintRect.height += 2 * pixelWidth; RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width, paintRect.height, null); Map atts = new java.util.HashMap(); atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); atts.put(SRC_TRANSPARENCY, "true"); rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(xoffset, yoffset); g2d.scale(1000, 1000); float startx = effBorderRect.x; float starty = effBorderRect.y; float width = effBorderRect.width; float height = effBorderRect.height; boolean[] b = new boolean[] { (bpsBefore != null), (bpsEnd != null), (bpsAfter != null), (bpsStart != null) }; if (!b[0] && !b[1] && !b[2] && !b[3]) { return; } float[] bw = new float[] { (b[0] ? bpsBefore.width / 1000f : 0.0f), (b[1] ? bpsEnd.width / 1000f : 0.0f), (b[2] ? bpsAfter.width / 1000f : 0.0f), (b[3] ? bpsStart.width / 1000f : 0.0f) }; float[] clipw = new float[] { BorderProps.getClippedWidth(bpsBefore) / 1000f, BorderProps.getClippedWidth(bpsEnd) / 1000f, BorderProps.getClippedWidth(bpsAfter) / 1000f, BorderProps.getClippedWidth(bpsStart) / 1000f }; starty += clipw[0]; height -= clipw[0]; height -= clipw[2]; startx += clipw[3]; width -= clipw[3]; width -= clipw[1]; boolean[] slant = new boolean[] { (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3]) }; if (bpsBefore != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty - clipw[0]; float clipy = outery + clipw[0]; float innery = outery + bw[0]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(sx1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(sx1a, outery); lineTo(ex1a, outery); } lineTo(ex1, clipy); lineTo(ex2, innery); lineTo(sx2, innery); closePath(); //clip(); g.clip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, outery, ex1a - sx1a, innery - outery); Java2DRenderer.drawBorderLine(lineRect, true, true, bpsBefore.style, bpsBefore.color, g); //restoreGraphicsState(); } if (bpsEnd != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = starty + height; float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx + width + clipw[1]; float clipx = outerx - clipw[1]; float innerx = outerx - bw[1]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, sy1); float sy1a = sy1; float ey1a = ey1; if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, sy1a); lineTo(outerx, ey1a); } lineTo(clipx, ey1); lineTo(innerx, ey2); lineTo(innerx, sy2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(innerx, sy1a, outerx - innerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsEnd.style, bpsEnd.color, g); //restoreGraphicsState(); } if (bpsAfter != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty + height + clipw[2]; float clipy = outery - clipw[2]; float innery = outery - bw[2]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(ex1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(ex1a, outery); lineTo(sx1a, outery); } lineTo(sx1, clipy); lineTo(sx2, innery); lineTo(ex2, innery); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, innery, ex1a - sx1a, outery - innery); Java2DRenderer.drawBorderLine(lineRect, true, false, bpsAfter.style, bpsAfter.color, g); //restoreGraphicsState(); } if (bpsStart != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = sy1 + height; float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx - clipw[3]; float clipx = outerx + clipw[3]; float innerx = outerx + bw[3]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, ey1); float sy1a = sy1; float ey1a = ey1; if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, ey1a); lineTo(outerx, sy1a); } lineTo(clipx, sy1); lineTo(innerx, sy2); lineTo(innerx, ey2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(outerx, sy1a, innerx - outerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsStart.style, bpsStart.color, g); //restoreGraphicsState(); } } public Dimension getImageSize() { return paintRect.getSize(); } }; try { g2a.paintImage(painter, rc, paintRect.x - xoffset, paintRect.y, paintRect.width, paintRect.height); } catch (IOException ioe) { handleIOTrouble(ioe); } }
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method initializes the design of the frame. * */// ww w. ja v a 2 s . c o m private void initialize() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = graphicsEnvironment.getMaximumWindowBounds(); setPreferredSize(bounds.getSize()); this.setJMenuBar(getBanner()); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Sets the main menu (the one separated by jsplitPane1) this.setContentPane(getBasePanel()); this.setTitle(Messages.getString("EditorFrame.application.title")); //$NON-NLS-1$ addWindowListener(this.windowListener); try { // Associates the icon (frame.icon = icon_tangara.png) to Tangara URL url = EditorFrame.class.getResource(ICON_PATH); MediaTracker attenteChargement = new MediaTracker(this); Image image = Toolkit.getDefaultToolkit().getImage(url); attenteChargement.addImage(image, 0); attenteChargement.waitForAll(); setIconImage(image); } catch (InterruptedException e) { LOG.warn("Error while loading icon"); //$NON-NLS-1$ } // fileChooser allows to easily choose a file // when you open (FILE->OPEN...) you have the choice between .txt or // .tgr fileChooser = new JFileChooser(Program.instance().getCurrentDirectory()); // for TangaraFile ".tgr" fileChooser.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) return true; return FileUtils.isTangaraFile(f); } @Override public String getDescription() { return Messages.getString("EditorFrame.file.programFilesDescription"); //$NON-NLS-1$ } }); fileChooserWithoutFilter = new JFileChooser(Program.instance().getCurrentDirectory()); pack(); setVisible(true); setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); }
From source file:org.openmicroscopy.shoola.agents.dataBrowser.layout.SquaryLayout.java
/** * Visits an {@link ImageSet} node that contains {@link ImageSet} nodes. * /*from www .j a v a 2 s . c o m*/ * @param node The parent {@link ImageSet} node. */ private void visitContainerNode(ImageSet node) { //Then figure out the number of columns, which is the same as the //number of rows. if (node.getChildrenDisplay().size() == 0) { //node with no child LayoutUtils.noChildLayout(node); return; } Object[] children = sorter.sortAsArray(node.getChildrenDisplay()); Dimension d; int maxY = 0; int x = 0, y = 0; ImageDisplay child; Dimension dd = node.getPreferredSize(); for (int i = 0; i < children.length; i++) { child = (ImageDisplay) children[i]; d = child.getPreferredSize(); d = new Dimension(dd.width, d.height); child.setBounds(x, y, d.width, d.height); child.setCollapsed(false); x = 0; if (maxY == 0) y += d.height; else y += maxY; maxY = 0; } Rectangle bounds = node.getContentsBounds(); d = bounds.getSize(); node.getInternalDesktop().setSize(d); node.getInternalDesktop().setPreferredSize(d); node.setCollapsed(false); }