下面列出了org.eclipse.swt.widgets.Text#setForeground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Control createDialogArea(Composite parent) {
Composite superComposite = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(superComposite, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
Text outputArea = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL);
outputArea.setSize(500, 300);
outputArea.setText(view.getStatisticsManager().getStatistics());
outputArea.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
return composite;
}
/**
* Create the composite.
*
* @param parent
* @param style
*/
public ApiDocumentationResultView() {
super(SWT.BORDER);
setBackgroundMode(SWT.INHERIT_FORCE);
setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 0;
setLayout(gridLayout);
lblLabel = new CLabel(this, SWT.NONE);
lblLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
lblLabel.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
lblLabel.setText("<Title of the API documentation>");
new Label(this, SWT.NONE);
textUrl = new Text(this, SWT.READ_ONLY | SWT.WRAP);
textUrl.setEditable(false);
textUrl.setForeground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
textUrl.setText("<url>");
textUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
}
/**
* Set the items available in the text (and ask it to ignore any changes while that's done).
*/
private void setTextText(Text text, IStartEndIgnore modifyListener, List<String> items)
{
modifyListener.startIgnore();
try
{
if (!text.isDisposed() && !CollectionsUtil.isEmpty(items))
{
if (ObjectUtil.areNotEqual(items.get(0), text.getText()))
{
text.setText(items.get(0));
}
text.setForeground(null);
}
}
finally
{
modifyListener.endIgnore();
}
}
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;
}
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;
}
public Composite buildStrategyDescriptionPanel(Composite aParentComposite, Atdl4jOptions atdl4jOptions)
{
setAtdl4jOptions( atdl4jOptions );
composite = new SWTVisibleGroup(aParentComposite, SWT.NONE);
((Group) composite).setText("Strategy Description");
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
strategyDescription = new Text(composite, SWT.WRAP | SWT.BORDER | SWT.V_SCROLL );
strategyDescription.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
strategyDescription.setForeground(composite.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
GridData descData = new GridData(SWT.FILL, SWT.FILL, true, false);
descData.heightHint = DEFAULT_STRATEGY_DESCRIPTION_HEIGHT_HINT;
strategyDescription.setLayoutData(descData);
return composite;
}
/**
* 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;
}
protected Control createDialogArea(Composite parent) {
// create composite
Composite composite = (Composite) super.createDialogArea(parent);
// create message
if (message != null) {
Label label = new Label(composite, SWT.WRAP);
label.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);
label.setLayoutData(data);
label.setFont(parent.getFont());
}
combo = new CCombo(composite, getInputComboStyle());
combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
| GridData.HORIZONTAL_ALIGN_FILL));
combo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent 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));
errorMessageText.setForeground(errorMessageText.getDisplay()
.getSystemColor(SWT.COLOR_RED));
// Set the error message text
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=66292
setErrorMessage(errorMessage);
applyDialogFont(composite);
return composite;
}
private void updateTextAfterHistorySelection(String text, String preferenceName)
{
Text textBox = FindBarEntriesHelper.PREFERENCE_NAME_REPLACE.equals(preferenceName) ? textReplace : textFind;
textBox.setForeground(null);
textBox.setText(text);
textBox.setSelection(0, text.length());
}
private static void createText(final Group group) {
group.setLayout(new GridLayout(2, false));
group.setText("Text widget");
final Label lbl0 = new Label(group, SWT.NONE);
lbl0.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl0.setText("No prompt :");
final Text txt0 = new Text(group, SWT.BORDER);
txt0.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
final Label lbl1 = new Label(group, SWT.NONE);
lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl1.setText("Simple text prompt :");
final Text txt1 = new Text(group, SWT.BORDER);
txt1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
PromptSupport.setPrompt("Type anything you want", txt1);
final Label lbl2 = new Label(group, SWT.NONE);
lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl2.setText("Other style (bold) :");
final Text txt2 = new Text(group, SWT.BORDER);
txt2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
PromptSupport.setPrompt("Type anything you want in bold", txt2);
PromptSupport.setFontStyle(SWT.BOLD, txt2);
final Label lbl3 = new Label(group, SWT.NONE);
lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl3.setText("Behaviour highlight :");
final Text txt3 = new Text(group, SWT.BORDER);
txt3.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
PromptSupport.setPrompt("Type anything you want", txt3);
PromptSupport.setFocusBehavior(FocusBehavior.HIGHLIGHT_PROMPT, txt3);
final Label lbl4 = new Label(group, SWT.NONE);
lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl4.setText("Change colors :");
final Text txt4 = new Text(group, SWT.BORDER);
txt4.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
PromptSupport.setPrompt("Type anything you want", txt4);
PromptSupport.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_YELLOW), txt4);
PromptSupport.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_BLACK), txt4);
final Label lbl5 = new Label(group, SWT.NONE);
lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
lbl5.setText("Change when widget is initialized :");
final Text txt5 = new Text(group, SWT.BORDER);
txt5.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
txt5.setText("Remove what is typed...");
txt5.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_BLACK));
txt5.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
PromptSupport.setPrompt("Type anything you want", txt5);
PromptSupport.setForeground(txt4.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE), txt5);
PromptSupport.setBackground(txt4.getDisplay().getSystemColor(SWT.COLOR_WHITE), txt5);
}
protected Text createTextBox(final Composite comp, final int controlStyle) {
Text t = new Text(comp, controlStyle);
t.setForeground(IGamaColors.BLACK.color()); // force the color, see #2601
return t;
}
@Override
protected Control createDialogArea(Composite parent)
{
FontData msgPromptFontData = new FontData(MAC_DIALOG_FONT, MAC_DIALOG_FONT_SIZE, SWT.BOLD);
final Font msgPromptFont = new Font(shell.getDisplay(), msgPromptFontData);
// ----------------------------------------------------------
// Composite for the header and prompt message.
parent.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).create());
parent.setFont(msgPromptFont);
Label authImageLbl = new Label(parent, SWT.None);
final Image authImage = UIPlugin.getImageDescriptor(SECURITY_IMAGE).createImage();
authImageLbl.setImage(authImage);
Label promptMsg = new Label(parent, SWT.WRAP);
promptMsg.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).align(SWT.BEGINNING, SWT.BEGINNING)
.create());
promptMsg.setFont(parent.getFont());
promptMsg.setText(promptMessage);
// ----------------------------------------------------------
// Now laying out UserName and Password fields.
new Label(parent, SWT.NONE); // Dummy label to fill in.
FontData fieldsFontData = new FontData(MAC_DIALOG_FONT, MAC_DIALOG_FONT_SIZE, SWT.NORMAL);
final Font fieldsFont = new Font(shell.getDisplay(), fieldsFontData);
Composite authDetails = new Composite(parent, SWT.None);
authDetails.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).create());
authDetails.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING)
.create());
authDetails.setFont(fieldsFont);
Composite labels = new Composite(authDetails, SWT.None);
labels.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).equalWidth(true).create());
Composite fieldsComp = new Composite(authDetails, SWT.None);
fieldsComp.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).equalWidth(true).create());
fieldsComp
.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).align(SWT.FILL, SWT.BEGINNING).create());
Label nameLbl = new Label(labels, SWT.None);
nameLbl.setText(StringUtil.makeFormLabel(Messages.SudoPasswordPromptDialog_User));
nameLbl.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.END, SWT.BEGINNING).create());
nameLbl.setFont(authDetails.getFont());
Text nameText = new Text(fieldsComp, SWT.BORDER | SWT.READ_ONLY);
nameText.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).create());
nameText.setText(System.getProperty("user.name")); //$NON-NLS-1$
nameText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
Label pwdLbl = new Label(labels, SWT.None);
pwdLbl.setText(StringUtil.makeFormLabel(Messages.SudoPasswordPromptDialog_Password));
pwdLbl.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.END, SWT.BEGINNING).create());
pwdLbl.setFont(authDetails.getFont());
pwdText = new Text(fieldsComp, SWT.BORDER | SWT.PASSWORD);
pwdText.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).create());
shell.addDisposeListener(new DisposeListener()
{
public void widgetDisposed(DisposeEvent e)
{
if (authImage != null)
{
authImage.dispose();
}
if (msgPromptFont != null)
{
msgPromptFont.dispose();
}
if (fieldsFont != null)
{
fieldsFont.dispose();
}
}
});
return parent;
}
private void createErrorControl( Composite parent )
{
Color bgColor = parent.getDisplay( )
.getSystemColor( SWT.COLOR_LIST_BACKGROUND );
Color fgColor = parent.getDisplay( )
.getSystemColor( SWT.COLOR_LIST_FOREGROUND );
parent.setBackground( bgColor );
parent.setForeground( fgColor );
GridLayout layout = new GridLayout( );
layout.numColumns = 3;
int spacing = 8;
int margins = 8;
layout.marginBottom = margins;
layout.marginTop = margins;
layout.marginLeft = margins;
layout.marginRight = margins;
layout.horizontalSpacing = spacing;
layout.verticalSpacing = spacing;
parent.setLayout( layout );
Label imageLabel = new Label( parent, SWT.NONE );
imageLabel.setBackground( bgColor );
Image image = getImage( );
if ( image != null )
{
image.setBackground( bgColor );
imageLabel.setImage( image );
imageLabel.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_CENTER
| GridData.VERTICAL_ALIGN_BEGINNING ) );
}
Text text = new Text( parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP );
text.setBackground( bgColor );
text.setForeground( fgColor );
// text.setForeground(JFaceColors.getErrorText(text.getDisplay()));
text.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
text.setText( Messages.getString("ReportDocumentEditor.errorMessage") ); //$NON-NLS-1$
detailsButton = new Button( parent, SWT.PUSH );
detailsButton.addSelectionListener( new SelectionAdapter( ) {
public void widgetSelected( SelectionEvent e )
{
showDetails( !showingDetails );
}
} );
detailsButton.setLayoutData( new GridData( SWT.BEGINNING,
SWT.CENTER,
false,
false ) );
detailsButton.setVisible( e != null );
updateDetailsText( );
detailsArea = new Composite( parent, SWT.NONE );
detailsArea.setBackground( bgColor );
detailsArea.setForeground( fgColor );
GridData data = new GridData( GridData.FILL_BOTH );
data.horizontalSpan = 3;
data.verticalSpan = 1;
detailsArea.setLayoutData( data );
detailsArea.setLayout( new FillLayout( ) );
parent.layout( true );
}
@Override
protected Control createDialogArea(Composite parent) {
Composite top = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(top, SWT.None);
composite.setLayoutData(createGridData(1));
int numberOfColumns = 2;
projectLocationFieldEditor = new ProjectDirectoryFieldEditorCustom("unused", "Project location", composite);
projectLocationFieldEditor.fillIntoGrid(composite, numberOfColumns);
projectLocationFieldEditor.setChangeButtonText("...");
projectLocationFieldEditor.setStringValue(defaultProjectLocation);
projectLocationFieldEditor.setEmptyStringAllowed(false);
if (this.showBaseInterpreter) {
Label label = new Label(composite, SWT.NONE);
label.setText("Base Interpreter:");
label.setLayoutData(createGridData(numberOfColumns));
comboBaseInterpreter = new Combo(composite, SWT.READ_ONLY);
comboBaseInterpreter.setLayoutData(createGridData(numberOfColumns));
for (IInterpreterInfo info : interpreterInfos) {
comboBaseInterpreter.add(info.getNameForUI());
comboBaseInterpreter.setData(info.getNameForUI(), info);
}
comboBaseInterpreter.setText(interpreterInfos[0].getNameForUI());
}
fileFieldEditor = new FileFieldEditorCustom("unused", "pipenv executable", composite);
fileFieldEditor.fillIntoGrid(composite, numberOfColumns);
fileFieldEditor.setChangeButtonText("...");
fileFieldEditor.setEmptyStringAllowed(false);
fileFieldEditor.setStringValue(defaultPipenvLocation);
errorMessageText = new Text(composite, SWT.READ_ONLY);
errorMessageText.setBackground(errorMessageText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
errorMessageText.setForeground(errorMessageText.getDisplay().getSystemColor(SWT.COLOR_RED));
GridData gridData = createGridData(numberOfColumns);
gridData.heightHint = 60;
errorMessageText.setLayoutData(gridData);
composite.setLayout(new GridLayout(numberOfColumns, false));
return top;
}
public void open() {
Shell parent = getParent();
display = parent.getDisplay();
shell = createShell( parent );
shell.setImage( GUIResource.getInstance().getImageSpoon() );
props.setLook( shell );
FormLayout formLayout = new FormLayout();
shell.setLayout( formLayout );
shell.setText( dialogTitle );
//Set Images
setImages();
// Canvas
wBrowser = new Browser( shell, SWT.NONE );
props.setLook( wBrowser );
// Browser canvas
FormData fdBrowser = new FormData();
fdBrowser.top = new FormAttachment( 0, TOOLBAR_HEIGHT );
fdBrowser.bottom = new FormAttachment( 100, 0 );
fdBrowser.right = new FormAttachment( 100, 0 );
fdBrowser.left = new FormAttachment( 0, 0 );
wBrowser.setLayoutData( fdBrowser );
wBrowser.setUrl( url );
// Left toolbar (back, forward, refresh, home)
toolbarLeft = new ToolBar( shell, SWT.WRAP );
FormData fdToolbarLeft = new FormData();
fdToolbarLeft.top = new FormAttachment( 0, MARGIN );
toolbarLeft.setLayoutData( fdToolbarLeft );
toolbarLeft.setCursor( cursorEnabled );
toolbarLeft.setBackground( toolbarLeft.getParent().getBackground() );
tltmBack = new ToolItem( toolbarLeft, SWT.PUSH );
tltmBack.setImage( imageBackEnabled );
tltmBack.setDisabledImage( imageBackDisabled );
tltmBack.setToolTipText( BaseMessages.getString( PKG, "Spoon.Documentation.Tooltip.Back" ) );
tltmBack.setEnabled( false );
tltmForward = new ToolItem( toolbarLeft, SWT.PUSH );
tltmForward.setImage( imageForwardEnabled );
tltmForward.setDisabledImage( imageForwardDisabled );
tltmForward.setToolTipText( BaseMessages.getString( PKG, "Spoon.Documentation.Tooltip.Forward" ) );
tltmForward.setEnabled( false );
tltmRefresh = new ToolItem( toolbarLeft, SWT.PUSH );
tltmRefresh.setImage( imageRefreshEnabled );
tltmRefresh.setDisabledImage( imageRefreshDisabled );
tltmRefresh.setToolTipText( BaseMessages.getString( PKG, "Spoon.Documentation.Tooltip.Refresh" ) );
tltmRefresh.setEnabled( true );
tltmHome = new ToolItem( toolbarLeft, SWT.PUSH );
tltmHome.setImage( imageHomeEnabled );
tltmHome.setDisabledImage( imageHomeDisabled );
tltmHome.setToolTipText( BaseMessages.getString( PKG, "Spoon.Documentation.Tooltip.Home" ) );
tltmHome.setEnabled( true );
// Right toolbar (print)
toolbarRight = new ToolBar( shell, SWT.WRAP );
FormData fdToolbarRight = new FormData();
fdToolbarRight.top = new FormAttachment( 0, MARGIN );
fdToolbarRight.right = new FormAttachment( 100, -1 * TOOL_ITEM_SPACING );
toolbarRight.setLayoutData( fdToolbarRight );
toolbarRight.setCursor( cursorEnabled );
toolbarRight.setBackground( toolbarRight.getParent().getBackground() );
// URL toolbar element
textURL = new Text( shell, SWT.BORDER );
FormData fdText = new FormData();
fdText.top = new FormAttachment( 0, MARGIN );
fdText.right = new FormAttachment( toolbarRight, -1 * TOOL_ITEM_SPACING );
fdText.left = new FormAttachment( toolbarLeft, TOOL_ITEM_SPACING );
textURL.setLayoutData( fdText );
textURL.setForeground( new Color( display, 101, 101, 101 ) );
tltmPrint = new ToolItem( toolbarRight, SWT.PUSH );
tltmPrint.setImage( imagePrintEnabled );
tltmPrint.setDisabledImage( imagePrintDisabled );
tltmPrint.setToolTipText( BaseMessages.getString( PKG, "Spoon.Documentation.Tooltip.Print" ) );
tltmPrint.setEnabled( true );
setUpListeners();
// Specs are 760/530, but due to rendering differences, we need to adjust the actual hgt/wdt used
BaseStepDialog.setSize( shell, 755, 538, true );
shell.setMinimumSize( 515, 408 );
shell.open();
while ( !shell.isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep();
}
}
}