Package com.coswald.jtalker.gui
Class TextEntryPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- com.coswald.jtalker.gui.TextEntryPanel
-
- All Implemented Interfaces:
Initializable
,KeyListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
public class TextEntryPanel extends JPanel implements Initializable, KeyListener
A panel that allows entry and sending of text. This consists of two parts: entry and sending. Entry is simple: we use a
JTextField
to enter in text, and said text is cleared when the enter button is pressed. However, "sending" is more complicated. We have created an interface calledTextPipe
, in which we allow the sending of specific text. If we were to visualize how this panel "sends" text, it would be like a bunch of pipes branching out from a single entry point. This entry point would be stopped by the "send" button, and when it is pressed, the pipe is opened (and susequently shut). We allow the installation of new pipes via theaddTextUpdater(TextPipe)
method. When you display the panel, it will look like this:- Since:
- JTalker 0.1.5
- Version:
- 0.0.1
- Author:
- C. William Oswald
- See Also:
TextPipe
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TextEntryPanel.TextUpdater
Updates any text pipe using the underlying textfield's
current text.-
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 Modifier and Type Field Description protected JTextField
entryField
The text entry field of the panel.protected JButton
sendButton
The send buttong of the panel.-
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
Constructors Constructor Description TextEntryPanel()
Constructs aTextEntryPanel
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTextUpdater(TextPipe pipe)
Adds aTextUpdater
to thisTextEntryPanel
.JButton
getButton()
Returns theJButton
that is used for sending text.JTextField
getTextField()
Returns theJTextField
that is used for text entry.void
init()
Initializes the entry panel by adding the components and making sure that the enter key also pushes the button.void
keyPressed(KeyEvent e)
Invoked when a key has been pressed.void
keyReleased(KeyEvent e)
Invoked when a key has been released.void
keyTyped(KeyEvent e)
Invoked when a key has been typed.void
requestFocus()
Requests that thisTextEntryPanel
gets the input focus.-
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, 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
-
-
-
-
Field Detail
-
entryField
protected JTextField entryField
The text entry field of the panel. This allows the text to be entered, and when the class is initialized, its text will be sent along anyTextPipe
given to this panel (and then subsiquently cleared).
-
sendButton
protected JButton sendButton
The send buttong of the panel. This allows the text to actually be sent along theTextPipe
s provided by theTextUpdater
s that are added to this button asActionListener
s.
-
-
Constructor Detail
-
TextEntryPanel
public TextEntryPanel()
Constructs aTextEntryPanel
. Note that you still have to call theinit
method in order for anything to work.
-
-
Method Detail
-
init
public void init()
Initializes the entry panel by adding the components and making sure that the enter key also pushes the button. The sizes for the button as well as the height of the entry panel are defined inGUIConstants
:width
andheight
. The text within thetext
entry field is set to the defaultfont
.- Specified by:
init
in interfaceInitializable
-
keyPressed
public void keyPressed(KeyEvent e)
Invoked when a key has been pressed. When and enter is pressed, it will click thesend
button, therefore activating its action performers.- Specified by:
keyPressed
in interfaceKeyListener
- Parameters:
e
- The key event (hopefully an enter).
-
keyReleased
public void keyReleased(KeyEvent e)
Invoked when a key has been released. This is unimplemented.- Specified by:
keyReleased
in interfaceKeyListener
- Parameters:
e
- The key event to ignore.
-
keyTyped
public void keyTyped(KeyEvent e)
Invoked when a key has been typed. This is unimplemented.- Specified by:
keyTyped
in interfaceKeyListener
- Parameters:
e
- the key event ot ignore.
-
requestFocus
public void requestFocus()
Requests that thisTextEntryPanel
gets the input focus. This will call the underlyingJTextField
'srequestFocus
method.- Overrides:
requestFocus
in classJComponent
-
addTextUpdater
public void addTextUpdater(TextPipe pipe)
Adds aTextUpdater
to thisTextEntryPanel
.- Parameters:
pipe
- The text pipe to make aTextUpdater
out of.
-
getTextField
public JTextField getTextField()
Returns theJTextField
that is used for text entry.- Returns:
- The
JTextField
that is used for text entry.
-
getButton
public JButton getButton()
Returns theJButton
that is used for sending text.- Returns:
- The
JButton
that is used for sending text.
-
-