1 19 20 package org.netbeans.modules.xml.schema.abe; 21 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Graphics ; 25 import java.awt.Graphics2D ; 26 import java.awt.dnd.DropTargetDragEvent ; 27 import java.awt.dnd.DropTargetDropEvent ; 28 import java.awt.dnd.DropTargetEvent ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import javax.swing.SwingConstants ; 32 import org.netbeans.modules.xml.schema.abe.palette.DnDHelper; 33 34 39 public class TweenerPanel extends ABEBaseDropPanel { 40 private static final long serialVersionUID = 7526472295622776147L; 41 private TranslucentLabel dropInfoLabel = new TranslucentLabel(new javax.swing.ImageIcon (getClass(). 42 getResource("/org/netbeans/modules/xml/schema/abe/resources/bulb.png"))); 43 47 public TweenerPanel(int orientation, InstanceUIContext context) { 48 super(context); 49 this.orientation=orientation; 50 initialize(); 51 } 53 54 55 private static final int HBAR_NOMINAL_WIDTH = 500; 59 private static final int HBAR_MAX_HEIGHT=2; 60 61 private static final int VBAR_MAX_WIDTH=10; 62 private static final int VBAR_NOMINAL_HEIGHT = StartTagPanel.getTagHeight(); 63 64 private static final int PADDING=3; 65 66 private static final int EXPAND_FACTOR = 3; 67 68 List <TweenerListener> tweenerListeners = new ArrayList <TweenerListener>(); 69 70 74 private void initialize() { 75 setOpaque(false); 76 77 if (getOrientation()==SwingConstants.HORIZONTAL) 78 _setSize(HBAR_NOMINAL_WIDTH, HBAR_MAX_HEIGHT); 79 else 80 _setSize(VBAR_MAX_WIDTH, VBAR_NOMINAL_HEIGHT); 81 } 82 83 84 88 public int getOrientation() { 89 return orientation; 90 } 91 92 93 97 private void _setSize(int w, int h) { 98 setPreferredSize(new Dimension (w,h)); 99 setMinimumSize(new Dimension (w,h)); 100 setMaximumSize(new Dimension (w,h)); 101 revalidate(); 102 } 103 104 105 106 107 111 115 protected void handleActive(boolean value) { 116 boolean oldValue=active; 117 if (oldValue!=value) { 118 active=value; 119 if(!active) 120 removeDropInfoLabel(); 121 repaint(); 122 } 123 } 124 125 126 127 128 132 136 public void paint(Graphics g) { 137 Graphics2D g2d=(Graphics2D )g; 138 super.paint(g2d); 139 if (isActive()) { 140 if (getOrientation()==SwingConstants.HORIZONTAL) { 141 int x = 0; 143 int y = (getHeight()/2) -1 ; int w = getVisibleRect().width; 145 146 g2d.setColor(Color.BLACK); 147 148 int left=PADDING; 149 int right=w-PADDING; 150 151 g2d.drawLine(left,y-2,left,y+3); 153 g2d.drawLine(left+1,y-1,left+1,y+2); 154 155 g2d.drawLine(right,y-2,right,y+3); 157 g2d.drawLine(right-1,y-1,right-1,y+2); 158 159 g2d.drawLine(left,y,right,y); 161 g2d.drawLine(left,y+1,right,y+1); 162 } else { 163 int x = (getWidth() / 2) - 1; 165 int h = getHeight(); 166 167 g2d.setColor(Color.BLACK); 168 169 int top=PADDING; 170 int bottom = h - (PADDING * 4) ; 171 172 g2d.drawLine(x-2,top,x+3,top); 174 g2d.drawLine(x-1,top+1,x+2,top+1); 175 176 g2d.drawLine(x-2,bottom,x+3,bottom); 178 g2d.drawLine(x-1,bottom-1,x+2,bottom-1); 179 180 g2d.drawLine(x,top,x,bottom); 182 g2d.drawLine(x+1,top,x+1,bottom); 183 } 184 } 185 } 186 187 public void addTweenerListener(TweenerListener tl){ 188 tweenerListeners.add(tl); 189 } 190 191 192 private int orientation; 193 private boolean active; 194 195 196 private void showExpanded(){ 197 Dimension dim = new Dimension (HBAR_NOMINAL_WIDTH, HBAR_MAX_HEIGHT * EXPAND_FACTOR); 198 setPreferredSize(dim); 199 setMinimumSize(dim); 200 revalidate(); 201 } 203 204 private void showCollapsed(){ 205 Dimension dim = new Dimension (HBAR_NOMINAL_WIDTH, HBAR_MAX_HEIGHT); 206 setPreferredSize(dim); 207 setMinimumSize(dim); 208 revalidate(); 209 } 211 212 public void drop(DropTargetDropEvent event) { 213 context.setUserInducedEventMode(true); 214 try{ 215 for(TweenerListener tl: tweenerListeners){ 216 if(!tl.dragAccept(DnDHelper.getDraggedPaletteItem(event))){ 217 event.rejectDrop(); 218 return; 219 } 220 } 221 222 for(TweenerListener tl: tweenerListeners){ 223 tl.drop(DnDHelper.getDraggedPaletteItem(event)); 224 } 225 if(orientation == SwingConstants.HORIZONTAL){ 226 showCollapsed(); 227 for(TweenerListener tl: tweenerListeners){ 228 tl.dragExited(); 229 } 230 } 231 }finally{ 232 context.setUserInducedEventMode(false); 233 } 234 } 235 236 public void dragExit(DropTargetEvent event) { 237 if(orientation == SwingConstants.HORIZONTAL){ 238 showCollapsed(); 239 } 240 for(TweenerListener tl: tweenerListeners){ 241 tl.dragExited(); 242 } 243 } 244 245 public void dragOver(DropTargetDragEvent event) { 246 } 247 248 public void dragEnter(DropTargetDragEvent event) { 249 if(orientation == SwingConstants.HORIZONTAL){ 250 showExpanded(); 251 } 252 for(TweenerListener tl: tweenerListeners){ 253 if(!tl.dragAccept(DnDHelper.getDraggedPaletteItem(event))){ 254 event.rejectDrag(); 256 return; 257 } 258 } 259 for(TweenerListener tl: tweenerListeners){ 260 tl.dragEntered(DnDHelper.getDraggedPaletteItem(event)); 261 } 262 addDropInfoLabel(); 263 } 264 265 266 268 269 private void addDropInfoLabel() { 270 String infoText = getDropInfoText(); 271 if(infoText != null){ 272 UIUtilities.showBulbMessageFor(infoText, context, this); 273 } 274 } 275 276 private void removeDropInfoLabel() { 277 NBGlassPaneAccessSupport.disposeNBGlassPane(); 278 } 279 280 private String dropInfoText; 281 public String getDropInfoText() { 282 return dropInfoText; 283 } 284 285 public void setDropInfoText(String dropInfoText) { 286 this.dropInfoText = dropInfoText; 287 } 288 289 public void accept(UIVisitor visitor) { 290 } 292 293 294 } 295 | Popular Tags |