1 11 package org.eclipse.ui.internal.browser; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.custom.ScrolledComposite; 15 import org.eclipse.swt.graphics.Color; 16 import org.eclipse.swt.graphics.Font; 17 import org.eclipse.swt.graphics.Point; 18 import org.eclipse.swt.graphics.Rectangle; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.swt.widgets.Listener; 23 import org.eclipse.swt.widgets.ScrollBar; 24 25 public abstract class FallbackScrolledComposite extends ScrolledComposite { 26 private static final int H_SCROLL_INCREMENT = 5; 27 28 private static final int V_SCROLL_INCREMENT = 64; 29 30 38 public FallbackScrolledComposite(Composite parent, int style) { 39 super(parent, style); 40 addListener(SWT.Resize, new Listener() { 41 public void handleEvent(Event e) { 42 reflow(true); 43 } 44 }); 45 setExpandVertical(true); 46 setExpandHorizontal(true); 47 initializeScrollBars(); 48 } 49 50 56 public void setForeground(Color fg) { 57 super.setForeground(fg); 58 if (getContent() != null) 59 getContent().setForeground(fg); 60 } 61 62 68 public void setBackground(Color bg) { 69 super.setBackground(bg); 70 if (getContent() != null) 71 getContent().setBackground(bg); 72 } 73 74 78 public void setFont(Font font) { 79 super.setFont(font); 80 if (getContent() != null) 81 getContent().setFont(font); 82 } 83 84 87 public void setContent(Control content) { 88 super.setContent(content); 89 if (content != null) { 90 content.setForeground(getForeground()); 91 content.setBackground(getBackground()); 92 content.setFont(getFont()); 93 } 94 } 95 96 99 public boolean setFocus() { 100 if (getContent() != null) 101 return getContent().setFocus(); 102 return super.setFocus(); 103 } 104 105 113 public void reflow(boolean flushCache) { 114 Composite c = (Composite) getContent(); 115 Rectangle clientArea = getClientArea(); 116 if (c == null) 117 return; 118 119 Point newSize = c 120 .computeSize(clientArea.width, SWT.DEFAULT, flushCache); 121 122 setMinSize(newSize); 123 updatePageIncrement(); 124 layout(flushCache); 125 } 126 127 private void updatePageIncrement() { 128 ScrollBar vbar = getVerticalBar(); 129 if (vbar != null) { 130 Rectangle clientArea = getClientArea(); 131 int increment = clientArea.height - 5; 132 vbar.setPageIncrement(increment); 133 } 134 } 135 136 private void initializeScrollBars() { 137 ScrollBar hbar = getHorizontalBar(); 138 if (hbar != null) { 139 hbar.setIncrement(H_SCROLL_INCREMENT); 140 } 141 ScrollBar vbar = getVerticalBar(); 142 if (vbar != null) { 143 vbar.setIncrement(V_SCROLL_INCREMENT); 144 } 145 updatePageIncrement(); 146 } 147 } 148 | Popular Tags |