Lines 14-21
Link Here
|
14 |
package org.openide.text; |
14 |
package org.openide.text; |
15 |
|
15 |
|
16 |
import java.io.*; |
16 |
import java.io.*; |
17 |
import java.util.*; |
17 |
import java.util.ArrayList; |
18 |
import java.lang.ref.*; |
18 |
import java.util.Iterator; |
|
|
19 |
import java.util.List; |
19 |
import java.util.WeakHashMap; |
20 |
import java.util.WeakHashMap; |
20 |
import javax.swing.text.*; |
21 |
import javax.swing.text.*; |
21 |
import javax.swing.event.*; |
22 |
import javax.swing.event.*; |
Lines 23-28
Link Here
|
23 |
|
24 |
|
24 |
import org.openide.*; |
25 |
import org.openide.*; |
25 |
import org.openide.loaders.*; |
26 |
import org.openide.loaders.*; |
|
|
27 |
import org.openide.util.WeakSet; |
26 |
import org.openide.util.WeakListener; |
28 |
import org.openide.util.WeakListener; |
27 |
import org.openide.util.Task; |
29 |
import org.openide.util.Task; |
28 |
import org.openide.util.RequestProcessor; |
30 |
import org.openide.util.RequestProcessor; |
Lines 80-86
Link Here
|
80 |
|
82 |
|
81 |
/** Init listeners |
83 |
/** Init listeners |
82 |
*/ |
84 |
*/ |
83 |
private void init () { |
85 |
void init () { |
84 |
listener = new LR (); |
86 |
listener = new LR (); |
85 |
pos.getCloneableEditorSupport ().addChangeListener (WeakListener.change (listener, pos.getCloneableEditorSupport ())); |
87 |
pos.getCloneableEditorSupport ().addChangeListener (WeakListener.change (listener, pos.getCloneableEditorSupport ())); |
86 |
} |
88 |
} |
Lines 272-278
Link Here
|
272 |
/** Register line. |
274 |
/** Register line. |
273 |
*/ |
275 |
*/ |
274 |
Object readResolve() throws ObjectStreamException { |
276 |
Object readResolve() throws ObjectStreamException { |
275 |
return Set.registerLine (this); |
277 |
// return Set.registerLine (this); |
|
|
278 |
//Set.registerPendingLine(this); |
279 |
return this.pos.getCloneableEditorSupport().getLineSet().registerLine(this); |
276 |
} |
280 |
} |
277 |
|
281 |
|
278 |
|
282 |
|
Lines 623-634
Link Here
|
623 |
*/ |
627 |
*/ |
624 |
public static abstract class Set extends Line.Set { |
628 |
public static abstract class Set extends Line.Set { |
625 |
/** listener on document changes */ |
629 |
/** listener on document changes */ |
626 |
private LineListener listener; |
630 |
private final LineListener listener; |
627 |
/** all lines in the set or null */ |
631 |
/** all lines in the set or null */ |
628 |
private java.util.List list; |
632 |
private java.util.List list; |
629 |
/** map to hold all existing lines (Line, Reference (Line)) */ |
|
|
630 |
private static WeakHashMap allLines = new WeakHashMap (37); |
631 |
|
633 |
|
|
|
634 |
|
632 |
/** Constructor. |
635 |
/** Constructor. |
633 |
* @param doc document to work on |
636 |
* @param doc document to work on |
634 |
*/ |
637 |
*/ |
Lines 640-691
Link Here
|
640 |
listener = new LineListener (doc, support); |
643 |
listener = new LineListener (doc, support); |
641 |
} |
644 |
} |
642 |
|
645 |
|
|
|
646 |
|
643 |
/** Find the line given as parameter in list of all lines attached to this set |
647 |
/** Find the line given as parameter in list of all lines attached to this set |
644 |
* and if the line exist in the list, notify it about being edited. */ |
648 |
* and if the line exist in the list, notify it about being edited. */ |
645 |
boolean fireLineChanged(Line comparingLine, DocumentEvent p0) { |
649 |
void linesChanged(int startLineNumber, int endLineNumber, DocumentEvent p0) { |
646 |
Reference ref = (Reference)allLines.get (comparingLine); |
650 |
List changedLines = getLinesFromRange(startLineNumber, endLineNumber); |
647 |
if (ref == null) { |
|
|
648 |
return false; |
649 |
} |
650 |
Line line = (Line)ref.get (); |
651 |
|
651 |
|
652 |
if(line == null) { |
652 |
for(Iterator it = changedLines.iterator(); it.hasNext(); ) { |
653 |
return false; |
653 |
Line line = (Line)it.next(); |
|
|
654 |
|
655 |
line.firePropertyChange(Annotatable.PROP_TEXT, null, null); |
656 |
|
657 |
// revalidate all parts attached to this line |
658 |
// that they are still part of the line |
659 |
if(line instanceof DocumentLine) { |
660 |
((DocumentLine)line).notifyChange(p0, this, listener.doc); |
661 |
} |
654 |
} |
662 |
} |
655 |
|
|
|
656 |
line.firePropertyChange(Annotatable.PROP_TEXT, null, null); |
657 |
|
658 |
// revalidate all parts attached to this line |
659 |
// that they are still part of the line |
660 |
if (line instanceof DocumentLine) |
661 |
((DocumentLine)line).notifyChange(p0, this, listener.doc); |
662 |
|
663 |
return true; |
664 |
} |
663 |
} |
665 |
|
664 |
|
666 |
/** Find the line given as parameter in list of all lines attached to this set |
665 |
/** Find the line given as parameter in list of all lines attached to this set |
667 |
* and if the line exist in the list, notify it about being moved. */ |
666 |
* and if the line exist in the list, notify it about being moved. */ |
668 |
boolean fireLineMoved(Line comparingLine) { |
667 |
void linesMoved(int startLineNumber, int endLineNumber) { |
669 |
Reference ref = (Reference)allLines.get (comparingLine); |
668 |
List movedLines = getLinesFromRange(startLineNumber, endLineNumber); |
670 |
if (ref == null) { |
|
|
671 |
return false; |
672 |
} |
673 |
Line line = (Line)ref.get (); |
674 |
|
669 |
|
675 |
if(line == null) { |
670 |
for(Iterator it = movedLines.iterator(); it.hasNext(); ) { |
676 |
return false; |
671 |
Line line = (Line)it.next(); |
|
|
672 |
line.firePropertyChange(Line.PROP_LINE_NUMBER, null, null); |
673 |
|
674 |
// notify all parts attached to this line |
675 |
// that they were moved |
676 |
if (line instanceof DocumentLine) { |
677 |
((DocumentLine)line).notifyMove(); |
678 |
} |
677 |
} |
679 |
} |
678 |
|
|
|
679 |
line.firePropertyChange(Line.PROP_LINE_NUMBER, null, null); |
680 |
|
681 |
// notify all parts attached to this line |
682 |
// that they were moved |
683 |
if (line instanceof DocumentLine) |
684 |
((DocumentLine)line).notifyMove(); |
685 |
|
686 |
return true; |
687 |
} |
680 |
} |
688 |
|
681 |
|
|
|
682 |
/** Gets the lines with line number whitin the range inclusive. |
683 |
* @return <code>List</code> of lines from range inclusive */ |
684 |
private List getLinesFromRange(int startLineNumber, int endLineNumber) { |
685 |
List linesInRange = new ArrayList(10); |
686 |
|
687 |
synchronized(lines) { |
688 |
for(Iterator it = lines.keySet().iterator(); it.hasNext(); ) { |
689 |
Line line = (Line)it.next(); |
690 |
int lineNumber = line.getLineNumber(); |
691 |
if(startLineNumber <= lineNumber |
692 |
&& lineNumber <= endLineNumber) { |
693 |
linesInRange.add(line); |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
return linesInRange; |
699 |
} |
700 |
|
689 |
/* Returns an unmodifiable set of Lines sorted by their |
701 |
/* Returns an unmodifiable set of Lines sorted by their |
690 |
* line numbers that contains all lines holded by this |
702 |
* line numbers that contains all lines holded by this |
691 |
* Line.Set. |
703 |
* Line.Set. |
Lines 714-723
Link Here
|
714 |
public Line getOriginal (int line) throws IndexOutOfBoundsException { |
726 |
public Line getOriginal (int line) throws IndexOutOfBoundsException { |
715 |
int newLine = listener.getLine (line); |
727 |
int newLine = listener.getLine (line); |
716 |
int offset = NbDocument.findLineOffset (listener.doc, newLine); |
728 |
int offset = NbDocument.findLineOffset (listener.doc, newLine); |
717 |
// System.out.println("Then: " + line + " now: " + newLine + " offset: " + offset); // NOI18N |
|
|
718 |
Line ll = registerLine (createLine (offset)); |
719 |
|
729 |
|
720 |
return ll; |
730 |
return this.registerLine(createLine(offset)); |
721 |
} |
731 |
} |
722 |
|
732 |
|
723 |
/* Creates current line. |
733 |
/* Creates current line. |
Lines 727-736
Link Here
|
727 |
*/ |
737 |
*/ |
728 |
public Line getCurrent (int line) throws IndexOutOfBoundsException { |
738 |
public Line getCurrent (int line) throws IndexOutOfBoundsException { |
729 |
int offset = NbDocument.findLineOffset (listener.doc, line); |
739 |
int offset = NbDocument.findLineOffset (listener.doc, line); |
730 |
// System.out.println("Then: " + line + " now: " + newLine + " offset: " + offset); // NOI18N |
|
|
731 |
Line ll = registerLine (createLine (offset)); |
732 |
|
740 |
|
733 |
return ll; |
741 |
return this.registerLine(createLine(offset)); |
734 |
} |
742 |
} |
735 |
|
743 |
|
736 |
/** Creates a {@link Line} for a given offset. |
744 |
/** Creates a {@link Line} for a given offset. |
Lines 739-762
Link Here
|
739 |
*/ |
747 |
*/ |
740 |
protected abstract Line createLine (int offset); |
748 |
protected abstract Line createLine (int offset); |
741 |
|
749 |
|
742 |
/** Registers the line. |
|
|
743 |
* @param l line to register |
744 |
* @return the line l or line previously registered |
745 |
*/ |
746 |
static synchronized Line registerLine (Line l) { |
747 |
Reference ref = (Reference)allLines.get (l); |
748 |
Line prev = ref == null ? null : (Line)ref.get (); |
749 |
if (prev == null) { |
750 |
if (l instanceof DocumentLine) |
751 |
((DocumentLine)l).init (); |
752 |
allLines.put (l, new WeakReference (l)); |
753 |
return l; |
754 |
} else { |
755 |
return prev; |
756 |
} |
757 |
|
758 |
|
759 |
} |
760 |
} |
750 |
} |
761 |
|
751 |
|
762 |
|
752 |
|