Example usage for java.awt Rectangle setSize

List of usage examples for java.awt Rectangle setSize

Introduction

In this page you can find the example usage for java.awt Rectangle setSize.

Prototype

public void setSize(Dimension d) 

Source Link

Document

Sets the size of this Rectangle to match the specified Dimension .

Usage

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

/**
 * /*w  ww.ja  v  a2 s  .co m*/
 * @throws IOException
 * @throws FactoryException 
 * @throws NoSuchAuthorityCodeException 
 * @throws MismatchedDimensionException
 * @throws NoSuchAuthorityCodeException
 * @throws ParseException 
 */
@Test
//   @Ignore
public void time() throws IOException, NoSuchAuthorityCodeException, FactoryException, ParseException {

    final AbstractGridFormat format = TestUtils.getFormat(timeURL);
    ImageMosaicReader reader = TestUtils.getReader(timeURL, format);

    final String[] metadataNames = reader.getMetadataNames();
    assertNotNull(metadataNames);
    assertEquals(metadataNames.length, 10);
    assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN"));
    assertEquals("2004-02-01T00:00:00.000Z", reader.getMetadataValue("TIME_DOMAIN_MINIMUM"));
    assertEquals("2004-05-01T00:00:00.000Z", reader.getMetadataValue("TIME_DOMAIN_MAXIMUM"));
    assertEquals(
            "2004-02-01T00:00:00.000Z,2004-03-01T00:00:00.000Z,2004-04-01T00:00:00.000Z,2004-05-01T00:00:00.000Z",
            reader.getMetadataValue(metadataNames[0]));

    // limit yourself to reading just a bit of it
    final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    final GeneralEnvelope envelope = reader.getOriginalEnvelope();
    final Dimension dim = new Dimension();
    dim.setSize(reader.getOriginalGridRange().getSpan(0) / 2.0, reader.getOriginalGridRange().getSpan(1) / 2.0);
    final Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange());
    rasterArea.setSize(dim);
    final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
    gg.setValue(new GridGeometry2D(range, envelope));

    // use imageio with defined tiles
    final ParameterValue<Boolean> useJai = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
    useJai.setValue(false);

    // specify time
    final ParameterValue<List> time = ImageMosaicFormat.TIME.createValue();

    final SimpleDateFormat formatD = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    formatD.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date timeD = formatD.parse("2004-02-01T00:00:00.000Z");
    time.setValue(new ArrayList() {
        {
            add(timeD);
        }
    });

    // Test the output coverage
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, time }, "time test");

    // specify time range
    // Test the output coverage
    reader = TestUtils.getReader(timeURL, format);
    time.setValue(new ArrayList() {
        {
            add(new DateRange(formatD.parse("2004-02-01T00:00:00.000Z"),
                    formatD.parse("2004-03-01T00:00:00.000Z")));
        }
    });
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, time }, "time test");

}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

/**
 * Tests the {@link ImageMosaicReader} with support for different
 * resolutions/different number of overviews.
 * /*from  w w  w.  j  a va  2s .c  o m*/
 * world_a.tif => Pixel Size = (0.833333333333333,-0.833333333333333); 4
 * overviews world_b1.tif => Pixel Size =
 * (1.406250000000000,-1.406250000000000); 2 overviews world_b2.tif => Pixel
 * Size = (0.666666666666667,-0.666666666666667); 0 overviews
 * 
 * @throws IOException
 * @throws MismatchedDimensionException
 * @throws FactoryException
 */
@Test
//    @Ignore
public void testHeterogeneousGranules() throws IOException, MismatchedDimensionException, FactoryException {

    final AbstractGridFormat format = TestUtils.getFormat(heterogeneousGranulesURL);
    ImageMosaicReader reader = TestUtils.getReader(heterogeneousGranulesURL, format);

    final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    final GeneralEnvelope envelope = reader.getOriginalEnvelope();
    final Dimension dim = new Dimension();
    dim.setSize(reader.getOriginalGridRange().getSpan(0) / 7.0, reader.getOriginalGridRange().getSpan(1) / 7.0);
    final Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange());
    rasterArea.setSize(dim);
    final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
    gg.setValue(new GridGeometry2D(range, envelope));

    // use imageio with defined tiles
    final ParameterValue<Boolean> useJai = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
    useJai.setValue(false);

    final ParameterValue<OverviewPolicy> op = AbstractGridFormat.OVERVIEW_POLICY.createValue();

    LOGGER.info("\nTesting with OverviewPolicy = QUALITY");
    op.setValue(OverviewPolicy.QUALITY);
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, op },
            "heterogeneous granules test: OverviewPolicy=QUALITY", rasterArea);

    LOGGER.info("\nTesting with OverviewPolicy = SPEED");
    reader = TestUtils.getReader(heterogeneousGranulesURL, format);
    op.setValue(OverviewPolicy.SPEED);
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, op },
            "heterogeneous granules test: OverviewPolicy=SPEED", rasterArea);

    LOGGER.info("\nTesting with OverviewPolicy = NEAREST");
    reader = TestUtils.getReader(heterogeneousGranulesURL, format);
    op.setValue(OverviewPolicy.NEAREST);
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, op },
            "heterogeneous granules test: OverviewPolicy=NEAREST", rasterArea);

    LOGGER.info("\nTesting with OverviewPolicy = IGNORE");
    reader = TestUtils.getReader(heterogeneousGranulesURL, format);
    op.setValue(OverviewPolicy.IGNORE);
    TestUtils.checkCoverage(reader, new GeneralParameterValue[] { gg, useJai, op },
            "heterogeneous granules test: OverviewPolicy=IGNORE", rasterArea);

}

From source file:org.sugarcrm.voodoodriver.Utils.java

/**
 * Take a screen shot and save it to the specified file.
 *
 * @param outputFile  file to save the screenshot into
 * @param reporter    {@link Reporter} object for logging errors
 * @param logOK whether logging to reporter is OK.  false if this
 *              is called from a reporter object.
 * @return whether the screenshot was taken successfully
 *///  www . j a va 2 s .c  om

public static boolean takeScreenShot(String outputFile, Reporter reporter, boolean logOK) {
    Robot r = null;

    reporter.Log("Taking Screenshot.");

    File tmp = new File(outputFile);
    if (tmp.exists() && logOK) {
        String msg;
        msg = String.format("Existing screenshot '%s' will be overwritten.", outputFile);
        reporter.Warn(msg);
    }

    try {
        r = new Robot();
    } catch (java.awt.AWTException e) {
        if (logOK) {
            reporter.ReportError("Screenshot failed (running headless?)");
            reporter.ReportException(e);
        }
        return false;
    }

    Rectangle rec = new Rectangle();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    dim.setSize(dim);
    rec.setSize(dim);
    BufferedImage img = r.createScreenCapture(rec);

    try {
        ImageIO.write(img, "png", new File(outputFile));
    } catch (java.io.IOException e) {
        if (logOK) {
            reporter.ReportError("Screenshot failed (I/O Error)");
            reporter.ReportException(e);
        }
        return false;
    }

    reporter.Log(String.format("Screenshot file: %s", outputFile));
    reporter.Log("Screenshot finished.");

    return true;
}