Java Code Examples for org.eclipse.swt.SWT#BACKGROUND
The following examples show how to use
org.eclipse.swt.SWT#BACKGROUND .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartView.java From slr-toolkit with Eclipse Public License 1.0 | 5 votes |
private void setUpDrawing(Composite parent) { paintCanvas = new Canvas(parent, SWT.BACKGROUND); preview = new ChartPreview(); paintCanvas.addPaintListener(preview); paintCanvas.addControlListener(preview); preview.setPreview(paintCanvas); preview.setDataPresent(false); preview.setTextToShow(noDataToDisplay); }
Example 2
Source File: TmfEventsTable.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
@Override public void handleEvent(Event event) { TableItem item = (TableItem) event.item; List<?> styleRanges = (List<?>) item.getData(Key.STYLE_RANGES); GC gc = event.gc; Color background = item.getBackground(event.index); /* * Paint the background if it is not the default system color. In * Windows, if you let the widget draw the background, it will not * show the item's background color if the item is selected or hot. * If there are no style ranges and the item background is the * default system color, we do not want to paint it or otherwise we * would override the platform theme (e.g. alternating colors). */ if (styleRanges != null || !background.equals(item.getParent().getBackground())) { // we will paint the table item's background event.detail &= ~SWT.BACKGROUND; // paint the item's default background gc.setBackground(background); gc.fillRectangle(event.x, event.y, event.width, event.height); } /* * We will paint the table item's foreground. In Windows, if you * paint the background but let the widget draw the foreground, it * will override your background, unless the item is selected or * hot. */ event.detail &= ~SWT.FOREGROUND; // paint the highlighted background for all style ranges if (styleRanges != null) { Rectangle textBounds = item.getTextBounds(event.index); String text = item.getText(event.index); for (Object o : styleRanges) { if (o instanceof StyleRange) { StyleRange styleRange = (StyleRange) o; if (styleRange.data.equals(event.index)) { int startIndex = styleRange.start; int endIndex = startIndex + styleRange.length; int startX = gc.textExtent(text.substring(0, startIndex)).x; int endX = gc.textExtent(text.substring(0, endIndex)).x; gc.setBackground(styleRange.background); gc.fillRectangle(textBounds.x + startX, textBounds.y, (endX - startX), textBounds.height); } } } } }
Example 3
Source File: ControlThemer.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
protected void addSelectionColorOverride() { if (controlIsDisposed()) { return; } // Override selection color to match what is set in theme selectionOverride = new Listener() { public void handleEvent(Event event) { if (!invasiveThemesEnabled()) { return; } GC gc = event.gc; Color oldBackground = gc.getBackground(); if ((event.detail & SWT.SELECTED) != 0) { Scrollable scrollable = (Scrollable) event.widget; Rectangle clientArea = scrollable.getClientArea(); gc.setBackground(getSelection()); // The +2 on width is for Linux, since clientArea begins at [-2,-2] and // without it we don't properly color full width (see broken coloring when scrolling horizontally) gc.fillRectangle(clientArea.x, event.y, clientArea.width + 2, event.height); event.detail &= ~SWT.SELECTED; event.detail &= ~SWT.BACKGROUND; gc.setBackground(oldBackground); } else { // Draw normal background color. This seems to only be necessary for some variants of Linux, // and is the correct way to force custom painting of background when setBackground() doesn't work // properly. if (!isWindows && !isMacOSX) { Color controlBG = control.getBackground(); if (controlBG.getRGB().equals(oldBackground.getRGB())) { gc.setBackground(getBackground()); gc.fillRectangle(event.x, event.y, event.width, event.height); event.detail &= ~SWT.BACKGROUND; gc.setBackground(oldBackground); } } } // force foreground color. Otherwise on dark themes we get black FG (all the time on Win, on // non-focus for Mac) gc.setForeground(getForeground()); } }; getControl().addListener(SWT.EraseItem, selectionOverride); }
Example 4
Source File: TreeThemer.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void addCustomTreeControlDrawing() { // Hack to overdraw the native tree expand/collapse controls and use custom plus/minus box. if (isMacOSX || isUbuntu || controlIsDisposed()) { return; } // FIXME The native control/arrow still shows through on OpenSuSE 11.4 final Tree tree = getTree(); customDrawingListener = new Listener() { public void handleEvent(Event event) { if (!invasiveThemesEnabled()) { return; } GC gc = event.gc; Widget item = event.item; boolean isExpanded = false; boolean draw = false; if (item instanceof TreeItem) { TreeItem tItem = (TreeItem) item; isExpanded = tItem.getExpanded(); draw = tItem.getItemCount() > 0; } if (!draw) { return; } final int width = 10; final int height = 12; final int x = event.x - 16; final int y = event.y + 4; Color oldBackground = gc.getBackground(); gc.setBackground(getBackground()); // wipe out the native control gc.fillRectangle(x, y, width + 1, height - 1); // +1 and -1 because of hovering selecting on windows // vista // draw a plus/minus based on expansion! gc.setBackground(getForeground()); // draw surrounding box (with alpha so that it doesn't get too strong). gc.setAlpha(195); gc.drawRectangle(x + 1, y + 1, width - 2, width - 2); // make it smaller than the area erased gc.setAlpha(255); // draw '-' int halfWidth = width >> 1; gc.drawLine(x + 3, y + halfWidth, x + 7, y + halfWidth); if (!isExpanded) { // draw '|' to make it a plus gc.drawLine(x + halfWidth, y + 3, x + halfWidth, y + 7); } gc.setBackground(oldBackground); event.detail &= ~SWT.BACKGROUND; } }; tree.addListener(SWT.PaintItem, customDrawingListener); }
Example 5
Source File: JobHasJobLogConfiguredImportRuleComposite.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public Composite getComposite( Composite parent, ImportRuleInterface importRule ) { PropsUI props = PropsUI.getInstance(); composite = new Composite( parent, SWT.BACKGROUND ); props.setLook( composite ); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; composite.setLayout( formLayout ); // Schema input field... // Label schemaLabel = new Label( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( schemaLabel ); schemaLabel.setText( "Schema " ); FormData fdSchemaLabel = new FormData(); fdSchemaLabel.left = new FormAttachment( 0, 0 ); fdSchemaLabel.top = new FormAttachment( 0, 0 ); schemaLabel.setLayoutData( fdSchemaLabel ); schemaText = new Text( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( schemaText ); FormData fdSchemaText = new FormData(); fdSchemaText.left = new FormAttachment( schemaLabel, Const.MARGIN ); fdSchemaText.top = new FormAttachment( 0, 0 ); fdSchemaText.right = new FormAttachment( schemaLabel, 150 ); schemaText.setLayoutData( fdSchemaText ); // Table name input field... // Label tableLabel = new Label( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( tableLabel ); tableLabel.setText( "Table " ); FormData fdTableLabel = new FormData(); fdTableLabel.left = new FormAttachment( schemaText, Const.MARGIN ); fdTableLabel.top = new FormAttachment( 0, 0 ); tableLabel.setLayoutData( fdTableLabel ); tableText = new Text( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( tableText ); FormData fdTableText = new FormData(); fdTableText.left = new FormAttachment( tableLabel, Const.MARGIN ); fdTableText.top = new FormAttachment( 0, 0 ); fdTableText.right = new FormAttachment( tableLabel, 150 ); tableText.setLayoutData( fdTableText ); // Connection name input field... // Label connectionLabel = new Label( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( connectionLabel ); connectionLabel.setText( "Connection " ); FormData fdConnectionLabel = new FormData(); fdConnectionLabel.left = new FormAttachment( tableText, Const.MARGIN ); fdConnectionLabel.top = new FormAttachment( 0, 0 ); connectionLabel.setLayoutData( fdConnectionLabel ); connectionText = new Text( composite, SWT.SINGLE | SWT.BORDER | SWT.LEFT ); props.setLook( connectionText ); FormData fdConnectionText = new FormData(); fdConnectionText.left = new FormAttachment( connectionLabel, Const.MARGIN ); fdConnectionText.top = new FormAttachment( 0, 0 ); fdConnectionText.right = new FormAttachment( connectionLabel, 200 ); connectionText.setLayoutData( fdConnectionText ); return composite; }