下面列出了org.eclipse.swt.widgets.Text#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Text createTextControl(Composite parent) {
IStyle cellStyle = getCellStyle();
final Text textControl = new Text(parent, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
textControl.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
textControl.addKeyListener(new KeyAdapter() {
private final Color originalColor = textControl.getForeground();
@Override
public void keyReleased(KeyEvent e) {
if (!validateCanonicalValue()) {
textControl.setForeground(GUIHelper.COLOR_RED);
} else {
textControl.setForeground(originalColor);
}
};
});
return textControl;
}
private void createMaxCallDepthArea(Composite parent) {
Composite composite= new Composite(parent, SWT.NONE);
composite.setFont(parent.getFont());
GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
Label label= new Label(composite, SWT.NONE);
label.setFont(composite.getFont());
label.setText(CallHierarchyMessages.FiltersDialog_maxCallDepth);
fMaxCallDepth = new Text(composite, SWT.SINGLE | SWT.BORDER);
fMaxCallDepth.setFont(composite.getFont());
fMaxCallDepth.setTextLimit(6);
fMaxCallDepth.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validateInput();
}
});
GridData gridData = new GridData();
gridData.widthHint = convertWidthInCharsToPixels(10);
fMaxCallDepth.setLayoutData(gridData);
}
private void createNewTraceNameGroup(Composite parent) {
Font font = parent.getFont();
Composite folderGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
folderGroup.setLayout(layout);
folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
String name = fTrace.getName();
// New trace name label
Label newTaceLabel = new Label(folderGroup, SWT.NONE);
newTaceLabel.setFont(font);
newTaceLabel.setText(Messages.RenameTraceDialog_TraceNewName);
// New trace name entry field
fNewTraceNameText = new Text(folderGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
fNewTraceNameText.setLayoutData(data);
fNewTraceNameText.setFont(font);
fNewTraceNameText.setFocus();
fNewTraceNameText.setText(name);
fNewTraceNameText.setSelection(0, name.length());
fNewTraceNameText.addListener(SWT.Modify, event -> validateNewTraceName());
}
protected Text createTextControl(Composite parent) {
IStyle cellStyle = getCellStyle();
final Text textControl = new Text(parent, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
textControl.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
textControl.addKeyListener(new KeyAdapter() {
private final Color originalColor = textControl.getForeground();
@Override
public void keyReleased(KeyEvent e) {
if (!validateCanonicalValue()) {
textControl.setForeground(GUIHelper.COLOR_RED);
} else {
textControl.setForeground(originalColor);
}
};
});
return textControl;
}
private void createExperimentNameGroup(Composite parent) {
Font font = parent.getFont();
Composite folderGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
folderGroup.setLayout(layout);
folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// New experiment label
Label experimentLabel = new Label(folderGroup, SWT.NONE);
experimentLabel.setFont(font);
experimentLabel.setText(Messages.NewExperimentDialog_ExperimentName);
// New experiment name entry field
fExperimentName = new Text(folderGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
fExperimentName.setLayoutData(data);
fExperimentName.setFont(font);
fExperimentName.addListener(SWT.Modify, event -> validateNewExperimentName());
}
private void createNewTraceNameGroup(Composite parent) {
Font font = parent.getFont();
Composite folderGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
folderGroup.setLayout(layout);
folderGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
String name = fTrace.getName();
// New trace name label
Label newTraceLabel = new Label(folderGroup, SWT.NONE);
newTraceLabel.setFont(font);
newTraceLabel.setText(Messages.CopyTraceDialog_TraceNewName);
// New trace name entry field
fNewTraceName = new Text(folderGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
fNewTraceName.setLayoutData(data);
fNewTraceName.setFont(font);
fNewTraceName.setFocus();
fNewTraceName.setText(name);
fNewTraceName.setSelection(0, name.length());
fNewTraceName.addListener(SWT.Modify, event -> validateNewTraceName());
}
/**
* Creates the text field showing the established commands.
*
* @param parent the parent composite of the text field
* @return the text field
*/
private static Text createEstablishedCommandsText(final Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
GridDataFactory.fillDefaults().span(2, 1).exclude(true).applyTo(composite);
final Text text = new Text(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
GridDataFactory.fillDefaults().grab(true, true).hint(0 /* Do not layout dependent to the content */, 100)
.span(2, 1).applyTo(text);
text.setEditable(false);
text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_BLACK));
text.setForeground(text.getDisplay().getSystemColor(SWT.COLOR_GRAY));
text.setFont(JFaceResources.getFont(CONSOLE_FONT));
return text;
}
/**
* Create the export destination specification widgets
* @param parent
* org.eclipse.swt.widgets.Composite
*/
protected void createDestinationGroup(Composite parent) {
Font font = parent.getFont();
// destination specification group
Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
destinationSelectionGroup.setLayout(layout);
destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
| GridData.VERTICAL_ALIGN_FILL));
destinationSelectionGroup.setFont(font);
Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
destinationLabel.setText(getDestinationLabel());
destinationLabel.setFont(font);
// destination name entry field
destinationNameField = new Text(destinationSelectionGroup, SWT.BORDER);
destinationNameField.addListener(SWT.Modify, this);
destinationNameField.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
destinationNameField.setLayoutData(data);
destinationNameField.setFont(font);
// destination browse button
destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
destinationBrowseButton.addListener(SWT.Selection, this);
destinationBrowseButton.setFont(font);
setButtonLayoutData(destinationBrowseButton);
new Label(parent, SWT.NONE); // vertical spacer
}
@Override
protected Control createDialogArea(Composite parent) {
// create composite
final Composite composite = (Composite) super.createDialogArea(parent);
// create label for name text
createSubtitleLabel(composite, Messages.AddAnalysisDialog_Name);
// create name text
fNameText = new Text(composite, getInputTextStyle());
fNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
fNameText.addModifyListener(e -> validateInputs());
// create name error text
fNameErrorLabel = createErrorLabel(composite);
// spacer
new Label(composite, SWT.WRAP);
// create label for command text
createSubtitleLabel(composite, Messages.AddAnalysisDialog_Command);
// create command text
fCommandText = new Text(composite, getInputTextStyle());
fCommandText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
final Font mono = new Font(parent.getDisplay(), "Monospace", 9, SWT.NONE); //$NON-NLS-1$
fCommandText.setFont(mono);
fCommandText.addModifyListener(e -> validateInputs());
fCommandText.addDisposeListener(e -> mono.dispose());
// create command error text
fCommandErrorLabel = createErrorLabel(composite);
applyDialogFont(composite);
return composite;
}
private void createFontArea(Composite composite)
{
Composite themesComp = new Composite(composite, SWT.NONE);
themesComp.setLayout(new GridLayout(3, false));
themesComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Label label = new Label(themesComp, SWT.NONE);
label.setText(Messages.ThemePreferencePage_FontNameLabel);
fFont = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
fFontText = new Text(themesComp, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
fFontText.setText(toString(fFont));
fFontText.setFont(fFont);
fFontText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Button selectFontButton = new Button(themesComp, SWT.PUSH);
selectFontButton.setText(Messages.ThemePreferencePage_SelectFontButtonLabel);
selectFontButton.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
final FontDialog fontDialog = new FontDialog(getShell());
fontDialog.setFontList(fFont.getFontData());
final FontData data = fontDialog.open();
if (data != null)
{
setFont(new Font(fFont.getDevice(), fontDialog.getFontList()));
}
}
});
}
/**
* Creates a new text widget
*
* @param parent
* the parent composite to add this text widget to
* @param hspan
* the horizontal span to take up on the parent composite
* @return the new text widget
*/
public static Text createSingleText(Composite parent, int hspan)
{
Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);
t.setFont(parent.getFont());
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = hspan;
t.setLayoutData(gd);
return t;
}
/**
* @param composite
*/
private void createMeasureField(Composite composite) {
new Label(composite, SWT.NONE).setText(LABEL_MEASURE);
measure = new Text(composite, SWT.SINGLE | SWT.BORDER);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 2;
measure.setLayoutData(gridData);
measure.setFont(composite.getFont());
if ( measureData != null && !measureData.equals( "" ) ) //$NON-NLS-1$
{
measure.setText( NumberUtil.double2LocaleNum( ( (Double) measureData ).doubleValue( ) ) );
}
measure.addVerifyListener(new VerifyListener(){
public void verifyText(VerifyEvent e) {
// TODO Auto-generated method stub
boolean doit = false;
char eChar = e.character;System.out.print(eChar + 0);
String validChars = "0123456789,.\b"; //$NON-NLS-1$
if(e.keyCode == SWT.DEL || validChars.indexOf(eChar) >= 0)
{
doit = true;
}
e.doit = doit;
}});
}
/**
* Creates a new text widget
* @param parent the parent composite to add this text widget to
* @param style the style bits for the text widget
* @param hspan the horizontal span to take up on the parent composite
* @param text the initial text, not <code>null</code>
* @return the new text widget
* @since 3.6
*/
public static Text createText(Composite parent, int style, int hspan, String text) {
Text t = new Text(parent, style);
t.setFont(parent.getFont());
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = hspan;
t.setLayoutData(gd);
t.setText(text);
return t;
}
@Override
protected Control createDialogArea(Composite parent) {
// create composite
Composite composite = (Composite) super.createDialogArea(parent);
// create message
if (message != null) {
Text messageText = new Text(composite,
SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
messageText.setText(message);
GridData data = new GridData(GridData.GRAB_HORIZONTAL
| GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
| GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
messageText.setLayoutData(data);
messageText.setFont(parent.getFont());
}
text = new Text(composite, getInputTextStyle());
text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
text.addModifyListener(e -> validateInput());
errorMessageText = new Text(composite, SWT.READ_ONLY | SWT.WRAP);
errorMessageText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
errorMessageText.setBackground(errorMessageText.getDisplay()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
// Set the error message text
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=66292
setErrorMessage(errorMessage);
applyDialogFont(composite);
return composite;
}
private void insertMatrixCell(Composite cmp_container, BigDecimal val, Text[] textCmp) {
Text txt_Cell = new Text(cmp_container, SWT.NONE);
textCmp[0] = txt_Cell;
txt_Cell.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
txt_Cell.setText(numberFormat.format(val));
txt_Cell.setFont(Font.MONOSPACE);
txt_Cell.setEditable(false);
}
public void init() throws IllegalArgumentException, InvocationTargetException, XulException {
XulTextbox diffText = (XulTextbox) document.getElementById( "diff" );
Text text = (Text) diffText.getManagedObject();
text.setFont( JFaceResources.getFont( JFaceResources.TEXT_FONT ) );
}
/**
* Creates this object's visual components.
*
* @param parent
* org.eclipse.swt.widgets.Composite
* @param heightHint
* height hint for the container selection widget group
*/
protected void createContents( Composite parent,
String resourceLabelString, int heightHint )
{
Font font = parent.getFont( );
// server name group
Composite composite = new Composite( parent, SWT.NONE );
GridLayout layout = new GridLayout( );
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout( layout );
composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
composite.setFont( font );
// container group
if ( heightHint == SWT.DEFAULT )
containerGroup = new ContainerSelectionGroup( composite,
this,
true,
null,
showClosedProjects );
else
containerGroup = new ContainerSelectionGroup( composite,
this,
true,
null,
showClosedProjects,
heightHint );
// resource name group
Composite nameGroup = new Composite( composite, SWT.NONE );
layout = new GridLayout( );
layout.numColumns = 2;
layout.marginWidth = 0;
nameGroup.setLayout( layout );
nameGroup.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_FILL
| GridData.GRAB_HORIZONTAL ) );
nameGroup.setFont( font );
Label label = new Label( nameGroup, SWT.NONE );
label.setText( resourceLabelString );
label.setFont( font );
// resource name entry field
resourceNameField = new Text( nameGroup, SWT.BORDER );
resourceNameField.addListener( SWT.Modify, this );
GridData data = new GridData( GridData.HORIZONTAL_ALIGN_FILL
| GridData.GRAB_HORIZONTAL );
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
resourceNameField.setLayoutData( data );
resourceNameField.setFont( font );
validateControls( );
}
/**
* Creates the project location specification controls.
*
* @param group
* the parent composite
* @param enabled
* the initial enabled state of the widgets created
*/
private void createUserSpecifiedProjectLocationGroup( Composite group,
boolean enabled )
{
Font font = group.getFont( );
// location label
locationLabel = new Label( group, SWT.NONE );
locationLabel.setText( LABEL_DIRECTORY );
locationLabel.setEnabled( enabled );
locationLabel.setFont( font );
// file location entry field
locationPathField = new Text( group, SWT.BORDER );
GridData data = new GridData( GridData.FILL_HORIZONTAL );
data.widthHint = 250;
locationPathField.setLayoutData( data );
locationPathField.setEnabled( enabled );
locationPathField.setFont( font );
// browse button
browseButton = new Button( group, SWT.PUSH );
browseButton.setText( LABEL_BROWSE );
browseButton.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent event )
{
handleLocationBrowseButtonPressed( );
}
} );
browseButton.setEnabled( enabled );
browseButton.setFont( font );
setButtonLayoutData( browseButton );
if ( defaultFileLocation != null )
{
locationPathField.setText( defaultFileLocation );
}
else
{
locationPathField.setText( "" );//$NON-NLS-1$
}
}
/**
* Create group
*
* @param parent
*/
public void create( Composite parent )
{
// get font
Font font = parent.getFont( );
// label control
Label label = new Label( parent, SWT.LEFT );
label.setFont( font );
label.setText( this.labelText );
Composite composite = new Composite( parent, SWT.NULL );
GridLayout layout = new GridLayout( );
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 2;
composite.setLayout( layout );
GridData data = new GridData( GridData.FILL_HORIZONTAL );
composite.setLayoutData( data );
// text control
text = new Text( composite, SWT.BORDER );
text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
text.setFont( font );
text.setText( this.textValue );
text.addVerifyListener( new VerifyListener( ) {
public void verifyText( VerifyEvent e )
{
e.doit = e.text.indexOf( DELIMITER ) < 0;
}
} );
// directory selection button
button = new Button( composite, SWT.PUSH );
button.setFont( font );
button.setText( this.buttonText );
button.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent event )
{
dialog = new DirectoryDialog( PlatformUI.getWorkbench( )
.getDisplay( ).getActiveShell( ) );
dialog.setText( dialogTitle );
dialog.setMessage( dialogMessage );
dialog.setFilterPath( dialogFilterPath );
String folderName = dialog.open( );
if ( folderName == null )
{
return;
}
text.setText( folderName );
}
} );
}
/**
* Creates a new text widget
* @param parent the parent composite to add this text widget to
* @param style the style bits for the text widget
* @param hspan the horizontal span to take up on the parent composite
* @param fill the fill for the grid layout
* @return the new text widget
* @since 3.3
*/
public static Text createText(Composite parent, int style, int hspan, int fill) {
Text t = new Text(parent, style);
t.setFont(parent.getFont());
GridData gd = new GridData(fill);
gd.horizontalSpan = hspan;
t.setLayoutData(gd);
return t;
}