Пример #1
1
 /**
  * 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);
 }
 @Test
 public void test_setBackgroundLorg_eclipse_swt_graphics_Color() {
   Color color = new Color(control.getDisplay(), 255, 0, 0);
   control.setBackground(color);
   assertEquals(
       "getBackground not equal color after setBackground(color)", color, control.getBackground());
   control.setBackground(null);
   assertTrue(
       "getBackground unchanged after setBackground(null)",
       !control.getBackground().equals(color));
   color.dispose();
   // Skipping test run for GTK, already failing on GTK3. May be related to bug 421836
   if (!"gtk".equals(SWT.getPlatform())) {
     // With alpha zero
     color = new Color(control.getDisplay(), 255, 0, 0, 0);
     control.setBackground(color);
     assertEquals(
         "getBackground not equal color after setBackground(color) with 0 alpha",
         color,
         control.getBackground());
     control.setBackground(null);
     assertTrue(
         "getBackground unchanged after setBackground(null)",
         !control.getBackground().equals(color));
     color.dispose();
   }
 }
  private void adaptToTextForegroundChange(Highlighting highlighting, PropertyChangeEvent event) {
    RGB rgb = null;

    Object value = event.getNewValue();
    if (value instanceof RGB) rgb = (RGB) value;
    else if (value instanceof String) rgb = StringConverter.asRGB((String) value);

    if (rgb != null) {

      String property = event.getProperty();
      Color color = fColorManager.getColor(property);

      if ((color == null || !rgb.equals(color.getRGB()))
          && fColorManager instanceof IColorManagerExtension) {
        IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
        ext.unbindColor(property);
        ext.bindColor(property, rgb);
        color = fColorManager.getColor(property);
      }

      TextAttribute oldAttr = highlighting.getTextAttribute();
      highlighting.setTextAttribute(
          new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
    }
  }
Пример #4
0
  protected Declaration handleStyleFeature(Style style, EStructuralFeature feature) {
    Declaration declaration = CssFactory.eINSTANCE.createDeclaration();
    declaration.setProperty(feature.getName());

    GMFToCSSConverter converter = GMFToCSSConverter.instance;

    if (isString(feature)) {
      declaration.setExpression(converter.convert((String) style.eGet(feature)));
    }

    if (isInteger(feature)) {
      if (feature.getName().endsWith("Color")) {
        Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
        declaration.setExpression(converter.convert(color));
        color.dispose();
      } else {
        declaration.setExpression(converter.convert((Integer) style.eGet(feature)));
      }
    }

    if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
      declaration.setExpression(converter.convert((GradientData) style.eGet(feature)));
    }

    if (feature.getEType() instanceof EEnum) {
      declaration.setExpression(converter.convert((Enumerator) style.eGet(feature)));
    }

    if (isBoolean(feature)) {
      declaration.setExpression(converter.convert((Boolean) style.eGet(feature)));
    }

    return declaration;
  }
Пример #5
0
 public static String serializeColor(Color value) {
   return Integer.toString(value.getRed())
       + ","
       + Integer.toString(value.getGreen())
       + ","
       + Integer.toString(value.getBlue());
 }
  /**
   * Renders a label for the given rectangle. The label is fitted into the rectangle if possible.
   *
   * @param event the paint event to work with on
   * @param text the text to render
   * @param color the color to use
   * @param bounds the rectangle bounds
   */
  protected void render(
      final PaintEvent event, final String text, final RGB color, final IRectangle<N> bounds) {
    if (text != null) {
      // quite strange to create a new font object all the time?
      // it did not work when I tried to reuse a long-living font object!
      final Font font = new Font(event.display, fontName, 16, SWT.BOLD);
      try {
        event.gc.setFont(font);
        final Color c = new Color(event.display, color);
        try {
          event.gc.setForeground(c);
        } finally {
          c.dispose();
        }

        final Point p = event.gc.textExtent(text);
        p.x = p.x * 12 / 10; // make some space
        final float scale =
            (float) Math.min(bounds.getWidth() / (double) p.x, bounds.getHeight() / (double) p.y);
        final Transform transform = new Transform(event.display);
        try {
          transform.translate(
              (int) (bounds.getX() + bounds.getWidth() / 12d),
              bounds.getY() + (bounds.getHeight() - scale * p.y) / 2);
          transform.scale(scale, scale);
          event.gc.setTransform(transform);
          event.gc.drawString(text, 0, 0, true);
        } finally {
          transform.dispose();
        }
      } finally {
        font.dispose();
      }
    }
  }
  /*
   * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
   * @since 3.0
   */
  @Override
  public void unconfigure() {
    if (fOutlinePresenter != null) {
      fOutlinePresenter.uninstall();
      fOutlinePresenter = null;
    }
    if (fStructurePresenter != null) {
      fStructurePresenter.uninstall();
      fStructurePresenter = null;
    }
    if (fHierarchyPresenter != null) {
      fHierarchyPresenter.uninstall();
      fHierarchyPresenter = null;
    }
    if (fForegroundColor != null) {
      fForegroundColor.dispose();
      fForegroundColor = null;
    }
    if (fBackgroundColor != null) {
      fBackgroundColor.dispose();
      fBackgroundColor = null;
    }

    if (fPreferenceStore != null) fPreferenceStore.removePropertyChangeListener(this);

    super.unconfigure();

    fIsConfigured = false;
  }
  void resize() {
    Point size = comp.getSize();
    Image oldBackgroundImage = backgroundImage;
    backgroundImage = new Image(comp.getDisplay(), size.x, size.y);
    GC gc = new GC(backgroundImage);
    comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0);
    Color background = comp.getBackground();
    Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    RGB backgroundRGB = background.getRGB();
    // TODO naive and hard coded, doesn't deal with high contrast, etc.
    Color gradientTop =
        new Color(
            comp.getDisplay(),
            backgroundRGB.red + 12,
            backgroundRGB.green + 10,
            backgroundRGB.blue + 10);
    int h = size.y;
    int curveStart = 0;
    int curve_width = 5;

    int[] curve =
        new int[] {
          0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0,
        };
    int[] line1 = new int[curve.length + 4];
    int index = 0;
    int x = curveStart;
    line1[index++] = x + 1;
    line1[index++] = h;
    for (int i = 0; i < curve.length / 2; i++) {
      line1[index++] = x + curve[2 * i];
      line1[index++] = curve[2 * i + 1];
    }
    line1[index++] = x + curve_width;
    line1[index++] = 0;

    int[] line2 = new int[line1.length];
    index = 0;
    for (int i = 0; i < line1.length / 2; i++) {
      line2[index] = line1[index++] - 1;
      line2[index] = line1[index++];
    }

    // custom gradient
    gc.setForeground(gradientTop);
    gc.setBackground(background);
    gc.drawLine(4, 0, size.x, 0);
    gc.drawLine(3, 1, size.x, 1);
    gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true);
    gc.setForeground(background);
    gc.drawLine(2, size.y - 1, size.x, size.y - 1);
    gradientTop.dispose();

    gc.setForeground(border);
    gc.drawPolyline(line2);
    gc.dispose();
    comp.setBackgroundImage(backgroundImage);
    if (oldBackgroundImage != null) oldBackgroundImage.dispose();
  }
 private void freeDropShadowsColors() {
   // Free colors :
   {
     for (Color c : dropShadowsColors) {
       if (c != null && !c.isDisposed()) c.dispose();
     }
   }
 }
Пример #10
0
  public void applyColor(ColorType type, RGB rgb) {
    Color newColor = new Color(SwtUtils.DISPLAY, rgb);
    Color oldColor = null;

    switch (type) {
      case BACKGROUND:
        {
          oldColor = iniAppearance.getColorBackground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setBackground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setBackground(newColor);
          }

          iniAppearance.setColorBackground(newColor);
          break;
        }
      case FOREGROUND:
        {
          oldColor = iniAppearance.getColorForeground();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setForeground(newColor);
          }
          for (Text chat : chatControls) {
            if (chat.isDisposed()) continue;

            chat.setForeground(newColor);
          }

          iniAppearance.setColorForeground(newColor);
          break;
        }
      case LOG_BACKGROUND:
        {
          oldColor = iniAppearance.getColorLogBackground();

          for (StyledText text : logControls) {
            if (text.isDisposed()) continue;

            text.setBackground(newColor);
            text.setForeground(newColor);
          }

          iniAppearance.setColorLogBackground(newColor);
        }
    }

    if (oldColor != null) oldColor.dispose();
  }
Пример #11
0
  @Test
  public void dispose_disposesColors() {
    ColorSequence sequence = new ColorSequence(display, rgb1);
    Color color = sequence.get(0);

    sequence.dispose();

    assertTrue(color.isDisposed());
  }
Пример #12
0
 @Override
 public void dispose() {
   blue.dispose();
   darkPurple.dispose();
   lightBlue.dispose();
   purple.dispose();
   red.dispose();
   super.dispose();
 }
Пример #13
0
  @Test
  public void testBorderColor() {
    assertNull(figure.getBorderColor());

    dmImage.setBorderColor("#010203");
    Color expected = new Color(null, 1, 2, 3);
    assertEquals(expected, figure.getBorderColor());
    expected.dispose();
  }
 @Test
 public void test_setForegroundLorg_eclipse_swt_graphics_Color() {
   Color color = new Color(control.getDisplay(), 255, 0, 0);
   control.setForeground(color);
   assertEquals(color, control.getForeground());
   control.setForeground(null);
   assertTrue(!control.getForeground().equals(color));
   color.dispose();
 }
 @Override
 public void setBackgroundColor(Color bg) {
   Color oldColor = getBackgroundColor();
   super.setBackgroundColor(bg);
   if (!oldColor.equals(bg)) {
     createImage();
     repaint();
   }
 }
Пример #16
0
 @Override
 public void dispose() {
   callbacks.clear();
   for (org.eclipse.swt.graphics.Color c : colorRegistry) {
     c.dispose();
   }
   colorRegistry.clear();
   super.dispose();
 }
Пример #17
0
 /**
  * Sets the receiver's background color to the color specified by the argument, or to the default
  * system color for the control if the argument is null.
  *
  * @param color the new color (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setBackground(Color color) {
   // super.setBackground(color); // This has no effect as the background
   // will
   // be hidden by the client script
   JsonObject properties = new JsonObject();
   properties.add("R", color.getRed());
   properties.add("G", color.getGreen());
   properties.add("B", color.getBlue());
   getRemoteObject().set("background", properties);
 }
Пример #18
0
 private void apply(GC gc, SvgGradientStop stop, boolean foreground) {
   Color c = new Color(gc.getDevice(), stop.color.red(), stop.color.green(), stop.color.blue());
   if (foreground) {
     gc.setForeground(c);
   } else {
     gc.setBackground(c);
   }
   c.dispose();
   gc.setAlpha((int) (255 * stop.opacity));
 }
  /*
   * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
   */
  public void widgetDisposed(DisposeEvent event) {
    if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) fStatusTextFont.dispose();
    fStatusTextFont = null;
    if (fStatusTextForegroundColor != null && !fStatusTextForegroundColor.isDisposed())
      fStatusTextForegroundColor.dispose();
    fStatusTextForegroundColor = null;

    fTextFont = null;
    fShell = null;
    fText = null;
  }
Пример #20
0
 /** @param offColor the offColor to set */
 public synchronized void setOffColor(Color offColor) {
   if (this.offColor != null && this.offColor.equals(offColor)) {
     return;
   }
   if ((offColor.getRed() << 16 | offColor.getGreen() << 8 | offColor.getBlue()) == 0xFFFFFF) {
     this.offColor = CustomMediaFactory.getInstance().getColor(new RGB(255, 255, 254));
   } else {
     this.offColor = offColor;
   }
   repaint();
 }
Пример #21
0
 /** Disposes of all resources associated with a particular instance of the PaintExample. */
 public void dispose() {
   if (paintSurface != null) paintSurface.dispose();
   if (paintColors != null)
     for (int i = 0; i < paintColors.length; ++i) {
       final Color color = paintColors[i];
       if (color != null) color.dispose();
     }
   paintDefaultFont = null;
   paintColors = null;
   paintSurface = null;
   freeResources();
 }
Пример #22
0
  /**
   * Test of the method <code>setTheme()</code>.
   *
   * @throws Exception handled by JUnit
   */
  public void testSetTheme() throws Exception {

    final Color color1 = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNotNull(color1);

    lnf.setTheme(new DummyTheme());
    lnf.initialize();
    assertFalse(color1.isDisposed());

    final Color color2 = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNull(color2);
  }
Пример #23
0
 public void dispose(Display display) {
   Map<RGB, Color> colorTable = fDisplayTable.get(display);
   if (colorTable != null) {
     Iterator<Color> e = colorTable.values().iterator();
     while (e.hasNext()) {
       Color color = e.next();
       if (color != null && !color.isDisposed()) {
         color.dispose();
       }
     }
   }
 }
Пример #24
0
  /**
   * Calculate gradient color.
   *
   * @param contrast Contrast on color
   * @param bg Background color
   * @return color
   */
  public static RGB getGradientColor(Color bg, double contrast) {
    int blue = bg.getBlue();
    blue = (int) (blue - (blue * contrast));
    blue = blue > 0 ? blue : 0;

    int red = bg.getRed();
    red = (int) (red - (red * contrast));
    red = red > 0 ? red : 0;

    int green = bg.getGreen();
    green = (int) (green - (green * contrast));
    green = green > 0 ? green : 0;

    return new RGB(red, green, blue);
  }
Пример #25
0
  /**
   * Factory method for creating a new IDiagramModelZentaObject for an IZentaElement
   *
   * @param element
   * @return a new IDiagramModelZentaObject
   */
  public static IDiagramModelZentaObject createDiagramModelZentaObject(IZentaElement element) {
    IDiagramModelZentaObject dmo = IZentaFactory.eINSTANCE.createDiagramModelZentaObject();
    dmo.setZentaElement(element);
    dmo.setType(Preferences.getDefaultFigureType(dmo));

    // Set user fill color
    if (Preferences.STORE.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_FILL_COLOR)) {
      Color fillColor = ColorFactory.getDefaultFillColor(dmo);
      if (fillColor != null) {
        dmo.setFillColor(ColorFactory.convertRGBToString(fillColor.getRGB()));
      }
    }

    return dmo;
  }
Пример #26
0
  /**
   * Returns a corner image for the specified position and color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param position the wanted position of the image
   * @param rgb the wanted color
   * @return the image
   */
  public static Image getCornerImage(DecorationPosition position, RGB rgb) {
    final String key = "CORNER_IMAGE:" + position + ":" + rgb; // $NON-NLS-1$ //$NON-NLS-2$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, 5, 5);
    final GC gc = new GC(image);
    gc.setBackground(color);

    switch (position) {
      case TOP_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 0, 0, 4});
        break;
      case CENTER_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 2, 0, 4});
        break;
      case BOTTOM_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 4, 0, 4});
        break;
      case TOP_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 0, 0, 4, 4});
        break;
      case CENTER_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 2, 0, 4, 4});
        break;
      case BOTTOM_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 4, 0, 4, 4});
        break;
    }

    gc.dispose();
    color.dispose();

    /*
     * Set the transparent color
     */
    final ImageData ideaData = image.getImageData();
    final int whitePixel = ideaData.palette.getPixel(new RGB(255, 255, 255));
    ideaData.transparentPixel = whitePixel;

    ir.put(key, image);

    return image;
  }
  @Test
  public void testDispatches() {
    dispatcher.dispatch();

    InOrder order = inOrder(gc);
    order.verify(gc).drawPolyline(aryEq(new int[] {0, 1, 5, 5}));
    order.verify(gc).setLineWidth(3);
    ArgumentCaptor<Color> captor = ArgumentCaptor.forClass(Color.class);
    order.verify(gc).setForeground(captor.capture());
    order.verify(gc).setAlpha(10);
    Color color = captor.getValue();
    assertEquals(50, color.getRed());
    assertEquals(100, color.getGreen());
    assertEquals(200, color.getBlue());
    order.verify(gc).drawPolyline(aryEq(new int[] {0, 1, 5, 5}));
  }
Пример #28
0
  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 dispose() {
   if (mOutlineColor != null) {
     mOutlineColor.dispose();
     mOutlineColor = null;
   }
 }
Пример #30
0
  /**
   * 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);
  }