下面列出了org.eclipse.swt.widgets.Composite#getLayoutData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Point betterComputeSize(Composite c, Point size, int wHint,
int hHint) {
if (c.getChildren().length == 0 && (size.x == 64 || size.y == 64)) {
Object ld = c.getLayoutData();
if (ld instanceof FormData) {
FormData fd = (FormData) ld;
if (fd.width != 0 && fd.height != 0) {
Rectangle trim = c.computeTrim (0, 0, fd.width, fd.height);
return new Point(trim.width, trim.height);
}
}
return new Point(1, 1);
}
if (size.x == 0 || size.y == 0) {
return size;
}
if (minWidth > 0 && size.x < minWidth) {
size.x = minWidth;
}
if (minHeight > 0 && size.y < minHeight) {
size.y = minHeight;
}
return size;
}
protected Point betterComputeSize(Composite c, Point size, int wHint, int hHint, boolean changed) {
if (c.getChildren().length == 0 && (size.x == 64 || size.y == 64)) {
Object ld = c.getLayoutData();
if (ld instanceof FormData) {
FormData fd = (FormData) ld;
if (fd.width != 0 && fd.height != 0) {
Rectangle trim = c.computeTrim (0, 0, fd.width, fd.height);
return new Point(trim.width, trim.height);
}
}
return new Point(1, 1);
}
if (size.x == 0 || size.y == 0) {
return size;
}
if (minWidth > 0 && size.x < minWidth) {
size.x = minWidth;
}
if (minHeight > 0 && size.y < minHeight) {
size.y = minHeight;
}
return size;
}
/**
* Creates the options configuration section of the find dialog.
*
* @param parent
* the parent composite
* @return the options configuration section
*/
private Composite createConfigPanel(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
panel.setLayout(layout);
Composite directionGroup = createDirectionGroup(panel);
setGridData(directionGroup, SWT.FILL, true, SWT.FILL, false);
Composite optionsGroup = createOptionsGroup(panel);
setGridData(optionsGroup, SWT.FILL, true, SWT.FILL, true);
((GridData) optionsGroup.getLayoutData()).horizontalSpan = 2;
return panel;
}
@Override
protected void createRightContents(Composite rightChild) {
super.createRightContents(rightChild);
Object data = rightChild.getLayoutData();
if(data instanceof GridData){
((GridData)data).verticalIndent = 12;
}
createLabel("Text:", createControlGDFill(2), getLabelToolTipText(ConfigurationLegal.ATTR_TEXT)); // $NLX-ApplicationLayoutLegalPanel.Text-1$
GridData gd = new GridData();
gd.horizontalIndent = getControlIndentAmt();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
gd.widthHint = 300;
createMultiLineTextComputed(ConfigurationLegal.ATTR_TEXT, gd, 13);
}
public ApplicationLayoutCallbackPanel(IPanelExtraData extra, Composite parent) {
super(parent, SWT.NONE);
initialize();
GridData gd = createFillGD(getNumParentColumns());
if (parent.getLayoutData() instanceof GridData) {
int width = ((GridData)parent.getLayoutData()).widthHint;
if (width > 0)
gd.widthHint = width;
}
setLayoutData(gd);
setExtraData(extra);
setCurrentParent(this);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 10;
this.setLayout(gridLayout);
createCallbackControls();
}
@Override
protected void createRightContents(Composite rightChild) {
((GridData)rightChild.getLayoutData()).horizontalAlignment = SWT.FILL;
cmplxComposite = new ComplexPanelComposite(rightChild, SWT.NONE);
initComplexDataNode(cmplxComposite);
cmplxComposite.updatePanelData(data);
cmplxComposite.setLayout(SWTLayoutUtils.createLayoutNoMarginDefaultSpacing(1));
cmplxComposite.setLayoutData(SWTLayoutUtils.createGDFill());
cmplxComposite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
TreeItem[] items = ruleViewer.getTree().getItems();
if(items != null && items.length > 0){
Object firstItem = items[0].getData();
ruleViewer.setSelection(new StructuredSelection(firstItem));
}
}
@Override
protected void createRightContents(Composite rightChild) {
((GridData)rightChild.getLayoutData()).horizontalAlignment = SWT.FILL;
_complexComposite = new ComplexPanelComposite(rightChild, SWT.NONE);
initComplexDataNode(_complexComposite);
_complexComposite.updatePanelData(_data);
_complexComposite.setLayout(SWTLayoutUtils.createLayoutNoMarginDefaultSpacing(1));
_complexComposite.setLayoutData(SWTLayoutUtils.createGDFill());
_complexComposite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
TreeItem[] items = _linkViewer.getTree().getItems();
if(items != null && items.length > 0){
Object firstItem = items[0].getData();
_linkViewer.setSelection(new StructuredSelection(firstItem));
}
}
@Override
public void createControl(final Composite composite, final TabbedPropertySheetWidgetFactory widgetFactory, final ExtensibleGridPropertySection extensibleGridPropertySection) {
GridData gd = (GridData) composite.getLayoutData();
gd.grabExcessHorizontalSpace = true;
ControlDecoration controlDecoration = new ControlDecoration(composite.getChildren()[0], SWT.RIGHT);
controlDecoration.setDescriptionText(Messages.bind(Messages.warningDisplayLabelMaxLength, MAX_LENGTH, MAX_LENGTH));
controlDecoration.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
expressionViewer = new ExpressionViewer(composite,SWT.BORDER,widgetFactory,editingDomain, ProcessPackage.Literals.FLOW_ELEMENT__DYNAMIC_LABEL);
expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
expressionViewer.addFilter(new AvailableExpressionTypeFilter(new String[]{ExpressionConstants.CONSTANT_TYPE,ExpressionConstants.VARIABLE_TYPE,ExpressionConstants.PARAMETER_TYPE,ExpressionConstants.SCRIPT_TYPE}));
expressionViewer.setExpressionNameResolver(new DefaultExpressionNameResolver("displayName"));
expressionViewer.setInput(eObject) ;
expressionViewer.setMessage(Messages.dynamicLabelHint) ;
expressionViewer.addExpressionValidator(new ExpressionLengthValidator(MAX_LENGTH));
refreshDataBindingContext();
}
@Override
public void initialize(IManagedForm form) {
parmSection = editor.getParameterPage().getParameterSection();
super.initialize(form);
sectionClient = newComposite(getSection());
tree = newTree(sectionClient);
Composite buttonContainer = new2ColumnComposite(sectionClient);
((GridData) buttonContainer.getLayoutData()).grabExcessVerticalSpace = false;
createOverrideButton = newPushButton(buttonContainer, "Create Override",
"Overrides allow an aggregate to replace a parameter's value in one or more of its delegates");
createNonSharedOverrideButton = newPushButton(buttonContainer, "Create non-shared Override",
"Click here to create a non-shared override for this parameter");
tree.addListener(SWT.MouseDoubleClick, this); // edit gesture
tree.addListener(SWT.MouseHover, this); // hover
enableBorders(sectionClient);
toolkit.paintBordersFor(sectionClient);
}
@Override
public void initialize(IManagedForm form) {
super.initialize(form);
((GridData) this.getSection().getLayoutData()).grabExcessVerticalSpace = false;
Composite sectionClient = new2ColumnComposite(this.getSection());
((GridData) sectionClient.getLayoutData()).grabExcessVerticalSpace = false;
// FrameworkImplementation choose, 2 radio buttons
if (isAeDescriptor() || isCasConsumerDescriptor()) {
toolkit.createLabel(sectionClient, "Implementation Language").setToolTipText(
"Choose the implementation language here.");
Composite buttons = new2ColumnComposite(sectionClient);
cppButton = newRadioButton(buttons, "C/C++", "C/C++", NOT_SELECTED);
javaButton = newRadioButton(buttons, "Java", "Java", SELECTED);
// DescriptorType choose, 2 radio buttons
toolkit.createLabel(sectionClient, "Engine Type").setToolTipText(
"Choose the type of the engine here.");
buttons = new2ColumnComposite(sectionClient);
primitiveButton = newRadioButton(buttons, "Primitive", S_, SELECTED);
aggregateButton = newRadioButton(buttons, "Aggregate", S_, NOT_SELECTED);
}
}
@Override
protected Control createDialogArea(final Composite parent) {
final Object layoutData = parent.getLayoutData();
if (layoutData instanceof GridData) {
((GridData) layoutData).heightHint = DEFAULT_SIZE.x;
((GridData) layoutData).widthHint = DEFAULT_SIZE.y;
}
final Browser browser = new Browser(parent, NONE);
browser.setText(html);
return browser;
}
@Override
protected Composite createToolTipContentArea(final Event event, final Composite parent) {
final Object layoutData = parent.getLayoutData();
final StyledText text = lastDescriptor.toStyledText(parent, NONE);
if (layoutData instanceof GridData) {
((GridData) layoutData).heightHint = text.getBounds().height;
((GridData) layoutData).widthHint = text.getBounds().width;
}
return parent;
}
private Label createWrapLabel(String text) {
Composite parent = getCurrentParent();
Label t = new CustomLabel(parent, SWT.WRAP | SWT.READ_ONLY, ""); //$NON-NLS-1$
t.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
GridData gd = createSpanGD(2);
if (parent.getLayoutData() instanceof GridData) {
int width = ((GridData)parent.getLayoutData()).widthHint;
if (width > getControlIndentAmt())
gd.widthHint = width - getControlIndentAmt();
}
t.setLayoutData(gd);
t.setText(text);
return t;
}
/**
* New centered 2 span composite.
*
* @param parent the parent
* @return the composite
*/
// this composite spans col 1 & 2, out of a 4 column (0, 1, 2, 3) grid layout
public Composite newCentered2SpanComposite(Composite parent) {
spacer(parent); // skip over col 0
Composite composite = newComposite(parent);
((GridData) composite.getLayoutData()).horizontalSpan = 2;
return composite;
}
/**
* Setup 1 column layout.
*
* @param managedForm the managed form
* @return the composite
*/
public Composite setup1ColumnLayout(IManagedForm managedForm) {
final ScrolledForm sform = managedForm.getForm();
final Composite form = sform.getBody();
form.setLayout(new GridLayout(1, false)); // this is required !
Composite xtra = toolkit.createComposite(form);
xtra.setLayout(new GridLayout(1, false));
xtra.setLayoutData(new GridData(GridData.FILL_BOTH));
Control c = form.getParent();
while (!(c instanceof ScrolledComposite))
c = c.getParent();
((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
return xtra;
}
/**
* Setup 2 column layout.
*
* @param managedForm the managed form
* @param w1 the w 1
* @param w2 the w 2
* @return the form 2 panel
*/
public Form2Panel setup2ColumnLayout(IManagedForm managedForm, int w1, int w2) {
final ScrolledForm sform = managedForm.getForm();
final Composite form = sform.getBody();
form.setLayout(new GridLayout(1, false)); // this is required !
Composite xtra = toolkit.createComposite(form);
xtra.setLayout(new GridLayout(1, false));
xtra.setLayoutData(new GridData(GridData.FILL_BOTH));
Control c = xtra.getParent();
while (!(c instanceof ScrolledComposite))
c = c.getParent();
((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
((GridData) xtra.getLayoutData()).heightHint = c.getSize().y;
sashForm = new SashForm(xtra, SWT.HORIZONTAL);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); // needed
leftPanel = newComposite(sashForm);
((GridLayout) leftPanel.getLayout()).marginHeight = 5;
((GridLayout) leftPanel.getLayout()).marginWidth = 5;
rightPanel = newComposite(sashForm);
((GridLayout) rightPanel.getLayout()).marginHeight = 5;
((GridLayout) rightPanel.getLayout()).marginWidth = 5;
sashForm.setWeights(new int[] { w1, w2 });
leftPanelPercent = (float) w1 / (float) (w1 + w2);
rightPanelPercent = (float) w2 / (float) (w1 + w2);
rightPanel.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
setSashFormWidths();
}
});
return new Form2Panel(form, leftPanel, rightPanel);
}
@Override
public void initialize(IManagedForm form) {
super.initialize(form);
// set up Composite to hold widgets in the section
Composite sectionClient = newComposite(getSection());
enableBorders(sectionClient);
Composite buttonContainer = new2ColumnComposite(sectionClient);
((GridData) buttonContainer.getLayoutData()).grabExcessVerticalSpace = false;
((GridData) buttonContainer.getLayoutData()).grabExcessHorizontalSpace = false;
((GridData) buttonContainer.getLayoutData()).horizontalAlignment = SWT.RIGHT;
addButton = newPushButton(buttonContainer, "Add...", "Click here to add an import");
removeButton = newPushButton(buttonContainer, "Remove",
"Click here to remove the selected import.");
setDataPathButton = newPushButton(buttonContainer, "Set DataPath",
"Click here to view or set the data path to use when resolving imports by name.");
importTable = newTable(sectionClient, SWT.FULL_SELECTION, NO_MIN_HEIGHT);
newTableColumn(importTable).setText("Kind");
newTableColumn(importTable).setText("Location/Name");
importTable.setHeaderVisible(true);
packTable(importTable);
// in addition to normal keyup and mouse up:
importTable.addListener(SWT.MouseHover, this);
importTable.addListener(SWT.MouseDown, this);
toolkit.paintBordersFor(sectionClient);
}
/**
* Resizes the Section's client and updates the Property Viewer's
* {@link ScrolledComposite} to account for GridLayouts in the client.
*/
private void resizePropertyView() {
// Disable re-drawing for the ScrolledComposite.
scrollComposite.setRedraw(false);
int verticalPadding = scrollComposite.getHorizontalBar().getSize().y;
int horizontalPadding = scrollComposite.getVerticalBar().getSize().x;
Rectangle clientArea = scrollComposite.getClientArea();
Point clientAreaSize = new Point(clientArea.width - horizontalPadding,
clientArea.height - verticalPadding);
// Recompute the size of the first Composite in the ScrolledComposite
// based on the width of the ScrolledComposite's client area.
Point size = scrollCompositeClient.computeSize(clientAreaSize.x,
clientAreaSize.y);
// Update the size of the ScrolledComposite's client.
scrollCompositeClient.setSize(size);
// Set the minimum size at which the ScrolledComposite will start
// drawing scroll bars. This should be the size of its client area minus
// the spaces the scroll bars would consume.
scrollComposite.setMinSize(clientAreaSize.x + 1, clientAreaSize.y + 1);
// We need to call layout() so the ScrolledComposite will update.
scrollComposite.layout();
// Set the height hint for the Section's parent Composite. This keeps
// the TableViewer from going beyond the bottom edge of the Properties
// Viewer. We want to keep the add and delete buttons visible, and the
// TableViewer already has its own scroll bars!
Composite sectionParent = section.getParent();
GridData gridData = (GridData) sectionParent.getLayoutData();
GridLayout gridLayout = (GridLayout) sectionParent.getParent()
.getLayout();
gridData.heightHint = sectionParent.getParent().getSize().y
- gridLayout.marginTop;
// The parent of the Section has a FillLayout. Its parent has a
// GridLayout, but sometimes it does not update. Tell it to layout so
// the Section's parent will update its size.
section.getParent().getParent().layout();
// Enable re-drawing for the ScrolledComposite.
scrollComposite.setRedraw(true);
return;
}
@Override
public void initialize(IManagedForm form) {
super.initialize(form);
Composite sectionClient = new2ColumnComposite(this.getSection());
// sectionClient (2 col)
// label / ccombo
// comp2
// comp2a fcButtonContainer
// label / text
((GridData) sectionClient.getLayoutData()).grabExcessHorizontalSpace = false;
flowChoiceLabel = newLabelWithTip(sectionClient, Messages.getString("FlowSection.FlowKind"), //$NON-NLS-1$
Messages.getString("FlowSection.FlowKindTip")); //$NON-NLS-1$
flowControllerChoice = newCComboWithTip(sectionClient, Messages
.getString("FlowSection.FlowKindTip")); //$NON-NLS-1$
flowControllerChoice.add(FIXED_FLOW);
flowControllerChoice.add(CAPABILITY_LANGUAGE_FLOW);
flowControllerChoice.add(USER_DEFINED_FLOW);
Composite comp2 = new2ColumnComposite(sectionClient);
((GridData) comp2.getLayoutData()).horizontalSpan = 2;
((GridData) comp2.getLayoutData()).grabExcessVerticalSpace = false;
Composite comp2a = new2ColumnComposite(comp2);
Composite fcButtonContainer = newButtonContainer(comp2, VERTICAL_BUTTONS, 0);
flowControllerLabel = newLabelWithTip(comp2a, "Flow Controller:",
"The XML descriptor for the Custom Flow Controller");
flowControllerGUI = newUnUpdatableTextWithTip(comp2a, "",
"The XML descriptor for the Custom Flow Controller");
flowControllerGUI.addListener(SWT.MouseDown, this);
flowControllerGUI.addListener(SWT.MouseHover, this);
flowControllerKeyLabel = newLabelWithTip(comp2a, "Key Name:",
"A unique key name for this Flow Controller");
flowControllerKeyGUI = newUnUpdatableTextWithTip(comp2a, "",
"A unique key name for this Flow Controller");
// flowControllerSpecifierLabel = newLabelWithTip(sectionClient, "Specify:",
// "Click the Browse or Search button to specify a Flow Controller");
// Composite fcButtonContainer = newButtonContainer(sectionClient, HORIZONTAL_BUTTONS, 150);
specifyFlowControllerImportButton = newPushButton(fcButtonContainer, "Browse...",
"Click here to specify a locally defined Flow Controller", ENABLED);
findFlowControllerDescriptorButton = newPushButton(fcButtonContainer, "Search",
"Click here to search for a Flow Controller", ENABLED);
// flow list
Composite flowComposite = new2ColumnComposite(sectionClient);
((GridData) flowComposite.getLayoutData()).horizontalSpan = 2;
enableBorders(flowComposite);
toolkit.paintBordersFor(flowComposite);
flowList = newTable(flowComposite, SWT.FULL_SELECTION, 0);
// Buttons
final Composite buttonContainer = newButtonContainer(flowComposite, VERTICAL_BUTTONS, 70);
upButton = newPushButton(buttonContainer, S_UP,
Messages.getString("FlowSection.upTip"), !ENABLED); //$NON-NLS-1$
downButton = newPushButton(buttonContainer, S_DOWN,
Messages.getString("FlowSection.downTip"), !ENABLED); //$NON-NLS-1$
enableBorders(sectionClient);
toolkit.paintBordersFor(sectionClient);
}