com.inet.editor
Class BaseEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.inet.editor.BaseEditor
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CaretListener

public class BaseEditor
extends javax.swing.JPanel
implements javax.swing.event.CaretListener, java.awt.event.ActionListener

A simple editor component with some base features.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
BaseEditor(boolean hasScrollpane)
          Complete construction of an editor, which is editable and has a toolbar.
BaseEditor(boolean hasScrollpane, boolean editable, boolean hasToolbar, boolean isHtml)
          Complete construction of an editor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ev)
          Handelt die Events der Toolbar.
 void addActionListener(java.awt.event.ActionListener listener)
          Adds an action listener to this editor
 void allowImagePaste(boolean allowImagePaste)
          Enables or disables the image-paste function of the editor.
 void caretUpdate(javax.swing.event.CaretEvent ev)
          Aktualisiert die Toolbar nachdem der Textcursor (Caret) im pane bewegt wurde.
 int getCurrentLoadID()
          Returns the load-ID of the currently displayed document.
 java.awt.Font getDefaultFont()
          Returns the default font, if any.
 java.util.Dictionary<java.lang.Object,java.lang.Object> getDocumentProperties()
          Returns the persistant document properties table.
 javax.swing.JTextPane getEditor()
          Liefert das innere Textsteuerelement.
 com.inet.html.utils.EmbeddedImage[] getEmbeddedImages()
          Returns a list with the reference to all images used in this document or null, if the document isn't an InetHtmlDocument.
 java.awt.Dimension getMinimumSize()
          
 java.awt.Dimension getPreferredSize()
          
 java.lang.String getText()
          Liefert den aktuellen Text des Document in HTML oder Plaintext
 javax.swing.JToolBar getToolbar()
          Accessor Methode für UI
 javax.swing.undo.UndoManager getUndoManager()
          FIXME TEST ONLY
 void insertFrom(BaseEditor editor)
          Fügt Text vom übergebenen Editor ein.
 void insertHtml(java.lang.String htmlText)
          Inserts a HTML content into the current document.
 boolean isChanged()
          If the text was changed since the last setText()
 boolean isEditable()
          Ist der Editor aktuell im Bearbeitungsmode.
 boolean isHtml()
          Liefert getText() einen HTML formatierten oder eine Plain Text
 boolean isLoading()
          If the text of setText is completly loaded.
 boolean isShowLinkURL()
          A flag which descides whether a link-tooltip always displayes the target URL.
 void requestFocus()
          Damit man den Focus ins Textfeld setzen kann
 void setBase(java.net.URL base)
          Set a default value for getBase()
 void setConfiguration(InetHtmlConfiguration htmlConfiguration)
          Set the default configuration for HTML documents, opened by this editor.
 void setCustomHyperlinkHandler(HyperlinkHandler handler)
          Sets the custom handler for the HyperlinkListener of this editor.
 void setCustomPasteHandler(PasteFileHandler handler)
          Sets the custom PasteFileHandler of the current TransferHandler.
 void setDefaultFont(java.awt.Font defaultFont)
          Sets the default font for this editor.
 void setDefaultFontPX(java.awt.Font defaultFont)
          Sets the default font for this editor.
 void setDocumentProperties(java.util.Dictionary<java.lang.Object,java.lang.Object> properties)
          Sets a persistant document property table.
 void setDocumentProperty(java.lang.Object key, java.lang.Object value)
          Adds or sets a persistant document property.
 void setEditable(boolean editable)
          Setzte den aktuellen Bearbeitungsmode.
 void setEnabled(boolean enabled)
          
 void setFontScale(float scale)
          Sets the scale factor
 void setPage(java.net.URL page)
          Loads the page references by the page URL and thes the base URL.
 void setShowLinkURL(boolean showLinkURL)
          A switch to descide whether a link-tooltip always displayes the target URL.
 void setText(java.lang.String str, boolean isHtml)
          Setzt den Text und das Format des Textes.
 void setTextAntiAlias(boolean enabled)
          Enables or disables the text anti-alias render hint
 void setTextSelectionEnabled(boolean enabled)
          Enables or disables the selectability of the content of the editor.
 void setTextShowMode()
          Show only the text and hide the toolbar
 int setTextWithLoadID(java.lang.String str, boolean isHtml)
          Sets the text to display.
 void setUnChanged()
          Reset the status of changed.
 void showDocument(java.net.URL url, java.lang.String string)
          Opens the specified location.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 pane
editable - if true, the editor is editable by default
hasToolbar - if true, the editor will have a toolbar
isHtml - set to true, if the content will be HTML by default
Method Detail

requestFocus

public void requestFocus()
Damit man den Focus ins Textfeld setzen kann

Overrides:
requestFocus in class javax.swing.JComponent

showDocument

public void showDocument(java.net.URL url,
                         java.lang.String string)
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 load
string - The target for the page, e.g. _blank

setBase

public void setBase(java.net.URL base)
Set a default value for getBase()

Parameters:
base - the new base value.

setText

public void setText(java.lang.String str,
                    boolean isHtml)
Setzt den Text und das Format des Textes. Wird über invokeLater() aufgerufen, das heißt die Daten sind nicht sofort da.

Parameters:
str - der text, darf nicht null sein
isHtml - ob in HTML formatiert

setTextWithLoadID

public int setTextWithLoadID(java.lang.String str,
                             boolean isHtml)
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.
The value returned by this method is the load-ID of this method call. When and if this content gets displayed, getCurrentLoadID will 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 display
isHtml - 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.

getText

public java.lang.String getText()
Liefert den aktuellen Text des Document in HTML oder Plaintext

Returns:
der Text des aktuellen editors

isHtml

public boolean isHtml()
Liefert getText() einen HTML formatierten oder eine Plain Text

Returns:
wahr, wenn das aktuelle Document im HTML-Format ist

isChanged

public boolean isChanged()
If the text was changed since the last setText()

Returns:
true if it was changed
See Also:
setUnChanged()

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()
Ist der Editor aktuell im Bearbeitungsmode.

Returns:
true, wenn der innere Editor editierbar ist

setTextShowMode

public void setTextShowMode()
Show only the text and hide the toolbar


setEditable

public void setEditable(boolean editable)
Setzte den aktuellen Bearbeitungsmode. Aktiviert die Buttons entsprechend.

Parameters:
editable - wahr = editierbar

setEnabled

public void setEnabled(boolean enabled)

Overrides:
setEnabled in class javax.swing.JComponent

getEditor

public javax.swing.JTextPane getEditor()
Liefert das innere Textsteuerelement.

Returns:
das innere JTextPane

getToolbar

public javax.swing.JToolBar getToolbar()
Accessor Methode für UI

Returns:
die Toolbar des Editors

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent ev)
Aktualisiert die Toolbar nachdem der Textcursor (Caret) im pane bewegt wurde. Methode des interface CaretListener.

Specified by:
caretUpdate in interface javax.swing.event.CaretListener
Parameters:
ev - das zu behandelnde Event

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ev)
Handelt die Events der Toolbar. Methode des interface ActionListener.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ev - das zu behandelnde Event

insertHtml

public void insertHtml(java.lang.String htmlText)
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 conveniance method to programatically insert content without the requirement for any further settings.

Parameters:
htmlText - the HTML content to insert

insertFrom

public void insertFrom(BaseEditor editor)
Fügt Text vom übergebenen Editor ein. Wenn eine Selection dann nur die Selektion, ansonsten alles.

Parameters:
editor - the editor to get the content from

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Adds an action listener to this editor

Parameters:
listener - the listener to add, must not be null

getEmbeddedImages

public com.inet.html.utils.EmbeddedImage[] getEmbeddedImages()
Returns a list with the reference to all images used in this document or null, if the document isn't an InetHtmlDocument.

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

public javax.swing.undo.UndoManager getUndoManager()
FIXME TEST ONLY

Returns:
the undo manager of this editor

getPreferredSize

public java.awt.Dimension getPreferredSize()

Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()

Overrides:
getMinimumSize in class javax.swing.JComponent

setConfiguration

public void setConfiguration(InetHtmlConfiguration htmlConfiguration)
Set the default configuration for HTML documents, opened by this editor.

Parameters:
htmlConfiguration - the configuration to set

setDefaultFont

public void setDefaultFont(java.awt.Font defaultFont)
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

public void setDefaultFontPX(java.awt.Font defaultFont)
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

public java.awt.Font getDefaultFont()
Returns the default font, if any.
Note: The size of this font has to be interpreted as px!

Returns:
default font or null if none is set.

setPage

public void setPage(java.net.URL page)
Loads the page references by the page URL and thes the base URL. If the page could not be loaded, an error page is displayed.

Parameters:
page - The URL to load.

getDocumentProperties

public java.util.Dictionary<java.lang.Object,java.lang.Object> 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

public void setDocumentProperties(java.util.Dictionary<java.lang.Object,java.lang.Object> properties)
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

public void setDocumentProperty(java.lang.Object key,
                                java.lang.Object value)
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 null
value - 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

public void setCustomHyperlinkHandler(HyperlinkHandler handler)
Sets the custom handler for the HyperlinkListener of 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

public void setCustomPasteHandler(PasteFileHandler handler)
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

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