org.comedia.ui
Class CSyntaxEditor

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.text.JTextComponent
                          |
                          +--javax.swing.JEditorPane
                                |
                                +--javax.swing.JTextPane
                                      |
                                      +--org.comedia.ui.CEditor
                                            |
                                            +--org.comedia.ui.CSyntaxEditor
All Implemented Interfaces:
javax.accessibility.Accessible, javax.swing.event.DocumentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, javax.swing.event.UndoableEditListener

public class CSyntaxEditor
extends CEditor
implements javax.swing.event.DocumentListener

Presents an editor bean with syntax highlighting, smart indents and other features.

Usage example:

 JFrame frame = new JFrame("Comedia Syntax Editor Test");
 CSyntaxEditor editor = new CSyntaxEditor();
 JScrollPane scroll = new JScrollPane();
 scroll.setViewportView(editor);
 editor.setSyntaxHighlighter(new CJavaHighlighter());
 editor.read(new FileReader("d:\\test.java"), null);
 

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JEditorPane
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Inner classes inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class org.comedia.ui.CEditor
undoList, undoPosition
 
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
CSyntaxEditor()
          Constructs this class with default parameters.
CSyntaxEditor(CSyntaxDocument doc)
          Constructs a new class, with a specified document model.
 
Method Summary
 void changedUpdate(javax.swing.event.DocumentEvent e)
          Performs an event when edited text was changed.
protected  javax.swing.text.EditorKit createDefaultEditorKit()
          Creates the EditorKit to use by default.
 CAbstractHighlighter getSyntaxHighlighter()
          Gets the current syntax highlighter.
 int getTabSpace()
          Gets the current tab space length.
 void insertUpdate(javax.swing.event.DocumentEvent e)
          Performs an event when edited text was inserted.
 boolean isIndent()
          Checks the current indent status.
static void main(java.lang.String[] args)
          The main routine to run this module as standalone application.
 void performHighlight()
          Performs the syntax highlighting for the whole text.
 void performHighlight(int start, int end)
          Performs the syntax highlighting.
protected  void processKeyEvent(java.awt.event.KeyEvent e)
          Invoked when key event is accepted from user.
 void removeUpdate(javax.swing.event.DocumentEvent e)
          Performs an event when edited text was removed.
 void setDocument(javax.swing.text.Document doc)
          Sets a new document model for this editor.
 void setIndent(boolean indent)
          Sets a new indent status.
 void setSyntaxHighlighter(CAbstractHighlighter highlighter)
          Sets a new syntax highlighter.
 void setTabSpace(int tabSpace)
          Sets a new tab space length.
 
Methods inherited from class org.comedia.ui.CEditor
discardUndo, isModified, read, redo, setModified, undo, undoableEditHappened, write
 
Methods inherited from class javax.swing.JTextPane
addStyle, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, replaceSelection, setCharacterAttributes, setEditorKit, setLogicalStyle, setParagraphAttributes, setStyledDocument
 
Methods inherited from class javax.swing.JEditorPane
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, isFocusCycleRoot, isManagingFocus, processComponentKeyEvent, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretPosition, getDisabledTextColor, getDocument, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getUI, isEditable, isFocusTraversable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, removeCaretListener, removeKeymap, removeNotify, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel
 
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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isLightweightComponent, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processFocusEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CSyntaxEditor

public CSyntaxEditor()
Constructs this class with default parameters.

CSyntaxEditor

public CSyntaxEditor(CSyntaxDocument doc)
Constructs a new class, with a specified document model.
Parameters:
doc - the document model
Method Detail

setDocument

public void setDocument(javax.swing.text.Document doc)
Sets a new document model for this editor.
Overrides:
setDocument in class javax.swing.JTextPane
Parameters:
doc - a new document model.

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
Performs an event when edited text was changed.
Specified by:
changedUpdate in interface javax.swing.event.DocumentListener
Parameters:
e - an object which describes an event.

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Performs an event when edited text was inserted.
Specified by:
insertUpdate in interface javax.swing.event.DocumentListener
Parameters:
e - an object which describes an event.

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Performs an event when edited text was removed.
Specified by:
removeUpdate in interface javax.swing.event.DocumentListener
Parameters:
e - an object which describes an event.

performHighlight

public void performHighlight()
Performs the syntax highlighting for the whole text.

performHighlight

public void performHighlight(int start,
                             int end)
Performs the syntax highlighting.
Parameters:
start - a start position.
end - an end position.

isIndent

public boolean isIndent()
Checks the current indent status.

setIndent

public void setIndent(boolean indent)
Sets a new indent status.
Parameters:
indent - TRUE to turn indent on, FALSE otherwise.

getTabSpace

public int getTabSpace()
Gets the current tab space length.

setTabSpace

public void setTabSpace(int tabSpace)
Sets a new tab space length.
Parameters:
tabSpace - a new tab space length.

getSyntaxHighlighter

public CAbstractHighlighter getSyntaxHighlighter()
Gets the current syntax highlighter.

setSyntaxHighlighter

public void setSyntaxHighlighter(CAbstractHighlighter highlighter)
Sets a new syntax highlighter.
Parameters:
highlighter - a new syntax highlighter.

createDefaultEditorKit

protected javax.swing.text.EditorKit createDefaultEditorKit()
Creates the EditorKit to use by default. This is implemented to return javax.swing.text.StyledEditorKit.
Overrides:
createDefaultEditorKit in class javax.swing.JTextPane
Returns:
the editor kit

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e)
Invoked when key event is accepted from user.
Overrides:
processKeyEvent in class javax.swing.JEditorPane
Parameters:
e - the event received.

main

public static void main(java.lang.String[] args)
The main routine to run this module as standalone application.