Package com.data2semantics.yasgui.client.configmenu

Source Code of com.data2semantics.yasgui.client.configmenu.Compatibilities

package com.data2semantics.yasgui.client.configmenu;

/*
* #%L
* YASGUI
* %%
* Copyright (C) 2013 Laurens Rietveld
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/

import com.data2semantics.yasgui.client.View;
import com.data2semantics.yasgui.client.helpers.JsMethods;
import com.data2semantics.yasgui.client.helpers.LocalStorageHelper;
import com.data2semantics.yasgui.client.settings.Imgs;
import com.data2semantics.yasgui.client.settings.ZIndexes;
import com.data2semantics.yasgui.shared.StaticConfig;
import com.google.gwt.storage.client.Storage;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class Compatibilities extends Window {
 
  private static int HEIGHT = 290;
  private static int WIDTH = 700;
  private static int ROW_HEIGHT = 40;
  private static int BUTTON_WIDTH = 150;
 
  private static String URL_COMPATIBILTIES_LOCAL_STORAGE = "http://caniuse.com/#feat=namevalue-storage";
  private static String URL_COMPATIBILTIES_HISTORY = "http://caniuse.com/#search=history";
  private static String URL_COMPATIBILITIES_DOWNLOAD_ATTRIBUTE = "http://caniuse.com/#feat=download";
  private static String URL_COMPATIBILITIES_DOWNLOAD_FILE = "http://caniuse.com/#feat=bloburls";
  private static String URL_COMPATIBILITIES_APPCACHE = "http://caniuse.com/offline-apps";
 
  public static int VERSION_NUMBER = 4; //used for determining whether we need warning icon (i.e. something not compatible, and not shown before)
  private boolean html5StorageSupported = false;
  private boolean downloadAttributeSupported = false;
  private boolean downloadFileSupported = false;
  private boolean historySupported = false;
  private boolean offlineSupported = false;
  private boolean allSupported = false;
  private View view;
  private VLayout layout = new VLayout();;
  public Compatibilities(View view) {
    this.view = view;
    setHeight(HEIGHT);
    setWidth(WIDTH);
    setZIndex(ZIndexes.MODAL_WINDOWS);
    setTitle("Features supported by your browser");
    setIsModal(true);
    setDismissOnOutsideClick(true);
    setAutoCenter(true);
    layout.setMargin(10);
    addItem(layout);
    checkCompatibilities();
  }
 
  private void checkCompatibilities() {
    html5StorageSupported = Storage.isLocalStorageSupported();
    downloadFileSupported = JsMethods.stringToDownloadSupported();
    downloadAttributeSupported = JsMethods.downloadAttributeSupported();
    historySupported = JsMethods.historyApiSupported();
    offlineSupported = JsMethods.offlineSupported();
    allSupported = (html5StorageSupported && downloadFileSupported && downloadAttributeSupported && historySupported);
  }
 
  public boolean allSupported() {
    return allSupported;
  }
 
 
 
  public void drawContent() {
    LocalStorageHelper.setCompatibilitiesShown(StaticConfig.VERSION_ID);
   
    String html = "<div style='width:100%;text-align:center;'>You are using <strong>" + JsMethods.getBrowserName() + " " + JsMethods.getBrowserVersionNumber() + "</strong> on <strong>" + JsMethods.GetBrowserOs() + "</strong>. ";
    if (allSupported) {
      html += "Congrats! Your browser supports all YASGUI functionality";
    } else {
      html += "We recommend the latest version of Chrome";
    }
    html += "</div>";
    HTMLFlow header = new HTMLFlow();
    header.setWidth100();
    header.setLayoutAlign(Alignment.CENTER);
    header.setContents(html);
    header.setMargin(10);
    layout.addMember(header);
   
    drawHtml5LocalStorage();
    drawDownloadFunctionality();
    drawDownloadFilenameFunctionality();
    drawHistoryFunctionality();
    drawOfflineFunctionality();
    draw();
   
    //ok, so we've shown the stuff. reload the menu button, as we might still have an exclamation mark there
    view.getElements().redrawConfigMenu();
  }
  private void drawOfflineFunctionality() {
    HLayout hlayout = new HLayout();
    hlayout.setHeight(ROW_HEIGHT);
   
    hlayout.addMember(getIcon(offlineSupported));
    hlayout.addMember(getRowName("Offline Functionality"));
    if (offlineSupported) {
      hlayout.addMember(getExplanation("Supported by your browser. YASGUI will still function without internet connection (e.g. on localhost endpoints)"));
    } else {
      hlayout.addMember(getExplanation("Not supported by your browser. You won't be able to use YASGUI without internet connection (e.g. on localhost endpoints)"));
    }
    hlayout.addMember(getLink(URL_COMPATIBILITIES_APPCACHE));
   
    layout.addMember(hlayout);
   
  }

  private void drawHistoryFunctionality() {
    HLayout hlayout = new HLayout();
    hlayout.setHeight(ROW_HEIGHT);
   
    hlayout.addMember(getIcon(historySupported));
    hlayout.addMember(getRowName("History"));
    if (historySupported) {
      hlayout.addMember(getExplanation("Supported by your browser. You can use the browser 'back' button to return to previous YASGUI states"));
    } else {
      hlayout.addMember(getExplanation("Not supported by your browser. You won't be able to go back (using the browser 'back' button) to previous YASGUI states"));
    }
    hlayout.addMember(getLink(URL_COMPATIBILTIES_HISTORY));
   
    layout.addMember(hlayout);
  }
 
  private void drawHtml5LocalStorage() {
    HLayout hlayout = new HLayout();
    hlayout.setHeight(ROW_HEIGHT);
   
    hlayout.addMember(getIcon(html5StorageSupported));
    hlayout.addMember(getRowName("Local Storage"));
    if (html5StorageSupported) {
      hlayout.addMember(getExplanation("Supported by your browser. Allows for client-side caching, resulting in faster page loads"));
    } else {
      hlayout.addMember(getExplanation("Not supported by your browser. This results in slightly slower page loads, as client-side caching is not possible"));
    }
    hlayout.addMember(getLink(URL_COMPATIBILTIES_LOCAL_STORAGE));
   
    layout.addMember(hlayout);
  }
 
  private void drawDownloadFunctionality() {
    HLayout hlayout = new HLayout();
    hlayout.setHeight(ROW_HEIGHT);
   
    hlayout.addMember(getIcon(downloadFileSupported));
    hlayout.addMember(getRowName("Clientside File Downloads"));
    if (downloadFileSupported) {
      hlayout.addMember(getExplanation("Supported by your browser. Allows you to download query results to file"));
    } else {
      hlayout.addMember(getExplanation("Not supported by your browser. You are not able to download query results to file"));
    }
   
    hlayout.addMember(getLink(URL_COMPATIBILITIES_DOWNLOAD_FILE));
   
    layout.addMember(hlayout);
  }
 
  private void drawDownloadFilenameFunctionality() {
    HLayout hlayout = new HLayout();
    hlayout.setHeight(ROW_HEIGHT);
   
    hlayout.addMember(getIcon(downloadAttributeSupported));
    hlayout.addMember(getRowName("Download attributes"));
    if (downloadAttributeSupported) {
      hlayout.addMember(getExplanation("Supported by your browser. This allows the files you download to have 'sensible' names, instead of a long unrecognizable ID"));
    } else {
      hlayout.addMember(getExplanation("Not supported by your browser. Files you download will have a strange ID as filename, instead of a more sensible name"));
    }
   
    hlayout.addMember(getLink(URL_COMPATIBILITIES_DOWNLOAD_ATTRIBUTE));
   
    layout.addMember(hlayout);
  }
 
 
 
  private Img getIcon(boolean supported) {
    Img img;
    if (supported) {
      img = new Img(Imgs.CHECKBOX.get());
    } else {
      img = new Img(Imgs.CROSS.get());
    }
    img.setLayoutAlign(VerticalAlignment.CENTER);
    img.setValign(VerticalAlignment.CENTER);
    img.setHeight(32);
    img.setWidth(32);
    img.setMargin(5);
    return img;
  }
 
  private HTMLFlow getRowName(String string) {
    string = "<div style='height:" + Integer.toString(ROW_HEIGHT) + "px;'><img src='" + Imgs.OTHER_IMAGES_DIR.getUnprocessed() + Imgs.OTHER_1PX.get() + "' alt=\"\" style=\"width:1px; height:100%; vertical-align:middle\" /><strong>" + string + "</strong></div>";
    HTMLFlow label = new HTMLFlow(string);
    label.setWidth(150);
    label.setHeight100();
    label.setLayoutAlign(VerticalAlignment.CENTER);
    return label;
  }
 
  private Button getLink(final String url) {
    Button moreInfo = new Button("Show Compatible Browsers");
    moreInfo.setWidth(BUTTON_WIDTH);
    moreInfo.setLayoutAlign(VerticalAlignment.CENTER);
    moreInfo.addClickHandler(new ClickHandler(){

      @Override
      public void onClick(ClickEvent event) {
        com.google.gwt.user.client.Window.open(url, "_blank", "");
      }});
    return moreInfo;
  }
 
  private Label getExplanation(String string){
    Label label = new Label(string);
    label.setWidth100();
    label.setMargin(5);
    return label;
  }
 
}
TOP

Related Classes of com.data2semantics.yasgui.client.configmenu.Compatibilities

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.