|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.text.JTextComponent javax.swing.JEditorPane javax.swing.JTextPane edu.northwestern.at.utils.swing.XTextPane
public class XTextPane
A JTextPane with extra support for StyledString
's and other
features.
Nested Class Summary | |
---|---|
static class |
XTextPane.LinkInfo
Link information. |
Nested classes/interfaces inherited from class javax.swing.JEditorPane |
---|
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport |
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.JEditorPane |
---|
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS |
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 | |
---|---|
XTextPane()
Constructs a new XTextPane with no initial text. |
|
XTextPane(java.lang.String s)
Constructs a new XTextPane with plain string as initial text. |
|
XTextPane(StyledString styledStr)
Constructs a new XTextPane with alignment allowed. |
|
XTextPane(StyledString styledStr,
boolean alignment)
Constructs a new XTextPane. |
Method Summary | |
---|---|
void |
appendBoldText(java.lang.String str)
Appends bold text. |
void |
appendItalicText(java.lang.String str)
Appends italic text. |
void |
appendLink(java.lang.String str,
Link link)
Appends a link. |
void |
appendPlainText(java.lang.String str)
Appends plain text. |
void |
appendStyledText(StyledString styledStr)
Appends styled text. |
void |
appendUnderlineText(java.lang.String str)
Appends underlined text. |
boolean |
clipboardHasPasteableData()
Check if clipboard has pasteable data. |
void |
copy()
Copys the selected text to the clipboard. |
void |
cut()
Cuts the selected text to the clipboard. |
javax.swing.Action |
getCopyAction()
Gets the copy action. |
java.awt.Cursor |
getCurrentCursor()
Get the current cursor. |
javax.swing.Action |
getCutAction()
Gets the cut action. |
javax.swing.Action |
getDeleteAction()
Gets the delete action. |
javax.swing.text.Document |
getDoc()
Gets the document. |
int |
getDocLength()
Gets the document length. |
XTextPane.LinkInfo[] |
getLinks()
Gets the links. |
javax.swing.Action |
getPasteAction()
Gets the paste action. |
PrintableComponent |
getPrintableComponent(java.lang.String title,
java.awt.print.PageFormat pageFormat)
Return printable component. |
StyledString |
getStyledSelection()
Gets the styled currently selected text. |
StyledString |
getStyledText()
Gets the styled text. |
StyleInfo |
getStyleInfo(int subStart,
int subEnd)
Gets the style information for a substring. |
javax.swing.undo.UndoManager |
getUndoManager()
Get undo manager. |
void |
insertBoldText(int pos,
java.lang.String str)
Inserts bold text. |
void |
insertItalicText(int pos,
java.lang.String str)
Inserts italicized text. |
void |
insertLink(int pos,
java.lang.String str,
Link link)
Inserts a link. |
void |
insertPlainText(int pos,
java.lang.String str)
Inserts plain text. |
void |
insertStyledText(int pos,
StyledString styledStr)
Inserts styled text. |
void |
insertStyledText(int pos,
StyledString styledStr,
javax.swing.text.AttributeSet insertionAttributes,
javax.swing.text.AttributeSet paragraphAttributes)
Inserts styled text. |
void |
insertUnderlinedText(int pos,
java.lang.String str)
Inserts underlined text. |
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 |
lostOwnership(java.awt.datatransfer.Clipboard clipboard,
java.awt.datatransfer.Transferable contents)
Notifies this object that it is no longer the owner of the contents of the clipboard. |
void |
paste()
Pastes the contents of the clipboard. |
void |
printContents(java.lang.String title,
java.awt.print.PrinterJob printerJob,
java.awt.print.PageFormat pageFormat)
Prints the styled text. |
void |
replaceSelection(StyledString styledStr)
Replaces the currently selected text with styled text. |
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 |
saveToImageFile(java.io.File imageFile,
java.lang.String imageType)
Save editor contents to image file. |
void |
saveToJPEGFile(java.io.File jpegFile)
Save editor contents to JPEG file. |
void |
saveToPNGFile(java.io.File pngFile)
Save editor contents to PNG file. |
void |
scrollTo(int offset,
javax.swing.JScrollPane scrollPane)
Scrolls to an offset in the document. |
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 |
setAlignment(boolean alignment)
Set honoring of alignment. |
void |
setBorder(int pixels)
Sets the border. |
void |
setFont(java.lang.String family,
int size)
Sets the font. |
void |
setLinks(XTextPane.LinkInfo[] links)
Sets the links. |
void |
setStyledText(StyledString styledStr)
Sets the styled text. |
void |
setStyleInfo(StyleInfo styleInfo,
int pos)
Sets the style information. |
void |
setUndoManager(javax.swing.undo.UndoManager undoManager)
Set undo manager used by parent. |
void |
unselect()
Unselect selection. |
Methods inherited from class javax.swing.JTextPane |
---|
addStyle, createDefaultEditorKit, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, replaceSelection, setCharacterAttributes, setDocument, setEditorKit, setLogicalStyle, setParagraphAttributes, setStyledDocument |
Methods inherited from class javax.swing.JEditorPane |
---|
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText |
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, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, 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, 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, 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 |
---|
public XTextPane(StyledString styledStr, boolean alignment)
styledStr
- Initial styled text contents, or null if none.alignment
- True if the left, center, and right alignment
options are allowed. public XTextPane(java.lang.String s)
public XTextPane()
public XTextPane(StyledString styledStr)
styledStr
- Initial styled text contents, or null if none. Method Detail |
---|
public javax.swing.text.Document getDoc()
public int getDocLength()
public void setBorder(int pixels)
pixels
- Number of pixels in border on all four sides. public void setFont(java.lang.String family, int size)
family
- Font family name.size
- Font size. public StyledString getStyledText()
public StyledString getStyledSelection()
public void setStyledText(StyledString styledStr)
styledStr
- Styled string. public void appendStyledText(StyledString styledStr)
styledStr
- Styled string. public void appendPlainText(java.lang.String str)
str
- String. public void appendBoldText(java.lang.String str)
str
- String. public void appendItalicText(java.lang.String str)
str
- String. public void appendUnderlineText(java.lang.String str)
str
- String. public void appendLink(java.lang.String str, Link link)
Links are blue and underlined. A single-click on a link goes to the linked object.
str
- String.link
- Link. public void insertStyledText(int pos, StyledString styledStr, javax.swing.text.AttributeSet insertionAttributes, javax.swing.text.AttributeSet paragraphAttributes)
pos
- Position in document to insert text.styledStr
- Styled string.insertionAttributes
- Default attributes for the
insertion.paragraphAttributes
- Default paragraph attributes. public void insertStyledText(int pos, StyledString styledStr)
pos
- Position in document to insert text.styledStr
- Styled string. public void insertPlainText(int pos, java.lang.String str)
pos
- Position in document to insert text.str
- String. public void insertBoldText(int pos, java.lang.String str)
pos
- Position in document to insert text.str
- String. public void insertItalicText(int pos, java.lang.String str)
pos
- Position in document to insert text.str
- String. public void insertUnderlinedText(int pos, java.lang.String str)
pos
- Position in document to insert text.str
- String. public void insertLink(int pos, java.lang.String str, Link link)
Links are blue and underlined. A single-click on a link goes to the linked object.
pos
- Position in document to insert text.str
- String text to insert in document.link
- Link, or null to just make the inserted
text blue and underlined. public void replaceSelection(StyledString styledStr)
styledStr
- Replacement styled string. public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable contents)
This method does nothing. We ignored transfers of ownership of the clipboard.
lostOwnership
in interface java.awt.datatransfer.ClipboardOwner
clipboard
- The clipboard that is no longer owned.contents
- The contents which this owner had placed
on the clipboard. public boolean isCutEnabled()
isCutEnabled
in interface CutCopyPaste
public boolean isCopyEnabled()
isCopyEnabled
in interface CutCopyPaste
public boolean isPasteEnabled()
isPasteEnabled
in interface CutCopyPaste
public javax.swing.Action getCutAction()
public void cut()
cut
in interface CutCopyPaste
cut
in class javax.swing.text.JTextComponent
public javax.swing.Action getCopyAction()
public void copy()
copy
in interface CutCopyPaste
copy
in class javax.swing.text.JTextComponent
public javax.swing.Action getPasteAction()
public javax.swing.Action getDeleteAction()
public void paste()
paste
in interface CutCopyPaste
paste
in class javax.swing.text.JTextComponent
public boolean clipboardHasPasteableData()
clipboardHasPasteableData
in interface ClipboardHasPasteableData
public StyleInfo getStyleInfo(int subStart, int subEnd)
subStart
- Starting offset of substring.subEnd
- Ending offset of substring.
public XTextPane.LinkInfo[] getLinks()
public void setLinks(XTextPane.LinkInfo[] links)
links
- Array of Links. public void setStyleInfo(StyleInfo styleInfo, int pos)
styleInfo
- The style information.pos
- The position in the document of the string
for which style information is to be set. public void printContents(java.lang.String title, java.awt.print.PrinterJob printerJob, java.awt.print.PageFormat pageFormat)
title
- Title for output.printerJob
- The printer job.pageFormat
- The printer page format. public PrintableComponent getPrintableComponent(java.lang.String title, java.awt.print.PageFormat pageFormat)
getPrintableComponent
in interface PrintableContents
title
- Title for printing.pageFormat
- Page format for printing.
public void scrollToBeginning()
public void scrollToEnd()
public void scrollToEndForSure()
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.
public void scrollTo(int offset, javax.swing.JScrollPane scrollPane)
The offset is positioned at the top of the viewport.
This is an incredible hack and doe
offset
- The offset in the document.scrollPane
- The scroll pane. public java.awt.Cursor getCurrentCursor()
public void setAlignment(boolean alignment)
alignment
- True to allow left/center/right alignment. public void setUndoManager(javax.swing.undo.UndoManager undoManager)
undoManager
- The undo manager. public javax.swing.undo.UndoManager getUndoManager()
public boolean isTextSelected()
isTextSelected
in interface CutCopyPaste
public void selectAll()
selectAll
in interface SelectAll
selectAll
in class javax.swing.text.JTextComponent
public boolean isSelectAllEnabled()
isSelectAllEnabled
in interface SelectAll
public void unselect()
unselect
in interface SelectAll
public boolean isUnselectEnabled()
isUnselectEnabled
in interface SelectAll
public void saveToFile(java.lang.String fileName)
saveToFile
in interface SaveToFile
fileName
- Name of file to which to save results. public void saveToFile(java.awt.Window parentWindow)
saveToFile
in interface SaveToFile
parentWindow
- Parent window for file dialog.
Runs a file dialog to get the name of the file to which to save results.
public void saveToImageFile(java.io.File imageFile, java.lang.String imageType) throws java.io.IOException
imageFile
- File to received editor contents as jpeg image.imageType
- String providing image file type (jpg, png, etc.)
java.io.IOException
- if I/O exception occurs. public void saveToJPEGFile(java.io.File jpegFile) throws java.io.IOException
jpegFile
- File to received editor contents as jpeg image.
java.io.IOException
- if I/O exception occurs. public void saveToPNGFile(java.io.File pngFile) throws java.io.IOException
pngFile
- File to received editor contents as png image.
java.io.IOException
- if I/O exception occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |