129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 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.DocumentPartitioningChangedEvent;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.HashMap;
|
|
18 import java.util.Iterator;
|
|
19 import java.util.Map;
|
|
20
|
|
21 import dwtx.core.runtime.Assert;
|
|
22
|
|
23 /**
|
|
24 * Event describing the change of document partitionings.
|
|
25 *
|
|
26 * @see dwtx.jface.text.IDocumentExtension3
|
|
27 * @since 3.0
|
|
28 */
|
|
29 public class DocumentPartitioningChangedEvent {
|
|
30
|
|
31 /** The document whose partitionings changed */
|
|
32 private final IDocument fDocument;
|
|
33 /** The map of partitionings to changed regions. */
|
|
34 private final Map fMap= new HashMap();
|
|
35
|
|
36
|
|
37 /**
|
|
38 * Creates a new document partitioning changed event for the given document.
|
|
39 * Initially this event is empty, i.e. does not describe any change.
|
|
40 *
|
|
41 * @param document the changed document
|
|
42 */
|
|
43 public DocumentPartitioningChangedEvent(IDocument document) {
|
|
44 fDocument= document;
|
|
45 }
|
|
46
|
|
47 /**
|
|
48 * Returns the changed document.
|
|
49 *
|
|
50 * @return the changed document
|
|
51 */
|
|
52 public IDocument getDocument() {
|
|
53 return fDocument;
|
|
54 }
|
|
55
|
|
56 /**
|
|
57 * Returns the changed region of the given partitioning or <code>null</code>
|
|
58 * if the given partitioning did not change.
|
|
59 *
|
|
60 * @param partitioning the partitioning
|
|
61 * @return the changed region of the given partitioning or <code>null</code>
|
|
62 */
|
|
63 public IRegion getChangedRegion(String partitioning) {
|
|
64 return (IRegion) fMap.get(partitioning);
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * Returns the set of changed partitionings.
|
|
69 *
|
|
70 * @return the set of changed partitionings
|
|
71 */
|
|
72 public String[] getChangedPartitionings() {
|
|
73 String[] partitionings= new String[fMap.size()];
|
|
74 fMap.keySet().toArray(partitionings);
|
|
75 return partitionings;
|
|
76 }
|
|
77
|
|
78 /**
|
|
79 * Sets the specified range as changed region for the given partitioning.
|
|
80 *
|
|
81 * @param partitioning the partitioning
|
|
82 * @param offset the region offset
|
|
83 * @param length the region length
|
|
84 */
|
|
85 public void setPartitionChange(String partitioning, int offset, int length) {
|
|
86 Assert.isNotNull(partitioning);
|
|
87 fMap.put(partitioning, new Region(offset, length));
|
|
88 }
|
|
89
|
|
90 /**
|
|
91 * Returns <code>true</code> if the set of changed partitionings is empty,
|
|
92 * <code>false</code> otherwise.
|
|
93 *
|
|
94 * @return <code>true</code> if the set of changed partitionings is empty
|
|
95 */
|
|
96 public bool isEmpty() {
|
|
97 return fMap.isEmpty();
|
|
98 }
|
|
99
|
|
100 /**
|
|
101 * Returns the coverage of this event. This is the minimal region that
|
|
102 * contains all changed regions of all changed partitionings.
|
|
103 *
|
|
104 * @return the coverage of this event
|
|
105 */
|
|
106 public IRegion getCoverage() {
|
|
107 if (fMap.isEmpty())
|
|
108 return new Region(0, 0);
|
|
109
|
|
110 int offset= -1;
|
|
111 int endOffset= -1;
|
|
112 Iterator e= fMap.values().iterator();
|
|
113 while (e.hasNext()) {
|
|
114 IRegion r= (IRegion) e.next();
|
|
115
|
|
116 if (offset < 0 || r.getOffset() < offset)
|
|
117 offset= r.getOffset();
|
|
118
|
|
119 int end= r.getOffset() + r.getLength();
|
|
120 if (end > endOffset)
|
|
121 endOffset= end;
|
|
122 }
|
|
123
|
|
124 return new Region(offset, endOffset - offset);
|
|
125 }
|
|
126 }
|