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
public class EditPane
- extends JPanel
- implements Observer
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
Constructor Summary |
EditPane(VenusUI appFrame)
Constructor for the EditPane class. |
Method Summary |
int |
convertLineColumnToStreamPosition(int line,
int column)
Given line and column (position in the line) numbers, calculate
its byte stream position in text being edited. |
Point |
convertStreamPositionToLineColumn(int position)
|
void |
copyText()
copy currently-selected text into clipboard |
void |
cutText()
cut currently-selected text into clipboard |
void |
discardAllUndoableEdits()
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 |
displayCaretPosition(Point p)
Display cursor coordinates |
int |
doFindText(String find,
boolean caseSensitive)
Finds next occurrence of text in a forward search of a string. |
int |
doReplace(String find,
String replace,
boolean caseSensitive)
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. |
String |
getFilename()
Delegates to corresponding FileStatus method |
int |
getFileStatus()
Get the editing status for this EditPane's associated document. |
String |
getLineNumbersList(Document doc)
|
String |
getPathname()
Delegates to corresponding FileStatus method |
String |
getSource()
Get source code text |
int |
getSourceLineCount()
Calculate and return number of lines in source code text. |
UndoManager |
getUndoManager()
get the manager in charge of Undo and Redo operations |
boolean |
hasUnsavedEdits()
Delegates to corresponding FileStatus method |
boolean |
isNew()
Delegates to corresponding FileStatus method |
void |
pasteText()
paste clipboard contents at cursor position |
void |
redo()
Redo previous edit |
void |
selectAllText()
select all text |
void |
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 method |
void |
setShowLineNumbersEnabled(boolean enabled)
enable or disable checkbox that controls display of line numbers |
void |
setSourceCode(String s,
boolean editable)
For initalizing the source code when opening an ASM file |
boolean |
showingLineNumbers()
get editor's line number display status |
void |
tellEditingComponentToRequestFocusInWindow()
Delegates to text area's requestFocusInWindow method. |
void |
undo()
Undo previous edit |
void |
update(Observable fontChanger,
Object arg)
Update, if source code is visible, when Font setting changes. |
void |
updateRedoState()
Update state of Edit menu's Redo menu item. |
void |
updateStaticFileStatus()
Delegates to corresponding FileStatus method |
void |
updateUndoState()
Update state of Edit menu's Undo menu item. |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
EditPane
public EditPane(VenusUI appFrame)
- Constructor for the EditPane class.
setSourceCode
public void setSourceCode(String s,
boolean editable)
- For initalizing 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
public String getLineNumbersList(Document doc)
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
public String getSource()
- Get source code text
- Returns:
- Sting 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
public String getFilename()
- Delegates to corresponding FileStatus method
getPathname
public String getPathname()
- Delegates to corresponding FileStatus method
setPathname
public void setPathname(String pathname)
- 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
public UndoManager 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:
enable
- 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
public void displayCaretPosition(Point p)
- Display cursor coordinates
- Parameters:
p
- Point object with x-y (column, line number) coordinates of cursor
convertStreamPositionToLineColumn
public Point convertStreamPositionToLineColumn(int position)
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
public int doFindText(String find,
boolean caseSensitive)
- 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
public int doReplace(String find,
String replace,
boolean caseSensitive)
- 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
public int doReplaceAll(String find,
String replace,
boolean caseSensitive)
- 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
public void update(Observable fontChanger,
Object arg)
- Update, if source code is visible, when Font setting changes.
This method is specified by the Observer interface.
- Specified by:
update
in interface Observer