All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openscience.jmol.app.webexport.Widgets Maven / Gradle / Ivy

There is a newer version: 14.31.10
Show newest version
/* $RCSfile$
 * $Author jonathan gutow$
 * Updated Dec. 2015 by Angel Herraez
 * valid for JSmol
 *
 * Copyright (C) 2005-2016  The Jmol Development Team
 *
 * Contact: [email protected]
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301, USA.
 */
package org.openscience.jmol.app.webexport;

import org.jmol.i18n.GT;

import javajs.util.CU;
import javajs.util.P3;

class Widgets { 
  
  // group of javascript widgets to allow user input to Jmol

  Widget[] widgetList = new Widget[5];

  Widgets() {
    // this should just be a list of available widgets
    widgetList[0] = new SpinOnWidget();
    widgetList[1] = new BackgroundColorWidget();
    widgetList[2] = new StereoViewWidget();
    widgetList[3] = new AnimationWidget();
    widgetList[4] = new ConsoleWidget();
    // widgetList[3] = new DownLoadWidget();
  }

  abstract class Widget {
    String name;

    /**
     * 
     * Each Widget must implement this function and make sure to use
     * the appletID number to specify the target applet i.e. "JmolApplet(appletID)".
     * NOTE anything that must be translated in the web page should be wrapped in both a call to
     * GT.escapeHTML and GT._ as in the following: GT.escapeHTML(GT._("text to translate"))
     * @param appletID
     * @param instance
     * @return  the JavaScript and html to implement the widget
     */
    abstract String getJavaScript(int appletID, JmolInstance instance);

    /**
     *  
     *  A COPY OF THIS .JS FILE MUST BE STORED IN THE html PART OF WEBEXPORT
     *  
     * @return  "none" (no file needed) or javascript file necessary to implement the widget
     */
    abstract String getJavaScriptFileName();// returns the name of the

    /**
     * The list of files returned by this function should contain the full path to
     * each file.  The only exception is that files that only contain a filename
     * will be assumed to be in the html section of WebExport.
     * @return string of filenames.
     */
    abstract String[] getSupportFileNames();// returns array of support file names.
    //These file names should include the full path within the Java application jar.
    //files stored in html part of WebExport will be found even if only the filename
    //is given.

  }

  class SpinOnWidget extends Widget {
    SpinOnWidget() {
      name = GT._("Spin on/off");
    }
    @Override
    String[] getSupportFileNames(){
      String[] fileNames = new String[0];
      return(fileNames);
    }
    @Override
    String getJavaScriptFileName() {
      return "none";
    }

    @Override
    String getJavaScript(int appletID, JmolInstance instance) {
      return ""
          + "";
    }
  }

  class BackgroundColorWidget extends Widget {
    BackgroundColorWidget() {
      name = GT._("Background Color");
    }

    @Override
    String getJavaScriptFileName() {
      return ("JmolColorPicker.js");
    }
    
    @Override
    String[] getSupportFileNames(){
      String[] fileNames = new String[0];
      return(fileNames);
    }
    
    @Override
    String getJavaScript(int appletID, JmolInstance instance) {
      P3 ptRGB = CU.colorPtFromInt(instance.bgColor, null);
      return "
" + GT.escapeHTML(GT._("background color:")) + "
"; } } class StereoViewWidget extends Widget { StereoViewWidget() { name = GT._("Stereo Viewing"); } @Override String getJavaScriptFileName() { return "none"; } @Override String[] getSupportFileNames(){ String[] fileNames = new String[0]; return(fileNames); } @Override String getJavaScript(int appletID, JmolInstance instance) { return ""; } } class AnimationWidget extends Widget { AnimationWidget() { name = GT._("Animation Control"); } @Override String getJavaScriptFileName() { return ("JmolAnimationCntrl.js"); } @Override String[] getSupportFileNames(){ String[] fileNames = new String[9]; String imagePath = "org/openscience/jmol/app/images/"; fileNames[0] = imagePath+"lastButton.png"; fileNames[1] = imagePath+"playButton.png"; fileNames[2] = imagePath+"playLoopButton.png"; fileNames[3] = imagePath+"playOnceButton.png"; fileNames[4] = imagePath+"playPalindromeButton.png"; fileNames[5] = imagePath+"prevButton.png"; fileNames[6] = imagePath+"pauseButton.png"; fileNames[7] = imagePath+"nextButton.png"; fileNames[8] = imagePath+"firstButton.png"; return(fileNames); } @Override String getJavaScript(int appletID, JmolInstance instance) { String jsString = "
" + "
" + GT.escapeHTML(GT._("Animation")) + "
" + "
" + "" + "" + "" + "" + "" + "" + "
" + "
" + "" + GT.escapeHTML(GT._("Mode:"))+"" + "" + "" + "" + "
" + "
"; return (jsString); } } class ConsoleWidget extends Widget { ConsoleWidget() { name = GT._("Open Console Button"); } @Override String getJavaScriptFileName() { return ("none"); } @Override String[] getSupportFileNames(){ String[] fileNames = new String[0]; return(fileNames); } @Override String getJavaScript(int appletID, JmolInstance instance) { return (""); } } class DownLoadWidget extends Widget { //not yet implemented DownLoadWidget() { name = GT._("Download view"); } @Override String getJavaScriptFileName() { // TODO return ("none"); } @Override String[] getSupportFileNames(){ String[] fileNames = new String[0]; return(fileNames); } @Override String getJavaScript(int appletID, JmolInstance instance) { // TODO return (GT._("unimplemented")); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy