List of usage examples for java.awt Dimension setSize
public void setSize(int width, int height)
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Returns the dimension of the last saved framesize. * * @return last saved frame size in preferences *//*from w w w.jav a 2s .co m*/ protected Dimension loadLastFrameSize() { Preferences preferences = Preferences.userNodeForPackage(this.getClass()); Dimension windowSize = new Dimension(); windowSize.setSize(preferences.getDouble(FRAME_WIDTH, DEFAULT_FRAME_WIDTH), preferences.getDouble(FRAME_HEIGHT, DEFAULT_FRAME_HEIGHT)); return windowSize; }
From source file:org.fit.cssbox.swingbox.SwingBoxEditorKit.java
private void readImpl(InputStream in, SwingBoxDocument doc, int pos) throws IOException, BadLocationException { if (component == null) throw new IllegalStateException( "Component is null, editor kit is probably deinstalled from a JEditorPane."); if (pos > doc.getLength() || pos < 0) { BadLocationException e = new BadLocationException("Invalid location", pos); readError(null, e);/*from www . j a v a2 s . co m*/ throw e; } ContentReader rdr = new ContentReader(); URL url = (URL) doc.getProperty(Document.StreamDescriptionProperty); CSSBoxAnalyzer analyzer = getCSSBoxAnalyzer(); Container parent = component.getParent(); Dimension dim; if (parent != null && parent instanceof JViewport) { dim = ((JViewport) parent).getExtentSize(); } else { dim = component.getBounds().getSize(); } if (dim.width <= 10) { // component might not be initialized, use screen size :) Dimension tmp = Toolkit.getDefaultToolkit().getScreenSize(); dim.setSize(tmp.width / 2.5, tmp.height / 2.5); } // long time = System.currentTimeMillis(); List<ElementSpec> elements; try { String ctype = null; Object ct = doc.getProperty("Content-Type"); if (ct != null) { if (ct instanceof List) ctype = (String) ((List<?>) ct).get(0); else ctype = ct.toString(); } DocumentSource docSource = new StreamDocumentSource(in, url, ctype); elements = rdr.read(docSource, analyzer, dim); String title = analyzer.getDocumentTitle(); if (title == null) title = "No title"; doc.putProperty(Document.TitleProperty, title); } catch (IOException e) { readError(url, e); throw e; } // System.out.println(System.currentTimeMillis() - time + " ms"); ElementSpec elementsArray[] = elements.toArray(new ElementSpec[0]); doc.create(elementsArray); // component.revalidate(); // component.repaint(); // System.out.println(System.currentTimeMillis() - time + " ms"); // Dictionary<Object, Object> dic = doc.getDocumentProperties(); // Enumeration<Object> en = dic.keys(); // while( en.hasMoreElements()) { // Object k = en.nextElement(); // System.out.println(k + " " + dic.get(k)); // } readFinish(url); }
From source file:com.projity.dialog.assignment.AssignmentEntryPane.java
public void init() { if (project == null) return;//from w w w. j a v a 2 s .c o m ResourcePool pool = project.getResourcePool(); // if (assignmentModel==null){ pool.getResourceOutline().getHierarchy().removeHierarchyListener(this); pool.getResourceOutline().getHierarchy().addHierarchyListener(this); assignmentModel = NodeModelFactory.getInstance().replicate(pool.getResourceOutline(), new NodeFactoryTransformer()); assignmentModel.getHierarchy().setNbEndVoidNodes(0); // don't allow blank lines // } if (spreadSheet == null) { spreadSheet = new AssignmentSpreadSheet(resourceAssigner); spreadSheet.setSpreadSheetCategory(spreadsheetCategory); // for columns. Must do first spreadSheet.setActions(new String[] {}); } cache = NodeModelCacheFactory.getInstance().createDefaultCache(assignmentModel, pool, NodeModelCache.ASSIGNMENT_TYPE, "AssignmentEntry", transformerClosure); SpreadSheetFieldArray fields = getFields(); spreadSheet.setCache(cache, fields, fields.getCellStyle(), fields.getActionList()); // set widths of these columns explicitly if (!replace) { //TODO width should come from definition in xml, not hard coded here // spreadSheet.getColumnModel().getColumn(REQUEST_DEMAND_TYPE_COLUMN).setPreferredWidth(50); spreadSheet.getColumnModel().getColumn(UNITS_COLUMN).setPreferredWidth(50); } JViewport viewport = createViewport(); viewport.setView(spreadSheet); setViewport(viewport); setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); Dimension d = spreadSheet.getPreferredSize(); Dimension enclosing = new Dimension(); //big awful hack to remove GraphicConfiguration config = GraphicConfiguration.getInstance(); int rowHeaderWidth = config.getRowHeaderWidth() + spreadSheet.getRowMargin() * 2; //should be rowHeader's one // TableColumnModel tm=spreadSheet.getColumnModel(); // int w=tm.getTotalColumnWidth(); enclosing.setSize(d.getWidth()/*+rowHeaderWidth*/, d.getHeight()); viewport.setPreferredSize(enclosing); //setBorder(new EmptyBorder(0,0,0,0)); updateTable(); }
From source file:com.qumasoft.guitools.compare.CompareFrame.java
void fitToScreen() { if (parentFrame == null) { Toolkit screenToolkit = java.awt.Toolkit.getDefaultToolkit(); Dimension screenSize = screenToolkit.getScreenSize(); // <editor-fold> setLocation(0, 20);// w ww . j av a 2s .c o m screenSize.setSize((screenSize.width * 90) / 100, (screenSize.height * 90) / 100); // </editor-fold> setSize(screenSize); } else { setLocation(parentFrame.getLocation()); setSize(parentFrame.getSize()); } }
From source file:org.geotools.coverage.io.netcdf.NetCDFMosaicReaderTest.java
@Test @Ignore//from w ww . j a va2s . c o m public void oracle() throws IOException, ParseException, NoSuchAuthorityCodeException, FactoryException { final File workDir = new File("C:\\data\\dlr\\ascatL1_mosaic"); final AbstractGridFormat format = new ImageMosaicFormat(); assertNotNull(format); ImageMosaicReader reader = (ImageMosaicReader) format.getReader(workDir.toURI().toURL()); assertNotNull(format); String[] names = reader.getGridCoverageNames(); String name = names[1]; final String[] metadataNames = reader.getMetadataNames(name); assertNotNull(metadataNames); assertEquals(metadataNames.length, 18); assertEquals("false", reader.getMetadataValue(name, "HAS_TIME_DOMAIN")); assertEquals("true", reader.getMetadataValue(name, "HAS_NUMSIGMA_DOMAIN")); assertEquals("0,1,2", reader.getMetadataValue(name, "NUMSIGMA_DOMAIN")); assertEquals("java.lang.Integer", reader.getMetadataValue(name, "NUMSIGMA_DOMAIN_DATATYPE")); assertEquals("true", reader.getMetadataValue(name, "HAS_RUNTIME_DOMAIN")); assertEquals("false", reader.getMetadataValue(name, "HAS_ELEVATION_DOMAIN")); assertEquals("false", reader.getMetadataValue(name, "HAS_XX_DOMAIN")); assertEquals("20110620020000", reader.getMetadataValue(name, "RUNTIME_DOMAIN")); assertEquals("java.lang.String", reader.getMetadataValue(name, "RUNTIME_DOMAIN_DATATYPE")); // limit yourself to reading just a bit of it final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope envelope = reader.getOriginalEnvelope(name); final Dimension dim = new Dimension(); dim.setSize(reader.getOriginalGridRange(name).getSpan(0) / 2.0, reader.getOriginalGridRange(name).getSpan(1) / 2.0); final Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange(name)); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, envelope)); final ParameterValue<Boolean> direct = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue(); direct.setValue(false); final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue(); bkg.setValue(new double[] { -9999.0 }); ParameterValue<List<String>> dateValue = null; ParameterValue<List<String>> sigmaValue = null; final String selectedSigma = "1"; final String selectedRuntime = "20110620020000"; Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(name); for (ParameterDescriptor param : params) { if (param.getName().getCode().equalsIgnoreCase("RUNTIME")) { dateValue = param.createValue(); dateValue.setValue(new ArrayList<String>() { { add(selectedRuntime); } }); } else if (param.getName().getCode().equalsIgnoreCase("NUMSIGMA")) { sigmaValue = param.createValue(); sigmaValue.setValue(new ArrayList<String>() { { add(selectedSigma); } }); } } // Test the output coverage GridCoverage2D coverage = reader.read(name, new GeneralParameterValue[] { gg, bkg, direct, sigmaValue, dateValue }); assertNotNull(coverage); }
From source file:org.geotools.coverage.io.netcdf.NetCDFReaderTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test// ww w. ja va 2 s. c o m @Ignore public void IASI() throws Exception { final URL testURL = TestData.url(this, "IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc"); final Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true)); // Get format final AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(testURL, hints); final NetCDFReader reader = (NetCDFReader) format.getReader(testURL, hints); assertNotNull(format); assertNotNull(reader); try { String[] names = reader.getGridCoverageNames(); assertNotNull(names); assertEquals(names.length, 20); // surface_emissivity final String coverageName = "surface_emissivity"; final String[] metadataNames = reader.getMetadataNames(coverageName); assertNotNull(metadataNames); assertEquals(14, metadataNames.length); // Parsing metadata values assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN")); assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN")); assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NEW_DOMAIN")); // additional domains final String newDomain = reader.getMetadataValue(coverageName, "NEW_DOMAIN"); assertNotNull(metadataNames); final String[] newDomainValues = newDomain.split(","); assertNotNull(newDomainValues); assertEquals(12, newDomainValues.length); assertEquals(13.063399669990758, Double.valueOf(newDomainValues[11]), 1E-6); assertEquals(3.6231999084702693, Double.valueOf(newDomainValues[0]), 1E-6); // subsetting the envelope final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName); final GeneralEnvelope reducedEnvelope = new GeneralEnvelope( new double[] { originalEnvelope.getLowerCorner().getOrdinate(0), originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] { originalEnvelope.getMedian().getOrdinate(0), originalEnvelope.getMedian().getOrdinate(1) }); reducedEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem(coverageName)); // Selecting bigger gridRange for a zoomed result final Dimension dim = new Dimension(); GridEnvelope gridRange = reader.getOriginalGridRange(coverageName); dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0); final Rectangle rasterArea = ((GridEnvelope2D) gridRange); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, reducedEnvelope)); // specify additional Dimensions Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName); ParameterValue<List> new_ = null; for (ParameterDescriptor param : params) { if (param.getName().getCode().equalsIgnoreCase("NEW")) { new_ = param.createValue(); new_.setValue(new ArrayList() { { add(Double.valueOf(newDomainValues[11])); } }); } } GeneralParameterValue[] values = new GeneralParameterValue[] { gg, new_ }; GridCoverage2D coverage = reader.read(coverageName, values); assertNotNull(coverage); if (TestData.isInteractiveTest()) { coverage.show(); } else { PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } } finally { if (reader != null) { try { reader.dispose(); } catch (Throwable t) { // Does nothing } } } }
From source file:org.geotools.coverage.io.netcdf.NetCDFReaderTest.java
@Test public void NetCDFTestOnFilter() throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException { File mosaic = new File(TestData.file(this, "."), "NetCDFTestOnFilter"); if (mosaic.exists()) { FileUtils.deleteDirectory(mosaic); }/*from ww w . j a v a 2 s. co m*/ assertTrue(mosaic.mkdirs()); File file = TestData.file(this, "O3-NO2.nc"); FileUtils.copyFileToDirectory(file, mosaic); file = new File(mosaic, "O3-NO2.nc"); final Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true)); // Get format final AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints); final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints); assertNotNull(format); try { String[] names = reader.getGridCoverageNames(); names = new String[] { names[1] }; for (String coverageName : names) { final String[] metadataNames = reader.getMetadataNames(coverageName); assertNotNull(metadataNames); assertEquals(12, metadataNames.length); // Parsing metadata values assertEquals("true", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN")); final String timeMetadata = reader.getMetadataValue(coverageName, "TIME_DOMAIN"); assertEquals( "2012-04-01T00:00:00.000Z/2012-04-01T00:00:00.000Z,2012-04-01T01:00:00.000Z/2012-04-01T01:00:00.000Z", timeMetadata); assertNotNull(timeMetadata); assertEquals("2012-04-01T00:00:00.000Z", reader.getMetadataValue(coverageName, "TIME_DOMAIN_MINIMUM")); assertEquals("2012-04-01T01:00:00.000Z", reader.getMetadataValue(coverageName, "TIME_DOMAIN_MAXIMUM")); assertEquals("true", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN")); final String elevationMetadata = reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN"); assertNotNull(elevationMetadata); assertEquals("10.0/10.0,450.0/450.0", elevationMetadata); assertEquals(2, elevationMetadata.split(",").length); assertEquals("10.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MINIMUM")); assertEquals("450.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MAXIMUM")); // subsetting the envelope final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName); final GeneralEnvelope reducedEnvelope = new GeneralEnvelope( new double[] { originalEnvelope.getLowerCorner().getOrdinate(0), originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] { originalEnvelope.getMedian().getOrdinate(0), originalEnvelope.getMedian().getOrdinate(1) }); reducedEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem(coverageName)); // Selecting bigger gridRange for a zoomed result final Dimension dim = new Dimension(); GridEnvelope gridRange = reader.getOriginalGridRange(coverageName); dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0); final Rectangle rasterArea = ((GridEnvelope2D) gridRange); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, reducedEnvelope)); final ParameterValue<Filter> filterParam = NetCDFFormat.FILTER.createValue(); FilterFactory2 FF = FeatureUtilities.DEFAULT_FILTER_FACTORY; Filter filter = FF.equals(FF.property("z"), FF.literal(450.0)); filterParam.setValue(filter); GeneralParameterValue[] values = new GeneralParameterValue[] { filterParam }; GridCoverage2D coverage = reader.read(coverageName, values); assertNotNull(coverage); if (TestData.isInteractiveTest()) { coverage.show(); } else { PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } } } catch (Throwable t) { throw new RuntimeException(t); } finally { if (reader != null) { try { reader.dispose(); } catch (Throwable t) { // Does nothing } } } }
From source file:org.geotools.coverage.io.netcdf.NetCDFReaderTest.java
@Test public void NetCDFTestAscatL1() throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException { File mosaic = new File(TestData.file(this, "."), "NetCDFTestAscatL1"); if (mosaic.exists()) { FileUtils.deleteDirectory(mosaic); }//w ww. j a v a 2s .c o m assertTrue(mosaic.mkdirs()); File file = TestData.file(this, "ascatl1.nc"); FileUtils.copyFileToDirectory(file, mosaic); file = new File(mosaic, "ascatl1.nc"); final Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true)); hints.add(new Hints(Utils.EXCLUDE_MOSAIC, true)); // Get format final AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints); final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints); assertNotNull(format); try { String[] names = reader.getGridCoverageNames(); names = new String[] { names[1] }; for (String coverageName : names) { final String[] metadataNames = reader.getMetadataNames(coverageName); assertNotNull(metadataNames); assertEquals(17, metadataNames.length); // Parsing metadata values assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN")); assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN")); assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NUMSIGMA_DOMAIN")); final String sigmaMetadata = reader.getMetadataValue(coverageName, "NUMSIGMA_DOMAIN"); assertNotNull(sigmaMetadata); assertEquals("0,1,2", sigmaMetadata); assertEquals(3, sigmaMetadata.split(",").length); // subsetting the envelope final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName); final GeneralEnvelope reducedEnvelope = new GeneralEnvelope( new double[] { originalEnvelope.getLowerCorner().getOrdinate(0), originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] { originalEnvelope.getMedian().getOrdinate(0), originalEnvelope.getMedian().getOrdinate(1) }); reducedEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem(coverageName)); // Selecting bigger gridRange for a zoomed result final Dimension dim = new Dimension(); GridEnvelope gridRange = reader.getOriginalGridRange(coverageName); dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0); final Rectangle rasterArea = ((GridEnvelope2D) gridRange); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, reducedEnvelope)); ParameterValue<List<String>> sigmaValue = null; final String selectedSigma = "1"; Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName); for (ParameterDescriptor param : params) { if (param.getName().getCode().equalsIgnoreCase("NUMSIGMA")) { sigmaValue = param.createValue(); sigmaValue.setValue(new ArrayList<String>() { { add(selectedSigma); } }); } } GeneralParameterValue[] values = new GeneralParameterValue[] { gg, sigmaValue }; GridCoverage2D coverage = reader.read(coverageName, values); assertNotNull(coverage); if (TestData.isInteractiveTest()) { coverage.show(); } else { PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } } } catch (Throwable t) { throw new RuntimeException(t); } finally { if (reader != null) { try { reader.dispose(); } catch (Throwable t) { // Does nothing } } } }
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);/* www . jav a2s . c om*/ /* * 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:org.geotools.coverage.io.netcdf.NetCDFReaderTest.java
@Test public void NetCDFTestOn4DcoveragesWithDifferentSchemas() throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException { File mosaic = new File(TestData.file(this, "."), "NetCDFTestOn4DcoveragesWithDifferentSchemas"); if (mosaic.exists()) { FileUtils.deleteDirectory(mosaic); }//w w w .ja v a 2 s. c o m assertTrue(mosaic.mkdirs()); File file = TestData.file(this, "O3-NO2-noZ.nc"); FileUtils.copyFileToDirectory(file, mosaic); file = new File(mosaic, "O3-NO2-noZ.nc"); final Hints hints = new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true)); // Get format final AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints); final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints); assertNotNull(format); try { String[] names = reader.getGridCoverageNames(); for (String coverageName : names) { final String[] metadataNames = reader.getMetadataNames(coverageName); assertNotNull(metadataNames); assertEquals(metadataNames.length, 12); // Parsing metadata values assertEquals("true", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN")); final String timeMetadata = reader.getMetadataValue(coverageName, "TIME_DOMAIN"); assertEquals( "2012-04-01T00:00:00.000Z/2012-04-01T00:00:00.000Z,2012-04-01T01:00:00.000Z/2012-04-01T01:00:00.000Z", timeMetadata); assertNotNull(timeMetadata); assertEquals("2012-04-01T00:00:00.000Z", reader.getMetadataValue(coverageName, "TIME_DOMAIN_MINIMUM")); assertEquals("2012-04-01T01:00:00.000Z", reader.getMetadataValue(coverageName, "TIME_DOMAIN_MAXIMUM")); if (coverageName.equalsIgnoreCase("O3")) { assertEquals("true", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN")); final String elevationMetadata = reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN"); assertNotNull(elevationMetadata); assertEquals("10.0/10.0,450.0/450.0", elevationMetadata); assertEquals(2, elevationMetadata.split(",").length); assertEquals("10.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MINIMUM")); assertEquals("450.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MAXIMUM")); } else { // Note that This sample doesn't have elevation for NO2 assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN")); final String elevationMetadata = reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN"); assertNull(elevationMetadata); } // subsetting the envelope final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue(); final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName); final GeneralEnvelope reducedEnvelope = new GeneralEnvelope( new double[] { originalEnvelope.getLowerCorner().getOrdinate(0), originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] { originalEnvelope.getMedian().getOrdinate(0), originalEnvelope.getMedian().getOrdinate(1) }); reducedEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem(coverageName)); // Selecting bigger gridRange for a zoomed result final Dimension dim = new Dimension(); GridEnvelope gridRange = reader.getOriginalGridRange(coverageName); dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0); final Rectangle rasterArea = ((GridEnvelope2D) gridRange); rasterArea.setSize(dim); final GridEnvelope2D range = new GridEnvelope2D(rasterArea); gg.setValue(new GridGeometry2D(range, reducedEnvelope)); 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("2012-04-01T00:00:00.000Z"); time.setValue(new ArrayList() { { add(timeD); } }); final ParameterValue<List> elevation = ImageMosaicFormat.ELEVATION.createValue(); elevation.setValue(new ArrayList() { { add(450d); // Elevation } }); GeneralParameterValue[] values = coverageName.equalsIgnoreCase("O3") ? new GeneralParameterValue[] { gg, time, elevation } : new GeneralParameterValue[] { gg, time }; GridCoverage2D coverage = reader.read(coverageName, values); assertNotNull(coverage); if (TestData.isInteractiveTest()) { coverage.show(); } else { PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles(); } } } catch (Throwable t) { throw new RuntimeException(t); } finally { if (reader != null) { try { reader.dispose(); } catch (Throwable t) { // Does nothing } } } }