Package org.jdesktop.swingx
Class JXEditorPane
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JEditorPane
-
- org.jdesktop.swingx.JXEditorPane
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.Scrollable,Targetable
@JavaBean public class JXEditorPane extends javax.swing.JEditorPane implements Targetable
JXEditorPaneoffers enhanced functionality over the standardJEditorPane. Unlike its parent,JXEdtiorPanehonors display propertiesby default. Users can revert to the behavior ofJEditorPaneby setting the property tofalse.Additional Features
- Improved text editing
- The standard text component commands for cut, copy, and paste used enhanced selection methods. The commands will only be active if there is text to cut or copy selected or valid text in the clipboard to paste.
- Improved HTML editing
-
Using the context-sensitive approach for the standard text commands,
JXEditorPaneprovides HTML editing commands that alter functionality depending on the document state. Currently, the user can quick-format the document with headers (H# tags), paragraphs, and breaks. - Built-in UndoManager
-
Text components provide
UndoableEditEvents.JXEditorPaneplaces those events in anUndoManagerand provides undo/redo commands. Undo and redo are context-sensitive (like the text commands) and will only be active if it is possible to perform the command. - Built-in search
-
Using SwingX search mechanisms,
JXEditorPaneprovides search capabilities, allowing the user to find text within the document.
Example
Creating a
JXEditorPaneis no different than creating aJEditorPane. However, the following example demonstrates the best way to access the improved command functionality.JXEditorPane editorPane = new JXEditorPane("some URL"); add(editorPane); JToolBar toolBar = ActionContainerFactory.createToolBar(editorPane.getCommands[]); toolBar.addSeparator(); toolBar.add(editorPane.getParagraphSelector()); setToolBar(toolBar);- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJXEditorPane.ActionsA small class which dispatches actions.private classJXEditorPane.CaretHandlerListens to the caret placement and adjusts the editing properties as appropriate.classJXEditorPane.DocumentSearchableASearchableimplementation forDocuments.private classJXEditorPane.ParagraphSelectorA control which should be placed in the toolbar to enable paragraph selection.private classJXEditorPane.PropertyHandlerprivate static classJXEditorPane.SloppyHTMLEditorKitHandles sloppy HTML.private classJXEditorPane.UndoHandler-
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
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringACTION_COPYprivate static java.lang.StringACTION_CUTprivate static java.lang.StringACTION_FINDprivate static java.lang.StringACTION_PASTEprivate static java.lang.StringACTION_REDOprivate static java.lang.StringACTION_UNDOprivate javax.swing.event.CaretListenercaretHandlerprivate static java.util.logging.LoggerLOGprivate Searchablesearchableprivate javax.swing.JComboBoxselectorprivate TargetableSupporttargetSupportprivate javax.swing.event.UndoableEditListenerundoHandlerprivate javax.swing.undo.UndoManagerundoManager-
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
-
-
Constructor Summary
Constructors Constructor Description JXEditorPane()Creates a newJXEditorPane.JXEditorPane(java.lang.String url)Creates aJXEditorPanebased on a string containing a URL specification.JXEditorPane(java.lang.String type, java.lang.String text)Creates aJXEditorPanethat has been initialized to the given text.JXEditorPane(java.net.URL initialPage)Creates aJXEditorPanebased on a specified URL for input.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyTag(javax.swing.text.html.HTML.Tag tag)Applys the tag to the current selectionbooleandoCommand(java.lang.Object command, java.lang.Object value)Perform the command using the object value.private voidfind()(package private) javax.swing.event.CaretListenergetCaretListener()java.lang.Object[]getCommands()Returns an array of supported commands.javax.swing.JComboBoxgetParagraphSelector()Retrieves a component which will be used as the paragraph selector.intgetScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)SearchablegetSearchable()(package private) javax.swing.event.UndoableEditListenergetUndoableEditListener()booleanhasCommand(java.lang.Object command)Return a flag that indicates if a command is supported.private voidinit()protected voidinitActions()Register the actions that this class can handle.voidpaste()The paste method has been overloaded to strip off the tags This doesn't really work.voidsetEditorKit(javax.swing.text.EditorKit kit)Overidden to perform document initialization based on type.voidsetSearchable(Searchable searchable)sets the Searchable for this editor.private voidupdateActionState()Updates the state of the actions in response to an undo/redo operation.-
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createDefaultEditorKit, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, getUIClassID, paramString, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, replaceSelection, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
-
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, viewToModel2D, 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, 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, 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, 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, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
-
undoHandler
private javax.swing.event.UndoableEditListener undoHandler
-
undoManager
private javax.swing.undo.UndoManager undoManager
-
caretHandler
private javax.swing.event.CaretListener caretHandler
-
selector
private javax.swing.JComboBox selector
-
ACTION_FIND
private static final java.lang.String ACTION_FIND
- See Also:
- Constant Field Values
-
ACTION_UNDO
private static final java.lang.String ACTION_UNDO
- See Also:
- Constant Field Values
-
ACTION_REDO
private static final java.lang.String ACTION_REDO
- See Also:
- Constant Field Values
-
ACTION_CUT
private static final java.lang.String ACTION_CUT
- See Also:
- Constant Field Values
-
ACTION_COPY
private static final java.lang.String ACTION_COPY
- See Also:
- Constant Field Values
-
ACTION_PASTE
private static final java.lang.String ACTION_PASTE
- See Also:
- Constant Field Values
-
targetSupport
private TargetableSupport targetSupport
-
searchable
private Searchable searchable
-
-
Constructor Detail
-
JXEditorPane
public JXEditorPane()
Creates a newJXEditorPane. The document model is set tonull.
-
JXEditorPane
public JXEditorPane(java.lang.String url) throws java.io.IOExceptionCreates aJXEditorPanebased on a string containing a URL specification.- Parameters:
url- the URL- Throws:
java.io.IOException- if the URL isnullor cannot be accessed
-
JXEditorPane
public JXEditorPane(java.lang.String type, java.lang.String text)Creates aJXEditorPanethat has been initialized to the given text. This is a convenience constructor that calls thesetContentTypeandsetTextmethods.- Parameters:
type- mime type of the given texttext- the text to initialize with; may benull- Throws:
java.lang.NullPointerException- if thetypeparameter isnull
-
JXEditorPane
public JXEditorPane(java.net.URL initialPage) throws java.io.IOExceptionCreates aJXEditorPanebased on a specified URL for input.- Parameters:
initialPage- the URL- Throws:
java.io.IOException- if the URL isnullor cannot be accessed
-
-
Method Detail
-
init
private void init()
-
getCaretListener
javax.swing.event.CaretListener getCaretListener()
-
getUndoableEditListener
javax.swing.event.UndoableEditListener getUndoableEditListener()
-
setEditorKit
public void setEditorKit(javax.swing.text.EditorKit kit)
Overidden to perform document initialization based on type.- Overrides:
setEditorKitin classjavax.swing.JEditorPane
-
initActions
protected void initActions()
Register the actions that this class can handle.
-
updateActionState
private void updateActionState()
Updates the state of the actions in response to an undo/redo operation.
-
getParagraphSelector
public javax.swing.JComboBox getParagraphSelector()
Retrieves a component which will be used as the paragraph selector. This can be placed in the toolbar.Note: This is only valid for the HTMLEditorKit
-
applyTag
protected void applyTag(javax.swing.text.html.HTML.Tag tag)
Applys the tag to the current selection
-
paste
public void paste()
The paste method has been overloaded to strip off the tags This doesn't really work.- Overrides:
pastein classjavax.swing.text.JTextComponent
-
find
private void find()
-
getSearchable
public Searchable getSearchable()
- Returns:
- a not-null Searchable for this editor.
-
setSearchable
public void setSearchable(Searchable searchable)
sets the Searchable for this editor. If null, a default searchable will be used.- Parameters:
searchable-
-
hasCommand
public boolean hasCommand(java.lang.Object command)
Description copied from interface:TargetableReturn a flag that indicates if a command is supported.- Specified by:
hasCommandin interfaceTargetable- Parameters:
command- is a Action.ACTION_COMMAND_KEY- Returns:
- true if command is supported; false otherwise
-
getCommands
public java.lang.Object[] getCommands()
Description copied from interface:TargetableReturns an array of supported commands. If this Targetable doesn't support any commands (which is unlikely) then an empty array is returned.- Specified by:
getCommandsin interfaceTargetable- Returns:
- array of supported commands
-
doCommand
public boolean doCommand(java.lang.Object command, java.lang.Object value)Description copied from interface:TargetablePerform the command using the object value.- Specified by:
doCommandin interfaceTargetable- Parameters:
command- is a Action.ACTION_COMMAND_KEYvalue- an arbitrary value. Usually this will be EventObject which trigered the command.
-
getScrollableUnitIncrement
public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)- Specified by:
getScrollableUnitIncrementin interfacejavax.swing.Scrollable- Overrides:
getScrollableUnitIncrementin classjavax.swing.text.JTextComponent
-
-