List of usage examples for java.awt Dimension setSize
public void setSize(int width, int height)
From source file:Main.java
/** * Converts a Bound to a Dimension. Note that some information will be * lost (depth, x, y, etc) yet the width and height will be preserved * @param pBound//from w ww .j a v a2s . c o m * @return */ public static Dimension convertToDimension(Bounds pBound) { Dimension result = new Dimension(); result.setSize(pBound.getWidth(), pBound.getHeight()); return result; }
From source file:Main.java
/** * Displays a message dialog with given information. *//*from w w w . j a v a2 s .c om*/ public static void showInformationDialog(Component component, String message) { final JPanel panel = new JPanel(new BorderLayout(5, 5)); final JLabel messageLabel = new JLabel(message); messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize())); panel.add(messageLabel, BorderLayout.CENTER); // Adjust stack trace dimensions final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7); final Dimension maxStackTraceDimension = new Dimension(500, 500); maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()), Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight())); JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE); }
From source file:org.xulux.swing.util.SwingUtils.java
/** * @param rectangle the rectangle to get the dimensions for * @return the dimensions for the rectangle specified *//*from w w w. j ava 2s .co m*/ public static Dimension getDimension(WidgetRectangle rectangle) { if (rectangle == null) { return null; } Dimension dim = new Dimension(); dim.setSize(rectangle.getWidth(), rectangle.getHeight()); return dim; }
From source file:ryerson.daspub.utility.VideoUtils.java
/** * Get video stream screen dimensions.// w ww . j av a 2 s.com * @param Input Input video file * @returns Video stream screen dimensions * @throws IllegalArgumentException */ public static Dimension getSize(File Input) throws IllegalArgumentException { // Create a Xuggler container object IContainer container = IContainer.make(); // Open up the container if (container.open(Input.getAbsolutePath(), IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("Could not open file: " + Input.getAbsolutePath()); // get streams int numStreams = container.getNumStreams(); // iterate through the streams to find video dimensions Dimension dim = new Dimension(); for (int i = 0; i < numStreams; i++) { // find the stream object IStream stream = container.getStream(i); // get the pre-configured decoder that can decode this stream; IStreamCoder coder = stream.getStreamCoder(); if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) { dim.setSize(coder.getWidth(), coder.getHeight()); } } // return result return dim; }
From source file:jfractus.app.Main.java
private static void parseSize(String sizeStr, Dimension dim) throws ArgumentParseException, BadValueOfArgumentException { Scanner scanner = new Scanner(sizeStr); scanner.useLocale(Locale.ENGLISH); scanner.useDelimiter("x"); int outWidth = 0, outHeight = 0; try {//from w w w. j a v a 2 s . co m outWidth = scanner.nextInt(); outHeight = scanner.nextInt(); if (outWidth < 0 || outHeight < 0) throw new BadValueOfArgumentException("Bad value of argument"); } catch (InputMismatchException e) { throw new ArgumentParseException("Command line parse exception"); } catch (NoSuchElementException e) { throw new ArgumentParseException("Command line parse exception"); } if (scanner.hasNext()) throw new ArgumentParseException("Command line parse exception"); dim.setSize(outWidth, outHeight); }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Returns a label with multiple lines that is sized according to * the string parameter./*from w w w .jav a 2 s. c o m*/ * * @param msg the string that will be contained in the label. * * @return a MultiLineLabel sized according to the passed * in string. */ public static MultiLineLabel getSizedLabel(String msg) { Dimension dim = new Dimension(); MultiLineLabel label = new MultiLineLabel(msg); FontMetrics fm = label.getFontMetrics(label.getFont()); int width = fm.stringWidth(msg); dim.setSize(Integer.MAX_VALUE, width / 9); //what's this magic? label.setPreferredSize(dim); return label; }
From source file:com.moviejukebox.scanner.artwork.PosterScanner.java
/** * Read an URL and get the dimensions of the image using a specific image * type//www . j a v a2 s .c o m * * @param imageUrl * @param imageType * @return */ public static Dimension getUrlDimensions(String imageUrl, String imageType) { Dimension imageDimension = new Dimension(0, 0); @SuppressWarnings("rawtypes") Iterator readers = ImageIO.getImageReadersBySuffix(imageType); if (readers.hasNext()) { ImageReader reader = (ImageReader) readers.next(); try (InputStream in = new URL(imageUrl).openStream(); ImageInputStream iis = ImageIO.createImageInputStream(in)) { reader.setInput(iis, Boolean.TRUE); imageDimension.setSize(reader.getWidth(0), reader.getHeight(0)); } catch (IOException ex) { LOG.debug("getUrlDimensions error: {}: can't open url: {}", ex.getMessage(), imageUrl); } finally { reader.dispose(); } } return imageDimension; }
From source file:util.WebUtil.java
public static Dimension getDimension(Dimension d, int mw, int mh) { int w = (int) d.getWidth(); int h = (int) d.getHeight(); int nh = h;//from www . ja v a 2 s . c o m int nw = w; if (w > mw) { float r = (float) mw / (float) w; nh = (int) ((float) h * (float) r); nw = mw; } if (nh > mh) { float r = (float) mh / (float) nh; nw = (int) ((float) nw * (float) r); nh = mh; } d.setSize(nw, nh); return d; }
From source file:fr.pasteque.pos.sales.restaurant.Place.java
public void setButtonBounds() { Dimension d = m_btn.getPreferredSize(); d.setSize(d.getWidth() + 30, d.getHeight()); m_btn.setBounds(m_ix - d.width / 2, m_iy - d.height / 2, d.width, d.height); }
From source file:org.apache.fop.render.svg.SVGRenderer.java
/** {@inheritDoc} */ public void renderPage(PageViewport pageViewport) throws IOException { log.debug("Rendering page: " + pageViewport.getPageNumberString()); // Get a DOMImplementation DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document this.document = domImpl.createDocument(null, "svg", null); // Create an SVGGeneratorContext to customize SVG generation SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.document); ctx.setComment("Generated by " + userAgent.getProducer() + " with Batik SVG Generator"); ctx.setEmbeddedFontsOn(true);/*from ww w.ja v a 2 s. c o m*/ // Create an instance of the SVG Generator this.svgGenerator = new SVGGraphics2D(ctx, true); Rectangle2D viewArea = pageViewport.getViewArea(); Dimension dim = new Dimension(); dim.setSize(viewArea.getWidth() / 1000, viewArea.getHeight() / 1000); this.svgGenerator.setSVGCanvasSize(dim); AffineTransform at = this.svgGenerator.getTransform(); this.state = new Java2DGraphicsState(this.svgGenerator, this.fontInfo, at); try { //super.renderPage(pageViewport); renderPageAreas(pageViewport.getPage()); } finally { this.state = null; } writeSVGFile(pageViewport.getPageIndex()); this.svgGenerator = null; this.document = null; }