kawigi.editor
Class CodePane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JEditorPane
                      extended by javax.swing.JTextPane
                          extended by kawigi.editor.CodePane
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.Scrollable

public class CodePane
extends javax.swing.JTextPane
implements java.awt.event.MouseListener

This class was originally just a hack on JTextPane to stop it from wrapping lines, as there is no setting or method to do this normally. Then I needed it to override several classes to use my View classes (which allow me to do syntax highlighting). Since then, it's become a much more core piece of KawigiEdit - and then it was reduced again to be somewhere more in the middle of several other components.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JEditorPane
javax.swing.JEditorPane.AccessibleJEditorPane, javax.swing.JEditorPane.AccessibleJEditorPaneHTML, javax.swing.JEditorPane.JEditorPaneAccessibleHypertextSupport
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JEditorPane
HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITS
 
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
CodePane()
          Creates a new NoWrapJTextPane and sets it to use various versions of my EditorKit implementation based on a few mime types.
 
Method Summary
 boolean canRedo()
          Returns true if there are redoable edits that have been undone.
 boolean canUndo()
          Returns true if there are undoable edits in the undo stack.
protected  javax.swing.text.EditorKit createDefaultEditorKit()
          By default, use my GenericView to render the text.
 Dispatcher getDispatcher()
          Returns the local dispatcher for commands that act on this CodePane.
 FindReplaceContext getFindReplaceContext()
          Returns the object handling state for Find/Replace commands on this CodePane.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Tweak of the default block scolling increment.
 boolean getScrollableTracksViewportWidth()
          It's brutally annoying that I have to write this, and sometimes it doesn't even quite work (I haven't had particular problems with it for a while now, though..
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Tweak of the default unit scrolling increment.
 void mouseClicked(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mouseEntered(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          Listens to mouse events on the text pane, so it knows when to create the popup menu.
 void mouseReleased(java.awt.event.MouseEvent e)
          Listens to mouse events on the text pane, so it knows when to create the popup menu.
 void readdUndoListener()
          This has to be called whenever the Document changes.
 void redo()
          Redoes the last undone edit.
 void resetPrefs()
          Notifies the CodePane that preferences might have changed that affect it.
 void undo()
          Undoes the last edit.
 
Methods inherited from class javax.swing.JTextPane
addStyle, getCharacterAttributes, getInputAttributes, getLogicalStyle, getParagraphAttributes, getStyle, getStyledDocument, getStyledEditorKit, getUIClassID, insertComponent, insertIcon, paramString, removeStyle, replaceSelection, 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, getStream, getText, 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, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, 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, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, 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, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
 

Constructor Detail

CodePane

public CodePane()
Creates a new NoWrapJTextPane and sets it to use various versions of my EditorKit implementation based on a few mime types. The special mime types it will now know are text/Java, text/C++, text/C#, text/VB.

Method Detail

resetPrefs

public void resetPrefs()
Notifies the CodePane that preferences might have changed that affect it.


getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
It's brutally annoying that I have to write this, and sometimes it doesn't even quite work (I haven't had particular problems with it for a while now, though..

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Overrides:
getScrollableTracksViewportWidth in class javax.swing.JEditorPane

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Tweak of the default block scolling increment. It should scroll by the height (or width) minus the font size. This makes wheel-scrolling a much nicer experience than it is by default.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Overrides:
getScrollableBlockIncrement in class javax.swing.text.JTextComponent

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Tweak of the default unit scrolling increment. The default seemed to scroll one pixel at a time, which I found rather useless. It took way too long to scroll a few lines. So now it scrolls roughly 1 1/2 lines at a time. I mentioned this plugin to NeverMore once, and he drilled me with questions about it. Then he got ready to ask me something that I could tell was important to him that he was missing in PopsEdit - and it was wheel scrolling. People get attached to their mouse wheels, what can I say? I said it worked and he was ecstatic. Not only that, but the scrolling increment had been tweaked to be "just right", since the latest version was the one where I added this tweak. It was funny to see him so impressed, I wasn't aware that PopsEdit had wheel scrolling turned off.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Overrides:
getScrollableUnitIncrement in class javax.swing.text.JTextComponent

createDefaultEditorKit

protected javax.swing.text.EditorKit createDefaultEditorKit()
By default, use my GenericView to render the text. This will be changed whenever someone looks at the problem in a specific language. If you're experimenting with views, you can change the default view here for when you run it standalone.

Overrides:
createDefaultEditorKit in class javax.swing.JTextPane

undo

public void undo()
Undoes the last edit.


redo

public void redo()
Redoes the last undone edit.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Listens to mouse events on the text pane, so it knows when to create the popup menu.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Listens to mouse events on the text pane, so it knows when to create the popup menu.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener

readdUndoListener

public void readdUndoListener()
This has to be called whenever the Document changes.


canUndo

public boolean canUndo()
Returns true if there are undoable edits in the undo stack.


canRedo

public boolean canRedo()
Returns true if there are redoable edits that have been undone.


getFindReplaceContext

public FindReplaceContext getFindReplaceContext()
Returns the object handling state for Find/Replace commands on this CodePane.


getDispatcher

public Dispatcher getDispatcher()
Returns the local dispatcher for commands that act on this CodePane.