List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:ddf.catalog.transformer.input.pptx.PptxInputTransformer.java
/** * If the slide show doesn't contain any slides, then return null. Otherwise, return jpeg * image data of the first slide in the deck. * * @param slideShow//w w w. ja v a 2s . com * @return jpeg thumbnail or null if thumbnail can't be created * @throws IOException */ private byte[] generatePptxThumbnail(XMLSlideShow slideShow) throws IOException { if (slideShow.getSlides().isEmpty()) { LOGGER.info("the powerpoint file does not contain any slides, skipping thumbnail generation"); return null; } Dimension pgsize = slideShow.getPageSize(); int largestDimension = (int) Math.max(pgsize.getHeight(), pgsize.getWidth()); float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension; int scaledHeight = (int) (pgsize.getHeight() * scalingFactor); int scaledWidth = (int) (pgsize.getWidth() * scalingFactor); BufferedImage img = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); try { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics.scale(scalingFactor, scalingFactor); slideShow.getSlides().get(0).draw(graphics); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { ImageIOUtil.writeImage(img, FORMAT_NAME, outputStream, RESOLUTION_DPI, IMAGE_QUALITY); return outputStream.toByteArray(); } } catch (RuntimeException e) { if (e.getCause() instanceof javax.imageio.IIOException) { LOGGER.warn("unable to generate thumbnail for PPTX file", e); } else { throw e; } } finally { graphics.dispose(); } return null; }
From source file:ArrowPanel.java
/** * Paints the arrow panel.// w w w .j ava 2 s .com * * @param g * the graphics device for drawing on. */ public void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; // first determine the size of the drawing area... final Dimension size = getSize(); final Insets insets = getInsets(); this.available.setRect(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); g2.translate(insets.left, insets.top); g2.fill(getArrow(this.type)); }
From source file:jflowmap.JFlowMapApplet.java
@Override public void init() { try {/*w w w . j a v a 2 s . c o m*/ Container parent; JFlowMapAppletFrame frame = new JFlowMapAppletFrame(this); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setSize((int) (screenSize.getWidth() * 0.8), (int) (screenSize.getHeight() * 0.8)); SwingUtils.centerOnScreen(frame); parent = frame.getContentPane(); createUI(parent); frame.setVisible(true); } catch (Exception ex) { logger.error(ex); JMsgPane.showProblemDialog(JFlowMapApplet.this, ex); } }
From source file:CenterLayout.java
/** * Returns the preferred size.//from w w w .j a v a 2 s. c om * * @param parent * the parent. * * @return the preferred size. */ public Dimension preferredLayoutSize(final Container parent) { synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); if (parent.getComponentCount() > 0) { final Component component = parent.getComponent(0); final Dimension d = component.getPreferredSize(); return new Dimension((int) d.getWidth() + insets.left + insets.right, (int) d.getHeight() + insets.top + insets.bottom); } else { return new Dimension(insets.left + insets.right, insets.top + insets.bottom); } } }
From source file:edu.uci.ics.jung.algorithms.layout.CircleLayout.java
public void initialize() { Dimension d = getSize(); if (d != null) { if (vertex_ordered_list == null) setVertexOrder(new ArrayList<V>(getGraph().getVertices())); double height = d.getHeight(); double width = d.getWidth(); if (radius <= 0) { radius = 0.45 * (height < width ? height : width); }/*from w ww .j a v a 2 s .c o m*/ int i = 0; for (V v : vertex_ordered_list) { Point2D coord = transform(v); double angle = (2 * Math.PI * i) / vertex_ordered_list.size(); coord.setLocation(Math.cos(angle) * radius + width / 2, Math.sin(angle) * radius + height / 2); CircleVertexData data = getCircleData(v); data.setAngle(angle); i++; } } }
From source file:mupomat.view.PodrskaLozinka.java
private void centrirajZaslon() { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - this.getWidth()) / 2); int y = (int) ((dimension.getHeight() - this.getHeight()) / 2); this.setLocation(x, y); this.setResizable(false); }
From source file:org.jfree.demo.TextBlockPanel.java
/** * Paints the panel./*w w w . j av a2 s. c om*/ * * @param g the graphics device. */ public void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; final Dimension size = getSize(); final Insets insets = getInsets(); final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); final double x = available.getX(); final double y = available.getY(); final float width = (float) available.getWidth(); final TextBlock block = TextUtilities.createTextBlock(this.text, this.font, Color.black, width, new G2TextMeasurer(g2)); g2.setPaint(Color.black); block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java
public void draw(final Graphics2D g2, final Rectangle2D bounds) { final Graphics2D gr2 = (Graphics2D) g2.create(); try {/* w w w. ja v a 2 s . co m*/ gr2.clip(bounds); if (scale) { final Dimension size = barcode.getPreferredSize(); final double horzScale = bounds.getWidth() / size.getWidth(); final double vertScale = bounds.getHeight() / size.getHeight(); if (keepAspectRatio) { final double scale = Math.min(horzScale, vertScale); gr2.scale(scale, scale); } else { gr2.scale(horzScale, vertScale); } } barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY()); } catch (OutputException e) { logger.error("Unable to draw barcode element", e); } finally { gr2.dispose(); } }
From source file:org.jfree.chart.demo.DrawStringPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D graphics2d = (Graphics2D) g; Dimension dimension = getSize(); Insets insets = getInsets();/*from w w w . ja v a 2 s . com*/ java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(insets.left, insets.top, dimension.getWidth() - (double) insets.left - (double) insets.right, dimension.getHeight() - (double) insets.top - (double) insets.bottom); double d = double1.getCenterX(); double d1 = double1.getCenterY(); java.awt.geom.Line2D.Double double2 = new java.awt.geom.Line2D.Double(d - 2D, d1 + 2D, d + 2D, d1 - 2D); java.awt.geom.Line2D.Double double3 = new java.awt.geom.Line2D.Double(d - 2D, d1 - 2D, d + 2D, d1 + 2D); graphics2d.setPaint(Color.red); graphics2d.draw(double2); graphics2d.draw(double3); graphics2d.setFont(font); graphics2d.setPaint(Color.black); if (rotate) TextUtilities.drawRotatedString(text, graphics2d, (float) d, (float) d1, anchor, angle, rotationAnchor); else TextUtilities.drawAlignedString(text, graphics2d, (float) d, (float) d1, anchor); }
From source file:test.be.fedict.eid.applet.JGraphTest.java
private void graphToFile(BasicVisualizationServer<String, String> visualization, File file) throws IOException { Dimension size = visualization.getSize(); int width = (int) (size.getWidth() + 1); int height = (int) (size.getHeight() + 1); LOG.debug("width: " + width); LOG.debug("height: " + height); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bufferedImage.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, 900, 650);//from ww w .j av a 2s . c om visualization.setBounds(0, 0, 900, 650); visualization.paint(graphics); graphics.dispose(); ImageIO.write(bufferedImage, "png", file); }