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

org.openscience.jmol.app.JmolApp Maven / Gradle / Ivy

There is a newer version: 14.31.10
Show newest version
/* $RCSfile$
 * $Author: hansonr $
 * $Date: 2009-06-26 23:35:44 -0500 (Fri, 26 Jun 2009) $
 * $Revision: 11131 $
 *
 * Copyright (C) 2000-2005  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 St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.openscience.jmol.app;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.io.File;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Map;
import java.util.Scanner;

import javajs.util.PT;

import org.jmol.i18n.GT;
import org.jmol.util.Logger;
import org.jmol.viewer.Viewer;
import org.jmol.api.JmolAppAPI;
import org.jmol.api.JmolViewer;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.HelpFormatter;

public class JmolApp implements JmolAppAPI {

  /**
   * The data model.
   */

  public int port;
  public int startupWidth, startupHeight;
  public Point border;
  public boolean haveBorder;

  public File userPropsFile;
  public HistoryFile historyFile, pluginFile;

  public boolean haveConsole = true;
  public boolean haveDisplay = true;
  public boolean splashEnabled = true;
  public boolean isDataOnly;
  public boolean isKiosk;
  public boolean isPrintOnly;
  public boolean isSilent;
  public Mapinfo = new Hashtable();
  public Point jmolPosition;
  public float autoAnimationDelay = 0.2f; // sec
  
  private String modelFilename;
  private String scriptFilename;
  private String script1 = "";
  private String script2 = "";
  private boolean scanInput;
  private String menuFile;

  
  //private JmolViewer vwr;
  //private JmolAdapter modelAdapter;

  public JmolApp() {
    // defer parsing until we can set a few options ourselves
  }
  
  /**
   * standard Jmol application entry point
   * @param args
   */
  public JmolApp(String[] args) {
    
    if (System.getProperty("javawebstart.version") != null) {

      // If the property is found, Jmol is running with Java Web Start. To fix
      // bug 4621090, the security manager is set to null.
      System.setSecurityManager(null);
    }
    if (System.getProperty("user.home") == null) {
      System.err.println(GT
          ._("Error starting Jmol: the property 'user.home' is not defined."));
      System.exit(1);
    }
    File ujmoldir = new File(new File(System.getProperty("user.home")), ".jmol");
    ujmoldir.mkdirs();
    userPropsFile = new File(ujmoldir, "properties");
    historyFile = new HistoryFile(new File(ujmoldir, "history"),
        "Jmol's persistent values");
    pluginFile = new HistoryFile(new File(ujmoldir, "plugins"),
        "Jmol plugin persistent values");

    
    parseCommandLine(args);
  }

  public void parseCommandLine(String[] args) {

    Options options = getOptions();

    CommandLine line = null;
    try {
      CommandLineParser parser = new PosixParser();
      line = parser.parse(options, args);
    } catch (ParseException exception) {
      System.err.println("Unexpected exception: " + exception.toString());
    }
    
    args = line.getArgs();
    if (args.length > 0) {
        modelFilename = args[0];
    }
    checkOptions(line, options);

  }

  private Options getOptions() {
    Options options = new Options();

    options.addOption("a","autoanimationdelay", true, GT
            ._("delay time in seconds for press-and-hold operation of toolbar animation buttons (default 0.2; numbers > 10 assumed to be milliseconds; set to 0 to disable)"));

    options.addOption("b", "backgroundtransparent", false,
        GT._("transparent background"));

    options.addOption("C", "checkload", false,
        GT._("check script syntax only - with file loading"));
    options.addOption("c", "check", false,
        GT._("check script syntax only - no file loading"));

    OptionBuilder.withValueSeparator();
    options.addOption("D", "property=value", true,
        GT._("supported options are given below"));
    options.addOption("d", "debug", false, GT._("debug"));

    options.addOption("g", "geometry", true,
        GT.o(GT._("window width x height, e.g. {0}"), "-g500x500"));

    options.addOption("h", "help", false, GT._("give this help page"));

    options.addOption("I", "input", false,
        GT._("allow piping of input from System.Input"));
    options.addOption("i", "silent", false, GT._("silent startup operation"));

    options.addOption("J", "jmolscript1", true,
        GT._("Jmol script to execute BEFORE -s option"));

    options.addOption("j","jmolscript2", true, GT
        ._("Jmol script to execute AFTER -s option"));

    options.addOption("k", "kiosk", false, GT._("kiosk mode -- no frame"));

    options.addOption("L", "nosplash", false,
        GT._("start with no splash screen"));
    options.addOption("l", "list", false,
        GT._("list commands during script execution"));

    options.addOption("M","multitouch", true, GT
        ._("use multitouch interface (requires \"sparshui\" parameter"));

    options.addOption("m","menu", true, GT._("menu file to use"));

    options.addOption("n", "nodisplay", false,
        GT._("no display (and also exit when done)"));

    options.addOption("o", "noconsole", false,
        GT._("no console -- all output to sysout"));

    options.addOption("P","port", true,GT
        ._("port for JSON/MolecularPlayground-style communication"));

    options.addOption("p", "printOnly", false,
        GT._("send only output from print messages to console (implies -i)"));

    options.addOption("q","quality", true, GT
            ._("JPG image quality (1-100; default 75) or PNG image compression (0-9; default 2, maximum compression 9)"));

    options.addOption("R", "restricted", false,
        GT._("restrict local file access"));
    options.addOption("r", "restrictSpt", false,
        GT._("restrict local file access (allow reading of SPT files)"));

    options.addOption("s","script", true, GT
        ._("script file to execute or '-' for System.in"));

    options.addOption("T","headlessmaxtime", true, GT._("headless max time (sec)"));

    options.addOption("t", "threaded", false,
        GT._("independent command thread"));

    options.addOption("U", "plugin", true, GT._("plugin to start initially"));

    options.addOption("w","write", true,GT.o(GT._("{0} or {1}:filename"),
        new Object[] { "CLIP", "GIF|JPG|JPG64|PNG|PPM" }));

    options.addOption("x", "exit", false,
        GT._("exit after script (implicit with -n)"));

    return options;
  }
  
  class OptSort implements Comparator




© 2015 - 2024 Weber Informatics LLC | Privacy Policy