Package com.inet.editor
Class BaseEditor
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.inet.editor.BaseEditor
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
An extended editor component with an additional tool bar and a popup menu.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA modifiedInetHtmlEditorKitwhich fires an additional property change event after the read function has finishedstatic classA lightweight CaretEvent implementaionstatic interfaceA listener to receive a notification when a text has been loaded to theBaseEditorNested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClient property, Value: Boolean, if set toBoolean.FALSE, setText will not reset the scroll positionFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionBaseEditor(boolean hasScrollpane) Complete construction of an editor, which is editable and has a toolbar.
NOTE: This may take a while (up to 50ms!).BaseEditor(boolean hasScrollpane, boolean editable, boolean hasToolbar, boolean isHtml) Complete construction of an editor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionListener(ActionListener listener) Adds an action listener to this editorprotected voidaddButtons(List<Component> defaultComponents, List<Component> editComponents, List<Component> formatComponents) Add buttons and commponent to the toolbar.voidAdds a listener to the editor to receive notification whenever a text or page has been loadedvoidallowImagePaste(boolean allowImagePaste) Enables or disables the image-paste function of the editor.protected StyledEditorKitcreateEditorKit(boolean isHtml) Create a new EditorKit.protected voidcreatePopup(JPopupMenu popupMenu) Create the context menu.protected URLgetBase()Get the location to resolve relative URLs against.intReturns the load-ID of the currently displayed document.Returns the default font, if any.
Note: The size of this font has to be interpreted as px!Returns the persistant document properties table.Returns the internal editor componentReturns a list with the reference to all images used in this document or null, if the document isn't anInetHtmlDocument.getText()Returns the content of the internal editor instance.Returns the tool bar componentReturns the toolbar controller used by this editorReturns the undo manager registered to the internal JEditorPane.protected booleanHas the current Editor a format button in the toolbar.voidinsertFrom(BaseEditor editor) Inserts the text of another editor into the current one.voidinsertHtml(String htmlText) Inserts a HTML content into the current document.protected booleanIs the automatic spell checking enabled.booleanIf the text was changed since the last setText()booleanReturns whether the internal editor is currently editablebooleanisHtml()Returns whether the content type of the internal editor is text/htmlbooleanIf the text of setText is completly loaded.booleanA flag which descides whether a link-tooltip always displayes the target URL.voidRemoves a listener from the editorvoidprotected voidsetAutoSpellCkeck(boolean enabled) Enable the automatic spell checking.voidSet a default value for getBase()voidsetConfiguration(InetHtmlConfiguration htmlConfiguration) Set the default configuration for HTML documents, opened by this editor.voidSets the custom handler for theHyperlinkListenerof this editor.voidsetCustomPasteHandler(PasteFileHandler handler) Sets the custom PasteFileHandler of the current TransferHandler.voidsetDefaultFont(Font defaultFont) Sets the default font for this editor.voidsetDefaultFontPX(Font defaultFont) Sets the default font for this editor.voidsetDocumentProperties(Dictionary<Object, Object> properties) Sets a persistant document property table.voidsetDocumentProperty(Object key, Object value) Adds or sets a persistant document property.voidsetEditable(boolean editable) Sets the editable state of the internal editor and updates the tool bar accordinglyvoidsetEnabled(boolean enabled) voidsetFontScale(float scale) Sets the scale factorvoidLoads the page references by thepageURL and thes the base URL.voidsetSearchVisible(boolean visible) Displays or hides the search-button, if availablevoidsetShowLinkURL(boolean showLinkURL) A switch to descide whether a link-tooltip always displayes the target URL.voidSets the text to display.voidsetTextAntiAlias(boolean enabled) Enables or disables the text anti-alias render hintvoidsetTextSelectionEnabled(boolean enabled) Enables or disables the selectability of the content of the editor.voidShow only the text and hide the tool barintsetTextWithLoadID(String str, boolean isHtml) Sets the text to display.voidReset the status of changed.voidshowDocument(URL url, String string) Opens the specified location.protected voidThis method is called when the text was loaded.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, 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, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, 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, getInputMethodRequests, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROPERTY_AUTO_SCROLL
Client property, Value: Boolean, if set toBoolean.FALSE, setText will not reset the scroll position- See Also:
-
-
Constructor Details
-
BaseEditor
public BaseEditor(boolean hasScrollpane) Complete construction of an editor, which is editable and has a toolbar.
NOTE: This may take a while (up to 50ms!).- Parameters:
hasScrollpane- true, if the editor is supposed to have a scroll pane
-
BaseEditor
public BaseEditor(boolean hasScrollpane, boolean editable, boolean hasToolbar, boolean isHtml) Complete construction of an editor.- Parameters:
hasScrollpane- true, if the editor is supposed to have a scroll paneeditable- if true, the editor is editable by defaulthasToolbar- if true, the editor will have a toolbarisHtml- set to true, if the content will be HTML by default
-
-
Method Details
-
requestFocus
public void requestFocus()- Overrides:
requestFocusin classJComponent
-
isAutoSpellCheck
protected boolean isAutoSpellCheck()Is the automatic spell checking enabled. The default is true. This can be overridden form a custom instance.- Returns:
- true if the spell checker is enabled, false if it's disabled or not present
-
setAutoSpellCkeck
protected void setAutoSpellCkeck(boolean enabled) Enable the automatic spell checking.- Parameters:
enabled- the new value
-
createPopup
Create the context menu. The default implementation add the spell checker. You can override this method to add your own menu items.- Parameters:
popupMenu- an empty JPopupMenu
-
addButtons
protected void addButtons(List<Component> defaultComponents, List<Component> editComponents, List<Component> formatComponents) Add buttons and commponent to the toolbar. You can override if you want add additional buttons.
NOTE: The buttons defined here will be added to the BEGINNING of the groups in the toolbar- Parameters:
defaultComponents- a list of components, which will always be visible, if there is a toolbareditComponents- a list of component that will hide if isEditable() is false.formatComponents- a list of components that will hide if the format is plain text
-
hasFormatButton
protected boolean hasFormatButton()Has the current Editor a format button in the toolbar. With the format button can the user switch between HTML and Plan text.- Returns:
- ever true
-
showDocument
Opens the specified location. The default implementation opens the page in the current editor window.
NOTE: It is recommended to override this method to open the page by the default browser!- Parameters:
url- The page to loadstring- The target for the page, e.g. _blank
-
getBase
Get the location to resolve relative URLs against. By default this is null. If a base tag is found and can be parsed, it will be used as the base location. It can be overridden. This also sets the base of the StyleSheet to be u as well as the base of the document.- Returns:
- the currently set base URL
-
setBase
Set a default value for getBase()- Parameters:
base- the new base value.
-
setText
Sets the text to display. This action is performed in a separate Thread, so this method will return before the document has finished loading. To check the load state of the document, query the isLoading function or register anBaseEditor.TextLoadListener.- Parameters:
str- The content to displayisHtml- has to be true, if the content is in HTML format
-
setTextWithLoadID
Sets the text to display. This action is performed in a separate Thread, so this method will return before the document has finished loading. To check the load state of the document, query the isLoading function or register anBaseEditor.TextLoadListener.
The value returned by this method is the load-ID of this method call. When and if this content gets displayed,getCurrentLoadIDwill have the same value. Note, that this may never happen, if this method is called several times in a row.- Parameters:
str- The content to displayisHtml- has to be true, if the content is in HTML format- Returns:
- The load-ID of this call.
-
getCurrentLoadID
public int getCurrentLoadID()Returns the load-ID of the currently displayed document. The load-ID is updated every time, a document gets displayed while no other load-action is pending.- Returns:
- The current load-ID.
-
textLoaded
protected void textLoaded()This method is called when the text was loaded. The default sets the editors inner margins to align HTML and text/plain equally -
createEditorKit
Create a new EditorKit. The EditorKit is used for a new Document.- Parameters:
isHtml- true, HTML- Returns:
- a EditorKit, never null
-
getText
Returns the content of the internal editor instance. The content can be HTML or plain text.- Returns:
- the content of the internal editor instance
-
isHtml
public boolean isHtml()Returns whether the content type of the internal editor is text/html- Returns:
- true, if the content type is text/html
-
isChanged
public boolean isChanged()If the text was changed since the last setText()- Returns:
- true if it was changed
- See Also:
-
isLoading
public boolean isLoading()If the text of setText is completly loaded. Does not means that it is completly layouted. Only the model (Document) is completly.- Returns:
- true, if the text is parsing.
-
setUnChanged
public void setUnChanged()Reset the status of changed. -
isEditable
public boolean isEditable()Returns whether the internal editor is currently editable- Returns:
- true, if editable, false if not
-
setTextShowMode
public void setTextShowMode()Show only the text and hide the tool bar -
setEditable
public void setEditable(boolean editable) Sets the editable state of the internal editor and updates the tool bar accordingly- Parameters:
editable- set true for editable
-
setEnabled
public void setEnabled(boolean enabled) - Overrides:
setEnabledin classJComponent
-
getEditor
Returns the internal editor component- Returns:
- the internal editor component, never null
-
getToolbar
Returns the tool bar component- Returns:
- the tool bar component, may be null if the editor has no tool bar
-
getToolBarController
Returns the toolbar controller used by this editor- Returns:
- the toolbar controller used by this editor, never
null
-
insertHtml
Inserts a HTML content into the current document. The content will be inserted at the current caret location. If there is a selection, this selection will be replaced.
This is a convenience method to programmatically insert content without the requirement for any further settings.- Parameters:
htmlText- the HTML content to insert
-
insertFrom
Inserts the text of another editor into the current one. If the source editor has a selection, only the selected text will be inserted. The text will be inserted at the current caret location.- Parameters:
editor- the editor to get the content from, must not be null
-
addActionListener
Adds an action listener to this editor- Parameters:
listener- the listener to add, must not be null
-
getEmbeddedImages
Returns a list with the reference to all images used in this document or null, if the document isn't anInetHtmlDocument.- Returns:
- A list of all images used in this document or
null
-
allowImagePaste
public void allowImagePaste(boolean allowImagePaste) Enables or disables the image-paste function of the editor.- Parameters:
allowImagePaste- true, to enable
-
getUndoManager
Returns the undo manager registered to the internal JEditorPane. Use this function to reset the undo points in case you've done changes directly to the internal editor- Returns:
- the undo manager of this editor
-
getPreferredSize
- Overrides:
getPreferredSizein classJComponent
-
getMinimumSize
- Overrides:
getMinimumSizein classJComponent
-
setConfiguration
Set the default configuration for HTML documents, opened by this editor.- Parameters:
htmlConfiguration- the configuration to set
-
setDefaultFont
Sets the default font for this editor. The size of this font will be interpreted as pt!
NOTE: This font and it's size will be preselected whe opening a document. This means: if the selection changes for any reasons, these settings will be overwritten by the font and size at the caret's location.- Parameters:
defaultFont- the default font and font-size
-
setDefaultFontPX
Sets the default font for this editor. The size of this font will internally be converted into pt.
NOTE: This font and it's size will be preselected whe opening a document. This means: if the selection changes for any reasons, these settings will be overwritten by the font and size at the caret's location.- Parameters:
defaultFont- the default font and font-size
-
setFontScale
public void setFontScale(float scale) Sets the scale factor- Parameters:
scale- a value between 0.1 and 10
-
getDefaultFont
Returns the default font, if any.
Note: The size of this font has to be interpreted as px!- Returns:
- default font or
nullif none is set.
-
setPage
Loads the page references by thepageURL and thes the base URL. If the page could not be loaded, an error page is displayed.
NOTE: This method will ensure that the current editor kit is anBaseEditor.SetPageEditorKit. If this is not the case, the editor kit will be replaced by aBaseEditor.SetPageEditorKit.- Parameters:
page- The URL to load.
-
getDocumentProperties
Returns the persistant document properties table. If the current document is an inetHtmlDocument the properties of this document will be merged into the returned properties- Returns:
- the current properties table
-
setDocumentProperties
Sets a persistant document property table. This property table will be applied to every document handeled by this editor.- Parameters:
properties- the properties table to use
-
setDocumentProperty
Adds or sets a persistant document property. This property will be applied to every InetHtmlDocument handeled by this editor.- Parameters:
key- the key of the property, must not be nullvalue- the value to set
-
setShowLinkURL
public void setShowLinkURL(boolean showLinkURL) A switch to descide whether a link-tooltip always displayes the target URL. By default set to false, which means, that the link tooltips will only show the target if there is no title-attribute defined.- Parameters:
showLinkURL- true, to force the link to be displayed
-
isShowLinkURL
public boolean isShowLinkURL()A flag which descides whether a link-tooltip always displayes the target URL. By default set to false, which means, that the link tooltips will only show the target if there is no title-attribute defined.- Returns:
- true, if the target will always be displayed
-
setCustomHyperlinkHandler
Sets the custom handler for theHyperlinkListenerof this editor. The handler will be the fist code to be executed when this listener receives an event. It may interrupt the default behavior of this listener.- Parameters:
handler- the instance custom handler, may be null to reset
-
setCustomPasteHandler
Sets the custom PasteFileHandler of the current TransferHandler.
Note: This only affects the TransferHandler of Html-Editors!- Parameters:
handler- the custom handler to use
-
setTextAntiAlias
public void setTextAntiAlias(boolean enabled) Enables or disables the text anti-alias render hint- Parameters:
enabled- true to enable text anti-alias
-
setSearchVisible
public void setSearchVisible(boolean visible) Displays or hides the search-button, if available- Parameters:
visible- true for visible, false for hidden
-
addTextLoadListener
Adds a listener to the editor to receive notification whenever a text or page has been loaded- Parameters:
listener- the listener to be added
-
removeTextLoadListener
Removes a listener from the editor- Parameters:
listener- the listener to be removed
-
setTextSelectionEnabled
public void setTextSelectionEnabled(boolean enabled) Enables or disables the selectability of the content of the editor. If the selection is disabled, all transfer actions are blocked as well (copy, cut, and so on)- Parameters:
enabled- true to enable, false to disable
-