1 19 20 package org.netbeans.modules.form.layoutsupport; 21 22 import java.awt.*; 23 import java.util.*; 24 import java.beans.*; 25 import java.security.*; 26 27 import org.openide.ErrorManager; 28 import org.openide.nodes.*; 29 import org.openide.util.actions.SystemAction; 30 31 import org.netbeans.modules.form.*; 32 import org.netbeans.modules.form.actions.SelectLayoutAction; 33 34 37 38 public class LayoutNode extends FormNode 39 implements RADComponentCookie, FormPropertyCookie 40 { 41 private LayoutSupportManager layoutSupport; 42 43 public LayoutNode(RADVisualContainer cont) { 44 super(Children.LEAF, cont.getFormModel()); 45 layoutSupport = cont.getLayoutSupport(); 46 setName(layoutSupport.getDisplayName()); 47 cont.setLayoutNodeReference(this); 48 } 49 50 public RADComponent getRADComponent() { 52 return layoutSupport.getMetaContainer(); 53 } 54 55 public FormProperty getProperty(String name) { 57 Node.Property prop = layoutSupport.getLayoutProperty(name); 58 return prop instanceof FormProperty ? (FormProperty) prop : null; 59 } 60 61 public void fireLayoutPropertiesChange() { 62 firePropertyChange(null, null, null); 63 } 64 65 public void fireLayoutPropertySetsChange() { 66 firePropertySetsChange(null, null); 67 } 68 69 public Image getIcon(int iconType) { 70 return layoutSupport.getIcon(iconType); 71 } 72 73 public Node.PropertySet[] getPropertySets() { 74 return layoutSupport.getPropertySets(); 75 } 76 77 public javax.swing.Action [] getActions(boolean context) { 78 if (systemActions == null) { ArrayList actions = new ArrayList(10); 80 81 if (!layoutSupport.getMetaContainer().isReadOnly()) { 82 actions.add(SystemAction.get(SelectLayoutAction.class)); 83 actions.add(null); 84 } 85 86 javax.swing.Action [] superActions = super.getActions(context); 87 for (int i=0; i < superActions.length; i++) 88 actions.add(superActions[i]); 89 90 systemActions = new SystemAction[actions.size()]; 91 actions.toArray(systemActions); 92 } 93 94 return systemActions; 95 } 96 97 public boolean hasCustomizer() { 98 return !layoutSupport.getMetaContainer().isReadOnly() 99 && layoutSupport.getCustomizerClass() != null; 100 } 101 102 protected Component createCustomizer() { 103 Class customizerClass = layoutSupport.getCustomizerClass(); 104 if (customizerClass == null) 105 return null; 106 107 Component supportCustomizer = layoutSupport.getSupportCustomizer(); 108 if (supportCustomizer != null) 109 return supportCustomizer; 110 111 Object customizerObject; 113 try { 114 customizerObject = customizerClass.newInstance(); 115 } 116 catch (InstantiationException e) { 117 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 118 return null; 119 } 120 catch (IllegalAccessException e) { 121 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 122 return null; 123 } 124 125 if (customizerObject instanceof Component 126 && customizerObject instanceof Customizer) 127 { 128 Customizer customizer = (Customizer) customizerObject; 129 customizer.setObject( 130 layoutSupport.getPrimaryContainerDelegate().getLayout()); 131 132 customizer.addPropertyChangeListener(new PropertyChangeListener() { 133 public void propertyChange(PropertyChangeEvent evt) { 134 Node.Property[] properties; 135 if (evt.getPropertyName() != null) { 136 Node.Property changedProperty = 137 layoutSupport.getLayoutProperty(evt.getPropertyName()); 138 if (changedProperty != null) 139 properties = new Node.Property[] { changedProperty }; 140 else return; } 142 else { 143 properties = layoutSupport.getAllProperties(); 144 evt = null; 145 } 146 147 updatePropertiesFromCustomizer(properties, evt); 148 } 149 }); 150 151 return (Component) customizer; 152 } 153 154 return null; 155 } 156 157 private void updatePropertiesFromCustomizer( 158 final Node.Property[] properties, 159 final PropertyChangeEvent evt) 160 { 161 AccessController.doPrivileged(new PrivilegedAction() { 164 public Object run() { 165 try { 166 PropertyChangeEvent ev = evt == null ? null : 167 new PropertyChangeEvent( 168 layoutSupport.getLayoutDelegate(), 169 evt.getPropertyName(), 170 evt.getOldValue(), evt.getNewValue()); 171 172 for (int i=0; i < properties.length; i++) { 173 if (properties[i] instanceof FormProperty) 174 ((FormProperty)properties[i]).reinstateProperty(); 175 177 if (ev != null) 178 layoutSupport.containerLayoutChanged(ev); 179 } 180 181 if (ev == null) layoutSupport.containerLayoutChanged(null); 183 } 185 catch (PropertyVetoException ex) { 186 } 189 catch (Exception ex) { 190 ErrorManager.getDefault().notify(ex); 191 } 192 193 return null; 194 } 195 }); 196 } 197 198 221 } 222 | Popular Tags |