2,2c2,2 < * @(#)CompositeFigure.java 5.2 --- > * @(#)CompositeFigure.java 3a4,9 > * Project: JHotdraw - a GUI framework for technical drawings > * http://www.jhotdraw.org > * http://jhotdraw.sourceforge.net > * Copyright: © by the original author(s) and all contributors > * License: Lesser GNU Public License (LGPL) > * http://www.opensource.org/licenses/lgpl-license.html 24a32,33 > * > * @version <$CURRENT_VERSION$> 55a65,67 > * > * @param figure to be added to the drawing > * @return the figure that was inserted (might be different from the figure specified). 69a83,83 > * @deprecated use addAll(FigureEnumeration) instead 71a86,98 > addAll(new FigureEnumerator(newFigures)); > } > > /** > * Adds a FigureEnumeration of figures. > * > * @see #add > * @param fe (unused) enumeration containing all figures to be added > */ > public void addAll(FigureEnumeration fe) { > while (fe.hasMoreElements()) { > add(fe.nextFigure()); > } 72,74d85 < Enumeration k = newFigures.elements(); < while (k.hasMoreElements()) < add((Figure) k.nextElement()); 78a103,105 > * > * @param figure that is part of the drawing and should be removed > * @return the figure that has been removed (might be different from the figure specified) 81a109,109 > return orphan(figure); 82,82c158,158 < if (fFigures.contains(figure)) { --- > if (fFigures.contains(figure)) { 83,83c159,159 < figure.removeFromContainer(this); --- > figure.removeFromContainer(this); 84,87d159 < fFigures.removeElement(figure); < _removeFromQuadTree(figure); < } < return figure; 92a116,116 > * @deprecated use removeAll(FigureEnumeration) instead 94a119,129 > removeAll(new FigureEnumerator(figures)); > > } > > /** > * Removes a FigureEnumeration of figures. > * @see #remove > */ > public void removeAll(FigureEnumeration fe) { > while (fe.hasMoreElements()) { > remove(fe.nextFigure()); 95,97d118 < Enumeration k = figures.elements(); < while (k.hasMoreElements()) { < remove((Figure) k.nextElement()); 106,106c138,138 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 107,107c139,139 < while (k.hasMoreElements()) { --- > while (fe.hasMoreElements()) { 108,108c140,140 < Figure figure = k.nextFigure(); --- > Figure figure = fe.nextFigure(); 121a154,155 > * > * @param figure that is part of the drawing and should be added 132a171,171 > * @deprecated use orphanAll(FigureEnumeration) instead 134a174,180 > orphanAll(new FigureEnumerator(newFigures)); > } > > public void orphanAll(FigureEnumeration fe) { > while (fe.hasMoreElements()) { > orphan(fe.nextFigure()); > } 135,137d173 < Enumeration k = newFigures.elements(); < while (k.hasMoreElements()) < orphan((Figure) k.nextElement()); 142a186,189 > * > * @param figure figure to be replaced > * @param replacement figure that should replace the specified figure > * @return the figure that has been inserted (might be different from the figure specified) 144,144c191,191 < public synchronized void replace(Figure figure, Figure replacement) { --- > public synchronized Figure replace(Figure figure, Figure replacement) { 148a196,196 > figure.removeFromContainer(this); 149a199,199 > replacement.changed(); 149,149c198,198 < figure.changed(); --- > figure.changed(); 151a201,201 > return replacement; 155a206,207 > * > * @param figure that is part of the drawing 160a213,213 > _nLowestZ--; 161,161c214,214 < figure.setZValue(--_nLowestZ); --- > figure.setZValue(_nLowestZ); 167a221,222 > * > * @param figure that is part of the drawing 172a228,228 > _nHighestZ++; 173,173c229,229 < figure.setZValue(++_nHighestZ); --- > figure.setZValue(_nHighestZ); 178a235,352 > * Sends a figure to a certain layer within a drawing. Each figure > * lays in a unique layer and the layering order decides which > * figure is drawn on top of another figure. Figures with a higher > * layer number have usually been added later and may overlay > * figures in lower layers. Layers are counted from to (the number > * of figures - 1). > * The figure is removed from its current layer (if it has been already > * part of this drawing) and is transferred to the specified layers after > * all figures between the original layer and the new layer are shifted to > * one layer below to fill the layer sequence. It is not possible to skip a > * layer number and if the figure is sent to a layer beyond the latest layer > * it will be added as the last figure to the drawing and its layer number > * will be set to the be the one beyond the latest layer so far. > * > * @param figure figure to be sent to a certain layer > * @param layerNr target layer of the figure > */ > public void sendToLayer(Figure figure, int layerNr) { > if (fFigures.contains(figure)) { > if (layerNr >= fFigures.size()) { > System.out.println("original layerNr: " + layerNr); > layerNr = fFigures.size() - 1; > } > Figure layerFigure = getFigureFromLayer(layerNr); > int layerFigureZValue = layerFigure.getZValue(); > int figureLayer = getLayer(figure); > // move figure forward > System.out.println("figureLayer: "+figureLayer + " layerNr: " + layerNr); > if (figureLayer < layerNr) { > assignFiguresToPredecessorZValue(figureLayer + 1, layerNr); > } > else if (figureLayer > layerNr) { > assignFiguresToSuccessorZValue(layerNr, figureLayer - 1); > } > > fFigures.removeElement(figure); > fFigures.insertElementAt(figure, layerNr); > figure.setZValue(layerFigureZValue); > figure.changed(); > System.out.println("figureLayer(2): "+ figure.getZValue()); > } > } > > private void assignFiguresToPredecessorZValue(int lowerBound, int upperBound) { > // cannot shift figures to a lower layer if the lower bound is > // already the first layer. > /* > if (lowerBound <= 0) { > return; > } > > if (upperBound >= fFigures.size()) { > upperBound = fFigures.size() - 1; > } > > for (int i = lowerBound; i <= upperBound; i++) { > */ > if (upperBound >= fFigures.size()) { > upperBound = fFigures.size() - 1; > } > > for (int i = upperBound; i >= lowerBound; i--) { > Figure currentFigure = (Figure)fFigures.elementAt(i); > Figure predecessorFigure = (Figure)fFigures.elementAt(i - 1); > System.out.println("AssignPredeccessor " + i + " -> " + (i-1) + " with z: " + currentFigure.getZValue() + " -> " + predecessorFigure.getZValue()); > currentFigure.setZValue(predecessorFigure.getZValue()); > } > } > > private void assignFiguresToSuccessorZValue(int lowerBound, int upperBound) { > if (upperBound >= fFigures.size()) { > upperBound = fFigures.size() - 1; > } > > for (int i = upperBound; i >= lowerBound; i--) { > Figure currentFigure = (Figure)fFigures.elementAt(i); > Figure successorFigure = (Figure)fFigures.elementAt(i + 1); > System.out.println("AssignSuccessor " + i + " -> " + (i+1) + " with z: " + currentFigure.getZValue() + " -> " + successorFigure.getZValue()); > currentFigure.setZValue(successorFigure.getZValue()); > } > } > > /** > * Gets the layer for a certain figure (first occurrence). The number > * returned is the number of the layer in which the figure is placed. > * > * @param figure figure to be queried for its layering place > * @return number of the layer in which the figure is placed and -1 if the > * figure could not be found. > * @see #sendToLayer > */ > public int getLayer(Figure figure) { > if (!fFigures.contains(figure)) { > return -1; > } > else { > return fFigures.indexOf(figure); > } > } > > /** > * Gets the figure from a certain layer. > * > * @param layerNr number of the layer which figure should be returned > * @return figure from the layer specified, null, if the layer nr was outside > * the number of possible layer (0...(number of figures - 1)) > * @see #sendToLayer > */ > public Figure getFigureFromLayer(int layerNr) { > if ((layerNr >= 0) && (layerNr < fFigures.size())) { > return (Figure)fFigures.elementAt(layerNr); > } > else { > return null; > } > } > > /** 183,183c357,357 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 184,184c358,358 < while (k.hasMoreElements()) --- > while (fe.hasMoreElements()) { 185,185c359,359 < k.nextFigure().draw(g); --- > fe.nextFigure().draw(g); 185a360,360 > } 193,193c368,368 < while (fe.hasMoreElements()) --- > while (fe.hasMoreElements()) { 195a371,371 > } 209,209c385,385 < return new FigureEnumerator(fFigures); --- > return new FigureEnumerator((Vector)fFigures.clone()); 217,217c393,393 < public FigureEnumeration figures(Rectangle --- > public FigureEnumeration figures(Rectangle viewRectangle) { 218,219d393 < viewRectangle) { < 243a30,30 > * 244,244d29 < 247a81,81 > * 248,248d80 < 263,263c435,435 < return new ReverseFigureEnumerator(fFigures); --- > return new ReverseFigureEnumerator((Vector)fFigures.clone()); 274,274c446,446 < if (figure.containsPoint(x, y)) --- > if (figure.containsPoint(x, y)) { 276a449,449 > } 288,288c461,461 < if (r.intersects(fr)) --- > if (r.intersects(fr)) { 290a464,464 > } 309,309c483,483 < if (figure.containsPoint(x, y) && !figure.includes(without)) --- > if (figure.containsPoint(x, y) && !figure.includes(without)) { 311a486,486 > } 328,328c503,503 < if (r.intersects(fr) && !figure.includes(without)) --- > if (r.intersects(fr) && !figure.includes(without)) { 330a506,506 > } 344,344c520,520 < if (figure != null) --- > if (figure != null) { 346a523,523 > } 362,362c539,539 < if (found != null) --- > if (found != null) { 365a543,543 > } 371a550,550 > * @return true if the figure is part of this CompositeFigure, else otherwise 374,374c553,553 < if (super.includes(figure)) --- > if (super.includes(figure)) { 375a555,555 > } 377,377c557,557 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 378,378c558,558 < while (k.hasMoreElements()) { --- > while (fe.hasMoreElements()) { 379,379c559,559 < Figure f = k.nextFigure(); --- > Figure f = fe.nextFigure(); 380,380c560,560 < if (f.includes(figure)) --- > if (f.includes(figure)) { 382a563,563 > } 393a575,575 > while (fe.hasMoreElements()) { 393,393c574,574 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 394,394d574 < while (k.hasMoreElements()) 395,395c576,576 < k.nextFigure().moveBy(x,y); --- > fe.nextFigure().moveBy(x,y); 395a577,577 > } 403,403c585,585 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 404,404c586,586 < while (k.hasMoreElements()) { --- > while (fe.hasMoreElements()) { 405,405c587,587 < Figure figure = k.nextFigure(); --- > Figure figure = fe.nextFigure(); 415,415c597,597 < if (listener() != null) --- > if (listener() != null) { 417a600,600 > } 424,424c607,607 < if (listener() != null) --- > if (listener() != null) { 426a610,610 > } 433,433c617,617 < if (listener() != null) --- > if (listener() != null) { 435a620,620 > } 449a635,639 > dw.writeInt(figureCount()); > FigureEnumeration fe = figures(); > while (fe.hasMoreElements()) { > dw.writeStorable(fe.nextFigure()); > } 450,453d634 < dw.writeInt(fFigures.size()); < Enumeration k = fFigures.elements(); < while (k.hasMoreElements()) < dw.writeStorable((Storable) k.nextElement()); 463,463c649,649 < for (int i=0; i for (int i=0; i } 472,472c659,659 < FigureEnumeration k = figures(); --- > FigureEnumeration fe = figures(); 473,473c660,660 < while (k.hasMoreElements()) { --- > while (fe.hasMoreElements()) { 474,474c661,661 < Figure figure = k.nextFigure(); --- > Figure figure = fe.nextFigure(); 492a680,682 > FigureEnumeration fe = figures(); > while (fe.hasMoreElements()) { > _addToQuadTree(fe.nextFigure()); 493,495d679 < for(Enumeration e=fFigures.elements(); e.hasMoreElements(); ) { < Figure f = (Figure) e.nextElement(); < _addToQuadTree(f); 496a114,114 > * 497,497d113 < 503a162,162 > } 504,504d161 < 510a169,169 > * 511,511d168 <