Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.memoire.bu
Class BuTextPane  view BuTextPane download BuTextPane.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.text.JTextComponent
                  extended byjavax.swing.JEditorPane
                      extended byjavax.swing.JTextPane
                          extended bycom.memoire.bu.BuTextPane
All Implemented Interfaces:
javax.accessibility.Accessible, BuTextComponentInterface, 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 BuTextPane
extends javax.swing.JTextPane
implements javax.swing.event.UndoableEditListener, javax.swing.event.DocumentListener, BuTextComponentInterface

This component extends a JTextPane. This component provides its own methods to read and save files (even to zip them).

Version:
1.1

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
private  int anchor
           
private static int BUFFER_SIZE
          This constant defines the size of the buffer used to read files
private  javax.swing.undo.CompoundEdit compoundEdit
           
private  java.lang.String currentFile
           
private  boolean dirty
           
private  boolean newText
           
static int OPEN
          This constant defines an open dialog box.
private  boolean operation
           
private  com.memoire.re.RE regexp
           
static int SAVE
          This constant defines a save dialog box.
private  javax.swing.undo.UndoManager undo
           
 
Fields inherited from class javax.swing.JEditorPane
 
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.Container
 
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
BuTextPane()
           
 
Method Summary
 void beginCompoundEdit()
          Used for ReplaceAll.
 void beginOperation()
          When an operation has began, setChanged() cannot be called.
 void changedUpdate(javax.swing.event.DocumentEvent e)
          When a modification is made in the text, we turn the 'to_be_saved' flag to true.
static java.lang.String chooseFile(java.awt.Component owner, int mode)
          Display a file chooser dialog box.
 void clean()
          Called after having saved or created a new document to ensure the content isn't 'dirty'.
 void colorize(BuCommonInterface _app)
           
 void discard()
          Discard all edits contained in the UndoManager.
 void duplicate()
           
 void endCompoundEdit()
          See beginCompoundEdit().
 void endOperation()
          Calling this will allow the DocumentListener to use setChanged().
 boolean find(java.lang.String searchStr, int start, boolean ignoreCase)
          Return the result of a string search.
 int getAnchor()
          Return the anchor position.
 java.lang.String getCurrentFile()
          Return the full path of the opened file.
 int getLength()
          Return the lentgh of the text in the pane.
 int getLineEndOffset(int _n)
           
 int getLineStartOffset(int _n)
          This is just to reduce code size of other classes.
 boolean getOperation()
          Return true if we can use the setChanged() method, false otherwise.
 java.awt.Dimension getPreferredScrollableViewportSize()
           
 java.awt.Dimension getPreferredSize()
          Returns the preferred size for the JEditorPane.
 boolean getScrollableTracksViewportHeight()
          Returns true when a Viewport should force the height of this component to match the viewport height.
 boolean getScrollableTracksViewportWidth()
          Returns true when a Viewport should force the width of this component to match the viewport width.
 java.lang.String getSyntax()
           
 javax.swing.undo.UndoManager getUndo()
          Useful for the GUI.
 void go(int _line)
           
 void insertUpdate(javax.swing.event.DocumentEvent e)
          When a modification is made in the text, we turn the 'to_be_saved' flag to true.
 boolean isDirty()
          Return true if pane content has changed, false otherwise.
 boolean isEmpty()
          Return true if pane is empty, false otherwise.
 boolean isNew()
          Return true if current text is new, false otherwise.
 void newFile()
          Set a new file.
 void open(java.lang.String path)
          Called to load a new file in the text pane.
 void paint(java.awt.Graphics _g)
          Paint the component.
 void paintComponent(java.awt.Graphics _g)
          Paint the component's body.
 void redo()
          redo the last operation
 void removeUpdate(javax.swing.event.DocumentEvent e)
          When a modification is made in the text, we turn the 'to_be_saved' flag to true.
 boolean replace(java.lang.String searchStr, java.lang.String replaceStr, int start, int end, boolean ignoreCase)
           
 boolean replaceAll(java.lang.String searchStr, java.lang.String replaceStr, int start, int end, boolean ignoreCase)
          Return the result of a string replace.
 void save(java.lang.String file)
          Store the text in a specified file.
 void saveContent()
          Called to save this component's content.
 void select()
           
 void setAnchor(int offset)
          Set the anchor postion.
 void setBorder(javax.swing.border.Border b)
          Set the value of the JComponent.border>JComponent.border 55 property.
 void setCaretPosition(int _pos)
          Sets the caret to a new position.
 void setDirty()
          Called when the content of the pane has changed.
 void setSyntax(java.lang.String _syntax)
           
static void showError(java.lang.String message)
          Display an error message in a dialog box.
static void showMessage(java.lang.String message)
          Display a sample message in a dialog box.
 java.lang.String toString()
          Return a String representation of this object.
 void undo()
          undo the last operation
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
          When an undoable event is fired, we add it to the undo/redo list.
 void zip(java.lang.String zipFile)
          Zip text pane content into specified file.
 void zipContent()
          Called to save current content in specified zip file.
 
Methods inherited from class javax.swing.JTextPane
addStyle, createDefaultEditorKit, 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, getStream, getText, isFocusCycleRoot, 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, getInputMethodListeners, getKeymap, getKeymap, getMargin, getNavigationFilter, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, read, removeCaretListener, removeInputMethodListener, removeKeymap, select, selectAll, setCaret, setCaretColor, 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, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, 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, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, 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, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, 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, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.memoire.bu.BuTextComponentInterface
getCaretPosition, select
 

Field Detail

OPEN

public static final int OPEN
This constant defines an open dialog box.

See Also:
Constant Field Values

SAVE

public static final int SAVE
This constant defines a save dialog box.

See Also:
Constant Field Values

regexp

private com.memoire.re.RE regexp

compoundEdit

private javax.swing.undo.CompoundEdit compoundEdit

currentFile

private java.lang.String currentFile

anchor

private int anchor

dirty

private boolean dirty

newText

private boolean newText

operation

private boolean operation

undo

private javax.swing.undo.UndoManager undo

BUFFER_SIZE

private static final int BUFFER_SIZE
This constant defines the size of the buffer used to read files

See Also:
Constant Field Values
Constructor Detail

BuTextPane

public BuTextPane()
Method Detail

paint

public void paint(java.awt.Graphics _g)
Description copied from class: javax.swing.JComponent

Paint the component. This is a delicate process, and should only be called from the repaint thread, under control of the javax.swing.RepaintManager. Client code should usually call Component.repaint()>Component.repaint() 55 to trigger painting.

The body of the paint call involves calling JComponent.paintComponent(java.awt.Graphics)>JComponent.paintComponent(java.awt.Graphics) 55 , JComponent.paintBorder(java.awt.Graphics)>JComponent.paintBorder(java.awt.Graphics) 55 , and JComponent.paintChildren(java.awt.Graphics)>JComponent.paintChildren(java.awt.Graphics) 55 in order. If you want to customize painting behavior, you should override one of these methods rather than paint.

For more details on the painting sequence, see this article.


setBorder

public void setBorder(javax.swing.border.Border b)
Description copied from class: javax.swing.JComponent
Set the value of the JComponent.border>JComponent.border 55 property.


select

public void select()

duplicate

public void duplicate()

go

public void go(int _line)
Specified by:
go in interface BuTextComponentInterface

paintComponent

public void paintComponent(java.awt.Graphics _g)
Description copied from class: javax.swing.JComponent
Paint the component's body. This usually means calling ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)>ComponentUI.update(java.awt.Graphics, javax.swing.JComponent) 55 on the JComponent.ui>JComponent.ui 55 property of the component, if it is non-null. You may override this if you wish to customize the component's body-painting behavior. The component's body is painted first, before the border and children.


getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Description copied from class: javax.swing.JEditorPane
Returns true when a Viewport should force the width of this component to match the viewport width. This is implemented to return true when the parent is an instance of JViewport and the viewport width > the UI's minimum width.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Description copied from class: javax.swing.JEditorPane
Returns true when a Viewport should force the height of this component to match the viewport height. This is implemented to return true when the parent is an instance of JViewport and the viewport height > the UI's minimum height.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

getPreferredSize

public java.awt.Dimension getPreferredSize()
Description copied from class: javax.swing.JEditorPane
Returns the preferred size for the JEditorPane. This is implemented to return the super's preferred size, unless one of JEditorPane.getScrollableTracksViewportHeight()>JEditorPane.getScrollableTracksViewportHeight() 55 or JEditorPane.getScrollableTracksViewportWidth()>JEditorPane.getScrollableTracksViewportWidth() 55 returns true, in which case the preferred width and/or height is replaced by the UI's minimum size.


setCaretPosition

public void setCaretPosition(int _pos)
Description copied from class: javax.swing.text.JTextComponent
Sets the caret to a new position.


getSyntax

public java.lang.String getSyntax()

setSyntax

public void setSyntax(java.lang.String _syntax)

colorize

public void colorize(BuCommonInterface _app)

chooseFile

public static java.lang.String chooseFile(java.awt.Component owner,
                                          int mode)
Display a file chooser dialog box.


showMessage

public static void showMessage(java.lang.String message)
Display a sample message in a dialog box.


showError

public static void showError(java.lang.String message)
Display an error message in a dialog box.


getCurrentFile

public java.lang.String getCurrentFile()
Return the full path of the opened file.


beginOperation

public void beginOperation()
When an operation has began, setChanged() cannot be called. This is very important when we need to insert or remove some parts of the texte without turning on the 'to_be_saved' flag.


endOperation

public void endOperation()
Calling this will allow the DocumentListener to use setChanged().


getOperation

public boolean getOperation()
Return true if we can use the setChanged() method, false otherwise.


newFile

public void newFile()
Set a new file. We first ask the user if he'd like to save its changes (if some have been made).


getLineStartOffset

public int getLineStartOffset(int _n)
This is just to reduce code size of other classes.


getLineEndOffset

public int getLineEndOffset(int _n)

zipContent

public void zipContent()
Called to save current content in specified zip file. Call zip(String file) but asks user for overwriting if file already exists.


zip

public void zip(java.lang.String zipFile)
Zip text pane content into specified file.


saveContent

public void saveContent()
Called to save this component's content. Call save(String file) but let the user choosing a file name. In the case the user choosed an existing file, we ask him if he really wants to overwrite it.


save

public void save(java.lang.String file)
Store the text in a specified file.


open

public void open(java.lang.String path)
Called to load a new file in the text pane. Determines which line separator (\n, \r\n...) are used in the file to open. Convert'em into Swing line separator (\n).


isNew

public boolean isNew()
Return true if current text is new, false otherwise.


isEmpty

public boolean isEmpty()
Return true if pane is empty, false otherwise.


isDirty

public boolean isDirty()
Return true if pane content has changed, false otherwise.


setDirty

public void setDirty()
Called when the content of the pane has changed.


clean

public void clean()
Called after having saved or created a new document to ensure the content isn't 'dirty'.


discard

public void discard()
Discard all edits contained in the UndoManager.


getUndo

public javax.swing.undo.UndoManager getUndo()
Useful for the GUI.


undo

public void undo()
undo the last operation


redo

public void redo()
redo the last operation


getAnchor

public int getAnchor()
Return the anchor position.


setAnchor

public void setAnchor(int offset)
Set the anchor postion.


getLength

public int getLength()
Return the lentgh of the text in the pane.

Specified by:
getLength in interface BuTextComponentInterface

beginCompoundEdit

public void beginCompoundEdit()
Used for ReplaceAll. This merges all text changes made between the beginCompoundEdit() and the endCompoundEdit() calls into only one undo event.


endCompoundEdit

public void endCompoundEdit()
See beginCompoundEdit().


find

public boolean find(java.lang.String searchStr,
                    int start,
                    boolean ignoreCase)
Return the result of a string search.

Specified by:
find in interface BuTextComponentInterface

replace

public boolean replace(java.lang.String searchStr,
                       java.lang.String replaceStr,
                       int start,
                       int end,
                       boolean ignoreCase)
Specified by:
replace in interface BuTextComponentInterface

replaceAll

public boolean replaceAll(java.lang.String searchStr,
                          java.lang.String replaceStr,
                          int start,
                          int end,
                          boolean ignoreCase)
                   throws com.memoire.re.REException
Return the result of a string replace.


undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
When an undoable event is fired, we add it to the undo/redo list.

Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
When a modification is made in the text, we turn the 'to_be_saved' flag to true.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
When a modification is made in the text, we turn the 'to_be_saved' flag to true.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
When a modification is made in the text, we turn the 'to_be_saved' flag to true.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

toString

public java.lang.String toString()
Return a String representation of this object.