Changeset 38948 for main/trunk/greenstone3
- Timestamp:
- 2024-04-23T18:59:30+12:00 (7 weeks ago)
- Location:
- main/trunk/greenstone3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java
r38942 r38948 1009 1009 } 1010 1010 collageApp.showStatus("Stopping threads"); 1011 System.err.println("\n\n ***Closing collage Application: stopping threads...");1011 System.err.println("\n\n@@@ Closing collage Application: stopping threads..."); 1012 1012 collageApp.stopRunning(); 1013 1013 -
main/trunk/greenstone3/src/java/org/greenstone/applet/phind/JPhind.java
r38943 r38948 143 143 implements ActionListener, WebswingShutdownListener { 144 144 145 int verbosity_ = 3; 145 private int verbosity_ = 3; 146 // dimensions of this component if run as application 147 private int appX = 500; 148 private int appY = 500; 146 149 147 150 // if run as webswing vs either commandline application or as applet through appletviewer … … 378 381 } 379 382 380 381 383 // Initialise the user interface 382 384 setBackground(panel_bg); … … 875 877 876 878 verbosity_ = parameterValue("verbosity", verbosity_); 877 879 appX = parameterValue("width", appX); 880 appY = parameterValue("height", appY); 881 878 882 String webswing = parameterValue("webswing", "0"); 879 883 isWebswing = webswing.equals("1") ? true : false; … … 1285 1289 JFrame frame = new JFrame("Phind Applet as Application"); 1286 1290 frame.getContentPane().add(phind, BorderLayout.CENTER); 1287 frame.setSize(500,500); 1291 System.err.println("App dimensions: " + phind.appX + "x" + phind.appY); 1292 frame.setSize(phind.appX, phind.appY); 1288 1293 // https://stackoverflow.com/questions/19433358/difference-between-dispose-and-exit-on-close-in-java 1289 1294 // default: https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html#EXIT_ON_CLOSE -
main/trunk/greenstone3/web/interfaces/default/transform/layouts/webswing-collage.xsl
r38946 r38948 75 75 76 76 if(!webswingInstance0.options.args) { 77 webswingInstance0.options.args="";77 webswingInstance0.options.args=""; 78 78 } 79 79 … … 81 81 var appletEl = document.getElementById("collage-applet-element"); 82 82 83 if(!appletEl) { 84 85 if(verbosity >= 4) { 86 console.log("No collage-applet-element on page. Reading in from pageResponse/XSLT."); 83 // Fill up webswingParams JSON record with non-dynamic values and other vals 84 // that may perhaps not be set on the applet element, to use as fallback 85 var webswingParams = { 86 //"webswing":1, // set in webswing.config.in to discourage editing 87 "verbosity": verbosity, 88 "gsdlversion":3, 89 "maxDepth": 500, 90 "maxDisplay": 25, 91 "refreshDelay": 1500, 92 "isJava2":"auto", 93 "bgcolor":"#96c29a" 94 }; 95 96 if(!appletEl && verbosity >= 4) { 97 console.log("No collage-applet-element on page. Using webswing params vals from pageResponse/XSLT."); 87 98 } 88 99 … … 106 117 var gs3CollBrowsePath = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + gs.cgiParams.cl; // cl is classifier, e.g "CL3" 107 118 108 var gsdlversion = 3; 109 var collection = gs.cgiParams.c; 110 var library = gs.xsltParams.library_name; 111 var documentroot = gs.xsltParams.servlet_context; 112 var hrefMustHave = gs3CollBrowsePath; 113 var imageMustNotHave = "interfaces/"; 114 var imageType = ".jpg%.png"; 115 var classifier = gs.cgiParams.cl + ".1"; 116 117 // non-dynamic values 118 var maxDepth = 500; 119 var maxDisplay = 25; 120 var refreshDelay = 1500; 121 var isJava2 = "auto"; 122 var bgcolor = "#96c29a"; 123 124 125 // Control the width and height of the Java application launched with webswing 126 // by passing width and height params set to the attributes of the webswing element 127 // https://stackoverflow.com/questions/21851633/get-height-from-style-attribute 128 var w = document.getElementById("webswing-collage").style.width; 129 var h = document.getElementById("webswing-collage").style.height; 130 131 } else { // the applet element exists, get all webswing config settings from there 132 119 webswingParams["baseurl"] = baseURL; 120 webswingParams["collection"] = gs.cgiParams.c; 121 webswingParams["library"] = gs.xsltParams.library_name; 122 webswingParams["documentroot"] = gs.xsltParams.servlet_context; 123 webswingParams["hrefMustHave"] = gs3CollBrowsePath; 124 webswingParams["imageMustNotHave"] = "interfaces/"; 125 webswingParams["imageType"] = ".jpg%.png"; 126 webswingParams["classifier"] = gs.cgiParams.cl + ".1"; 127 128 129 130 if(appletEl) { // get all available webswing config settings from applet element 131 if(verbosity >= 4) { 132 console.log("collage-applet-element on page, using its params where available."); 133 } 133 134 // If using the inactive/deprecated applet element as shim, instead of javascript 134 135 // working out the webswing config params from the pageRequest or XSLT variables: … … 136 137 // as a GS3 library designer may know to how to customize applet parameters 137 138 // better than they know javascript or how to construct webswing parameters. 138 139 // First (re)setting the verbosity variable already declared earlier140 var tmp_verbosity = appletEl.querySelector("param[name='verbosity']").value;141 if(tmp_verbosity) {142 verbosity = tmp_verbosity;143 }144 var baseURL = appletEl.querySelector("param[name='baseurl']").value;145 var gsdlversion = appletEl.querySelector("param[name='gsdlversion']").value;146 var collection = appletEl.querySelector("param[name='collection']").value;147 var library = appletEl.querySelector("param[name='library']").value;148 var documentroot = appletEl.querySelector("param[name='documentroot']").value;149 var hrefMustHave = appletEl.querySelector("param[name='hrefMustHave']").value;150 var imageMustNotHave = appletEl.querySelector("param[name='imageMustNotHave']").value;151 var imageType = appletEl.querySelector("param[name='imageType']").value;152 var classifier = appletEl.querySelector("param[name='classifier']").value;153 var maxDepth = appletEl.querySelector("param[name='maxDepth']").value;154 var maxDisplay = appletEl.querySelector("param[name='maxDisplay']").value;155 var refreshDelay = appletEl.querySelector("param[name='refreshDelay']").value;156 var isJava2 = appletEl.querySelector("param[name='isJava2']").value;157 var bgcolor = appletEl.querySelector("param[name='bgcolor']").value;158 159 var w = appletEl.width;160 var h = appletEl.height;161 139 140 // Now get the param subelements of the applet element 141 for (var webswingParam of Object.keys(webswingParams)) { 142 var querySelectorStr = "param[name='"+webswingParam+"']"; 143 var appletParam = appletEl.querySelector(querySelectorStr); 144 if(appletParam) { // if this parameter was set on the applet 145 webswingParams[webswingParam] = appletParam.value; 146 } else { 147 if(verbosity>=3) { 148 console.log("Applet element doesn't supply param: " + webswingParam + ". Using fallback: " + webswingParams[webswingParam]); 149 } 150 } 151 } 152 162 153 } 163 164 webswingInstance0.options.args += "--baseurl \"" + baseURL + "\""; 165 //webswingInstance0.options.args += " --webswing 1"; // set in webswing.config.in 166 webswingInstance0.options.args += " --gsdlversion " + gsdlversion; 167 webswingInstance0.options.args += " --collection " + collection; 168 webswingInstance0.options.args += " --library " + library; 169 webswingInstance0.options.args += " --documentroot " + documentroot; 170 webswingInstance0.options.args += " --hrefMustHave " + hrefMustHave; 171 webswingInstance0.options.args += " --imageMustNotHave \""+ imageMustNotHave+ "\""; 172 webswingInstance0.options.args += " --verbosity " + verbosity; 173 webswingInstance0.options.args += " --imageType \"" + imageType + "\""; 174 webswingInstance0.options.args += " --classifier \"" + classifier + "\""; 175 webswingInstance0.options.args += " --maxDepth " + maxDepth; 176 webswingInstance0.options.args += " --maxDisplay " + maxDisplay; 177 webswingInstance0.options.args += " --refreshDelay " + refreshDelay; 178 webswingInstance0.options.args += " --isJava2 \""+ isJava2 +"\""; 179 webswingInstance0.options.args += " --bgcolor \""+ bgcolor +"\""; 180 181 182 // common code, regardless of whether we use the applet element as a shim or not 183 var suffixIndex = 0; 184 if(w) { 185 suffixIndex = w.indexOf("px"); 186 if(suffixIndex>0) { 187 w = w.substring(0, suffixIndex); 188 } 189 webswingInstance0.options.args += " --width " + w; 190 } 191 if(h) { 192 suffixIndex = h.indexOf("px"); 193 if(suffixIndex>0) { 194 h = h.substring(0, suffixIndex); 195 } 196 webswingInstance0.options.args += " --height " + h; 197 } 198 154 155 // Special case: width and height are attributes of the applet tag not subelements 156 // and may need parsing. 157 // Control the width and height of the Java application launched with webswing by 158 // passing the width and height params set on the webswing element, unless an applet 159 // element is available. In that case try to get the dimensions from the applet tag. 160 // https://stackoverflow.com/questions/21851633/get-height-from-style-attribute 161 var w = appletEl ? appletEl.getAttribute("width") : document.getElementById("webswing-collage").style.width; 162 var h = appletEl ? appletEl.getAttribute("height") : document.getElementById("webswing-collage").style.height; 163 webswingParams["width"] = stripUnitOffAttribute("px", w); 164 webswingParams["height"] = stripUnitOffAttribute("px", h); 165 166 167 // Having collected all the webswingParams, we can finally build up the single webswing customArgs string 168 var _args = ""; 169 for (var webswingParam of Object.keys(webswingParams)) { 170 _args += "--" + webswingParam + " \"" + webswingParams[webswingParam] + "\" "; // space at end to precede next arg 171 } 172 webswingInstance0.options.args += _args.substring(0, _args.length-1); // remove extra space at end 173 174 199 175 // Set to false if running the webswing instance as a webswing application. This has 200 176 // nothing to do with if the applet element exists on the page: it can be on the page … … 238 214 var results = new RegExp("[\\?&]" + name + "=([^&#]*)").exec(location.href); 239 215 return results == null ? null : decodeURIComponent(results[1]); 216 } 217 218 function stripUnitOffAttribute(unit, attr) { 219 // common code, regardless of whether we use the applet element as a shim or not 220 var suffixIndex = 0; 221 if(attr) { 222 suffixIndex = attr.indexOf(unit); 223 if(suffixIndex>0) { 224 attr = attr.substring(0, suffixIndex); 225 } 226 } 227 return attr; 240 228 } 241 229 </gsf:script> -
main/trunk/greenstone3/web/interfaces/default/transform/pages/classifier.xsl
r38938 r38948 173 173 code="org.greenstone.applet.GsdlCollageApplet.GsdlCollageApplet.class" 174 174 archive="GsdlCollageApplet.jar, webswing-api.jar" 175 width=" 600"176 height=" 300">175 width="800" 176 height="400"> 177 177 <xsl:attribute name="codebase">/<xsl:value-of select="$servlet_context"/>/applet</xsl:attribute> 178 178 -
main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl
r38947 r38948 145 145 } 146 146 147 var verbosity = 4;147 var verbosity = 3; 148 148 var appletEl = document.querySelector("applet"); 149 149 150 150 // Set to false if running the webswing instance as a webswing application. This has 151 151 // nothing to do with if the applet element exists on the page: it can be on the page 152 // and you can still decide to run GsdlCollageas a webswing application. If switching152 // and you can still decide to run JPhind as a webswing application. If switching 153 153 // between running as application and applet, remember to adjust webswing.config.in 154 154 // If we do push the deprecated applet element onto the page, we can use it as a shim: … … 157 157 var isWebswingRunAsApplet = true; 158 158 159 160 if(!appletEl) { 161 if(verbosity >= 4) { 159 // Fill up webswingParams JSON record with non-dynamic values and other vals 160 // that may perhaps not be set on the applet element, to use as fallback 161 var webswingParams = { 162 //"webswing":1, // set in webswing.config.in to discourage editing 163 "verbosity": verbosity, 164 "phindcgi": "?a=a&rt=r&s=PhindApplet&o=xml&ro=1", 165 "classifier": 1, // true or false 166 "backdrop": "interfaces/default/images/phindbg1.jpg", 167 "orientation": "vertical", 168 "depth": 2, 169 "resultorder": "L,l,E,e,D,d", 170 "fontsize": 10, 171 "blocksize": 10 172 } 173 174 // When passed into webswing if run as an application, the mostly static args will look like 175 //--verbosity 3 --phindcgi \"?a=a&rt=r&s=PhindApplet&o=xml&ro=1\" --classifier 1 --backdrop interfaces/default/images/phindbg1.jpg --orientation vertical --depth 2 --resultorder \"L,l,E,e,D,d\" --fontsize 10 --blocksize 10 176 // More will get prefixed and suffixed 177 178 if(!appletEl && verbosity >= 4) { 162 179 console.log("No applet element on page. Reading in from pageResponse/XSLT."); 163 180 } 164 165 //https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript 181 182 // The entirely javascript way of setting our webswing app parameters 183 // (does not read the parameters set on the applet element) 166 184 // dynamic phind arguments 167 var baseURL = window.location.origin+window.location.pathname; 168 var collection = gs.cgiParams.c; 169 var library = gs.xsltParams.library_name; 170 171 // largely static phind arguments 172 var phindcgi = "?a=a&rt=r&s=PhindApplet&o=xml&ro=1"; 173 var classifier = 1; // true or false 174 var backdrop = "interfaces/default/images/phindbg1.jpg"; 175 var orientation = "vertical"; 176 var depth = 2; 177 var resultorder = "L,l,E,e,D,d"; 178 var fontsize = 10; 179 var blocksize = 10; 180 } 181 182 // If run as webswing application, we need an extra cmdline arg: the baseURL at the *start* 185 webswingParams["collection"] = gs.cgiParams.c; 186 webswingParams["library"] = gs.xsltParams.library_name; 187 188 // If run as webswing application, we need an extra cmdline arg at the *start*: the baseURL 183 189 // It is not of key-value form, just the baseURL by itself. 184 190 if(!isWebswingRunAsApplet) { 191 //https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript 192 var baseURL = window.location.origin+window.location.pathname; 185 193 // webswingInstance0.options.args += "\"" + baseURL+ "?a=a&rt=d&s=PhindApplet&c="+gs.cgiParams.c + "\""; 186 webswingInstance0.options.args += "\"" + baseURL + "\""; 187 } 188 189 webswingInstance0.options.args += " --collection " + collection; 190 webswingInstance0.options.args += " --library " + library; 191 192 193 // The more static params look like 194 //--phindcgi \"?a=a&rt=r&s=PhindApplet&o=xml&ro=1\" --classifier 1 --backdrop interfaces/default/images/phindbg1.jpg --orientation vertical --depth 2 --resultorder \"L,l,E,e,D,d\" --fontsize 10 --blocksize 10 195 webswingInstance0.options.args += " --phindcgi \"" + phindcgi + "\""; 196 webswingInstance0.options.args += " --classifier " + classifier; 197 webswingInstance0.options.args += " --backdrop \"" + backdrop + "\""; 198 webswingInstance0.options.args += " --orientation " + orientation; 199 webswingInstance0.options.args += " --depth " + depth; 200 webswingInstance0.options.args += " --resultorder \"" + resultorder + "\""; 201 webswingInstance0.options.args += " --fontsize " + fontsize; 202 webswingInstance0.options.args += " --blocksize " + blocksize; 203 194 webswingInstance0.options.args += "\"" + baseURL + "\" "; 195 } 196 197 if(appletEl) { // get all available webswing config settings from applet element 198 if(verbosity >= 4) { 199 console.log("Found an applet HTML element on page, using its params where available."); 200 } 201 // If using the inactive/deprecated applet element as shim, instead of javascript 202 // working out the webswing config params from the pageRequest or XSLT variables: 203 // Get the webswing configuration arguments from the lingering applet html element, 204 // as a GS3 library designer may know to how to customize applet parameters 205 // better than they know javascript or how to construct webswing parameters. 206 207 // Now get the param subelements of the applet element 208 for (var webswingParam of Object.keys(webswingParams)) { 209 var querySelectorStr = "param[name='"+webswingParam+"']"; 210 var appletParam = appletEl.querySelector(querySelectorStr); 211 if(appletParam) { // if this parameter was set on the applet 212 webswingParams[webswingParam] = appletParam.value; 213 } else { 214 if(verbosity>=3) { 215 console.log("Applet element doesn't supply param: " + webswingParam + ". Using fallback: " + webswingParams[webswingParam]); 216 } 217 } 218 } 219 220 } 221 222 // Special case: width and height are attributes of the applet tag not subelements 223 // and may need parsing. 224 // Control the width and height of the Java application launched with webswing by 225 // passing the width and height params set on the webswing element, unless an applet 226 // element is available. In that case try to get the dimensions from the applet tag. 227 // https://stackoverflow.com/questions/21851633/get-height-from-style-attribute 228 var w = appletEl ? appletEl.getAttribute("width") : document.getElementById("webswing-phind").style.width; 229 var h = appletEl ? appletEl.getAttribute("height") : document.getElementById("webswing-phind").style.height; 230 webswingParams["width"] = stripUnitOffAttribute("px", w); 231 webswingParams["height"] = stripUnitOffAttribute("px", h); 232 233 234 // Having collected all the webswingParams, we can finally build up the single webswing customArgs string 235 var _args = ""; 236 for (var webswingParam of Object.keys(webswingParams)) { 237 _args += "--" + webswingParam + " \"" + webswingParams[webswingParam] + "\" "; // space at end to precede next arg 238 } 239 webswingInstance0.options.args += _args.substring(0, _args.length-1); // remove extra space at end 204 240 205 241 // When run as webswing applet (instead of as webswing application), the webswing var … … 237 273 return results == null ? null : decodeURIComponent(results[1]); 238 274 } 275 276 function stripUnitOffAttribute(unit, attr) { 277 // common code, regardless of whether we use the applet element as a shim or not 278 var suffixIndex = 0; 279 if(attr) { 280 suffixIndex = attr.indexOf(unit); 281 if(suffixIndex>0) { 282 attr = attr.substring(0, suffixIndex); 283 } 284 } 285 return attr; 286 } 239 287 </gsf:script> 240 288
Note:
See TracChangeset
for help on using the changeset viewer.