Package processing.app

Examples of processing.app.Sketch


  /**
   * 
   */
  private void handleCreateCustomTemplate ()
  {
    Sketch sketch = getSketch();

    File ajs = sketch.getMode().getContentFile( CoffeeScriptBuild.TEMPLATE_FOLDER_NAME );

    File tjs = getCustomTemplateFolder();

    if ( !tjs.exists() )
    {
View Full Code Here


        editor.prepareRun();
        if(editor.toolbar() != null)
        editor.toolbar().activate(DebugToolbar.DEBUG); // after prepareRun, since this removes highlights

        try {
            Sketch sketch = editor.getSketch();
            DebugBuild build = new DebugBuild(sketch);

            Logger.getLogger(Debugger.class.getName()).log(Level.INFO, "building sketch: {0}", sketch.getName());
            //LineMapping.addLineNumbers(sketch); // annotate
            mainClassName = build.build(false);
            //LineMapping.removeLineNumbers(sketch); // annotate
            Logger.getLogger(Debugger.class.getName()).log(Level.INFO, "class: {0}", mainClassName);
View Full Code Here

     *
     * @param javaLine the java line id
     * @return the corresponding sketch line id or null if failed to translate
     */
    public LineID javaToSketchLine(LineID javaLine) {
        Sketch sketch = editor.getSketch();

        // it may belong to a pure java file created in the sketch
        // try to find an exact filename match and check the extension
        SketchCode tab = editor.getTab(javaLine.fileName());
        if (tab != null && tab.isExtension("java")) {
            // can translate 1:1
            return originalToRuntimeLine(javaLine);
        }

        // check if it is the preprocessed/assembled file for this sketch
        // java file name needs to match the sketches filename
        if (!javaLine.fileName().equals(sketch.getName() + ".java")) {
            return null;
        }

        // find the tab (.pde file) this line belongs to
        // get the last tab that has an offset not greater than the java line number
        for (int i = sketch.getCodeCount() - 1; i >= 0; i--) {
            tab = sketch.getCode(i);
            // ignore .java files
            // the tab's offset must not be greater than the java line number
            if (tab.isExtension("pde") && tab.getPreprocOffset() <= javaLine.lineIdx()) {
                return originalToRuntimeLine(new LineID(tab.getFileName(), javaLine.lineIdx() - tab.getPreprocOffset()));
            }
View Full Code Here

     * removed from.
     */
    protected List<LineID> stripBreakpointComments() {
        List<LineID> bps = new ArrayList();
        // iterate over all tabs
        Sketch sketch = getSketch();
        for (int i = 0; i < sketch.getCodeCount(); i++) {
            SketchCode tab = sketch.getCode(i);
            String code = tab.getProgram();
            String lines[] = code.split("\\r?\\n"); // newlines not included
            //System.out.println(code);

            // scan code for breakpoint comments
View Full Code Here

     *
     * @param tabFileName the file name identifying the tab. (as in
     * {@link SketchCode#getFileName()})
     */
    public void switchToTab(String tabFileName) {
        Sketch s = getSketch();
        for (int i = 0; i < s.getCodeCount(); i++) {
            if (tabFileName.equals(s.getCode(i).getFileName())) {
                s.setCurrentCode(i);
                break;
            }
        }
    }
View Full Code Here

     * @param fileName the filename to search for.
     * @return the {@link SketchCode} object representing the tab, or null if
     * not found
     */
    public SketchCode getTab(String fileName) {
        Sketch s = getSketch();
        for (SketchCode c : s.getCode()) {
            if (c.getFileName().equals(fileName)) {
                return c;
            }
        }
        return null;
View Full Code Here

   * @throws IOException
   */
  private boolean saveSketch() throws IOException{
    if(!editor.getSketch().isModified()) return false;
    isSaving = true;
    Sketch sc = editor.getSketch();
   
    boolean deleteOldSave = false;
    String oldSave = null;
    if(!autosaveDir.exists()){
      autosaveDir = new File(sc.getFolder().getAbsolutePath(), AUTOSAVEFOLDER);
      autosaveDir.mkdir();
    }
    else
    {
      // delete the previous backup after saving current one.
      String prevSaves[] = Base.listFiles(autosaveDir, false);
      if(prevSaves.length > 0){
        deleteOldSave = true;
        oldSave = prevSaves[0];
      }
    }
    String newParentDir = autosaveDir + File.separator + System.currentTimeMillis();
    String newName = sc.getName();

   
    // check on the sanity of the name
    String sanitaryName = Sketch.checkName(newName);
    File newFolder = new File(newParentDir, sanitaryName);
    if (!sanitaryName.equals(newName) && newFolder.exists()) {
      Base.showMessage("Cannot Save",
                       "A sketch with the cleaned name\n" +
                       "“" + sanitaryName + "” already exists.");
      isSaving = false;
      return false;
    }
    newName = sanitaryName;

//    String newPath = newFolder.getAbsolutePath();
//    String oldPath = folder.getAbsolutePath();

//    if (newPath.equals(oldPath)) {
//      return false;  // Can't save a sketch over itself
//    }

    // make sure there doesn't exist a tab with that name already
    // but ignore this situation for the first tab, since it's probably being
    // resaved (with the same name) to another location/folder.
    for (int i = 1; i < sc.getCodeCount(); i++) {
      if (newName.equalsIgnoreCase(sc.getCode()[i].getPrettyName())) {
        Base.showMessage("Nope",
                         "You can't save the sketch as \"" + newName + "\"\n" +
                         "because the sketch already has a tab with that name.");
        isSaving = false;
        return false;
      }
    }

   

    // if the new folder already exists, then first remove its contents before
    // copying everything over (user will have already been warned).
    if (newFolder.exists()) {
      Base.removeDir(newFolder);
    }
    // in fact, you can't do this on Windows because the file dialog
    // will instead put you inside the folder, but it happens on OS X a lot.

    // now make a fresh copy of the folder
    newFolder.mkdirs();

    // grab the contents of the current tab before saving
    // first get the contents of the editor text area
    if (sc.getCurrentCode().isModified()) {
      sc.getCurrentCode().setProgram(editor.getText());
    }

    File[] copyItems = sc.getFolder().listFiles(new FileFilter() {
      public boolean accept(File file) {
        String name = file.getName();
        // just in case the OS likes to return these as if they're legit
        if (name.equals(".") || name.equals("..")) {
          return false;
        }
        // list of files/folders to be ignored during "save as"
        for (String ignorable : editor.getMode().getIgnorable()) {
          if (name.equals(ignorable)) {
            return false;
          }
        }
        // ignore the extensions for code, since that'll be copied below
        for (String ext : editor.getMode().getExtensions()) {
          if (name.endsWith(ext)) {
            return false;
          }
        }
        // don't do screen captures, since there might be thousands. kind of
        // a hack, but seems harmless. hm, where have i heard that before...
        if (name.startsWith("screen-")) {
          return false;
        }
        return true;
      }
    });
    // now copy over the items that make sense
    for (File copyable : copyItems) {
      if (copyable.isDirectory()) {
        Base.copyDir(copyable, new File(newFolder, copyable.getName()));
      } else {
        Base.copyFile(copyable, new File(newFolder, copyable.getName()));
      }
    }

    // save the other tabs to their new location
    for (int i = 1; i < sc.getCodeCount(); i++) {
      File newFile = new File(newFolder, sc.getCode()[i].getFileName());
      sc.getCode()[i].saveAs(newFile);
    }

    // While the old path to the main .pde is still set, remove the entry from
    // the Recent menu so that it's not sticking around after the rename.
    // If untitled, it won't be in the menu, so there's no point.
//    if (!isUntitled()) {
//      editor.removeRecent();
//    }

    // save the main tab with its new name
    File newFile = new File(newFolder, newName + ".pde");
    sc.getCode()[0].saveAs(newFile);

//    updateInternal(newName, newFolder);
//
//    // Make sure that it's not an untitled sketch
//    setUntitled(false);
View Full Code Here

TOP

Related Classes of processing.app.Sketch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.