下面列出了org.eclipse.swt.widgets.Text#setBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @generated
*/
public void relocate(CellEditor celleditor) {
Text text = (Text) celleditor.getControl();
Rectangle rect = getWrapLabel().getTextBounds().getCopy();
getWrapLabel().translateToAbsolute(rect);
if (!text.getFont().isDisposed()) {
if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
//Adjust editor location
rect.x = rect.x - 5;
if (rect.width < 75) {
rect.width = 75;
}
rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
} else {
int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
}
}
if (!rect.equals(new Rectangle(text.getBounds()))) {
text.setBounds(rect.x, rect.y, rect.width, rect.height);
}
}
private void initialize() {
text = new Text(this, SWT.NONE);
text.setBounds(new Rectangle(5, 5, 70, 13));
text1 = new Text(this, SWT.NONE);
text1.setBounds(new Rectangle(80, 5, 70, 13));
text2 = new Text(this, SWT.NONE);
text2.setBounds(new Rectangle(155, 5, 70, 13));
this.setLayout(null);
this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
setSize(new Point(307, 46));
}
private Group createNote(final Composite parent, final Question question, boolean visible) {
final Group notePanel = new Group(parent, SWT.NONE);
notePanel.setText("Note:");
final GridLayout gridLayout = new GridLayout();
notePanel.setLayout(gridLayout);
final GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
gridData.horizontalSpan = 1;
notePanel.setLayoutData(gridData);
final Font boldFont = new Font(notePanel.getDisplay(), new FontData(Constants.ARIAL, 10, SWT.BOLD));
notePanel.setFont(boldFont);
notePanel.pack();
setControl(parent);
Text note = new Text(notePanel, SWT.MULTI | SWT.WRAP);
note.setLayoutData(new GridData(GridData.FILL_BOTH));
String noteText = question.getNote();
if (noteText.contains("$$$")) {
noteText = noteText.split("\\$\\$\\$")[1];
}
note.setText(noteText);
note.pack();
note.setBounds(10, 20, 585, 60);
note.setSize(note.computeSize(585, SWT.DEFAULT));
setControl(notePanel);
note.setEditable(false);
note.setEnabled(true);
notePanel.setVisible(visible);
return notePanel;
}
public CompositeForCodeTab(final Composite parent, final int style, final Answer answer) {
super(parent, style);
// Non-editable text box containing answer value
final Text txtBoxAnswers = new Text(this, SWT.BORDER);
txtBoxAnswers.setBounds(5, 5, 210, 25);
txtBoxAnswers.setEditable(false);
txtBoxAnswers.setText(answer.getValue());
// Code dependency text field
final Text txtValue = new Text(this, SWT.BORDER);
txtValue.setBounds(220, 5, 200, 25);
txtValue.setVisible(true);
final CodeDependency codeDependency = new CodeDependency();
if (answer.getCodeDependencies() != null) {
for (final CodeDependency cd : answer.getCodeDependencies()) {
if (cd.getValue() != null) {
txtValue.setText(cd.getValue());
codeDependency.setValue(txtValue.getText());
}
}
}
txtValue.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(final FocusEvent e) {
codeDependency.setValue(txtValue.getText());
}
});
final ArrayList<CodeDependency> codeDependencies = new ArrayList<CodeDependency>();
codeDependencies.add(codeDependency);
answer.setCodeDependencies(codeDependencies);
}
@Override
public void relocate(final CellEditor cellEditor) {
final Text text = (Text) cellEditor.getControl();
final Rectangle rect = figure.getBounds().getCopy();
figure.translateToAbsolute(rect);
text.setBounds(rect.x + NoteFigure.RETURN_WIDTH, rect.y + NoteFigure.RETURN_WIDTH, rect.width - NoteFigure.RETURN_WIDTH * 2, rect.height - NoteFigure.RETURN_WIDTH * 2);
}
@Override
public void relocate(CellEditor cellEditor) {
final Text text = (Text) cellEditor.getControl();
final Rectangle rect = figure.getBounds().getCopy();
figure.translateToAbsolute(rect);
text.setBounds(rect.x + WalkerNoteFigure.RETURN_WIDTH, rect.y + WalkerNoteFigure.RETURN_WIDTH,
rect.width - WalkerNoteFigure.RETURN_WIDTH * 2, rect.height - WalkerNoteFigure.RETURN_WIDTH * 2);
}
public void relocate( CellEditor celleditor )
{
Text text = (Text) celleditor.getControl( );
Rectangle rect = figure.getClientArea( ).getCopy( );
figure.translateToAbsolute( rect );
int xOffset = 0;
int wOffset = 0;
int yOffset = 0;
int hOffset = 0;
if ( SWT.getPlatform( ).equalsIgnoreCase( "gtk" ) ) { //$NON-NLS-1$
xOffset = GTK_X_OFFSET;
wOffset = GTK_W_OFFSET;
}
else if ( SWT.getPlatform( ).equalsIgnoreCase( "carbon" ) ) { //$NON-NLS-1$
xOffset = MAC_X_OFFSET;
wOffset = MAC_W_OFFSET;
yOffset = MAC_Y_OFFSET;
hOffset = MAC_H_OFFSET;
}
else
{
xOffset = WIN_X_OFFSET;
wOffset = WIN_W_OFFSET;
}
text.setBounds( rect.x + xOffset, rect.y + yOffset, rect.width
+ wOffset, rect.height + hOffset );
}
/**
* @generated
*/
public void relocate(CellEditor celleditor) {
Text text = (Text) celleditor.getControl();
Rectangle rect = getLabel().getTextBounds().getCopy();
getLabel().translateToAbsolute(rect);
if (!text.getFont().isDisposed()) {
int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
}
if (!rect.equals(new Rectangle(text.getBounds()))) {
text.setBounds(rect.x, rect.y, rect.width, rect.height);
}
}
public void relocate(CellEditor cellEditor) {
Text text = (Text) cellEditor.getControl();
Rectangle rect = this.figure.getBounds().getCopy();
this.figure.translateToAbsolute(rect);
text.setBounds(rect.x + NoteFigure.RETURN_WIDTH, rect.y
+ NoteFigure.RETURN_WIDTH, rect.width - NoteFigure.RETURN_WIDTH
* 2, rect.height - NoteFigure.RETURN_WIDTH * 2);
}
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) container.getLayout();
gridLayout.numColumns = 2;
Composite composite = new Composite(container, SWT.NONE);
GridData gd_composite = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
gd_composite.heightHint = 328;
gd_composite.widthHint = 406;
composite.setLayoutData(gd_composite);
Group grpAbcd = new Group(composite, SWT.NONE);
grpAbcd.setText("abcd");
grpAbcd.setBounds(0, 10, 396, 63);
Combo combo = new Combo(grpAbcd, SWT.NONE);
combo.setBounds(10, 33, 169, 25);
Combo combo_1 = new Combo(grpAbcd, SWT.NONE);
combo_1.setBounds(217, 33, 169, 25);
TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
table.setBounds(0, 211, 396, 287);
Composite composite_1 = new Composite(container, SWT.NONE);
GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_composite_1.heightHint = 502;
gd_composite_1.widthHint = 183;
composite_1.setLayoutData(gd_composite_1);
Label label_3 = new Label(composite_1, SWT.NONE);
label_3.setText("\u89E6\u6478\u4E8B\u4EF6:");
label_3.setBounds(21, 91, 61, 17);
text_3 = new Text(composite_1, SWT.BORDER);
text_3.setBounds(88, 88, 85, 23);
Label label_7 = new Label(composite_1, SWT.NONE);
label_7.setText("\u4E3B\u8981\u5BFC\u822A:");
label_7.setBounds(21, 307, 61, 17);
text_7 = new Text(composite_1, SWT.BORDER);
text_7.setBounds(88, 304, 85, 23);
Label label_8 = new Label(composite_1, SWT.NONE);
label_8.setText("\u7CFB\u7EDF\u6309\u952E:");
label_8.setBounds(21, 333, 61, 17);
text_8 = new Text(composite_1, SWT.BORDER);
text_8.setBounds(88, 330, 85, 23);
Label label_9 = new Label(composite_1, SWT.NONE);
label_9.setText("\u542F\u52A8\u6D3B\u52A8:");
label_9.setBounds(21, 362, 61, 17);
text_9 = new Text(composite_1, SWT.BORDER);
text_9.setBounds(88, 359, 85, 23);
Label label_10 = new Label(composite_1, SWT.NONE);
label_10.setText("\u5176\u4ED6\u4E8B\u4EF6:");
label_10.setBounds(21, 388, 61, 17);
text_10 = new Text(composite_1, SWT.BORDER);
text_10.setBounds(88, 385, 85, 23);
return container;
}