protected static Product createTestProduct(String name, String type) { Product product = new Product(name, type, 10, 10); product.setFileLocation(new File(String.format("out/%s.dim", name))); return product; }
@Override protected void onApply() { if (!canApply()) { return; } TargetProductSelectorModel model = targetProductSelector.getModel(); String productDirPath = model.getProductDir().getAbsolutePath(); appContext.getPreferences().setPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, productDirPath); Product targetProduct = null; try { long t0 = System.currentTimeMillis(); targetProduct = createTargetProduct(); createTargetProductTime = System.currentTimeMillis() - t0; } catch (Throwable t) { handleInitialisationError(t); return; } if (targetProduct == null) { throw new NullPointerException("The target product is null."); } targetProduct.setName(model.getProductName()); targetProduct.setFileLocation(model.getProductFile()); GRMProductWriterSwingWorker worker = new GRMProductWriterSwingWorker(targetProduct); worker.executeWithBlocking(); // start the thread }
public Product open(final File inputFile) throws IOException { product = geoTiffReader.readProductNodes(inputFile, null); product.setFileLocation(inputFile); addAuxXML(product); addExtraBands(inputFile, product); product.setStartTime(getStartTime(product)); product.setEndTime(getEndTime(product)); return product; } private String getTime(final Product product, final String tag){
private Product createComplexProduct(final File inputFile, final Header header, final int bandType) throws IOException { final int width = header.getNumSamples(); final int height = header.getNumLines(); final Product product = new Product(inputFile.getName(), "RAT", width, height); product.setProductReader(this); product.setFileLocation(inputFile); product.setDescription(header.getDescription()); product.getMetadataRoot().addElement(header.getAsMetadata()); initGeoCoding(product, header); applyBeamProperties(product, header.getBeamProperties()); final Band tgtBandI = new Band("i_band", bandType, width, height); tgtBandI.setUnit("real"); product.addBand(tgtBandI); final Band tgtBandQ = new Band("q_band", ProductData.TYPE_FLOAT32, width, height); tgtBandQ.setUnit("imaginary"); product.addBand(tgtBandQ); ReaderUtils.createVirtualIntensityBand(product, tgtBandI, tgtBandQ, "_band"); isComplex = true; String ratFilePath = inputFile.getPath().substring(0, inputFile.getPath().length()-4); inStream = new FileImageInputStream(new File(ratFilePath)); inStream.setByteOrder(header.getJavaByteOrder()); return product; }
protected Product readProductNodesImpl() throws IOException { final File inputFile = ReaderUtils.getFileFromInput(getInput()); inStream = new FileImageInputStream(inputFile); inStream.setByteOrder(ByteOrder.LITTLE_ENDIAN); readHeader(); final Product product = new Product(inputFile.getName(), "SunRaster", width, height); product.setProductReader(this); product.setFileLocation(inputFile); final Band band = new Band("data", ProductData.TYPE_FLOAT32, width, height); band.setUnit(Unit.AMPLITUDE); product.addBand(band); return product; }
private Product createComplexProduct(final File inputFile, final Header header, final int bandType) throws IOException { final int width = header.getNumSamples(); final int height = header.getNumLines(); final Product product = new Product(inputFile.getName(), "RAT", width, height); product.setProductReader(this); product.setFileLocation(inputFile); product.setDescription(header.getDescription()); product.getMetadataRoot().addElement(header.getAsMetadata()); initGeoCoding(product, header); applyBeamProperties(product, header.getBeamProperties()); final Band tgtBandI = new Band("i_band", bandType, width, height); tgtBandI.setUnit("real"); product.addBand(tgtBandI); final Band tgtBandQ = new Band("q_band", bandType, width, height); tgtBandQ.setUnit("imaginary"); product.addBand(tgtBandQ); ReaderUtils.createVirtualIntensityBand(product, tgtBandI, tgtBandQ, "_band"); isComplex = true; String ratFilePath = inputFile.getPath().substring(0, inputFile.getPath().length()-4); inStream = new FileImageInputStream(new File(ratFilePath)); inStream.setByteOrder(header.getJavaByteOrder()); return product; }
product.setFileLocation(fileFromInput); product.setProductReader(this);
@Before public void setup() { Product product = new Product("P", "T", 10, 10); product.setFileLocation(new File(String.format("out/%s.dim", product.getName()))); band = new VirtualBand("V", ProductData.TYPE_INT32, 10, 10, "42"); product.addBand(band); productManager = new ProductManager(); productManager.addProduct(product); }
@Override public void initialize() throws OperatorException { try { final ProductEntry[] entryList = DBSearch.search(sourceProduct, 1, minMJD, maxMJD); if (entryList.length > 0) { final File file = entryList[0].getFile(); final Product targetProduct = CommonReaders.readProduct(file); this.productReader = targetProduct.getProductReader(); targetProduct.setFileLocation(file); super.setTargetProduct(targetProduct); updateMetadata(); } else { throw new OperatorException("No image pair found in database"); } } catch (Exception e) { throw new OperatorException(e); } }
/** * Provides an implementation of the <code>readProductNodes</code> interface method. Clients implementing this * method can be sure that the input object and eventually the subset information has already been set. * <p> * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code> method. * * @throws IOException if an I/O error occurs */ @Override protected Product readProductNodesImpl() throws IOException { try { File fileFromInput = ReaderUtils.getFileFromInput(getInput()); if (fileFromInput.isDirectory()) { fileFromInput = RCMProductReaderPlugIn.findMetadataFile(fileFromInput); } dataDir = createDirectory(fileFromInput); dataDir.readProductDirectory(); final Product product = dataDir.createProduct(); product.getGcpGroup(); product.setFileLocation(fileFromInput); product.setProductReader(this); addQuicklook(product, Quicklook.DEFAULT_QUICKLOOK_NAME, getQuicklookFile()); return product; } catch (Exception e) { handleReaderException(e); } return null; }
product.setFileLocation(fileFromInput); product.setProductReader(this);
@Before public void setUp() throws Exception { targetUI = new TargetUI(); appContext = new MockAppContext(); final File path = GlobalTestConfig.getBeamTestDataOutputDirectory(); defaultProducts = new Product[2]; for (int i = 0; i < defaultProducts.length; i++) { Product prod = new Product("P" + i, "T" + i, 10, 10); prod.setFileLocation(path); appContext.getProductManager().addProduct(prod); defaultProducts[i] = prod; } }
@Before public void setUp() throws Exception { sourceUI = new SourceUI(); appContext = new MockAppContext(); final File path = GlobalTestConfig.getBeamTestDataOutputDirectory(); defaultProducts = new Product[2]; for (int i = 0; i < defaultProducts.length; i++) { Product prod = new Product("P" + i, "T" + i, 10, 10); prod.setFileLocation(path); appContext.getProductManager().addProduct(prod); defaultProducts[i] = prod; } }
/** * Provides an implementation of the <code>readProductNodes</code> interface method. Clients implementing this * method can be sure that the input object and eventually the subset information has already been set. * <p> * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code> method. * * @throws java.io.IOException if an I/O error occurs */ @Override protected Product readProductNodesImpl() throws IOException { final File inputFile = ReaderUtils.getFileFromInput(getInput()); final File annFile = findAnnotationFile(inputFile); final MetadataElement annElem = readAnnotation(annFile); getProductType(inputFile); getDimensions(annElem); final Product product = new Product(FileUtils.getFilenameWithoutExtension(annFile), productTypeStr, rasterWidth, rasterHeight); addBands(inputFile.getParentFile(), product); addMetaData(product, annElem); final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product); ReaderUtils.addGeoCoding(product, getLatCorners(absRoot), getLonCorners(absRoot)); product.setProductReader(this); product.setFileLocation(inputFile); setQuicklookBandName(product); product.setModified(false); return product; }
/** * Provides an implementation of the <code>readProductNodes</code> interface method. Clients implementing this * method can be sure that the input object and eventually the subset information has already been set. * <p> * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code> method. * * @throws IOException if an I/O error occurs */ @Override protected Product readProductNodesImpl() throws IOException { try { final File fileFromInput = ReaderUtils.getFileFromInput(getInput()); dataDir = createDirectory(fileFromInput); dataDir.readProductDirectory(); final Product product = dataDir.createProduct(); final MetadataElement absMeta = AbstractMetadata.getAbstractedMetadata(product); product.getGcpGroup(); product.setFileLocation(fileFromInput); product.setProductReader(this); setQuicklookBandName(product); addQuicklook(product, Quicklook.DEFAULT_QUICKLOOK_NAME, getQuicklookFile()); return product; } catch (Exception e) { handleReaderException(e); } return null; }
/** * Provides an implementation of the <code>readProductNodes</code> interface method. Clients implementing this * method can be sure that the input object and eventually the subset information has already been set. * <p/> * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code> method. * * @throws java.io.IOException if an I/O error occurs */ @Override protected Product readProductNodesImpl() throws IOException { final File inputFile = ReaderUtils.getFileFromInput(getInput()); productDir = createProductDir(inputFile); Product product = null; try { dataDir = createProductDirectory(productDir); dataDir.readProductDirectory(); product = dataDir.createProduct(); product.setFileLocation(inputFile); setQuicklookBandName(product); addQuicklooks(product, productDir); product.getGcpGroup(); product.setProductReader(this); product.setModified(false); } catch (Exception e) { handleReaderException(e); } return product; }
@Test public void testNewProductIsDisposed() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); Product newProduct = new Product("new", "T1", 0, 0); newProduct.setFileLocation(new File("")); selector.setSelectedProduct(newProduct); assertSame(newProduct, selector.getSelectedProduct()); selector.setSelectedProduct(defaultProducts[0]); assertSame(defaultProducts[0], selector.getSelectedProduct()); Assert.assertNotNull(newProduct.getFileLocation()); selector.releaseProducts(); Assert.assertNull(newProduct.getFileLocation()); // assert that new product is disposed, because it is not selected }
@Test public void testNewProductIsNotDisposed() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); selector.setSelectedProduct(defaultProducts[0]); assertSame(defaultProducts[0], selector.getSelectedProduct()); Product newProduct = new Product("new", "T1", 0, 0); newProduct.setFileLocation(new File("")); selector.setSelectedProduct(newProduct); assertSame(newProduct, selector.getSelectedProduct()); Assert.assertNotNull(newProduct.getFileLocation()); selector.releaseProducts(); Assert.assertNotNull(newProduct.getFileLocation()); // assert that new product is not disposed while it is selected }
@Override public Product createProduct() throws IOException { final MetadataElement newRoot = addMetaData(); addBinaryDataToProduct(newRoot); findImages(newRoot); final MetadataElement absRoot = newRoot.getElement(AbstractMetadata.ABSTRACT_METADATA_ROOT); final int sceneWidth = absRoot.getAttributeInt(AbstractMetadata.num_samples_per_line); final int sceneHeight = absRoot.getAttributeInt(AbstractMetadata.num_output_lines); final Product product = new Product(getProductName(), getProductType(), sceneWidth, sceneHeight); updateProduct(product, newRoot); addTiePointGrids(product); // empty addBands(product); addGeoCoding(product); product.setName(getProductName()); product.setProductType(getProductType()); product.setDescription(getProductDescription()); product.setFileLocation(getBaseDir()); ReaderUtils.addMetadataProductSize(product); return product; } }
@Test public void testSetSelectedProduct() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); Product selectedProduct = selector.getSelectedProduct(); assertSame(appContext.getSelectedProduct(), selectedProduct); selector.setSelectedProduct(defaultProducts[1]); selectedProduct = selector.getSelectedProduct(); assertSame(defaultProducts[1], selectedProduct); Product oldProduct = new Product("new", "T1", 0, 0); oldProduct.setFileLocation(new File("")); selector.setSelectedProduct(oldProduct); selectedProduct = selector.getSelectedProduct(); assertSame(oldProduct, selectedProduct); Product newProduct = new Product("new", "T2", 0, 0); selector.setSelectedProduct(newProduct); selectedProduct = selector.getSelectedProduct(); assertSame(newProduct, selectedProduct); Assert.assertNull(oldProduct.getFileLocation()); // assert that old product is disposed }