greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 15693

Show
Ignore:
Timestamp:
2008-05-23 18:51:55 (5 months ago)
Author:
ak19
Message:

Corrected a miscalculation of the start_offset. Turned DocumentEvent? into a member variable so that it can be constructed beforehand and fired when writing has finished in the WriterThread?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gli/trunk/src/org/greenstone/gatherer/util/AppendLineOnlyFileDocument.java

    r15641 r15693  
    6767    /** An independant thread responsible for writing the 'in memory' contents of the document model to the random access file as appropriate. This is done so IO lag does not effect the gui as much as it used to. */ 
    6868    private WriterThread writer; 
    69  
     69     
     70    /** Keeps track of the document insert update event to be fired next (after a line element is written) */ 
     71    private DocumentEvent event = null; 
    7072     
    7173    public AppendLineOnlyFileDocument(String filename) { 
     
    117119    } 
    118120 
     121    /** Notifies listeners of a document insert update event */ 
    119122    protected void fireInsertUpdate(DocumentEvent event) { 
    120123        Object[] listeners = listeners_list.getListenerList();  
     
    159162            // Queue the content to be written. 
    160163            writer.queue(new_line_element); 
    161             // moved the firing of DocumentEvent to the WriterThread.run() method for when the new line is *actually* written to the document 
    162             // DocumentEvent event = new AppendLineOnlyFileDocumentEvent(new_line_element, (int)start_offset, str_length, DocumentEvent.EventType.INSERT);  
    163             // fireInsertUpdate(event); 
     164 
     165            // moved the firing of DocumentEvent to the WriterThread.run() method for when the new line is *actually* written to the doc 
     166            event = new AppendLineOnlyFileDocumentEvent(new_line_element, (int)start_offset, str_length, DocumentEvent.EventType.INSERT);  
     167            //fireInsertUpdate(event); 
    164168            new_line_element = null; 
    165169        } 
     
    787791                        try { 
    788792                            write(element.getStartOffset(), element.getEndOffset(), content, content.getBytes("UTF-8").length); 
    789                              
    790                             // Now fire an event so everyone knows the Document's content has changed. 
    791                             int str_length = content.getBytes("UTF-8").length; 
    792                             long start_offset = length; 
    793                             DocumentEvent event = new AppendLineOnlyFileDocumentEvent(element, (int)start_offset, str_length, DocumentEvent.EventType.INSERT); 
    794                             AppendLineOnlyFileDocument.this.fireInsertUpdate(event); 
    795                              
    796793                        } 
    797794                        catch(Exception error) { 
    798795                            DebugStream.printStackTrace(error);                      
    799796                        } 
    800                         element.clearContent(); 
     797                        // having written the element, we fire any document insert update event prepared earlier 
     798                        if(event != null) { 
     799                            AppendLineOnlyFileDocument.this.fireInsertUpdate(event); 
     800                        } 
     801                        element.clearContent();     
    801802                    } 
    802803                } 
     
    813814                        } 
    814815                        print("WriterThread.wait() complete"); 
    815                    
     816                   
    816817                } 
    817818            }