예제 #1
0
 public void dispose() {
   if (editor != null) {
     editor.dispose();
     editor = null;
   }
   if (canvas != null && !canvas.isDisposed()) {
     canvas.dispose();
   }
   canvas = null;
   if (valueImage != null && !valueImage.isDisposed()) {
     valueImage.dispose();
   }
   valueImage = null;
   if (nameLayout != null && !nameLayout.isDisposed()) {
     nameLayout.dispose();
   }
   nameLayout = null;
   if (valueLayout != null && !valueLayout.isDisposed()) {
     valueLayout.dispose();
   }
   valueLayout = null;
   //        if (border != null && !border.isDisposed()) {
   //            border.dispose();
   //        }
   //        border = null;
 }
예제 #2
0
  private void updateLabels() {
    Object value = source.getPropertyValue(descriptor.getId());
    if (nameLayout != null && !nameLayout.isDisposed()) {
      nameLayout.setText(descriptor.getDisplayName());
      nameLayout.setStyle(
          new TextStyle(canvas.getFont(), canvas.getForeground(), null),
          0,
          nameLayout.getText().length());
    }
    ILabelDescriptor labelDescriptor = descriptor.getLabelDescriptor();
    ImageDescriptor image = labelDescriptor == null ? null : labelDescriptor.getImage(value);
    if (valueImage != null) {
      valueImage.dispose();
    }
    valueImage = image == null ? null : image.createImage(false, Display.getCurrent());

    ColorDescriptor color = labelDescriptor == null ? null : labelDescriptor.getForeground(value);
    if (valueColor != null) {
      valueColor.dispose();
    }
    valueColor = color == null ? null : color.createColor(Display.getCurrent());

    FontDescriptor font = labelDescriptor == null ? null : labelDescriptor.getFont(value);
    if (valueFont != null) {
      valueFont.dispose();
    }
    valueFont = font == null ? null : font.createFont(Display.getCurrent());

    if (valueLayout != null && !valueLayout.isDisposed()) {
      String valueText =
          labelDescriptor == null
              ? (value == null
                  ? "" //$NON-NLS-1$
                  : value.toString())
              : labelDescriptor.getText(value);
      if (valueText == null) valueText = ""; // $NON-NLS-1$
      valueLayout.setText(valueText);
      valueLayout.setStyle(
          new TextStyle(
              valueFont == null ? canvas.getFont() : valueFont,
              valueColor == null ? canvas.getForeground() : valueColor,
              null),
          0,
          valueText.length());
    }
    canvas.layout(true);
    canvas.redraw();
  }
예제 #3
0
 protected void finalize() throws Throwable {
   System.out.println("layout finalized"); // $NON-NLS-1$
   if (layout != null && !layout.isDisposed()) {
     layout.dispose();
   }
   layout = null;
   super.finalize();
 }
예제 #4
0
  /**
   * Provides a TextLayout that can be used for Bidi purposes. This TextLayout should not be
   * disposed by clients.
   *
   * @return an SWT TextLayout instance
   */
  public synchronized TextLayout getTextLayout(int orientation) {
    if (layout == null || layout.isDisposed()) layout = new TextLayout(Display.getDefault());

    layout.setOrientation(orientation);
    return layout;
  }
예제 #5
0
  private void paintCanvas(GC gc, int px, int py, int pw, int ph) {
    if (canvas == null || canvas.isDisposed()) return;

    Rectangle r = canvas.getBounds();
    Color b1 = canvas.getBackground();

    gc.setAntialias(SWT.ON);
    gc.setTextAntialias(SWT.ON);

    // Draw selection background:
    if (isSelected()) {
      gc.setBackground(selectedBackground);
      gc.fillRoundRectangle(0, 0, r.width, r.height, CORNER, CORNER);
    } else if (showingHover) {
      int oldAlpha = gc.getAlpha();
      gc.setAlpha(96 * oldAlpha / 255);
      gc.setBackground(selectedBackground);
      gc.fillRoundRectangle(0, 0, r.width, r.height, CORNER, CORNER);
      gc.setAlpha(oldAlpha);
    }

    // Draw edit indicator:
    if (showingEditorHover) {
      int oldAlpha = gc.getAlpha();
      gc.setAlpha(192 * oldAlpha / 255);
      gc.setBackground(b1);
      gc.fillRoundRectangle(
          r.width / 2 + HOVER_SHRINK_H,
          HOVER_SHRINK_V,
          r.width / 2 - HOVER_SHRINK_H - HOVER_SHRINK_H,
          r.height - HOVER_SHRINK_V - HOVER_SHRINK_V,
          HOVER_CORNER,
          HOVER_CORNER);
      gc.setAlpha(oldAlpha);
      //
      //            Control ec = editor == null ? null : editor.getControl();
      //            if (ec != null && !ec.isDisposed()) {
      //                Rectangle eb = ec.getBounds();
      //                gc.setAlpha(192);
      //                gc.setBackground(b1);
      //                gc.fillRoundRectangle(eb.x, eb.y, eb.width, eb.height, 8, 8);
      //                gc.setAlpha(255);
      //            }
    }

    // Draw property name label:
    gc.setForeground(canvas.getForeground());
    gc.setFont(canvas.getFont());
    if (nameLayout != null && !nameLayout.isDisposed()) {
      Rectangle nb = nameLayout.getBounds();
      nameLayout.draw(gc, MARGIN_H, (r.height - nb.height) / 2);
    }

    // Draw property value repsentating image:
    int right = r.width - MARGIN_H;
    if (valueImage != null && !valueImage.isDisposed()) {
      Rectangle ib = valueImage.getBounds();
      int iw, ih;
      if (ib.height > r.height) {
        ih = r.height;
        iw = ib.width * r.height / ib.height;
      } else {
        ih = ib.height;
        iw = ib.width;
      }
      gc.drawImage(valueImage, 0, 0, ib.width, ib.height, right - iw, (r.height - ih) / 2, iw, ih);
      right = right - iw - 3;
    }

    // Draw property value label:
    if (valueLayout != null && !valueLayout.isDisposed()) {
      Rectangle vb = valueLayout.getBounds();
      valueLayout.draw(gc, right - vb.width, (r.height - vb.height) / 2);
    }
  }