Exemple #1
0
 private String getInfo() {
   return String.format(
       "%s (%s%%)",
       Values.Amount.format(item.getActual()), // $NON-NLS-1$
       Values.Percent.format(
           (double) item.getActual() / (double) model.getRootNode().getActual()));
 }
Exemple #2
0
    @Override
    public void render(
        final PaintEvent event,
        final ITreeModel<IRectangle<TaxonomyNode>> model,
        final IRectangle<TaxonomyNode> rectangle,
        final IColorProvider<TaxonomyNode, Color> colorProvider,
        final ILabelProvider<TaxonomyNode> labelProvider) {
      TaxonomyNode item = rectangle.getNode();

      if (item.getClassification() != null) return;

      Color oldForeground = event.gc.getForeground();
      Color oldBackground = event.gc.getBackground();

      Rectangle r =
          new Rectangle(
              rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight());
      this.colorProvider.drawRectangle(model.getRoot().getNode(), item, event.gc, r);

      String label = item.getName();
      String info =
          String.format(
              "%s (%s%%)",
              Values.Amount.format(item.getActual()), // $NON-NLS-1$
              Values.Percent.format(
                  (double) item.getActual() / (double) this.model.getRootNode().getActual()));

      event.gc.setForeground(Colors.getTextColor(event.gc.getBackground()));

      Point labelExtend = event.gc.textExtent(label);
      Point infoExtend = event.gc.textExtent(info);

      int width = Math.max(labelExtend.x, infoExtend.x);
      if (width <= rectangle.getWidth() || rectangle.getWidth() > rectangle.getHeight()) {
        event.gc.drawText(label, r.x + 2, r.y + 2, true);
        event.gc.drawText(info, r.x + 2, r.y + 2 + labelExtend.y, true);
      } else {
        final Transform transform = new Transform(event.display);
        try {
          transform.translate(r.x, r.y);
          transform.rotate(-90);
          event.gc.setTransform(transform);
          event.gc.drawString(label, -labelExtend.x - 2, 2, true);
          event.gc.drawString(info, -infoExtend.x - 2, 2 + labelExtend.y, true);
        } finally {
          transform.dispose();
        }
      }

      event.gc.setForeground(oldForeground);
      event.gc.setBackground(oldBackground);
    }