| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.uruma.renderer.impl; |
| 17 | |
|
| 18 | |
import org.eclipse.swt.SWT; |
| 19 | |
import org.eclipse.swt.events.ControlEvent; |
| 20 | |
import org.eclipse.swt.events.ControlListener; |
| 21 | |
import org.eclipse.swt.graphics.Point; |
| 22 | |
import org.eclipse.swt.widgets.Control; |
| 23 | |
import org.eclipse.swt.widgets.CoolBar; |
| 24 | |
import org.eclipse.swt.widgets.CoolItem; |
| 25 | |
import org.eclipse.swt.widgets.ToolBar; |
| 26 | |
import org.eclipse.swt.widgets.ToolItem; |
| 27 | |
import org.seasar.uruma.component.jface.CoolBarComponent; |
| 28 | |
import org.seasar.uruma.context.PartContext; |
| 29 | |
import org.seasar.uruma.context.WidgetHandle; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 12 | public class CoolBarRenderer extends |
| 37 | |
AbstractCompositeRenderer<CoolBarComponent, CoolBar> { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
@Override |
| 44 | |
protected void doRenderComposite(final CoolBarComponent controlComponent, |
| 45 | |
final CoolBar control) { |
| 46 | 4 | } |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
@Override |
| 55 | |
protected void doRenderAfter(final CoolBar widget, |
| 56 | |
final CoolBarComponent uiComponent, final WidgetHandle parent, |
| 57 | |
final PartContext context) { |
| 58 | 4 | setChildlenSize(widget, uiComponent); |
| 59 | 4 | setResizeListener(widget, uiComponent); |
| 60 | 4 | } |
| 61 | |
|
| 62 | |
private void setChildlenSize(final CoolBar widget, |
| 63 | |
final CoolBarComponent uiComponent) { |
| 64 | 28 | for (CoolItem item : widget.getItems()) { |
| 65 | 24 | Control control = item.getControl(); |
| 66 | 24 | if (control == null) { |
| 67 | 0 | continue; |
| 68 | |
} |
| 69 | |
|
| 70 | 24 | Point controlSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); |
| 71 | 24 | Point itemSize = item.computeSize(controlSize.x, controlSize.y); |
| 72 | |
|
| 73 | 24 | Point minimumSize = controlSize; |
| 74 | 24 | if (control instanceof ToolBar) { |
| 75 | 8 | ToolBar bar = (ToolBar) control; |
| 76 | 8 | if (bar.getItemCount() > 0) { |
| 77 | 8 | ToolItem toolItem = bar.getItem(0); |
| 78 | 8 | minimumSize = new Point(toolItem.getBounds().width, |
| 79 | |
toolItem.getBounds().height); |
| 80 | |
} |
| 81 | |
} |
| 82 | 24 | item.setMinimumSize(minimumSize); |
| 83 | 24 | item.setPreferredSize(itemSize); |
| 84 | 24 | item.setSize(itemSize); |
| 85 | |
} |
| 86 | 4 | } |
| 87 | |
|
| 88 | |
private void setResizeListener(final CoolBar widget, |
| 89 | |
final CoolBarComponent uiComponent) { |
| 90 | 4 | widget.addControlListener(new ControlListener() { |
| 91 | |
public void controlMoved(final ControlEvent event) { |
| 92 | 4 | } |
| 93 | |
|
| 94 | 4 | public void controlResized(final ControlEvent event) { |
| 95 | 4 | widget.getParent().layout(); |
| 96 | 4 | } |
| 97 | |
}); |
| 98 | 4 | } |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
@Override |
| 104 | |
protected Class<CoolBar> getWidgetType() { |
| 105 | 12 | return CoolBar.class; |
| 106 | |
} |
| 107 | |
} |