| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
| 5 | |
| 6 | import org.eclipse.swt.SWT; |
| 7 | import org.eclipse.swt.graphics.Point; |
| 8 | import org.eclipse.swt.graphics.Rectangle; |
| 9 | import org.eclipse.swt.widgets.Button; |
| 10 | import org.eclipse.swt.widgets.Composite; |
| 11 | import org.eclipse.swt.widgets.Control; |
| 12 | import org.eclipse.swt.widgets.Layout; |
| 13 | |
| 14 | /** |
| 15 | * Internal class for laying out the dialog. |
| 16 | */ |
| 17 | public class DialogCellLayout extends Layout { |
| 18 | |
| 19 | /** |
| 20 | * The current contents. |
| 21 | */ |
| 22 | private Control contents; |
| 23 | /** |
| 24 | * The button. |
| 25 | */ |
| 26 | private Button selButton; |
| 27 | private Button delButton; |
| 28 | |
| 29 | |
| 30 | public DialogCellLayout(Control contents, Button selectionButton, Button deleteButton) { |
| 31 | this.selButton = selectionButton; |
| 32 | this.delButton = deleteButton; |
| 33 | this.contents = contents; |
| 34 | } |
| 35 | |
| 36 | /* (non-Javadoc) |
| 37 | * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean) |
| 38 | */ |
| 39 | @Override |
| 40 | protected Point computeSize(Composite composite, int wHint, int hHint, |
| 41 | boolean force) { |
| 42 | if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { |
| 43 | return new Point(wHint, hHint); |
| 44 | } |
| 45 | Point contentsSize = contents.computeSize(SWT.DEFAULT, SWT.DEFAULT, |
| 46 | force); |
| 47 | Point buttonSize = selButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, |
| 48 | force); |
| 49 | // Just return the button width to ensure the button is not clipped |
| 50 | // if the label is long. |
| 51 | // The label will just use whatever extra width there is |
| 52 | Point result = new Point(buttonSize.x, Math.max(contentsSize.y, |
| 53 | buttonSize.y)); |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | /* (non-Javadoc) |
| 58 | * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean) |
| 59 | */ |
| 60 | @Override |
| 61 | protected void layout(Composite editor, boolean force) { |
| 62 | Rectangle bounds = editor.getClientArea(); |
| 63 | Point selSize = selButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, force); |
| 64 | Point delSize = delButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, force); |
| 65 | if (contents != null) { |
| 66 | contents.setBounds(bounds.x, 0, bounds.width - selSize.x - delSize.x, bounds.height); |
| 67 | } |
| 68 | selButton.setBounds(bounds.width - selSize.x, 0, selSize.x, bounds.height); |
| 69 | delButton.setBounds(bounds.width - selSize.x - delSize.x, 0, delSize.x, bounds.height); |
| 70 | } |
| 71 | |
| 72 | } |