1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
77 */
78 public class ZoneView extends BoxView {
79
80 int maxZoneSize = 8 * 1024;
81 int maxZonesLoaded = 3;
82 Vector<View> loadedZones;
83
84 /**
85 * Constructs a ZoneView.
86 *
87 * @param elem the element this view is responsible for
88 * @param axis either View.X_AXIS or View.Y_AXIS
89 */
90 public ZoneView(Element elem, int axis) {
91 super(elem, axis);
92 loadedZones = new Vector<View>();
93 }
94
95 /**
96 * Get the current maximum zone size.
97 */
98 public int getMaximumZoneSize() {
99 return maxZoneSize;
100 }
101
102 /**
103 * Set the desired maximum zone size. A
104 * zone may get larger than this size if
105 * a single child view is larger than this
106 * size since zones are formed on child view
107 * boundaries.
108 *
109 * @param size the number of characters the zone
110 * may represent before attempting to break
111 * the zone into a smaller size.
112 */
113 public void setMaximumZoneSize(int size) {
114 maxZoneSize = size;
115 }
116
117 /**
118 * Get the current setting of the number of zones
119 * allowed to be loaded at the same time.
120 */
121 public int getMaxZonesLoaded() {
122 return maxZonesLoaded;
123 }
124
125 /**
126 * Sets the current setting of the number of zones
127 * allowed to be loaded at the same time. This will throw an
128 * <code>IllegalArgumentException</code> if <code>mzl</code> is less
129 * than 1.
130 *
131 * @param mzl the desired maximum number of zones
132 * to be actively loaded, must be greater than 0
133 * @exception IllegalArgumentException if <code>mzl</code> is < 1
134 */
135 public void setMaxZonesLoaded(int mzl) {
136 if (mzl < 1) {
137 throw new IllegalArgumentException("ZoneView.setMaxZonesLoaded must be greater than 0.");
138 }
139 maxZonesLoaded = mzl;
167 * Unload a zone (Convert the zone to its memory saving state).
168 * The zones are expected to represent a subset of the
169 * child elements of the element this view is responsible for.
170 * Therefore, the default implementation is to simple remove
171 * all the children.
172 *
173 * @param zone the child view desired to be set to an
174 * unloaded state.
175 */
176 protected void unloadZone(View zone) {
177 //System.out.println("unloading: " + zone.getStartOffset() + "," + zone.getEndOffset());
178 zone.removeAll();
179 }
180
181 /**
182 * Determine if a zone is in the loaded state.
183 * The zones are expected to represent a subset of the
184 * child elements of the element this view is responsible for.
185 * Therefore, the default implementation is to return
186 * true if the view has children.
187 */
188 protected boolean isZoneLoaded(View zone) {
189 return (zone.getViewCount() > 0);
190 }
191
192 /**
193 * Create a view to represent a zone for the given
194 * range within the model (which should be within
195 * the range of this objects responsibility). This
196 * is called by the zone management logic to create
197 * new zones. Subclasses can provide a different
198 * implementation for a zone by changing this method.
199 *
200 * @param p0 the start of the desired zone. This should
201 * be >= getStartOffset() and < getEndOffset(). This
202 * value should also be < p1.
203 * @param p1 the end of the desired zone. This should
204 * be > getStartOffset() and <= getEndOffset(). This
205 * value should also be > p0.
206 */
207 protected View createZone(int p0, int p1) {
208 Document doc = getDocument();
209 View zone;
210 try {
211 zone = new Zone(getElement(),
212 doc.createPosition(p0),
213 doc.createPosition(p1));
214 } catch (BadLocationException ble) {
215 // this should puke in some way.
216 throw new StateInvariantError(ble.getMessage());
217 }
218 return zone;
219 }
220
221 /**
222 * Loads all of the children to initialize the view.
223 * This is called by the <code>setParent</code> method.
224 * This is reimplemented to not load any children directly
225 * (as they are created by the zones). This method creates
|
1 /*
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
77 */
78 public class ZoneView extends BoxView {
79
80 int maxZoneSize = 8 * 1024;
81 int maxZonesLoaded = 3;
82 Vector<View> loadedZones;
83
84 /**
85 * Constructs a ZoneView.
86 *
87 * @param elem the element this view is responsible for
88 * @param axis either View.X_AXIS or View.Y_AXIS
89 */
90 public ZoneView(Element elem, int axis) {
91 super(elem, axis);
92 loadedZones = new Vector<View>();
93 }
94
95 /**
96 * Get the current maximum zone size.
97 * @return the current maximum zone size
98 */
99 public int getMaximumZoneSize() {
100 return maxZoneSize;
101 }
102
103 /**
104 * Set the desired maximum zone size. A
105 * zone may get larger than this size if
106 * a single child view is larger than this
107 * size since zones are formed on child view
108 * boundaries.
109 *
110 * @param size the number of characters the zone
111 * may represent before attempting to break
112 * the zone into a smaller size.
113 */
114 public void setMaximumZoneSize(int size) {
115 maxZoneSize = size;
116 }
117
118 /**
119 * Get the current setting of the number of zones
120 * allowed to be loaded at the same time.
121 * @return current setting of the number of zones
122 * allowed to be loaded at the same time
123 */
124 public int getMaxZonesLoaded() {
125 return maxZonesLoaded;
126 }
127
128 /**
129 * Sets the current setting of the number of zones
130 * allowed to be loaded at the same time. This will throw an
131 * <code>IllegalArgumentException</code> if <code>mzl</code> is less
132 * than 1.
133 *
134 * @param mzl the desired maximum number of zones
135 * to be actively loaded, must be greater than 0
136 * @exception IllegalArgumentException if <code>mzl</code> is < 1
137 */
138 public void setMaxZonesLoaded(int mzl) {
139 if (mzl < 1) {
140 throw new IllegalArgumentException("ZoneView.setMaxZonesLoaded must be greater than 0.");
141 }
142 maxZonesLoaded = mzl;
170 * Unload a zone (Convert the zone to its memory saving state).
171 * The zones are expected to represent a subset of the
172 * child elements of the element this view is responsible for.
173 * Therefore, the default implementation is to simple remove
174 * all the children.
175 *
176 * @param zone the child view desired to be set to an
177 * unloaded state.
178 */
179 protected void unloadZone(View zone) {
180 //System.out.println("unloading: " + zone.getStartOffset() + "," + zone.getEndOffset());
181 zone.removeAll();
182 }
183
184 /**
185 * Determine if a zone is in the loaded state.
186 * The zones are expected to represent a subset of the
187 * child elements of the element this view is responsible for.
188 * Therefore, the default implementation is to return
189 * true if the view has children.
190 * param zone the child view
191 * @param zone the zone
192 * @return whether or not the zone is in the loaded state.
193 */
194 protected boolean isZoneLoaded(View zone) {
195 return (zone.getViewCount() > 0);
196 }
197
198 /**
199 * Create a view to represent a zone for the given
200 * range within the model (which should be within
201 * the range of this objects responsibility). This
202 * is called by the zone management logic to create
203 * new zones. Subclasses can provide a different
204 * implementation for a zone by changing this method.
205 *
206 * @param p0 the start of the desired zone. This should
207 * be >= getStartOffset() and < getEndOffset(). This
208 * value should also be < p1.
209 * @param p1 the end of the desired zone. This should
210 * be > getStartOffset() and <= getEndOffset(). This
211 * value should also be > p0.
212 * @return a view to represent a zone for the given range within
213 * the model
214 */
215 protected View createZone(int p0, int p1) {
216 Document doc = getDocument();
217 View zone;
218 try {
219 zone = new Zone(getElement(),
220 doc.createPosition(p0),
221 doc.createPosition(p1));
222 } catch (BadLocationException ble) {
223 // this should puke in some way.
224 throw new StateInvariantError(ble.getMessage());
225 }
226 return zone;
227 }
228
229 /**
230 * Loads all of the children to initialize the view.
231 * This is called by the <code>setParent</code> method.
232 * This is reimplemented to not load any children directly
233 * (as they are created by the zones). This method creates
|