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

Quick Search    Search Deep

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

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.text.JTextComponent
                  extended byjavax.swing.JTextArea
                      extended bycom.memoire.bu.BuTextArea
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 BuTextArea
extends javax.swing.JTextArea
implements javax.swing.event.UndoableEditListener, javax.swing.event.DocumentListener, BuTextComponentInterface

This component extends a JTextArea, providing methods to undo/redo, find/replace and read/save. This component extends a JTextArea. 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.JTextArea
javax.swing.JTextArea.AccessibleJTextArea
 
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  java.lang.String fontName
           
private  int fontSize
           
private  int fontStyle
           
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.JTextArea
 
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
BuTextArea()
          The constructor add the necessary listeners, set some stuffs (caret color, borers, fonts...).
BuTextArea(int _lines, int _cols)
           
 
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.
private  void changeFont()
          Set the new font.
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 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.
 java.lang.String getFontName()
          Return current font's name
 int getFontSize()
          Return current font's size
 int getFontStyle()
          Return current font's style (bold, italic...)
 int getLength()
          Return the lentgh of the text in the area.
 int getLineStartOffset(int off)
          This is just to reduce code size of other classes.
 boolean getOperation()
          Return true if we can use the setChanged() method, false otherwise.
 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 area content has changed, false otherwise.
 boolean isEmpty()
          Return true if area is empty, false otherwise.
 boolean isNew()
          Return true if current text is new, false otherwise.
static void main(java.lang.String[] argv)
           
 void newFile()
          Set a new file.
 void open(java.lang.String path)
          Called to load a new file in the text area.
 void paint(java.awt.Graphics _g)
          Paint the component.
 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 setDirty()
          Called when the content of the area has changed.
 void setFontName(java.lang.String name)
          Set the font which has to be used.
 void setFontSize(int size)
          Set the size of the font.
 void setFontStyle(int style)
          Set the style of the font.
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 area content into specified file.
 void zipContent()
          Called to save current content in specified zip file.
 
Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, replaceRange, setColumns, setLineWrap, setRows, setTabSize, setWrapStyleWord
 
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, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paramString, paste, read, removeCaretListener, removeInputMethodListener, removeKeymap, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDocument, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, 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, paintComponent, 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, 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, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, 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

fontName

private java.lang.String fontName

currentFile

private java.lang.String currentFile

anchor

private int anchor

fontSize

private int fontSize

fontStyle

private int fontStyle

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

BuTextArea

public BuTextArea()
The constructor add the necessary listeners, set some stuffs (caret color, borers, fonts...).


BuTextArea

public BuTextArea(int _lines,
                  int _cols)
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.


select

public void select()

duplicate

public void duplicate()

go

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

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.


getFontName

public java.lang.String getFontName()
Return current font's name


getFontSize

public int getFontSize()
Return current font's size


getFontStyle

public int getFontStyle()
Return current font's style (bold, italic...)


setFontName

public void setFontName(java.lang.String name)
Set the font which has to be used.


setFontSize

public void setFontSize(int size)
Set the size of the font.


setFontStyle

public void setFontStyle(int style)
Set the style of the font.


changeFont

private void changeFont()
Set the new font.


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 off)
This is just to reduce code size of other classes.


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 area 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 area. 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 area is empty, false otherwise.


isDirty

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


setDirty

public void setDirty()
Called when the content of the area 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 area.

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.


main

public static void main(java.lang.String[] argv)