Changeset 38937 for main/trunk/greenstone3/src
- Timestamp:
- 2024-04-22T16:15:36+12:00 (4 weeks ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/applet
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/DisplayImages.java
r38908 r38937 123 123 if(screen_buffer_ == null) { 124 124 System.err.println("### why is screen_buffer_ null?"); 125 } 125 if(java.awt.GraphicsEnvironment.isHeadless()) { 126 System.err.println("### It's running headless so screen_buffer_ is null"); 127 } 128 if(!app_.isDisplayable()) { 129 System.err.println("### Collage app is not displayable, that's why screen_buffer_ is null"); 130 } 131 } 132 126 133 screen_graphic_ = screen_buffer_.getGraphics(); 127 134 screen_graphic_.setColor(bgcolor_); … … 438 445 Thread.sleep(1000); 439 446 continue; 440 } 447 } 448 //System.err.println("#### DisplayImages.run(): moving to next image"); 441 449 CollageImage collage_image = download_images_.getCollageImage(); 442 450 -
main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java
r38936 r38937 150 150 super(); 151 151 152 // status bar that applet has, but we want one also if we run JPhind as application 153 // And in fact, when webswing runs our applet, we never get a status bar. So we 154 // create a custom status bar now even if we're running as an applet. 155 // When this applet is run through the appletviewer we might end up with 2 status bars. 152 // status bar if run as application or as webswing applet, 153 // mimicing running as regular applet which gives us a status bar by default 154 // Useful for Phind, not for Collage where there are layout issues even if hidden 156 155 //setLayout(new BorderLayout()); 157 156 //if(!isRunAsApplet) { … … 176 175 } 177 176 177 /** 178 * This method is called (by main()) only when this class is run 179 * as an application, not as applet. It prepares the variables and 180 * commandline parameters to be set up, so the rest of the 181 * initialisation can be done in the usual way (with the 182 * Applet.getParameters() method) in the init() method called 183 * hereafter for both application and applet mode. 184 */ 178 185 public void applicationPreInit(String[] args) { 179 186 // I copied the contents of this contructor for my code for the JPhind.java constructor … … 204 211 if(key.equals("xtraParams")) { 205 212 value = value.replace("&", "&"); // just in case we have html entities 206 parseXtraParams(value, "=", "&", appParams); 207 /* 208 String[] param_list = value.split("&", 0); // 0 for all occurrences 209 for(String key_val : param_list) { 210 String[] paramPair = key_val.split("=", 2); // get first 2 strings, key and val 211 //System.err.println("key_val: " + key_val); 212 if(paramPair.length == 2) { 213 String xtraParamsKey = paramPair[0]; 214 String xtraParamsVal = paramPair[1]; 215 //System.err.println("key - val: " + xtraParamsKey + " - " + xtraParamsVal); 216 appParams.put(xtraParamsKey, xtraParamsVal); 217 } 218 } 219 */ 213 parseXtraParams(value, "=", "&", appParams); 220 214 } 221 215 … … 223 217 } 224 218 } 225 226 // TODO: we can possibly remove this as it's done in init() now before we need it227 isWebswing = appParams.getOrDefault("webswing", "0").equals("1") ? true : false;228 219 229 220 // Need these parameters set before init(), so that the display works … … 318 309 for(String key_val : param_list) { 319 310 String[] paramPair = key_val.split(kvSeparator, 2); // get first 2 strings, key and val 320 System.err.println("key_val: " + key_val);311 //System.err.println("key_val: " + key_val); 321 312 if(paramPair.length == 2) { 322 313 String xtraParamsKey = paramPair[0]; … … 328 319 } 329 320 330 if (verbosity_ >= 3) {321 if (verbosity_ >= 4) { 331 322 System.err.println("*** xtraParams key - val: " + xtraParamsKey + " - " + xtraParamsVal); 332 323 } … … 530 521 } 531 522 532 // This block was a nice idea if it worked, but it doesn't work. It's here for syntax. 533 // Handle getting called by webswing JavaScript (but only if run in webswing mode): 534 // when the user navigates away from the webswing app's web page, do cleanup 523 // This block was a nice idea had it worked, but it doesn't 524 // work. It's here as sample syntax. Handle getting called by 525 // webswing JavaScript (but only if run in webswing mode): 526 // when the user navigates away from the webswing app's web 527 // page, do cleanup 535 528 // https://www.webswing.org/docs/23.2/integrate/jslink.html#invoking-java-from-javascript 536 529 // https://vaadin.com/directory/component/webswing-vaadin1 537 530 if(isWebswing) { 538 531 539 System.err.println("#### isWebswing, about to add listeners");532 //System.err.println("#### isWebswing, about to add listeners"); 540 533 541 534 WebswingUtil.getWebswingApi().addBrowserActionListener(new WebActionListener() { … … 543 536 public void actionPerformed(WebActionEvent actionEvent) { 544 537 545 System.err.println("*** ***** JavaScript to Java: actionPerformed called.");538 System.err.println("***JavaScript to Java comms: actionPerformed called"); 546 539 //System.err.println("actionEvent = "); 547 540 … … 566 559 // shutdown the way we'd like on the javascript kill() 567 560 // command when the user navigates away from the collage 568 // page as that only generates a Java WindowClosingEvent569 // by default if no tshutdown handlers registered. And a561 // page, as that only generates a Java WindowClosingEvent 562 // by default if no shutdown handlers registered. And a 570 563 // WindowClosingEvent only has any effect on applications, 571 564 // not applets. But we can write our own custom handler to 572 // mimic the applet shutdown sequence: refer to 565 // mimic the applet shutdown sequence of stop() then 566 // destroy() see 573 567 // https://www.webswing.org/docs/20.2/integrate/api.html 574 // This code also written with the help of the source code 575 // to know the methods in interface WebswingShutdownListener 576 // and the import statements required for the methods. 577 // and then call System.exit(0) on top of usual applet 578 // behaviour to make sure we get rid of the applet 579 // "application" that webswing launched for us (it took 580 // the applet code and ran it, presumably like a java 581 // program, so a System.exit call may be warranted). 568 // This code also written with the help of webswing's 569 // source code to know the methods in interface 570 // WebswingShutdownListener and the import statements 571 // required for these methods. 572 // After stop() and destroy(), we call System.exit(0) on 573 // top of usual applet behaviour to make sure we get rid 574 // of the applet "application" that webswing launched for 575 // us (it took the applet code and ran it, presumably like 576 // a java program, so a System.exit call may be warranted, 577 // whereas System.exit() isn't called on a regular applet). 582 578 WebswingUtil.getWebswingApi().addShutdownListener(new WebswingShutdownListener() { 583 // These are official API comments for info579 // These are official webswing API comments for info 584 580 /** 585 581 * Invoked before Webswing requests application to exit. … … 614 610 // We're like the browser now and so we should 615 611 // honour the above contract. 616 617 System.err.println("------- WebswingShutdownListener.onShutdown() - our custom behaviour"); 612 if (verbosity_ >= 3) { 613 System.err.println("------- GsdlCollageApplet WebswingShutdownListener.onShutdown() - our custom behaviour"); 614 615 // This message is sent to JavaScript too late: webpage has already 616 // finished unloading and the JS webswingInstance can't receive msgs. 617 // if(isWebswing && isRunAsApplet) { 618 // WebswingUtil.getWebswingApi().sendActionEvent("javaToWebswingJSConsoleLog", "GsdlCollageApplet running as webswing applet - quitting now", null); 619 // } 620 } 618 621 stop(); 619 622 destroy(); … … 623 626 // webswing. And this handler/webswing stands 624 627 // in place of a browser and controls what 625 // Oughtto happen if a browser doesn't take628 // *ought* to happen if a browser doesn't take 626 629 // care of the applet life cycle and we ought 627 // to do it .630 // to do it (here in the webswing handler). 628 631 System.exit(0); 629 632 } … … 631 634 } 632 635 633 /*634 System.err.println("XXX App width: " + this.getWidth());635 System.err.println("XXX App height: " + this.getHeight());636 637 638 // webswing applet doesn't have dimensions set because there's no applet element setting it639 // so we need to set the size on the Collage Applet if launched with webswing and run in applet mode640 if(isWebswing && isRunAsApplet) {641 //this.setPreferredSize(new Dimension(X_DIM(), Y_DIM()));642 this.setSize(X_DIM(), Y_DIM());643 this.resize(X_DIM(), Y_DIM());644 645 System.err.println("@@@@ App width: " + this.getWidth());646 System.err.println("@@@@ App height: " + this.getHeight());647 648 if(!this.isShowing()) {649 System.err.println("@@@@ The webswing Applet isn't showing!");650 this.setVisible(true);651 }652 if(!this.isShowing()) {653 System.err.println("@@@@ The webswing Applet is STILL not showing!");654 }655 }656 */657 636 658 637 MediaTracker trk = new MediaTracker(this); … … 665 644 image_url, href_musthave, image_mustnothave, 666 645 image_ignore, imageType_,document_root,verbosity_,trk); 667 668 if(isShowing() && isDisplayable()) { //The case if(!(isRunAsApplet && isWebswing)) { 669 System.err.println("**** Creating display thread"); 646 // If GsdlCollageApplet is launched as a *webswing applet*, it 647 // doesn't have dimensions, isn't showing nor is it even 648 // displayable at this point in the code. Only when webswing 649 // resizes the GsdlCollageApplet Component, does it have 650 // dimensions and do we know for sure it is showing. 651 if(isShowing() && isDisplayable()) { // case of: if(!(isRunAsApplet && isWebswing)) { 652 if (verbosity_ >= 4) { 653 System.err.println("**** Creating display thread"); 654 } 670 655 // starts the display image thread with the currently downloaded images 671 656 display_thread_ = new DisplayImages(this, download_images_,isJava2_, bgcolor_); 672 657 } else { 673 System.err.println("**** GsdlCollageApplet.init() - display_thread_ not yet showing."); 674 System.err.println("**** Will create and start display_thread_ later, in ComponentListener.resize()"); 658 if (verbosity_ >= 4) { 659 System.err.println("**** GsdlCollageApplet.init() - display_thread_ not yet showing."); 660 System.err.println("**** Will create and start display_thread_ later, in ComponentListener.resize()"); 661 } 675 662 } 676 663 // The display_thread_ needs the component showing before it can be started up. … … 688 675 689 676 public void componentHidden(ComponentEvent e) { 690 System.err.println(e.getComponent().getClass().getName() + " --- Hidden"); 677 if (verbosity_ >= 4) { 678 System.err.println(e.getComponent().getClass().getName() + " --- Hidden"); 679 } 691 680 } 692 681 693 682 public void componentMoved(ComponentEvent e) { 694 System.err.println(e.getComponent().getClass().getName() + " --- Moved"); 683 if (verbosity_ >= 4) { 684 System.err.println(e.getComponent().getClass().getName() + " --- Moved"); 685 } 695 686 } 696 687 697 688 public void componentResized(ComponentEvent e) { 698 System.err.println(e.getComponent().getClass().getName() + " --- Resized");699 700 689 if(display_thread_ == null) { 690 if (verbosity_ >= 4) { 691 System.err.println(e.getComponent().getClass().getName() + " --- Resized"); 692 System.err.println("Ready to instantiate display thread"); 693 } 701 694 display_thread_ = new DisplayImages(this, download_images_,isJava2_, bgcolor_); 702 695 display_thread_.start(); … … 704 697 } 705 698 706 public void componentShown(ComponentEvent e) { 707 System.err.println("XXXXX" + e.getComponent().getClass().getName() + " --- Shown"); 699 public void componentShown(ComponentEvent e) { 708 700 if(display_thread_ == null) { 701 if (verbosity_ >= 4) { 702 System.err.println("@@@ " + e.getComponent().getClass().getName() + " --- Shown"); 703 System.err.println("GsdlCollageApplet ready to instantiate display thread"); 704 } 709 705 display_thread_ = new DisplayImages(this, download_images_,isJava2_, bgcolor_); 710 706 display_thread_.start(); … … 718 714 // TODO: Do I need to follow 719 715 // https://stackoverflow.com/questions/5861894/how-to-synchronize-or-lock-upon-variables-in-java 716 // I just followed the Java API's recommendations about what to do 717 // as replacement around Thread.stop() and Thread.destroy() being 718 // deprecated (note: not Applet.stop() and 719 // Applet.destroy(). https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#stop-- 720 720 public void stopRunning() { 721 721 if(verbosity_ >= 3) { … … 741 741 } 742 742 743 // Applet's mouseDown() is deprecated, so we implement mousePressed 743 744 protected class CollageMouseAdapter extends MouseAdapter { 744 745 … … 748 749 public void mousePressed(MouseEvent e) 749 750 { 750 751 System.err.println("Mouse pressed");752 751 int x = e.getX(); 753 752 int y = e.getY(); … … 782 781 System.err.println("@@@GsdlCollageApplet.CollageMouseAdapter.mousePressed()" 783 782 + "\n\topening url " + from_url + "\n\t" 784 + "for non-applet and non-webswing applicationis not yet implemented.");783 + "for non-applets and non-webswing applications is not yet implemented."); 785 784 } 786 785 } … … 790 789 791 790 } 792 //return true;793 791 } 794 792 } … … 797 795 public void start() 798 796 { 799 // starts the display image thread with the currently downloaded images800 //display_thread_ = new DisplayImages(this, download_images_,isJava2_, bgcolor_);801 //this.setVisible(true);802 797 download_thread_.start(); 803 798 … … 838 833 public void stop() 839 834 { 840 System.err.println("\n\n*** Stopping collage Applet: stopping threads..."); 835 if(verbosity_ >= 3) { 836 System.err.println("\n\n@@@ GsdlCollageApplet.stop() called: stopping threads..."); 837 } 841 838 //download_thread_.stop(); 842 839 //display_thread_.stop(); 843 840 stopRunning(); 844 841 // TODO: maybe we want to unset the interrupt variable on the threads to restart 845 // on start() getting called? No: we system.exit() in the webswing shutdown handler 846 847 //download_thread_ = null; 848 //display_thread_ = null; 849 850 } 851 852 /** Destroys threads for downloading and displaying images */ 842 // on start() getting called? No: because we system.exit() in the webswing 843 // shutdown handler we implemented. 844 } 845 846 /** Destroys threads for downloading and displaying images Java 847 * API method specification for destroy(): "Called by the browser 848 * or applet viewer to inform this applet that it is being 849 * reclaimed and that it should destroy any resources that it has 850 * allocated. The stop method will always be called before 851 * destroy." 852 */ 853 853 public void destroyed() 854 854 { 855 856 System.err.println("@@@@@@@@@ GsdlCollageApplet.destroy() called"); 857 858 // Let's be sure to have stopped running 859 //stopRunning(); 860 855 if(verbosity_ >= 3) { 856 System.err.println("@@@@@@@@@ GsdlCollageApplet.destroy() called"); 857 } 861 858 download_thread_ = null; 862 859 … … 887 884 System.err.println("Applet still trying to paint!!"); 888 885 } 889 890 891 892 } 893 886 887 } 894 888 895 889 -
main/trunk/greenstone3/src/java/org/greenstone/applet/phind/JPhind.java
r38936 r38937 350 350 add(resultPanel, BorderLayout.CENTER); 351 351 352 // status bar that applet has, but we want one also if we run JPhind as application 353 // And in fact, when webswing runs our applet, we never get a status bar. So we 354 // create a custom status bar now even if we're running as an applet. 355 // When this applet is run through the appletviewer we might end up with 2 status bars. 352 // Manual status bar to mimic applet's default one, in case we 353 // want one if we run Collage as application And in fact, when 354 // webswing runs our applet, we never get a status bar. So we 355 // can create a custom status bar now even if we're running as 356 // an applet. When this applet is run through the 357 // appletviewer we might end up with 2 status bars. 358 356 359 //if(!isRunAsApplet) { 357 360 statusBar = new JLabel();
Note:
See TracChangeset
for help on using the changeset viewer.