List of usage examples for org.eclipse.swt.graphics Color equals
public boolean equals(Object object)
From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java
/** * Creates an image based on the color provided and returns it. * * @param device - The Device//from ww w . j ava 2 s. c o m * @param color - The color used to create the image * * */ static Image createImage(Device device, Color color) { Image image = new Image(device, 16, 16); GC gc = new GC(image); gc.setBackground(color); Rectangle rect = image.getBounds(); gc.fillRectangle(rect); if (color.equals(device.getSystemColor(SWT.COLOR_BLACK))) { gc.setForeground(device.getSystemColor(SWT.COLOR_WHITE)); } gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); gc.dispose(); return image; }
From source file:KalendarDialog.java
private void setDayForDisplay(Calendar now) { int currentDay = now.get(Calendar.DATE); now.add(Calendar.DAY_OF_MONTH, -(now.get(Calendar.DATE) - 1)); // int startIndex = now.get(Calendar.DAY_OF_WEEK) - 1; // int year = now.get(Calendar.YEAR); // int month = now.get(Calendar.MONTH) + 1; // int lastDay = this.getLastDayOfMonth(year, month); // int endIndex = startIndex + lastDay - 1; // int startday = 1; for (int i = 0; i < 42; i++) { Color temp = days[i].getBackground(); if (temp.equals(display.getSystemColor(SWT.COLOR_BLUE))) { days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE)); }/*from w ww. j a va 2 s .com*/ } for (int i = 0; i < 42; i++) { if (i >= startIndex && i <= endIndex) { days[i].setText("" + startday); if (startday == currentDay) { days[i].setBackground(display.getSystemColor(SWT.COLOR_BLUE)); // } startday++; } else { days[i].setText(""); } } }
From source file:org.eclipse.swt.examples.javaviewer.JavaLineStyler.java
/** * Event.detail line start offset (input) * Event.text line text (input) * LineStyleEvent.styles Enumeration of StyleRanges, need to be in order. (output) * LineStyleEvent.background line background color (output) *///www .j av a2 s . com @Override public void lineGetStyle(LineStyleEvent event) { List<StyleRange> styles = new ArrayList<>(); int token; StyleRange lastStyle; // If the line is part of a block comment, create one style for the entire line. if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) { styles.add(new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null)); event.styles = styles.toArray(new StyleRange[styles.size()]); return; } Color defaultFgColor = ((Control) event.widget).getForeground(); scanner.setRange(event.lineText); token = scanner.nextToken(); while (token != EOF) { if (token == OTHER) { // do nothing for non-colored tokens } else if (token != WHITE) { Color color = getColor(token); // Only create a style if the token color is different than the // widget's default foreground color and the token's style is not // bold. Keywords are bolded. if ((!color.equals(defaultFgColor)) || (token == KEY)) { StyleRange style = new StyleRange(scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null); if (token == KEY) { style.fontStyle = SWT.BOLD; } if (styles.isEmpty()) { styles.add(style); } else { // Merge similar styles. Doing so will improve performance. lastStyle = styles.get(styles.size() - 1); if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) { lastStyle.length += style.length; } else { styles.add(style); } } } } else if ((!styles.isEmpty()) && ((lastStyle = styles.get(styles.size() - 1)).fontStyle == SWT.BOLD)) { int start = scanner.getStartOffset() + event.lineOffset; lastStyle = styles.get(styles.size() - 1); // A font style of SWT.BOLD implies that the last style // represents a java keyword. if (lastStyle.start + lastStyle.length == start) { // Have the white space take on the style before it to // minimize the number of style ranges created and the // number of font style changes during rendering. lastStyle.length += scanner.getLength(); } } token = scanner.nextToken(); } event.styles = styles.toArray(new StyleRange[styles.size()]); }
From source file:JavaViewer.java
/** * Event.detail line start offset (input) Event.text line text (input) * LineStyleEvent.styles Enumeration of StyleRanges, need to be in order. * (output) LineStyleEvent.background line background color (output) *///from w w w .j a va 2s .co m public void lineGetStyle(LineStyleEvent event) { Vector styles = new Vector(); int token; StyleRange lastStyle; // If the line is part of a block comment, create one style for the // entire line. if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) { styles.addElement(new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null)); event.styles = new StyleRange[styles.size()]; styles.copyInto(event.styles); return; } Color defaultFgColor = ((Control) event.widget).getForeground(); scanner.setRange(event.lineText); token = scanner.nextToken(); while (token != EOF) { if (token == OTHER) { // do nothing for non-colored tokens } else if (token != WHITE) { Color color = getColor(token); // Only create a style if the token color is different than the // widget's default foreground color and the token's style is // not // bold. Keywords are bolded. if ((!color.equals(defaultFgColor)) || (token == KEY)) { StyleRange style = new StyleRange(scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null); if (token == KEY) { style.fontStyle = SWT.BOLD; } if (styles.isEmpty()) { styles.addElement(style); } else { // Merge similar styles. Doing so will improve // performance. lastStyle = (StyleRange) styles.lastElement(); if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) { lastStyle.length += style.length; } else { styles.addElement(style); } } } } else if ((!styles.isEmpty()) && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) { int start = scanner.getStartOffset() + event.lineOffset; lastStyle = (StyleRange) styles.lastElement(); // A font style of SWT.BOLD implies that the last style // represents a java keyword. if (lastStyle.start + lastStyle.length == start) { // Have the white space take on the style before it to // minimize the number of style ranges created and the // number of font style changes during rendering. lastStyle.length += scanner.getLength(); } } token = scanner.nextToken(); } event.styles = new StyleRange[styles.size()]; styles.copyInto(event.styles); }
From source file:GraphicsExample.java
Image createImage(Display display, Color color) { Image image = new Image(display, 16, 16); GC gc = new GC(image); gc.setBackground(color);/*from w ww . java2s . c om*/ Rectangle rect = image.getBounds(); gc.fillRectangle(rect); if (color.equals(display.getSystemColor(SWT.COLOR_BLACK))) { gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); } gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); gc.dispose(); return image; }
From source file:org.eclipse.swt.examples.accessibility.CTableItem.java
/** * Sets the receiver's background color to the color specified * by the argument, or to the default system color for the item * if the argument is null.//from ww w . j a v a 2s.com * * @param color the new color (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 2.0 */ public void setBackground(Color color) { checkWidget(); if (color != null && color.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } Color oldColor = background; if (oldColor == color) return; background = color; if (oldColor != null && oldColor.equals(color)) return; if ((parent.getStyle() & SWT.VIRTUAL) != 0) cached = true; redrawItem(); }
From source file:org.eclipse.swt.examples.accessibility.CTableItem.java
/** * Sets the receiver's foreground color to the color specified * by the argument, or to the default system color for the item * if the argument is null./* ww w . j a v a 2 s. c om*/ * * @param color the new color (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 2.0 */ public void setForeground(Color color) { checkWidget(); if (color != null && color.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } Color oldColor = foreground; if (oldColor == color) return; foreground = color; if (oldColor != null && oldColor.equals(color)) return; if ((parent.getStyle() & SWT.VIRTUAL) != 0) cached = true; redrawItem(); }
From source file:org.eclipse.swt.examples.accessibility.CTableItem.java
/** * Sets the background color at the given column index in the receiver * to the color specified by the argument, or to the default system color for the item * if the argument is null.//from w ww . j a v a 2s . c o m * * @param index the column index * @param color the new color (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 3.0 */ public void setBackground(int columnIndex, Color color) { checkWidget(); if (color != null && color.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } int validColumnCount = Math.max(1, parent.columns.length); if (!(0 <= columnIndex && columnIndex < validColumnCount)) return; if (cellBackgrounds == null) { if (color == null) return; cellBackgrounds = new Color[validColumnCount]; } Color oldColor = cellBackgrounds[columnIndex]; if (oldColor == color) return; cellBackgrounds[columnIndex] = color; if (oldColor != null && oldColor.equals(color)) return; if ((parent.getStyle() & SWT.VIRTUAL) != 0) cached = true; if (isInViewport()) { Rectangle bounds = getCellBounds(columnIndex); parent.redraw(bounds.x, bounds.y, bounds.width, bounds.height, false); } }
From source file:org.eclipse.swt.examples.accessibility.CTableItem.java
/** * Sets the foreground color at the given column index in the receiver * to the color specified by the argument, or to the default system color for the item * if the argument is null.// w ww. j av a2 s. c o m * * @param index the column index * @param color the new color (or null) * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 3.0 */ public void setForeground(int columnIndex, Color color) { checkWidget(); if (color != null && color.isDisposed()) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } int validColumnCount = Math.max(1, parent.columns.length); if (!(0 <= columnIndex && columnIndex < validColumnCount)) return; if (cellForegrounds == null) { if (color == null) return; cellForegrounds = new Color[validColumnCount]; } Color oldColor = cellForegrounds[columnIndex]; if (oldColor == color) return; cellForegrounds[columnIndex] = color; if (oldColor != null && oldColor.equals(color)) return; if ((parent.getStyle() & SWT.VIRTUAL) != 0) cached = true; if (isInViewport()) { redraw(getTextX(columnIndex), parent.getItemY(this), textWidths[columnIndex] + 2 * MARGIN_TEXT, parent.itemHeight, columnIndex); } }