package org.eclipse.dawnsci.remotedataset.client.dyn;

import java.awt.image.BufferedImage;

import org.eclipse.dawnsci.remotedataset.client.slice.DynamicConnectionInfoExt;
import org.eclipse.dawnsci.remotedataset.client.slice.SliceClient;

/**
 * DO NOT USE THIS CLASS FOR API. 
 * 
 * Instead if you need an MJPG Dataset use:
 * 
 * IRemoteDatasetService service = ... // OSGi
 * IRemoteDataset rgb = service.createMJPGDataset(...)
 * 
 * then plot RGB
 * 
 * @author Matthew Gerring
 *
 */
public class DynamicDatasetFactory {

	/**
	 * 
	 * @param client
	 * @param shape
	 * @return
	 */
	public static IDynamicMonitorDatasetHolder createGreyScaleImage(SliceClient<BufferedImage> client, int... shape) {
		DynamicImage ret = new DynamicImage(false, client, shape);
		prepare(ret, client);
		return ret;
	}
	
	/**
	 * 
	 * @param client
	 * @param shape
	 * @return
	 */
	public static IDynamicMonitorDatasetHolder createRGBImage(SliceClient<BufferedImage> client, int... shape) {
		DynamicImage ret = new DynamicImage(true, client, shape);
		prepare(ret, client);
		return ret;
	}

	private static void prepare(IDynamicMonitorDatasetHolder ret, SliceClient<BufferedImage> client) {
		ret.getDataset().addMetadata(new DynamicConnectionInfoExt(client));
	}
}


@@ -1180,16 +1180,344 @@
 ient) %7B%0A
+%09%09if (ret.getDataset() != null) %7B%0A%09%09%09// We check that there is something to prepare and throw an exception suggesting what may be wrong%0A%09%09%09if (ret.getDataset().getShape() == null %7C%7C ret.getDataset().getShape().length == 0) %7B%0A%09%09%09%09throw new IllegalArgumentException(%22There is no data to prepare, is the device turned on?%22);%0A%09%09%09%7D%0A%09
 %09%09ret.ge
@@ -1578,14 +1578,18 @@
 ient));%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A%0A

Improve error handling to account for if there is no data to prepare and the possibility that a device is not switched