Esempio n. 1
0
 public String saveAsFile(boolean accessingAsFile) throws IOException {
   File file = new SikuliIDEFileChooser(SikuliIDE.getInstance(), accessingAsFile).save();
   if (file == null) {
     return null;
   }
   String bundlePath = FileManager.slashify(file.getAbsolutePath(), false);
   if (!file.getAbsolutePath().endsWith(".sikuli")) {
     bundlePath += ".sikuli";
   }
   if (FileManager.exists(bundlePath)) {
     int res =
         JOptionPane.showConfirmDialog(
             null,
             SikuliIDEI18N._I("msgFileExists", bundlePath),
             SikuliIDEI18N._I("dlgFileExists"),
             JOptionPane.YES_NO_OPTION);
     if (res != JOptionPane.YES_OPTION) {
       return null;
     }
   } else {
     FileManager.mkdir(bundlePath);
   }
   try {
     saveAsBundle(bundlePath, (SikuliIDE.getInstance().getCurrentFileTabTitle()));
     if (Settings.isMac()) {
       if (!Settings.handlesMacBundles) {
         makeBundle(bundlePath, accessingAsFile);
       }
     }
   } catch (IOException iOException) {
   }
   return getCurrentShortFilename();
 }
Esempio n. 2
0
 protected static boolean addToClasspath(String jar) {
   Method method;
   URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
   URL[] urls = sysLoader.getURLs();
   log0(lvl, "before adding to classpath: " + jar);
   for (int i = 0; i < urls.length; i++) {
     log0(lvl, "%d: %s", i, urls[i]);
   }
   Class sysclass = URLClassLoader.class;
   try {
     jar = FileManager.slashify(new File(jar).getAbsolutePath(), false);
     if (Settings.isWindows()) {
       jar = "/" + jar;
     }
     URL u = (new URI("file", jar, null)).toURL();
     method = sysclass.getDeclaredMethod("addURL", new Class[] {URL.class});
     method.setAccessible(true);
     method.invoke(sysLoader, new Object[] {u});
   } catch (Exception ex) {
     log0(-1, ex.getMessage());
     return false;
   }
   urls = sysLoader.getURLs();
   log0(lvl, "after adding to classpath");
   for (int i = 0; i < urls.length; i++) {
     log0(lvl, "%d: %s", i, urls[i]);
   }
   return true;
 }
Esempio n. 3
0
 @Override
 public void typeKey(int key) {
   Debug.log(3, "Robot: doType: %s ( %d )", KeyEvent.getKeyText(key), key);
   if (Settings.isMac()) {
     if (key == Key.toJavaKeyCodeFromText("#N.")) {
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C."));
       return;
     } else if (key == Key.toJavaKeyCodeFromText("#T.")) {
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C."));
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C."));
       return;
     } else if (key == Key.toJavaKeyCodeFromText("#X.")) {
       key = Key.toJavaKeyCodeFromText("#T.");
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A."));
       return;
     }
   }
   doType(KeyMode.PRESS_RELEASE, key);
   waitForIdle();
 }
Esempio n. 4
0
 public App focus(int num) {
   Debug.history("App.focus " + this.toString() + " #" + num);
   if (_pid != 0) {
     if (_osUtil.switchApp(_pid, num) == 0) {
       Debug.error("App.focus failed: " + _appName + "(" + _pid + ") not found");
       return null;
     }
   } else {
     boolean failed = false;
     if (Settings.isWindows()) {
       _pid = _osUtil.switchApp(_appName, num);
       if (_pid == 0) {
         failed = true;
       }
     } else {
       if (_osUtil.switchApp(_appName, num) < 0) {
         failed = true;
       }
     }
     if (failed) {
       Debug.error("App.focus failed: " + _appName + " not found");
       return null;
     }
   }
   return this;
 }
Esempio n. 5
0
 public String saveFile() throws IOException {
   if (_editingFile == null) {
     return saveAsFile(Settings.isMac());
   } else {
     ImagePath.remove(_srcBundlePath);
     writeSrcFile();
     return getCurrentShortFilename();
   }
 }
Esempio n. 6
0
 public App open() {
   if (Settings.isWindows() || Settings.isLinux()) {
     int pid = _osUtil.openApp(_appName);
     _pid = pid;
     Debug.history("App.open " + this.toString());
     if (pid == 0) {
       Debug.error("App.open failed: " + _appName + " not found");
       return null;
     }
   } else {
     Debug.history("App.open " + this.toString());
     if (_osUtil.openApp(_appName) < 0) {
       Debug.error("App.open failed: " + _appName + " not found");
       return null;
     }
   }
   return this;
 }
Esempio n. 7
0
 public static void printArgs() {
   if (Debug.getDebugLevel() < lvl) {
     return;
   }
   String[] args = Settings.getSikuliArgs();
   if (args.length > 0) {
     Debug.log(lvl, "--- Sikuli parameters ---");
     for (int i = 0; i < args.length; i++) {
       Debug.log(lvl, "%d: %s", i + 1, args[i]);
     }
   }
   args = Settings.getArgs();
   if (args.length > 0) {
     Debug.log(lvl, "--- User parameters ---");
     for (int i = 0; i < args.length; i++) {
       Debug.log(lvl, "%d: %s", i + 1, args[i]);
     }
   }
 }
 public void prompt(String msg) {
   captureScreen(scrOCP);
   Rectangle rect = new Rectangle(scrOCP.getBounds());
   this.setBounds(rect);
   promptMsg = msg;
   Debug.log(
       4,
       "CapturePrompt: [%d,%d (%d, %d)] %s",
       rect.x,
       rect.y,
       rect.width,
       rect.height,
       promptMsg);
   this.setVisible(true);
   if (!Settings.isJava7()) {
     if (Settings.isMac()) {
       SysUtil.getOSUtil().bringWindowToFront(this, false);
     }
   }
   this.requestFocus();
 }
Esempio n. 9
0
 public File getCurrentFile(boolean shouldSave) {
   if (shouldSave && _editingFile == null && isDirty()) {
     try {
       saveAsFile(Settings.isMac());
     } catch (IOException e) {
       Debug.error(
           me + "getCurrentFile: Problem while trying to save %s\n%s",
           _editingFile.getAbsolutePath(),
           e.getMessage());
     }
   }
   return _editingFile;
 }
Esempio n. 10
0
 @Override
 public void releaseModifiers(int modifiers) {
   if ((modifiers & KeyModifier.SHIFT) != 0) {
     keyRelease(KeyEvent.VK_SHIFT);
   }
   if ((modifiers & KeyModifier.CTRL) != 0) {
     keyRelease(KeyEvent.VK_CONTROL);
   }
   if ((modifiers & KeyModifier.ALT) != 0) {
     keyRelease(KeyEvent.VK_ALT);
   }
   if ((modifiers & KeyModifier.META) != 0) {
     if (Settings.isWindows()) {
       keyRelease(KeyEvent.VK_WINDOWS);
     } else {
       keyRelease(KeyEvent.VK_META);
     }
   }
 }
Esempio n. 11
0
 private void checkMousePosition(Location p) {
   PointerInfo mp = MouseInfo.getPointerInfo();
   Point pc;
   if (mp == null) {
     Debug.error(
         "RobotDesktop: checkMousePosition: MouseInfo.getPointerInfo invalid\nafter move to %s",
         p);
   } else {
     pc = mp.getLocation();
     if (pc.x != p.x || pc.y != p.y) {
       Debug.error(
           "RobotDesktop: checkMousePosition: should be %s\nbut after move is %s"
               + "\nPossible cause: Mouse actions are blocked generally or by the frontmost application."
               + (Settings.isWindows()
                   ? "\nYou might try to run the SikuliX stuff as admin."
                   : ""),
           p,
           new Location(pc));
     }
   }
 }
Esempio n. 12
0
 protected void showTarget(Location loc, double secs) {
   if (Settings.isShowActions()) {
     ScreenHighlighter overlay = new ScreenHighlighter(this, null);
     overlay.showTarget(loc, (float) secs);
   }
 }
Esempio n. 13
0
  public void initBeforeLoad(String scriptType, boolean reInit) {
    String scrType = null;
    boolean paneIsEmpty = false;

    if (scriptType == null) {
      scriptType = Settings.EDEFAULT;
      paneIsEmpty = true;
    }

    if (Settings.EPYTHON.equals(scriptType)) {
      scrType = Settings.CPYTHON;
      _indentationLogic = SikuliIDE.getIDESupport(scriptType).getIndentationLogic();
      _indentationLogic.setTabWidth(pref.getTabWidth());
    } else if (Settings.ERUBY.equals(scriptType)) {
      scrType = Settings.CRUBY;
      _indentationLogic = null;
    }

    if (scrType != null) {
      sikuliContentType = scrType;
      editorKit = new SikuliEditorKit();
      editorViewFactory = (EditorViewFactory) editorKit.getViewFactory();
      setEditorKit(editorKit);
      setContentType(scrType);

      if (_indentationLogic != null) {
        pref.addPreferenceChangeListener(
            new PreferenceChangeListener() {
              @Override
              public void preferenceChange(PreferenceChangeEvent event) {
                if (event.getKey().equals("TAB_WIDTH")) {
                  _indentationLogic.setTabWidth(Integer.parseInt(event.getNewValue()));
                }
              }
            });
      }
    }

    initKeyMap();

    if (transferHandler == null) {
      transferHandler = new MyTransferHandler();
    }
    setTransferHandler(transferHandler);
    _highlighter = new EditorCurrentLineHighlighter(this);

    addCaretListener(_highlighter);

    setFont(new Font(pref.getFontName(), Font.PLAIN, pref.getFontSize()));
    setMargin(new Insets(3, 3, 3, 3));
    setBackground(Color.WHITE);
    if (!Settings.isMac()) {
      setSelectionColor(new Color(170, 200, 255));
    }

    updateDocumentListeners();

    addKeyListener(this);
    addCaretListener(this);
    popMenuImage = new SikuliIDEPopUpMenu("POP_IMAGE", this);
    if (!popMenuImage.isValidMenu()) {
      popMenuImage = null;
    }

    if (paneIsEmpty || reInit) {
      //			this.setText(String.format(Settings.TypeCommentDefault, getSikuliContentType()));
      this.setText("");
    }
    SikuliIDE.getStatusbar().setCurrentContentType(getSikuliContentType());
    Debug.log(3, "InitTab: (%s)", getSikuliContentType());
    if (!Settings.hasTypeRunner(getSikuliContentType())) {
      SikuliX.popup(
          "No installed runner supports ("
              + getSikuliContentType()
              + ")\n"
              + "Trying to run the script will crash IDE!",
          "... serious problem detected!");
    }
  }