1 19 20 package org.netbeans.modules.form.layoutsupport.delegates; 21 22 import java.awt.*; 23 import javax.swing.*; 24 25 import org.netbeans.modules.form.layoutsupport.*; 26 import org.netbeans.modules.form.fakepeer.FakePeerSupport; 27 28 33 34 public class ScrollPaneSupport extends AbstractLayoutSupport { 35 36 39 public Class getSupportedClass() { 40 return ScrollPane.class; 41 } 42 43 58 public int getNewIndex(Container container, 59 Container containerDelegate, 60 Component component, 61 int index, 62 Point posInCont, 63 Point posInComp) 64 { 65 if (container.getComponentCount() > 1) return -1; 67 return 0; 68 } 69 70 public String getAssistantContext() { 71 return "scrollPaneLayout"; } 73 74 87 public boolean paintDragFeedback(Container container, 88 Container containerDelegate, 89 Component component, 90 LayoutConstraints newConstraints, 91 int newIndex, 92 Graphics g) 93 { 94 Dimension sz = container.getSize(); 95 Insets insets = container.getInsets(); 96 sz.width -= insets.left + insets.right; 97 sz.height -= insets.top + insets.bottom; 98 99 g.drawRect(0, 0, sz.width, sz.height); 100 return true; 101 } 102 103 110 public void addComponentsToContainer(Container container, 111 Container containerDelegate, 112 Component[] components, 113 int index) 114 { 115 if (components.length == 0) 116 return; 117 118 if (container instanceof ScrollPane) { 119 ScrollPane scroll = (ScrollPane) container; 121 Component removedComp = null; 122 if (scroll.getComponentCount() > 0) 123 removedComp = scroll.getComponent(0); 124 try { 125 scroll.add(components[0]); 126 } catch (NullPointerException npex) { 127 } 133 if (System.getProperty("java.version").startsWith("1.5") && (scroll.getPeer() != null)) { 135 Component comp = scroll.getComponent(0); 136 comp.removeNotify(); 137 ensureFakePeerAttached(comp); 138 comp.addNotify(); 139 scroll.validate(); 140 } 141 ensureFakePeerAttached(removedComp); 144 } 145 } 146 147 154 public boolean removeComponentFromContainer(Container container, 155 Container containerDelegate, 156 Component component) 157 { 158 return false; } 160 161 static private void ensureFakePeerAttached(Component comp) { 162 FakePeerSupport.attachFakePeer(comp); 163 if (comp instanceof Container) 164 FakePeerSupport.attachFakePeerRecursively((Container)comp); 165 } 166 } 167 | Popular Tags |