Exemple #1
0
 @Override
 public void init() {
   this.printer = new PrinterController(this);
   this.pos = new PosController(this);
   this.window = JSObject.getWindow(this);
   this.log("[Applet] Запущен");
 }
Exemple #2
0
 // Call a javascript function. Valid arguments can null, string and numbers.
 private synchronized void _func_call(String func, Collection args) throws Exception {
   ArrayList new_args = (ArrayList) prepare_call_args(args);
   String js_call = func + "(" + KMisc.list_join(new_args, ", ") + ")";
   JSObject.getWindow(this.applet_obj).eval("javascript:" + js_call);
   KMisc.sleep_ms(15); // It seems like (some browsers at least)
   // do not support rapid successive calls.
 }
  // send a netlogo command asynchronously; receive notice of completion at this callback
  public void asynchronousCommand(final String cmd, final String callback) {
    final JSObject window = JSObject.getWindow(this);

    if (SwingUtilities.isEventDispatchThread()) {
      Thread t =
          new Thread("command thread off of EDT") {
            public void run() {
              try {
                panel().command(cmd);
                window.call(callback, null);
              } catch (CompilerException e) {
                e.printStackTrace();
              }
            }
          };
      t.start();
    } else {
      try {
        panel().command(cmd);
        window.call(callback, null);
      } catch (CompilerException e) {
        e.printStackTrace();
      }
    }
  }
Exemple #4
0
  /** Inicia la ejecución del applet */
  public void start() {

    Log.log("Starting Applet");

    if (running) {
      return;
    }

    running = true;

    boolean jsObjectFound = false;
    jsBrowserWindow = null;

    try {
      Class.forName("netscape.javascript.JSObject");
      jsObjectFound = true;
    } catch (Exception e) {
      Log.log("Error instantiating JSObject class", e);
    }

    if (jsObjectFound) {
      try {
        jsBrowserWindow = JSObject.getWindow(this);
        Log.log("jsBrowserWindow: " + jsBrowserWindow);
      } catch (Exception e) {
        Log.log("Error in JSObject", e);
      }
    }

    Log.log("Applet Started");
  }
  // evaluate a netlogo report asynchronously; return the result to this callback as the argument
  public void asynchronousReport(final String cmd, final String callback) {
    final JSObject window = JSObject.getWindow(this);

    if (SwingUtilities.isEventDispatchThread()) {
      Thread t =
          new Thread("reporter thread off of EDT") {
            public void run() {
              Object retval = null;
              try {
                retval = panel().report(cmd);
                Object[] args = {retval};
                window.call(callback, args);
              } catch (CompilerException e) {
                e.printStackTrace();
              }
            }
          };
      t.start();
    } else {
      Object retval = null;
      try {
        retval = panel().report(cmd);
        Object[] args = {retval};
        window.call(callback, args);
      } catch (CompilerException e) {
        e.printStackTrace();
      }
    }
  }
    public void componentShown(ComponentEvent evt) {
      // sets the security manager to fix a bug in liveconnect in Safari on Mac
      if (key != -1) {
        return;
      }
      window = (JSObject) JSObject.getWindow(applet());

      AccessController.doPrivileged(
          new PrivilegedAction() {
            public Object run() {
              log("> init Robot");
              try {
                SecurityManager oldsecurity = System.getSecurityManager();
                boolean isOpera = false;
                try {
                  isOpera = (System.getProperty("browser").equals("Opera.plugin"));
                } catch (Exception e) {
                }
                try {
                  securitymanager = oldsecurity;
                  securitymanager.checkTopLevelWindow(null);
                  // xdomain
                  if (charMap == null) {
                    if (!confirm(
                        "DOH has detected that the current Web page is attempting to access DOH, but belongs to a different domain than the one you agreed to let DOH automate. If you did not intend to start a new DOH test by visiting this Web page, press Cancel now and leave the Web page. Otherwise, press OK to trust this domain to automate DOH tests.")) {
                      stop();
                      return null;
                    }
                  }
                  log("Found old security manager");
                } catch (Exception e) {
                  e.printStackTrace();
                  log("Making new security manager");
                  securitymanager = new RobotSecurityManager(isOpera, oldsecurity);
                  securitymanager.checkTopLevelWindow(null);
                  System.setSecurityManager(securitymanager);
                }
                // instantiate the Robot
                robot = new Robot();
              } catch (Exception e) {
                log("Error calling _init_: " + e.getMessage());
                key = -2;
                e.printStackTrace();
              }
              log("< init Robot");
              return null;
            }
          });
      if (key == -2) {
        // applet not trusted
        // start the test without it
        window.eval("doh.robot._appletDead=true;doh.run();");
      } else {
        // now that the applet has really started, let doh know it's ok to use it
        log("_initRobot");
        dohrobot = (JSObject) window.eval("doh.robot");
        dohrobot.call("_initRobot", new Object[] {applet()});
      }
    }
Exemple #7
0
 /** Redirects to screenbird homepage. */
 private void redirectWebPage() {
   try {
     JSObject win = JSObject.getWindow(this);
     System.out.println("Redirecting window");
     win.call("redirectHome", new Object[] {});
     System.out.println("Redirected window");
   } catch (Exception e) {
     System.err.println(e);
     System.err.println("Window already closed");
   }
 }
Exemple #8
0
 /**
  * Reads all available cookies
  *
  * @return The complete cookie string
  */
 protected String getCookie() {
   /*
    ** get all cookies for a document
    */
   try {
     JSObject myBrowser = JSObject.getWindow(applet);
     JSObject myDocument = (JSObject) myBrowser.getMember("document");
     String myCookie = (String) myDocument.getMember("cookie");
     if (myCookie != null && myCookie.length() > 0) return myCookie;
   } catch (Exception e) {
     LOG.error("getCookie failed", e);
   }
   return "?";
 }
Exemple #9
0
  /**
   * Using the Javascript located on the web page which opened this applet, we close the web page;
   * thus closing the applet with it.
   */
  public boolean closeApplet() {

    try {
      JSObject win = JSObject.getWindow(this);
      System.out.println("Closing window");
      win.call("closeRecorderForm", new Object[] {});
      System.out.println("Closed window");
    } catch (Exception e) {
      System.err.println(e);
      System.err.println("Window already closed");
    }

    return false;
  }
 // export world to a string variable which is passed as an argument to the js callback function
 public void exportWorldStateAsynchronously(final String callback) {
   final JSObject window = JSObject.getWindow(this);
   org.nlogo.awt.EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           StringWriter sw = new StringWriter();
           panel()
               .workspace()
               .exportWorld(new PrintWriter(sw)); // exportWorld(new PrintWriter(sw) );
           String state = sw.toString();
           Object[] args = {state};
           window.call(callback, args);
         }
       });
 }
  public void init() {

    win = JSObject.getWindow(this);
    toCopy = this.getParameter("tocopy");
    try {
      SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              JButton copyButton = new JButton("Copy to Clipboard");
              copyButton.addActionListener(new CopyToClipboard());
              add(copyButton);
            }
          });
    } catch (Exception e) {
      System.err.println("Error initializing ClipboardApplet.");
    }
  }
Exemple #12
0
  /**
   * Delete a cookie
   *
   * @param name The name of the cookie
   */
  protected void deleteCookie(String name) {
    setCookie(name, " ");
    /*
     **  delete a cookie, set the expiration in the past
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.MONTH, -1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + expires;
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");
      LOG.debug("del: " + s1);
      myDocument.setMember("cookie", s1);
    } catch (JSException e) {
      LOG.error("deleteCookie " + name + " failed", e);
    }
  }
 // import this string as a NL workd, and then call the js funciton when it's complete.
 public void importWorldFromString(final String str, final String callback) {
   final JSObject window = JSObject.getWindow(this);
   org.nlogo.awt.EventQueue.invokeLater(
       new Runnable() {
         public void run() {
           try {
             StringReader sr = new StringReader(str);
             panel().workspace().importWorld(sr);
             panel().commandLater("display");
             window.call(callback, null);
             // window.eval(callback);
           } catch (IOException e) {
             e.printStackTrace();
           } catch (CompilerException e) {
             e.printStackTrace();
           }
         }
       });
 }
Exemple #14
0
  @Override
  public void start() {
    Robocode robocode = new Robocode();

    URL url = getDocumentBase();
    FileUtil.setUrl(getCodeBase());

    selected_robotsx = getParameter("sel_robots");

    JSObject window = JSObject.getWindow(this);
    String summary = "Robocode Battle";
    LogUtil.setWindow(window);
    // LogUtil.log("codebase url:: " + url.getFile());
    LogUtil.log(summary);

    Properties prop = System.getProperties();
    System.out.println(prop.getProperty("java.class.path"));
    System.out.println(url.getFile());
    JPanel newContentPane = robocode.initialize(selected_robotsx);
    setContentPane(newContentPane);
  }
Exemple #15
0
  /**
   * Write a cookie
   *
   * @param name The name of the cookie
   * @param value The value to write
   */
  protected void setCookie(String name, String value) {
    value = cleanValue(value);
    /*
     **  write a cookie
     **    computes the expiration date, good for 1 month
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.YEAR, 1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + "=" + value + expires;
    LOG.debug(s1);
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");

      myDocument.setMember("cookie", s1);
      LOG.debug("set:" + s1);
    } catch (JSException e) {
      LOG.error("setCookie " + name + "=" + value + " failed", e);
    }
  }
  /** Inits the layout. */
  private void initLayout() {
    self = this;
    window = JSObject.getWindow(self);
    // fileLocation.setEditable(false);
    fileNameField = new JTextField(25);
    fileNameField.setEditable(false);
    fileNameField.setBackground(Color.WHITE);

    chooseBtn = new JButton();
    chooseBtn.setText(getMessage(MessageCode.FTP_FILE_CHOOSE));

    uploadBtn = new JButton();
    uploadBtn.setText(getMessage(MessageCode.FTP_FILE_UPLOAD));
    uploadBtn.setEnabled(false);

    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(getMessage(MessageCode.FTP_FILECHOOSER_TITLE));
    fileChooser.setAcceptAllFileFilterUsed(false);

    final boolean filterTypes = StringUtils.isNotBlank(allowTypes);
    final boolean filterMaxSize = maxSize > 0;

    if (filterTypes || filterMaxSize) {
      fileChooser.setFileFilter(
          new FileFilter() {
            @Override
            public String getDescription() {
              return filterTypes
                  ? getMessage(MessageCode.ALLOW_ALL_FILE)
                  : getMessage(MessageCode.ALLOW_SOME_FILE) + allowTypes;
            }

            @Override
            public boolean accept(File f) {

              if (f.isDirectory()) {
                return true;
              }

              boolean flag = true;
              if (filterTypes) {
                flag = false;
                String ext = FilenameUtils.getExtension(f.getName());
                String[] types = StringUtils.split(allowTypes, ",");
                for (String t : types) {
                  if (StringUtils.equalsIgnoreCase(t, ext)) {
                    flag = true;
                    break;
                  }
                }
              }

              if (flag && filterMaxSize) {
                flag = FileUtils.sizeOf(f) <= maxSize;
              }

              return flag;
            }
          });
    }

    progressInfo = new JLabel(getMessage(MessageCode.FTP_UPLOAD_PROGRESS));

    progressBar = new JProgressBar(0, 100);
    progressBar.setPreferredSize(new Dimension(380, 20));
    // progressBar.setString("请选择文件");
    progressBar.setStringPainted(true);
    progressBar.setBorderPainted(true);
    // progressBar.setBackground(Color.gray);
    // progressBar.setForeground(Color.blue);

    progressPanel = new JPanel();
    progressPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    progressPanel.add(progressInfo);
    progressPanel.add(progressBar);
    progressPanel.setBackground(Color.WHITE);
    progressPanel.setVisible(false);

    // main.add(fileLocation);
    selectPanel = new JPanel();
    selectPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    selectPanel.add(fileNameField);
    selectPanel.add(chooseBtn);
    selectPanel.add(uploadBtn);
    selectPanel.setBackground(Color.WHITE);

    GridLayout layout = new GridLayout(2, 1);
    Container container = self.getContentPane();
    container.setLayout(layout);
    container.add(selectPanel);
    container.add(progressPanel);
    container.setBackground(Color.WHITE);
  }
 public JSListener(String callbackfunction, Applet appl) {
   window = JSObject.getWindow(appl);
   callback = callbackfunction;
 }
Exemple #18
0
 public void init() {
   jso = JSObject.getWindow(this);
 }
  public void init() {
    window = JSObject.getWindow(this);

    String initStr = "JToJSGet applet initialized.";
    System.out.println(initStr);
  }