Package org.ka2ddo.yaac.gui.terminal
Class Terminal
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.ka2ddo.yaac.gui.terminal.Terminal
- All Implemented Interfaces:
KeyListener
,MouseListener
,MouseMotionListener
,ImageObserver
,MenuContainer
,Serializable
,Runnable
,EventListener
public final class Terminal
extends JComponent
implements Runnable, KeyListener, MouseListener, MouseMotionListener
This class implements a simple Terminal window to access interface ports for
debugging. It opens input and output streams to the specified device (Internet
socket or serial device), interprets the bytes from the input stream as
ISO-8859-1 characters (including control characters) to display, and accepts
user input from the keyboard and sends it to the output stream (optionally
locally echoing the entered characters to the screen).
The screen implements a simple emulation of a DEC VT102 screen. It will be 24 lines
tall and either 80 or 132 characters wide. The screen maintains positional and
escape sequence context state from the input characters. It also supports optional
auto-LF for some systems that refuse to send line feeds after carriage returns.
TODO: optionally support UTF-8 instead of ISO-8859-1?
- Author:
- Andrew Pavlin, KA2DDO
- See Also:
-
Nested Class Summary
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
Modifier and TypeFieldDescriptionstatic final InputStream
Fake InputStream that is always at end-of-file.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
ConstructorDescriptionTerminal
(InputStream is, OutputStream os, String portName, boolean echoed) Create a Terminal screen widget for managing the named connection, optionally opening input and output streams from and to that connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAutoFlush
(char ch) Add another character to the set of user-typed characters that cause a output stream flush.void
close()
Shut down a Terminal and close the I/O streams it is connected to.void
displayLocalText
(String text) Display the programmatically-generated text on the Terminal screen.int
Returns the current height of this component.If the minimum size has been set to a non-null
value just returns it.If thepreferredSize
has been set to a non-null
value just returns it.int
getWidth()
Returns the current width of this component.void
Invoked when a key has been pressed.void
Invoked when a key has been released.void
Invoked when a key has been typed.void
Invoked when the mouse button has been clicked (pressed and released) on a component.void
Invoked when a mouse button is pressed on a component and then dragged.void
Invoked when the mouse enters a component.void
Invoked when the mouse exits a component.void
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.void
Invoked when a mouse button has been pressed on a component.void
Invoked when a mouse button has been released on a component.protected void
void
removeAutoFlush
(char ch) Remove a character from the set of user-typed characters that cause a output stream flush.final void
run()
DO NOT CALL.void
setDoAutoLF
(boolean doAutoLF) Specify whether a linefeed should be injected automatically after a carriage return if a linefeed is not explicitly provided by the remote system.void
Set the InputStream to read for characters to display.void
Set the OutputStream to write user-typed characters.static void
showTerminal
(InputStream is, OutputStream os, boolean closeStreamsOnClose, JComponent parent, String portType, String portName) Create a modal Terminal dialog window for the specified pair of streamsvoid
validate()
Validates this container and all of its subcomponents.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, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, 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, transferFocusDownCycle, 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, getAccessibleContext, 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
-
Field Details
-
NULL_INPUT_STREAM
Fake InputStream that is always at end-of-file.
-
-
Constructor Details
-
Terminal
Create a Terminal screen widget for managing the named connection, optionally opening input and output streams from and to that connection.- Parameters:
is
- InputStream to read for characters to display on the screen widget, or null to not open the stream yetos
- OutputStream to write keyboard characters to, or null to not provide an OutputStream yetportName
- String name to title the screen widgetechoed
- boolean true if characters typed into the widget by the user should be displayed, rather than waiting for an echo-back from the connection
-
-
Method Details
-
setInputStream
Set the InputStream to read for characters to display.- Parameters:
is
- InputStream to read
-
setOutputStream
Set the OutputStream to write user-typed characters.- Parameters:
os
- OutputStream to write- Throws:
IllegalStateException
-
setDoAutoLF
public void setDoAutoLF(boolean doAutoLF) Specify whether a linefeed should be injected automatically after a carriage return if a linefeed is not explicitly provided by the remote system.- Parameters:
doAutoLF
- boolean true if automatic linefeed injection should be performed
-
addAutoFlush
public void addAutoFlush(char ch) Add another character to the set of user-typed characters that cause a output stream flush. By default, only Carriage Return causes a forced flush.- Parameters:
ch
- char to add
-
removeAutoFlush
public void removeAutoFlush(char ch) Remove a character from the set of user-typed characters that cause a output stream flush.- Parameters:
ch
- char to remove
-
getHeight
public int getHeight()Returns the current height of this component. This method is preferable to writingcomponent.getBounds().height
, orcomponent.getSize().height
because it doesn't cause any heap allocations.- Overrides:
getHeight
in classJComponent
- Returns:
- the current height of this component
-
getWidth
public int getWidth()Returns the current width of this component. This method is preferable to writingcomponent.getBounds().width
, orcomponent.getSize().width
because it doesn't cause any heap allocations.- Overrides:
getWidth
in classJComponent
- Returns:
- the current width of this component
-
validate
public void validate()Validates this container and all of its subcomponents.The
validate
method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.If this
Container
is not valid, this method invokes thevalidateTree
method and marks thisContainer
as valid. Otherwise, no action is performed. -
getMinimumSize
If the minimum size has been set to a non-null
value just returns it. If the UI delegate'sgetMinimumSize
method returns a non-null
value then return that; otherwise defer to the component's layout manager.- Overrides:
getMinimumSize
in classJComponent
- Returns:
- the value of the
minimumSize
property
-
getPreferredSize
If thepreferredSize
has been set to a non-null
value just returns it. If the UI delegate'sgetPreferredSize
method returns a nonnull
value then return that; otherwise defer to the component's layout manager.- Overrides:
getPreferredSize
in classJComponent
- Returns:
- the value of the
preferredSize
property
-
paintComponent
- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- theGraphics
object to protect
-
run
public final void run()DO NOT CALL. The Terminal instance uses this method on a background thread to read characters from the input stream and render the characters on the screen widget. -
close
public void close()Shut down a Terminal and close the I/O streams it is connected to. -
displayLocalText
Display the programmatically-generated text on the Terminal screen. Typically used to display state change information when the connection associated with a Terminal changes state.- Parameters:
text
- String to append (as if it was received at this instant from the input stream); string should be less than 128 characters long
-
keyPressed
Invoked when a key has been pressed. See the class description forKeyEvent
for a definition of a key pressed event.- Specified by:
keyPressed
in interfaceKeyListener
-
keyTyped
Invoked when a key has been typed. See the class description forKeyEvent
for a definition of a key typed event.- Specified by:
keyTyped
in interfaceKeyListener
-
keyReleased
Invoked when a key has been released. See the class description forKeyEvent
for a definition of a key released event.- Specified by:
keyReleased
in interfaceKeyListener
-
mouseClicked
Invoked when the mouse button has been clicked (pressed and released) on a component.- Specified by:
mouseClicked
in interfaceMouseListener
-
mousePressed
Invoked when a mouse button has been pressed on a component.- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
Invoked when a mouse button has been released on a component.- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseEntered
Invoked when the mouse enters a component.- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
Invoked when the mouse exits a component.- Specified by:
mouseExited
in interfaceMouseListener
-
mouseDragged
Invoked when a mouse button is pressed on a component and then dragged.MOUSE_DRAGGED
events will continue to be delivered to the component where the drag originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).Due to platform-dependent Drag and Drop implementations,
MOUSE_DRAGGED
events may not be delivered during a native Drag and Drop operation.- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseMoved
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
showTerminal
public static void showTerminal(InputStream is, OutputStream os, boolean closeStreamsOnClose, JComponent parent, String portType, String portName) throws IOException Create a modal Terminal dialog window for the specified pair of streams- Parameters:
is
- InputStream to read from remote connectionos
- OutputStream to write user keyboard input to remote connectioncloseStreamsOnClose
- boolean true if streams should be closed when dialog window is closedparent
- JComponent widget that is the windowing system parent of this created dialog windowportType
- String of port type that should be displayed in the dialog window title barportName
- String of specific port instance name that should be displayed in the dialog window title bar- Throws:
IOException
- if terminal could not accept streams or streams could not be closed successfully when the dialog was dismissed
-