edu.northwestern.at.utils.swing
Class XTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextArea
                      extended by edu.northwestern.at.utils.swing.XTextArea
All Implemented Interfaces:
ClipboardHasPasteableData, CutCopyPaste, PrintableContents, SaveToFile, SelectAll, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

public class XTextArea
extends javax.swing.JTextArea
implements PrintableContents, ClipboardHasPasteableData, CutCopyPaste, SaveToFile, SelectAll

A JTextArea with different defaults and behavior.

The constructors are the same as in JTextArea. We did not bother giving them their own javadoc.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTextArea
javax.swing.JTextArea.AccessibleJTextArea
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
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
XTextArea()
           
XTextArea(javax.swing.text.Document doc)
           
XTextArea(javax.swing.text.Document doc, java.lang.String text, int rows, int columns)
           
XTextArea(int rows, int columns)
           
XTextArea(java.lang.String text)
           
XTextArea(java.lang.String text, int rows, int columns)
           
 
Method Summary
 void clearSelection()
          Clear selection.
 boolean clipboardHasPasteableData()
          Check if clipboard has pasteable data.
 void copy()
          Copy to clipboard.
 void cut()
          Cut to clipboard.
 PrintableComponent getPrintableComponent(java.lang.String title, java.awt.print.PageFormat pageFormat)
          Return printable component.
 javax.swing.JScrollPane getScrollPane()
          Attaches a scroll bar to the text area and returns the scroll pane.
 boolean isCopyEnabled()
          Is copy enabled?
 boolean isCutEnabled()
          Is cut enabled?
 boolean isPasteEnabled()
          Is paste enabled?
 boolean isSelectAllEnabled()
          Checks if "select all" enabled.
 boolean isTextSelected()
          Is anything selected which can be cut/copied?
 boolean isUnselectEnabled()
          Is unselect enabled?
 void paste()
          Paste from clipboard.
 void printContents(java.lang.String title, java.awt.print.PrinterJob printerJob, java.awt.print.PageFormat pageFormat)
          Prints the XTextArea contents.
 void saveToFile(java.lang.String fileName)
          Save to a named file.
 void saveToFile(java.awt.Window parentWindow)
          Save to a file using a file dialog.
 void scrollToBeginning()
          Scrolls to the beginning of the document.
 void scrollToEnd()
          Scrolls to the end of the document.
 void scrollToEndForSure()
          Scrolls to the end of the document for sure.
 void selectAll()
          Selects all text.
 void setTabsEnabled(boolean tabsEnabled)
          Enables or disables tabs.
 void setText(java.lang.String t)
          Sets the area text and resets the caret position to 0.
 void unselect()
          Unselect selection.
 
Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setRows, setTabSize, setWrapStyleWord
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, 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, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, 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
 

Constructor Detail

XTextArea

public XTextArea()

XTextArea

public XTextArea(javax.swing.text.Document doc)

XTextArea

public XTextArea(javax.swing.text.Document doc,
                 java.lang.String text,
                 int rows,
                 int columns)

XTextArea

public XTextArea(int rows,
                 int columns)

XTextArea

public XTextArea(java.lang.String text)

XTextArea

public XTextArea(java.lang.String text,
                 int rows,
                 int columns)
Method Detail

getScrollPane

public javax.swing.JScrollPane getScrollPane()
Attaches a scroll bar to the text area and returns the scroll pane.

The scroll bar policy is set to vertical scroll bar always and horizontal scroll bar never.

Returns:
The scroll pane.

setTabsEnabled

public void setTabsEnabled(boolean tabsEnabled)
Enables or disables tabs.

When tabs are enabled they are entered as regular characters into the text in the field. When they are disabled a tab advances to the next focus component. Tabs are disabled by default.

Parameters:
tabsEnabled - True to enable tabs.

setText

public void setText(java.lang.String t)
Sets the area text and resets the caret position to 0.

Overrides:
setText in class javax.swing.text.JTextComponent
Parameters:
t - The new text for the area.

printContents

public void printContents(java.lang.String title,
                          java.awt.print.PrinterJob printerJob,
                          java.awt.print.PageFormat pageFormat)
Prints the XTextArea contents.

Parameters:
title - Title for output.
printerJob - The printer job.
pageFormat - The printer page format.

getPrintableComponent

public PrintableComponent getPrintableComponent(java.lang.String title,
                                                java.awt.print.PageFormat pageFormat)
Return printable component.

Specified by:
getPrintableComponent in interface PrintableContents
Parameters:
title - Title for printing.
pageFormat - Page format for printing.
Returns:
Printable component for XTextArea.

scrollToBeginning

public void scrollToBeginning()
Scrolls to the beginning of the document.


scrollToEnd

public void scrollToEnd()
Scrolls to the end of the document.


scrollToEndForSure

public void scrollToEndForSure()
Scrolls to the end of the document for sure.

The Swing text package is very ornery when it comes to programmatic scrolling. This "for sure" method starts a thread that wakes up every tenth of a second for two seconds and makes sure that the text pane is scrolled to the end.


clipboardHasPasteableData

public boolean clipboardHasPasteableData()
Check if clipboard has pasteable data.

Specified by:
clipboardHasPasteableData in interface ClipboardHasPasteableData
Returns:
true if clipboard has pasteable text recognized by XTextArea.

clearSelection

public void clearSelection()
Clear selection.


cut

public void cut()
Cut to clipboard.

Specified by:
cut in interface CutCopyPaste
Overrides:
cut in class javax.swing.text.JTextComponent

copy

public void copy()
Copy to clipboard.

Specified by:
copy in interface CutCopyPaste
Overrides:
copy in class javax.swing.text.JTextComponent

paste

public void paste()
Paste from clipboard.

Specified by:
paste in interface CutCopyPaste
Overrides:
paste in class javax.swing.text.JTextComponent

isCutEnabled

public boolean isCutEnabled()
Is cut enabled?

Specified by:
isCutEnabled in interface CutCopyPaste

isCopyEnabled

public boolean isCopyEnabled()
Is copy enabled?

Specified by:
isCopyEnabled in interface CutCopyPaste

isPasteEnabled

public boolean isPasteEnabled()
Is paste enabled?

Specified by:
isPasteEnabled in interface CutCopyPaste

isTextSelected

public boolean isTextSelected()
Is anything selected which can be cut/copied?

Specified by:
isTextSelected in interface CutCopyPaste

saveToFile

public void saveToFile(java.lang.String fileName)
Save to a named file.

Specified by:
saveToFile in interface SaveToFile
Parameters:
fileName - Name of file to which to save results.

saveToFile

public void saveToFile(java.awt.Window parentWindow)
Save to a file using a file dialog.

Specified by:
saveToFile in interface SaveToFile
Parameters:
parentWindow - Parent window for file dialog.

Runs a file dialog to get the name of the file to which to save results.


selectAll

public void selectAll()
Selects all text.

Specified by:
selectAll in interface SelectAll
Overrides:
selectAll in class javax.swing.text.JTextComponent

isSelectAllEnabled

public boolean isSelectAllEnabled()
Checks if "select all" enabled.

Specified by:
isSelectAllEnabled in interface SelectAll
Returns:
returns true if select all enabled.

unselect

public void unselect()
Unselect selection.

Specified by:
unselect in interface SelectAll

isUnselectEnabled

public boolean isUnselectEnabled()
Is unselect enabled?

Specified by:
isUnselectEnabled in interface SelectAll