com.lightdev.app.shtm
public class SHTMLEditorPane extends JEditorPane implements DropTargetListener, DragSourceListener, DragGestureListener
This is extending JEditorPane
by cut and paste
and drag and drop for HTML text.
JEditorPane
inherits cut and paste from
JTextComponent
where handling for plain text is implemented only.
JEditorPane
has no additional functionality to add cut
and paste for the various content types it supports
(such as 'text/html').
In stage 4 support for caret movement inside tables and table manipulation methods are added.
In stage 6 support for list manipulation was added.
See Also: HTMLText HTMLTextSelection
Field Summary | |
---|---|
static int | ALL_CELLS range indicator for applying attributes to all cells |
static String | deleteNextCharAction |
static String | deletePrevCharAction |
static String | DEFAULT_TABLE_WIDTH default table width |
static String | DEFAULT_VERTICAL_ALIGN default vertical alignment |
static String | endAction |
static String | homeAction |
static String | insertLineBreakAction |
static String | moveDownAction |
static String | moveUpAction |
static String | newListItemAction |
static String | shiftEndAction |
static String | shiftHomeAction |
static int | THIS_CELL range indicator for applying attributes to the current cell only |
static int | THIS_COLUMN range indicator for applying attributes to cells of the current column only |
static int | THIS_ROW range indicator for applying attributes to cells of the current row only |
Constructor Summary | |
---|---|
SHTMLEditorPane()
construct a new SHTMLEditorPane |
Method Summary | |
---|---|
void | appendTableColumn()
append a table column after the last column
(if any) |
void | appendTableRow()
Appends a row to a table if the caret is inside a table. |
void | applyAttributes(AttributeSet attributeSet, boolean applyToCompleteParagraph) |
void | applyAttributes(AttributeSet attributeSet, boolean applyToCompleteParagraph, boolean replace)
Sets the attributes for a given part of this editor. |
void | applyCellAttributes(AttributeSet a, int range)
apply a set of attributes to a given range of cells
of the table the caret is currently in (if any)
|
void | applyCharacterTag(String tag) (Unfinished.) |
void | applyListAttributes(AttributeSet a)
apply a set of attributes to the list the caret is
currently in (if any)
|
void | applyParagraphTag(String tag, Vector overwritableTags)
Switches the elements in the current selection to the given tag. |
void | applyTableAttributes(AttributeSet a)
apply a set of attributes to the table the caret is
currently in (if any)
|
void | deleteTableCol()
delete the column of the table the caret is currently in (if any)
width of adjacent column is adjusted, if there is more than one column in the table. |
void | deleteTableRow()
delete the row of the table the caret is currently in (if any) |
void | dragDropEnd(DragSourceDropEvent event)
this message goes to DragSourceListener, informing it that the dragging
has ended |
void | dragEnter(DropTargetDragEvent event) is invoked when you are dragging over the DropSite |
void | dragEnter(DragSourceDragEvent event)
this message goes to DragSourceListener, informing it that the dragging
has entered the DropSite |
void | dragExit(DropTargetEvent event) is invoked when you are exit the DropSite without dropping |
void | dragExit(DragSourceEvent event)
this message goes to DragSourceListener, informing it that the dragging
has exited the DropSite |
void | dragGestureRecognized(DragGestureEvent event) a drag gesture has been initiated |
void | dragOver(DropTargetDragEvent event) is invoked when a drag operation is going on |
void | dragOver(DragSourceDragEvent event)
this message goes to DragSourceListener, informing it that
the dragging is currently ocurring over the DropSite |
void | drop(DropTargetDropEvent event)
a drop has occurred. |
void | dropActionChanged(DropTargetDragEvent event) is invoked if the user modifies the current drop gesture |
void | dropActionChanged(DragSourceDragEvent event) is invoked when the user changes the dropAction |
String | elementToHTML(Element element) Returns the string HTML representation of the element. |
Element | getCurrentLinkElement() |
Element | getCurrentParagraphElement() Gets the paragraph element in which the caret is located. |
Element | getCurrentTableCell()
Gets the table cell at the current caret position.
|
JPopupMenu | getPopup() |
SHTMLDocument | getSHTMLDocument() |
Element | getTableCell(int position)
Gets the table cell element at the given position, or null if none. |
TransferHandler | getTransferHandler() |
void | goNextCell(Element cell) |
void | goPrevCell(Element cell) |
void | initDnd()
Initialize the drag and drop implementation for this component.
|
void | insertAnchor(String anchorName)
apply a new anchor to the currently selected text
If nothing is selected, this method does nothing |
void | insertBreak()
insert a line break (i.e. a break for which paragraph
spacing is not applied) |
void | insertNewTable(int colCount)
Insert a new table.
|
void | insertTableColumn()
insert a table column before the current column
(if any) |
void | insertTableRow(String forcedCellName)
Inserts a row to a table, assuming the caret is currently
inside a table. |
protected boolean | processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) |
void | removeAnchor(String anchorName)
remove an anchor with a given name
|
void | removeCharacterAttributes() |
void | removeParagraphAttributes() |
void | replaceSelection(HTMLText replacementHTMLText)
Replaces the currently selected content with new content
represented by the given HTMLText . |
void | setLink(String linkText, String href, String className)
set a text link at the current selection replacing the selection
with a given text.
|
void | setLink(String linkText, String href, String className, String linkImage, Dimension size)
Sets a hyperlink at the current selection, replacing the selection
with the given text or image.
|
void | setPopup(JPopupMenu popup) |
void | setText(String sText)
Convenience method for setting the document text
contains hack around JDK bug 4799813
see http://developer.java.sun.com/developer/bugParade/bugs/4799813.html
regression in 1.4.x, to be fixed in 1.5
When setting the text to be "& footext", it becomes "&footext" (space disappears)
same ocurrs for "</a> &", it becomes "</a>&" (space disappears)
with the hack it now does not occur anymore. |
void | toggleList(String listTag, AttributeSet attributeSet, boolean forceOff)
toggle list formatting on or off for the currently
selected text portion.
|
void | toggleTableHeaderCell() For each cell within the selection, turns a table data cell into a table header cell or vice
versa. |
boolean | tryDefaultKeyStrokeActionWithinCell(int keyCode, int modifiers, ActionEvent event) Performs the default key stroke action, assuming that the caret is within
a table cell and that the action is a cursor move; if the cursor leaves
the current table cell, undoes the action.
|
SHTMLEditorPane
Parameters: attributeSet the set of attributes to apply applyToCompleteParagraph true, if the attributes shall be applied to the whole paragraph, false, if only the selected range of characters shall have them replace true, if existing attribtes are to be replaced, false if not
Parameters: a the set of attributes to apply range the range of cells to apply attributes to
Parameters: a the set of attributes to apply
Parameters: tag the tag name to switche elements to overwritableTags Tags that may be overwritten by the new tag.
Parameters: a the set of attributes to apply
width of adjacent column is adjusted, if there is more than one column in the table. Width adjustment only works, if width attributes of both the column to remove and its adjacent column have the same unit (pt or %).
If there is only one cell or if the caret is not in a table, this method does nothing
Smart border handling automatically sets the left border of a cell to zero, if the cell on the left of that cell has a right border and both cells have no margin. In that case removing the first column will cause all cells of the new first column to have no left border.
DataFlavor
, do the drop.
Parameters: event - the event specifiying the drop operation
See Also: java.awt.datatransfer.DataFlavor
Returns: the Element having the current table cell or null if the caret is not inside a table cell
DropTarget, DragSource and DragGestureRecognizer are instantiated and a MouseListener is established to track the selection in drag operations
this ideally is called in the constructor of a class which would like to implement drag and drop
If nothing is selected, this method does nothing
Parameters: anchorName the name of the new anchor
Parameters: colCount the number of columns the new table shall have
Parameters: anchorName the name of the anchor to remove
HTMLText
. If there is no selection
this amounts to an insert of the given text. If there
is no replacement text this amounts to a removal of the
current selection.
This method overrides replaceSelection in JEditorPane
for usage
of our own HTMLText object.
Parameters: replacementHTMLText the content to replace the selection with
If nothing is selected, but the caret is inside a link, this will replace the existing link. If nothing is selected and the caret is not inside a link, this method does nothing.
Parameters: linkText the text that shall appear as link at the current selection href the target this link shall refer to className the style class to be used
Parameters: linkText the text to show as link (or null, if an image shall appear instead) href the link reference className the style name to be used for the link linkImage the file name of the image be used for the link (or null, if a text link is to be set instead) size the size of the image or null
Parameters: sText the html-text of the document
Switches list display on for the given type, if the selection contains parts not formatted as list or parts formatted as list of another type.
Switches list formatting off, if the selection contains only parts formatted as list of the given type.
Parameters: listTag the list tag type to toggle on or off (UL or OL) attributeSet the attributes to use for the list to toggle to forceOff indicator for toggle operation. If true, possibly exisiting list formatting inside the selected parts always is switched off. If false, the method decides, if list formatting for the parts inside the selection needs to be switched on or off.