Mercurial > projects > dwt-addons
annotate dwtx/jface/text/reconciler/DirtyRegionQueue.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | f70d9508c95c |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.reconciler.DirtyRegionQueue; | |
14 | |
131 | 15 import dwtx.jface.text.reconciler.IReconciler; // packageimport |
16 import dwtx.jface.text.reconciler.IReconcilingStrategy; // packageimport | |
17 import dwtx.jface.text.reconciler.AbstractReconcileStep; // packageimport | |
18 import dwtx.jface.text.reconciler.IReconcilingStrategyExtension; // packageimport | |
19 import dwtx.jface.text.reconciler.MonoReconciler; // packageimport | |
20 import dwtx.jface.text.reconciler.IReconcileStep; // packageimport | |
21 import dwtx.jface.text.reconciler.AbstractReconciler; // packageimport | |
22 import dwtx.jface.text.reconciler.Reconciler; // packageimport | |
23 import dwtx.jface.text.reconciler.IReconcilableModel; // packageimport | |
24 import dwtx.jface.text.reconciler.DirtyRegion; // packageimport | |
25 import dwtx.jface.text.reconciler.IReconcileResult; // packageimport | |
26 import dwtx.jface.text.reconciler.IReconcilerExtension; // packageimport | |
27 | |
28 | |
129 | 29 import dwt.dwthelper.utils; |
30 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
31 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
32 |
162 | 33 import tango.core.sync.Mutex; |
34 import tango.core.sync.Condition; | |
129 | 35 |
36 /** | |
37 * Queue used by {@link dwtx.jface.text.reconciler.AbstractReconciler} to manage | |
38 * dirty regions. When a dirty region is inserted into the queue, the queue tries | |
39 * to fold it into the neighboring dirty region. | |
40 * | |
41 * @see dwtx.jface.text.reconciler.AbstractReconciler | |
42 * @see dwtx.jface.text.reconciler.DirtyRegion | |
43 */ | |
162 | 44 class DirtyRegionQueue : Mutex { |
129 | 45 |
46 /** The list of dirty regions. */ | |
162 | 47 private List fDirtyRegions; |
48 private Condition cond; | |
129 | 49 /** |
50 * Creates a new empty dirty region. | |
51 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
52 public this() { |
162 | 53 //super(); |
54 fDirtyRegions= new ArrayList(); | |
55 cond = new Condition(this); | |
56 } | |
57 | |
58 public void wait(){ | |
59 cond.wait(); | |
60 } | |
61 public void wait(int delay){ | |
62 cond.wait(delay/1000.0); | |
63 } | |
64 public void notifyAll(){ | |
65 cond.notifyAll(); | |
129 | 66 } |
67 | |
68 /** | |
69 * Adds a dirty region to the end of the dirty-region queue. | |
70 * | |
71 * @param dr the dirty region to add | |
72 */ | |
73 public void addDirtyRegion(DirtyRegion dr) { | |
74 // If the dirty region being added is directly after the last dirty | |
75 // region on the queue then merge the two dirty regions together. | |
76 DirtyRegion lastDR= getLastDirtyRegion(); | |
77 bool wasMerged= false; | |
78 if (lastDR !is null) | |
79 if (lastDR.getType() is dr.getType()) | |
80 if (lastDR.getType() is DirtyRegion.INSERT) { | |
81 if (lastDR.getOffset() + lastDR.getLength() is dr.getOffset()) { | |
82 lastDR.mergeWith(dr); | |
83 wasMerged= true; | |
84 } | |
85 } else if (lastDR.getType() is DirtyRegion.REMOVE) { | |
86 if (dr.getOffset() + dr.getLength() is lastDR.getOffset()) { | |
87 lastDR.mergeWith(dr); | |
88 wasMerged= true; | |
89 } | |
90 } | |
91 | |
92 if (!wasMerged) | |
93 // Don't merge- just add the new one onto the queue. | |
94 fDirtyRegions.add(dr); | |
95 } | |
96 | |
97 /** | |
98 * Returns the last dirty region that was added to the queue. | |
99 * | |
100 * @return the last DirtyRegion on the queue | |
101 */ | |
102 private DirtyRegion getLastDirtyRegion() { | |
103 int size= fDirtyRegions.size(); | |
134 | 104 return (size is 0 ? null : cast(DirtyRegion) fDirtyRegions.get(size - 1)); |
129 | 105 } |
106 | |
107 /** | |
108 * Returns the number of regions in the queue. | |
109 * | |
110 * @return the dirty-region queue-size | |
111 */ | |
112 public int getSize() { | |
113 return fDirtyRegions.size(); | |
114 } | |
115 | |
116 /** | |
117 * Throws away all entries in the queue. | |
118 */ | |
119 public void purgeQueue() { | |
120 fDirtyRegions.clear(); | |
121 } | |
122 | |
123 /** | |
124 * Removes and returns the first dirty region in the queue | |
125 * | |
126 * @return the next dirty region on the queue | |
127 */ | |
128 public DirtyRegion removeNextDirtyRegion() { | |
129 if (fDirtyRegions.size() is 0) | |
130 return null; | |
134 | 131 DirtyRegion dr= cast(DirtyRegion) fDirtyRegions.get(0); |
129 | 132 fDirtyRegions.remove(0); |
133 return dr; | |
134 } | |
135 } |