/** * 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) */ 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); }
/** * Manually paints the checked or unchecked symbol. This provides a fast replacement for the * variant that paints the images defined in this class. * * <p>The reason for this is that painting manually is 2-3 times faster than painting the image - * which is very notable if you have a completely filled table! (see example!) * * @param gc The GC to use when dawing * @param rect The cell ara where the symbol should be painted into. * @param checked Wether the symbol should be the checked or unchecked * @param bgColor The background color of the cell. * @param fillColor The color of the box drawn (with of without checked mark). Used when a click * indication is desired. */ protected void drawCheckedSymbol( GC gc, Rectangle rect, boolean checked, Color bgColor, Color fillColor) { // clear background: gc.setBackground(bgColor); gc.fillRectangle(rect); // paint rectangle: Rectangle bound = getAlignedLocation(rect, IMAGE_CHECKED); gc.setForeground(BORDER_LIGHT); gc.drawLine(bound.x, bound.y, bound.x + bound.width, bound.y); gc.drawLine(bound.x, bound.y, bound.x, bound.y + bound.height); gc.setForeground(BORDER_DARK); gc.drawLine( bound.x + bound.width, bound.y + 1, bound.x + bound.width, bound.y + bound.height - 1); gc.drawLine(bound.x, bound.y + bound.height, bound.x + bound.width, bound.y + bound.height); if (!bgColor.equals(fillColor)) { gc.setBackground(fillColor); gc.fillRectangle(bound.x + 1, bound.y + 1, bound.width - 1, bound.height - 1); } if (checked) // draw a check symbol: drawCheckSymbol(gc, bound); }
public LineNameLabel(String lineName, int X, int Y, int length, String type) { this.name = lineName; if (type.equalsIgnoreCase("S")) { // 显示在上面 Y = Y - labHeight - dis; } else { // 显示在下面 Y = Y + dis; } if (bgColor.equals(ColorConstants.white)) { fontColor = ColorConstants.black; } else { fontColor = ColorConstants.white; } // 股道线名称 this.nameLabel.setVisible(false); this.nameLabel.setText(lineName); this.nameLabel.setFont(font1); this.nameLabel.setForegroundColor(fontColor); this.nameLabel.setSize(lineName.length() * 6, labHeight); this.nameLabel.setLocation(new Point(X + length / 2 - lineName.length() * 3, Y)); panel.add(this.nameLabel); baseData.getTracklineNameList().add(nameLabel); }
@Override public void setBackgroundColor(Color bg) { Color oldColor = getBackgroundColor(); super.setBackgroundColor(bg); if (!oldColor.equals(bg)) { createImage(); repaint(); } }
public void setBackground(Color color) { super.setBackground(color); // Are these settings the same as before? if (backgroundImage == null && gradientColors == null && gradientPercents == null) { if (color == null) { if (background == null) return; } else { if (color.equals(background)) return; } } background = color; backgroundImage = null; gradientColors = null; gradientPercents = null; redraw(); }
public void updateCSSColor(Color colorToChange, Color newColor) { if (colorToChange == null || newColor == null || colorToChange.equals(newColor)) { return; } FloatValue newRedValue = new FloatValue((short) 1, (float) newColor.getRed()); FloatValue newGreenValue = new FloatValue((short) 1, (float) newColor.getGreen()); FloatValue newBlueValue = new FloatValue((short) 1, (float) newColor.getBlue()); RGBColorValue newRGBColorValue = new RGBColorValue(newRedValue, newGreenValue, newBlueValue); StyleDeclaration sd = originalStyle.clone(); int sdlen = sd.size(); for (int sdindex = 0; sdindex < sdlen; sdindex++) { Value val = sd.getValue(sdindex); if (val instanceof RGBColorValue) { RGBColorValue colorVal = (RGBColorValue) val; if (isSameColor(colorVal, colorToChange)) { sd.put(sdindex, newRGBColorValue, sd.getIndex(sdindex), sd.getPriority(sdindex)); } } } element.getStyle().setCssText(sd.toString(cssEngine)); }
public void setTextBackground(Color c) { if (c == this.textBackground || (c != null && c.equals(this.textBackground))) return; this.textBackground = c; refreshControl(); }
/** @see IFigure#setForegroundColor(Color) */ public void setForegroundColor(Color fg) { if (fgColor != null && fgColor.equals(fg)) return; fgColor = fg; repaint(); }