Changeset 38885


Ignore:
Timestamp:
2024-03-28T00:03:56+13:00 (8 weeks ago)
Author:
anupama
Message:
  1. Simplified collage applet parameters for GS3. TODO: Just noticed I can remove sitename as it's now only used for href_musthave, which I can set as an official collage applet parameter, so moving that out of the Java code will also reduce my unncessary code additions. 2. Got the status bar working at last, which was a great pain, as it mattered when it was added and where in the code to get the sizing right without overlapping with the collage display (or being obscured entirely by it). It had to be added in main. TODO: a param to hide the status bar as my new code to the collage applet may be the only one to use it, and I only added the showStatus messages to test it works.
Location:
main/trunk/greenstone3
Files:
5 edited

Legend:

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

    r38881 r38885  
    9292    super("DisplayImages");
    9393
    94     final int xDim_fallback = 600;
    95     final int yDim_fallback = 300;
    96    
    9794    // parameters saved locally
    9895    app_             = app;
     
    110107        //app_y_dim_  = (app_.getHeight() == 0) ? yDim_fallback : app_.getHeight();
    111108        app_x_dim_  = app_.getWidth();
    112         app_y_dim_  = app.getHeight();
     109        app_y_dim_  = app_.getHeight();
    113110
    114111        System.err.println("@@@ xDim: " + app_x_dim_);
     
    117114    else
    118115    {
    119         app_x_dim_  = xDim_fallback;
    120         app_y_dim_  = yDim_fallback;
     116        app_x_dim_  = app_.X_DIM;
     117        app_y_dim_  = app_.Y_DIM;
    121118    }
    122119
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/DownloadUrls.java

    r38871 r38885  
    2222public class DownloadUrls extends Thread {
    2323    // for GS3   
    24     String gs3CollImgPath = null;
    2524    String baseURL = null;
    2625   
     
    106105               "image_ignore_ "+  image_ignore+"\n"+
    107106               "image_type_ "+ image_type+"\n"+
    108                "document root "+ document_root_
     107               "document_root_ "+ document_root_
    109108                   );
    110109
     
    114113    }
    115114
    116     public void setupForGS3(String gs3CollImgPath, String baseURL)
    117     {
    118     this.gs3CollImgPath = gs3CollImgPath;
    119     this.baseURL = baseURL;
    120     }
    121  
    122115    /** Determines whether or not a url has already been examined
    123116     *
     
    431424
    432425    // connect to the url
    433     CURL curl = (app_.gsdlversion == 3) ? new CURL(new_url, this.baseURL) : new CURL(new_url);
     426    CURL curl = (app_.gsdlversion == 3) ? new CURL(new_url, app_.baseURL) : new CURL(new_url);
    434427
    435428    if (curl.connected_ok())
  • main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java

    r38881 r38885  
    33//import java.applet.Applet;
    44import javax.swing.JApplet;
     5//import javax.swing.SwingUtilities;
    56import java.awt.event.WindowAdapter;
    67import java.awt.event.WindowEvent;
     
    2829 
    2930public class GsdlCollageApplet extends JApplet {
     31    static final int EXTRA_HEIGHT = 30; // for status bar or any extra elements
     32    static final int X_DIM = 600;
     33    static final int Y_DIM = 300;
     34   
    3035    // To run this GsdlCollageApplet as Application instead of as Applet
    3136    boolean isWebswingApplication = false; // if run as webswing *and* application (not applet)
     
    3843    // package access, used mainly for GS3
    3944    int gsdlversion = 2;
    40     String site = null;
    41     String library = null;
    42     String collection = null;
    43     String gs3CollImgPath = null;
    4445    String baseURL = null;
    4546   
     
    118119    Thread paint ;
    119120
    120     public GsdlCollageApplet() { super(); }
    121 
    122     //public GsdlCollageApplet(String[] args) {
    123 
    124     //this.setPreferredSize(new Dimension(600, 300));
    125     //}
    126 
     121    public GsdlCollageApplet() {
     122
     123    super();
     124   
     125    // status bar that applet has, but we want one also if we run JPhind as application
     126    // And in fact, when webswing runs our applet, we never get a status bar. So we
     127    // create a custom status bar now even if we're running as an applet.
     128    // When this applet is run through the appletviewer we might end up with 2 status bars.
     129    //setLayout(new BorderLayout());
     130    //if(!isRunAsApplet) {
     131    statusBar = new JLabel();   
     132    //this.add(statusBar, BorderLayout.SOUTH);
     133    /*
     134    Window win = SwingUtilities.getWindowAncestor(this);
     135    if(win instanceof JFrame) {
     136        JFrame topFrame = (JFrame)win;
     137        topFrame.add(statusBar, BorderLayout.SOUTH);
     138    } else { //AppletViewer or browser
     139        this.add(statusBar, BorderLayout.SOUTH);
     140    }*/
     141   
     142    //Dimension d = statusBar.getSize();
     143    //d.height = EXTRA_HEIGHT;
     144    //statusBar.setPreferredSize(d);
     145    //}
     146
     147    }
    127148
    128149    public void applicationPreInit(String[] args) {
     
    131152    // instead of as applet
    132153    this.isRunAsApplet = false;
    133     try {
    134         this.docBaseURL = new URL(args[0]);     
    135     } catch(MalformedURLException mue) {       
    136         mue.printStackTrace();
    137         System.err.println("*** Unable to instantiate URL from parameter: " + args[0]);
    138         System.exit(-1);
    139     }
    140154
    141155    appParams = new HashMap<String,String>((args.length+1)/2);
     156    // For GS2, gwcgi = param gwcgi
     157    // For GS3, gwcgi = param gwcgi + param library
     158    //          docBaseURL = starting_url/image_url = param gwcgi
    142159
    143160    String key = null;
    144161    String value = null;
    145     for(int i = 1; i < args.length; i++) { // after arg0, have key-value pairs (params)
    146         if(i%2==1) {
     162    for(int i = 0; i < args.length; i++) {
     163        if(i%2==0) {
    147164        key = args[i].substring(2); // remove -- prefix of paramname
    148165        //System.err.println("got key: " + key);
     
    176193        }
    177194    }
    178 
     195   
    179196    isWebswingApplication = appParams.getOrDefault("webswing", "0").equals("1") ? true : false;
    180 
    181     // manually calling (J)Applet method init()
    182     init();
    183     start();
     197    try {
     198        this.docBaseURL = new URL(appParams.get("baseurl"));
     199    } catch(MalformedURLException mue) {       
     200        mue.printStackTrace();
     201        System.err.println("*** Unable to instantiate URL from parameter baseurl: " + appParams.get("baseurl"));
     202        System.exit(-1);
     203    }
     204   
    184205    }
    185206   
     
    240261    String caption_param        = getParameter("caption");
    241262        String document_root        = getParameter("documentroot");
    242         String gwcgi                = getParameter("gwcgi");
     263    String gwcgi                = getParameter("gwcgi");   // for GS2
     264    String baseurl              = getParameter("baseurl"); // for GS3, URL before /library
    243265   
    244266    String gsdlVersionStr = getParameter("gsdlversion");
     
    327349
    328350       
    329         if (document_root !=null){
    330         if(this.gsdlversion == 2) {
    331         document_root = document_root.substring(1);
    332        
    333         if (document_root.indexOf("/") > 0 ){
    334             document_root = document_root.substring(0, document_root.indexOf("/"));
    335         }
    336         }
    337         //else{
    338         //document_root = "greenstone3";
    339         //}
    340     }
    341 
     351        if (document_root !=null){  // e.g. "/greenstone/web/images" for GS2
     352        if(document_root.indexOf("/") == 0) {
     353        document_root = document_root.substring(1); // takes off first slash
     354        }
     355        if (document_root.indexOf("/") > 0 ){ // e.g we end up with "greenstone" for GS2, "greenstone3" for GS3
     356        document_root = document_root.substring(0, document_root.indexOf("/"));
     357        }       
     358    }
    342359
    343360    String image_url  = getParameter("imageURL");
     
    349366    if (image_url==null)
    350367    {
    351         String gwcgi_param  = getParameter("gwcgi");
    352         if(gsdlversion == 2) {
    353         gwcgi_param = tidy_URL(gwcgi_param, true); //true to append ? to URL
    354         } else {
    355         gwcgi_param = tidy_URL(gwcgi_param, false);
    356         }
    357    
    358368        String collection_param  = getParameter("collection");
    359369        String classifier_param  = getParameter("classifier");
     
    361371        if(gsdlversion == 2) {
    362372        // GS2 way
     373        String gwcgi_param  = gwcgi;
     374        gwcgi_param = tidy_URL(gwcgi_param, true); //true to append ? to URL
    363375        image_url = gwcgi_param + "a=d";
    364376        image_url += "&c=" + collection_param;
     
    366378        } else {
    367379        // Try GS3 way
    368         //image_url = gwcgi_param + "/collection/" + collection_param + "/browse/";
    369         image_url = gwcgi_param + "browse/";
     380        String library = getParameter("library");
     381        String site = getParameter("sitename");
     382       
     383        // starting URL (image_url) might not be base_url. We need to store base_url separately
     384        baseURL = tidy_URL(baseurl, false);
     385        if(!baseURL.endsWith("/")) {
     386            baseURL += "/";
     387        }
     388       
     389        // building up to baseURL/LIBNAME/collection/COLNAME/browse/
     390        image_url = baseURL + library + "/collection/" + collection_param + "/browse/";
     391       
    370392        int index = classifier_param.indexOf(".");
    371393        if(index == -1) {
     
    383405            image_url = image_url + classifierSuffix;
    384406        }
    385        
    386         this.library = getParameter("library");
    387         this.site = getParameter("sitename");
    388         this.collection = collection_param;
    389         if(library != null && site != null && collection != null) {
    390             this.gs3CollImgPath = library + "/sites/" + site + "/collect/" + collection;
     407
     408        if(library != null && site != null && collection_param != null) {
     409            String gs3CollImgPath = library + "/sites/" + site + "/collect/" + collection_param;
    391410            if(href_musthave == null) {
    392                 href_musthave = this.gs3CollImgPath;
     411                href_musthave = gs3CollImgPath;
    393412            } else {
    394             href_musthave += "%" + this.gs3CollImgPath;
     413            href_musthave += "%" + gs3CollImgPath;
    395414            }         
    396415            if(verbosity_ >= 3) {
     
    398417            }
    399418        }
    400         // starting URL (image_url) might not be base_url
    401         this.baseURL = getParameter("baseurl");
    402         // TODO: is it not the other way: gwcgi should be param set to base_url
    403         // and image_url/starting_url should be obtained from parameters also?
    404         }
    405     }
    406 
    407     // status bar that applet has, but we want one also if we run JPhind as application
    408     // And in fact, when webswing runs our applet, we never get a status bar. So we
    409     // create a custom status bar now even if we're running as an applet.
    410     // When this applet is run through the appletviewer we might end up with 2 status bars.
    411     setLayout(new BorderLayout());
    412     //if(!isRunAsApplet) {
    413     statusBar = new JLabel();
    414     this.add(statusBar, BorderLayout.SOUTH);
    415     Dimension d = statusBar.getSize();
    416     d.height = 30;
    417     statusBar.setPreferredSize(d);
    418     //}
     419        }
     420    }
    419421
    420422    MediaTracker trk = new  MediaTracker(this);
     
    427429                        image_url, href_musthave, image_mustnothave,
    428430                        image_ignore, imageType_,document_root,verbosity_,trk);
    429 
    430     download_thread_.setupForGS3(this.gs3CollImgPath, this.baseURL);
    431431   
    432432    // starts the display image thread with the currently downloaded images
     
    434434    }
    435435
     436    public JLabel getStatusBar() {
     437    return this.statusBar;
     438    }
     439   
    436440 
    437441    /** Goes to the url associated with the image that is clicked on screen<br>
     
    600604
    601605
     606    public static void printUsage() {
     607    System.err.println("Params needed include: --gsdlversion <3/2> [--baseurl <GS3 DL baseURL>/--gwcgi <library.cgi URL>] --library l --sitename s --collection c --classifier cl --imageType \".jpg%.png\" --imageMustNotHave \"interfaces/\" --documentroot greenstone3 [--webswing <1/0>] [--verbosity <v>] --maxDepth 500 --maxDisplay 25 --refreshDelay 1500 --isJava2 auto --bgcolor \"#96c29a\" [--xtraParams <key1=value1&key2=value2&...]");
     608    }
     609   
    602610    // To also be able to run this applet as an application, need a main method
    603611    /**
    604      * Try running as:
    605 java -cp ./web/applet/GsdlCollageApplet.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet "http://localhost:8383/greenstone3/" --gwcgi "http://localhost:8383/greenstone3/library/collection/smallbea/" --library library --collection smallbea --gsdlversion 3 --baseurl "http://localhost:8383/greenstone3/" --sitename localsite --documentroot greenstone3 --verbosity 3 --imageType ".jpg%%.png" --imageMustNotHave "interfaces/" --classifier "CL2.3" --maxDepth 500 --maxDisplay 25 --refreshDelay 1500 --isJava2 auto --bgcolor "#96c29a"
     612     * After building the GS3 Multimedia collection, try running this Application as:
     613java -cp ./web/applet/GsdlCollageApplet.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet --baseurl "http://localhost:8383/greenstone3/" --library library --collection smallbea --gsdlversion 3 --sitename localsite --documentroot greenstone3 --verbosity 3 --imageType ".jpg%.png" --imageMustNotHave "interfaces/" --classifier "CL2.3" --maxDepth 500 --maxDisplay 25 --refreshDelay 1500 --isJava2 auto --bgcolor "#96c29a"
    606614     */
    607615    public static void main(String[] args) {
    608     if(args.length < 9) {
    609         System.err.println("Need minimum --params: <baseURL> --library <library> --collection <collection> --classifier <classifier> --phindcgi <URL> --library <libURL> [--webswing <1/0>] [--backdrop <ImgURL>] [--xtraParams <key1=value1&key2=value2&...]");
    610     }
    611     else { // collection fao.org, classifier 1, phindcgi url, library url, backdrop imgurl
     616    if(args.length == 0) {
     617        printUsage();
     618    } else if(args[0].equals("--help") || args[0].equals("-h")) {
     619        printUsage();
     620    } else {
    612621        JFrame frame = new JFrame("Collage Applet as Application");
    613622        GsdlCollageApplet collageApp = new GsdlCollageApplet();
    614623        frame.getContentPane().add(collageApp, BorderLayout.CENTER);
    615         frame.setSize(600,300);
     624        frame.setSize(X_DIM, Y_DIM); //Y_DIM+EXTRA_HEIGHT);
     625        frame.setVisible(true);
    616626        // https://stackoverflow.com/questions/19433358/difference-between-dispose-and-exit-on-close-in-java
    617627        // default: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE
    618         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // don't do EXIT_ON_CLOSE in Applets!
    619         frame.setVisible(true);
     628        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Running as an application. But don't do EXIT_ON_CLOSE in Applet mode!
     629
     630        // prepare to run the collage applet as an application
    620631        collageApp.applicationPreInit(args);
     632
     633        // status bar code. Not ideal, but had to add it here to get relative dimensions right
     634        collageApp.setLayout(new BorderLayout());
     635        JLabel statusBar = collageApp.getStatusBar();
     636        frame.add(statusBar, BorderLayout.SOUTH);
     637        Dimension d = statusBar.getSize();
     638        d.height = EXTRA_HEIGHT;
     639        d.width = collageApp.getWidth();
     640        statusBar.setPreferredSize(d);
     641        //statusBar.setPreferredSize(new Dimension(collageApp.getWidth(), EXTRA_HEIGHT));   
     642       
     643        // Run it at last: manually calling (J)Applet methods init() and start()
     644        collageApp.init();
     645
     646        collageApp.showStatus("Collage application running");
     647        collageApp.start();
     648
     649        // When we terminate the application, need to manually call the applet method stop()
    621650        //https://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html#windowfocuslistener       
    622651        frame.addWindowListener(new WindowAdapter() {
    623652        public void windowClosing(WindowEvent e) {
    624             //collageApp.init();
     653            collageApp.showStatus("Stopping threads");
     654            System.err.println("\n\n*** Closing applet: stopping threads...");
    625655            collageApp.stop();
    626656            collageApp.destroy();
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GsdlCollageBrowse.java

    r38881 r38885  
    9393    app_info +="<param name='collection'   value='";
    9494    app_info += this.cluster_name + "'/>";
    95     //app_info += "<param name='gwcgi' value='http://localhost:8383/greenstone3/library' /><param name='classifier' value='CL3.1' /><param name='hrefMustHave' value='CL3' /><param name='imageMustNotHave' value='hl=%x=%gt=%gc=%.pr' /><param name='imageType' value='.jpg%%.png' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
    9695    app_info += "<param name='gsdlversion' value='3' />";
    9796    app_info += "<param name='baseurl' value='http://localhost:8383/greenstone3/' />";
    9897    app_info += "<param name='sitename' value='localsite' />\n";
     98   
     99    //app_info += "<param name='gwcgi' value='http://localhost:8383/greenstone3/library' /><param name='classifier' value='CL3.1' /><param name='hrefMustHave' value='CL3' /><param name='imageMustNotHave' value='hl=%x=%gt=%gc=%.pr' /><param name='imageType' value='.jpg%%.png' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
     100
    99101    //app_info += "<param name='documentroot' value='library/collection/" + this.cluster_name + "/'/>";
    100102    app_info += "<param name='documentroot' value='greenstone3'/>\n";
    101103    app_info += "<param name='verbosity' value='3' />\n";
    102     app_info += "<param name='imageType' value='.jpg%%.png' />\n";
     104    app_info += "<param name='imageType' value='.jpg%.png' />\n";
    103105    //app_info += "<param name='hrefMustHave' value='smallbea' />\n";
    104     //app_info += "<param name='imageMustNotHave' value='hl=%x=%gt=%gc=%.pr' />\n";
    105106    app_info += "<param name='imageMustNotHave' value='interfaces/' />\n";
    106     app_info += "<param name='gwcgi' value='http://localhost:8383/greenstone3/library/collection/smallbea/' /><param name='classifier' value='CL2.3' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
     107    app_info += "<param name='classifier' value='CL2.3' /><param name='maxDepth' value='500' /><param name='maxDisplay' value='25' /><param name='refreshDelay' value='1500' /><param name='isJava2' value='auto' /><param name='bgcolor' value='#96c29a' />The Collage Applet.</"+GSXML.APPLET_ELEM+">"; // TODO
    107108   
    108109    Document dom = this.converter.getDOM(app_info);
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/classifier.xsl

    r38884 r38885  
    163163      <param name='gsdlversion' value='3' />
    164164      <param name='baseurl' value='http://localhost:8383/greenstone3/' />
    165       <param name='sitename' value='localsite' />
    166      
    167       <param name="gwcgi" value="http://localhost:8383/greenstone3/library"/>
     165      <param name='sitename' value='localsite' />     
    168166      <param name='library' value='library'/>
    169167      <param name="collection" value="smallbea"/>
Note: See TracChangeset for help on using the changeset viewer.