|
|
Re: Sizing text widgets [message #444129 is a reply to message #444060] |
Thu, 07 October 2004 03:39 |
Howard Fore Messages: 4 Registered: July 2009 |
Junior Member |
|
|
Grant Slender wrote:
> It depends. What layout manager do you have on the pageEditor?
The pageResponsibilitiesText text widget is in a composite with GridLayout
applied.
> A larger snippet of your code would help understand why this happens.
Ok. The text widget is setup in buildPageEditor, called from
createPartControl. One of the widgets setup in createPartControl is a
TabFolder. Because I could not reliably determine the width of the widget
from within createPartControl I created a listener on the tabfolder and
when the tab with the items in buildPageEditor is selected I call
setPageEditorControlsSize. This is when the pageResponsibilitiesText
widget is resized over neighboring widgets.
private void buildPageEditor() {
GridLayout pageEditorLayout = new GridLayout();
pageEditorLayout.numColumns = 3;
pageEditorLayout.makeColumnsEqualWidth = true;
pageEditor.setLayout(pageEditorLayout);
pageTitleList = new List(pageEditor,SWT.NONE);
GridData pageTitleListLayoutData = new GridData();
pageTitleListLayoutData.horizontalSpan = 1;
pageTitleListLayoutData.verticalAlignment = SWT.FILL;
pageTitleListLayoutData.horizontalAlignment = SWT.FILL;
pageTitleListLayoutData.grabExcessHorizontalSpace = true;
pageTitleListLayoutData.grabExcessVerticalSpace = true;
pageTitleList.setLayoutData(pageTitleListLayoutData);
pageTitleList.addSelectionListener(new PageTitleListListener());
Composite pageEditorComposite = new Composite(pageEditor,SWT.NONE);
GridData pageEditorCompositeLayoutData = new GridData();
pageEditorCompositeLayoutData.horizontalSpan = 2;
pageEditorCompositeLayoutData.verticalAlignment = SWT.FILL;
pageEditorCompositeLayoutData.horizontalAlignment = SWT.FILL;
pageEditorCompositeLayoutData.grabExcessHorizontalSpace = true;
pageEditorCompositeLayoutData.grabExcessVerticalSpace = true;
pageEditorComposite.setLayoutData(pageEditorCompositeLayoutD ata);
GridLayout pageEditorCompositeLayout = new GridLayout();
pageEditorCompositeLayout.numColumns = 2;
pageEditorComposite.setLayout(pageEditorCompositeLayout);
Label pageTitleLabel = new Label(pageEditorComposite,SWT.NONE);
pageTitleLabel.setText("Page title");
pageTitleText = new Text(pageEditorComposite,SWT.SINGLE|SWT.BORDER);
GridData pageTitleTextLayoutData = new GridData();
pageTitleTextLayoutData.grabExcessHorizontalSpace = true;
pageTitleTextLayoutData.horizontalAlignment = SWT.FILL;
pageTitleText.setLayoutData(pageTitleTextLayoutData);
pageTitleText.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageTitleModified = true;
}
}
);
Label pageResponsibilitiesLabel = new
Label(pageEditorComposite,SWT.NONE);
GridData pageResponsibilitiesLabelLayoutData = new GridData();
pageResponsibilitiesLabelLayoutData.verticalAlignment = SWT.TOP;
pageResponsibilitiesLabel.setLayoutData(pageResponsibilities LabelLayoutData);
pageResponsibilitiesLabel.setText("Responsibilities");
pageResponsibilitiesText = new
Text(pageEditorComposite,SWT.MULTI|SWT.WRAP|SWT.V_SCROLL|SWT .BORDER);
GridData pageResponsibilitiesTextLayoutData = new GridData();
pageResponsibilitiesTextLayoutData.grabExcessHorizontalSpace = true;
pageResponsibilitiesTextLayoutData.horizontalAlignment = SWT.FILL;
pageResponsibilitiesText.setLayoutData(pageResponsibilitiesT extLayoutData);
pageResponsibilitiesText.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e) {
pageResponsibilitiesModified = true;
}
}
);
Label pageLinksLabel = new Label(pageEditorComposite,SWT.NONE);
GridData pageLinksLabelLayoutData = new GridData();
pageLinksLabelLayoutData.verticalAlignment = SWT.TOP;
pageLinksLabel.setLayoutData(pageLinksLabelLayoutData);
pageLinksLabel.setText("Exit Links");
pageLinksList = new
List(pageEditorComposite,SWT.MULTI|SWT.WRAP|SWT.V_SCROLL|SWT .BORDER);
GridData pageLinksListLayoutData = new GridData();
pageLinksListLayoutData.grabExcessHorizontalSpace = true;
pageLinksListLayoutData.horizontalAlignment = SWT.FILL;
pageLinksList.setLayoutData(pageLinksListLayoutData);
Composite fillerComposite = new Composite(pageEditorComposite,SWT.NONE);
fillerComposite.setLayoutData(new GridData());
ToolBar pageLinksToolBar = new
ToolBar(pageEditorComposite,SWT.FLAT|SWT.HORIZONTAL);
GridData pageLinksToolBarLayoutData = new GridData();
pageLinksToolBarLayoutData.grabExcessHorizontalSpace = true;
pageLinksToolBarLayoutData.horizontalAlignment = SWT.LEFT;
pageLinksToolBar.setLayoutData(pageLinksToolBarLayoutData);
ToolItem addLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
addLinkToolItem.setText("Add");
ToolItem editLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
editLinkToolItem.setText("Edit");
ToolItem deleteLinkToolItem = new ToolItem(pageLinksToolBar, SWT.NONE);
deleteLinkToolItem.setText("Delete");
Composite fillerCompositeBottom = new
Composite(pageEditorComposite,SWT.NONE);
GridLayout fillerCompositeBottomLayout = new GridLayout();
fillerCompositeBottomLayout.makeColumnsEqualWidth = true;
fillerCompositeBottomLayout.numColumns = 2;
fillerCompositeBottom.setLayout(fillerCompositeBottomLayout) ;
applyChangesButton = new Button(fillerCompositeBottom,SWT.PUSH);
applyChangesButton.setText("Apply");
GridData applyChangesButtonLayoutData = new GridData();
applyChangesButtonLayoutData.horizontalAlignment = SWT.FILL;
applyChangesButtonLayoutData.verticalAlignment = SWT.BOTTOM;
applyChangesButton.setLayoutData(applyChangesButtonLayoutDat a);
applyChangesButton.addSelectionListener(new
ApplyChangesButtonListener());
cancelChangesButton = new Button(fillerCompositeBottom,SWT.PUSH);
cancelChangesButton.setText("Cancel");
GridData cancelChangesButtonLayoutData = new GridData();
cancelChangesButtonLayoutData.horizontalAlignment = SWT.FILL;
cancelChangesButtonLayoutData.verticalAlignment = SWT.BOTTOM;
cancelChangesButton.setLayoutData(cancelChangesButtonLayoutD ata);
cancelChangesButton.addSelectionListener(new
CancelChangesButtonListener());
Button newPageButton = new Button (pageEditor,SWT.PUSH);
newPageButton.setText("Add new page");
newPageButton.addSelectionListener(new AddPageListener());
// Add page titles to list
// Loop over pages in DOM
NodeList pagesNodeList =
document.getDocumentElement().getElementsByTagName("page");
Element page = null;
String pageTitle = null;
for(int itr = 0; itr < pagesNodeList.getLength(); itr++) {
page = (Element) pagesNodeList.item(itr);
pageTitle =
page.getElementsByTagName("title").item(0).getFirstChild().getNodeValue();
pageTitleList.add(pageTitle);
}
cancelChangesButton.setEnabled(false);
applyChangesButton.setEnabled(false);
pageTitleText.setEnabled(false);
pageResponsibilitiesText.setEnabled(false);
pageLinksList.setEnabled(false);
pageEditor.layout(true);
}
private void setPageEditorControlsSize(){
// set responsibilities text size
GC gc = new GC (pageResponsibilitiesText);
FontMetrics fm = gc.getFontMetrics ();
int pageResponsibilitiesTextHeight = 10 * fm.getHeight();
gc.dispose ();
pageResponsibilitiesText.setSize (pageResponsibilitiesText.computeSize
(SWT.DEFAULT, pageResponsibilitiesTextHeight));
pageEditor.layout();
}
|
|
|
Powered by
FUDForum. Page generated in 0.02904 seconds