Index: /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java	(revision 38889)
+++ /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java	(revision 38890)
@@ -1,7 +1,11 @@
 package org.greenstone.applet.GsdlCollageApplet;
+
+import org.webswing.toolkit.api.WebswingUtil;
 
 //import java.applet.Applet;
 import javax.swing.JApplet;
-//import javax.swing.SwingUtilities;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
@@ -33,11 +37,4 @@
     private int Y_DIM = 300;
 
-    public int X_DIM() {
-	return X_DIM;
-    }
-    public int Y_DIM() {
-	return Y_DIM;
-    }
-
     // To run this GsdlCollageApplet as Application instead of as Applet
     boolean isWebswingApplication = false; // if run as webswing *and* application (not applet)
@@ -99,5 +96,13 @@
 
    
-
+    /** Gets the set, calculated or default width (x dimension) of the applet/application */
+    public int X_DIM() {
+	return X_DIM;
+    }
+    /** Gets the set, calculated or default height (y dimension) of the applet/application */
+    public int Y_DIM() {
+	return Y_DIM;
+    }
+    
     /** Gets verbosity */
     public int verbosity()    { return verbosity_; }
@@ -152,4 +157,5 @@
 	//}
 
+	this.addMouseListener(new CollageMouseAdapter());
     }
 
@@ -432,18 +438,4 @@
 		    image_url = image_url + classifierSuffix;
 		}
-
-		/*
-		if(library != null && site != null && collection_param != null) {
-		    String gs3CollImgPath = library + "/sites/" + site + "/collect/" + collection_param;
-		    if(href_musthave == null) {
-		    	href_musthave = gs3CollImgPath;
-		    } else {
-			href_musthave += "%" + gs3CollImgPath;
-		    }		   
-		    if(verbosity_ >= 3) {
-			System.err.println("href_musthave includes gs3CollImgPath: " + gs3CollImgPath);
-		    }
-		}
-		*/
 	    }
 	}
@@ -466,12 +458,19 @@
 	return this.statusBar;
     }
-    
+
+    protected class CollageMouseAdapter extends MouseAdapter {
  
     /** Goes to the url associated with the image that is clicked on screen<br>
      *  Displays the url containing the image in a new window */
-    public boolean mouseDown(Event event, int x, int y)
+    //public boolean mouseDown(Event event, int x, int y)
+    public void mousePressed(MouseEvent e)
     {
+
+	System.err.println("Mouse pressed");
+	int x = e.getX();
+	int y = e.getY();
+	
 	// determines which image was clicked on
-	CollageImage cimage = display_thread_.clickedOnImage(x,y);
+	CollageImage cimage = GsdlCollageApplet.this.display_thread_.clickedOnImage(x,y);
 	// if they were clicking on an image (as opposed to background)
 	if (cimage != null)
@@ -491,12 +490,24 @@
 		    from_url =  new URL(cimage.from_url_  + "#" + cimage.name_);
 		}
-		getAppletContext().showDocument(from_url,"gsdlDoc");
+
+		if(isRunAsApplet) {
+		    GsdlCollageApplet.this.getAppletContext().showDocument(from_url,"gsdlDoc");
+		} else if(isWebswingApplication) {
+		    WebswingUtil.getWebswingApi().sendActionEvent("openURL",
+					  from_url.toString() + " - " +"gsdlDoc",
+					  null); // window name is gsdlDoc		    
+		} else {
+		    System.err.println("@@@GsdlCollageApplet.CollageMouseAdapter.mousePressed()"
+		       + "\n\topening url " + from_url + "\n\t"
+		       + "for non-applet and non-webswing application is not yet implemented.");
+		}
 	    } 
-	    catch (MalformedURLException e) { 
-		e.printStackTrace();
-	    }
-
-	}
-        return true;
+	    catch (MalformedURLException ex) { 
+		ex.printStackTrace();
+	    }
+
+	}
+        //return true;
+    }
     }
     
@@ -662,4 +673,5 @@
 	    // It's now figured out the dimensions based on anything specified, so set frame size
 	    frame.setSize(collageApp.X_DIM(), collageApp.Y_DIM()); //Y_DIM+EXTRA_HEIGHT);
+	    
 	    // status bar code. Not ideal, but had to add it here to get relative dimensions right
 	    collageApp.setLayout(new BorderLayout());
Index: /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/MyAffineTransform.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/MyAffineTransform.java	(revision 38889)
+++ /main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/MyAffineTransform.java	(revision 38890)
@@ -21,4 +21,11 @@
 
 	double scale_factor = 1.0;
+
+	//to avoid attempting to divide by 0
+	// TODO: Why is it even 0? I had initialised app_x/y_dim_ with fallback to ensure non-0
+	// Hard to debug, as I've seen it happen only once.
+	//if(DisplayImages.app_x_dim_ == 0 || DisplayImages.app_y_dim_ == 0) {
+	//    return scale_factor;
+	//}
 
 	// three quarters of the application width & height
Index: /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-collage.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-collage.xsl	(revision 38889)
+++ /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-collage.xsl	(revision 38890)
@@ -120,8 +120,11 @@
 	          var url = data;
 		  // check if a target tab/window name has been specified
-		  // Any better way of passing more than 1 string between Java and JavaScript?
+		  // TODO: Any better way of passing > 1 string between Java and JavaScript?
 		  var index = url.indexOf(" - ");
 		  if (index !== -1) {
 		     var target = url.substring(index+3); // skip past " - " to get target name
+		     url = url.substring(0, index);
+		     // Note that target window name is not the same as target window title
+		     // https://stackoverflow.com/questions/8051811/how-to-show-window-title-using-window-open
 		     window.open(url, target);	             
 		  } else {
Index: /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl	(revision 38889)
+++ /main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl	(revision 38890)
@@ -119,8 +119,9 @@
 	          var url = data;
 		  // check if a target tab/window name has been specified
-		  // Any better way of passing more than 1 string between Java and JavaScript?
+		  // TODO: Any better way of passing > 1 string between Java and JavaScript?
 		  var index = url.indexOf(" - ");
 		  if (index !== -1) {
 		     var target = url.substring(index+3); // skip past " - " to get target name
+		     url = url.substring(0, index);
 		     window.open(url, target);	             
 		  } else {
