コード例 #1
0
 /* (non-Javadoc)
  * @see org.eclipse.vtp.desktop.editors.core.theme.ComponentFrame#initializeGraphics(org.eclipse.swt.graphics.GC, java.util.Map)
  */
 public void initializeGraphics(GC gc, Map<String, Object> resourceMap) {
   Font originalFont = gc.getFont();
   Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL);
   gc.setFont(nameFont);
   Point extent = gc.stringExtent(this.getDesignElement().getName());
   if (extent.x > 110) // too long, attempt to wrap text
   {
     extent.x = 0;
     String[] parts = this.getDesignElement().getName().split(" ");
     Point stringExtent = gc.stringExtent(parts[0]);
     int ew = 0;
     ew += stringExtent.x;
     extent.x = stringExtent.x;
     for (int i = 1; i < parts.length; i++) {
       stringExtent = gc.stringExtent(" " + parts[i]);
       if (ew + stringExtent.x > 110) // wrap it
       {
         stringExtent = gc.stringExtent(parts[i]);
         if (extent.x < ew) extent.x = ew;
         ew = stringExtent.x;
         extent.y += 2 + stringExtent.y;
       } else ew += stringExtent.x;
     }
     if (extent.x < ew) extent.x = ew;
   }
   int width = (extent.x + 35);
   int height = (extent.y + 10 + (uiElement.hasConnectors() ? 12 : 0));
   Point centerPoint = uiElement.getCenterPoint();
   upperLeft = new Point(centerPoint.x - (width / 2), centerPoint.y - (height / 2));
   int buffer = width % 2;
   lowerRight = new Point(upperLeft.x + width + buffer, upperLeft.y + height + buffer);
   gc.setFont(originalFont);
   nameFont.dispose();
 }
コード例 #2
0
ファイル: Sleak.java プロジェクト: cbsrbiobank/biobank
 void paintCanvas(Event event) {
   canvas.setCursor(null);
   int index = list.getSelectionIndex();
   if (index == -1) return;
   GC gc = event.gc;
   Object object = objects[index];
   if (object instanceof Color) {
     if (((Color) object).isDisposed()) return;
     gc.setBackground((Color) object);
     gc.fillRectangle(canvas.getClientArea());
     return;
   }
   if (object instanceof Cursor) {
     if (((Cursor) object).isDisposed()) return;
     canvas.setCursor((Cursor) object);
     return;
   }
   if (object instanceof Font) {
     if (((Font) object).isDisposed()) return;
     gc.setFont((Font) object);
     FontData[] array = gc.getFont().getFontData();
     StringBuffer sb = new StringBuffer();
     String lf = text.getLineDelimiter();
     for (int i = 0; i < array.length; i++) {
       FontData data = array[i];
       String style = "NORMAL"; // $NON-NLS-1$
       int bits = data.getStyle();
       if (bits != 0) {
         if ((bits & SWT.BOLD) != 0) style = "BOLD "; // $NON-NLS-1$
         if ((bits & SWT.ITALIC) != 0) style += "ITALIC"; // $NON-NLS-1$
       }
       sb.append(data.getName())
           .append(" ")
           .append(data.getHeight()) // $NON-NLS-1$
           .append(" ")
           .append(style)
           .append(lf); // $NON-NLS-1$
     }
     gc.drawString(sb.toString(), 0, 0);
     return;
   }
   // NOTHING TO DRAW FOR GC
   // if (object instanceof GC) {
   // return;
   // }
   if (object instanceof Image) {
     if (((Image) object).isDisposed()) return;
     gc.drawImage((Image) object, 0, 0);
     return;
   }
   if (object instanceof Region) {
     if (((Region) object).isDisposed()) return;
     String string = ((Region) object).getBounds().toString();
     gc.drawString(string, 0, 0);
     return;
   }
 }
コード例 #3
0
  private static void paintImage(GC gc, Point size) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);
    gc.drawText(gc.getFont().getFontData()[0].toString(), 10, 10, true);
  }
コード例 #4
0
  // @see
  // org.gudy.azureus2.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, org.gudy.azureus2.ui.swt.views.table.TableCellSWT)
  public void cellPaint(GC gc, TableCellSWT cell) {
    VuzeActivitiesEntry entry = (VuzeActivitiesEntry) cell.getDataSource();
    if (entry == null) {
      return;
    }

    TableRow row = cell.getTableRow();
    if (row == null) {
      return;
    }
    String text = (String) row.getData("text");

    if (text != null && text.length() > 0) {
      if (font == null) {
        FontData[] fontData = gc.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        font = new Font(gc.getDevice(), fontData);
      }
      gc.setFont(font);

      Rectangle bounds = getDrawBounds(cell);

      GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, true, true, SWT.WRAP | SWT.CENTER);

      sp.calculateMetrics();

      if (sp.hasHitUrl()) {
        URLInfo[] hitUrlInfo = sp.getHitUrlInfo();
        for (int i = 0; i < hitUrlInfo.length; i++) {
          URLInfo info = hitUrlInfo[i];
          // handle fake row when showing in column editor

          info.urlUnderline = cell.getTableRow() == null || cell.getTableRow().isSelected();
          if (info.urlUnderline) {
            info.urlColor = null;
          } else {
            info.urlColor = colorLinkNormal;
          }
        }
        int[] mouseOfs = cell.getMouseOffset();
        if (mouseOfs != null) {
          Rectangle realBounds = cell.getBounds();
          URLInfo hitUrl = sp.getHitUrl(mouseOfs[0] + realBounds.x, mouseOfs[1] + realBounds.y);
          if (hitUrl != null) {
            hitUrl.urlColor = colorLinkHover;
          }
        }
      }

      sp.printString();
    }
  }
コード例 #5
0
ファイル: ChordList.java プロジェクト: akochurov/tuxguitar
 protected Font getFont(GC painter) {
   if (this.font == null || this.font.isDisposed()) {
     Font available = painter.getFont();
     if (available == null || available.isDisposed()) {
       available = getDisplay().getSystemFont();
     }
     FontData[] datas = available.getFontData();
     if (datas.length > 0) {
       this.font =
           new Font(getDisplay(), datas[0].getName(), Math.min(7, datas[0].getHeight()), SWT.BOLD);
     }
   }
   return this.font;
 }
コード例 #6
0
  /**
   * Create a background image that shows the scale and channels as requested
   *
   * @return
   */
  private Image CreateBackgroundImage(int numHorizontalLines, int numVerticalLines) {
    // * Image i = new Image(device, boundsRectangle);
    // * GC gc = new GC(i);
    // * gc.drawRectangle(0, 0, 50, 50);
    // * gc.dispose();
    Rectangle rect = getBounds();
    if ((rect.width == 0) || (rect.height == 0)) return null;
    Image TheImage = new Image(getDisplay(), rect);
    GC gc = new GC(TheImage);
    gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
    int step = (getSize().y - 20) / (numHorizontalLines - 1);
    int width = getSize().x;
    int height = getSize().y;
    gc.fillRectangle(0, 0, width, getSize().y);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_CYAN));
    int Value =
        myLowRangeValue
            + (int) (10.0 * (float) (myhighValue - myLowRangeValue) / (float) rect.height);
    int RangeStep =
        (int)
            ((float) (rect.height - 20)
                / (float) (numHorizontalLines - 1)
                * (float) (myhighValue - myLowRangeValue)
                / (float) rect.height);
    for (int i = 0; i < numHorizontalLines; i++) {
      gc.drawLine(0, 10 + (step * i), width, 10 + (step * i));
      gc.drawString(
          Integer.toString(Value + RangeStep * (numHorizontalLines - (i + 1))),
          10,
          10 + (step * i));
    }
    step = (getSize().x - 20) / (numVerticalLines - 1);
    for (int i = 0; i < numVerticalLines; i++) {
      gc.drawLine(10 + (step * i), 0, 10 + (step * i), height);
    }
    step = (int) Math.round(gc.getFont().getFontData()[0].height * 1.5);
    if (ShowLabels) {
      for (int i = 0; i < chan.length; i++) {
        gc.setForeground(chan[i].fg);
        gc.drawString(chan[i].name, 50, 10 + (step * i));
      }
    }
    gc.setForeground(chan[0].fg);
    gc.drawString(myStatus, 200, 10);

    // gc.drawString(string, x, y)
    gc.dispose();
    return TheImage;
  }
コード例 #7
0
ファイル: ShellCaption.java プロジェクト: seanws/tagsea
  public void paintControl(PaintEvent e) {

    if (text == null || foreground == null) return;

    GC gc = e.gc;

    Color oldForeground = gc.getForeground(), oldBackground = gc.getBackground();
    Font oldFont = gc.getFont();
    int oldAntiAlias = gc.getTextAntialias();

    gc.setTextAntialias(SWT.ON);

    if (background != null) gc.setBackground(background);
    if (font != null) gc.setFont(font);

    int finalX = x, finalY = y;

    if (useRelativeXY) {
      Point size = shell.getSize();
      Point textExtent = gc.textExtent(text);

      if (x >= 0) finalX = x;
      else {
        finalX = size.x + x;
        finalX -= textExtent.x;
      }

      if (y >= 0) finalY = y;
      else {
        finalY = size.y + y;
        finalY -= textExtent.y;
      }
    }

    gc.setForeground(foreground);
    gc.drawText(text, finalX, finalY, background == null);

    gc.setForeground(oldForeground);
    gc.setBackground(oldBackground);
    gc.setFont(oldFont);
    gc.setTextAntialias(oldAntiAlias);
  }
コード例 #8
0
  private static void paintImage2(GC gc, Point size, int f) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    // Scale line width, corner roundness, and font size.
    // Caveat: line width expands in all directions, so the origin also has to move.

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.setLineWidth(f);
    gc.drawRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);
    FontData fontData = gc.getFont().getFontData()[0];
    fontData.setHeight(fontData.getHeight() * f);
    Font font = new Font(gc.getDevice(), fontData);
    try {
      gc.setFont(font);
      gc.drawText(fontData.toString(), 10 * f, 10 * f, true);
    } finally {
      font.dispose();
    }
  }
コード例 #9
0
ファイル: TimeSeriesView.java プロジェクト: npp97/magic
  public void paintCanvas(GC gc, Point point) {
    if (timeSeries != null) {

      Font old = gc.getFont();
      FontData fd = old.getFontData()[0];
      fd.setHeight(20);
      gc.setFont(new Font(display, fd));
      gc.setForeground(new Color(display, 200, 200, 200));
      Painter.drawText(title, gc, 50, 20, PosHorizontal.LEFT, PosVerical.TOP);
      gc.setFont(old);

      if (point != null) {
        updateRangeOfOutputWindow(point.x, point.y);
      }

      updateDataWindowConversionValues();

      Color color_bluegreen = new Color(display, 190, 240, 190);
      int avg = valueToGraph(dataSum / dataCount);
      gc.setForeground(color_bluegreen);
      gc.drawLine(xStart, avg, xEnd, avg);

      drawGrid(gc);

      drawXYAxis(gc);

      if (compare_timeSeries != null) {

        Color color_red = new Color(display, 240, 0, 0);
        Color color_redgrey = new Color(display, 240, 190, 190);

        drawTimeSeries(gc, compare_timeSeries, color_red, color_redgrey);
      }

      drawTimeSeries(gc, timeSeries, color_black, color_grey);
    }
  }
コード例 #10
0
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.mantis.MantisComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "rust.selection.color", 82, 140, 55);
    Color elementBlue = getColor(gc, resourceMap, "rust.element.color", 207, 234, 195);
    Color elementGradBlue = getColor(gc, resourceMap, "rust.element.color.gradient", 161, 211, 137);
    Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);
    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;
    int mainBodyHeight = height - (uiElement.hasConnectors() ? 12 : 0);

    if (uiElement.hasConnectors()) {
      // draw inspector tray
      gc.setBackground(elementBlue);
      gc.fillRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);

      // draw inspector tray border
      if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
        gc.setForeground(selectedColor);
      }
      gc.drawRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);
    }

    // draw main body
    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);
    gc.setBackground(elementGradBlue);
    gc.fillRoundRectangle(
        upperLeft.x + 1,
        upperLeft.y + (mainBodyHeight / 2) - 1,
        lowerRight.x - upperLeft.x - 2,
        (mainBodyHeight / 2) + (mainBodyHeight % 2),
        20,
        20);
    //		gc.setForeground(elementBlue);
    //		gc.fillGradientRectangle(upperLeft.x + 2,
    //			upperLeft.y
    //			+ (mainBodyHeight / 3),
    //			lowerRight.x - upperLeft.x - 4,
    //			((mainBodyHeight / 3) * 2) - 5,
    //			true);
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw main body border
    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);

    gc.setForeground(foreground);
    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 19, lowerRight.y - 8, lowerRight.x - 5, lowerRight.y - 8);
      //			gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 10, lowerRight.y - 3, lowerRight.x - 5, lowerRight.y - 8);
    }

    // draw icon
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(
          icon,
          upperLeft.x + 5,
          upperLeft.y + (((mainBodyHeight - 16) / 2) + ((mainBodyHeight - 16) % 2)));
    }

    // draw element name
    int curX = upperLeft.x + 25;
    int curY = upperLeft.y + 5;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 2 + stringExtent.y;
        curX = upperLeft.x + 25;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }

    // draw decorator icons
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }

    // resource cleanup
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    nameFont.dispose();
  }
コード例 #11
0
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.attraction.AttractionComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "attraction.selection.color", 0, 0, 255);
    Color elementBlue = getColor(gc, resourceMap, "attraction.element.color", 201, 229, 255);
    Color elementGradBlue =
        getColor(gc, resourceMap, "attraction.element.color.gradient", 153, 206, 255);
    Font nameFont = getFont(gc, resourceMap, "attraction.element.font", "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);

    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;

    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_PRINTING) == 0) {
      gc.setBackground(elementGradBlue);
      gc.fillRoundRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 2),
          lowerRight.x - upperLeft.x,
          ((lowerRight.y - upperLeft.y) / 2),
          12,
          12);
      gc.setForeground(elementBlue);
      gc.fillGradientRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 3),
          lowerRight.x - upperLeft.x,
          (((lowerRight.y - upperLeft.y) / 3) * 2) - 5,
          true);
    }
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 17, lowerRight.y - 10, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 5, lowerRight.x - 3, lowerRight.y - 10);
    }

    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(icon, upperLeft.x + 10, upperLeft.y + 12);
    }
    int curX = upperLeft.x + 30;
    int curY = upperLeft.y + 15;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 3 + stringExtent.y;
        curX = upperLeft.x + 30;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }
  }