1 11 package org.eclipse.ui.forms.widgets; 12 13 import org.eclipse.swt.graphics.Point; 14 import org.eclipse.swt.widgets.Control; 15 16 21 public class LayoutCache { 22 private SizeCache[] caches = new SizeCache[0]; 23 24 27 public LayoutCache() { 28 } 29 30 35 public LayoutCache(Control[] controls) { 36 rebuildCache(controls); 37 } 38 39 45 public SizeCache getCache(int idx) { 46 return caches[idx]; 47 } 48 49 56 public void setControls(Control[] controls) { 57 if (controls.length != caches.length) { 59 rebuildCache(controls); 60 return; 61 } 62 63 for (int idx = 0; idx < controls.length; idx++) { 64 caches[idx].setControl(controls[idx]); 65 } 66 } 67 68 74 private void rebuildCache(Control[] controls) { 75 SizeCache[] newCache = new SizeCache[controls.length]; 76 77 for (int idx = 0; idx < controls.length; idx++) { 78 if (idx < caches.length) { 80 newCache[idx] = caches[idx]; 81 newCache[idx].setControl(controls[idx]); 82 } else { 83 newCache[idx] = new SizeCache(controls[idx]); 84 } 85 } 86 87 caches = newCache; 88 } 89 90 98 public Point computeSize(int controlIndex, int widthHint, int heightHint) { 99 return caches[controlIndex].computeSize(widthHint, heightHint); 100 } 101 102 108 public void flush(int controlIndex) { 109 caches[controlIndex].flush(); 110 } 111 112 115 public void flush() { 116 for (int idx = 0; idx < caches.length; idx++) { 117 caches[idx].flush(); 118 } 119 } 120 } 121 | Popular Tags |