Revision: 18267
http://sourceforge.net/p/gate/code/18267
Author: markagreenwood
Date: 2014-08-21 11:59:47 +0000 (Thu, 21 Aug 2014)
Log Message:
-----------
fixed a horrid document edit swing related nastiness
Modified Paths:
--------------
gate/trunk/.settings/org.eclipse.jdt.core.prefs
gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
gate/trunk/plugins/Learning/src/gate/learning/test/TestLearningAPI.java
gate/trunk/src/main/gate/gui/docview/TextualDocumentView.java
Modified: gate/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- gate/trunk/.settings/org.eclipse.jdt.core.prefs 2014-08-21 10:13:44 UTC
(rev 18266)
+++ gate/trunk/.settings/org.eclipse.jdt.core.prefs 2014-08-21 11:59:47 UTC
(rev 18267)
@@ -1,4 +1,14 @@
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
Modified: gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
2014-08-21 10:13:44 UTC (rev 18266)
+++ gate/trunk/plugins/Learning/src/gate/learning/NLPFeaturesOfDoc.java
2014-08-21 11:59:47 UTC (rev 18267)
@@ -623,6 +623,7 @@
if(singleAnnSet != null) {
AnnotationSet coverAnnSet = singleAnnSet.get(
tokenStartOffset, tokenEndOffset);
+ System.out.println("****************: "+coverAnnSet);
Iterator<Annotation> overlappingIterator = coverAnnSet.iterator();
if(overlappingIterator.hasNext()) {
Annotation superannotation = overlappingIterator.next();
Modified:
gate/trunk/plugins/Learning/src/gate/learning/test/TestLearningAPI.java
===================================================================
--- gate/trunk/plugins/Learning/src/gate/learning/test/TestLearningAPI.java
2014-08-21 10:13:44 UTC (rev 18266)
+++ gate/trunk/plugins/Learning/src/gate/learning/test/TestLearningAPI.java
2014-08-21 11:59:47 UTC (rev 18267)
@@ -462,7 +462,7 @@
* This test has been disabled (02/Apr/2014, IR) as it produces different
* numbers when run on Java 6 vs Java 7.
*/
- public void dont_testSVMRelationLearning() throws GateException, IOException
{
+ public void testSVMRelationLearning() throws GateException, IOException {
System.out.print("Testing the SVM with linear kernel on relation
extraction...");
// Initialisation relation-learning
File scHome = new File(new File(learningHome, "test"),
"relation-learning");
Modified: gate/trunk/src/main/gate/gui/docview/TextualDocumentView.java
===================================================================
--- gate/trunk/src/main/gate/gui/docview/TextualDocumentView.java
2014-08-21 10:13:44 UTC (rev 18266)
+++ gate/trunk/src/main/gate/gui/docview/TextualDocumentView.java
2014-08-21 11:59:47 UTC (rev 18267)
@@ -32,6 +32,7 @@
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -52,7 +53,6 @@
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
-
/**
* This class provides a central view for a textual document.
*/
@@ -60,24 +60,30 @@
@SuppressWarnings("serial")
public class TextualDocumentView extends AbstractDocumentView {
- public TextualDocumentView(){
+ public TextualDocumentView() {
blinkingTagsForAnnotations = new HashMap<AnnotationData, HighlightData>();
- //use linked lists as they grow and shrink in constant time and direct
access
- //is not required.
+ // use linked lists as they grow and shrink in constant time and
+ // direct access
+ // is not required.
highlightsToAdd = new LinkedList<HighlightData>();
highlightsToRemove = new LinkedList<HighlightData>();
blinkingHighlightsToRemove = new HashSet<AnnotationData>();
blinkingHighlightsToAdd = new LinkedList<AnnotationData>();
gateDocListener = new GateDocumentListener();
+ swingDocListener = new SwingDocumentListener();
}
@Override
public void cleanup() {
super.cleanup();
highlightsMinder.stop();
+
+ if (document != null) document.removeDocumentListener(gateDocListener);
+ textView.getDocument().removeDocumentListener(swingDocListener);
+
}
- public HighlightData addHighlight(AnnotationData aData, Color colour){
+ public HighlightData addHighlight(AnnotationData aData, Color colour) {
HighlightData hData = new HighlightData(aData, colour);
synchronized(TextualDocumentView.this) {
highlightsToAdd.add(hData);
@@ -87,22 +93,25 @@
}
/**
- * Adds several highlights in one go.
- * This method should be called from within the UI thread.
- * @param annotations the collection of annotations for which highlights
- * are to be added.
+ * Adds several highlights in one go. This method should be called
+ * from within the UI thread.
+ *
+ * @param annotations the collection of annotations for which
+ * highlights are to be added.
* @param colour the colour for the highlights.
* @return the list of tags for the added highlights. The order of the
- * elements corresponds to the order defined by the iterator of the
- * collection of annotations provided.
+ * elements corresponds to the order defined by the iterator
+ * of the collection of annotations provided.
*/
- public List<HighlightData> addHighlights(Collection<AnnotationData>
annotations, Color colour){
+ public List<HighlightData> addHighlights(
+ Collection<AnnotationData> annotations, Color colour) {
List<HighlightData> tags = new ArrayList<HighlightData>();
- for(AnnotationData aData : annotations) tags.add(addHighlight(aData,
colour));
+ for(AnnotationData aData : annotations)
+ tags.add(addHighlight(aData, colour));
return tags;
}
- public void removeHighlight(HighlightData tag){
+ public void removeHighlight(HighlightData tag) {
synchronized(TextualDocumentView.this) {
highlightsToRemove.add(tag);
}
@@ -110,12 +119,14 @@
}
/**
- * Same as {@link #addHighlights(java.util.Collection, java.awt.Color)} but
+ * Same as
+ * {@link #addHighlights(java.util.Collection, java.awt.Color)} but
* without the intermediate creation of HighlightData objects.
+ *
* @param list list of HighlightData
*/
public void addHighlights(List<HighlightData> list) {
- for (HighlightData highlightData : list) {
+ for(HighlightData highlightData : list) {
synchronized(TextualDocumentView.this) {
highlightsToAdd.add(highlightData);
}
@@ -125,40 +136,47 @@
/**
* Removes several highlights in one go.
+ *
* @param tags the tags for the highlights to be removed
*/
- public void removeHighlights(Collection<HighlightData> tags){
- //this might get an optimised implementation at some point,
- //for the time being this seems to work fine.
- for(HighlightData tag : tags) removeHighlight(tag);
+ public void removeHighlights(Collection<HighlightData> tags) {
+ // this might get an optimised implementation at some point,
+ // for the time being this seems to work fine.
+ for(HighlightData tag : tags)
+ removeHighlight(tag);
}
-
/**
* Set the text orientation in the document.
*
- * @param orientation
- * either left to right or right to left
+ * @param orientation either left to right or right to left
*/
public void changeOrientation(ComponentOrientation orientation) {
// set the orientation
textView.setComponentOrientation(orientation);
- // disable the listener
- gateDocListener.setActive(false);
- // this is required as eventhough orientation gets applied,
- // the screen is not updated unless a character input is
- // detected by the textView
- textView.insert("a", 0);
- textView.replaceRange("", 0, 1);
- // enabling the listener again
- gateDocListener.setActive(true);
- }//changeOrientation
- public void scrollAnnotationToVisible(Annotation ann){
- //if at least part of the blinking section is visible then we
- //need to do no scrolling
- //this is required for long annotations that span more than a
- //screen
+ try {
+ // disable the listener
+ document.removeDocumentListener(gateDocListener);
+ // this is required as eventhough orientation gets applied,
+ // the screen is not updated unless a character input is
+ // detected by the textView
+ textView.insert("a", 0);
+ textView.replaceRange("", 0, 1);
+ }
+ finally {
+ // enabling the listener again
+ document.addDocumentListener(gateDocListener);
+ }
+
+
+ }// changeOrientation
+
+ public void scrollAnnotationToVisible(Annotation ann) {
+ // if at least part of the blinking section is visible then we
+ // need to do no scrolling
+ // this is required for long annotations that span more than a
+ // screen
Rectangle visibleView = scroller.getViewport().getViewRect();
int viewStart = textView.viewToModel(visibleView.getLocation());
Point endPoint = new Point(visibleView.getLocation());
@@ -166,126 +184,126 @@
int viewEnd = textView.viewToModel(endPoint);
int annStart = ann.getStartNode().getOffset().intValue();
int annEnd = ann.getEndNode().getOffset().intValue();
- if(annEnd < viewStart || viewEnd < annStart){
- try{
+ if(annEnd < viewStart || viewEnd < annStart) {
+ try {
textView.scrollRectToVisible(textView.modelToView(annStart));
- }catch(BadLocationException ble){
- //this should never happen
+ } catch(BadLocationException ble) {
+ // this should never happen
throw new GateRuntimeException(ble);
}
}
}
-
-
/**
- * Gives access to the highliter's change highlight operation. Can be used to
- * change the offset of an existing highlight.
+ * Gives access to the highliter's change highlight operation. Can be
+ * used to change the offset of an existing highlight.
+ *
* @param tag the tag for the highlight
* @param newStart new start offset.
* @param newEnd new end offset.
* @throws BadLocationException
*/
public void moveHighlight(Object tag, int newStart, int newEnd)
- throws BadLocationException{
- if(tag instanceof HighlightData){
- textView.getHighlighter().changeHighlight(((HighlightData)tag).tag,
newStart, newEnd);
+ throws BadLocationException {
+ if(tag instanceof HighlightData) {
+ textView.getHighlighter().changeHighlight(((HighlightData)tag).tag,
+ newStart, newEnd);
}
}
-
-
/**
- * Removes all blinking highlights and shows the new ones, corresponding to
- * the new set of selected annotations
+ * Removes all blinking highlights and shows the new ones,
+ * corresponding to the new set of selected annotations
*/
@Override
public void setSelectedAnnotations(List<AnnotationData> selectedAnnots) {
- synchronized(blinkingTagsForAnnotations){
- //clear the pending queue, if any
+ synchronized(blinkingTagsForAnnotations) {
+ // clear the pending queue, if any
blinkingHighlightsToAdd.clear();
- //request the removal of existing highlights
+ // request the removal of existing highlights
blinkingHighlightsToRemove.addAll(blinkingTagsForAnnotations.keySet());
- //add all the new annotations to the "to add" queue
- for(AnnotationData aData : selectedAnnots){
+ // add all the new annotations to the "to add" queue
+ for(AnnotationData aData : selectedAnnots) {
blinkingHighlightsToAdd.add(aData);
}
- //restart the timer
+ // restart the timer
highlightsMinder.restart();
}
}
-// public void addBlinkingHighlight(Annotation ann){
-// synchronized(TextualDocumentView.this){
-// blinkingHighlightsToAdd.add(ann);
-//
-//// blinkingTagsForAnnotations.put(ann.getId(),
-//// new HighlightData(ann, null, null));
-// highlightsMinder.restart();
-// }
-// }
+ // public void addBlinkingHighlight(Annotation ann){
+ // synchronized(TextualDocumentView.this){
+ // blinkingHighlightsToAdd.add(ann);
+ //
+ // // blinkingTagsForAnnotations.put(ann.getId(),
+ // // new HighlightData(ann, null, null));
+ // highlightsMinder.restart();
+ // }
+ // }
-// public void removeBlinkingHighlight(Annotation ann){
-// synchronized(TextualDocumentView.this) {
-// blinkingHighlightsToRemove.add(ann.getId());
-// highlightsMinder.restart();
-// }
-// }
+ // public void removeBlinkingHighlight(Annotation ann){
+ // synchronized(TextualDocumentView.this) {
+ // blinkingHighlightsToRemove.add(ann.getId());
+ // highlightsMinder.restart();
+ // }
+ // }
+ // public void removeAllBlinkingHighlights(){
+ // synchronized(TextualDocumentView.this){
+ // //clear the pending queue, if any
+ // blinkingHighlightsToAdd.clear();
+ // //request the removal of existing highlights
+ // blinkingHighlightsToRemove.addAll(blinkingTagsForAnnotations.keySet());
+ // // Iterator annIdIter = new
+ // ArrayList(blinkingTagsForAnnotations.keySet()).
+ // // iterator();
+ // // while(annIdIter.hasNext()){
+ // // HighlightData annTag =
+ // blinkingTagsForAnnotations.remove(annIdIter.next());
+ // // Object tag = annTag.tag;
+ // // if(tag != null){
+ // // Highlighter highlighter = textView.getHighlighter();
+ // // highlighter.removeHighlight(tag);
+ // // }
+ // // }
+ // highlightsMinder.restart();
+ // }
+ // }
-// public void removeAllBlinkingHighlights(){
-// synchronized(TextualDocumentView.this){
-// //clear the pending queue, if any
-// blinkingHighlightsToAdd.clear();
-// //request the removal of existing highlights
-// blinkingHighlightsToRemove.addAll(blinkingTagsForAnnotations.keySet());
-//// Iterator annIdIter = new
ArrayList(blinkingTagsForAnnotations.keySet()).
-//// iterator();
-//// while(annIdIter.hasNext()){
-//// HighlightData annTag =
blinkingTagsForAnnotations.remove(annIdIter.next());
-//// Object tag = annTag.tag;
-//// if(tag != null){
-//// Highlighter highlighter = textView.getHighlighter();
-//// highlighter.removeHighlight(tag);
-//// }
-//// }
-// highlightsMinder.restart();
-// }
-// }
-
-
@Override
public int getType() {
return CENTRAL;
}
/**
- * Stores the target (which should always be a {@link Document}) into the
- * {@link #document} field.
+ * Stores the target (which should always be a {@link Document}) into
+ * the {@link #document} field.
*/
@Override
public void setTarget(Object target) {
- if(document != null){
- //remove the old listener
+ if(document != null) {
+ // remove the old listener
document.removeDocumentListener(gateDocListener);
}
super.setTarget(target);
- //register the new listener
+ // register the new listener
this.document.addDocumentListener(gateDocListener);
}
public void setEditable(boolean editable) {
- textView.setEditable(editable);
+ textView.setEditable(editable);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see gate.gui.docview.AbstractDocumentView#initGUI()
*/
@Override
protected void initGUI() {
-// textView = new JEditorPane();
-// textView.setContentType("text/plain");
-// textView.setEditorKit(new RawEditorKit());
+ // textView = new JEditorPane();
+ // textView.setContentType("text/plain");
+ // textView.setEditorKit(new RawEditorKit());
textView = new JTextArea();
textView.setAutoscrolls(false);
@@ -298,13 +316,13 @@
scroller = new JScrollPane(textView);
textView.setText(document.getContent().toString());
- textView.getDocument().addDocumentListener(new SwingDocumentListener());
+ textView.getDocument().addDocumentListener(swingDocListener);
// display and put the caret at the beginning of the file
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
- if (textView.modelToView(0) != null) {
+ if(textView.modelToView(0) != null) {
textView.scrollRectToVisible(textView.modelToView(0));
}
textView.select(0, 0);
@@ -314,17 +332,17 @@
}
}
});
-// contentPane = new JPanel(new BorderLayout());
-// contentPane.add(scroller, BorderLayout.CENTER);
+ // contentPane = new JPanel(new BorderLayout());
+ // contentPane.add(scroller, BorderLayout.CENTER);
-// //get a pointer to the annotation list view used to display
-// //the highlighted annotations
-// Iterator horizViewsIter = owner.getHorizontalViews().iterator();
-// while(annotationListView == null && horizViewsIter.hasNext()){
-// DocumentView aView = (DocumentView)horizViewsIter.next();
-// if(aView instanceof AnnotationListView)
-// annotationListView = (AnnotationListView)aView;
-// }
+ // //get a pointer to the annotation list view used to display
+ // //the highlighted annotations
+ // Iterator horizViewsIter = owner.getHorizontalViews().iterator();
+ // while(annotationListView == null && horizViewsIter.hasNext()){
+ // DocumentView aView = (DocumentView)horizViewsIter.next();
+ // if(aView instanceof AnnotationListView)
+ // annotationListView = (AnnotationListView)aView;
+ // }
highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());
highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);
highlightsMinder.setDelay(BLINK_DELAY);
@@ -332,42 +350,43 @@
highlightsMinder.setCoalesce(true);
highlightsMinder.start();
-// blinker = new Timer(this.getClass().getCanonicalName() + "_blink_timer",
-// true);
-// final BlinkAction blinkAction = new BlinkAction();
-// blinker.scheduleAtFixedRate(new TimerTask(){
-// public void run() {
-// blinkAction.actionPerformed(null);
-// }
-// }, 0, BLINK_DELAY);
+ // blinker = new Timer(this.getClass().getCanonicalName() +
+ // "_blink_timer",
+ // true);
+ // final BlinkAction blinkAction = new BlinkAction();
+ // blinker.scheduleAtFixedRate(new TimerTask(){
+ // public void run() {
+ // blinkAction.actionPerformed(null);
+ // }
+ // }, 0, BLINK_DELAY);
initListeners();
}
@Override
- public Component getGUI(){
-// return contentPane;
+ public Component getGUI() {
+ // return contentPane;
return scroller;
}
- protected void initListeners(){
-// textView.addComponentListener(new ComponentAdapter(){
-// public void componentResized(ComponentEvent e){
-// try{
-// scroller.getViewport().setViewPosition(
-// textView.modelToView(0).getLocation());
-// scroller.paintImmediately(textView.getBounds());
-// }catch(BadLocationException ble){
-// //ignore
-// }
-// }
-// });
+ protected void initListeners() {
+ // textView.addComponentListener(new ComponentAdapter(){
+ // public void componentResized(ComponentEvent e){
+ // try{
+ // scroller.getViewport().setViewPosition(
+ // textView.modelToView(0).getLocation());
+ // scroller.paintImmediately(textView.getBounds());
+ // }catch(BadLocationException ble){
+ // //ignore
+ // }
+ // }
+ // });
- // stop control+H from deleting text and transfers the key to the parent
+ // stop control+H from deleting text and transfers the key to the
+ // parent
textView.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_H
- && e.isControlDown()) {
+ if(e.getKeyCode() == KeyEvent.VK_H && e.isControlDown()) {
getGUI().dispatchEvent(e);
e.consume();
}
@@ -376,83 +395,86 @@
}
@Override
- protected void unregisterHooks(){}
+ protected void unregisterHooks() {
+ }
+
@Override
- protected void registerHooks(){}
+ protected void registerHooks() {
+ }
/**
* Blinks the blinking highlights if any.
*/
- protected class UpdateHighlightsAction extends AbstractAction{
+ protected class UpdateHighlightsAction extends AbstractAction {
@Override
- public void actionPerformed(ActionEvent evt){
- synchronized(blinkingTagsForAnnotations){
+ public void actionPerformed(ActionEvent evt) {
+ synchronized(blinkingTagsForAnnotations) {
updateBlinkingHighlights();
updateNormalHighlights();
}
}
+ protected void updateBlinkingHighlights() {
+ // this needs to either add or remove the highlights
- protected void updateBlinkingHighlights(){
- //this needs to either add or remove the highlights
-
- //first remove the queued highlights
+ // first remove the queued highlights
Highlighter highlighter = textView.getHighlighter();
- for(AnnotationData aData : blinkingHighlightsToRemove){
+ for(AnnotationData aData : blinkingHighlightsToRemove) {
HighlightData annTag = blinkingTagsForAnnotations.remove(aData);
- if(annTag != null){
+ if(annTag != null) {
Object tag = annTag.tag;
- if(tag != null){
- //highlight was visible and will be removed
+ if(tag != null) {
+ // highlight was visible and will be removed
highlighter.removeHighlight(tag);
annTag.tag = null;
}
}
}
blinkingHighlightsToRemove.clear();
- //then add the queued highlights
- for(AnnotationData aData : blinkingHighlightsToAdd){
- blinkingTagsForAnnotations.put(aData,
- new HighlightData(aData, null));
+ // then add the queued highlights
+ for(AnnotationData aData : blinkingHighlightsToAdd) {
+ blinkingTagsForAnnotations.put(aData, new HighlightData(aData, null));
}
blinkingHighlightsToAdd.clear();
- //finally switch the state of the current blinking highlights
- //get out as quickly as possible if nothing to do
+ // finally switch the state of the current blinking highlights
+ // get out as quickly as possible if nothing to do
if(blinkingTagsForAnnotations.isEmpty()) return;
- Iterator<AnnotationData> annIdIter = new
ArrayList<AnnotationData>(blinkingTagsForAnnotations.keySet()).
- iterator();
+ Iterator<AnnotationData> annIdIter =
+ new
ArrayList<AnnotationData>(blinkingTagsForAnnotations.keySet())
+ .iterator();
- if(highlightsShown){
- //hide current highlights
- while(annIdIter.hasNext()){
+ if(highlightsShown) {
+ // hide current highlights
+ while(annIdIter.hasNext()) {
HighlightData annTag =
- blinkingTagsForAnnotations.get(annIdIter.next());
-// Annotation ann = annTag.annotation;
- if (annTag != null) {
+ blinkingTagsForAnnotations.get(annIdIter.next());
+ // Annotation ann = annTag.annotation;
+ if(annTag != null) {
Object tag = annTag.tag;
if(tag != null) highlighter.removeHighlight(tag);
annTag.tag = null;
}
}
highlightsShown = false;
- }else{
- //show highlights
- while(annIdIter.hasNext()){
+ } else {
+ // show highlights
+ while(annIdIter.hasNext()) {
HighlightData annTag =
- blinkingTagsForAnnotations.get(annIdIter.next());
- if (annTag != null) {
+ blinkingTagsForAnnotations.get(annIdIter.next());
+ if(annTag != null) {
Annotation ann = annTag.annotation;
- try{
- Object tag = highlighter.addHighlight(
- ann.getStartNode().getOffset().intValue(),
- ann.getEndNode().getOffset().intValue(),
- new DefaultHighlighter.DefaultHighlightPainter(
- textView.getSelectionColor()));
+ try {
+ Object tag =
+ highlighter.addHighlight(ann.getStartNode().getOffset()
+ .intValue(), ann.getEndNode().getOffset()
+ .intValue(),
+ new DefaultHighlighter.DefaultHighlightPainter(
+ textView.getSelectionColor()));
annTag.tag = tag;
-// scrollAnnotationToVisible(ann);
- }catch(BadLocationException ble){
- //this should never happen
+ // scrollAnnotationToVisible(ann);
+ } catch(BadLocationException ble) {
+ // this should never happen
throw new GateRuntimeException(ble);
}
}
@@ -461,52 +483,58 @@
}
}
- protected void updateNormalHighlights(){
+ protected void updateNormalHighlights() {
synchronized(TextualDocumentView.this) {
- if((highlightsToRemove.size() + highlightsToAdd.size()) > 0){
-// Point viewPosition = scroller.getViewport().getViewPosition();
+ if((highlightsToRemove.size() + highlightsToAdd.size()) > 0) {
+ // Point viewPosition =
+ // scroller.getViewport().getViewPosition();
Highlighter highlighter = textView.getHighlighter();
-// textView.setVisible(false);
-// scroller.getViewport().setView(new JLabel("Updating"));
- //add all new highlights
- while(highlightsToAdd.size() > 0){
+ // textView.setVisible(false);
+ // scroller.getViewport().setView(new JLabel("Updating"));
+ // add all new highlights
+ while(highlightsToAdd.size() > 0) {
HighlightData hData = highlightsToAdd.remove(0);
- try{
- hData.tag = highlighter.addHighlight(
- hData.annotation.getStartNode().getOffset().intValue(),
- hData.annotation.getEndNode().getOffset().intValue(),
- new
DefaultHighlighter.DefaultHighlightPainter(hData.colour));
- }catch(BadLocationException ble){
- //the offsets should always be OK as they come from an annotation
+ try {
+ hData.tag =
+ highlighter.addHighlight(hData.annotation.getStartNode()
+ .getOffset().intValue(), hData.annotation
+ .getEndNode().getOffset().intValue(),
+ new DefaultHighlighter.DefaultHighlightPainter(
+ hData.colour));
+ } catch(BadLocationException ble) {
+ // the offsets should always be OK as they come from an
+ // annotation
ble.printStackTrace();
}
-// annotationListView.addAnnotation(hData, hData.annotation,
-// hData.set);
+ // annotationListView.addAnnotation(hData, hData.annotation,
+ // hData.set);
}
- //remove all the highlights that need removing
- while(highlightsToRemove.size() > 0){
+ // remove all the highlights that need removing
+ while(highlightsToRemove.size() > 0) {
HighlightData hData = highlightsToRemove.remove(0);
- if(hData.tag != null){
+ if(hData.tag != null) {
highlighter.removeHighlight(hData.tag);
}
-// annotationListView.removeAnnotation(hData);
+ // annotationListView.removeAnnotation(hData);
}
-
- //restore the updated view
-// scroller.getViewport().setView(textView);
-// textView.setVisible(true);
-// scroller.getViewport().setViewPosition(viewPosition);
+ // restore the updated view
+ // scroller.getViewport().setView(textView);
+ // textView.setVisible(true);
+ // scroller.getViewport().setViewPosition(viewPosition);
}
}
}
+
protected boolean highlightsShown = false;
}
- public static class HighlightData{
+ public static class HighlightData {
Annotation annotation;
+
Color colour;
+
Object tag;
public HighlightData(AnnotationData aData, Color colour) {
@@ -515,7 +543,7 @@
}
}
- protected class GateDocumentListener implements DocumentListener{
+ protected class GateDocumentListener implements DocumentListener {
@Override
public void annotationSetAdded(DocumentEvent e) {
@@ -527,80 +555,91 @@
@Override
public void contentEdited(DocumentEvent e) {
- if(active){
- //reload the content.
- textView.setText(document.getContent().toString());
- }
+ // reload the content.
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ textView.getDocument().removeDocumentListener(swingDocListener);
+ textView.setText(document.getContent().toString());
+ } finally {
+ textView.getDocument().addDocumentListener(swingDocListener);
+ }
+ }
+ });
}
-
- public void setActive(boolean active){
- this.active = active;
- }
- private boolean active = true;
}
- protected class SwingDocumentListener implements
javax.swing.event.DocumentListener{
+ protected class SwingDocumentListener implements
+ javax.swing.event.DocumentListener {
@Override
public void insertUpdate(final javax.swing.event.DocumentEvent e) {
- //propagate the edit to the document
- try{
- //deactivate our own listener so we don't get cycles
- gateDocListener.setActive(false);
- document.edit(new Long(e.getOffset()), new Long(e.getOffset()),
- new DocumentContentImpl(
- e.getDocument().getText(e.getOffset(),
e.getLength())));
- }catch(BadLocationException ble){
+ // propagate the edit to the document
+ try {
+ // deactivate our own listener so we don't get cycles
+ document.removeDocumentListener(gateDocListener);
+ document.edit(
+ new Long(e.getOffset()),
+ new Long(e.getOffset()),
+ new DocumentContentImpl(e.getDocument().getText(e.getOffset(),
+ e.getLength())));
+ } catch(BadLocationException ble) {
ble.printStackTrace(Err.getPrintWriter());
- }catch(InvalidOffsetException ioe){
+ } catch(InvalidOffsetException ioe) {
ioe.printStackTrace(Err.getPrintWriter());
- }finally{
- //reactivate our listener
- gateDocListener.setActive(true);
+ } finally {
+ // reactivate our listener
+ document.addDocumentListener(gateDocListener);
}
-// //update the offsets in the list
-// Component listView = annotationListView.getGUI();
-// if(listView != null) listView.repaint();
+ // //update the offsets in the list
+ // Component listView = annotationListView.getGUI();
+ // if(listView != null) listView.repaint();
}
@Override
public void removeUpdate(final javax.swing.event.DocumentEvent e) {
- //propagate the edit to the document
- try{
- //deactivate our own listener so we don't get cycles
- gateDocListener.setActive(false);
+ // propagate the edit to the document
+ try {
+ // deactivate our own listener so we don't get cycles
+ // gateDocListener.setActive(false);
+ document.removeDocumentListener(gateDocListener);
document.edit(new Long(e.getOffset()),
- new Long(e.getOffset() + e.getLength()),
- new DocumentContentImpl(""));
- }catch(InvalidOffsetException ioe){
+ new Long(e.getOffset() + e.getLength()),
+ new DocumentContentImpl(""));
+ } catch(InvalidOffsetException ioe) {
ioe.printStackTrace(Err.getPrintWriter());
- }finally{
- //reactivate our listener
- gateDocListener.setActive(true);
+ } finally {
+ // reactivate our listener
+ // gateDocListener.setActive(true);
+ document.addDocumentListener(gateDocListener);
}
-// //update the offsets in the list
-// Component listView = annotationListView.getGUI();
-// if(listView != null) listView.repaint();
+ // //update the offsets in the list
+ // Component listView = annotationListView.getGUI();
+ // if(listView != null) listView.repaint();
}
@Override
public void changedUpdate(javax.swing.event.DocumentEvent e) {
- //some attributes changed: we don't care about that
+ // some attributes changed: we don't care about that
}
- }//class SwingDocumentListener implements javax.swing.event.DocumentListener
+ }// class SwingDocumentListener implements
+ // javax.swing.event.DocumentListener
// When the textPane loses the focus it doesn't really lose
// the selection, it just stops painting it so we need to force
// the painting
public class PermanentSelectionCaret extends DefaultCaret {
private boolean isFocused;
+
@Override
public void setSelectionVisible(boolean hasFocus) {
- if (hasFocus != isFocused) {
+ if(hasFocus != isFocused) {
isFocused = hasFocus;
super.setSelectionVisible(false);
super.setSelectionVisible(true);
}
}
+
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
@@ -613,54 +652,58 @@
* The scroll pane holding the text
*/
protected JScrollPane scroller;
-// protected AnnotationListView annotationListView;
-// /**
-// * The main panel containing the text scroll in the central location.
-// */
-// protected JPanel contentPane;
+ // protected AnnotationListView annotationListView;
+ // /**
+ // * The main panel containing the text scroll in the central
+ // location.
+ // */
+ // protected JPanel contentPane;
+
protected GateDocumentListener gateDocListener;
+ protected SwingDocumentListener swingDocListener;
+
/**
- * The annotations used for blinking highlights and their tags. A map from
- * {@link AnnotationData} to tag(i.e. {@link Object}).
+ * The annotations used for blinking highlights and their tags. A map
+ * from {@link AnnotationData} to tag(i.e. {@link Object}).
*/
protected Map<AnnotationData, HighlightData> blinkingTagsForAnnotations;
/**
- * This list stores the {@link TextualDocumentView.HighlightData} values for
annotations pending
- * highlighting
+ * This list stores the {@link TextualDocumentView.HighlightData}
+ * values for annotations pending highlighting
*/
protected List<HighlightData> highlightsToAdd;
-
+
/**
- * This list stores the {@link TextualDocumentView.HighlightData} values for
highlights that need
- * to be removed
+ * This list stores the {@link TextualDocumentView.HighlightData}
+ * values for highlights that need to be removed
*/
protected List<HighlightData> highlightsToRemove;
-
+
/**
- * Used internally to store the annotations for which blinking highlights
- * need to be removed.
+ * Used internally to store the annotations for which blinking
+ * highlights need to be removed.
*/
- protected Set<AnnotationData> blinkingHighlightsToRemove;
-
+ protected Set<AnnotationData> blinkingHighlightsToRemove;
+
/**
- * Used internally to store the annotations for which blinking highlights
- * need to be added.
+ * Used internally to store the annotations for which blinking
+ * highlights need to be added.
*/
- protected List<AnnotationData> blinkingHighlightsToAdd;
-
+ protected List<AnnotationData> blinkingHighlightsToAdd;
+
protected Timer highlightsMinder;
-
+
protected JTextArea textView;
-
+
/**
* The delay used by the blinker.
*/
protected final static int BLINK_DELAY = 400;
-
+
/**
* The delay used by the highlights minder.
*/
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs