/*
 * #%L
 * SCIFIO tutorials for core and plugin use.
 * %%
 * Copyright (C) 2011 - 2013 Open Microscopy Environment:
 * 	- Board of Regents of the University of Wisconsin-Madison
 * 	- Glencoe Software, Inc.
 * 	- University of Dundee
 * %%
 * To the extent possible under law, the SCIFIO developers have waived
 * all copyright and related or neighboring rights to this tutorial code.
 * 
 * See the CC0 1.0 Universal license for details:
 * http://creativecommons.org/publicdomain/zero/1.0/
 * #L%
 */

package io.scif.tutorials;

import io.scif.Checker;
import io.scif.Format;
import io.scif.FormatException;
import io.scif.Metadata;
import io.scif.Parser;
import io.scif.Reader;
import io.scif.SCIFIO;

import java.io.IOException;

/**
 * Demonstrates how individual components can be used together instead of the
 * convenience method in IntroToSCIFIO
 * 
 * @author Mark Hiner
 */
public class T2aUntypedComponents {

	public static void main(final String... args) throws FormatException,
		IOException
	{
		// In IntroToSCIFIO we used a convenience method to obtain an initialized
		// reader. This glossed over the individual steps of opening an image, which
		// can also be accomplished manually through the SCIFIO components.

		// As always, we create a context and sample image path first
		final SCIFIO scifio = new SCIFIO();
		final String sampleImage =
			"8bit-signed&pixelType=int8&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake";

		// This time we'll get a handle on the Format itself, which will allow us
		// to create the additional components.
		final Format format = scifio.format().getFormat(sampleImage);

		// If we had been given a Format instead of the context, we can manually
		// check it's compatibility through a Checker component.
		final Checker checker = format.createChecker();
		System.out.println("Is compatibile: " + checker.isFormat(sampleImage));

		// Typically the first thing we want to do, after confirming we have a
		// Format that can support an image, is parse the Metadata of that image
		final Parser parser = format.createParser();
		final Metadata meta = parser.parse(sampleImage);

		// Metadata is used by other components, such as Readers, Writers, and
		// Translators
		// to open, save, and convert - respectively - image information. Assuming
		// we're
		// going to open an image, we'll need to initialize a reader now.
		Reader reader = format.createReader();

		// Tells the reader which metadata object to use while reading
		reader.setMetadata(meta);

		// Tells the reader which image source to read from
		reader.setSource(sampleImage);

		// It is important to note that by using components all originating from
		// a single Format instance, we can be sure that these components are
		// compatible with each other.
		// A method that accepted multiple individual components and expected them
		// to be compatible may not be particularly useful. But note that it would
		// also be unnecessary - any component can find its parent Format:

		// both of these paths lead to the same Format, and will create a Reader
		// capable of reading the parsed Metadata
		reader = parser.getFormat().createReader();
		reader =
			scifio.format().getFormatFromParser(parser.getClass()).createReader();

		// Unlike Formats within each context, component are never singletons and
		// thus we must re-initialize the reader.
		reader.setMetadata(meta);
		reader.setSource(sampleImage);

		// At this point we've caught up to the IntroToSCIFIO, and could begin
		// opening planes with our reader.
	}
}

@@ -851,16 +851,17 @@
 ToSCIFIO
+.
 %0A * %0A * 
@@ -1297,16 +1297,17 @@
 th first
+.
 %0A%09%09final
@@ -1838,17 +1838,16 @@
 compatib
-i
 le: %22 + 
@@ -2026,16 +2026,17 @@
 at image
+.
 %0A%09%09final
@@ -2216,21 +2216,16 @@
 nslators
-%0A%09%09//
  to open
@@ -2245,16 +2245,17 @@
 onvert -
+-
  respect
@@ -2261,22 +2261,28 @@
 tively -
+-
  image
+%0A%09%09//
  informa
@@ -2299,24 +2299,14 @@
 ming
-%0A%09%09//
  we're
-%0A%09%09//
  goi
@@ -2339,16 +2339,21 @@
  need to
+%0A%09%09//
  initial
@@ -2476,16 +2476,17 @@
  reading
+.
 %0A%09%09reade
@@ -2560,16 +2560,17 @@
 ead from
+.
 %0A%09%09reade
@@ -2956,16 +2956,17 @@
 essary -
+-
  any com
@@ -3006,17 +3006,17 @@
 :%0A%0A%09%09// 
-b
+B
 oth of t
@@ -3119,16 +3119,17 @@
 Metadata
+.
 %0A%09%09reade

clean up javadoc a little