Beispiel #1
0
    @Override
    protected Transferable createTransferable(JComponent c) {
      JTextPane aTextPane = (JTextPane) c;

      SikuliEditorKit kit = ((SikuliEditorKit) aTextPane.getEditorKit());
      Document doc = aTextPane.getDocument();
      int sel_start = aTextPane.getSelectionStart();
      int sel_end = aTextPane.getSelectionEnd();

      StringWriter writer = new StringWriter();
      try {
        _copiedImgs.clear();
        kit.write(writer, doc, sel_start, sel_end - sel_start, _copiedImgs);
        return new StringSelection(writer.toString());
      } catch (Exception e) {
        Debug.error(me + "createTransferable: Problem creating text to copy\n%s", e.getMessage());
      }
      return null;
    }
Beispiel #2
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!");
    }
  }