processing.app
Class Editor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by processing.app.Editor
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants, RunnerListener

public class Editor
extends javax.swing.JFrame
implements RunnerListener

Main editor panel for the Processing Development Environment.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.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 java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Editor(Base ibase, java.lang.String path, int[] location)
           
 
Method Summary
 int getCaretOffset()
          Get the position (character offset) of the caret.
 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.
 java.lang.String getLineText(int line)
          Get text for a specified line.
 java.awt.Dimension getMinimumSize()
          Hack for #@#)$(* Mac OS X 10.2.
 int getScrollPosition()
           
 java.lang.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.
 java.awt.Point getSketchLocation()
          Get the last location of the sketch's run window.
 java.lang.String getText()
          Get the contents of the current buffer.
 java.lang.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).
 void handleCopy()
          Implements Edit → Copy.
 void handleCut()
          Implements Edit → Cut.
 void handleExport()
          Called by Sketch → Export.
 void handleExportApplication()
          Handler for Sketch → Export Application
 void handlePageSetup()
          Handler for File → Page Setup.
 void handlePaste()
          Implements Edit → Paste.
 void handlePrint()
          Handler for File → Print.
 void handleRun(boolean present)
          Implements Sketch → Run.
 boolean handleSave(boolean immediately)
          Actually handle the save command.
 boolean handleSaveAs()
           
 void handleSelectAll()
          Implements Edit → Select All.
 void handleStop()
          Implements Sketch → Stop, or pressing Stop on the toolbar.
 void insertText(java.lang.String what)
           
 void internalCloseRunner()
          Handle internal shutdown of the runner.
 void internalRunnerClosed()
          Called by Runner to notify that the sketch has stopped running.
 boolean isSelectionActive()
          True if some text is currently selected.
static javax.swing.JMenuItem newJMenuItem(java.lang.String title, int what)
          A software engineer, somewhere, needs to have his abstraction taken away.
static javax.swing.JMenuItem newJMenuItemAlt(java.lang.String title, int what)
          Same as newJMenuItem(), but adds the ALT (on Linux and Windows) or OPTION (on Mac OS X) key as a modifier.
static javax.swing.JMenuItem newJMenuItemShift(java.lang.String title, int what)
          Like newJMenuItem() but adds shift as a modifier for the key command.
 void setLineText(int line, java.lang.String what)
          Replace the text on a specified line.
 void setSelectedText(java.lang.String what)
           
 void setSelection(int start, int stop)
           
 void setSketchLocation(java.awt.Point p)
          Set the location of the sketch run window.
 void setText(java.lang.String what)
          Replace the entire contents of the front-most tab.
 void startCompoundEdit()
          Use before a manipulating text to group editing operations together as a single undo.
 void statusEmpty()
          Clear the status area.
 void statusError(java.lang.Exception e)
          Show an exception in the editor status bar.
 void statusError(java.lang.String what)
          Show an error int the status bar.
 void statusNotice(java.lang.String msg)
          Show a notice message in the editor status bar.
 void stopCompoundEdit()
          Use with startCompoundEdit() to group edit operations in a single undo.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.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, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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, isOpaque, 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, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

Editor

public Editor(Base ibase,
              java.lang.String path,
              int[] location)
Method Detail

getMinimumSize

public java.awt.Dimension getMinimumSize()
Hack for #@#)$(* Mac OS X 10.2.

This appears to only be required on OS X 10.2, and is not even being called on later versions of OS X or Windows.

Overrides:
getMinimumSize in class java.awt.Container

newJMenuItem

public static javax.swing.JMenuItem newJMenuItem(java.lang.String title,
                                                 int what)
A software engineer, somewhere, needs to have his abstraction taken away. In some countries they jail or beat people for writing the sort of API that would require a five line helper function just to set the command key for a menu item.


newJMenuItemShift

public static javax.swing.JMenuItem newJMenuItemShift(java.lang.String title,
                                                      int what)
Like newJMenuItem() but adds shift as a modifier for the key command.


newJMenuItemAlt

public static javax.swing.JMenuItem newJMenuItemAlt(java.lang.String title,
                                                    int what)
Same as newJMenuItem(), but adds the ALT (on Linux and Windows) or OPTION (on Mac OS X) key as a modifier.


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 java.lang.String getText()
Get the contents of the current buffer. Used by the Sketch class.


getText

public java.lang.String getText(int start,
                                int stop)
Get a range of text from the current buffer.


setText

public void setText(java.lang.String what)
Replace the entire contents of the front-most tab.


insertText

public void insertText(java.lang.String what)

getSelectedText

public java.lang.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(java.lang.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 java.lang.String getLineText(int line)
Get text for a specified line.


setLineText

public void setLineText(int line,
                        java.lang.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.


handlePaste

public void handlePaste()
Implements Edit → Paste.


handleSelectAll

public void handleSelectAll()
Implements Edit → Select All.


handleRun

public void handleRun(boolean present)
Implements Sketch → Run.

Parameters:
present - Set true to run in full screen (present mode).

setSketchLocation

public void setSketchLocation(java.awt.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 java.awt.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.


handleStop

public void handleStop()
Implements Sketch → Stop, or pressing Stop on the toolbar.


internalRunnerClosed

public void internalRunnerClosed()
Called by Runner to notify that the sketch has stopped running. Tools should not call this function, use handleStop() instead.


internalCloseRunner

public void internalCloseRunner()
Handle internal shutdown of the runner.


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()

handleExport

public void handleExport()
Called by Sketch → Export. Handles calling the export() function on sketch, and queues all the gui status stuff that comes along with it.

Made synchronized to (hopefully) avoid problems of people hitting export twice, quickly, and horking things up.


handleExportApplication

public void handleExportApplication()
Handler for Sketch → Export Application


handlePageSetup

public void handlePageSetup()
Handler for File → Page Setup.


handlePrint

public void handlePrint()
Handler for File → Print.


statusError

public void statusError(java.lang.String what)
Show an error int the status bar.

Specified by:
statusError in interface RunnerListener

statusError

public void statusError(java.lang.Exception e)
Show an exception in the editor status bar.

Specified by:
statusError in interface RunnerListener

statusNotice

public void statusNotice(java.lang.String msg)
Show a notice message in the editor status bar.


statusEmpty

public void statusEmpty()
Clear the status area.