Inheritance diagram for LayeredCanvas::
Public Methods | |
void | clear () |
Clear the canvas, i.e. More... | |
int | getNrOfLayers () |
void | enableLayer (int layer) |
void | disableLayer (int layer) |
boolean | isEnabled (int layer) |
int | addObject (CanvasObject obj) |
int | addObject (CanvasObject obj, int index, int objID) |
This is the only function that really adds objects. More... | |
CanvasObject | getObject (int objID) |
CanvasObject | getObject (int layer, int index) |
CanvasObject | getObjectCopy (int objID, boolean ics) |
CanvasObject | getObjectCopy (int layer, int index, boolean ics) |
void | removeObject (int objID) |
void | removeObject (int layer, int index) |
void | removeAllObjects () |
int | getObjectID (CanvasObject obj) |
String[] | whichClassesAt (int layer) |
Static Public Attributes | |
final int | MIN_LAYERS = 1 |
final String | STD_CLASS = "HxJava.CanvasObject.CanvasObject" |
Protected Methods | |
boolean | declareClassAt (String className, int layer) |
int | findLayer (CanvasObject obj) |
Protected Attributes | |
int | nrOfLayers |
ObjectRepository | _repository |
Vector[] | classes |
Class | stdClass |
boolean[] | enableFlags |
|
Clear the canvas, i.e. remove all objects from the canvas and draw the background color on the entire canvas. Reimplemented in ScribbleCanvas.
00081 { 00082 drawBackground(); 00083 removeAllObjects(); 00084 } |
|
00091 { 00092 return nrOfLayers; 00093 } |
|
00097 { 00098 if (hasLayer(layer)) { 00099 enableFlags[layer] = true; 00100 } 00101 } |
|
00105 { 00106 if (hasLayer(layer)) { 00107 enableFlags[layer] = false; 00108 } 00109 } |
|
00113 { 00114 if (hasLayer(layer)) { 00115 return enableFlags[layer]; 00116 } 00117 return false; 00118 } |
|
00128 { 00129 return addObject(obj, -1, -1); 00130 } |
|
This is the only function that really adds objects. If index or objID are -1 a suited value will be determined. NOTE TO PROGRAMMERS: take care that supplying an object ID can cause multiple objects to have the same identifier! In normal situations the repository should supply the ID.
00141 { 00142 int layer; 00143 int newID = -1; 00144 00145 if ((layer = findLayer(obj)) != -1) { 00146 00147 if (obj instanceof ScribbleFigure && 00148 ((ScribbleFigure)obj).hasNoColor()) { 00149 ((ScribbleFigure)obj).setColor(getDefaultDrawColor()); 00150 } 00151 00152 // Convert the object to the current zoomFactor and add. 00153 00154 obj.setZoomFactor(getZoomFactor()); 00155 if (index < 0) { 00156 newID = _repository.add(obj, layer); 00157 } else { 00158 newID = _repository.addAt(obj, layer, index); 00159 } 00160 if (objID >= 0) { 00161 newID = objID; 00162 00163 if (index < 0) 00164 _repository.setObjectID(obj, objID); 00165 else 00166 _repository.setObjectID(layer, index, objID); 00167 00168 // To avoid loss of identifiers set back ID counter 00169 // of object repository (not necessary, though) 00170 00171 _repository.setCurID(_repository.getCurID() - 1); 00172 } 00173 00174 // Check canvas extent 00175 00176 int w = (int)(obj.getX1() + obj.getWidth() + 0.5) + EXT_MARGIN; 00177 int h = (int)(obj.getY1() + obj.getHeight() + 0.5) + EXT_MARGIN; 00178 Dimension objE = getObjectExtent(); 00179 if ((w > objE.width) || (h > objE.height)) { 00180 w = Math.max(w, objE.width); 00181 h = Math.max(h, objE.height); 00182 if (DEBUG_LAYOUT) 00183 OutputStreamArea.println("addObject (" + getID() + "): extent changed"); 00184 setObjectExtent(new Dimension(w, h)); 00185 } 00186 00187 repaint(); 00188 } 00189 return newID; 00190 } |
|
00194 { 00195 // Return the requested object as is... 00196 00197 return (_repository.get(objID)); 00198 } |
|
00202 { 00203 if (!hasLayer(layer)) { 00204 return null; 00205 } 00206 00207 // Return the requested object as is... 00208 00209 return (_repository.get(layer, index)); 00210 } |
|
00214 { 00215 // Return a copy of the requested object, after back-scaling 00216 // to the Image Coordinate System (if requested). 00217 00218 CanvasObject obj = _repository.get(objID); 00219 if (obj != null) { 00220 obj = (CanvasObject)(obj.clone()); 00221 if (ics) { 00222 obj.setZoomFactor(STD_ZOOM); 00223 } 00224 } 00225 return (obj); 00226 } |
|
00230 { 00231 if (!hasLayer(layer)) { 00232 return null; 00233 } 00234 00235 // Return a copy of the requested object, after back-scaling 00236 // to the Image Coordinate System (if requested). 00237 00238 CanvasObject obj = _repository.get(layer, index); 00239 if (obj != null) { 00240 obj = (CanvasObject)(obj.clone()); 00241 if (ics) { 00242 obj.setZoomFactor(STD_ZOOM); 00243 } 00244 } 00245 return (obj); 00246 } |
|
00250 { 00251 _repository.remove(objID); 00252 checkObjectExtentChanged(); 00253 } |
|
00257 { 00258 if (!hasLayer(layer)) { 00259 return; 00260 } 00261 _repository.remove(layer, index); 00262 checkObjectExtentChanged(); 00263 } |
|
00267 { 00268 _repository.removeAllObjects(); 00269 checkObjectExtentChanged(); 00270 } |
|
00274 { 00275 return _repository.getObjectID(obj); 00276 } |
|
|
|
00373 { 00374 Class newClass; 00375 00376 if (hasLayer(layer)) { 00377 00378 // Retrieve Class-object determined by className. 00379 00380 try { 00381 newClass = Class.forName(className); 00382 } catch (ClassNotFoundException e) { 00383 return false; 00384 } 00385 00386 // If 'newClass' is not the same class as, or a subclass 00387 // of, 'stdClass', we can not accept objects of 'newClass'. 00388 00389 if (stdClass == null || 00390 (!(stdClass.isAssignableFrom(newClass)))) { 00391 return false; 00392 } 00393 00394 // Check against all other classes declared so far. 00395 00396 for (int i=0; i < nrOfLayers; i++) { 00397 for (int j=0; j < classes[i].size(); j++) { 00398 try { 00399 Class curClass = 00400 Class.forName((String)classes[i].elementAt(j)); 00401 if (curClass.isAssignableFrom(newClass)) { 00402 return (layer == i); 00403 } 00404 if (newClass.isAssignableFrom(curClass)) { 00405 return false; 00406 } 00407 } catch (ClassNotFoundException e) { } 00408 } 00409 } 00410 classes[layer].addElement(className); 00411 return true; 00412 } 00413 return false; 00414 } |
|
00427 { 00428 for (int i=0; i < nrOfLayers; i++) { 00429 for (int j=0; j < classes[i].size(); j++) { 00430 try { 00431 if (Class.forName((String)classes[i]. 00432 elementAt(j)).isInstance(obj)) { 00433 return i; 00434 } 00435 } catch (ClassNotFoundException e) { } 00436 } 00437 } 00438 return -1; 00439 } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|