1 19 20 package org.netbeans.modules.form.layoutsupport.delegates; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.util.*; 25 26 import org.openide.nodes.Node; 27 28 import org.netbeans.modules.form.layoutsupport.*; 29 import org.netbeans.modules.form.codestructure.*; 30 import org.netbeans.modules.form.FormProperty; 31 32 39 40 public class CardLayoutSupport extends AbstractLayoutSupport { 41 42 private CardConstraints currentCard; 43 44 47 public Class getSupportedClass() { 48 return CardLayout.class; 49 } 50 51 60 public void addComponents(CodeExpression[] newCompExpressions, 61 LayoutConstraints[] newConstraints, 62 int index) 63 { 64 super.addComponents(newCompExpressions, newConstraints, index); 66 67 if (index < 0) 69 index = getComponentCount() - 1; 70 else 71 index += newCompExpressions.length - 1; 72 73 if (currentCard == null && index >= 0 && index < getComponentCount()) 74 currentCard = (CardConstraints) getConstraints(index); 75 } 76 77 81 public void selectComponent(int index) { 82 LayoutConstraints constraints = getConstraints(index); 84 if (constraints instanceof CardConstraints) 85 currentCard = (CardConstraints) constraints; 86 } 87 88 96 public void arrangeContainer(Container container, 97 Container containerDelegate) 98 { 99 LayoutManager lm = containerDelegate.getLayout(); 100 if (!(lm instanceof CardLayout) || currentCard == null) 101 return; 102 103 ((CardLayout)lm).show(containerDelegate, 105 (String )currentCard.getConstraintsObject()); 106 } 107 108 125 public int getNewIndex(Container container, 126 Container containerDelegate, 127 Component component, 128 int index, 129 Point posInCont, 130 Point posInComp) 131 { 132 if (!(containerDelegate.getLayout() instanceof CardLayout)) 133 return -1; 134 return containerDelegate.getComponentCount(); 135 } 136 137 public String getAssistantContext() { 138 return "cardLayout"; } 140 141 156 public boolean paintDragFeedback(Container container, 157 Container containerDelegate, 158 Component component, 159 LayoutConstraints newConstraints, 160 int newIndex, 161 Graphics g) 162 { 163 if (!(containerDelegate.getLayout() instanceof CardLayout)) 164 return false; 165 166 Dimension sz = containerDelegate.getSize(); 167 Insets insets = containerDelegate.getInsets(); 168 sz.width -= insets.left + insets.right; 169 sz.height -= insets.top + insets.bottom; 170 171 g.drawRect(0, 0, sz.width, sz.height); 172 return true; 173 } 174 175 177 189 protected LayoutConstraints readConstraintsCode(CodeExpression constrExp, 190 CodeGroup constrCode, 191 CodeExpression compExp) 192 { 193 CardConstraints constr = new CardConstraints("card"); FormCodeSupport.readPropertyExpression(constrExp, 195 constr.getProperties()[0], 196 false); 197 return constr; 198 } 199 200 210 protected CodeExpression createConstraintsCode(CodeGroup constrCode, 211 LayoutConstraints constr, 212 CodeExpression compExp, 213 int index) 214 { 215 if (!(constr instanceof CardConstraints)) 216 return null; 218 return getCodeStructure().createExpression( 219 FormCodeSupport.createOrigin(constr.getProperties()[0])); 220 } 221 222 226 protected LayoutConstraints createDefaultConstraints() { 227 return new CardConstraints("card"+(getComponentCount()+1)); } 229 230 232 234 public static class CardConstraints implements LayoutConstraints { 235 private String card; 236 237 private Node.Property[] properties; 238 239 public CardConstraints(String card) { 240 this.card = card; 241 } 242 243 public Node.Property[] getProperties() { 244 if (properties == null) { 245 properties = new Node.Property[] { 246 new FormProperty("CardConstraints cardName", String .class, 248 getBundle().getString("PROP_cardName"), getBundle().getString("HINT_cardName")) { 251 public Object getTargetValue() { 252 return card; 253 } 254 255 public void setTargetValue(Object value) { 256 card = (String )value; 257 } 258 public void setPropertyContext( 259 org.netbeans.modules.form.FormPropertyContext ctx) 260 { } } 263 }; 264 properties[0].setValue("NOI18N", Boolean.TRUE); } 266 267 return properties; 268 } 269 270 public Object getConstraintsObject() { 271 return card; 272 } 273 274 public LayoutConstraints cloneConstraints() { 275 return new CardConstraints(card); 276 } 277 } 278 } 279 | Popular Tags |