|
Lines 15-34
Link Here
|
| 15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
| 16 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
| 17 |
|
17 |
|
|
|
18 |
import org.eclipse.jface.layout.GridDataFactory; |
| 19 |
import org.eclipse.jface.layout.GridLayoutFactory; |
| 18 |
import org.eclipse.jface.wizard.WizardPage; |
20 |
import org.eclipse.jface.wizard.WizardPage; |
| 19 |
import org.eclipse.mylar.tasks.core.LocalAttachment; |
21 |
import org.eclipse.mylar.tasks.core.LocalAttachment; |
| 20 |
import org.eclipse.swt.SWT; |
22 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.graphics.GC; |
23 |
import org.eclipse.swt.custom.ScrolledComposite; |
|
|
24 |
import org.eclipse.swt.events.ControlAdapter; |
| 25 |
import org.eclipse.swt.events.ControlEvent; |
| 26 |
import org.eclipse.swt.events.PaintEvent; |
| 27 |
import org.eclipse.swt.events.PaintListener; |
| 22 |
import org.eclipse.swt.graphics.Image; |
28 |
import org.eclipse.swt.graphics.Image; |
| 23 |
import org.eclipse.swt.graphics.Point; |
|
|
| 24 |
import org.eclipse.swt.graphics.Rectangle; |
29 |
import org.eclipse.swt.graphics.Rectangle; |
| 25 |
import org.eclipse.swt.layout.GridData; |
30 |
import org.eclipse.swt.layout.GridData; |
| 26 |
import org.eclipse.swt.layout.GridLayout; |
31 |
import org.eclipse.swt.layout.GridLayout; |
| 27 |
import org.eclipse.swt.widgets.Canvas; |
32 |
import org.eclipse.swt.widgets.Canvas; |
| 28 |
import org.eclipse.swt.widgets.Composite; |
33 |
import org.eclipse.swt.widgets.Composite; |
| 29 |
import org.eclipse.swt.widgets.Event; |
|
|
| 30 |
import org.eclipse.swt.widgets.Label; |
34 |
import org.eclipse.swt.widgets.Label; |
| 31 |
import org.eclipse.swt.widgets.Listener; |
|
|
| 32 |
import org.eclipse.swt.widgets.ScrollBar; |
35 |
import org.eclipse.swt.widgets.ScrollBar; |
| 33 |
import org.eclipse.swt.widgets.Text; |
36 |
import org.eclipse.swt.widgets.Text; |
| 34 |
|
37 |
|
|
Lines 125-197
Link Here
|
| 125 |
|
128 |
|
| 126 |
private void createImagePreview(Composite composite, LocalAttachment attachment) { |
129 |
private void createImagePreview(Composite composite, LocalAttachment attachment) { |
| 127 |
final Image image = new Image(composite.getDisplay(), attachment.getFilePath()); |
130 |
final Image image = new Image(composite.getDisplay(), attachment.getFilePath()); |
| 128 |
final Canvas canvas = new Canvas(composite, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL |
131 |
final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL |
| 129 |
| SWT.H_SCROLL | SWT.BORDER); |
132 |
| SWT.BORDER); |
| 130 |
canvas.setLayoutData(new GridData(GridData.FILL_BOTH)); |
133 |
scrolledComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); |
| 131 |
|
134 |
scrolledComposite.setExpandHorizontal(true); |
| 132 |
// Adapted from snippit 48 |
135 |
scrolledComposite.setExpandVertical(true); |
| 133 |
// http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java?rev=HEAD |
136 |
|
| 134 |
final Point origin = new Point(0, 0); |
137 |
Composite canvasComposite = new Composite(scrolledComposite, SWT.NONE); |
| 135 |
final ScrollBar hBar = canvas.getHorizontalBar(); |
138 |
canvasComposite.setLayout(GridLayoutFactory.fillDefaults().create()); |
| 136 |
hBar.addListener(SWT.Selection, new Listener() { |
139 |
Canvas canvas = new Canvas(canvasComposite, SWT.NONE); |
| 137 |
public void handleEvent(Event e) { |
140 |
final Rectangle imgSize = image.getBounds(); |
| 138 |
int hSelection = hBar.getSelection(); |
141 |
canvas.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).hint( |
| 139 |
int destX = -hSelection - origin.x; |
142 |
imgSize.width, imgSize.height).create()); |
| 140 |
Rectangle rect = image.getBounds(); |
143 |
canvas.addPaintListener(new PaintListener() { |
| 141 |
canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); |
144 |
|
| 142 |
origin.x = -hSelection; |
145 |
public void paintControl(PaintEvent e) { |
| 143 |
} |
146 |
e.gc.drawImage(image, 0, 0); |
| 144 |
}); |
|
|
| 145 |
final ScrollBar vBar = canvas.getVerticalBar(); |
| 146 |
vBar.addListener(SWT.Selection, new Listener() { |
| 147 |
public void handleEvent(Event e) { |
| 148 |
int vSelection = vBar.getSelection(); |
| 149 |
int destY = -vSelection - origin.y; |
| 150 |
Rectangle rect = image.getBounds(); |
| 151 |
canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); |
| 152 |
origin.y = -vSelection; |
| 153 |
} |
| 154 |
}); |
| 155 |
canvas.addListener(SWT.Resize, new Listener() { |
| 156 |
public void handleEvent(Event e) { |
| 157 |
Rectangle rect = image.getBounds(); |
| 158 |
Rectangle client = canvas.getClientArea(); |
| 159 |
hBar.setMaximum(rect.width); |
| 160 |
vBar.setMaximum(rect.height); |
| 161 |
hBar.setThumb(Math.min(rect.width, client.width)); |
| 162 |
vBar.setThumb(Math.min(rect.height, client.height)); |
| 163 |
int hPage = rect.width - client.width; |
| 164 |
int vPage = rect.height - client.height; |
| 165 |
int hSelection = hBar.getSelection(); |
| 166 |
int vSelection = vBar.getSelection(); |
| 167 |
if (hSelection >= hPage) { |
| 168 |
if (hPage <= 0) |
| 169 |
hSelection = 0; |
| 170 |
origin.x = -hSelection; |
| 171 |
} |
| 172 |
if (vSelection >= vPage) { |
| 173 |
if (vPage <= 0) |
| 174 |
vSelection = 0; |
| 175 |
origin.y = -vSelection; |
| 176 |
} |
| 177 |
canvas.redraw(); |
| 178 |
} |
147 |
} |
|
|
148 |
|
| 179 |
}); |
149 |
}); |
| 180 |
canvas.addListener(SWT.Paint, new Listener() { |
150 |
canvas.setSize(imgSize.width, imgSize.height); |
| 181 |
public void handleEvent(Event e) { |
151 |
scrolledComposite.setMinSize(imgSize.width, imgSize.height); |
| 182 |
GC gc = e.gc; |
152 |
scrolledComposite.setContent(canvasComposite); |
| 183 |
gc.drawImage(image, origin.x, origin.y); |
153 |
scrolledComposite.addControlListener(new ControlAdapter() { |
| 184 |
Rectangle rect = image.getBounds(); |
154 |
|
| 185 |
Rectangle client = canvas.getClientArea(); |
155 |
@Override |
| 186 |
int marginWidth = client.width - rect.width; |
156 |
public void controlResized(ControlEvent e) { |
| 187 |
if (marginWidth > 0) { |
157 |
Rectangle clientArea = scrolledComposite.getClientArea(); |
| 188 |
gc.fillRectangle(rect.width, 0, marginWidth, client.height); |
158 |
|
| 189 |
} |
159 |
ScrollBar hBar = scrolledComposite.getHorizontalBar(); |
| 190 |
int marginHeight = client.height - rect.height; |
160 |
hBar.setMinimum(1); |
| 191 |
if (marginHeight > 0) { |
161 |
hBar.setMaximum(clientArea.width - imgSize.width); |
| 192 |
gc.fillRectangle(0, rect.height, client.width, marginHeight); |
162 |
hBar.setPageIncrement(hBar.getThumb()); |
| 193 |
} |
163 |
hBar.setIncrement(10); |
|
|
164 |
|
| 165 |
ScrollBar vBar = scrolledComposite.getVerticalBar(); |
| 166 |
vBar.setMinimum(0); |
| 167 |
vBar.setMaximum(clientArea.height - imgSize.height); |
| 168 |
vBar.setPageIncrement(vBar.getThumb()); |
| 169 |
vBar.setIncrement(10); |
| 194 |
} |
170 |
} |
|
|
171 |
|
| 195 |
}); |
172 |
}); |
| 196 |
} |
173 |
} |