1 11 package org.eclipse.ui.internal.presentations; 12 13 import org.eclipse.jface.util.Geometry; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.graphics.Point; 16 import org.eclipse.swt.graphics.Rectangle; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 import org.eclipse.swt.widgets.Layout; 20 import org.eclipse.ui.internal.dnd.DragUtil; 21 import org.eclipse.ui.internal.layout.SizeCache; 22 23 29 public class ProxyControl { 30 private Composite control; 31 private SizeCache target; 32 33 public ProxyControl(Composite parent) { 34 control = new Composite(parent, SWT.NONE); 35 control.setVisible(false); 36 37 control.setLayout(new Layout() { 38 protected void layout (Composite composite, boolean flushCache) { 39 } 41 42 protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { 43 if (target == null) { 44 return new Point(0,0); 45 } 46 47 return target.computeSize(wHint, hHint); 48 } 49 }); 50 } 51 52 57 public void setTarget(SizeCache target) { 58 if (this.target != target) { 59 this.target = target; 60 } 61 } 62 63 68 public Control getTargetControl() { 69 if (target == null) { 70 return null; 71 } 72 73 return target.getControl(); 74 } 75 76 81 public Control getControl() { 82 return control; 83 } 84 85 88 public void layout() { 89 if (getTargetControl() == null) { 90 return; 91 } 92 93 Rectangle parentBounds = DragUtil.getDisplayBounds(control.getParent()); 94 95 Rectangle bounds = control.getBounds(); 97 bounds.x += parentBounds.x; 98 bounds.y += parentBounds.y; 99 bounds = bounds.intersection(parentBounds); 100 101 Rectangle targetBounds = Geometry.toControl(getTargetControl().getParent(), bounds); 102 103 getTargetControl().setBounds(targetBounds); 104 } 105 106 110 public void dispose() { 111 if (control == null) { 112 return; 113 } 114 this.target = null; 115 control.dispose(); 116 control = null; 117 } 118 } 119 | Popular Tags |