Package mars.venus.editor
Class FileEditorTab
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
mars.venus.editor.FileEditorTab
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,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 multi-file editor, and existing duties were
split between EditPane (now FileEditorTab) and the new EditTabbedPane (now EditTab) class.
- Author:
- Sanderson and Bumgarner
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, 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
ConstructorsConstructorDescriptionFileEditorTab
(VenusUI gui) Create a new tab within the "Edit" tab for editing a file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Comment or uncomment the selection, or line at cursor if nothing is selected.int
convertLineColumnToStreamPosition
(int lineIndex, int columnIndex) Given line and column (position in the line) numbers, calculate its byte stream position in text being edited.convertStreamPositionToLineColumn
(int offset) Given character stream offset in text being edited, calculate its column and line number coordinates.void
copyText()
Copy the currently selected text to the clipboard.void
cutText()
Cut the currently selected text to the clipboard.void
Get rid of any accumulated undoable edits.void
displayCaretPosition
(int offset) Update the caret position label on the editor's border to display the current line and column.void
displayCaretPosition
(Point position) Update the status bar display for the caret position.int
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.getFile()
Get the file represented by this tab.Get the file status of this tab.static String
getLineNumbersList
(Document document) Form string with source code line numbers.Get the source code text.int
Calculate and return number of lines in source code text.Get the manager in charge of Undo and Redo operationsboolean
boolean
isNew()
void
Paste the current clipboard contents at the cursor position.void
redo()
Redo the previously undone edit.void
Delegates to text area's requestFocusInWindow method.void
Select all text.void
selectLine
(int line) Select the specified editor text line.void
selectLine
(int lineIndex, int columnIndex) Select the specified editor text line.void
Set the file represented by this tab.void
setFileStatus
(FileStatus fileStatus) Set the file status of this tab.void
setSourceCode
(String sourceCode, boolean editable) For initializing the source code when opening an ASM file.void
undo()
Undo the previous edit.void
Automatically update whether the Undo and Redo actions are enabled or disabled based on the status of theUndoManager
.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, 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
-
FileEditorTab
Create a new tab within the "Edit" tab for editing a file.
-
-
Method Details
-
setSourceCode
For initializing the source code when opening an ASM file.- Parameters:
sourceCode
- 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
Form string with source code line numbers. Resulting string is HTML, for which JLabel will happily honor<br>
to do multiline label (it ignores\n
). The line number list is aJLabel
with one line number per line. -
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 the source code text.- Returns:
- String containing source code.
-
getFileStatus
Get the file status of this tab.- Returns:
- The file status.
-
setFileStatus
Set the file status of this tab.- Parameters:
fileStatus
- The file status.
-
hasUnsavedEdits
public boolean hasUnsavedEdits()- See Also:
-
isNew
public boolean isNew()- See Also:
-
getFile
Get the file represented by this tab.- Returns:
- The file object.
-
setFile
Set the file represented by this tab.- Parameters:
file
- The file object.
-
requestTextAreaFocus
public void requestTextAreaFocus()Delegates to text area's requestFocusInWindow method. -
getUndoManager
Get the manager in charge of Undo and Redo operations- Returns:
- The undo manager object.
-
copyText
public void copyText()Copy the currently selected text to the clipboard. -
cutText
public void cutText()Cut the currently selected text to the clipboard. -
pasteText
public void pasteText()Paste the current clipboard contents at the cursor position. -
selectAllText
public void selectAllText()Select all text. -
undo
public void undo()Undo the previous edit. -
redo
public void redo()Redo the previously undone edit. -
commentLines
public void commentLines()Comment or uncomment the selection, or line at cursor if nothing is selected. -
updateUndoRedoActions
public void updateUndoRedoActions()Automatically update whether the Undo and Redo actions are enabled or disabled based on the status of theUndoManager
. -
displayCaretPosition
public void displayCaretPosition(int offset) 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:
offset
- Offset into the text stream of caret.
-
displayCaretPosition
Update the status bar display for the caret position.- Parameters:
position
- Position of the caret (x = column, y = line).
-
convertStreamPositionToLineColumn
Given character stream offset in text being edited, calculate its column and line number coordinates.- Parameters:
offset
- Position of character.- Returns:
- The column and line number position (x = column, y = line).
-
convertLineColumnToStreamPosition
public int convertLineColumnToStreamPosition(int lineIndex, int columnIndex) Given line and column (position in the line) numbers, calculate its byte stream position in text being edited.- Parameters:
lineIndex
- Line number in file (starts with 0)columnIndex
- Position within that line (starts with 0)- 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 line number to select. Numbering starts at 1, and nothing will happen if the parameter value is less than 1
-
selectLine
public void selectLine(int lineIndex, int columnIndex) Select the specified editor text line. Lines are numbered starting with 1, consistent with line numbers displayed by the editor.- Parameters:
lineIndex
- The line number to select. Numbering starts at 0, and nothing will happen if the parameter value is less than 0columnIndex
- 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 replacement 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.
-