コード例 #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();
 }
コード例 #2
0
  private void savePrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    pref.setCaptureDelay((Double) _spnDelay.getValue());
    pref.setCaptureHotkey(_cap_hkey);
    pref.setCaptureHotkeyModifiers(_cap_mod);
    pref.setAutoNamingMethod(
        _radTimestamp.isSelected()
            ? UserPreferences.AUTO_NAMING_TIMESTAMP
            : _radOCR.isSelected()
                ? UserPreferences.AUTO_NAMING_OCR
                : UserPreferences.AUTO_NAMING_OFF);
    if (_old_cap_hkey != _cap_hkey || _old_cap_mod != _cap_mod) {
      ide.removeCaptureHotkey(_old_cap_hkey, _old_cap_mod);
      ide.installCaptureHotkey(_cap_hkey, _cap_mod);
    }
    pref.setCheckUpdate(_chkAutoUpdate.isSelected());

    pref.setExpandTab(_chkExpandTab.isSelected());
    pref.setTabWidth((Integer) _spnTabWidth.getValue());

    pref.setFontName((String) _cmbFontName.getSelectedItem());
    pref.setFontSize((Integer) _spnFontSize.getValue());

    Locale locale = (Locale) _cmbLang.getSelectedItem();
    pref.setLocale(locale);
    I18N.setLocale(locale);
  }
コード例 #3
0
 void takeScreenshot() {
   SikuliIDE ide = SikuliIDE.getInstance();
   ide.setVisible(false);
   try {
     Thread.sleep(500);
   } catch (Exception e) {
   }
   _simg = (new ScreenUnion()).getScreen().capture();
   ide.setVisible(true);
 }
コード例 #4
0
  private void updateFontPreview() {
    SikuliIDE ide = SikuliIDE.getInstance();
    Font font =
        new Font(
            (String) _cmbFontName.getSelectedItem(), Font.PLAIN, (Integer) _spnFontSize.getValue());

    SikuliCodePane codePane = SikuliIDE.getInstance().getCurrentCodePane();
    if (Utils.typeOfCodePane(codePane) == Utils.SikuliCodePaneType.SIKULI_PANE_TYPE_TEXT) {
      // preview only supported on text code panes
      SikuliTextPane textPane = (SikuliTextPane) (codePane.getComponent());
      textPane.setFont(font);
    }
  }
コード例 #5
0
 @Override
 public void actionPerformed(ActionEvent e) {
   actionPerformedUpdates(_parent);
   _imgBtn.getWindow().close();
   _parent.dispose();
   SikuliIDE.getInstance().getCurrentCodePane().setDirty(setDirty(false));
 }
コード例 #6
0
 public boolean close() throws IOException {
   if (isDirty()) {
     Object[] options = {
       SikuliIDEI18N._I("yes"), SikuliIDEI18N._I("no"), SikuliIDEI18N._I("cancel")
     };
     int ans =
         JOptionPane.showOptionDialog(
             this,
             SikuliIDEI18N._I("msgAskSaveChanges", getCurrentShortFilename()),
             SikuliIDEI18N._I("dlgAskCloseTab"),
             JOptionPane.YES_NO_CANCEL_OPTION,
             JOptionPane.WARNING_MESSAGE,
             null,
             options,
             options[0]);
     if (ans == JOptionPane.CANCEL_OPTION || ans == JOptionPane.CLOSED_OPTION) {
       return false;
     } else if (ans == JOptionPane.YES_OPTION) {
       if (saveFile() == null) {
         return false;
       }
     } else {
       SikuliIDE.getInstance().getTabPane().resetLastClosed();
     }
     if (_srcBundleTemp) {
       FileManager.deleteTempDir(_srcBundlePath);
     }
     setDirty(false);
   }
   if (_srcBundlePath != null) {
     ImagePath.remove(_srcBundlePath);
   }
   return true;
 }
コード例 #7
0
  private void loadPrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    double delay = pref.getCaptureDelay();
    _spnDelay.setValue(delay);
    _old_cap_hkey = _cap_hkey = pref.getCaptureHotkey();
    _old_cap_mod = _cap_mod = pref.getCaptureHotkeyModifiers();
    setTxtHotkey(_cap_hkey, _cap_mod);
    switch (pref.getAutoNamingMethod()) {
      case UserPreferences.AUTO_NAMING_TIMESTAMP:
        _radTimestamp.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OCR:
        _radOCR.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OFF:
        _radOff.setSelected(true);
        break;
      default:
        Debug.error("Error in reading auto naming method preferences");
    }
    _chkAutoUpdate.setSelected(pref.getCheckUpdate());

    _chkExpandTab.setSelected(pref.getExpandTab());
    _spnTabWidth.setValue(pref.getTabWidth());
    initFontPrefs();
    initLangPrefs();
  }
コード例 #8
0
 // <editor-fold defaultstate="collapsed" desc="file handling">
 public String loadFile(boolean accessingAsFile) throws IOException {
   File file = new SikuliIDEFileChooser(SikuliIDE.getInstance(), accessingAsFile).load();
   if (file == null) {
     return null;
   }
   String fname = FileManager.slashify(file.getAbsolutePath(), false);
   SikuliIDE ide = SikuliIDE.getInstance();
   int i = ide.isAlreadyOpen(fname);
   if (i > -1) {
     Debug.log(2, "Already open in IDE: " + fname);
     return null;
   }
   loadFile(fname);
   if (_editingFile == null) {
     return null;
   }
   return fname;
 }
コード例 #9
0
 public void setDirty(boolean flag) {
   if (_dirty == flag) {
     return;
   }
   _dirty = flag;
   // <editor-fold defaultstate="collapsed" desc="RaiMan no global dirty">
   if (flag) {
     // RaiManMod getRootPane().putClientProperty("Window.documentModified", true);
   } else {
     // SikuliIDE.getInstance().checkDirtyPanes();
   }
   // </editor-fold>
   SikuliIDE.getInstance().setCurrentFileTabTitleDirty(_dirty);
 }
コード例 #10
0
  public String exportAsZip() throws IOException, FileNotFoundException {
    File file = new SikuliIDEFileChooser(SikuliIDE.getInstance()).export();
    if (file == null) {
      return null;
    }

    String zipPath = file.getAbsolutePath();
    String srcName = file.getName();
    if (!file.getAbsolutePath().endsWith(".skl")) {
      zipPath += ".skl";
    } else {
      srcName = srcName.substring(0, srcName.lastIndexOf('.'));
    }
    writeFile(getSrcBundle() + srcName + ".py");
    FileManager.zip(getSrcBundle(), zipPath);
    Debug.log(2, "export to executable file: " + zipPath);
    return zipPath;
  }
コード例 #11
0
 public void refreshControls() {
   SikuliIDE.getInstance().updateUndoRedoStates();
 }
コード例 #12
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!");
    }
  }
コード例 #13
0
 public PreferencesWin() {
   super(SikuliIDE._I("winPreferences"));
   initComponents();
   loadPrefs();
 }