下面列出了org.eclipse.swt.widgets.Composite#getLayout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates the buttons for this dialog's button bar.
* <p>
* The <code>WizardDialog</code> implementation of this framework method
* prevents the parent composite's columns from being made equal width in
* order to remove the margin between the Back and Next buttons.
* </p>
*
* @param parent
* the parent composite to contain the buttons
*/
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false;
if (wizard.isHelpAvailable()) {
helpButton = createButton(parent, IDialogConstants.HELP_ID,
IDialogConstants.HELP_LABEL, false);
}
if (wizard.needsPreviousAndNextButtons()) {
createPreviousAndNextButtons(parent);
}
finishButton = createButton(parent, IDialogConstants.FINISH_ID,
IDialogConstants.FINISH_LABEL, true);
cancelButton = createCancelButton(parent);
if (parent.getDisplay().getDismissalAlignment() == SWT.RIGHT) {
// Make the default button the right-most button.
// See also special code in org.eclipse.jface.dialogs.Dialog#initializeBounds()
finishButton.moveBelow(null);
}
}
private void createListDialogField(Composite composite) {
Composite c= new Composite(composite, SWT.NONE);
c.setFont(composite.getFont());
c.setLayout(createGridLayout(3));
c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 4, 0));
((GridLayout) c.getLayout()).marginWidth= 0;
String[] buttonlabels= new String[] { JavadocExportMessages.JavadocStandardWizardPage_selectallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_clearallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_configurebutton_label};
JavadocLinkDialogLabelProvider labelProvider= new JavadocLinkDialogLabelProvider();
ListAdapter adapter= new ListAdapter();
fListDialogField= new CheckedListDialogField<JavadocLinkRef>(adapter, buttonlabels, labelProvider);
fListDialogField.setDialogFieldListener(adapter);
fListDialogField.setCheckAllButtonIndex(0);
fListDialogField.setUncheckAllButtonIndex(1);
fListDialogField.setViewerComparator(new ViewerComparator());
createLabel(c, SWT.NONE, JavadocExportMessages.JavadocStandardWizardPage_referencedclasses_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 4, 0));
fListDialogField.doFillIntoGrid(c, 3);
LayoutUtil.setHorizontalGrabbing(fListDialogField.getListControl(null));
fListDialogField.enableButton(2, false);
}
/**
* Create contents of the dialog.
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite cmp_Container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) cmp_Container.getLayout();
gridLayout.verticalSpacing = 10;
gridLayout.horizontalSpacing = 10;
IntegerSpinner spn_Value = new IntegerSpinner(cmp_Container, SWT.NONE);
this.spn_Value[0] = spn_Value;
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
spn_Value.setLayoutData(gd);
Label lbl_Unit = new Label(cmp_Container, SWT.NONE);
this.lbl_Unit[0] = lbl_Unit;
lbl_Unit.setText(unitText);
cmp_Container.pack();
return cmp_Container;
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
* @param marginWidth The margin width to be used by the composite
* @param marginHeight The margin height to be used by the composite
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int marginWidth, int marginHeight) {
int nCulumns= getNumberOfColumns(editors);
Control[][] controls= new Control[editors.length][];
for (int i= 0; i < editors.length; i++) {
controls[i]= editors[i].doFillIntoGrid(parent, nCulumns);
}
if (labelOnTop) {
nCulumns--;
modifyLabelSpans(controls, nCulumns);
}
GridLayout layout= null;
if (parent.getLayout() instanceof GridLayout) {
layout= (GridLayout) parent.getLayout();
} else {
layout= new GridLayout();
}
if (marginWidth != SWT.DEFAULT) {
layout.marginWidth= marginWidth;
}
if (marginHeight != SWT.DEFAULT) {
layout.marginHeight= marginHeight;
}
layout.numColumns= nCulumns;
parent.setLayout(layout);
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
* @param marginWidth The margin width to be used by the composite
* @param marginHeight The margin height to be used by the composite
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int marginWidth, int marginHeight) {
int nCulumns= getNumberOfColumns(editors);
Control[][] controls= new Control[editors.length][];
for (int i= 0; i < editors.length; i++) {
controls[i]= editors[i].doFillIntoGrid(parent, nCulumns);
}
if (labelOnTop) {
nCulumns--;
modifyLabelSpans(controls, nCulumns);
}
GridLayout layout= null;
if (parent.getLayout() instanceof GridLayout) {
layout= (GridLayout) parent.getLayout();
} else {
layout= new GridLayout();
}
if (marginWidth != SWT.DEFAULT) {
layout.marginWidth= marginWidth;
}
if (marginHeight != SWT.DEFAULT) {
layout.marginHeight= marginHeight;
}
layout.numColumns= nCulumns;
parent.setLayout(layout);
}
/**
* Creates a composite and fills in the given editors.
* @param labelOnTop Defines if the label of all fields should be on top of the fields
* @param marginWidth The margin width to be used by the composite
* @param marginHeight The margin height to be used by the composite
*/
public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int marginWidth, int marginHeight) {
int nCulumns= getNumberOfColumns(editors);
Control[][] controls= new Control[editors.length][];
for (int i= 0; i < editors.length; i++) {
controls[i]= editors[i].doFillIntoGrid(parent, nCulumns);
}
if (labelOnTop) {
nCulumns--;
modifyLabelSpans(controls, nCulumns);
}
GridLayout layout= null;
if (parent.getLayout() instanceof GridLayout) {
layout= (GridLayout) parent.getLayout();
} else {
layout= new GridLayout();
}
if (marginWidth != SWT.DEFAULT) {
layout.marginWidth= marginWidth;
}
if (marginHeight != SWT.DEFAULT) {
layout.marginHeight= marginHeight;
}
layout.numColumns= nCulumns;
parent.setLayout(layout);
}
public static Label separater(final Composite composite, final int span) {
final Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
gridData.heightHint = 1;
// gridData.horizontalIndent = Resources.INDENT;
if (span > 0) {
gridData.horizontalSpan = span;
} else {
gridData.horizontalSpan = ((GridLayout) composite.getLayout()).numColumns;
}
label.setLayoutData(gridData);
return label;
}
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 1;
Link desc = new Link(composite, SWT.NONE);
desc.setText(Messages.EmulatorsStatusHandler_Message);
desc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Program.launch(WPConstants.SDK_DOWNLOAD_URL);
}
});
getShell().setText(Messages.EmulatorsStatusHandler_Title);
return composite;
}
@Override
public void createControl(Composite parent) {
super.createControl(parent);
final Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_BOTH);
((GridLayout) comp.getLayout()).verticalSpacing = 0;
createProjectEditor(comp);
createVerticalSpacer(comp, 1);
createMainTypeEditor(comp, LauncherMessages.JavaMainTab_Main_cla_ss__4);
createVerticalSpacer(comp, 1);
createLaunchOptionEditor(comp, Messages.MainLaunchConfigurationTab_10);
setControl(comp);
}
private void findHeader(Composite row) {
Control[] children = row.getParent().getChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Composite) {
Composite child = (Composite) children[i];
Layout layout = child.getLayout();
if (layout instanceof HeaderLayout) {
delegate = (HeaderLayout) layout;
addListenersToDelegate(row, (HeaderLayout) layout);
return;
}
}
}
}
/**
* Creates the Cancel button for this wizard dialog. Creates a standard (<code>SWT.PUSH</code>)
* button and registers for its selection events. Note that the number of
* columns in the button bar composite is incremented. The Cancel button is
* created specially to give it a removeable listener.
*
* @param parent
* the parent button bar
* @return the new Cancel button
*/
private Button createCancelButton(Composite parent) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText(IDialogConstants.CANCEL_LABEL);
setButtonLayoutData(button);
button.setFont(parent.getFont());
button.setData(new Integer(IDialogConstants.CANCEL_ID));
button.addSelectionListener(cancelListener);
return button;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite topControl = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) topControl.getLayout();
gridLayout.numColumns = 2;
// gridLayout.marginHeight = 0;
// gridLayout.marginWidth = 0;
iconAndMessageWidget.createComponentInlined(topControl);
iconAndMessageWidget.messageControlLayoutData().widthHint =
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
return topControl;
}
/**
* Enable borders.
*
* @param composite the composite
*/
public void enableBorders(Composite composite) {
GridLayout g = (GridLayout) composite.getLayout();
if (g.marginHeight < 2)
g.marginHeight = 2;
if (g.marginWidth < 1)
g.marginWidth = 1;
}
public void createViewer(final Composite parent) {
if (parent == null) { return; }
if (viewer == null) {
viewer = new ParameterExpandBar(parent, SWT.V_SCROLL, areItemsClosable(), areItemsPausable(), false, false,
this);
final Object layout = parent.getLayout();
if (layout instanceof GridLayout) {
final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
viewer.setLayoutData(data);
}
viewer.computeSize(parent.getSize().x, SWT.DEFAULT);
viewer.setSpacing(5);
}
}
@Override
public void createControl(Composite parent) {
Font font = parent.getFont();
Group group = createGroup(parent, "Working directory:", 2, 1, GridData.FILL_HORIZONTAL);
setControl(group);
// PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IJavaDebugHelpContextIds.WORKING_DIRECTORY_BLOCK);
//default choice
Composite comp = createComposite(group, font, 2, 2, GridData.FILL_BOTH, 0, 0);
fUseDefaultDirButton = createRadioButton(comp, "Default:");
fUseDefaultDirButton.addSelectionListener(fListener);
fWorkingDirText = createSingleText(comp, 1);
fWorkingDirText.addModifyListener(fListener);
fWorkingDirText.setEditable(false);
//user enter choice
fUseOtherDirButton = createRadioButton(comp, "Other:");
fUseOtherDirButton.addSelectionListener(fListener);
fOtherWorkingText = createSingleText(comp, 1);
fOtherWorkingText.addModifyListener(fListener);
//buttons
Composite buttonComp = createComposite(comp, font, 3, 2, GridData.HORIZONTAL_ALIGN_END);
GridLayout ld = (GridLayout) buttonComp.getLayout();
ld.marginHeight = 1;
ld.marginWidth = 0;
fWorkspaceButton = createPushButton(buttonComp, "Workspace...", null);
fWorkspaceButton.addSelectionListener(fListener);
fFileSystemButton = createPushButton(buttonComp, "File System...", null);
fFileSystemButton.addSelectionListener(fListener);
fVariablesButton = createPushButton(buttonComp, "Variables...", null);
fVariablesButton.addSelectionListener(fListener);
}
public final void createControl(Composite parent) {
Font font = parent.getFont();
group = SWTFactory.createGroup(parent, blockTitle, 2, 1, GridData.FILL_HORIZONTAL);
setControl(group);
//default choice
Composite comp = SWTFactory.createComposite(group, font, 2, 2, GridData.FILL_BOTH, 0, 0);
fRbDefaultDir = SWTFactory.createRadiobutton(comp, Messages.CompilerWorkingDirectoryBlock_Default+':', 1);
fRbDefaultDir.addSelectionListener(fListener);
fDefaultDirText = SWTFactory.createSingleText(comp, 1);
fDefaultDirText.addModifyListener(fListener);
fDefaultDirText.setEnabled(false);
//user enter choice
fRbOtherDir = SWTFactory.createRadiobutton(comp, Messages.CompilerWorkingDirectoryBlock_Other+':', 1);
fRbOtherDir.addSelectionListener(fListener);
fOtherDirText = SWTFactory.createSingleText(comp, 1);
fOtherDirText.addModifyListener(fListener);
//buttons
Composite buttonComp = SWTFactory.createComposite(comp, font, 3, 2, GridData.HORIZONTAL_ALIGN_END);
GridLayout ld = (GridLayout)buttonComp.getLayout();
ld.marginHeight = 1;
ld.marginWidth = 0;
fWorkspaceButton = createPushButton(buttonComp, Messages.CompilerWorkingDirectoryBlock_Workspace, null);
fWorkspaceButton.addSelectionListener(fListener);
fFileSystemButton = createPushButton(buttonComp, Messages.CompilerWorkingDirectoryBlock_FileSystem, null);
fFileSystemButton.addSelectionListener(fListener);
fVariablesButton = createPushButton(buttonComp, Messages.CompilerWorkingDirectoryBlock_Variables, null);
fVariablesButton.addSelectionListener(fListener);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
GridLayout layout= (GridLayout)parent.getLayout();
layout.numColumns++;
layout.makeColumnsEqualWidth= false;
Label label= new Label(parent, SWT.NONE);
GridData data= new GridData();
data.widthHint= layout.horizontalSpacing;
label.setLayoutData(data);
super.createButtonsForButtonBar(parent);
}
@Override
protected void fillClientArea(Composite parent) {
//change the parents layout to only have one column instead of two
Object layoutDataObj = parent.getLayout();
if(layoutDataObj instanceof GridLayout){
GridLayout layout = (GridLayout)layoutDataObj;
layout.numColumns = 1;
}
//crate a comboBox to select a design element type if more than one is specified
if(hasMultipleDesignElements()){
createDesignElementPickerCombo(parent);
}
//create a table that will contain all the design elements
createDesignElementsTable(parent);
populateDesignElementsTable();
//set initial selection in the combo and update the table contents.
if(null != _combo){
if(_combo.getItemCount()>0){
_combo.select(0);
String comboValue = _combo.getItem(0);
if(StringUtil.isNotEmpty(comboValue)){
String selectedDesignElementId = _labelToDesElemIdMap.get(comboValue);
if(StringUtil.isNotEmpty(selectedDesignElementId)){
_selectedDesignElementId = selectedDesignElementId;
refreshTableContents();
}
}
}
}
}
@Override
protected Control createDialogArea(final Composite parent) {
createMessageArea(parent);
final Composite labelAndText = (Composite) super.createDialogArea(parent);
((GridLayout) labelAndText.getLayout()).numColumns = 1;
GridData labelAndTextData = new GridData(GridData.FILL_BOTH);
labelAndTextData.horizontalSpan = 2;
labelAndText.setLayoutData(labelAndTextData);
if (!superType.isArray()) {
Composite typePanel = new Composite(labelAndText, SWT.NULL);
GridLayout typePanelLayout = new GridLayout();
typePanelLayout.numColumns = 2;
typePanel.setLayout(typePanelLayout);
Label typeLabel = new Label(typePanel, SWT.NONE);
typeLabel.setText("Type: ");
TypeCombo typeSelection = new TypeCombo(typePanel);
typeSelection.setInput(superType, typeSystem, filterTypes);
selectedType = typeSelection.getType();
// maybe consider to show the type of the array and disable the selector
GridData typeSelectionData = new GridData();
typeSelectionData.horizontalSpan = 1;
typeSelectionData.horizontalAlignment = SWT.FILL;
typeSelectionData.grabExcessHorizontalSpace = true;
typeSelection.setLayoutData(typeSelectionData);
typeSelection.addListener(new ITypePaneListener() {
@Override
public void typeChanged(Type newType) {
selectedType = newType;
if (newType.isArray()) {
enableSizeEnter(labelAndText);
} else {
disableSizeEnter();
}
parent.pack(true);
}
});
}
if (superType.isArray()) {
enableSizeEnter(labelAndText);
}
return labelAndText;
}
/**
* Create contents of the dialog.
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite cmp_container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) cmp_container.getLayout();
gridLayout.verticalSpacing = 10;
gridLayout.horizontalSpacing = 10;
Label lbl_title = new Label(cmp_container, SWT.NONE);
lbl_title.setText(I18n.YTRUDER_Title);
Label lbl_separator = new Label(cmp_container, SWT.SEPARATOR | SWT.HORIZONTAL);
lbl_separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label lbl_description = new Label(cmp_container, SWT.NONE);
lbl_description.setText(I18n.YTRUDER_Description);
{
NButton btn_TranslateByDistance = new NButton(cmp_container, SWT.RADIO);
this.btn_TranslateByDistance[0] = btn_TranslateByDistance;
btn_TranslateByDistance.setText(I18n.YTRUDER_TranslationByDistance);
btn_TranslateByDistance.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btn_TranslateByDistance.setSelection(ys.getMode() == 1);
}
{
NButton btn_SymmetryAcrossPlane = new NButton(cmp_container, SWT.RADIO);
this.btn_SymmetryAcrossPlane[0] = btn_SymmetryAcrossPlane;
btn_SymmetryAcrossPlane.setText(I18n.YTRUDER_SymmetryAcrossPlane);
btn_SymmetryAcrossPlane.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btn_SymmetryAcrossPlane.setSelection(ys.getMode() == 2);
}
{
NButton btn_ProjectionOnPlane = new NButton(cmp_container, SWT.RADIO);
this.btn_ProjectionOnPlane[0] = btn_ProjectionOnPlane;
btn_ProjectionOnPlane.setText(I18n.YTRUDER_ProjectionOnPlane);
btn_ProjectionOnPlane.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btn_ProjectionOnPlane.setSelection(ys.getMode() == 3);
}
{
NButton btn_ExtrudeRadially = new NButton(cmp_container, SWT.RADIO);
this.btn_ExtrudeRadially[0] = btn_ExtrudeRadially;
btn_ExtrudeRadially.setText(I18n.YTRUDER_ExtrudeRadially);
btn_ExtrudeRadially.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btn_ExtrudeRadially.setSelection(ys.getMode() == 4);
}
Label lbl_lineThreshold = new Label(cmp_container, SWT.NONE);
lbl_lineThreshold.setText(I18n.YTRUDER_Value);
BigDecimalSpinner spn_value = new BigDecimalSpinner(cmp_container, SWT.NONE);
this.spn_value[0] = spn_value;
spn_value.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
spn_value.setMaximum(new BigDecimal(999999));
spn_value.setMinimum(new BigDecimal(-999999));
spn_value.setValue(new BigDecimal(ys.getDistance()));
Label lbl_rotationAngle = new Label(cmp_container, SWT.NONE);
lbl_rotationAngle.setText(I18n.YTRUDER_CondlineAngle);
BigDecimalSpinner spn_rotationAngle = new BigDecimalSpinner(cmp_container, SWT.NONE);
this.spn_condlineAngleThreshold[0] = spn_rotationAngle;
spn_rotationAngle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
spn_rotationAngle.setMaximum(new BigDecimal(180));
spn_rotationAngle.setMinimum(new BigDecimal(0));
spn_rotationAngle.setValue(new BigDecimal(ys.getCondlineAngleThreshold()));
Label lbl_af = new Label(cmp_container, SWT.NONE);
lbl_af.setText(I18n.YTRUDER_Axis);
Combo cmb_axis = new Combo(cmp_container, SWT.READ_ONLY);
this.cmb_axis[0] = cmb_axis;
cmb_axis.setItems(new String[] {I18n.YTRUDER_X, I18n.YTRUDER_Y, I18n.YTRUDER_Z});
cmb_axis.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
cmb_axis.select(ys.getAxis());
cmp_container.pack();
return cmp_container;
}