Class DownloadDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class DownloadDialog extends TextDialog
Complex multi-lingual dialog for installing "DEnS" = "Documentation, Examples and Sources" on the local machine. Could be used for other kinds of archives when the texts are adjusted accordingly. After completion of this dialog (a) the local file system may have changed and (b) the CALLER must retrieve this info (by get_newPosition() and get_newDigest()) and store it persistently. The initial situation when calling may be
 
    position and checksums of DEnS known,           |  unknown
    (from persistent storage or a previous call)    |
      calculate checksum anew                       |
    digest identical, files  | differ, files changed|
      unchanged              |                      |
                             |                      |
    uptodate | outofdate     | uptodate | outofdate |
             |               |          |           |
  ----print this situation----------------------------------------
 ask for user wishes
    1) download DEnS ..........................................
    2) browse local copy ..........................
    3) browse web copy ......................................
    4) terminate this dialog .................................
 
  ---- download process ------------------------------------------
   online                    |
   load zip                  |
   unzip                     |
   calculate md5             |

  ---- AFTER return / must be done on caller's level -------------
   store position/checksum to persistent storage

 
The architecture is as follows
      +--------------------+
      |JDialog             |
      |                    |
      +--------------------+
               /_\
                |
      +--------------------+
      |TextDialog          |
      |                    |
      +--------------------+
               /_\
                |                         +-------------------------+
      +--------------------+              | GetAndUnpackZipArchive  |
      |DownloadDialog      | -----------<>|  .fromTo()              |
      |                    |              +-------------------------+
      +--------------------+

  
The persistent storage of the file position must be done by the caller, using get_newPosition() and get_newDigest().
ATTENTION some of the translation keys are defined by messages from "GetAndUnpackZipArchive".
(Created by extracting from bandm_book/.../book2/base/Gui.java,translations.muli and extending (checksum, etc).)
(Replaces DownloadDialog_DeEn, which is deprecated because it uses jawaws/JNLP)
See Also:
  • Field Details

    • lang

      final String lang
      Current user language. Is fixed for one run uf this dialog.
    • langs

      final List<String> langs
      List of language preferences. Only needed for fall-back when a translation is missing.
    • defaultLang

      public static final String defaultLang
      Current language, if none is given to the constructor call.
      See Also:
    • DEnS_dir_name

      protected final String DEnS_dir_name
      Input parameter by the caller: name of the DEnS directory, fixed per application.
    • downloadUrl

      protected final URL downloadUrl
      Input parameter by the caller: where to download the ZIP file.
    • browseUrl

      @Opt protected final @Opt URL browseUrl
      Input parameter by the caller: where to read the documentation online.
    • docu_start_filepath

      protected final String docu_start_filepath
      Input parameter by the caller: relative start for HTML-browing relative to DEnS_dir_name.
    • oldPosition

      @Opt protected final @Opt File oldPosition
      Input parameter by the caller: last local store positon of DEnS, if any.
    • curPosition

      @Opt protected @Opt File curPosition
      Local value: last successful storage of DEnS during this dialog.
    • newPosition

      @Opt protected @Opt File newPosition
      Output value: last successful storage of DEnS during this dialog.
    • oldDigest

      @Opt protected final @eu.bandm.tools.annotations.Opt byte[] oldDigest
      Input parameter by the caller: last checksum d of DEnS, if any.
    • curDigest

      @Opt protected @eu.bandm.tools.annotations.Opt byte[] curDigest
      Local value: last checksum of DEnS during this dialog.
    • newDigest

      @Opt protected @eu.bandm.tools.annotations.Opt byte[] newDigest
      Output value: last checksum of DEnS during this dialog.
    • tampered

      protected boolean tampered
      Output value: whether the current/new downloaded data has been locally altered.
    • mulicat

      protected CatalogByString mulicat
      Dictionary of all translations. Must be enhanced when new a language is added.
    • selected_DEnS_Path

      protected File selected_DEnS_Path
      Temporary storage during dialog, between choosing and confirmation.
  • Constructor Details

    • DownloadDialog

      public DownloadDialog(@Opt @Opt JFrame frame, @Opt @Opt String title, String DEnS_dir_name, URL downloadUrl, @Opt @Opt URL browseUrl, String docu_start_filepath, boolean modal, @Opt @Opt String lang, @Opt @Opt File oldPosition, @Opt @eu.bandm.tools.annotations.Opt byte[] oldDigest, @Opt @Opt String serviceEmail, @Opt @Opt Dimension windowsize)
      After creation the (inherited) message runDialog() must be called. This performs the dialog by calling "react()" etc.
      This dialog class has its own translation dictionary. This must also contain the translations for the error messages from GetAndUnpackZipArchive. This code supports languges "de" and "en". New languages can be added by subclassing
          d= new DownloadDialog_DeEn(....)
               {{mulicat.put("when opening url socket", 
                             "nl", "xx xx xx",
                                 "fr", "xx xx xx");
                 mulicat.put("when writing local file",
                             "nl", "xx xx xx",
                                 "fr", "xx xx xx");
            }};
        
      Parameters:
      frame - OPT, window of application, MAY be used by Swing for positioning, etc.
      title - OPT, window title for dialog pop-up window
      DEnS_dir_name - file name of the one(1) directory which will be created on the local machine for storing all Do+X+S-files This must be also the only(1) top-level dir in the installed zipfile. When for the position of download is asked, and a directory with this name is selected, than the effect is the same as if its parent were selected.
      browseUrl - the url where the online net browsing can start,
      docu_start_filepath - file name of the entry point for local browsing, relative to the download position (something like "doc/user/index.html")
      modal - whether the dialog is a modal one
      lang - OPT preferred language, defaults to defaultLang.
      oldPosition - OPT file position of previous, memorized download of DEnS-files
      oldDigest - OPT checksum for oldPosition. Both must be null, or not-null.
      windowsize - OPT for the dialog window
  • Method Details

    • get_newPosition

      @Opt public @Opt File get_newPosition()
      Output parameter: Only set != null when a new position has been entered by the user and the download succeeded.
    • get_newDigest

      @Opt public @eu.bandm.tools.annotations.Opt byte[] get_newDigest()
      Output parameter: Is != null iff get_newPosition()!= null.
    • get_tampered

      public boolean get_tampered()
      Output parameter: whether the current/new downloaded data has been locally altered.
    • muli

      protected String muli(String key, List<String> translations, Object... args)
      Definition of a new translation at the place of its application. Returns the translated text. (Not useful with MulIMessage sending!)
    • muli

      protected String muli(String key, List<String> translations)
      Definition of a new translation at the place of its application. Returns the translated text. (Not useful with MulIMessage sending!)
    • muli

      protected String muli(String key, String... pairs)
      Definition of a new translation at the place of its application. Returns the translated text. (Not useful with MulIMessage sending!)
    • appendStatusText

      protected void appendStatusText()
      Create text which describes the current information status, and which will appear as first. Is only called ONCE(1), at the very beginning. First inquiry situation:
      persistent info, but no old download
      persistent info, old download, tampered with
      persistent info, old download, unchanged
    • appendAlternatives

      protected void appendAlternatives()
      Create text which describes the possible alternatives
      download/download anew
      browse online
      browse local IFF local loaded
    • closeDialogLink

      protected String closeDialogLink()
      Text building block.
    • react

      protected void react()
      Reactions on situation/alternative texts:
      answer = "download"
      ===> file chooser
      =======> result = abort ====> restart loop
      =======> result = selected ====> safety question
      =======> answer = cancel ====> restart loop
      =======> answer = okay ====> start download, iff okay, calculate new checksum, set values of curPosition, curDigest and tampered.


      answer = "browseMet" "browseLocal"
      ===> browser remote control failed ===> show text to load page manually
      ===> browser remote control returns okay ===> show text to end dialog
      Overrides:
      react in class TextDialog