Class JEditorPane
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
- Direct Known Subclasses:
JTextPane
JEditorPane, rendered by a
SJEditorPane (RTE) peer, editable by default
like the JDK class. Decided per D_jeditorpane / SD_sjeditorpane_rte (Shape S: always-RTE, single peer);
the read-only Div peer is gone.
R_leaf_peer_lockdown status: non-leaf, keeps the protected peer ctor
JDKJTextPane extends JEditorPane, so JEditorPane is
non-leaf in the public Swing hierarchy. Per R_leaf_peer_lockdown we keep the protected
(Component peer) ctor open as the D_peer_ctor_injection seam for a future JTextPane
(or other subclass) to pass its own peer through. The class stays non-final.
R_swing_is_truth two-way sync (editable)
The baseJTextComponent keeps a Document
as the emulator-side source of truth and only auto-syncs it to
TextFieldBase peers — RTE is not one, so JEditorPane wires both
directions itself:
- Swing → peer.
setTextchainssuper.setText(t)(mutating the Document, firing user DocumentListeners) and pushes the markup into RTE'shtmlValueviapeer.setText. DirectDocumentmutation (e.g.getDocument().insertString(...)) does NOT reach the peer — that path needs an HTMLEditorKit pipeline that's permanently OOS per R_match_swing_errors sub-bucket (b). - peer → Swing. Browser edits fire RTE's value-change (EAGER, so
the Document tracks typing per R_swing_is_truth's "updates while typing" contract);
the listener mirrors the HTML into the Document under
preventPeerEvents(R_swing_is_truth feedback guard), wrapped inEHelper.callSwingper R_callswing_envelope. SogetText()reflects user edits and DocumentListeners fire.
Lossy HTML subset (SD_sjeditorpane_rte)
RTE renders/accepts only its Quill subset — no tables, no arbitrary CSS, base64-only images. This is now the accepted regression in display too (theDiv peer that rendered any HTML is deleted). The emulator's
Document still holds the faithful markup, so getText() is exact; only
the rendered peer is lossy. Details in SJEditorPane.
Content type, page and document: the JDK's
The content type is the installed kit's, the page is the document'sStreamDescriptionProperty, and a kit change brings a new, empty document — so the
content type goes first. setPage(java.net.URL) is the JDK's body over the protected
getStream(URL) hook, fetching on the server and synchronously, and skipping a URL that is
the same file as the loaded one. None of it reads the peer (D_emulator_owned_state).
HTML element model
Atext/html pane's getDocument() is a
HTMLDocument — a read-only projection of the
markup, reparsed on every change (D_htmldocument). So the JDK-shaped introspection code
works:
pane.setContentType("text/html");
pane.setText("<h2>Report</h2><p id=\"total\">42</p>");
Element total = ((HTMLDocument) pane.getDocument()).getElement("total");
getText() keeps returning markup — the document's own text is
the rendered text, as in Swing — and the document's HTML mutators WARN, so
writes still go through setText. A text/plain pane keeps a
PlainDocument.
Hyperlink activation
addHyperlinkListener(HyperlinkListener) delivers ACTIVATED when the user clicks a
link in a non-editable pane, with source rebound to this emulator. The
peer-side plumbing lives on SJEditorPane; the
non-editable restriction is Swing's own (HTMLEditorKit.LinkController).
EditorKit: the stylesheet, not the rendering pipeline
setEditorKit(EditorKit) accepts a HTMLEditorKit so
that kit.getStyleSheet().addRule(…) styles the pane's rendered content
(D_htmleditorkit). The kit's rendering half stays out of scope — Vaadin renders the
HTML, and the JDK path is Graphics-based (R_match_swing_errors sub-bucket (b)) — so a
custom ViewFactory is inert, and installing a kit does not swap the
document (the content type does, see above).
What drops-and-WARNs
setEditorKit with any other kind of kit, getEditorKit before one
is installed, and createEditorKitForContentType /
getEditorKitForContentType — content-type-driven kit lookup has nothing to
return.- See Also:
-
Field Summary
FieldsFields inherited from class JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY, preventPeerEventsFields inherited from class JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, FILL_CHROME, FILL_DEFAULT, LEFT_ALIGNMENT, listenerList, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJEditorPane(com.vaadin.flow.component.Component peer) R_leaf_peer_lockdown D_peer_ctor_injection seam — kept protected because JTextPane is a JDK subclass.JEditorPane(String url) URL-string-loading ctor — parses the string and dispatches tosetPage(java.lang.String).JEditorPane(String type, String text) (String type, String text)JDK ctor — sets the content type first sosetTextwrites against the right mime default, then writes the initial markup.JEditorPane(URL initialPage) URL-loading ctor — fetches the URL synchronously viasetPage(java.net.URL). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHyperlinkListener(HyperlinkListener listener) Register a listener for link activation on a read-only pane.protected DocumentFactory for the defaultDocument.static EditorKitvoidFan out to this emulator's registered listeners, in registration order.final StringThe installed kit's content type.getPage()The page loaded into the current document — itsStreamDescriptionProperty.protected InputStreamOpens the connection, sets the content type from it, and returns its stream.getText()The pane's markup — HTML for an HTML pane, exactly assetText/setPage/ the last browser edit left it.protected voidPushessetText's markup into RTE'shtmlValueunderpreventPeerEvents(so the peer's value-change listener doesn't re-mirror our own write back into the Document).voidremoveHyperlinkListener(HyperlinkListener listener) voidscrollToReference(String reference) Scrolls to the named anchor — which needs view geometry only the browser has, so it WARNs.final voidsetContentType(String type) Sets the type of content, installing the kit the JDK would: the type up to any";"parameter list, if one oftext/plain,text/html,text/rtf,application/rtf, elsetext/plain.voidsetEditable(boolean b) voidsetEditorKit(EditorKit kit) Install an editor kit.voidsetEditorKitForContentType(String type, EditorKit k) voidParsesurland loads it.voidLoadspage, the JDK's way: the stream comes fromgetStream(URL), which also sets the content type from the connection, and the page is read into a new document of that type's kit.voidReplaces the Document's text in onereplace, so aDocumentFiltersees a replace; a Document that is not anAbstractDocumentgets a remove and an insert.protected voidwirePeerToDocument(com.vaadin.swingbridge.surrogates.SJEditorPane editor) Subscribes to browser edits and mirrors them into the Document (EAGER per R_swing_is_truth's "tracks typing",callSwingper R_callswing_envelope).Methods inherited from class JTextComponent
addCaretListener, addKeymap, copy, cut, fireCaretUpdate, getAccessibleContext, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, modelToView, modelToView2D, moveCaretPosition, paramString, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDocument, setDragEnabled, setDropMode, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, viewToModel2D, writeMethods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, 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, 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, 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, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, addSlotChild, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, fireHierarchyEvent, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, peerContentElement, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeSlotChild, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, applyBackgroundToPeer, applyVisibleToPeer, awtListeners, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, defaultFillCssClass, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, fireComponentEvent, 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, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isThemeDefault, 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, processKeyEvent, processMouseEvent, processMouseMotionEvent, 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, setMixingCutoutShape, setName, setSize, setSize, show, show, size, suppressMouseBridge, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, withPeer, withPeerOnLiveUI
-
Field Details
-
W3C_LENGTH_UNITS
- See Also:
-
HONOR_DISPLAY_PROPERTIES
- See Also:
-
-
Constructor Details
-
JEditorPane
public JEditorPane() -
JEditorPane
-
JEditorPane
URL-loading ctor — fetches the URL synchronously viasetPage(java.net.URL). IOException propagates per Swing's signature.- Throws:
IOException
-
JEditorPane
URL-string-loading ctor — parses the string and dispatches tosetPage(java.lang.String).- Throws:
IOException
-
JEditorPane
protected JEditorPane(com.vaadin.flow.component.Component peer) R_leaf_peer_lockdown D_peer_ctor_injection seam — kept protected because JTextPane is a JDK subclass. Subclasses passing a non-SJEditorPane peer lose the setText-forwarding and edit-sync the public ctors wire; that's their problem to handle (matches the JTextField precedent).
-
-
Method Details
-
wirePeerToDocument
protected void wirePeerToDocument(com.vaadin.swingbridge.surrogates.SJEditorPane editor) Subscribes to browser edits and mirrors them into the Document (EAGER per R_swing_is_truth's "tracks typing",callSwingper R_callswing_envelope). Overridable seam: JTextPane drives its two-way sync through RTE's Delta value instead of HTML, so it replaces this wiring rather than adding a second, conflicting listener. -
setText
Description copied from class:JTextComponentReplaces the Document's text in onereplace, so aDocumentFiltersees a replace; a Document that is not anAbstractDocumentgets a remove and an insert.- Overrides:
setTextin classJTextComponent
-
getText
The pane's markup — HTML for an HTML pane, exactly assetText/setPage/ the last browser edit left it.Overridden because the base reads the document, and an
HTMLDocument's text is the rendered text ("Report one two"), not the markup. Swing's own JEditorPane serializes viakit.write()instead, which we deliberately don't copy: its HTML-3.2 dialect (<font>,<b>,align=) would rewrite the caller's markup on every read.- Overrides:
getTextin classJTextComponent
-
pushTextToPeer
PushessetText's markup into RTE'shtmlValueunderpreventPeerEvents(so the peer's value-change listener doesn't re-mirror our own write back into the Document). Overridable seam: JTextPane pushes through its Delta serializer instead, driven by the Document mutationsuper.setTextalready made, so it overrides this to a no-op. -
setEditable
public void setEditable(boolean b) - Overrides:
setEditablein classJTextComponent
-
setContentType
Sets the type of content, installing the kit the JDK would: the type up to any";"parameter list, if one oftext/plain,text/html,text/rtf,application/rtf, elsetext/plain. Acharsetparameter on atext/type becomes the"charset"client property.A different kit brings its own empty document, as in the JDK, so a
setTextbeforesetContentTypeis lost:
Setting the installed registered type again changes nothing; an unregistered type installs a fresh document every time.pane.setContentType("text/html"); // first: installs the HTMLDocument pane.setText("<h2>Report</h2>");- Throws:
NullPointerException- iftypeis null
-
getContentType
The installed kit's content type. It is not the argument ofsetContentType(String):"ADMIN"reads back as"text/plain", and a parameter list never survives. -
addHyperlinkListener
Register a listener for link activation on a read-only pane. The event'ssourceis this JEditorPane — not the peer — so JDK-shaped user code castinge.getSource()works.getURL()/getDescription()carry what Swing'sLinkControllerwould supply; the sourceElementis alwaysnull(no HTMLDocument element model). Delivery isACTIVATED-only, and only while!isEditable()— both matching Swing. -
removeHyperlinkListener
-
getHyperlinkListeners
-
fireHyperlinkUpdate
Fan out to this emulator's registered listeners, in registration order. Public to match the JDK, where it is both the internal dispatch point and a documented way for user code to synthesize an event. -
setPage
Loadspage, the JDK's way: the stream comes fromgetStream(URL), which also sets the content type from the connection, and the page is read into a new document of that type's kit. A page that is the same file as the loaded one is not fetched again — only its reference, if any, is scrolled to — so a reload clears the page first:pane.getDocument().putProperty(Document.StreamDescriptionProperty, null); pane.setPage(url);The fetch runs on the server, and synchronously: the JDK loads an HTML page on a background thread, so its
"page"event comes after this returns, where here it comes before.- Throws:
IOException- ifpageis null ("invalid url") or the fetch fails — after the content type has switched, as in the JDK
-
getStream
Opens the connection, sets the content type from it, and returns its stream. A migrator's override (authentication, a custom resolver) is called fromsetPage(URL)as on the desktop. Redirects are not followed, as in the JDK.- Throws:
IOException
-
scrollToReference
Scrolls to the named anchor — which needs view geometry only the browser has, so it WARNs.setPage(URL)calls it for a URL with a reference, as the JDK's does. -
setPage
Parsesurland loads it.- Throws:
IOException- ifurlis null ("invalid url") or not a URL (MalformedURLException, as the JDK'snew URL(String)throws)
-
getPage
The page loaded into the current document — itsStreamDescriptionProperty. -
setEditorKit
Install an editor kit. Every kit is stored and read back bygetEditorKit(); only aHTMLEditorKitadditionally takes effect, its stylesheet binding to the peer so rules added to it (before or after this call) style the pane's content. Any other kind WARNs — without a route to the Vaadin peer, installing it could only pretend.Two JDK behaviours are deliberately not reproduced. The document is left alone — the JDK replaces it with
kit.createDefaultDocument(), whereas here the element model follows the content type instead (setContentType(String)), so installing a kit never silently changes whatgetDocument()returns. And the content type is left alone; set it explicitly if it matters. -
getEditorKit
- Returns:
- the installed kit, or
nullwhen none was set — where the JDK would manufacture one from the content type, which here would drive nothing (R_match_swing_errors sub-bucket (b))
-
getEditorKitForContentType
-
setEditorKitForContentType
-
createEditorKitForContentType
-
getUIClassID
- Overrides:
getUIClassIDin classJComponent
-
createDefaultDocument
Description copied from class:JTextComponentFactory for the defaultDocument. Real Swing subclasses override to pick richer Document models (the EditorKit-driven path in JEditorPane, etc.). Our base picksPlainDocument— the simplest line- oriented model, and what JTextField would pick anyway.- Overrides:
createDefaultDocumentin classJTextComponent
-