Changeset 38890


Ignore:
Timestamp:
2024-03-29T22:29:25+13:00 (4 weeks ago)
Author:
anupama
Message:
  1. Got rid of one deprecated warning: replaced deprecated Applet.mouseDown() with registering a MouseListner (MouseAdapter) and implementing its mouseDown-equivalent mousePressed(). 2. The old mouseDown wasn't opening a clicked image in new windows, and opening an image is expected behaviour I found. With the new method at least, this now works. 3. Fixed up the webswing-phind/-collage.xsl files to correctly work out the URL to open in a new browser tab. It used to leave the tab target name appended. It still opened the image in firefox, but we couldn't have relied on this. Other browsers or future browser versions may have not opened the image because the url string wasn't just right but contained an unnecessary string at the end.
Location:
main/trunk/greenstone3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java

    r38889 r38890  
    11package org.greenstone.applet.GsdlCollageApplet;
     2
     3import org.webswing.toolkit.api.WebswingUtil;
    24
    35//import java.applet.Applet;
    46import javax.swing.JApplet;
    5 //import javax.swing.SwingUtilities;
     7import java.awt.event.MouseAdapter;
     8import java.awt.event.MouseEvent;
     9import java.awt.event.MouseListener;
    610import java.awt.event.WindowAdapter;
    711import java.awt.event.WindowEvent;
     
    3337    private int Y_DIM = 300;
    3438
    35     public int X_DIM() {
    36     return X_DIM;
    37     }
    38     public int Y_DIM() {
    39     return Y_DIM;
    40     }
    41 
    4239    // To run this GsdlCollageApplet as Application instead of as Applet
    4340    boolean isWebswingApplication = false; // if run as webswing *and* application (not applet)
     
    9996
    10097   
    101 
     98    /** Gets the set, calculated or default width (x dimension) of the applet/application */
     99    public int X_DIM() {
     100    return X_DIM;
     101    }
     102    /** Gets the set, calculated or default height (y dimension) of the applet/application */
     103    public int Y_DIM() {
     104    return Y_DIM;
     105    }
     106   
    102107    /** Gets verbosity */
    103108    public int verbosity()    { return verbosity_; }
     
    152157    //}
    153158
     159    this.addMouseListener(new CollageMouseAdapter());
    154160    }
    155161
     
    432438            image_url = image_url + classifierSuffix;
    433439        }
    434 
    435         /*
    436         if(library != null && site != null && collection_param != null) {
    437             String gs3CollImgPath = library + "/sites/" + site + "/collect/" + collection_param;
    438             if(href_musthave == null) {
    439                 href_musthave = gs3CollImgPath;
    440             } else {
    441             href_musthave += "%" + gs3CollImgPath;
    442             }         
    443             if(verbosity_ >= 3) {
    444             System.err.println("href_musthave includes gs3CollImgPath: " + gs3CollImgPath);
    445             }
    446         }
    447         */
    448440        }
    449441    }
     
    466458    return this.statusBar;
    467459    }
    468    
     460
     461    protected class CollageMouseAdapter extends MouseAdapter {
    469462 
    470463    /** Goes to the url associated with the image that is clicked on screen<br>
    471464     *  Displays the url containing the image in a new window */
    472     public boolean mouseDown(Event event, int x, int y)
     465    //public boolean mouseDown(Event event, int x, int y)
     466    public void mousePressed(MouseEvent e)
    473467    {
     468
     469    System.err.println("Mouse pressed");
     470    int x = e.getX();
     471    int y = e.getY();
     472   
    474473    // determines which image was clicked on
    475     CollageImage cimage = display_thread_.clickedOnImage(x,y);
     474    CollageImage cimage = GsdlCollageApplet.this.display_thread_.clickedOnImage(x,y);
    476475    // if they were clicking on an image (as opposed to background)
    477476    if (cimage != null)
     
    491490            from_url =  new URL(cimage.from_url_  + "#" + cimage.name_);
    492491        }
    493         getAppletContext().showDocument(from_url,"gsdlDoc");
     492
     493        if(isRunAsApplet) {
     494            GsdlCollageApplet.this.getAppletContext().showDocument(from_url,"gsdlDoc");
     495        } else if(isWebswingApplication) {
     496            WebswingUtil.getWebswingApi().sendActionEvent("openURL",
     497                      from_url.toString() + " - " +"gsdlDoc",
     498                      null); // window name is gsdlDoc         
     499        } else {
     500            System.err.println("@@@GsdlCollageApplet.CollageMouseAdapter.mousePressed()"
     501               + "\n\topening url " + from_url + "\n\t"
     502               + "for non-applet and non-webswing application is not yet implemented.");
     503        }
    494504        }
    495         catch (MalformedURLException e) {
    496         e.printStackTrace();
    497         }
    498 
    499     }
    500         return true;
     505        catch (MalformedURLException ex) {
     506        ex.printStackTrace();
     507        }
     508
     509    }
     510        //return true;
     511    }
    501512    }
    502513   
     
    662673        // It's now figured out the dimensions based on anything specified, so set frame size
    663674        frame.setSize(collageApp.X_DIM(), collageApp.Y_DIM()); //Y_DIM+EXTRA_HEIGHT);
     675       
    664676        // status bar code. Not ideal, but had to add it here to get relative dimensions right
    665677        collageApp.setLayout(new BorderLayout());
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/MyAffineTransform.java

    r38853 r38890  
    2121
    2222    double scale_factor = 1.0;
     23
     24    //to avoid attempting to divide by 0
     25    // TODO: Why is it even 0? I had initialised app_x/y_dim_ with fallback to ensure non-0
     26    // Hard to debug, as I've seen it happen only once.
     27    //if(DisplayImages.app_x_dim_ == 0 || DisplayImages.app_y_dim_ == 0) {
     28    //    return scale_factor;
     29    //}
    2330
    2431    // three quarters of the application width & height
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-collage.xsl

    r38889 r38890  
    120120              var url = data;
    121121          // check if a target tab/window name has been specified
    122           // Any better way of passing more than 1 string between Java and JavaScript?
     122          // TODO: Any better way of passing > 1 string between Java and JavaScript?
    123123          var index = url.indexOf(" - ");
    124124          if (index !== -1) {
    125125             var target = url.substring(index+3); // skip past " - " to get target name
     126             url = url.substring(0, index);
     127             // Note that target window name is not the same as target window title
     128             // https://stackoverflow.com/questions/8051811/how-to-show-window-title-using-window-open
    126129             window.open(url, target);               
    127130          } else {
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl

    r38872 r38890  
    119119              var url = data;
    120120          // check if a target tab/window name has been specified
    121           // Any better way of passing more than 1 string between Java and JavaScript?
     121          // TODO: Any better way of passing > 1 string between Java and JavaScript?
    122122          var index = url.indexOf(" - ");
    123123          if (index !== -1) {
    124124             var target = url.substring(index+3); // skip past " - " to get target name
     125             url = url.substring(0, index);
    125126             window.open(url, target);               
    126127          } else {
Note: See TracChangeset for help on using the changeset viewer.