processing.app

## Class Editor

- Object
- - Component
  - - Container
    - - Window
      - - Frame
        - - JFrame
          - - Editor

- All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants, RunnerListener
  Direct Known Subclasses:
    JavaEditor

      public abstract class Editor
      extends JFrame
      implements RunnerListener

  Main editor panel for the Processing Development Environment.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class Window

      `Window.Type`

    - ### Nested classes/interfaces inherited from class Component

      `Component.BaselineResizeBehavior`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `ArrayList<ToolContribution>` | `contribTools`

    - ### Fields inherited from class JFrame

      `EXIT_ON_CLOSE`

    - ### Fields inherited from class Frame

      `CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR`

    - ### Fields inherited from class Component

      `BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

    - ### Fields inherited from interface WindowConstants

      `DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE`

    - ### Fields inherited from interface ImageObserver

      `ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRecent()`
    `abstract JMenu` | `buildFileMenu()`
    `abstract JMenu` | `buildHelpMenu()`
    `JMenu` | `buildModeMenu()` Override this if you want a special menu for your particular 'mode'.
    `abstract JMenu` | `buildSketchMenu()`
    `static boolean` | `checkParen(char[] array, int index, int stop)`
    `void` | `clearNotice(String msg)`
    `void` | `clearToolMenu()`
    `abstract Formatter` | `createFormatter()`
    `abstract EditorToolbar` | `createToolbar()`
    `abstract void` | `deactivateRun()`
    `Base` | `getBase()`
    `int` | `getCaretOffset()` Get the position (character offset) of the caret.
    `abstract String` | `getCommentPrefix()`
    `EditorConsole` | `getConsole()`
    `EditorState` | `getEditorState()`
    `int` | `getLineCount()` Get the number of lines in the currently displayed buffer.
    `int` | `getLineStartOffset(int line)` Get character offset for the start of a given line of text.
    `int` | `getLineStopOffset(int line)` Get character offset for end of a given line of text.
    `String` | `getLineText(int line)` Get text for a specified line.
    `Mode` | `getMode()`
    `JMenu` | `getModeMenu()`
    `int` | `getScrollPosition()`
    `String` | `getSelectedText()` Called to update the text but not switch to a different set of code (which would affect the undo manager).
    `int` | `getSelectionStart()` Get the beginning point of the current selection.
    `int` | `getSelectionStop()` Get the end point of the current selection.
    `Sketch` | `getSketch()` Gets the current sketch object.
    `Point` | `getSketchLocation()` Get the last location of the sketch's run window.
    `String` | `getStatusMessage()` Returns the current notice message in the editor status bar.
    `int` | `getStatusMode()` Returns the current mode of the editor status bar: NOTICE, ERR or EDIT.
    `String` | `getText()` Get the contents of the current buffer.
    `String` | `getText(int start, int stop)` Get a range of text from the current buffer.
    `JEditTextArea` | `getTextArea()` Get the JEditTextArea object for use (not recommended).
    `JMenu` | `getToolMenu()`
    `void` | `handleAutoFormat()`
    `void` | `handleCopy()` Implements Edit → Copy.
    `void` | `handleCopyAsHTML()`
    `void` | `handleCut()` Implements Edit → Cut.
    `abstract void` | `handleImportLibrary(String jarPath)`
    `void` | `handleIndent()`
    `void` | `handleIndentOutdent(boolean indent)`
    `void` | `handleOutdent()`
    `void` | `handlePageSetup()` Handler for File → Page Setup.
    `void` | `handlePaste()` Implements Edit → Paste.
    `void` | `handlePrint()` Handler for File → Print.
    `boolean` | `handleSave(boolean immediately)` Actually handle the save command.
    `boolean` | `handleSaveAs()`
    `void` | `handleSelectAll()` Implements Edit → Select All.
    `void` | `insertText(String what)`
    `abstract void` | `internalCloseRunner()` Halt the current runner for whatever reason.
    `boolean` | `isHalted()`
    `boolean` | `isSelectionActive()` True if some text is currently selected.
    `void` | `prepareRun()` Grab current contents of the sketch window, advance the console, stop any other running sketches...
    `void` | `rebuildModeMenu()`
    `void` | `rebuildToolMenu()`
    `void` | `removeRecent()`
    `void` | `removeTool()`
    `void` | `setLineText(int line, String what)` Replace the text on a specified line.
    `void` | `setSelectedText(String what)`
    `void` | `setSelection(int start, int stop)`
    `void` | `setSketchLocation(Point p)` Set the location of the sketch run window.
    `void` | `setText(String what)` Replace the entire contents of the front-most tab.
    `void` | `setWatcherSave()`
    `static void` | `showChanges()`
    `void` | `showReference(String filename)`
    `void` | `startCompoundEdit()` Use before a manipulating text to group editing operations together as a single undo.
    `void` | `startIndeterminate()`
    `void` | `statusEmpty()` Clear the status area.
    `void` | `statusError(Exception e)` Show an exception in the editor status bar.
    `void` | `statusError(String what)` Show an error in the status bar.
    `void` | `statusHalt()`
    `void` | `statusNotice(String msg)` Show a notice message in the editor status bar.
    `void` | `stopCompoundEdit()` Use with startCompoundEdit() to group edit operations in a single undo.
    `void` | `stopIndeterminate()`
    `void` | `updateTitle()` Set the title of the PDE window based on the current sketch, i.e.

    - ### Methods inherited from class JFrame

      `getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update`

    - ### Methods inherited from class Frame

      `addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated`

    - ### Methods inherited from class Window

      `addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront`

    - ### Methods inherited from class Container

      `add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate`

    - ### Methods inherited from class Component

      `action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface MenuContainer

      `getFont, postEvent`

- - ### Field Detail

    - #### contribTools

          public ArrayList<ToolContribution> contribTools

  - ### Method Detail

    - #### getEditorState

          public EditorState getEditorState()

    - #### removeRecent

          public void removeRecent()

    - #### addRecent

          public void addRecent()

    - #### getBase

          public Base getBase()

    - #### getMode

          public Mode getMode()

    - #### rebuildModeMenu

          public void rebuildModeMenu()

    - #### getModeMenu

          public JMenu getModeMenu()

    - #### getConsole

          public EditorConsole getConsole()

    - #### createToolbar

          public abstract EditorToolbar createToolbar()

    - #### createFormatter

          public abstract Formatter createFormatter()

    - #### buildFileMenu

          public abstract JMenu buildFileMenu()

    - #### buildSketchMenu

          public abstract JMenu buildSketchMenu()

    - #### handleImportLibrary

          public abstract void handleImportLibrary(String jarPath)

    - #### getToolMenu

          public JMenu getToolMenu()

    - #### rebuildToolMenu

          public void rebuildToolMenu()

    - #### clearToolMenu

          public void clearToolMenu()

    - #### removeTool

          public void removeTool()

    - #### buildModeMenu

          public JMenu buildModeMenu()

      Override this if you want a special menu for your particular 'mode'.

    - #### buildHelpMenu

          public abstract JMenu buildHelpMenu()

    - #### showReference

          public void showReference(String filename)

    - #### showChanges

          public static void showChanges()

    - #### getSketch

          public Sketch getSketch()

      Gets the current sketch object.

    - #### getTextArea

          public JEditTextArea getTextArea()

      Get the JEditTextArea object for use (not recommended). This should only be used in obscure cases that really need to hack the internals of the JEditTextArea. Most tools should only interface via the get/set functions found in this class. This will maintain compatibility with future releases, which will not use JEditTextArea.

    - #### getText

          public String getText()

      Get the contents of the current buffer. Used by the Sketch class.

    - #### getText

          public String getText(int start,
                       int stop)

      Get a range of text from the current buffer.

    - #### setText

          public void setText(String what)

      Replace the entire contents of the front-most tab.

    - #### insertText

          public void insertText(String what)

    - #### getSelectedText

          public String getSelectedText()

      Called to update the text but not switch to a different set of code (which would affect the undo manager).

    - #### setSelectedText

          public void setSelectedText(String what)

    - #### setSelection

          public void setSelection(int start,
                          int stop)

    - #### getCaretOffset

          public int getCaretOffset()

      Get the position (character offset) of the caret. With text selected, this will be the last character actually selected, no matter the direction of the selection. That is, if the user clicks and drags to select lines 7 up to 4, then the caret position will be somewhere on line four.

    - #### isSelectionActive

          public boolean isSelectionActive()

      True if some text is currently selected.

    - #### getSelectionStart

          public int getSelectionStart()

      Get the beginning point of the current selection.

    - #### getSelectionStop

          public int getSelectionStop()

      Get the end point of the current selection.

    - #### getLineText

          public String getLineText(int line)

      Get text for a specified line.

    - #### setLineText

          public void setLineText(int line,
                         String what)

      Replace the text on a specified line.

    - #### getLineStartOffset

          public int getLineStartOffset(int line)

      Get character offset for the start of a given line of text.

    - #### getLineStopOffset

          public int getLineStopOffset(int line)

      Get character offset for end of a given line of text.

    - #### getLineCount

          public int getLineCount()

      Get the number of lines in the currently displayed buffer.

    - #### startCompoundEdit

          public void startCompoundEdit()

      Use before a manipulating text to group editing operations together as a single undo. Use stopCompoundEdit() once finished.

    - #### stopCompoundEdit

          public void stopCompoundEdit()

      Use with startCompoundEdit() to group edit operations in a single undo.

    - #### getScrollPosition

          public int getScrollPosition()

    - #### handleCut

          public void handleCut()

      Implements Edit → Cut.

    - #### handleCopy

          public void handleCopy()

      Implements Edit → Copy.

    - #### handleCopyAsHTML

          public void handleCopyAsHTML()

    - #### handlePaste

          public void handlePaste()

      Implements Edit → Paste.

    - #### handleSelectAll

          public void handleSelectAll()

      Implements Edit → Select All.

    - #### handleAutoFormat

          public void handleAutoFormat()

    - #### getCommentPrefix

          public abstract String getCommentPrefix()

    - #### handleIndent

          public void handleIndent()

    - #### handleOutdent

          public void handleOutdent()

    - #### handleIndentOutdent

          public void handleIndentOutdent(boolean indent)

    - #### checkParen

          public static boolean checkParen(char[] array,
                           int index,
                           int stop)

    - #### setSketchLocation

          public void setSketchLocation(Point p)

      Set the location of the sketch run window. Used by Runner to update the Editor about window drag events while the sketch is running.

    - #### getSketchLocation

          public Point getSketchLocation()

      Get the last location of the sketch's run window. Used by Runner to make the window show up in the same location as when it was last closed.

    - #### setWatcherSave

          public void setWatcherSave()

    - #### updateTitle

          public void updateTitle()

      Set the title of the PDE window based on the current sketch, i.e. something like "sketch_070752a - Processing 0126"

    - #### handleSave

          public boolean handleSave(boolean immediately)

      Actually handle the save command. If 'immediately' is set to false, this will happen in another thread so that the message area will update and the save button will stay highlighted while the save is happening. If 'immediately' is true, then it will happen immediately. This is used during a quit, because invokeLater() won't run properly while a quit is happening. This fixes Bug 276.

    - #### handleSaveAs

          public boolean handleSaveAs()

    - #### handlePageSetup

          public void handlePageSetup()

      Handler for File → Page Setup.

    - #### handlePrint

          public void handlePrint()

      Handler for File → Print.

    - #### prepareRun

          public void prepareRun()

      Grab current contents of the sketch window, advance the console, stop any other running sketches... not in that order.

    - #### internalCloseRunner

          public abstract void internalCloseRunner()

      Halt the current runner for whatever reason. Might be the VM dying, the window closing, an error...

    - #### deactivateRun

          public abstract void deactivateRun()

    - #### statusError

          public void statusError(String what)

      Show an error in the status bar.
      Specified by:
        `statusError` in interface `RunnerListener`

    - #### statusError

          public void statusError(Exception e)

      Show an exception in the editor status bar.
      Specified by:
        `statusError` in interface `RunnerListener`

    - #### statusNotice

          public void statusNotice(String msg)

      Show a notice message in the editor status bar.
      Specified by:
        `statusNotice` in interface `RunnerListener`

    - #### clearNotice

          public void clearNotice(String msg)

    - #### getStatusMessage

          public String getStatusMessage()

      Returns the current notice message in the editor status bar.

    - #### getStatusMode

          public int getStatusMode()

      Returns the current mode of the editor status bar: NOTICE, ERR or EDIT.

    - #### statusEmpty

          public void statusEmpty()

      Clear the status area.

    - #### startIndeterminate

          public void startIndeterminate()

      Specified by:
        `startIndeterminate` in interface `RunnerListener`

    - #### stopIndeterminate

          public void stopIndeterminate()

      Specified by:
        `stopIndeterminate` in interface `RunnerListener`

    - #### statusHalt

          public void statusHalt()

      Specified by:
        `statusHalt` in interface `RunnerListener`

    - #### isHalted

          public boolean isHalted()

      Specified by:
        `isHalted` in interface `RunnerListener`