Nekit
v 0.9

com.nekhem.nekit
Class NekitPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JEditorPane
                                |
                                +--javax.swing.JTextPane
                                      |
                                      +--com.nekhem.nekit.NekitPane
All Implemented Interfaces:
javax.accessibility.Accessible, javax.swing.event.CaretListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, javax.swing.Scrollable, java.io.Serializable

public class NekitPane
extends javax.swing.JTextPane
implements java.awt.event.KeyListener, java.awt.event.MouseListener, javax.swing.event.CaretListener

This class handles the Text Pane for what concerns user interaction. The real text manipulation is done by NekitDocument Some events are managed by other classes using the abstraction of CaretContext: a Context is a region of text that follows different rules (at present there's only ListContext, for bullet lists) Every time the caret is moved, NekitPane cycles through all context to see if one is Active. So certain events (newline, ...) are dispatched to that context. This architecture is only a draft and needs optimization, but should become very flexible

See Also:
NekitDocument, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JEditorPane
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 javax.swing.text.AttributeSet baseAttributes
          The attributes of clear text
static boolean dontsetpos
           
static boolean setpos
          for passing boolean parameters
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
NekitPane(NekitPaneOwner owner)
          Constructor
 
Method Summary
 void addContext(java.lang.String name, CaretContext c)
          Add a CaretContext, this is a sort of "AddListener", because the CaretContext will be notified of some relevant events
 void caretUpdate(javax.swing.event.CaretEvent e)
           
 java.lang.String cleanText(java.lang.String txt)
          Filter the HTML as necessary
 void clearFormat()
          Set the selected region to normal text
 boolean currChar(java.lang.String ch)
          Check if the character at the caret equals the parameter
 void feedHtml(java.lang.String htmlText)
          Wrapper of setText, just to add some filtering at necessity
 java.lang.String getCleanText()
           
 void initText(java.lang.String initText)
          Set the initial text
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent ev)
           
 void newUserAction(java.lang.String type, java.awt.Point p)
          For the workaround "endline": the caret went on the start of the next line when the mouse clicked beyond the end (very annoying!)
 void paragraphizeSelection()
          Transform the selected region in a separate paragraph
 boolean prevChar(java.lang.String ch)
          Check if the character behind the caret equals the parameter
 void refreshOnUpdate()
          FIXME: redundant copy of SimpleRefresh
static java.lang.String removeGarbage(java.lang.String html)
          the idea is to edit a HTML fragment, so the tags [BODY] and [HTML] are eliminated
 void replaceSelection(java.lang.String content)
          Ovverride the JTextPane method
 void resetAttributes()
          Set default attributes to normal text
 void safeSetCaretPosition(int pos)
          Set the caret position only between the legal limits (doesn't throw exceptions)
 void setNekitDocument(NekitDocument d)
          setter
 void setNekitEditorKit(javax.swing.text.html.HTMLEditorKit ek)
          setter
 void setText(java.lang.String html)
          Override of JTextPane setText
 void simpleRefresh()
          Convenience method for refreshing and displaying changes
 void simpleRefresh(boolean setpos)
          idem, with the option not to set the caret position
 
Methods inherited from class javax.swing.JTextPane
addStyle, createDefaultEditorKit, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, setCharacterAttributes, setDocument, setEditorKit, setLogicalStyle, setParagraphAttributes, setStyledDocument
 
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

setpos

public static boolean setpos
for passing boolean parameters


dontsetpos

public static boolean dontsetpos

baseAttributes

public javax.swing.text.AttributeSet baseAttributes
The attributes of clear text

Constructor Detail

NekitPane

public NekitPane(NekitPaneOwner owner)
Constructor

Parameters:
owner - callback object
Method Detail

addContext

public void addContext(java.lang.String name,
                       CaretContext c)
Add a CaretContext, this is a sort of "AddListener", because the CaretContext will be notified of some relevant events

Parameters:
name - A identification name
c - the context

setNekitEditorKit

public void setNekitEditorKit(javax.swing.text.html.HTMLEditorKit ek)
setter

Parameters:
ek - -

setNekitDocument

public void setNekitDocument(NekitDocument d)
setter

Parameters:
d - -

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

newUserAction

public void newUserAction(java.lang.String type,
                          java.awt.Point p)
For the workaround "endline": the caret went on the start of the next line when the mouse clicked beyond the end (very annoying!) Could be resolved in jdx 1.4 (FIXME: check this) For every action register the exact point

Parameters:
type - type of action (mouse of keyboard)
p - the point

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent e)
Specified by:
caretUpdate in interface javax.swing.event.CaretListener

safeSetCaretPosition

public void safeSetCaretPosition(int pos)
Set the caret position only between the legal limits (doesn't throw exceptions)

Parameters:
pos - position requested

prevChar

public boolean prevChar(java.lang.String ch)
Check if the character behind the caret equals the parameter

Parameters:
ch - the character to compare
Returns:
true if the chars are equal

currChar

public boolean currChar(java.lang.String ch)
Check if the character at the caret equals the parameter

Parameters:
ch - the character to compare
Returns:
true if the chars are equal

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

feedHtml

public void feedHtml(java.lang.String htmlText)
Wrapper of setText, just to add some filtering at necessity

Parameters:
htmlText -

setText

public void setText(java.lang.String html)
Override of JTextPane setText

Overrides:
setText in class javax.swing.JEditorPane
Parameters:
html -

simpleRefresh

public void simpleRefresh()
Convenience method for refreshing and displaying changes


simpleRefresh

public void simpleRefresh(boolean setpos)
idem, with the option not to set the caret position

Parameters:
setpos - false=don't set the caret position

refreshOnUpdate

public void refreshOnUpdate()
FIXME: redundant copy of SimpleRefresh


cleanText

public java.lang.String cleanText(java.lang.String txt)
Filter the HTML as necessary

Parameters:
txt - original HTML
Returns:
filtered HTML

getCleanText

public java.lang.String getCleanText()

removeGarbage

public static java.lang.String removeGarbage(java.lang.String html)
the idea is to edit a HTML fragment, so the tags [BODY] and [HTML] are eliminated

Parameters:
html - original HTML
Returns:
stripped HTML

initText

public void initText(java.lang.String initText)
Set the initial text

Parameters:
initText - the HTML text

resetAttributes

public void resetAttributes()
Set default attributes to normal text


paragraphizeSelection

public void paragraphizeSelection()
Transform the selected region in a separate paragraph


replaceSelection

public void replaceSelection(java.lang.String content)
Ovverride the JTextPane method

Overrides:
replaceSelection in class javax.swing.JTextPane
Parameters:
content -
See Also:
JTextPane

clearFormat

public void clearFormat()
Set the selected region to normal text


Nekit
v 0.9

Submit a bug or feature
Nekhem Technologies