Search in sources :

Example 1 with SketchCode

use of processing.app.SketchCode in project processing by processing.

the class EditorHeader method placeTabs.

private boolean placeTabs(int left, int right, Graphics2D g) {
    Sketch sketch = editor.getSketch();
    int x = left;
    for (int i = 0; i < sketch.getCodeCount(); i++) {
        SketchCode code = sketch.getCode(i);
        Tab tab = tabs[i];
        //      int pieceCount = 2 + (tab.textWidth / PIECE_WIDTH);
        //      if (tab.textVisible == false) {
        //        pieceCount = 4;
        //      }
        //      int pieceWidth = pieceCount * PIECE_WIDTH;
        int state = (code == sketch.getCurrentCode()) ? SELECTED : UNSELECTED;
        //      if (g != null) {
        //        //g.drawImage(pieces[state][LEFT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
        //        path = new GeneralPath();
        //        path.moveTo(x, bottom);
        //        path.lineTo(x, top + NOTCH);
        //        path.lineTo(x + NOTCH, top);
        //      }
        tab.left = x;
        x += TEXT_MARGIN;
        //      x += PIECE_WIDTH;
        //      int contentLeft = x;
        //      for (int j = 0; j < pieceCount; j++) {
        //        if (g != null) {
        //          g.drawImage(pieces[state][MIDDLE], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
        //        }
        //        x += PIECE_WIDTH;
        //      }
        //      if (g != null) {
        int drawWidth = tab.textVisible ? tab.textWidth : NO_TEXT_WIDTH;
        x += drawWidth + TEXT_MARGIN;
        //        path.moveTo(x, top);
        //      }
        tab.right = x;
        if (g != null && tab.right < right) {
            g.setColor(tabColor[state]);
            drawTab(g, tab.left, tab.right, i == 0, false);
            if (tab.textVisible) {
                int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2;
                g.setColor(textColor[state]);
                //          int baseline = (int) Math.ceil((sizeH + fontAscent) / 2.0);
                //int baseline = bottom - (TAB_HEIGHT - fontAscent)/2;
                int tabHeight = TAB_BOTTOM - TAB_TOP;
                int baseline = TAB_TOP + (tabHeight + fontAscent) / 2;
                //g.drawString(sketch.code[i].name, textLeft, baseline);
                g.drawString(tab.text, textLeft, baseline);
            //          g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent);
            //          g.drawLine(tab.left, baseline, tab.right, baseline);
            }
            if (code.isModified()) {
                g.setColor(modifiedColor);
                //g.drawLine(tab.left + NOTCH, top, tab.right - NOTCH, top);
                //g.drawLine(tab.left + (i == 0 ? CURVE_RADIUS : 0), TAB_TOP, tab.right-1, TAB_TOP);
                g.drawLine(tab.right, TAB_TOP, tab.right, TAB_BOTTOM);
            }
        }
        //      if (g != null) {
        //        g.drawImage(pieces[state][RIGHT], x, 0, PIECE_WIDTH, PIECE_HEIGHT, null);
        //      }
        //      x += PIECE_WIDTH - 1;  // overlap by 1 pixel
        x += TAB_BETWEEN;
    }
    return x <= right;
}
Also used : SketchCode(processing.app.SketchCode) Sketch(processing.app.Sketch)

Example 2 with SketchCode

use of processing.app.SketchCode in project processing by processing.

the class EditorHeader method rebuildMenu.

public void rebuildMenu() {
    //System.out.println("rebuilding");
    if (menu != null) {
        menu.removeAll();
    } else {
        menu = new JMenu();
        popup = menu.getPopupMenu();
        add(popup);
        popup.setLightWeightPopupEnabled(true);
    /*
      popup.addPopupMenuListener(new PopupMenuListener() {
          public void popupMenuCanceled(PopupMenuEvent e) {
            // on redraw, the isVisible() will get checked.
            // actually, a repaint may be fired anyway, so this
            // may be redundant.
            repaint();
          }
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
        });
      */
    }
    JMenuItem item;
    final JRootPane rootPane = editor.getRootPane();
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = rootPane.getActionMap();
    Action action;
    String mapKey;
    KeyStroke keyStroke;
    item = Toolkit.newJMenuItemShift(Language.text("editor.header.new_tab"), KeyEvent.VK_N);
    action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getSketch().handleNewCode();
        }
    };
    mapKey = "editor.header.new_tab";
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.SHORTCUT_SHIFT_KEY_MASK);
    inputMap.put(keyStroke, mapKey);
    actionMap.put(mapKey, action);
    item.addActionListener(action);
    menu.add(item);
    item = new JMenuItem(Language.text("editor.header.rename"));
    action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getSketch().handleRenameCode();
        }
    };
    item.addActionListener(action);
    menu.add(item);
    item = Toolkit.newJMenuItemShift(Language.text("editor.header.delete"), KeyEvent.VK_D);
    action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Sketch sketch = editor.getSketch();
            if (// ok on OS X
            !Platform.isMacOS() && // mmm! accessor
            editor.base.getEditors().size() == 1 && sketch.getCurrentCodeIndex() == 0) {
                Messages.showWarning(Language.text("editor.header.delete.warning.title"), Language.text("editor.header.delete.warning.text"));
            } else {
                editor.getSketch().handleDeleteCode();
            }
        }
    };
    mapKey = "editor.header.delete";
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.SHORTCUT_SHIFT_KEY_MASK);
    inputMap.put(keyStroke, mapKey);
    actionMap.put(mapKey, action);
    item.addActionListener(action);
    menu.add(item);
    menu.addSeparator();
    //  KeyEvent.VK_LEFT and VK_RIGHT will make Windows beep
    final String prevTab = Language.text("editor.header.previous_tab");
    if (Platform.isLinux()) {
        item = Toolkit.newJMenuItem(prevTab, KeyEvent.VK_PAGE_UP);
    } else {
        item = Toolkit.newJMenuItemAlt(prevTab, KeyEvent.VK_LEFT);
    }
    action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getSketch().handlePrevCode();
        }
    };
    mapKey = "editor.header.previous_tab";
    if (Platform.isLinux()) {
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, Toolkit.SHORTCUT_KEY_MASK);
    } else {
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.SHORTCUT_ALT_KEY_MASK);
    }
    inputMap.put(keyStroke, mapKey);
    actionMap.put(mapKey, action);
    item.addActionListener(action);
    menu.add(item);
    final String nextTab = Language.text("editor.header.next_tab");
    if (Platform.isLinux()) {
        item = Toolkit.newJMenuItem(nextTab, KeyEvent.VK_PAGE_DOWN);
    } else {
        item = Toolkit.newJMenuItemAlt(nextTab, KeyEvent.VK_RIGHT);
    }
    action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editor.getSketch().handleNextCode();
        }
    };
    mapKey = "editor.header.next_tab";
    if (Platform.isLinux()) {
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Toolkit.SHORTCUT_KEY_MASK);
    } else {
        keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.SHORTCUT_ALT_KEY_MASK);
    }
    inputMap.put(keyStroke, mapKey);
    actionMap.put(mapKey, action);
    item.addActionListener(action);
    menu.add(item);
    Sketch sketch = editor.getSketch();
    if (sketch != null) {
        menu.addSeparator();
        ActionListener jumpListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                editor.getSketch().setCurrentCode(e.getActionCommand());
            }
        };
        for (SketchCode code : sketch.getCode()) {
            item = new JMenuItem(code.getPrettyName());
            item.addActionListener(jumpListener);
            menu.add(item);
        }
    }
    Toolkit.setMenuMnemonics(menu);
}
Also used : SketchCode(processing.app.SketchCode) Sketch(processing.app.Sketch)

Example 3 with SketchCode

use of processing.app.SketchCode in project processing by processing.

the class Editor method prepareRun.

/**
   * Grab current contents of the sketch window, advance the console,
   * stop any other running sketches... not in that order.
   * It's essential that this function be called by any Mode subclass,
   * otherwise current edits may not be stored for getProgram().
   */
public void prepareRun() {
    internalCloseRunner();
    statusEmpty();
    // do this to advance/clear the terminal window / dos prompt / etc
    for (int i = 0; i < 10; i++) System.out.println();
    // clear the console on each run, unless the user doesn't want to
    if (Preferences.getBoolean("console.auto_clear")) {
        console.clear();
    }
    // make sure the user didn't hide the sketch folder
    sketch.ensureExistence();
    // Go through all tabs; Replace All, Rename or Undo could have changed them
    for (SketchCode sc : sketch.getCode()) {
        if (sc.getDocument() != null) {
            try {
                sc.setProgram(sc.getDocumentText());
            } catch (BadLocationException e) {
            }
        }
    }
//    // if an external editor is being used, need to grab the
//    // latest version of the code from the file.
//    if (Preferences.getBoolean("editor.external")) {
//      sketch.reload();
//    }
}
Also used : SketchCode(processing.app.SketchCode) Point(java.awt.Point) java.awt.print(java.awt.print)

Example 4 with SketchCode

use of processing.app.SketchCode in project processing by processing.

the class Debugger method startTrackingLineChanges.

/** Start tracking all line changes (due to edits) in the current tab. */
protected void startTrackingLineChanges() {
    // TODO: maybe move this to the editor?
    SketchCode tab = editor.getSketch().getCurrentCode();
    if (runtimeTabsTracked.contains(tab.getFileName())) {
        return;
    }
    for (int i = 0; i < tab.getLineCount(); i++) {
        LineID old = new LineID(tab.getFileName(), i);
        LineID tracked = new LineID(tab.getFileName(), i);
        tracked.startTracking(editor.currentDocument());
        runtimeLineChanges.put(old, tracked);
    }
    runtimeTabsTracked.add(tab.getFileName());
//System.out.println("tracking tab: " + tab.getFileName());
}
Also used : SketchCode(processing.app.SketchCode)

Example 5 with SketchCode

use of processing.app.SketchCode in project processing by processing.

the class JavaBuild method placeException.

/**
   * Map an error from a set of processed .java files back to its location
   * in the actual sketch.
   * @param message The error message.
   * @param filename The .java file where the exception was found.
   * @param line Line number of the .java file for the exception (0-indexed!)
   * @return A RunnerException to be sent to the editor, or null if it wasn't
   *         possible to place the exception to the sketch code.
   */
public SketchException placeException(String message, String dotJavaFilename, int dotJavaLine) {
    //-1;
    int codeIndex = 0;
    int codeLine = -1;
    // first check to see if it's a .java file
    for (int i = 0; i < sketch.getCodeCount(); i++) {
        SketchCode code = sketch.getCode(i);
        if (code.isExtension("java")) {
            if (dotJavaFilename.equals(code.getFileName())) {
                codeIndex = i;
                codeLine = dotJavaLine;
                return new SketchException(message, codeIndex, codeLine);
            }
        }
    }
    // If not the preprocessed file at this point, then need to get out
    if (!dotJavaFilename.equals(sketch.getName() + ".java")) {
        return null;
    }
    // if it's not a .java file, codeIndex will still be 0
    // this section searches through the list of .pde files
    codeIndex = 0;
    for (int i = 0; i < sketch.getCodeCount(); i++) {
        SketchCode code = sketch.getCode(i);
        if (code.isExtension("pde")) {
            //        System.out.println("looking for line " + dotJavaLine);
            if (code.getPreprocOffset() <= dotJavaLine) {
                codeIndex = i;
                //          System.out.println("i'm thinkin file " + i);
                codeLine = dotJavaLine - code.getPreprocOffset();
            }
        }
    }
    // changed for 0194 for compile errors, but...
    return new SketchException(message, codeIndex, codeLine, -1, false);
}
Also used : SketchException(processing.app.SketchException) SketchCode(processing.app.SketchCode)

Aggregations

SketchCode (processing.app.SketchCode)18 Sketch (processing.app.Sketch)7 Point (java.awt.Point)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ZipFile (java.util.zip.ZipFile)2 Library (processing.app.Library)2 Messages (processing.app.Messages)2 SketchException (processing.app.SketchException)2 StringList (processing.data.StringList)2 Handle (processing.mode.java.tweak.Handle)2 ClassPathFactory (com.google.classpath.ClassPathFactory)1 EventQueue (java.awt.EventQueue)1 Font (java.awt.Font)1 WindowEvent (java.awt.event.WindowEvent)1 WindowFocusListener (java.awt.event.WindowFocusListener)1