1 11 12 package org.eclipse.ui.internal.layout; 13 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 21 57 public class CacheWrapper { 58 private Composite proxy; 59 60 private SizeCache cache = new SizeCache(); 61 62 private Rectangle lastBounds = new Rectangle(0, 0, 0, 0); 63 64 private class WrapperLayout extends Layout implements ICachingLayout { 65 protected Point computeSize(Composite composite, int wHint, int hHint, 66 boolean flushCache) { 67 Control[] children = composite.getChildren(); 68 if (children.length != 1) { 69 return new Point(0, 0); 70 } 71 72 cache.setControl(children[0]); 73 74 return cache.computeSize(wHint, hHint); 75 } 76 77 protected void layout(Composite composite, boolean flushCache) { 78 Control[] children = composite.getChildren(); 79 if (children.length != 1) { 80 return; 81 } 82 83 Control child = children[0]; 84 Rectangle newBounds = composite.getClientArea(); 85 if (!newBounds.equals(lastBounds)) { 86 child.setBounds(newBounds); 87 lastBounds = newBounds; 88 } 89 90 } 91 92 95 public void flush(Control dirtyControl) { 96 CacheWrapper.this.flushCache(); 97 } 98 } 99 100 105 public CacheWrapper(Composite parent) { 106 proxy = new Composite(parent, SWT.NONE); 107 108 proxy.setLayout(new WrapperLayout()); 109 } 110 111 115 public void flushCache() { 116 cache.flush(); 117 } 118 119 124 public Composite getControl() { 125 return proxy; 126 } 127 128 131 public void dispose() { 132 if (proxy != null) { 133 proxy.dispose(); 134 proxy = null; 135 } 136 } 137 } 138 | Popular Tags |