Package mars.venus
Class EditPane
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
mars.venus.EditPane
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Observer
,Accessible
Represents one file opened for editing. Maintains required internal structures.
Before Mars 4.0, there was only one editor pane, a tab, and only one file could
be open at a time. With 4.0 came the multifile (pane, tab) editor, and existing
duties were split between EditPane and the new EditTabbedPane class.
- Author:
- Sanderson and Bumgarner
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
convertLineColumnToStreamPosition(int line, int column)
Given line and column (position in the line) numbers, calculate its byte stream position in text being edited.convertStreamPositionToLineColumn(int position)
void
copyText()
copy currently-selected text into clipboardvoid
cutText()
cut currently-selected text into clipboardvoid
Get rid of any accumulated undoable edits.void
displayCaretPosition(int pos)
Update the caret position label on the editor's border to display the current line and column.void
Display cursor coordinatesint
doFindText(String find, boolean caseSensitive)
Finds next occurrence of text in a forward search of a string.int
Finds and replaces next occurrence of text in a string in a forward search.int
doReplaceAll(String find, String replace, boolean caseSensitive)
Finds and replaces ALL occurrences of text in a string in a forward search.Delegates to corresponding FileStatus methodint
Get the editing status for this EditPane's associated document.getLineNumbersList(Document doc)
Delegates to corresponding FileStatus methodGet source code textint
Calculate and return number of lines in source code text.Get theMARSTextEditingArea
of the EditPaneget the manager in charge of Undo and Redo operationsboolean
Delegates to corresponding FileStatus methodboolean
isNew()
Delegates to corresponding FileStatus methodvoid
paste clipboard contents at cursor positionvoid
redo()
Redo previous editvoid
select all textvoid
selectLine(int line)
Select the specified editor text line.void
selectLine(int line, int column)
Select the specified editor text line.void
setFileStatus(int fileStatus)
Set the editing status for this EditPane's associated document.void
setPathname(String pathname)
Delegates to corresponding FileStatus methodvoid
setShowLineNumbersEnabled(boolean enabled)
enable or disable checkbox that controls display of line numbersvoid
setSourceCode(String s, boolean editable)
For initializing the source code when opening an ASM fileboolean
get editor's line number display statusvoid
Delegates to text area's requestFocusInWindow method.void
undo()
Undo previous editvoid
update(Observable fontChanger, Object arg)
Update, if source code is visible, when Font setting changes.void
Update state of Edit menu's Redo menu item.void
Delegates to corresponding FileStatus methodvoid
Update state of Edit menu's Undo menu item.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
EditPane
Constructor for the EditPane class.
-
-
Method Details
-
setSourceCode
For initializing the source code when opening an ASM file- Parameters:
s
- String containing texteditable
- set true if code is editable else false
-
discardAllUndoableEdits
public void discardAllUndoableEdits()Get rid of any accumulated undoable edits. It is useful to call this method after opening a file into the text area. The act of setting its text content upon reading the file will generate an undoable edit. Normally you don't want a freshly-opened file to appear with its Undo action enabled. But it will unless you call this after setting the text. -
getLineNumbersList
-
getTextArea
Get theMARSTextEditingArea
of the EditPane -
getSourceLineCount
public int getSourceLineCount()Calculate and return number of lines in source code text. Do this by counting newline characters then adding one if last line does not end with newline character. -
getSource
Get source code text- Returns:
- String containing source code
-
setFileStatus
public void setFileStatus(int fileStatus)Set the editing status for this EditPane's associated document. For the argument, use one of the constants from class FileStatus.- Parameters:
fileStatus
- the status constant from class FileStatus
-
getFileStatus
public int getFileStatus()Get the editing status for this EditPane's associated document. This will be one of the constants from class FileStatus. -
getFilename
Delegates to corresponding FileStatus method -
getPathname
Delegates to corresponding FileStatus method -
setPathname
Delegates to corresponding FileStatus method -
hasUnsavedEdits
public boolean hasUnsavedEdits()Delegates to corresponding FileStatus method -
isNew
public boolean isNew()Delegates to corresponding FileStatus method -
tellEditingComponentToRequestFocusInWindow
public void tellEditingComponentToRequestFocusInWindow()Delegates to text area's requestFocusInWindow method. -
updateStaticFileStatus
public void updateStaticFileStatus()Delegates to corresponding FileStatus method -
getUndoManager
get the manager in charge of Undo and Redo operations- Returns:
- the UnDo manager
-
copyText
public void copyText()copy currently-selected text into clipboard -
cutText
public void cutText()cut currently-selected text into clipboard -
pasteText
public void pasteText()paste clipboard contents at cursor position -
selectAllText
public void selectAllText()select all text -
undo
public void undo()Undo previous edit -
redo
public void redo()Redo previous edit -
updateUndoState
public void updateUndoState()Update state of Edit menu's Undo menu item. -
updateRedoState
public void updateRedoState()Update state of Edit menu's Redo menu item. -
showingLineNumbers
public boolean showingLineNumbers()get editor's line number display status- Returns:
- true if editor is current displaying line numbers, false otherwise.
-
setShowLineNumbersEnabled
public void setShowLineNumbersEnabled(boolean enabled)enable or disable checkbox that controls display of line numbers- Parameters:
enabled
- True to enable box, false to disable.
-
displayCaretPosition
public void displayCaretPosition(int pos)Update the caret position label on the editor's border to display the current line and column. The position is given as text stream offset and will be converted into line and column.- Parameters:
pos
- Offset into the text stream of caret.
-
displayCaretPosition
Display cursor coordinates- Parameters:
p
- Point object with x-y (column, line number) coordinates of cursor
-
convertStreamPositionToLineColumn
-
convertLineColumnToStreamPosition
public int convertLineColumnToStreamPosition(int line, int column)Given line and column (position in the line) numbers, calculate its byte stream position in text being edited.- Parameters:
line
- Line number in file (starts with 1)column
- Position within that line (starts with 1)- Returns:
- corresponding stream position. Returns -1 if there is no corresponding position.
-
selectLine
public void selectLine(int line)Select the specified editor text line. Lines are numbered starting with 1, consistent with line numbers displayed by the editor.- Parameters:
line
- The desired line number of this TextPane's text. Numbering starts at 1, and nothing will happen if the parameter value is less than 1
-
selectLine
public void selectLine(int line, int column)Select the specified editor text line. Lines are numbered starting with 1, consistent with line numbers displayed by the editor.- Parameters:
line
- The desired line number of this TextPane's text. Numbering starts at 1, and nothing will happen if the parameter value is less than 1column
- Desired column at which to place the cursor.
-
doFindText
Finds next occurrence of text in a forward search of a string. Search begins at the current cursor location, and wraps around when the end of the string is reached.- Parameters:
find
- the text to locate in the stringcaseSensitive
- true if search is to be case-sensitive, false otherwise- Returns:
- TEXT_FOUND or TEXT_NOT_FOUND, depending on the result.
-
doReplace
Finds and replaces next occurrence of text in a string in a forward search. If cursor is initially at end of matching selection, will immediately replace then find and select the next occurrence if any. Otherwise it performs a find operation. The replace can be undone with one undo operation.- Parameters:
find
- the text to locate in the stringreplace
- the text to replace the find text with - if the find text existscaseSensitive
- true for case sensitive. false to ignore case- Returns:
- Returns TEXT_FOUND if not initially at end of selected match and matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if reaplacement is successful and there is at least one additional match.
-
doReplaceAll
Finds and replaces ALL occurrences of text in a string in a forward search. All replacements are bundled into one CompoundEdit, so one Undo operation will undo all of them.- Parameters:
find
- the text to locate in the stringreplace
- the text to replace the find text with - if the find text existscaseSensitive
- true for case sensitive. false to ignore case- Returns:
- the number of occurrences that were matched and replaced.
-
update
Update, if source code is visible, when Font setting changes. This method is specified by the Observer interface.
-