1 19 20 package org.netbeans.modules.form.actions; 21 import org.openide.util.HelpCtx; 22 import org.openide.nodes.*; 23 import org.openide.util.actions.NodeAction; 24 25 import org.netbeans.modules.form.*; 26 import org.netbeans.modules.form.layoutdesign.LayoutDesigner; 27 import org.netbeans.modules.form.layoutdesign.LayoutModel; 28 29 public class DefaultSizeAction extends NodeAction { 30 31 protected boolean asynchronous() { 32 return false; 33 } 34 35 protected boolean enable(Node[] nodes) { 36 for (int i=0; i < nodes.length; i++) { 37 if (getValidComponent(nodes[i]) == null) 38 return false; } 40 return true; 41 } 42 43 protected void performAction(Node[] nodes) { 44 FormModel formModel = null; 45 FormDesigner formDesigner = null; 46 LayoutDesigner layoutDesigner = null; 47 RADVisualComponent topDesignComponent = null; 48 LayoutModel layoutModel = null; 49 Object layoutUndoMark = null; 50 javax.swing.undo.UndoableEdit layoutUE = null; 51 boolean autoUndo = true; 52 53 try { 54 for (int i=0; i < nodes.length; i++) { 55 RADVisualComponent metacomp = getValidComponent(nodes[i]); 56 if (metacomp == null) 57 return; 59 if (layoutDesigner == null) { 60 formModel = metacomp.getFormModel(); 61 formDesigner = FormEditor.getFormDesigner(formModel); 62 layoutDesigner = formDesigner.getLayoutDesigner(); 63 layoutModel = formModel.getLayoutModel(); 64 layoutUndoMark = layoutModel.getChangeMark(); 65 layoutUE = layoutModel.getUndoableEdit(); 66 } 67 layoutDesigner.setDefaultSize(metacomp.getId()); 68 if (metacomp instanceof RADVisualContainer) { 69 formModel.fireContainerLayoutChanged((RADVisualContainer)metacomp, null, null, null); 70 } 72 if (topDesignComponent == null && metacomp == formDesigner.getTopDesignComponent()) { 73 topDesignComponent = metacomp; 74 } 75 else { formModel.fireContainerLayoutChanged(metacomp.getParentContainer(), null, null, null); 77 } 78 } 79 80 if (topDesignComponent != null) { 81 formDesigner.resetDesignerSize(); 82 } 83 autoUndo = false; 84 } finally { 85 if (layoutUE != null && !layoutUndoMark.equals(layoutModel.getChangeMark())) { 86 formModel.addUndoableEdit(layoutUE); 87 } 88 if (autoUndo) { 89 formModel.forceUndoOfCompoundEdit(); 90 } 91 } 92 } 93 94 public String getName() { 95 return org.openide.util.NbBundle.getBundle(DefaultSizeAction.class) 96 .getString("ACT_DefaultSize"); } 98 99 public HelpCtx getHelpCtx() { 100 return HelpCtx.DEFAULT_HELP; 101 } 102 103 private static RADVisualComponent getValidComponent(Node node) { 104 RADComponentCookie radCookie = (RADComponentCookie) 105 node.getCookie(RADComponentCookie.class); 106 if (radCookie != null) { 107 RADComponent metacomp = radCookie.getRADComponent(); 108 if (metacomp instanceof RADVisualComponent) { 109 RADVisualComponent visualMetaComp = (RADVisualComponent)metacomp; 110 RADVisualContainer parent = visualMetaComp.getParentContainer(); 111 if ((parent != null) && javax.swing.JScrollPane .class.isAssignableFrom(parent.getBeanInstance().getClass())) { 112 visualMetaComp = parent; 113 parent = parent.getParentContainer(); 114 } 115 if (FormUtils.isInTopDesignComponent(metacomp) && 116 ((parent != null && parent.getLayoutSupport() == null) 117 || (visualMetaComp instanceof RADVisualContainer 118 && ((RADVisualContainer)visualMetaComp).getLayoutSupport() == null 119 && (!(visualMetaComp instanceof RADVisualFormContainer) 120 || ((RADVisualFormContainer)visualMetaComp).getFormSizePolicy() 121 != RADVisualFormContainer.GEN_BOUNDS)))) 122 return visualMetaComp; 123 } 124 } 125 return null; 126 } 127 } 128 | Popular Tags |