Example usage for java.awt Dimension getHeight

List of usage examples for java.awt Dimension getHeight

Introduction

In this page you can find the example usage for java.awt Dimension getHeight.

Prototype

public double getHeight() 

Source Link

Usage

From source file:com.mightypocket.ashot.Mediator.java

private void updateImageProcessor(final ImageEx img) {
    final boolean ls = isLandscape();
    if (isScaleFit()) {
        Dimension customBounds = presenter.getPresenterDimension();

        int w = img.getValue().getWidth(null);
        int h = img.getValue().getHeight(null);

        if (landscape != img.isLandscape()) {
            final int t = w;
            w = h;//from  w w  w. j  ava2s.c o  m
            h = t;
        }

        double scale = Math.min(customBounds.getWidth() / w, customBounds.getHeight() / h);
        imageProcessor.setScale(scale);
    }

    final boolean ccw = p.getBoolean(PREF_ROTATION_CCW, true);

    if (ls != img.isLandscape()) {
        if (ccw == img.isCcw()) {
            if (ccw)
                imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R270 : ImageProcessor.Rotation.R90);
            else
                imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R90 : ImageProcessor.Rotation.R270);
        } else {
            if (ls) {
                imageProcessor.setRotation(ccw ? ImageProcessor.Rotation.R270 : ImageProcessor.Rotation.R90);
            } else {
                imageProcessor
                        .setRotation(img.isCcw() ? ImageProcessor.Rotation.R90 : ImageProcessor.Rotation.R270);
            }
        }
    } else {
        if (ccw == img.isCcw()) {
            imageProcessor.setRotation(ImageProcessor.Rotation.R0);
        } else {
            imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R180 : ImageProcessor.Rotation.R0);
        }
    }
}

From source file:org.safs.selenium.webdriver.CFComponent.java

/** @return Rectangle, the rectangle relative to the browser. 
 * /*from  w  w  w .ja v a 2 s  .  c om*/
 * If this return 'absolute rectangle on screen', we SHOULD remove override method {@link #getRectangleImage(Rectangle)}.<br>
 * But we need to be careful, Robot will be used to get image, we have to implement RMI to get image if the <br>
 * browser is running on a remote machine.<br>
 */
protected Rectangle getComponentRectangle() {
    String debugmsg = StringUtils.debugmsg(false);
    WebElement component = (compObject != null ? compObject : winObject);
    try {
        //Get component's location relative to the browser
        Point p = WDLibrary.getLocation(component, false);
        org.openqa.selenium.Dimension dim = component.getSize();
        return new Rectangle(p.x, p.y, dim.getWidth(), dim.getHeight());
    } catch (Exception e) {
        IndependantLog.warn(debugmsg + "Fail to get bounds for " + windowName + ":" + compName
                + " on screen due to " + StringUtils.debugmsg(e));
    }
    return null;
}

From source file:ome.services.ThumbnailCtx.java

/**
 * Creates metadata for a thumbnail of a given set of pixels set and X-Y
 * dimensions.//  w w  w .  j  a v a2  s. c  o  m
 * 
 * @param pixels The Pixels set to create thumbnail metadata for.
 * @param dimensions The dimensions of the thumbnail.
 * 
 * @return the thumbnail metadata as created.
 * @see getThumbnailMetadata()
 */
public Thumbnail createThumbnailMetadata(Pixels pixels, Dimension dimensions) {
    // Unload the pixels object to avoid transactional headaches
    Pixels unloadedPixels = new Pixels(pixels.getId(), false);
    Thumbnail thumb = new Thumbnail();
    thumb.setPixels(unloadedPixels);
    thumb.setMimeType(DEFAULT_MIME_TYPE);
    thumb.setSizeX((int) dimensions.getWidth());
    thumb.setSizeY((int) dimensions.getHeight());
    return thumb;
}

From source file:org.apache.fop.render.pcl.PCLImageHandlerGraphics2D.java

/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    PCLRenderingContext pclContext = (PCLRenderingContext) context;
    ImageGraphics2D imageG2D = (ImageGraphics2D) image;
    Dimension imageDim = imageG2D.getSize().getDimensionMpt();
    PCLGenerator gen = pclContext.getPCLGenerator();

    Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y);
    gen.setCursorPos(transPoint.getX(), transPoint.getY());

    boolean painted = false;
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
    tempGen.setDitheringQuality(gen.getDitheringQuality());
    try {//from w  w w. ja  v a2  s  .c o m
        GraphicContext ctx = (GraphicContext) pclContext.getGraphicContext().clone();

        AffineTransform prepareHPGL2 = new AffineTransform();
        prepareHPGL2.scale(0.001, 0.001);
        ctx.setTransform(prepareHPGL2);

        PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
        graphics.setGraphicContext(ctx);
        graphics.setClippingDisabled(false /*pclContext.isClippingDisabled()*/);
        Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imageDim.getWidth(), imageDim.getHeight());
        imageG2D.getGraphics2DImagePainter().paint(graphics, area);

        //If we arrive here, the graphic is natively paintable, so write the graphic
        gen.writeCommand(
                "*c" + gen.formatDouble4(pos.width / 100f) + "x" + gen.formatDouble4(pos.height / 100f) + "Y");
        gen.writeCommand("*c0T");
        gen.enterHPGL2Mode(false);
        gen.writeText("\nIN;");
        gen.writeText("SP1;");
        //One Plotter unit is 0.025mm!
        double scale = imageDim.getWidth() / UnitConv.mm2pt(imageDim.getWidth() * 0.025);
        gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;");
        gen.writeText("IR0,100,0,100;");
        gen.writeText("PU;PA0,0;\n");
        baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream
        gen.writeText("\n");

        gen.enterPCLMode(false);
        painted = true;
    } catch (UnsupportedOperationException uoe) {
        log.debug(
                "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage());
    }

    if (!painted) {
        //Fallback solution: Paint to a BufferedImage
        FOUserAgent ua = context.getUserAgent();
        ImageManager imageManager = ua.getFactory().getImageManager();
        ImageRendered imgRend;
        try {
            imgRend = (ImageRendered) imageManager.convertImage(imageG2D,
                    new ImageFlavor[] { ImageFlavor.RENDERED_IMAGE }/*, hints*/);
        } catch (ImageException e) {
            throw new IOException("Image conversion error while converting the image to a bitmap"
                    + " as a fallback measure: " + e.getMessage());
        }

        gen.paintBitmap(imgRend.getRenderedImage(), new Dimension(pos.width, pos.height),
                pclContext.isSourceTransparencyEnabled());
    }
}

From source file:com.sshtools.common.ui.SshToolsApplicationFrame.java

/**
 *
 *
 * @param application/*  w ww .j  a va2  s. c  om*/
 * @param panel
 *
 * @throws SshToolsApplicationException
 */
public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    this.panel = panel;
    this.application = application;

    if (application != null) {
        setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(),
                application.getApplicationVersion())); // + " " + application.getApplicationVersion());
    }

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    // Register the File menu
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));

        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));

        // Register the Help menu
    }
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99));

    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));

    }

    // Register the Changelog box action
    if (showChangelogBox && application != null) {
        panel.registerAction(changelogAction = new ChangelogAction(this, application));

    }
    panel.registerAction(faqAction = new FAQAction());
    panel.registerAction(beginnerAction = new BeginnerAction());
    panel.registerAction(advancedAction = new AdvancedAction());

    getApplicationPanel().rebuildActionComponents();

    JPanel p = new JPanel(new BorderLayout());

    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        JPanel t = new JPanel(new BorderLayout());
        t.add(panel.getToolBar(), BorderLayout.NORTH);
        t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
        toolSeparator.setVisible(panel.getToolBar().isVisible());

        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent evt) {
                log.debug("Tool separator is now " + pnl.getToolBar().isVisible());
                toolSeparator.setVisible(pnl.getToolBar().isVisible());
            }
        });
        p.add(t, BorderLayout.NORTH);
    }

    p.add(panel, BorderLayout.CENTER);

    if (panel.getStatusBar() != null) {
        p.add(panel.getStatusBar(), BorderLayout.SOUTH);
    }

    getContentPane().setLayout(new GridLayout(1, 1));
    getContentPane().add(p);

    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }

            }
        }
    });

    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;

    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);

            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());

                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;

                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }

                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }

                setLocation(newLocation);
                found = true;
            }
        }
    }

    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
}

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Called via SingleInstanceListener / SingleInstanceService. Shows a
 * splashscreen and bring the existing instance to the front.
 *///from w  ww  .j a  v  a  2 s . c  o m
@Override
public void newActivation(String[] arg0) {
    LOGGER.info(
            "A second instance of AtlasViewer has been started.. The single instance if requesting focus now...");

    /*
     * Showing the Spalshscreen for one secong
     */
    try {
        final URL splashscreenUrl = atlasConfig.getResource(AtlasConfig.SPLASHSCREEN_RESOURCE_NAME);
        if (splashscreenUrl != null) {
            JWindow splashWindow = new JWindow(atlasJFrame);
            JPanel panel = new JPanel(new BorderLayout());
            ImageIcon icon = new ImageIcon(splashscreenUrl);
            panel.add(new JLabel(icon), BorderLayout.CENTER);
            panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            splashWindow.getContentPane().add(panel);
            splashWindow.getRootPane().setOpaque(true);
            splashWindow.pack();
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            splashWindow.setLocation((int) (d.getWidth() - splashWindow.getWidth()) / 2,
                    (int) (d.getHeight() - splashWindow.getHeight()) / 2);
            splashWindow.setVisible(true);
            Thread.sleep(1500);
            splashWindow.dispose();
            splashWindow = null;
        }
    } catch (Exception e) {
        LOGGER.warn("Singleinstance.newActivation had problems while showing the splashscreen:", e);
    }

    if (getJFrame() != null) {
        if (!getJFrame().isShowing())
            getJFrame().setVisible(true);

        /* In case that it has been iconified */
        getJFrame().setExtendedState(Frame.NORMAL);

        getJFrame().requestFocus();
        getJFrame().toFront();
    }
}

From source file:com.sshtools.appframework.ui.SshToolsApplicationFrame.java

/**
 * @param application/*ww w  . j  a v a  2  s  .  c om*/
 * @param panel
 * 
 * @throws SshToolsApplicationException
 */

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    log.debug("Initialising frame");
    this.panel = panel;
    this.application = application;
    if (application != null) {
        setTitle(application.getApplicationName() + " - " + application.getApplicationVersion());
    }
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    // Register the File menu
    panel.registerActionMenu(new ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));
        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));
        // Register the Help menu
    }
    panel.registerActionMenu(new ActionMenu("Help", "Help", 'h', 99));
    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));
    }

    getApplicationPanel().rebuildActionComponents();
    // JPanel p = new JPanel(new ToolBarLayout());
    JPanel p = new JPanel(new BorderLayout(0, 0));
    JPanel center = new JPanel(new BorderLayout(0, 0));
    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        // center.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL),
        // BorderLayout.NORTH);
        // toolSeparator.setVisible(panel.getToolBar().isVisible());
        // panel.getToolBar().addComponentListener(new ComponentAdapter() {
        // public void componentShown(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // public void componentHidden(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // });
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {

            public void componentHidden(ComponentEvent evt) {
                // toolSeparator.setVisible(pnl.getToolBar().isVisible());

            }

        });
        p.add(panel.getToolBar(), BorderLayout.NORTH);
    }
    center.add(panel, BorderLayout.CENTER);
    p.add(center, BorderLayout.CENTER);
    getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    getContentPane().add(p);
    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }
            }

        }

    });
    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;
    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);
            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());
                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;
                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }
                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }
                setLocation(newLocation);
                found = true;
            }
        }
    }
    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            setSize(800, 600);
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
    log.debug("Initialisation of frame complete");
}

From source file:org.apache.fop.render.pdf.PDFDocumentHandler.java

/** {@inheritDoc} */
public void startPage(int index, String name, String pageMasterName, Dimension size) throws IFException {
    this.pdfResources = this.pdfDoc.getResources();

    PageBoundaries boundaries = new PageBoundaries(size, getContext().getForeignAttributes());

    Rectangle trimBox = boundaries.getTrimBox();
    Rectangle bleedBox = boundaries.getBleedBox();
    Rectangle mediaBox = boundaries.getMediaBox();
    Rectangle cropBox = boundaries.getCropBox();

    // set scale attributes
    double scaleX = 1;
    double scaleY = 1;
    String scale = (String) getContext().getForeignAttribute(PageScale.EXT_PAGE_SCALE);
    Point2D scales = PageScale.getScale(scale);
    if (scales != null) {
        scaleX = scales.getX();/*from   w  ww  .  j a v  a 2 s  .  c om*/
        scaleY = scales.getY();
    }

    //PDF uses the lower left as origin, need to transform from FOP's internal coord system
    AffineTransform boxTransform = new AffineTransform(scaleX / 1000, 0, 0, -scaleY / 1000, 0,
            scaleY * size.getHeight() / 1000);

    this.currentPage = this.pdfDoc.getFactory().makePage(this.pdfResources, index,
            toPDFCoordSystem(mediaBox, boxTransform), toPDFCoordSystem(cropBox, boxTransform),
            toPDFCoordSystem(bleedBox, boxTransform), toPDFCoordSystem(trimBox, boxTransform));
    if (accessEnabled) {
        logicalStructureHandler.startPage(currentPage);
    }

    pdfUtil.generatePageLabel(index, name);

    currentPageRef = new PageReference(currentPage, size);
    this.pageReferences.put(Integer.valueOf(index), currentPageRef);

    this.generator = new PDFContentGenerator(this.pdfDoc, this.outputStream, this.currentPage);
    // Transform the PDF's default coordinate system (0,0 at lower left) to the PDFPainter's
    AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0, (scaleY * size.height) / 1000f);
    basicPageTransform.scale(scaleX, scaleY);
    generator.saveGraphicsState();
    generator.concatenate(basicPageTransform);
}

From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private BufferedImage mergeRows(Queue<BufferedImage> legendsQueue) {
    // I am doing a straight cast since I know that I built this
    // dimension object by using the widths and heights of the various
    // bufferedimages for the various bkgColor map entries.
    final Dimension finalDimension = new Dimension();
    final int numRows = legendsQueue.size();
    finalDimension.setSize(Math.max(footerW, colorW + ruleW + labelW) + 2 * dx + 2 * margin,
            rowH * numRows + 2 * margin + (numRows - 1) * dy);

    final int totalWidth = (int) finalDimension.getWidth();
    final int totalHeight = (int) finalDimension.getHeight();
    BufferedImage finalLegend = ImageUtils.createImage(totalWidth, totalHeight, (IndexColorModel) null,
            transparent);/*from  ww  w. ja  v a2 s .  c  o  m*/

    /*
     * For RAMP type, only HORIZONTAL or VERTICAL condition is valid
     */
    if (colorMapType == ColorMapType.RAMP) {

        final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
        Graphics2D finalGraphics = ImageUtils.prepareTransparency(transparent, backgroundColor, finalLegend,
                hintsMap);
        hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        finalGraphics.setRenderingHints(hintsMap);

        int topOfRow = (int) (margin + 0.5);
        for (int i = 0; i < numRows; i++) {
            final BufferedImage img = legendsQueue.remove();

            // draw the image
            finalGraphics.drawImage(img, (int) (margin + 0.5), topOfRow, null);
            topOfRow += img.getHeight() + dy;

        }

        if (this.layout == LegendLayout.HORIZONTAL) {
            BufferedImage newImage = new BufferedImage(totalHeight, totalWidth, finalLegend.getType());
            Graphics2D g2 = newImage.createGraphics();
            g2.rotate(-Math.PI / 2, 0, 0);
            g2.drawImage(finalLegend, null, -totalWidth, 0);
            finalLegend = newImage;
            g2.dispose();
            finalGraphics.dispose();
        }
    } else {
        List<RenderedImage> imgs = new ArrayList<RenderedImage>(legendsQueue);

        LegendMerger.MergeOptions options = new LegendMerger.MergeOptions(imgs, (int) dx, (int) dy,
                (int) margin, 0, backgroundColor, transparent, true, layout, rowWidth, rows, columnHeight,
                columns, null, false, false);
        finalLegend = LegendMerger.mergeRasterLegends(options);
    }

    return finalLegend;

}

From source file:ome.services.ThumbnailBean.java

/** Actually does the work specified by {@link getThumbnailByLongestSideDirect()}.*/
private byte[] _getThumbnailByLongestSideDirect(Integer size, Integer theZ, Integer theT) {
    // Sanity check thumbnail sizes
    Dimension dimensions = sanityCheckThumbnailSizes(size, size);

    dimensions = ctx.calculateXYWidths(pixels, (int) dimensions.getWidth());
    return retrieveThumbnailDirect((int) dimensions.getWidth(), (int) dimensions.getHeight(), theZ, theT);
}