KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > ComponentDragger


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form;
21
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.awt.geom.*;
25 import javax.swing.*;
26 import javax.swing.undo.*;
27 import java.util.*;
28 import java.util.List JavaDoc;
29
30 import org.netbeans.modules.form.layoutsupport.*;
31
32 /**
33  *
34  * @author Tran Duc Trung
35  */

36
37 class ComponentDragger
38 {
39     private FormDesigner formDesigner;
40     private HandleLayer handleLayer;
41     private RADVisualComponent[] selectedComponents;
42     private Rectangle[] originalBounds; // in HandleLayer coordinates
43
private Point hotspot; // in HandleLayer coordinates
44
private Point mousePosition;
45     private int resizeType;
46
47     private RADVisualContainer targetMetaContainer;
48
49     private Container targetContainer;
50     private Container targetContainerDel;
51
52     static Stroke dashedStroke1 = new BasicStroke((float) 2.0,
53                                       BasicStroke.CAP_SQUARE,
54                                       BasicStroke.JOIN_MITER,
55                                       (float) 10.0,
56                                       new float[] { (float) 1.0, (float) 4.0 },
57                                       0);
58
59     static Stroke dashedStroke2 = new BasicStroke(
60                                       (float) 2.0,
61                                       BasicStroke.CAP_SQUARE,
62                                       BasicStroke.JOIN_MITER,
63                                       (float) 10.0,
64                                       new float[] { (float) 2.0, (float) 8.0 },
65                                       0);
66
67     /** The FormLoaderSettings instance */
68     // constructor for dragging
69
ComponentDragger(FormDesigner formDesigner,
70                      HandleLayer handleLayer,
71                      RADVisualComponent[] selectedComponents,
72                      Rectangle[] originalBounds,
73                      Point hotspot,
74                      RADVisualContainer fixedTargetMetaContainer)
75     {
76         this.formDesigner = formDesigner;
77         this.handleLayer = handleLayer;
78         this.selectedComponents = selectedComponents;
79         this.originalBounds = originalBounds;
80         this.hotspot = hotspot;
81         this.mousePosition = hotspot;
82         this.resizeType = 0;
83
84         if (fixedTargetMetaContainer != null) {
85             targetMetaContainer = fixedTargetMetaContainer;
86         }
87     }
88
89     // constructor for resizing
90
ComponentDragger(FormDesigner formDesigner,
91                      HandleLayer handleLayer,
92                      RADVisualComponent[] selectedComponents,
93                      Rectangle[] originalBounds,
94                      Point hotspot,
95                      int resizeType)
96     {
97         this.formDesigner = formDesigner;
98         this.handleLayer = handleLayer;
99         this.selectedComponents = selectedComponents;
100         this.originalBounds = originalBounds;
101         this.hotspot = hotspot;
102         this.mousePosition = hotspot;
103         this.resizeType = resizeType;
104     }
105
106     void drag(Point p, RADVisualContainer target) {
107         targetMetaContainer = target;
108         mousePosition = p;
109     }
110
111     void paintDragFeedback(Graphics2D g) {
112         Stroke oldStroke = g.getStroke();
113         g.setStroke(dashedStroke1);
114
115         Color oldColor = g.getColor();
116         g.setColor(FormLoaderSettings.getInstance().getSelectionBorderColor());
117
118         List JavaDoc constraints = new ArrayList(selectedComponents.length);
119         List JavaDoc indices = new ArrayList(selectedComponents.length);
120
121         boolean constraintsOK = computeConstraints(mousePosition,
122                                                    constraints, indices);
123
124         Point contPos = null;
125         LayoutSupportManager layoutSupport = null;
126         if (constraintsOK) {
127             contPos = SwingUtilities.convertPoint(targetContainerDel, 0, 0, handleLayer);
128             layoutSupport = targetMetaContainer.getLayoutSupport();
129             if (resizeType == 0)
130                 paintTargetContainerFeedback(g, targetContainerDel);
131         }
132
133         for (int i = 0; i < selectedComponents.length; i++) {
134             RADVisualComponent metacomp = selectedComponents[i];
135             boolean drawn = false;
136
137             if (constraintsOK) {
138                 Component comp = (Component) formDesigner.getComponent(metacomp);
139                 LayoutConstraints constr = (LayoutConstraints) constraints.get(i);
140                 int index = ((Integer JavaDoc)indices.get(i)).intValue();
141
142                 if (constr != null || index >= 0) {
143                     g.translate(contPos.x, contPos.y);
144                     drawn = layoutSupport.paintDragFeedback(
145                                 targetContainer, targetContainerDel,
146                                 comp, constr, index, g);
147                     g.translate(- contPos.x, - contPos.y);
148                 }
149 // else continue;
150
}
151
152             if (!drawn)
153                 paintDragFeedback(g, metacomp);
154         }
155
156         g.setColor(oldColor);
157         g.setStroke(oldStroke);
158     }
159
160     void dropComponents(Point point, RADVisualContainer target) {
161         List JavaDoc constraints = null; // constraints of the dragged components
162
List JavaDoc indices = null; // indices of the dragged components
163

164         targetMetaContainer = target;
165         if (targetMetaContainer != null) {
166             constraints = new ArrayList(selectedComponents.length);
167             indices = new ArrayList(selectedComponents.length);
168             computeConstraints(point, constraints, indices);
169         }
170         if (targetMetaContainer == null) {
171 // if (handleLayer.mouseOnVisual(point)) {
172
// return;
173
// }
174
constraints = indices = null;
175         }
176
177         FormModel formModel = formDesigner.getFormModel();
178
179         // LayoutSupportManager of the target container
180
LayoutSupportManager layoutSupport = null;
181         // original components in the target container
182
RADVisualComponent[] originalComponents = null;
183         LayoutConstraints[] originalConstraints = null;
184         // components moved from other containers
185
List JavaDoc movedFromOutside = null;
186         // components moved within the target container
187
List JavaDoc movedWithinTarget = null;
188
189         if (targetMetaContainer != null) { // target is a visual container
190
layoutSupport = targetMetaContainer.getLayoutSupport();
191             originalComponents = targetMetaContainer.getSubComponents();
192             originalConstraints =
193                 new LayoutConstraints[originalComponents.length];
194
195             // adjust indices considering that some of dragged components
196
// might be already in target container
197
adjustIndices(indices);
198
199             // collect components being dragged from other containers
200
for (int i=0; i < selectedComponents.length; i++) {
201                 if (selectedComponents[i].getParentContainer()
202                         != targetMetaContainer)
203                 {
204                     if (movedFromOutside == null)
205                         movedFromOutside = new ArrayList(selectedComponents.length);
206                     movedFromOutside.add(new Integer JavaDoc(i)); // remember index
207
}
208                 else {
209                     if (movedWithinTarget == null)
210                         movedWithinTarget = new ArrayList(selectedComponents.length);
211                     movedWithinTarget.add(selectedComponents[i]);
212                 }
213             }
214
215             // test whether target container accepts new components (dragged
216
// from other containers)
217
if (movedFromOutside != null && movedFromOutside.size() > 0) {
218                 int count = movedFromOutside.size();
219                 RADVisualComponent[] newComps = new RADVisualComponent[count];
220                 LayoutConstraints[] newConstr = new LayoutConstraints[count];
221
222                 for (int i=0; i < count; i++) {
223                     int index = ((Integer JavaDoc)movedFromOutside.get(i)).intValue();
224                     newComps[i] = selectedComponents[index];
225                     newConstr[i] = (LayoutConstraints) constraints.get(index);
226                 }
227
228                 // j - index to selectedComponents for the first new component
229
int j = ((Integer JavaDoc)movedFromOutside.get(0)).intValue();
230                 // jj - insertion point of the first component in target container
231
int jj = ((Integer JavaDoc)indices.get(j)).intValue();
232
233                 try {
234                     layoutSupport.acceptNewComponents(newComps, newConstr, jj);
235                 }
236                 catch (RuntimeException JavaDoc ex) {
237                     // layout support does not accept components
238
org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
239                     return;
240                 }
241
242                 // layout support might adjust the constraints
243
for (int i=0; i < count; i++) {
244                     int index = ((Integer JavaDoc)movedFromOutside.get(i)).intValue();
245                     constraints.set(index, newConstr[i]);
246                 }
247
248                 movedFromOutside.clear(); // for later use
249
}
250         }
251
252         // create list of components and constraints for target container
253
int n = selectedComponents.length
254                 + (originalComponents != null ? originalComponents.length : 0);
255         List JavaDoc newComponents = new ArrayList(n);
256         List JavaDoc newConstraints = new ArrayList(n);
257         int newI = 0;
258
259         // fill enough empty space
260
for (int i=0; i < n; i++) {
261             newComponents.add(null);
262             newConstraints.add(null);
263         }
264
265         if (targetMetaContainer != null) {
266             // add dragged components requiring exact position (index)
267
for (int i=0; i < selectedComponents.length; i++) {
268                 int index = ((Integer JavaDoc)indices.get(i)).intValue();
269                 if (index >= 0 && index < n && checkTarget(selectedComponents[i])) {
270                     while (newComponents.get(index) != null) // ensure free index
271
if (++index == n)
272                             index = 0;
273
274                     newComponents.set(index, selectedComponents[i]);
275                 }
276             }
277
278             // add all components being already in the target container
279
for (int i=0; i < originalComponents.length; i++) {
280                 RADVisualComponent metacomp = originalComponents[i];
281                 originalConstraints[i] = layoutSupport.getConstraints(metacomp);
282
283                 int index = newComponents.indexOf(metacomp);
284                 if (index < 0) { // not yet in newComponents
285
while (newComponents.get(newI) != null) // ensure free index
286
newI++;
287
288                     newComponents.set(newI, metacomp);
289                     newConstraints.set(newI, originalConstraints[i]);
290                 }
291             }
292         }
293
294         // add the rest of dragged components (driven by constraints typically)
295
for (int i=0; i < selectedComponents.length; i++) {
296             RADVisualComponent metacomp = selectedComponents[i];
297             int index = newComponents.indexOf(metacomp);
298             if (index >= 0) { // already in newComponents
299
newConstraints.set(index, constraints != null ?
300                                               constraints.get(i) : null);
301             }
302             else if (checkTarget(metacomp)) { // not yet in newComponents
303
while (newComponents.get(newI) != null) // ensure free index
304
newI++;
305
306                 newComponents.set(newI, metacomp);
307                 newConstraints.set(newI, constraints != null ?
308                                              constraints.get(i) : null);
309             }
310         }
311         // now we have lists of components and constraints in right order
312

313         // remove components from source containers
314
for (int i=0; i < n; i++) {
315             RADVisualComponent metacomp = (RADVisualComponent) newComponents.get(i);
316             if (metacomp != null) {
317                 RADVisualContainer parentCont = metacomp.getParentContainer();
318                 if (parentCont != targetMetaContainer) {
319                     if (movedFromOutside == null)
320                         movedFromOutside = new ArrayList(selectedComponents.length);
321                     movedFromOutside.add(metacomp);
322
323                     formModel.removeComponent(metacomp, false);
324                 }
325             }
326             else { // remove empty space
327
newComponents.remove(i);
328                 newConstraints.remove(i);
329                 i--;
330                 n--;
331             }
332         }
333
334         if (n == 0)
335             return; // dragging not allowed
336

337         // turn off undo/redo monitoring in FormModel as we provide our own
338
// undoable edit for the rest (adding part) of the operation
339
boolean undoRedoOn = formModel.isUndoRedoRecording();
340         if (undoRedoOn)
341             formModel.setUndoRedoRecording(false);
342
343         // prepare arrays of components and constraints (from lists)
344
RADVisualComponent[] newCompsArray = new RADVisualComponent[n];
345         LayoutConstraints[] newConstrArray = new LayoutConstraints[n];
346         
347         if (targetMetaContainer != null) { // target is a visual container
348
for (int i=0; i < n; i++) {
349                 newCompsArray[i] = (RADVisualComponent) newComponents.get(i);
350                 newConstrArray[i] = (LayoutConstraints) newConstraints.get(i);
351             }
352
353             // clear the target layout
354
layoutSupport.removeAll();
355
356             // add all components to the target container
357
targetMetaContainer.initSubComponents(newCompsArray);
358             layoutSupport.addComponents(newCompsArray, newConstrArray, 0);
359         }
360         else { // no visual target, add the components to Other Components
361
ComponentContainer othersMetaCont = formModel.getModelContainer();
362             for (int i=0; i < n; i++) {
363                 newCompsArray[i] = (RADVisualComponent) newComponents.get(i);
364                 othersMetaCont.add(newCompsArray[i]);
365             }
366         }
367
368         // fire changes - adding new components
369
RADVisualComponent[] compsMovedFromOutside;
370         if (movedFromOutside != null) {
371             n = movedFromOutside.size();
372             compsMovedFromOutside = new RADVisualComponent[n];
373             for (int i=0; i < n; i++) {
374                 compsMovedFromOutside[i] = (RADVisualComponent)
375                                            movedFromOutside.get(i);
376                 formModel.fireComponentAdded(compsMovedFromOutside[i], false);
377             }
378         }
379         else {
380             compsMovedFromOutside = new RADVisualComponent[0];
381             formModel.fireComponentsReordered(targetMetaContainer, new int[0]);
382         }
383
384         // fire changes - changing components layout
385
RADVisualComponent[] compsMovedWithinTarget;
386         if (movedWithinTarget != null) {
387             n = movedWithinTarget.size();
388             compsMovedWithinTarget = new RADVisualComponent[n];
389             for (int i=0; i < n; i++) {
390                 compsMovedWithinTarget[i] = (RADVisualComponent)
391                                             movedWithinTarget.get(i);
392                 formModel.fireComponentLayoutChanged(compsMovedWithinTarget[i],
393                                                      null, null, null);
394             }
395         }
396         else compsMovedWithinTarget = new RADVisualComponent[0];
397
398         // setup undoable edit
399
if (undoRedoOn) {
400             DropUndoableEdit dropUndo = new DropUndoableEdit();
401             dropUndo.formModel = formModel;
402             dropUndo.targetContainer = targetMetaContainer;
403             dropUndo.targetComponentsBeforeMove = originalComponents;
404             dropUndo.targetConstraintsBeforeMove = originalConstraints;
405             dropUndo.targetComponentsAfterMove = newCompsArray;
406             dropUndo.targetConstraintsAfterMove = newConstrArray;
407             dropUndo.componentsMovedFromOutside = compsMovedFromOutside;
408             dropUndo.componentsMovedWithinTarget = compsMovedWithinTarget;
409
410             formModel.addUndoableEdit(dropUndo);
411         }
412
413         // finish undoable edit
414
if (undoRedoOn) // turn on undo/redo monitoring again
415
formModel.setUndoRedoRecording(true);
416
417 // formDesigner.clearSelection(); // Issue 64342
418
// select dropped components in designer (after everything updates)
419
SwingUtilities.invokeLater(new Runnable JavaDoc() {
420             public void run() {
421                 formDesigner.setSelectedComponents(selectedComponents);
422             }
423         });
424     }
425
426     // ------------
427

428     private boolean computeConstraints(Point p, List JavaDoc constraints, List JavaDoc indices) {
429         if (selectedComponents == null || selectedComponents.length == 0)
430             return false;
431
432         if (targetMetaContainer == null)
433             return false; // unknown meta-container
434

435         RADVisualContainer fixTargetContainer = null;
436         do {
437             if (fixTargetContainer != null) {
438                 targetMetaContainer = fixTargetContainer;
439                 fixTargetContainer = null;
440             }
441
442             LayoutSupportManager layoutSupport = targetMetaContainer.getLayoutSupport();
443 // if (layoutSupport == null)
444
// return false; // no LayoutSupport (should not happen)
445

446             targetContainer = (Container) formDesigner.getComponent(targetMetaContainer);
447             if (targetContainer == null)
448                 return false; // container not in designer (should not happen)
449

450             targetContainerDel = targetMetaContainer.getContainerDelegate(targetContainer);
451             if (targetContainerDel == null)
452                 return false; // no container delegate (should not happen)
453

454             Point posInCont = SwingUtilities.convertPoint(handleLayer, p, targetContainerDel);
455
456             for (int i = 0; i < selectedComponents.length; i++) {
457                 LayoutConstraints constr = null;
458                 int index = -1;
459
460                 RADVisualComponent metacomp = selectedComponents[i];
461                 Component comp = (Component) formDesigner.getComponent(metacomp);
462
463                 if (comp != null) {
464                     if (!checkTarget(metacomp)) {
465                         fixTargetContainer = metacomp.getParentContainer();
466                         constraints.clear();
467                         indices.clear();
468                         if (fixTargetContainer == null)
469                             return false; // should not happen
470
break;
471                     }
472
473                     if (resizeType == 0) { // dragging
474
Point posInComp = new Point(hotspot.x - originalBounds[i].x,
475                                                     hotspot.y - originalBounds[i].y);
476                         index = layoutSupport.getNewIndex(
477                                     targetContainer, targetContainerDel,
478                                     comp, metacomp.getComponentIndex(),
479                                     posInCont, posInComp);
480                         constr = layoutSupport.getNewConstraints(
481                                     targetContainer, targetContainerDel,
482                                     comp, metacomp.getComponentIndex(),
483                                     posInCont, posInComp);
484
485                         if (constr == null && index >= 0) {
486                             // keep old constraints (if compatible)
487
LayoutSupportManager.storeConstraints(metacomp);
488                             constr = layoutSupport.getStoredConstraints(metacomp);
489                         }
490                     }
491                     else { // resizing
492
int up = 0, down = 0, left = 0, right = 0;
493
494                         if ((resizeType & LayoutSupportManager.RESIZE_DOWN) != 0)
495                             down = p.y - hotspot.y;
496                         else if ((resizeType & LayoutSupportManager.RESIZE_UP) != 0)
497                             up = hotspot.y - p.y;
498                         if ((resizeType & LayoutSupportManager.RESIZE_RIGHT) != 0)
499                             right = p.x - hotspot.x;
500                         else if ((resizeType & LayoutSupportManager.RESIZE_LEFT) != 0)
501                             left = hotspot.x - p.x;
502
503                         Insets sizeChanges = new Insets(up, left, down, right);
504                         constr = layoutSupport.getResizedConstraints(
505                                      targetContainer, targetContainerDel,
506                                      comp, metacomp.getComponentIndex(),
507                                      handleLayer.convertRectangleToComponent(new Rectangle(originalBounds[i]), targetContainerDel),
508                                      sizeChanges, posInCont);
509                     }
510                 }
511
512                 constraints.add(constr);
513                 indices.add(new Integer JavaDoc(index));
514             }
515         }
516         while (fixTargetContainer != null);
517
518         return true;
519     }
520
521     /** Checks whether metacomp is not a parent of target container (or the
522      * target container itself). Used to avoid dragging to a sub-tree.
523      * @return true if metacomp is OK
524      */

525     private boolean checkTarget(RADVisualComponent metacomp) {
526         if (!(metacomp instanceof RADVisualContainer))
527             return true;
528
529         RADComponent targetCont = targetMetaContainer;
530         while (targetCont != null) {
531             if (targetCont == metacomp)
532                 return false;
533             targetCont = targetCont.getParentComponent();
534         }
535
536         return true;
537     }
538
539     /** Modifies suggested indices of dragged components considering the fact
540      * that some of the components might be in the target container.
541      */

542     private void adjustIndices(List JavaDoc indices) {
543         int index;
544         int correction;
545         int prevIndex = -1;
546         int prevCorrection = 0;
547
548         for (int i=0; i < indices.size(); i++) {
549             index = ((Integer JavaDoc)indices.get(i)).intValue();
550             if (index >= 0) {
551                 if (index == prevIndex) {
552                     correction = prevCorrection;
553                 }
554                 else {
555                     correction = 0;
556                     RADVisualComponent[] targetComps =
557                                          targetMetaContainer.getSubComponents();
558                     for (int j=0; j < index; j++) {
559                         RADVisualComponent tComp = targetComps[j];
560                         boolean isSelected = false;
561                         for (int k=0; k < selectedComponents.length; k++)
562                             if (tComp == selectedComponents[k]) {
563                                 isSelected = true;
564                                 break;
565                             }
566
567                         if (isSelected)
568                             correction++;
569                     }
570                     prevIndex = index;
571                     prevCorrection = correction;
572                 }
573
574                 if (correction != 0) {
575                     index -= correction;
576                     indices.set(i, new Integer JavaDoc(index));
577                 }
578             }
579         }
580     }
581
582     private void paintDragFeedback(Graphics2D g, RADVisualComponent metacomp) {
583         Object JavaDoc comp = formDesigner.getComponent(metacomp);
584         if (!(comp instanceof Component) || !((Component)comp).isShowing())
585             return;
586
587         Component component = (Component) comp;
588
589         Rectangle rect = component.getBounds();
590         rect = SwingUtilities.convertRectangle(component.getParent(),
591                                                rect,
592                                                handleLayer);
593
594         rect.translate(mousePosition.x - hotspot.x,
595                        mousePosition.y - hotspot.y);
596         
597         g.draw(new Rectangle2D.Double(rect.x, rect.y, rect.width, rect.height));
598
599         if (metacomp instanceof RADVisualContainer) {
600             RADVisualComponent[] children =
601                 ((RADVisualContainer)metacomp).getSubComponents();
602             for (int i = 0; i < children.length; i++) {
603                 paintDragFeedback(g, children[i]);
604             }
605         }
606     }
607
608     private void paintTargetContainerFeedback(Graphics2D g, Container cont) {
609         Stroke oldStroke = g.getStroke();
610         g.setStroke(dashedStroke2);
611
612         Color oldColor = g.getColor();
613         g.setColor(FormLoaderSettings.getInstance().getDragBorderColor());
614         
615         Rectangle rect = new Rectangle(new Point(0,0), cont.getSize());
616         rect = SwingUtilities.convertRectangle(cont,
617                                                rect,
618                                                handleLayer);
619         g.draw(new Rectangle2D.Double(rect.x, rect.y, rect.width, rect.height));
620         g.setColor(oldColor);
621         g.setStroke(oldStroke);
622     }
623
624     // ---------
625

626     private static class DropUndoableEdit extends AbstractUndoableEdit {
627
628         FormModel formModel;
629         RADVisualContainer targetContainer;
630         RADVisualComponent[] targetComponentsBeforeMove;
631         LayoutConstraints[] targetConstraintsBeforeMove;
632         RADVisualComponent[] targetComponentsAfterMove;
633         LayoutConstraints[] targetConstraintsAfterMove;
634         RADVisualComponent[] componentsMovedFromOutside;
635         RADVisualComponent[] componentsMovedWithinTarget;
636
637         public void undo() throws CannotUndoException {
638             super.undo();
639
640             // turn off undo/redo monitoring in FormModel while undoing!
641
boolean undoRedoOn = formModel.isUndoRedoRecording();
642             if (undoRedoOn)
643                 formModel.setUndoRedoRecording(false);
644
645             for (int i=0; i < componentsMovedFromOutside.length; i++)
646                 formModel.removeComponentImpl(
647                                          componentsMovedFromOutside[i], false);
648
649             if (targetContainer != null) {
650                 LayoutSupportManager layoutSupport =
651                     targetContainer.getLayoutSupport();
652                 layoutSupport.removeAll();
653                 targetContainer.initSubComponents(targetComponentsBeforeMove);
654                 layoutSupport.addComponents(targetComponentsBeforeMove,
655                                             targetConstraintsBeforeMove,
656                                             0);
657
658                 for (int i=0; i < componentsMovedWithinTarget.length; i++)
659                     formModel.fireComponentLayoutChanged(
660                         componentsMovedWithinTarget[i], null, null, null);
661             }
662
663             if (undoRedoOn) // turn on undo/redo monitoring again
664
formModel.setUndoRedoRecording(true);
665         }
666
667         public void redo() throws CannotRedoException {
668             super.redo();
669
670             // turn off undo/redo monitoring in FormModel while redoing!
671
boolean undoRedoOn = formModel.isUndoRedoRecording();
672             if (undoRedoOn)
673                 formModel.setUndoRedoRecording(false);
674
675             if (targetContainer != null) {
676                 LayoutSupportManager layoutSupport =
677                     targetContainer.getLayoutSupport();
678                 layoutSupport.removeAll();
679                 targetContainer.initSubComponents(targetComponentsAfterMove);
680                 layoutSupport.addComponents(targetComponentsAfterMove,
681                                             targetConstraintsAfterMove,
682                                             0);
683             }
684             else {
685                 ComponentContainer othersMetaCont = formModel.getModelContainer();
686                 for (int i=0; i < targetComponentsAfterMove.length; i++)
687                     othersMetaCont.add(targetComponentsAfterMove[i]);
688             }
689
690             for (int i=0; i < componentsMovedFromOutside.length; i++)
691                 formModel.fireComponentAdded(componentsMovedFromOutside[i],
692                                              false);
693
694             for (int i=0; i < componentsMovedWithinTarget.length; i++)
695                 formModel.fireComponentLayoutChanged(
696                     componentsMovedWithinTarget[i], null, null, null);
697
698             if (undoRedoOn) // turn on undo/redo monitoring again
699
formModel.setUndoRedoRecording(true);
700         }
701
702         public String JavaDoc getUndoPresentationName() {
703             return ""; // NOI18N
704
}
705         public String JavaDoc getRedoPresentationName() {
706             return ""; // NOI18N
707
}
708     }
709 }
710
Popular Tags