站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

Term (Terminal Emulator) - NetBeans API Javadoc (Current Development Version)

org.netbeans.lib.terminalemulator 1.2

org.netbeans.lib.terminalemulator
Class Term

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.netbeans.lib.terminalemulator.Term
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
StreamTerm

public class Term
extends JComponent
implements Accessible

Term is a pure Java multi-purpose terminal emulator.

It has the following generic features:

Coordinate systems

The following coordinate systems are used with Term. They are all cartesian and have their origin at the top left. All but the first are 0-origin. But they differ in all other respects:
ANSI Screen coordinates
Address only the visible portion of the screen. They are 1-origin and extend thru the width and height of the visible portion of the screen per getColumns() and getRows().

This is how an application (like 'vi' etc) views the screen. This coordinate system primarily comes into play in the cursor addressing directive, op_cm() and otherwise is not really used in the implementation.

Cell coordinates
Each character usually takes one cell, and all placement on the screen is in terms of a grid of cells getColumns() wide This cellular nature is why fixed font is "required". In some locales some characters may be double-width. Japanese characters are like this, so they take up two cells. There are no double-height characters (that I know of).

Cursor motion is in cell coordinates, so to move past a Japanese character you need the cursor to move right twice. A cursor can also be placed on the second cell of a double-width character.

Note that this is strictly an internal coordinate system. For example Term.getCursorCol() and getCursorCoord() return buffer coordinates.

The main purpose of this coordinate system is to capture logical columns. In the vertical direction sometimes it extends only the height of the screen and sometimes the height of the buffer.

Buffer coordinates ...
... address the whole history character buffer. These are 0-origin and extend thru the width of the screen per getColumns(), or more if horizontal scrolling is enabled, and the whole history, that is, getHistorySize()+getRows().

The BCoord class captures the value of such coordinates. It is more akin to the 'int offset' used in the Java text package as opposed to javax.swing.text.Position.

If there are no double-width characters the buffer coords pretty much overlap with cell coords. If double-width characters are added then the buffer column and cell column will have a larger skew the more right you go.

Absolute coordinates ...
... are like Buffer coordinates in the horizontal direction. In the vertical direction their origin is the first line that was sent to the terminal. This line might have scrolled out of history and might no longer be in the buffer. In effect each line ever printed by Term gets a unique Absolute row.

What good is this? The ActiveRegion mechanism maintains coordinates for its' boundaries. As text scrolls out of history buffer row coordinates have to shift and all ActiveRegions' coords need to be relocated. This can get expensive because as soon as the history buffer becomes full each newline will require a relocation. This is the approach that javax.swing.text.Position implements and it's justified there because no Swing component has a "history buffer". However, if you use absolute coordinates you'll never have to relocate anything! Simple and effective.

Well almost. What happens when you reach Integer.MAX_VALUE? You wrap and that can confuse everything. What are the chances of this happening? Suppose term can process 4000 lines per second. A runaway process will produce Integer.MAX_VALUE lines in about 4 days. That's too close for comfort, so Term does detect the wrap and only then goes and relocates stuff. This, however, causes a secondary problem with testability since no-one wants to wait 4 days for a single wrap. So what I've done is periodically set Term.modulo to something smaller and tested stuff.

I'm indebted to Alan Kostinsky for this bit of lateral thinking.

Modes of use

There are three ways Term can be used. These modes aren't explicit they are just a convenient way of discussing functionality.
Screen mode
This represents the traditional terminal without a history buffer. Applications running under the terminal assume they are dealing with a fixed size screen and interact with it in the screen coordinate system through escape sequence (ANSI or otherwise). The most common application which uses terminals in this ways is the screen editor, like vi or emacs.

Term will convert keystrokes to an output stream and will process characters in an input stream and render them unto the screen. What and how these streams are connected to is up to the client of Term, since it is usually highly platform dependent. For example on unixes the streams may be connected to partially-JNI-based "pty" streams.

This mode works correctly even if there is history and you see a scrollbar, just as it does under XTerm and it's derivatives.

Buffer/Interactive mode
This is the primary facility that XTerm and other derivatives provide. The screen has a history buffer in the vertical dimension.

Because of limited history active regions can scroll out of history and while the coordinate invalidation problem is not addressed by absolute coordiantes sometimes we don't want stuff to wink out.
Which is why we have ...

Page mode
It is possible to "anchor" a location in the buffer and prevent it from going out of history. This can be helpful in having the client of Term make sure that crucial output doesn't get lost due to short-sighted history settings on the part of the user.

To use Term in this mode you can use setText() or appendText() instead of connecting to Terms streams. This mode is called page mode because the most common use of it would be as something akin to a hypertext browser. To that end Term supports nestable ActiveRegions and mapping of coordinates to regions. ActiveTerm puts all of this together in a comprehensive subclass.

What Term is not

See Also:
Serialized Form

Nested Class Summary
protected  class Term.AccessibleTerm
           
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int DEBUG_INPUT
           
static int DEBUG_KEYS
           
static int DEBUG_MARGINS
           
static int DEBUG_OPS
           
static int DEBUG_OUTPUT
           
static int DEBUG_WRAP
           
protected  int firsta
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
Term()
          Constructor
 
Method Summary
 void addInputListener(TermInputListener l)
          Add an input listener to this.
 void addListener(TermListener l)
          Add a TermListener to this.
 Coord advance(Coord c)
          Advance the coordinate by one charater and return new coord.
 void appendText(String text, boolean repaint)
          Add new text at the current cursor position.
 Coord backup(Coord c)
          Back up the coordinate by one character and return new Coord.
 int charWidth(char c)
          Return the cell width of the given character.
 void clear()
          Clear the visible portion of screen
 void clearHistory()
          Clear all of the history, including any visible portion of it.
 void clearHistoryNoRefresh()
          Clear all of the history without repainting the screen.
 void clearSelection()
          Clear the selection.
 void columnLeft(int n)
          Scroll the view 'n' columns to the left.
 void columnRight(int n)
          Scroll the view 'n' columns to the right.
 int CoordToPosition(Coord c)
          [DO NOT USE] Convert a 2D Coord to a 1D linear position.
 void copy()
          Transfer selected text into clipboard.
 void copyToClipboard()
          Transfer selected text into clipboard.
 void copyToSelection()
          Transfer selected text into selection.
protected  boolean debugInput()
          Return true if DEBUG_INPUT flag has been set.
protected  boolean debugOutput()
          Return true if DEBUG_OUTPUT flag has been set.
 Extent extentInLogicalLine(Coord begin, int offset, int length)
          Convert offsets in logical lines into physical coordinates.
 void fillSizeInfo(Dimension cells, Dimension pixels)
           
 void flush()
          Force a repaint.
 AccessibleContext getAccessibleContext()
          Since Term is a composite widget the main accessible JComponent is not Term but an internal JComponent.
 Color getActiveColor()
          Get the feedback color of active regions.
 JComponent getCanvas()
          Deprecated.  
 int getColumns()
          Get the number of character columns in the screen
 int getCursorCol()
          Get cursor column in buffer coordinates (0-origin)
 Coord getCursorCoord()
          Get (absolute) cursor coordinates.
 int getCursorRow()
          Get cursor row in buffer coordinates (0-origin).
 String getEmulation()
          Returns the termcap string that best describes what this Term emulates.
 Dimension getGlyphCellSize()
          Get the usable area for drawing glyphs This value changes when the gutter width or the font changes
 Color getHighlightColor()
          Get the color of the hilite (selection) - for non XOR mode
 Color getHighlightXORColor()
          Get the color of the hilite (selection) - for XOR mode
 int getHistoryBuffSize()
          returns curent history size of buffer.
 int getHistorySize()
          Return the number of lines in history
 org.netbeans.lib.terminalemulator.Interp getInterp()
          Return the Interpreter assigned to this.
 HashSet getKeyStrokeSet()
          Get KeyStroke set.
 int getRows()
          Get the number of character rows in the screen
 String getRowText(int row)
           
 JComponent getScreen()
          Returns the actual drawing area so events can be interposed upon, like context menus.
 String getSelectedText()
          Get contents of current selection.
 Extent getSelectionExtent()
          Get the extent of the current selection.
 int getTabSize()
          Get the TAB size.
 WordDelineator getWordDelineator()
          Get the WordDelineator used by this.
 void goTo(Coord coord)
           
 boolean isAnchored()
          Return true if the text is currently anchored.
 boolean isAutoCopy()
          Deprecated. Now always returns 'true'.
 boolean isClickToType()
           
 boolean isCoordVisible(Coord target)
          If the given coordinate is visible within the screen returns true, otherwise returns false.
 boolean isCursorVisible()
          Find out if cursor is visible.
 boolean isHorizontallyScrollable()
           
 boolean isReadOnly()
          Return whether keystrokes are ignored.
 boolean isRefreshEnabled()
           
 boolean isReverseVideo()
          Return the value set by setReverseVideo().
 boolean isScrollOnInput()
          Return whether Term scrolls to the bottom on keyboard input.
 boolean isScrollOnOutput()
          Return whether Term scrolls on any output.
 boolean isSelectionXOR()
           
 boolean isSizeRounded()
          Returns true if Term will round down resize requests to character cell size.
 boolean isTrackCursor()
          Return whether Term will scroll to track the cursor as text is added.
 void lineDown(int n)
          Scroll the view 'n' lines down.
 void lineUp(int n)
          Scroll the view 'n' lines up.
 Point mapToBufRowCol(Point p)
          Convert pixel coords to (history) buffer row/column coords (both 0-origin).
 Point mapToViewRowCol(Point p)
          Convert pixel coords to view (visible area) row/column coords (both o-origin).
 Ops ops()
          Return the terminal operations implementation.
 void pageDown(int n)
          Scroll the view 'n' pages down.
 void pageLeft(int n)
          Scroll the view 'n' pages to the left.
 void pageRight(int n)
          Scroll the view 'n' pages to the right.
 void pageUp(int n)
          Scroll the view 'n' pages up.
 void paste()
           
 void pasteFromClipboard()
          Transfer contents of clipboard to Terms input stream.
 void pasteFromSelection()
          Transfer contents of selection to Terms input stream.
 Coord PositionToCoord(int position)
          [DO NOT USE] Convert a 1D linear position to a 2D Coord.
protected  void possibly_repaint(boolean adjust_scrollbar)
           
 void possiblyNormalize(ActiveRegion region)
          Ensure that maximum of the given region is visible.
 void possiblyNormalize(Coord target)
          Ensure that the given coordinate is visible.
 void printStats(String message)
           
 void pushStream(TermStream stream)
           
 void putChar(char c)
          Send a character to the terminal screen.
 void putChars(char[] buf, int offset, int count)
          Send several characters to the terminal screen.
 RegionManager regionManager()
          Return the RegionManager associated with this Term
 void removeInputListener(TermInputListener l)
           
 void removeListener(TermListener l)
          Remove the given TermListener from this.
protected  void repaint(boolean adjust_scrollbar)
          Model and or view settings have changed, redraw everything.
 void requestFocus()
          Override of JComponent.
 boolean requestFocusInWindow()
           
 void reverseVisitLogicalLines(Coord begin, Coord end, LogicalLineVisitor llv)
          Visit logical lines in reverse from end through begin.
 void setActiveColor(Color color)
          Set the feedback color of active regions.
 void setAnchored(boolean anchored)
          Control whether an anchor is set.
 void setAttribute(int value)
          Set the display attribute for characters printed from now on.
 void setAutoCopy(boolean auto_copy)
          Deprecated. selections now always get copied to systemSelection if it exists.
 void setCharacterAttribute(Coord begin, Coord end, int value, boolean on)
          Set or unset the display attribute for characters from 'begin' to 'end' inclusive to 'value' depending on the value of 'on'.
 void setClickToType(boolean click_to_type)
          Set/unset focus policy.
 void setColumns(int cols)
          Set the number of character columns in the screen.
 void setCursorCoord(Coord coord)
          Move the cursor to the given (absolute) coordinates SHOULD be setCursorCoord!
 void setCursorVisible(boolean cursor_visible)
          Control whether the cursor is visible or not.
 void setCustomColor(int number, Color c)
          Register up to 8 new custom colors.
 void setDebugFlags(int flags)
           
 void setEmulation(String emulation)
          Set the Interpreter type by name.
 void setEnabled(boolean enabled)
          Override of JComponent.
 void setFont(Font new_font)
          Override of JComponent.
 void setGlyph(int glyph_id, int background_id)
           
 void setGlyphGutterWidth(int pixels)
          Set the width of the glyph gutter in pixels
 void setGlyphImage(int glyph_number, Image image)
          Associate an Image with a glyph id, or clear it if image is null.
 void setHighlightColor(Color color)
          Set the color of the hilite (selection) - for non XOR mode
 void setHighlightXORColor(Color color)
          Set the color of the hilite (selection) - for XOR mode
 void setHistorySize(int new_size)
          Set how many lines of history will be available.
 void setHorizontallyScrollable(boolean horizontally_scrollable)
          Controls horizontal scrolling and line wrapping.
 void setInputListener(TermInputListener l)
          Deprecated. Replaced by addInputListener(TermInputListener).
 void setInterp(org.netbeans.lib.terminalemulator.Interp interp)
          Set the emulation interpreter.
 void setKeyStrokeSet(HashSet keystroke_set)
           
 void setListener(TermListener l)
          Deprecated. Replaced byaddListener(TermListener).
 void setReadOnly(boolean read_only)
          Control whether keystrokes are ignored.
 void setRefreshEnabled(boolean refresh_enabled)
           
 void setReverseVideo(boolean reverse_video)
          Control whether the default foreground and background colors will be reversed.
 void setRowGlyph(int row, int glyph_id, int background_id)
           
 void setRows(int rows)
          Set the number of character rows in the screen.
 void setRowsColumns(int rows, int columns)
          Simultaneously set the number of character rows and columns.
 void setScrollOnInput(boolean scroll_on_input)
          Control whether Term scrolls to the bottom on keyboard input.
 void setScrollOnOutput(boolean scroll_on_output)
          Control whether Term scrolls on any output.
 void setSelectionExtent(Extent extent)
          Set the extent of the selection.
 void setSelectionXOR(boolean selection_xor)
          Sets whether the selection highlighting is XOR style or normal Swing style.
 void setSizeRounded(boolean size_rounded)
          Governs whether Term will round down resize requests to character cell size.
 void setTabSize(int tab_size)
          Set the TAB size.
 void setText(String text)
          Clear everything and assign new text.
 void setTrackCursor(boolean track_cursor)
          Control whether Term will scroll to track the cursor as text is added.
 void setWordDelineator(WordDelineator word_delineator)
          Set/unset WordDelineator.
 String textWithin(Coord begin, Coord end)
           
 Point toPixel(Coord target)
          Convert row/column coords to pixel coords within the widgets coordinate system.
protected  void updateTtySize()
          Once the terminal is connected to something, use this function to send all Term Listener notifications.
 void visitLogicalLines(Coord begin, Coord end, LogicalLineVisitor llv)
          Visit logical lines from begin through end.
 
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, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

firsta

protected int firsta

DEBUG_OPS

public static final int DEBUG_OPS
See Also:
Constant Field Values

DEBUG_KEYS

public static final int DEBUG_KEYS
See Also:
Constant Field Values

DEBUG_INPUT

public static final int DEBUG_INPUT
See Also:
Constant Field Values

DEBUG_OUTPUT

public static final int DEBUG_OUTPUT
See Also:
Constant Field Values

DEBUG_WRAP

public static final int DEBUG_WRAP
See Also:
Constant Field Values

DEBUG_MARGINS

public static final int DEBUG_MARGINS
See Also:
Constant Field Values
Constructor Detail

Term

public Term()
Constructor

Method Detail

pushStream

public void pushStream(TermStream stream)

setDebugFlags

public void setDebugFlags(int flags)

debugInput

protected boolean debugInput()
Return true if DEBUG_INPUT flag has been set.


debugOutput

protected boolean debugOutput()
Return true if DEBUG_OUTPUT flag has been set.


setWordDelineator

public void setWordDelineator(WordDelineator word_delineator)
Set/unset WordDelineator. Passing a null sets it to the default WordDelineator.


getWordDelineator

public WordDelineator getWordDelineator()
Get the WordDelineator used by this.


setInputListener

public void setInputListener(TermInputListener l)
Deprecated. Replaced by addInputListener(TermInputListener).

Set/unset input listener. Entered text gets sent via this listener


addInputListener

public void addInputListener(TermInputListener l)
Add an input listener to this.

Text entered via the keyboard gets sent via this listener.


removeInputListener

public void removeInputListener(TermInputListener l)

setListener

public void setListener(TermListener l)
Deprecated. Replaced byaddListener(TermListener).

Set/unset misc listener. The following events gets sent via this listener: window size changes


addListener

public void addListener(TermListener l)
Add a TermListener to this.


removeListener

public void removeListener(TermListener l)
Remove the given TermListener from this.


setClickToType

public void setClickToType(boolean click_to_type)
Set/unset focus policy.
When set, the Term screen will grab focus when clicked on, otherwise it will grab focus when the mouse moves into it.


isClickToType

public boolean isClickToType()

setReadOnly

public void setReadOnly(boolean read_only)
Control whether keystrokes are ignored.


isReadOnly

public boolean isReadOnly()
Return whether keystrokes are ignored.


clear

public void clear()
Clear the visible portion of screen


clearHistoryNoRefresh

public void clearHistoryNoRefresh()
Clear all of the history without repainting the screen.

This is useful if you want to avoid flicker.


clearHistory

public void clearHistory()
Clear all of the history, including any visible portion of it.

Use clearHistoryNoRefresh() if you find that clearHistory causes flickering.


regionManager

public RegionManager regionManager()
Return the RegionManager associated with this Term


textWithin

public String textWithin(Coord begin,
                         Coord end)

getRowText

public String getRowText(int row)

getKeyStrokeSet

public HashSet getKeyStrokeSet()
Get KeyStroke set.

Be default Term consumes all keystrokes. Any KeyStroke added to this set will be passed through and not consumed.

Be careful with control characters you need to create the keystroke as follows (note the - 64):

 KeyStroke.getKeyStroke(new Character((char)('T'-64)), Event.CTRL_MASK)
 


setKeyStrokeSet

public void setKeyStrokeSet(HashSet keystroke_set)

visitLogicalLines

public void visitLogicalLines(Coord begin,
                              Coord end,
                              LogicalLineVisitor llv)
Visit logical lines from begin through end.

If begin is null, then the start of the buffer is assumed. If end is null, then the end of the buffer is assumed.


reverseVisitLogicalLines

public void reverseVisitLogicalLines(Coord begin,
                                     Coord end,
                                     LogicalLineVisitor llv)
Visit logical lines in reverse from end through begin.

If begin is null, then the start of the buffer is assumed. If end is null, then the end of the buffer is assumed.


extentInLogicalLine

public Extent extentInLogicalLine(Coord begin,
                                  int offset,
                                  int length)
Convert offsets in logical lines into physical coordinates.

Usually called from within a LogicalLineVisitor.visit(). 'begin' should be the 'begin' Coord passed to visit. 'offset' is an offset into the logical line, the 'text' argument passed to visit().

Note that 'offset' is relative to begin.col!

Following is an example of a line "aaaaaxxxxxxxxxXXXxxxxxxxx" which got wrapped twice. Suppose you're searching for "XXX" and you began your search from the first 'x' on row 2.

            row |  columns |
            ----+----------+
            0   |0123456789|
            1   |          |
            2   |aaaaaxxxxx| wrap
            3   |xxxxXXXxxx| wrap
            4   |xxxxx     |
            5   |          |

 
The visitor will be called with 'begin' pointing at the first 'x', 'end' pointing at the last 'x' and 'text' containing the above line. Let's say you use String.indexOf("XXX") and get an offset of 9. Passing the 'begin' through and the 9 as an offset and 3 as the length will yield an Extent (3,4) - (3,7) which youcan forward to setSelectionExtent();

The implementation of this function is not snappy (it calls Term.advance() in a loop) but the assumption is that his function will not be called in a tight loop.


possiblyNormalize

public void possiblyNormalize(Coord target)
Ensure that the given coordinate is visible.

If the given coordinate is visible within the screen nothing happens. Otherwise the screen is scrolled so that the given target ends up approximately mid-sceeen.


possiblyNormalize

public void possiblyNormalize(ActiveRegion region)
Ensure that maximum of the given region is visible.

If the given region is visible within the screen nothing happens. If the region is bigger than the screen height, first line of the region will be displayed in first line of screen and end of region won't be displayed. If the region is bigger than the half of screen height, last line of the region will be displayed in the last line of the screen. Otherwise the region will start approximately in mid-sceeen


isCoordVisible

public boolean isCoordVisible(Coord target)
If the given coordinate is visible within the screen returns true, otherwise returns false.


setAttribute

public void setAttribute(int value)
Set the display attribute for characters printed from now on.

Unrecognized values silently ignored.


setCharacterAttribute

public void setCharacterAttribute(Coord begin,
                                  Coord end,
                                  int value,
                                  boolean on)
Set or unset the display attribute for characters from 'begin' to 'end' inclusive to 'value' depending on the value of 'on'.

Will cause a repaint.


setGlyph

public void setGlyph(int glyph_id,
                     int background_id)

setRowGlyph

public void setRowGlyph(int row,
                        int glyph_id,
                        int background_id)

getHistoryBuffSize

public int getHistoryBuffSize()
returns curent history size of buffer.


printStats

public void printStats(String message)

paste

public void paste()

pasteFromSelection

public void pasteFromSelection()
Transfer contents of selection to Terms input stream.

The pasted content is sent through sendChars.
The paste will silently fail if:

  • The selection has null contents.
  • The selections data flavor is not string.


pasteFromClipboard

public void pasteFromClipboard()
Transfer contents of clipboard to Terms input stream.

The pasted content is sent through sendChars.
The paste will silently fail if:

  • The selection has null contents.
  • The selections data flavor is not string.


copy

public void copy()
Transfer selected text into clipboard.


copyToClipboard

public void copyToClipboard()
Transfer selected text into clipboard.


copyToSelection

public void copyToSelection()
Transfer selected text into selection.


setRows

public void setRows(int rows)
Set the number of character rows in the screen.

See setRowsColumns() for some additional important information.


getRows

public int getRows()
Get the number of character rows in the screen


setColumns

public void setColumns(int cols)
Set the number of character columns in the screen.

See setRowsColumns() for some additional important information.


getColumns

public int getColumns()
Get the number of character columns in the screen


setRowsColumns

public void setRowsColumns(int rows,
                           int columns)
Simultaneously set the number of character rows and columns.

A Term is a composite widget made of a contained screen (getScreen()) and a scrollbar. It is not a JScrollPane. You're actually setting the screen size here.

Setting the column size also sets the width of the buffer. This doesn't alter the length (column at which lines were wrapped) of past lines, but only new additional lines. For example, if you set columns to 20, print a bunch of lines that wrap, then resize to 80 columns, all the lines that were wrapped to 20 will stay wrapped that way. This is consistent with xterm behaviour.

If this Term is embedded in a component with a layout manager that is set up to accept child resizes gracefully this widget will be resized as expected.

Alternatively if this Term is embedded in a Window (like JFrame) the window will need to be re-pack()ed as it does not accomodate it's childrens size changes. This has to be done by the application using Term. The best way to do this is to add a TermListener() and call pack() on the appropriate window when a resize notification is fired.


setSizeRounded

public void setSizeRounded(boolean size_rounded)
Governs whether Term will round down resize requests to character cell size.

Sizes are usually set by containers' layout managers. If rounding is enabled Term will attempt to adjust the size to an even multiple of the character cell size.

The layout manager might not neccesarily honor the rounded size. The situation can be somewhat improved by making sure that the ultimate container is re-packed as described in setRowsColumns(int, int).


isSizeRounded

public boolean isSizeRounded()
Returns true if Term will round down resize requests to character cell size.

See setSizeRounded(boolean) for more info.


fillSizeInfo

public void fillSizeInfo(Dimension cells,
                         Dimension pixels)

updateTtySize

protected void updateTtySize()
Once the terminal is connected to something, use this function to send all Term Listener notifications.


toPixel

public Point toPixel(Coord target)
Convert row/column coords to pixel coords within the widgets coordinate system. It returns the pixel of the upper left corner of the target cell.


mapToViewRowCol

public Point mapToViewRowCol(Point p)
Convert pixel coords to view (visible area) row/column coords (both o-origin).

In the returned Point, x represents the column, y the row.


mapToBufRowCol

public Point mapToBufRowCol(Point p)
Convert pixel coords to (history) buffer row/column coords (both 0-origin).

In the returned Point, x represents the column, y the row.


putChar

public void putChar(char c)
Send a character to the terminal screen.


putChars

public void putChars(char[] buf,
                     int offset,
                     int count)
Send several characters to the terminal screen.
While 'buf' will have a size it may not be fully filled, hence the explicit 'nchar'.


flush

public void flush()
Force a repaint.

Normally a putChar() or putChars() will call repaint, unless ... setRepaintEnabled() has been called with false. This function allows for some flexibility wrt to buffering and flushing:

                term.setRefreshEnabled(false);
                for (cx = 0; cx < buf.length; cx++) {
                        term.putChar(c);
                        if (c % 10 == 0)
                                term.flush();
                }
                term.setRefreshEnabled(true);
 


possibly_repaint

protected void possibly_repaint(boolean adjust_scrollbar)

repaint

protected void repaint(boolean adjust_scrollbar)
Model and or view settings have changed, redraw everything.


setReverseVideo

public void setReverseVideo(boolean reverse_video)
Control whether the default foreground and background colors will be reversed.

Note: This is independent of characters' reverse attribute.


isReverseVideo

public boolean isReverseVideo()
Return the value set by setReverseVideo().


setHighlightColor

public void setHighlightColor(Color color)
Set the color of the hilite (selection) - for non XOR mode


getHighlightColor

public Color getHighlightColor()
Get the color of the hilite (selection) - for non XOR mode


setHighlightXORColor

public void setHighlightXORColor(Color color)
Set the color of the hilite (selection) - for XOR mode


getHighlightXORColor

public Color getHighlightXORColor()
Get the color of the hilite (selection) - for XOR mode


setActiveColor

public void setActiveColor(Color color)
Set the feedback color of active regions.


getActiveColor

public Color getActiveColor()
Get the feedback color of active regions.


setAnchored

public void setAnchored(boolean anchored)
Control whether an anchor is set.

Setting an anchor will automatically cause the buffer to grow, in excess of what was set by setHistorySize(), to ensure that whatever is displayed and in the current history will still be accessible.

Also, if you're working with Extents, Coords and ActiveRegions, or visiting logical lines, you might want to anchor the text so that your coordinates don't get invalidated by lines going out of the buffer.

Repeated enabling of the anchor will discard all text that doesn't fit in history and start a new anchor.

When anchoring is disabled any text in excess of setHistorySize() is trimmed and the given history size comes into effect again.


isAnchored

public boolean isAnchored()
Return true if the text is currently anchored.


getCanvas

public JComponent getCanvas()
Deprecated. 

Returns the actual drawing area so events can be interposed upon, like context menus.


getScreen

public JComponent getScreen()
Returns the actual drawing area so events can be interposed upon, like context menus.


ops

public Ops ops()
Return the terminal operations implementation. WARNING! This is temporary


setEmulation

public void setEmulation(String emulation)
Set the Interpreter type by name.

See Also:
setInterp(org.netbeans.lib.terminalemulator.Interp)

getEmulation

public String getEmulation()
Returns the termcap string that best describes what this Term emulates.


setInterp

public void setInterp(org.netbeans.lib.terminalemulator.Interp interp)
Set the emulation interpreter.

It is not advisable to change the emulation after Term has been connected to a process, since it's often impossible to advise the process of the new terminal type.


getInterp

public org.netbeans.lib.terminalemulator.Interp getInterp()
Return the Interpreter assigned to this.


setHistorySize

public void setHistorySize(int new_size)
Set how many lines of history will be available.

If an anchor is in effect the history size will only have an effect when the anchor is reset.


getHistorySize

public int getHistorySize()
Return the number of lines in history


setGlyphGutterWidth

public void setGlyphGutterWidth(int pixels)
Set the width of the glyph gutter in pixels


setGlyphImage

public void setGlyphImage(int glyph_number,
                          Image image)
Associate an Image with a glyph id, or clear it if image is null. Numbering the glyphs is confusing. They start with 48. That is, if you register glyph #0 using hbvi/vim :K command the escape sequence emitted is 48. 48 is ascii '0'.


getGlyphCellSize

public Dimension getGlyphCellSize()
Get the usable area for drawing glyphs This value changes when the gutter width or the font changes


setCustomColor

public void setCustomColor(int number,
                           Color c)
Register up to 8 new custom colors. Unlike glyph id's you can start the numbers from 0. hbvi/vim's :K command will add a 58 to the number, but that is the code we interpret as custom color #0.


getCursorRow

public int getCursorRow()
Get cursor row in buffer coordinates (0-origin).


getCursorCol

public int getCursorCol()
Get cursor column in buffer coordinates (0-origin)


getCursorCoord

public Coord getCursorCoord()
Get (absolute) cursor coordinates.

The returned Coord is newly allocated and need not be cloned.


goTo

public void goTo(Coord coord)

setCursorCoord

public void setCursorCoord(Coord coord)
Move the cursor to the given (absolute) coordinates SHOULD be setCursorCoord!


setCursorVisible

public void setCursorVisible(boolean cursor_visible)
Control whether the cursor is visible or not.

We don't want a visible cursor when we're using Term in non-interactve mode.


isCursorVisible

public boolean isCursorVisible()
Find out if cursor is visible.


backup

public Coord backup(Coord c)
Back up the coordinate by one character and return new Coord.

Travels back over line boundaries
Returns null if 'c' is the first character in the buffer.


advance

public Coord advance(Coord c)
Advance the coordinate by one charater and return new coord.

Travels forward over line boundaries.
Returns null if 'c' is the last character in the buffer.


getSelectedText

public String getSelectedText()
Get contents of current selection.

Returns 'null' if there is no current selection.


getSelectionExtent

public Extent getSelectionExtent()
Get the extent of the current selection.

If there is no selection returns 'null'.


setSelectionExtent

public void setSelectionExtent(Extent extent)
Set the extent of the selection.


clearSelection

public void clearSelection()
Clear the selection.


setAutoCopy

public void setAutoCopy(boolean auto_copy)
Deprecated. selections now always get copied to systemSelection if it exists.

Set whether slections automatically get copied to the systemSelection when the selection is completed (the button is released).

This is how xterm and other X-windows selections work.

This property can probably be deprecated. It was neccessary in the pre-1.4.2 days when we didn't have a systemSelection and we wanted to have the option of not cloberring the systemClipboard on text selection.


isAutoCopy

public boolean isAutoCopy()
Deprecated. Now always returns 'true'.

Return the value set by setAutoCopy()


setRefreshEnabled

public void setRefreshEnabled(boolean refresh_enabled)

isRefreshEnabled

public boolean isRefreshEnabled()

setSelectionXOR

public void setSelectionXOR(boolean selection_xor)
Sets whether the selection highlighting is XOR style or normal Swing style.


isSelectionXOR

public boolean isSelectionXOR()

setTabSize

public void setTabSize(int tab_size)
Set the TAB size.

The cursor is moved to the next column such that

 column (0-origin) modulo tab_size == 0
 
The cursor will not go past the last column.

Note that the conventional assumption of what a tab is, is not entirely accurate. ANSI does not define TABs as above but rather as a directive to move to the next "tabstop" which has to have been set previously. In fact on unixes it is the terminal line discipline that expands tabs to spaces in the conventional way. That in, turn explains why TAB information doesn't make it into selections and why copying and pasting Makefile instructions is liable to lead to hard-to-diagnose make rpoblems, which, in turn drove the ANT people to reinvent the world.


getTabSize

public int getTabSize()
Get the TAB size.


setScrollOnInput

public void setScrollOnInput(boolean scroll_on_input)
Control whether Term scrolls to the bottom on keyboard input.

This is analogous to the xterm -sk/+sk option.


isScrollOnInput

public boolean isScrollOnInput()
Return whether Term scrolls to the bottom on keyboard input.


setScrollOnOutput

public void setScrollOnOutput(boolean scroll_on_output)
Control whether Term scrolls on any output.

When set to false, if the user moves the scrollbar to see some text higher up in history, the view will not change even if more output is produced. But if the cursor is visible, scrolling will happen. This is so that in an interactive session any prompt will be visible etc.

However, the tracking of the cursor is controlled by the 'trackCursor' property which by default is set to 'true'.

This property is analogous to the xterm -si/+si option.


isScrollOnOutput

public boolean isScrollOnOutput()
Return whether Term scrolls on any output.


setTrackCursor

public void setTrackCursor(boolean track_cursor)
Control whether Term will scroll to track the cursor as text is added.

If set to true, as output is being generated Term will try to keep the cursor in view.

This property is only relevant when scrollOnOutput is set to false. If scrollOnOutput is true, this property is also implicitly true.


isTrackCursor

public boolean isTrackCursor()
Return whether Term will scroll to track the cursor as text is added.


setHorizontallyScrollable

public void setHorizontallyScrollable(boolean horizontally_scrollable)
Controls horizontal scrolling and line wrapping.

When enabled a horizontal scrollbar becomes visible and line-wrapping is disabled.


isHorizontallyScrollable

public boolean isHorizontallyScrollable()

setText

public void setText(String text)
Clear everything and assign new text.

If the size of the text exceeds history early parts of it will get lost, unless an anchor was set using setAnchor().


appendText

public void appendText(String text,
                       boolean repaint)
Add new text at the current cursor position.

Doesn't repaint the view unless 'repaint' is set to 'true'.
Doesn't do anything if 'text' is 'null'.


pageUp

public void pageUp(int n)
Scroll the view 'n' pages up.

A page is the height of the view.


pageDown

public void pageDown(int n)
Scroll the view 'n' pages down.

A page is the height of the view.


lineUp

public void lineUp(int n)
Scroll the view 'n' lines up.


lineDown

public void lineDown(int n)
Scroll the view 'n' lines down.


pageLeft

public void pageLeft(int n)
Scroll the view 'n' pages to the left.


pageRight

public void pageRight(int n)
Scroll the view 'n' pages to the right.


columnRight

public void columnRight(int n)
Scroll the view 'n' columns to the right.


columnLeft

public void columnLeft(int n)
Scroll the view 'n' columns to the left.


charWidth

public int charWidth(char c)
Return the cell width of the given character.


setFont

public void setFont(Font new_font)
Override of JComponent.

We absolutely require fixed width fonts, so if the font is changed we create a monospaced version of it with the same style and size.

Overrides:
setFont in class JComponent

requestFocus

public void requestFocus()
Override of JComponent.

Pass on the request to the screen where all the actual focus management happens.

Overrides:
requestFocus in class JComponent

requestFocusInWindow

public boolean requestFocusInWindow()
Overrides:
requestFocusInWindow in class JComponent

setEnabled

public void setEnabled(boolean enabled)
Override of JComponent.

Pass on enabledness to sub-components (scrollbars and screen)

Overrides:
setEnabled in class JComponent

getAccessibleContext

public AccessibleContext getAccessibleContext()
Since Term is a composite widget the main accessible JComponent is not Term but an internal JComponent. We'll speak of Term accessibility when we in fact are referring to the that inner component.

Accessibility for Term is tricky because it doesn't fit into the roles delineated by Swing. The closest role is that of TEXT and that is too bound to how JTextComponent works. To wit ...

2D vs 1D coordinates
Term has a 2D coordinate system while AccessibleText works with 1D locations. So Term actually has code which translates between the two. This code is not exactly efficient but only kicks in when assistive technology latches on.
Line breaks ('\n's) count as characters! However we only count logical line breaks ('\n's appearing in the input stream) as opposed to wrapped lines!

The current implementation doesn't cache any of the mappings because that would require a word per line extra storage for the cumulative char count. The times actually we're pretty fast with a 4000 line histroy.

WORDs and SENTENCEs
For AccessibleText.get*Index() functions WORD uses the regular Term WordDelineator. SENTENCE translates to just a line.
Character attributes
Term uses the ANSI convention of character attributes so when AccessibleText.getCharacterAttribute() is used a rough translation is made as follows:
  • ANSI underscore -> StyleConstants.Underline
  • ANSI bright/bold -> StyleConstants.Bold
  • Non-black foreground color -> StyleConstants.Foreground
  • Explicitly set background color -> StyleConstants.Background
Font related information is always constant so it is not provided.
History
Term has history and lines wink out. If buffer coordinates were used to interact with accessibility, caretPosition and charCount would be dancing around. Fortunately Term has absolute coordinates. So positions returned via AccessibleText might eventually refer to text that has gone by.
Caret and Mark vs Cursor and Selection
While Term keeps the selection and cursor coordinates independent, JTextComponent merges them and AccessibleText inherits this view. With Term caretPosition is the position of the cursor and selection ends will not neccessarily match with the caret position.

Currently only notifications of ACCESSIBLE_CARET_PROPERTY and ACCESSIBLE_TEXT_PROPERTY are fired and that always in pairs. They are fired on the receipt of any character to be processed.

IMPORTANT: It is assumed that under assistive technology Term will be used primarily as a continuous text output device or a readonly document. Therefore ANSI cursor motion and text editing commands or anything that mutates the text will completely invalidate all of AccessibleTexts properties. (Perhaps an exception SHOULD be made for backspace)

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent

CoordToPosition

public int CoordToPosition(Coord c)
[DO NOT USE] Convert a 2D Coord to a 1D linear position.

This function really should be private but I need it to be public for unit-testing purposes.


PositionToCoord

public Coord PositionToCoord(int position)
[DO NOT USE] Convert a 1D linear position to a 2D Coord.

This function really should be private but I need it to be public for unit-testing purposes.


org.netbeans.lib.terminalemulator 1.2

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.