/* (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();
 }
  /* (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();
  }
  /* (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);
    }
  }