com.raelity.jvi.swing
Class TextView

java.lang.Object
  extended by com.raelity.jvi.swing.TextView
All Implemented Interfaces:
ViOptionBag, ViTextView

public class TextView
extends Object
implements ViTextView

Presents a swing editor interface for use with vi. There is one of these for each JEditorPane;

Notice the listeners for caret changes. If the caret changes to a location that is unexpected, i.e. it came from some external source, then an externalChange message is sent to vi.

The getEditorComponent method should not be used by the primary vi software. The primary vi software should only access, or make changes to, the underlying JEditorPane through other methods in this class.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.raelity.jvi.ViTextView
ViTextView.FOLDOP, ViTextView.JLOP, ViTextView.MARKOP, ViTextView.NLOP, ViTextView.TABOP, ViTextView.TAGOP, ViTextView.WMOP
 
Field Summary
protected  DefaultBuffer buf
           
protected  TextViewCache cache
           
protected  JEditorPane editorPane
           
protected  int expectedCaretPosition
           
protected  int mygen
           
protected  TextOps ops
           
protected  ViStatusDisplay statusDisplay
           
 boolean w_p_nu
          jVi doesn't support this flag.
protected  Window window
           
 
Constructor Summary
TextView(JEditorPane editorPane)
           
 
Method Summary
 void activateOptions(ViTextView tv)
          This is invoked when switchto bag's associated editor.
 void anonymousMark(ViTextView.MARKOP op, int count)
          Anonymous mark handling.
protected  void applyBackground(int[] blocks, MutableAttributeSet mas)
           
 void attach()
          establish all the listeners
 void clearSelect()
          clear the select, if any, on the screen, don't move the caret
 int coladvanceCoord(int lineOffset, int colIdx)
           
 void computeCursorPosition(int offset, MutableInt line, MutableInt column)
           
 void computeCursorPosition(MutableInt offset, MutableInt line, MutableInt column)
          Determine cursor position, all args get set (call by reference).
protected  void createOps(JEditorPane editorPane)
          Create methods to invoke and interact with editor pane actions.
protected  ViStatusDisplay createStatusDisplay()
          Override this class to provide a different implementations of status display.
protected  TextViewCache createTextViewCache()
          Override this method to provide different cache implementation
 void deleteChar(int start, int end)
          Delete a bunch of characters
 void deletePreviousChar()
          Delete previous character (backspace).
 void detach()
          tear down all the listeners
 void findMatch()
          find matching character for character under the cursor.
 void foldOperation(ViTextView.FOLDOP op)
          Perform the fold operation.
 void foldOperation(ViTextView.FOLDOP op, int offset)
          Perform the fold operation.
 DefaultBuffer getBuffer()
           
 int getBufferLineOffset(int coordLine)
          Reverse of getCoordLine, convert coord line to document line
 int getCaretPosition()
           
 int getCoordLine(int line)
           
 int getCoordLineCount()
           
 JEditorPane getEditorComponent()
           
 ViMark getMark(int i)
           
 int getMarkPosition()
           
 TextOps getOps()
           
 ViMark getPCMark()
           
 ViMark getPrevPCMark()
           
 ViStatusDisplay getStatusDisplay()
          Handle displayable editor state changes
 String getText(int offset, int length)
           
 int getViewBlankLines()
           
 int getViewBottomLine()
           
 int getViewCoordBlankLines()
           
 int getViewCoordBottomLine()
           
 int getViewCoordTopLine()
           
 int getViewLines()
           
 int getViewTopLine()
           
 ViFPOS getWCursor()
           
 int getWCurswant()
           
 Window getWindow()
           
 boolean getWPList()
           
 int getWPScroll()
           
 boolean getWSetCurswant()
           
 void insertChar(char c)
          insert character at cursor position.
 void insertNewLine()
          Insert new line at current position
 void insertTab()
          Insert tab at current position
 void insertText(int offset, String s)
          insert text at specified location
 void insertTypedChar(char c)
          Add a character verbatim to the window.
 boolean isEditable()
          Can the editor text be changed
 boolean isShutdown()
           
 void jumpDefinition(String ident)
          Jump to the definition of the identifier under the cursor.
 void jumpList(ViTextView.JLOP op, int count)
          Jump list handling
 boolean openNewLine(ViTextView.NLOP op)
           Create an empty line, autoindented, either before or after current line.
 void pushPCMark()
           
 void redo()
          redo a change
 void replaceChar(char c, boolean advanceCursor)
          Replace character at current cursor location with argument character
 void replaceString(int start, int end, String s)
          Replace indicated region with string
 void scroll(int n_lines)
          Scroll down (n_lines positive) or up (n_lines negative) the specified number of lines.
 void setCaretPosition(int offset)
          set the caret to the indicated position.
 void setCaretPosition(int lnum, int col)
          set the caret to the indicated position.
 void setCursorCoordLine(int coordLine, int col)
           
 void setSelect(int dot, int mark)
          select a region of the screen
 void setViewCoordTopLine(int coordLine)
          cause the idndicated line to be displayed as top line in view.
 void setViewTopLine(int line)
          cause the idndicated line to be displayed as top line in view.
 void setWCurswant(int c)
           
 void setWindow(Window window)
           
 void setWPList(boolean f)
           
 void setWPScroll(int n)
           
 void setWSetCurswant(boolean f)
           
 void shutdown()
          going away, do any remaining cleanup
 void startup(Buffer buf)
          called after TV and Buffer are constructed
 void tabOperation(ViTextView.TABOP op, int count)
          move to other file tab.
For NEXT,PREV if count == 0 then neighboring tab; if count != 0 then countTh tab, where first is one
 void undo()
          undo a change
 void updateCursor(ViCursor cursor)
          Change the cursor shape
 void updateHighlightSearchState()
          Update the hightlight search state
 void updateVisualState()
          Update the selection highlight.
 void viOptionSet(ViTextView tv, String name)
          The set command used to change an option
 void win_close_others(boolean forceit)
          Close other windows
 void win_close(boolean freeBuf)
          Close this window
 void win_cycle(int n)
          Cycle to the indicated buffer.
 void win_goto(int n)
          Goto the indicated buffer.
 void win_quit()
          Quit editing window.
 void win_split(int n)
          Split this window.
 void wordMatchOperation(ViTextView.WMOP op)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mygen

protected int mygen

editorPane

protected JEditorPane editorPane

buf

protected DefaultBuffer buf

ops

protected TextOps ops

cache

protected TextViewCache cache

window

protected Window window

statusDisplay

protected ViStatusDisplay statusDisplay

expectedCaretPosition

protected int expectedCaretPosition

w_p_nu

public boolean w_p_nu
jVi doesn't support this flag. Keep it as a per window flag like vim. The platform may do something with it.

Constructor Detail

TextView

public TextView(JEditorPane editorPane)
Method Detail

startup

public void startup(Buffer buf)
Description copied from interface: ViTextView
called after TV and Buffer are constructed

Specified by:
startup in interface ViTextView

shutdown

public void shutdown()
Description copied from interface: ViTextView
going away, do any remaining cleanup

Specified by:
shutdown in interface ViTextView

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface ViTextView
Returns:
true if this text view is shutdown

viOptionSet

public void viOptionSet(ViTextView tv,
                        String name)
Description copied from interface: ViOptionBag
The set command used to change an option

Specified by:
viOptionSet in interface ViOptionBag

activateOptions

public void activateOptions(ViTextView tv)
Description copied from interface: ViOptionBag
This is invoked when switchto bag's associated editor.

Specified by:
activateOptions in interface ViOptionBag

setWindow

public void setWindow(Window window)
Specified by:
setWindow in interface ViTextView

getWindow

public Window getWindow()
Specified by:
getWindow in interface ViTextView
Returns:
the associated Window

getWCursor

public ViFPOS getWCursor()
Specified by:
getWCursor in interface ViTextView
Returns:
the current location of the cursor in the window, note that this cursor is dynamic as caret moves this gets updated.

getWCurswant

public int getWCurswant()
Specified by:
getWCurswant in interface ViTextView

setWCurswant

public void setWCurswant(int c)
Specified by:
setWCurswant in interface ViTextView

getWSetCurswant

public boolean getWSetCurswant()
Specified by:
getWSetCurswant in interface ViTextView

setWSetCurswant

public void setWSetCurswant(boolean f)
Specified by:
setWSetCurswant in interface ViTextView

getPCMark

public ViMark getPCMark()
Specified by:
getPCMark in interface ViTextView

getPrevPCMark

public ViMark getPrevPCMark()
Specified by:
getPrevPCMark in interface ViTextView

pushPCMark

public void pushPCMark()
Specified by:
pushPCMark in interface ViTextView

getMark

public ViMark getMark(int i)
Specified by:
getMark in interface ViTextView

getWPScroll

public int getWPScroll()
Specified by:
getWPScroll in interface ViTextView

setWPScroll

public void setWPScroll(int n)
Specified by:
setWPScroll in interface ViTextView

getWPList

public boolean getWPList()
Specified by:
getWPList in interface ViTextView

setWPList

public void setWPList(boolean f)
Specified by:
setWPList in interface ViTextView

getBuffer

public final DefaultBuffer getBuffer()
Specified by:
getBuffer in interface ViTextView
Returns:
the associated Buffer

createStatusDisplay

protected ViStatusDisplay createStatusDisplay()
Override this class to provide a different implementations of status display.


createTextViewCache

protected TextViewCache createTextViewCache()
Override this method to provide different cache implementation


attach

public void attach()
Description copied from interface: ViTextView
establish all the listeners

Specified by:
attach in interface ViTextView

detach

public void detach()
Description copied from interface: ViTextView
tear down all the listeners

Specified by:
detach in interface ViTextView

createOps

protected void createOps(JEditorPane editorPane)
Create methods to invoke and interact with editor pane actions. May override for custom editor panes.


getEditorComponent

public JEditorPane getEditorComponent()
Specified by:
getEditorComponent in interface ViTextView
Returns:
the underlying text component

isEditable

public boolean isEditable()
Description copied from interface: ViTextView
Can the editor text be changed

Specified by:
isEditable in interface ViTextView
Returns:
true if the text can be changed.

insertNewLine

public void insertNewLine()
Description copied from interface: ViTextView
Insert new line at current position

Specified by:
insertNewLine in interface ViTextView

insertTab

public void insertTab()
Description copied from interface: ViTextView
Insert tab at current position

Specified by:
insertTab in interface ViTextView

replaceChar

public void replaceChar(char c,
                        boolean advanceCursor)
Description copied from interface: ViTextView
Replace character at current cursor location with argument character

Specified by:
replaceChar in interface ViTextView

deletePreviousChar

public void deletePreviousChar()
Description copied from interface: ViTextView
Delete previous character (backspace).

Specified by:
deletePreviousChar in interface ViTextView

insertChar

public void insertChar(char c)
insert character at cursor position. For some characters special actions may be taken.

Specified by:
insertChar in interface ViTextView

insertTypedChar

public void insertTypedChar(char c)
Add a character verbatim to the window.

Specified by:
insertTypedChar in interface ViTextView

replaceString

public void replaceString(int start,
                          int end,
                          String s)
Description copied from interface: ViTextView
Replace indicated region with string

Specified by:
replaceString in interface ViTextView

deleteChar

public void deleteChar(int start,
                       int end)
Description copied from interface: ViTextView
Delete a bunch of characters

Specified by:
deleteChar in interface ViTextView

insertText

public void insertText(int offset,
                       String s)
Description copied from interface: ViTextView
insert text at specified location

Specified by:
insertText in interface ViTextView

openNewLine

public boolean openNewLine(ViTextView.NLOP op)

Create an empty line, autoindented, either before or after current line. This is simple algorithm; but it ignores guarded text issues and code folding subtlties.

In this example, either the cursor was on line1 and do a NL_FORWARD, or cursor on line2 and NL_BACKWARD. The cursor is shown as '|' positioned where the newLine action will open up a clean line with proper autoindent.
     line1|\n
     line2\n
 
This has problems if line1 is guarded text (write protected), since it modifies that line. And issues with folding in that it will open the fold since a folded line is modified.

Specified by:
openNewLine in interface ViTextView

undo

public void undo()
Description copied from interface: ViTextView
undo a change

Specified by:
undo in interface ViTextView

redo

public void redo()
Description copied from interface: ViTextView
redo a change

Specified by:
redo in interface ViTextView

getText

public String getText(int offset,
                      int length)
               throws BadLocationException
Throws:
BadLocationException

getCaretPosition

public int getCaretPosition()
Specified by:
getCaretPosition in interface ViTextView
Returns:
the offset of the text insertion caret

getMarkPosition

public int getMarkPosition()
Specified by:
getMarkPosition in interface ViTextView
Returns:
the offset of the text insertion caret

setCaretPosition

public void setCaretPosition(int offset)
Description copied from interface: ViTextView
set the caret to the indicated position.

Specified by:
setCaretPosition in interface ViTextView

setCaretPosition

public void setCaretPosition(int lnum,
                             int col)
Description copied from interface: ViTextView
set the caret to the indicated position.

Specified by:
setCaretPosition in interface ViTextView

setSelect

public void setSelect(int dot,
                      int mark)
Description copied from interface: ViTextView
select a region of the screen

Specified by:
setSelect in interface ViTextView

clearSelect

public void clearSelect()
Description copied from interface: ViTextView
clear the select, if any, on the screen, don't move the caret

Specified by:
clearSelect in interface ViTextView

findMatch

public void findMatch()
Description copied from interface: ViTextView
find matching character for character under the cursor. This is the '%' command. It is here to take advantage of existing functionality in target environments.

Specified by:
findMatch in interface ViTextView

jumpDefinition

public void jumpDefinition(String ident)
Description copied from interface: ViTextView
Jump to the definition of the identifier under the cursor.

Specified by:
jumpDefinition in interface ViTextView

anonymousMark

public void anonymousMark(ViTextView.MARKOP op,
                          int count)
Description copied from interface: ViTextView
Anonymous mark handling. Count is the Nth mark forward, back. It is ignored by TOGGLE.

Specified by:
anonymousMark in interface ViTextView

jumpList

public void jumpList(ViTextView.JLOP op,
                     int count)
Description copied from interface: ViTextView
Jump list handling

Specified by:
jumpList in interface ViTextView

foldOperation

public void foldOperation(ViTextView.FOLDOP op)
Description copied from interface: ViTextView
Perform the fold operation.

Specified by:
foldOperation in interface ViTextView

foldOperation

public void foldOperation(ViTextView.FOLDOP op,
                          int offset)
Description copied from interface: ViTextView
Perform the fold operation.

Specified by:
foldOperation in interface ViTextView

wordMatchOperation

public void wordMatchOperation(ViTextView.WMOP op)
Specified by:
wordMatchOperation in interface ViTextView

tabOperation

public void tabOperation(ViTextView.TABOP op,
                         int count)
Description copied from interface: ViTextView
move to other file tab.
For NEXT,PREV if count == 0 then neighboring tab; if count != 0 then countTh tab, where first is one

Specified by:
tabOperation in interface ViTextView

computeCursorPosition

public void computeCursorPosition(MutableInt offset,
                                  MutableInt line,
                                  MutableInt column)
Description copied from interface: ViTextView
Determine cursor position, all args get set (call by reference).

Specified by:
computeCursorPosition in interface ViTextView

computeCursorPosition

public void computeCursorPosition(int offset,
                                  MutableInt line,
                                  MutableInt column)

getViewTopLine

public int getViewTopLine()
Specified by:
getViewTopLine in interface ViTextView
Returns:
the line number of first visible line in window

getViewBottomLine

public int getViewBottomLine()
Specified by:
getViewBottomLine in interface ViTextView
Returns:
the line number of line *after* end of window

setViewTopLine

public void setViewTopLine(int line)
Description copied from interface: ViTextView
cause the idndicated line to be displayed as top line in view.

Specified by:
setViewTopLine in interface ViTextView

getViewBlankLines

public int getViewBlankLines()
Specified by:
getViewBlankLines in interface ViTextView
Returns:
the number of unused lines on the display

getViewLines

public int getViewLines()
Specified by:
getViewLines in interface ViTextView
Returns:
the number of lines in window

scroll

public void scroll(int n_lines)
Scroll down (n_lines positive) or up (n_lines negative) the specified number of lines.

Specified by:
scroll in interface ViTextView

getViewCoordTopLine

public int getViewCoordTopLine()
Specified by:
getViewCoordTopLine in interface ViTextView
Returns:
the line number of first visible line in window

setViewCoordTopLine

public void setViewCoordTopLine(int coordLine)
Description copied from interface: ViTextView
cause the idndicated line to be displayed as top line in view.

Specified by:
setViewCoordTopLine in interface ViTextView

getViewCoordBlankLines

public int getViewCoordBlankLines()
Specified by:
getViewCoordBlankLines in interface ViTextView
Returns:
the number of unused lines on the display

getViewCoordBottomLine

public int getViewCoordBottomLine()
Specified by:
getViewCoordBottomLine in interface ViTextView
Returns:
the line number of line *after* end of window

getCoordLineCount

public int getCoordLineCount()
Specified by:
getCoordLineCount in interface ViTextView

getCoordLine

public int getCoordLine(int line)
Specified by:
getCoordLine in interface ViTextView

getBufferLineOffset

public int getBufferLineOffset(int coordLine)
Description copied from interface: ViTextView
Reverse of getCoordLine, convert coord line to document line

Specified by:
getBufferLineOffset in interface ViTextView

setCursorCoordLine

public void setCursorCoordLine(int coordLine,
                               int col)
Specified by:
setCursorCoordLine in interface ViTextView

coladvanceCoord

public int coladvanceCoord(int lineOffset,
                           int colIdx)
Specified by:
coladvanceCoord in interface ViTextView

updateCursor

public void updateCursor(ViCursor cursor)
Description copied from interface: ViTextView
Change the cursor shape

Specified by:
updateCursor in interface ViTextView

win_quit

public void win_quit()
Quit editing window. Can close last view.

Specified by:
win_quit in interface ViTextView

win_split

public void win_split(int n)
Split this window.

Specified by:
win_split in interface ViTextView
Parameters:
n - the size of the new window.

win_close

public void win_close(boolean freeBuf)
Close this window

Specified by:
win_close in interface ViTextView
Parameters:
freeBuf - true if the related buffer may be freed

win_close_others

public void win_close_others(boolean forceit)
Close other windows

Specified by:
win_close_others in interface ViTextView
Parameters:
forceit - true if always hide all other windows

win_goto

public void win_goto(int n)
Goto the indicated buffer.

Specified by:
win_goto in interface ViTextView
Parameters:
n - the index of the window to make current

win_cycle

public void win_cycle(int n)
Cycle to the indicated buffer.

Specified by:
win_cycle in interface ViTextView
Parameters:
n - the positive/negative number of windows to cycle.

getStatusDisplay

public ViStatusDisplay getStatusDisplay()
Description copied from interface: ViTextView
Handle displayable editor state changes

Specified by:
getStatusDisplay in interface ViTextView

getOps

public TextOps getOps()

updateVisualState

public void updateVisualState()
Update the selection highlight.

Specified by:
updateVisualState in interface ViTextView

updateHighlightSearchState

public void updateHighlightSearchState()
Description copied from interface: ViTextView
Update the hightlight search state

Specified by:
updateHighlightSearchState in interface ViTextView

applyBackground

protected void applyBackground(int[] blocks,
                               MutableAttributeSet mas)