001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form;
043:
044: import java.awt.*;
045: import java.awt.event.*;
046: import java.awt.geom.*;
047: import javax.swing.*;
048: import javax.swing.undo.*;
049: import java.util.*;
050: import java.util.List;
051:
052: import org.netbeans.modules.form.layoutsupport.*;
053:
054: /**
055: *
056: * @author Tran Duc Trung
057: */
058:
059: class ComponentDragger {
060: private FormDesigner formDesigner;
061: private HandleLayer handleLayer;
062: private RADVisualComponent[] selectedComponents;
063: private Rectangle[] originalBounds; // in HandleLayer coordinates
064: private Point hotspot; // in HandleLayer coordinates
065: private Point mousePosition;
066: private int resizeType;
067:
068: private RADVisualContainer targetMetaContainer;
069:
070: private Container targetContainer;
071: private Container targetContainerDel;
072:
073: static Stroke dashedStroke1 = new BasicStroke((float) 2.0,
074: BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER,
075: (float) 10.0, new float[] { (float) 1.0, (float) 4.0 }, 0);
076:
077: static Stroke dashedStroke2 = new BasicStroke((float) 2.0,
078: BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER,
079: (float) 10.0, new float[] { (float) 2.0, (float) 8.0 }, 0);
080:
081: /** The FormLoaderSettings instance */
082: // constructor for dragging
083: ComponentDragger(FormDesigner formDesigner,
084: HandleLayer handleLayer,
085: RADVisualComponent[] selectedComponents,
086: Rectangle[] originalBounds, Point hotspot,
087: RADVisualContainer fixedTargetMetaContainer) {
088: this .formDesigner = formDesigner;
089: this .handleLayer = handleLayer;
090: this .selectedComponents = selectedComponents;
091: this .originalBounds = originalBounds;
092: this .hotspot = hotspot;
093: this .mousePosition = hotspot;
094: this .resizeType = 0;
095:
096: if (fixedTargetMetaContainer != null) {
097: targetMetaContainer = fixedTargetMetaContainer;
098: }
099: }
100:
101: // constructor for resizing
102: ComponentDragger(FormDesigner formDesigner,
103: HandleLayer handleLayer,
104: RADVisualComponent[] selectedComponents,
105: Rectangle[] originalBounds, Point hotspot, int resizeType) {
106: this .formDesigner = formDesigner;
107: this .handleLayer = handleLayer;
108: this .selectedComponents = selectedComponents;
109: this .originalBounds = originalBounds;
110: this .hotspot = hotspot;
111: this .mousePosition = hotspot;
112: this .resizeType = resizeType;
113: }
114:
115: void drag(Point p, RADVisualContainer target) {
116: targetMetaContainer = target;
117: mousePosition = p;
118: }
119:
120: void paintDragFeedback(Graphics2D g) {
121: Stroke oldStroke = g.getStroke();
122: g.setStroke(dashedStroke1);
123:
124: Color oldColor = g.getColor();
125: g.setColor(FormLoaderSettings.getInstance()
126: .getSelectionBorderColor());
127:
128: List<LayoutConstraints> constraints = new ArrayList<LayoutConstraints>(
129: selectedComponents.length);
130: List<Integer> indices = new ArrayList<Integer>(
131: selectedComponents.length);
132:
133: boolean constraintsOK = computeConstraints(mousePosition,
134: constraints, indices);
135:
136: Point contPos = null;
137: LayoutSupportManager layoutSupport = null;
138: if (constraintsOK) {
139: contPos = SwingUtilities.convertPoint(targetContainerDel,
140: 0, 0, handleLayer);
141: layoutSupport = targetMetaContainer.getLayoutSupport();
142: if (resizeType == 0)
143: paintTargetContainerFeedback(g, targetContainerDel);
144: }
145:
146: for (int i = 0; i < selectedComponents.length; i++) {
147: RADVisualComponent metacomp = selectedComponents[i];
148: boolean drawn = false;
149:
150: if (constraintsOK) {
151: Component comp = (Component) formDesigner
152: .getComponent(metacomp);
153: LayoutConstraints constr = constraints.get(i);
154: int index = indices.get(i);
155:
156: if (constr != null || index >= 0) {
157: g.translate(contPos.x, contPos.y);
158: drawn = layoutSupport.paintDragFeedback(
159: targetContainer, targetContainerDel, comp,
160: constr, index, g);
161: g.translate(-contPos.x, -contPos.y);
162: }
163: // else continue;
164: }
165:
166: if (!drawn)
167: paintDragFeedback(g, metacomp);
168: }
169:
170: g.setColor(oldColor);
171: g.setStroke(oldStroke);
172: }
173:
174: void dropComponents(Point point, RADVisualContainer target) {
175: List<LayoutConstraints> constraints = null; // constraints of the dragged components
176: List<Integer> indices = null; // indices of the dragged components
177:
178: targetMetaContainer = target;
179: if (targetMetaContainer != null) {
180: constraints = new ArrayList<LayoutConstraints>(
181: selectedComponents.length);
182: indices = new ArrayList<Integer>(selectedComponents.length);
183: computeConstraints(point, constraints, indices);
184: }
185: if (targetMetaContainer == null) {
186: // if (handleLayer.mouseOnVisual(point)) {
187: // return;
188: // }
189: constraints = null;
190: indices = null;
191: }
192:
193: FormModel formModel = formDesigner.getFormModel();
194:
195: // LayoutSupportManager of the target container
196: LayoutSupportManager layoutSupport = null;
197: // original components in the target container
198: RADVisualComponent[] originalComponents = null;
199: LayoutConstraints[] originalConstraints = null;
200: // components moved from other containers
201: List<Integer> movedFromOutside = null;
202: // components moved within the target container
203: List<RADVisualComponent> movedWithinTarget = null;
204:
205: if (targetMetaContainer != null) { // target is a visual container
206: layoutSupport = targetMetaContainer.getLayoutSupport();
207: originalComponents = targetMetaContainer.getSubComponents();
208: originalConstraints = new LayoutConstraints[originalComponents.length];
209:
210: // adjust indices considering that some of dragged components
211: // might be already in target container
212: adjustIndices(indices);
213:
214: // collect components being dragged from other containers
215: for (int i = 0; i < selectedComponents.length; i++) {
216: if (selectedComponents[i].getParentContainer() != targetMetaContainer) {
217: if (movedFromOutside == null)
218: movedFromOutside = new ArrayList<Integer>(
219: selectedComponents.length);
220: movedFromOutside.add(i); // remember index
221: } else {
222: if (movedWithinTarget == null)
223: movedWithinTarget = new ArrayList<RADVisualComponent>(
224: selectedComponents.length);
225: movedWithinTarget.add(selectedComponents[i]);
226: }
227: }
228:
229: // test whether target container accepts new components (dragged
230: // from other containers)
231: if (movedFromOutside != null && movedFromOutside.size() > 0) {
232: int count = movedFromOutside.size();
233: RADVisualComponent[] newComps = new RADVisualComponent[count];
234: LayoutConstraints[] newConstr = new LayoutConstraints[count];
235:
236: for (int i = 0; i < count; i++) {
237: int index = movedFromOutside.get(i);
238: newComps[i] = selectedComponents[index];
239: newConstr[i] = constraints.get(index);
240: }
241:
242: // j - index to selectedComponents for the first new component
243: int j = movedFromOutside.get(0);
244: // jj - insertion point of the first component in target container
245: int jj = indices.get(j);
246:
247: try {
248: layoutSupport.acceptNewComponents(newComps,
249: newConstr, jj);
250: } catch (RuntimeException ex) {
251: // layout support does not accept components
252: org.openide.ErrorManager.getDefault().notify(
253: org.openide.ErrorManager.INFORMATIONAL, ex);
254: return;
255: }
256:
257: // layout support might adjust the constraints
258: for (int i = 0; i < count; i++) {
259: int index = movedFromOutside.get(i);
260: constraints.set(index, newConstr[i]);
261: }
262:
263: movedFromOutside.clear(); // for later use
264: }
265: }
266:
267: // create list of components and constraints for target container
268: int n = selectedComponents.length
269: + (originalComponents != null ? originalComponents.length
270: : 0);
271: List<RADVisualComponent> newComponents = new ArrayList<RADVisualComponent>(
272: n);
273: List<LayoutConstraints> newConstraints = new ArrayList<LayoutConstraints>(
274: n);
275: int newI = 0;
276:
277: // fill enough empty space
278: for (int i = 0; i < n; i++) {
279: newComponents.add(null);
280: newConstraints.add(null);
281: }
282:
283: if (targetMetaContainer != null) {
284: // add dragged components requiring exact position (index)
285: for (int i = 0; i < selectedComponents.length; i++) {
286: int index = indices.get(i);
287: if (index >= 0 && index < n
288: && checkTarget(selectedComponents[i])) {
289: while (newComponents.get(index) != null)
290: // ensure free index
291: if (++index == n)
292: index = 0;
293:
294: newComponents.set(index, selectedComponents[i]);
295: }
296: }
297:
298: // add all components being already in the target container
299: for (int i = 0; i < originalComponents.length; i++) {
300: RADVisualComponent metacomp = originalComponents[i];
301: originalConstraints[i] = layoutSupport
302: .getConstraints(metacomp);
303:
304: int index = newComponents.indexOf(metacomp);
305: if (index < 0) { // not yet in newComponents
306: while (newComponents.get(newI) != null)
307: // ensure free index
308: newI++;
309:
310: newComponents.set(newI, metacomp);
311: newConstraints.set(newI, originalConstraints[i]);
312: }
313: }
314: }
315:
316: // add the rest of dragged components (driven by constraints typically)
317: for (int i = 0; i < selectedComponents.length; i++) {
318: RADVisualComponent metacomp = selectedComponents[i];
319: int index = newComponents.indexOf(metacomp);
320: if (index >= 0) { // already in newComponents
321: newConstraints
322: .set(index, constraints != null ? constraints
323: .get(i) : null);
324: } else if (checkTarget(metacomp)) { // not yet in newComponents
325: while (newComponents.get(newI) != null)
326: // ensure free index
327: newI++;
328:
329: newComponents.set(newI, metacomp);
330: newConstraints
331: .set(newI, constraints != null ? constraints
332: .get(i) : null);
333: }
334: }
335: // now we have lists of components and constraints in right order
336:
337: List<RADVisualComponent> movedFromOutside2 = null;
338: // remove components from source containers
339: for (int i = 0; i < n; i++) {
340: RADVisualComponent metacomp = newComponents.get(i);
341: if (metacomp != null) {
342: RADVisualContainer parentCont = metacomp
343: .getParentContainer();
344: if (parentCont != targetMetaContainer) {
345: if (movedFromOutside2 == null)
346: movedFromOutside2 = new ArrayList<RADVisualComponent>(
347: selectedComponents.length);
348: movedFromOutside2.add(metacomp);
349:
350: formModel.removeComponent(metacomp, false);
351: }
352: } else { // remove empty space
353: newComponents.remove(i);
354: newConstraints.remove(i);
355: i--;
356: n--;
357: }
358: }
359:
360: if (n == 0)
361: return; // dragging not allowed
362:
363: // turn off undo/redo monitoring in FormModel as we provide our own
364: // undoable edit for the rest (adding part) of the operation
365: boolean undoRedoOn = formModel.isUndoRedoRecording();
366: if (undoRedoOn)
367: formModel.setUndoRedoRecording(false);
368:
369: // prepare arrays of components and constraints (from lists)
370: RADVisualComponent[] newCompsArray = new RADVisualComponent[n];
371: LayoutConstraints[] newConstrArray = new LayoutConstraints[n];
372:
373: if (targetMetaContainer != null) { // target is a visual container
374: for (int i = 0; i < n; i++) {
375: newCompsArray[i] = newComponents.get(i);
376: newConstrArray[i] = newConstraints.get(i);
377: }
378:
379: // clear the target layout
380: layoutSupport.removeAll();
381:
382: // add all components to the target container
383: targetMetaContainer.initSubComponents(newCompsArray);
384: layoutSupport.addComponents(newCompsArray, newConstrArray,
385: 0);
386: } else { // no visual target, add the components to Other Components
387: ComponentContainer othersMetaCont = formModel
388: .getModelContainer();
389: for (int i = 0; i < n; i++) {
390: newCompsArray[i] = newComponents.get(i);
391: othersMetaCont.add(newCompsArray[i]);
392: newCompsArray[i].resetConstraintsProperties();
393: }
394: }
395:
396: // fire changes - adding new components
397: RADVisualComponent[] compsMovedFromOutside;
398: if (movedFromOutside2 != null) {
399: n = movedFromOutside2.size();
400: compsMovedFromOutside = new RADVisualComponent[n];
401: for (int i = 0; i < n; i++) {
402: compsMovedFromOutside[i] = movedFromOutside2.get(i);
403: formModel.fireComponentAdded(compsMovedFromOutside[i],
404: false);
405: }
406: } else {
407: compsMovedFromOutside = new RADVisualComponent[0];
408: formModel.fireComponentsReordered(targetMetaContainer,
409: new int[0]);
410: }
411:
412: // fire changes - changing components layout
413: RADVisualComponent[] compsMovedWithinTarget;
414: if (movedWithinTarget != null) {
415: n = movedWithinTarget.size();
416: compsMovedWithinTarget = new RADVisualComponent[n];
417: for (int i = 0; i < n; i++) {
418: compsMovedWithinTarget[i] = movedWithinTarget.get(i);
419: formModel.fireComponentLayoutChanged(
420: compsMovedWithinTarget[i], null, null, null);
421: }
422: } else
423: compsMovedWithinTarget = new RADVisualComponent[0];
424:
425: // setup undoable edit
426: if (undoRedoOn) {
427: DropUndoableEdit dropUndo = new DropUndoableEdit();
428: dropUndo.formModel = formModel;
429: dropUndo.targetContainer = targetMetaContainer;
430: dropUndo.targetComponentsBeforeMove = originalComponents;
431: dropUndo.targetConstraintsBeforeMove = originalConstraints;
432: dropUndo.targetComponentsAfterMove = newCompsArray;
433: dropUndo.targetConstraintsAfterMove = newConstrArray;
434: dropUndo.componentsMovedFromOutside = compsMovedFromOutside;
435: dropUndo.componentsMovedWithinTarget = compsMovedWithinTarget;
436:
437: formModel.addUndoableEdit(dropUndo);
438: }
439:
440: // finish undoable edit
441: if (undoRedoOn) // turn on undo/redo monitoring again
442: formModel.setUndoRedoRecording(true);
443:
444: // formDesigner.clearSelection(); // Issue 64342
445: // select dropped components in designer (after everything updates)
446: SwingUtilities.invokeLater(new Runnable() {
447: public void run() {
448: formDesigner.setSelectedComponents(selectedComponents);
449: }
450: });
451: }
452:
453: // ------------
454:
455: private boolean computeConstraints(Point p,
456: List<LayoutConstraints> constraints, List<Integer> indices) {
457: if (selectedComponents == null
458: || selectedComponents.length == 0)
459: return false;
460:
461: if (targetMetaContainer == null)
462: return false; // unknown meta-container
463:
464: RADVisualContainer fixTargetContainer = null;
465: do {
466: if (fixTargetContainer != null) {
467: targetMetaContainer = fixTargetContainer;
468: fixTargetContainer = null;
469: }
470:
471: LayoutSupportManager layoutSupport = targetMetaContainer
472: .getLayoutSupport();
473: // if (layoutSupport == null)
474: // return false; // no LayoutSupport (should not happen)
475:
476: targetContainer = (Container) formDesigner
477: .getComponent(targetMetaContainer);
478: if (targetContainer == null)
479: return false; // container not in designer (should not happen)
480:
481: targetContainerDel = targetMetaContainer
482: .getContainerDelegate(targetContainer);
483: if (targetContainerDel == null)
484: return false; // no container delegate (should not happen)
485:
486: Point posInCont = SwingUtilities.convertPoint(handleLayer,
487: p, targetContainerDel);
488:
489: for (int i = 0; i < selectedComponents.length; i++) {
490: LayoutConstraints constr = null;
491: int index = -1;
492:
493: RADVisualComponent metacomp = selectedComponents[i];
494: Component comp = (Component) formDesigner
495: .getComponent(metacomp);
496:
497: if (comp != null) {
498: if (!checkTarget(metacomp)) {
499: fixTargetContainer = metacomp
500: .getParentContainer();
501: constraints.clear();
502: indices.clear();
503: if (fixTargetContainer == null)
504: return false; // should not happen
505: break;
506: }
507:
508: if (resizeType == 0) { // dragging
509: Point posInComp = new Point(hotspot.x
510: - originalBounds[i].x, hotspot.y
511: - originalBounds[i].y);
512: index = layoutSupport.getNewIndex(
513: targetContainer, targetContainerDel,
514: comp, metacomp.getComponentIndex(),
515: posInCont, posInComp);
516: constr = layoutSupport.getNewConstraints(
517: targetContainer, targetContainerDel,
518: comp, metacomp.getComponentIndex(),
519: posInCont, posInComp);
520:
521: if (constr == null && index >= 0) {
522: // keep old constraints (if compatible)
523: LayoutSupportManager
524: .storeConstraints(metacomp);
525: constr = layoutSupport
526: .getStoredConstraints(metacomp);
527: }
528: } else { // resizing
529: int up = 0, down = 0, left = 0, right = 0;
530:
531: if ((resizeType & LayoutSupportManager.RESIZE_DOWN) != 0)
532: down = p.y - hotspot.y;
533: else if ((resizeType & LayoutSupportManager.RESIZE_UP) != 0)
534: up = hotspot.y - p.y;
535: if ((resizeType & LayoutSupportManager.RESIZE_RIGHT) != 0)
536: right = p.x - hotspot.x;
537: else if ((resizeType & LayoutSupportManager.RESIZE_LEFT) != 0)
538: left = hotspot.x - p.x;
539:
540: Insets sizeChanges = new Insets(up, left, down,
541: right);
542: constr = layoutSupport
543: .getResizedConstraints(
544: targetContainer,
545: targetContainerDel,
546: comp,
547: metacomp.getComponentIndex(),
548: handleLayer
549: .convertRectangleToComponent(
550: new Rectangle(
551: originalBounds[i]),
552: targetContainerDel),
553: sizeChanges, posInCont);
554: }
555: }
556:
557: constraints.add(constr);
558: indices.add(new Integer(index));
559: }
560: } while (fixTargetContainer != null);
561:
562: return true;
563: }
564:
565: /** Checks whether metacomp is not a parent of target container (or the
566: * target container itself). Used to avoid dragging to a sub-tree.
567: * @return true if metacomp is OK
568: */
569: private boolean checkTarget(RADVisualComponent metacomp) {
570: if (!(metacomp instanceof RADVisualContainer))
571: return true;
572:
573: RADComponent targetCont = targetMetaContainer;
574: while (targetCont != null) {
575: if (targetCont == metacomp)
576: return false;
577: targetCont = targetCont.getParentComponent();
578: }
579:
580: return true;
581: }
582:
583: /** Modifies suggested indices of dragged components considering the fact
584: * that some of the components might be in the target container.
585: */
586: private void adjustIndices(List<Integer> indices) {
587: int index;
588: int correction;
589: int prevIndex = -1;
590: int prevCorrection = 0;
591:
592: for (int i = 0; i < indices.size(); i++) {
593: index = indices.get(i);
594: if (index >= 0) {
595: if (index == prevIndex) {
596: correction = prevCorrection;
597: } else {
598: correction = 0;
599: RADVisualComponent[] targetComps = targetMetaContainer
600: .getSubComponents();
601: for (int j = 0; j < index; j++) {
602: RADVisualComponent tComp = targetComps[j];
603: boolean isSelected = false;
604: for (int k = 0; k < selectedComponents.length; k++)
605: if (tComp == selectedComponents[k]) {
606: isSelected = true;
607: break;
608: }
609:
610: if (isSelected)
611: correction++;
612: }
613: prevIndex = index;
614: prevCorrection = correction;
615: }
616:
617: if (correction != 0) {
618: index -= correction;
619: indices.set(i, new Integer(index));
620: }
621: }
622: }
623: }
624:
625: private void paintDragFeedback(Graphics2D g,
626: RADVisualComponent metacomp) {
627: Object comp = formDesigner.getComponent(metacomp);
628: if (!(comp instanceof Component)
629: || !((Component) comp).isShowing())
630: return;
631:
632: Component component = (Component) comp;
633:
634: Rectangle rect = component.getBounds();
635: rect = SwingUtilities.convertRectangle(component.getParent(),
636: rect, handleLayer);
637:
638: rect.translate(mousePosition.x - hotspot.x, mousePosition.y
639: - hotspot.y);
640:
641: g.draw(new Rectangle2D.Double(rect.x, rect.y, rect.width,
642: rect.height));
643:
644: if (metacomp instanceof RADVisualContainer) {
645: RADVisualComponent[] children = ((RADVisualContainer) metacomp)
646: .getSubComponents();
647: for (int i = 0; i < children.length; i++) {
648: paintDragFeedback(g, children[i]);
649: }
650: }
651: }
652:
653: private void paintTargetContainerFeedback(Graphics2D g,
654: Container cont) {
655: Stroke oldStroke = g.getStroke();
656: g.setStroke(dashedStroke2);
657:
658: Color oldColor = g.getColor();
659: g.setColor(FormLoaderSettings.getInstance()
660: .getDragBorderColor());
661:
662: Rectangle rect = new Rectangle(new Point(0, 0), cont.getSize());
663: rect = SwingUtilities.convertRectangle(cont, rect, handleLayer);
664: g.draw(new Rectangle2D.Double(rect.x, rect.y, rect.width,
665: rect.height));
666: g.setColor(oldColor);
667: g.setStroke(oldStroke);
668: }
669:
670: // ---------
671:
672: private static class DropUndoableEdit extends AbstractUndoableEdit {
673:
674: FormModel formModel;
675: RADVisualContainer targetContainer;
676: RADVisualComponent[] targetComponentsBeforeMove;
677: LayoutConstraints[] targetConstraintsBeforeMove;
678: RADVisualComponent[] targetComponentsAfterMove;
679: LayoutConstraints[] targetConstraintsAfterMove;
680: RADVisualComponent[] componentsMovedFromOutside;
681: RADVisualComponent[] componentsMovedWithinTarget;
682:
683: @Override
684: public void undo() throws CannotUndoException {
685: super .undo();
686:
687: // turn off undo/redo monitoring in FormModel while undoing!
688: boolean undoRedoOn = formModel.isUndoRedoRecording();
689: if (undoRedoOn)
690: formModel.setUndoRedoRecording(false);
691:
692: for (int i = 0; i < componentsMovedFromOutside.length; i++)
693: formModel.removeComponentImpl(
694: componentsMovedFromOutside[i], false);
695:
696: if (targetContainer != null) {
697: LayoutSupportManager layoutSupport = targetContainer
698: .getLayoutSupport();
699: layoutSupport.removeAll();
700: targetContainer
701: .initSubComponents(targetComponentsBeforeMove);
702: layoutSupport.addComponents(targetComponentsBeforeMove,
703: targetConstraintsBeforeMove, 0);
704:
705: for (int i = 0; i < componentsMovedWithinTarget.length; i++)
706: formModel.fireComponentLayoutChanged(
707: componentsMovedWithinTarget[i], null, null,
708: null);
709: }
710:
711: if (undoRedoOn) // turn on undo/redo monitoring again
712: formModel.setUndoRedoRecording(true);
713: }
714:
715: @Override
716: public void redo() throws CannotRedoException {
717: super .redo();
718:
719: // turn off undo/redo monitoring in FormModel while redoing!
720: boolean undoRedoOn = formModel.isUndoRedoRecording();
721: if (undoRedoOn)
722: formModel.setUndoRedoRecording(false);
723:
724: if (targetContainer != null) {
725: LayoutSupportManager layoutSupport = targetContainer
726: .getLayoutSupport();
727: layoutSupport.removeAll();
728: targetContainer
729: .initSubComponents(targetComponentsAfterMove);
730: layoutSupport.addComponents(targetComponentsAfterMove,
731: targetConstraintsAfterMove, 0);
732: } else {
733: ComponentContainer othersMetaCont = formModel
734: .getModelContainer();
735: for (int i = 0; i < targetComponentsAfterMove.length; i++) {
736: othersMetaCont.add(targetComponentsAfterMove[i]);
737: targetComponentsAfterMove[i]
738: .resetConstraintsProperties();
739: }
740: }
741:
742: for (int i = 0; i < componentsMovedFromOutside.length; i++)
743: formModel.fireComponentAdded(
744: componentsMovedFromOutside[i], false);
745:
746: for (int i = 0; i < componentsMovedWithinTarget.length; i++)
747: formModel.fireComponentLayoutChanged(
748: componentsMovedWithinTarget[i], null, null,
749: null);
750:
751: if (undoRedoOn) // turn on undo/redo monitoring again
752: formModel.setUndoRedoRecording(true);
753: }
754:
755: @Override
756: public String getUndoPresentationName() {
757: return ""; // NOI18N
758: }
759:
760: @Override
761: public String getRedoPresentationName() {
762: return ""; // NOI18N
763: }
764: }
765: }
|