All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pathomation.UI.UI Maven / Gradle / Ivy

Go to download

Universal viewing of digital microscopy, whole slide imaging and digital pathology data. pma-java is a Java wrapper library for PMA.start (http://www.free.pathomation.com), a universal viewer by Pathomation for whole slide imaging and microscopy. YOU NEED TO HAVE PMA.START (OR PMA.CORE) RUNNING IN ORDER TO USE THIS LIBRARY. PMA-JAVA IS NOT A STAND-ALONE LIBRARY FOR WSI.

There is a newer version: 2.0.0.118
Show newest version
package com.pathomation.UI;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.pathomation.Core;


/**
 * Wrapper around PMA.UI JavaScript framework
 * 
 * @author Yassine Iddaoui
 *
 */
public class UI {

	public static String pmaStartUIJavascriptPath = "http://localhost:54001/Scripts/pmaui/";
	public static String pmaUIJavascriptPath = "pma.ui/";
	public static boolean pmaUIFrameworkEmbedded = false;
	public static int pmaUIViewportCount = 0;
	public static List pmaUIViewports = new ArrayList<>();
	public static int pmaUIGalleryCount = 0;
	public static List pmaUIGalleries = new ArrayList<>();
	public static int pmaUILoaderCount = 0;
	public static List pmaUILoaders = new ArrayList<>();

	/**
	 * internal helper function to prevent PMA.UI framework from being loaded more
	 * than once
	 * 
	 * @param sessionID
	 *            session ID of the actual session
	 * @return The links related to JS & CSS files to be included
	 */
	public static String pmaEmbedPmaUIFramework(String sessionID) {
		if (!pmaUIFrameworkEmbedded) {
			if (!pmaStartUIJavascriptPath.endsWith("/")) {
				pmaUIJavascriptPath += "/";
			}
		}
		String htmlCode = "\n" + "\n" + "\n"
				+ "\n" + "\n" + "\n"
				+ "\n";
		// System.out.print("\n");
		// System.out.print(
		// "\n");
		// System.out.print(
		// "\n");
		// System.out.print("\n");
		// System.out.print("\n");
		// System.out.print("\n");
		// System.out.print(
		// "");
		pmaUIFrameworkEmbedded = true;
		return htmlCode;
	}

	/**
	 * output HTML code to display a single slide through a PMA.UI viewport control
	 * authentication against PMA.core happens through a pre-established
	 * 
	 * @param server
	 *            PMA.Start of PMA.core
	 * @param slideRef
	 *            path to the slide
	 * @param sessionID
	 *            session id of the actual session
	 * @param options
	 *            Map of the options defining the display of the view port
	 * @return
	 */
	public static List embedSlideBySessionID(String server, String slideRef, String sessionID,
			Map... varargs) {
		// setting the default value when argument's value is omitted
		Map options = varargs.length > 0 ? varargs[0] : null;
		// pmaEmbedPmaUIFramework(sessionID);
		pmaUIViewportCount++;
		String viewPortID = "pma_viewport" + pmaUIViewportCount;
		pmaUIViewports.add(viewPortID);
		String htmlCode = pmaEmbedPmaUIFramework(sessionID) + "
\n" + ""; List results = new ArrayList<>(); results.add(htmlCode); results.add(viewPortID); return results; // return htmlCode; // return viewPortID; } /** * output HTML code to display a single slide through a PMA.UI viewport control * authentication against PMA.core happens in real-time through the provided * $username and $password credentials Note that the username and password and * NOT rendered in the HTML output (authentication happens on the server-side). * * @param server * PMA.Start of PMA.core * @param slideRef * path to the slide * @param username * credentials' username * @param password * optional argument (String), default value set to empty string. it * defines the credentials' password * @param options * optional argument (Map of Strings) defining the display of the * view port * @return */ public static List embedSlideByUsername(String server, String slideRef, String username, Object... varargs) { // setting the default values when arguments' values are omitted String password = ""; Map options = null; if (varargs.length > 0) { if (!(varargs[0] instanceof String) && varargs[0] != null) { throw new IllegalArgumentException("..."); } password = (String) varargs[0]; } if (varargs.length > 1) { if (!(varargs[1] instanceof Map) && varargs[1] != null) { throw new IllegalArgumentException("..."); } options = (Map) varargs[1]; } String session = Core.connect(server, username, password); return embedSlideBySessionID(server, slideRef, session, options); } /** * output HTML code to display a gallery that shows all thumbnails that exist in * a specific folder hosted by the specified PMA.core instance authentication * against PMA.core happens through a pre-established SessionID * * @param server * PMA.Start of PMA.core * @param path * folder containing the slides * @param sessionID * session id of the actual session * @param options * Map of the options defining the display of the view port * @return */ public static List embedGalleryBySessionID(String server, String path, String sessionID, Map... varargs) { // setting the default value when argument's value is omitted Map options = varargs.length > 0 ? varargs[0] : null; pmaUIGalleryCount++; String galleryID = "pma_gallery" + pmaUIGalleryCount; pmaUIGalleries.add(galleryID); String htmlCode = pmaEmbedPmaUIFramework(sessionID) + "
\n" + ""; List results = new ArrayList<>(); results.add(htmlCode); results.add(galleryID); return results; } /** * output HTML code to display a gallery that shows all thumbnails that exist in * a specific folder hosted by the specified PMA.core instance authentication * against PMA.core happens in real-time through the provided $username and * $password credentials Note that the username and password are NOT rendered in * the HTML output (authentication happens on the server-side). * @param server * PMA.Start of PMA.core * * @param path * folder containing the slides * @param username * credentials' username * @param password * optional argument (String), default value set to empty string. it * defines the credentials' password * @param options * optional argument (Map of Strings) defining the display of the * view port * @return */ public static List embedGalleryByUsername(String server, String path, String username, Object... varargs) { // setting the default values when arguments' values are omitted String password = ""; Map options = null; if (varargs.length > 0) { if (!(varargs[0] instanceof String) && varargs[0] != null) { throw new IllegalArgumentException("..."); } password = (String) varargs[0]; } if (varargs.length > 1) { if (!(varargs[1] instanceof Map) && varargs[1] != null) { throw new IllegalArgumentException("..."); } options = (Map) varargs[1]; } String session = Core.connect(server, username, password); return embedGalleryBySessionID(server, path, session, options); } /** * output HTML code to couple an earlier instantiated PMA.UI gallery to a PMA.UI * viewport. The PMA.UI viewport can be instantiated earlier, or not at all * * @param galleryDiv * HTML Div holding the gallery * @param viewportDiv * HTML Div holding the viewport * @return * @throws Exception */ public static String linkGalleryToViewport(String galleryDiv, String viewportDiv) throws Exception { // verify the validity of the galleryDiv argument if (pmaUIViewports.contains(galleryDiv)) { throw new Exception( "galleryDiv is not a PMA.UI gallery (it's actually a viewport; did you switch the arguments up?)"); } if (!pmaUIGalleries.contains(galleryDiv)) { throw new Exception("galleryDiv is not a valid PMA.UI gallery container"); } // verify the validity of the $viewportDiv argument if (pmaUIGalleries.contains(viewportDiv)) { throw new Exception( "viewportDiv is not a PMA.UI viewport (it's actually a gallery; did you switch the arguments up?)"); } pmaUILoaderCount++; String loaderID = "pma_slideLoader" + pmaUILoaderCount; pmaUILoaders.add(loaderID); String htmlCode = ""; if (!pmaUIViewports.contains(viewportDiv)) { // viewport container doesn't yet exist, but this doesn't have to be a // showstopper; just create it on the fly pmaUIViewports.add(viewportDiv); pmaUIViewportCount++; htmlCode = "
\n"; } htmlCode += ""; return htmlCode; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy