Exemplo n.º 1
0
 public String toString(List<DataSeries> series) {
   StringBuilder buf = new StringBuilder();
   for (DataSeries s : series) {
     if (buf.length() > 0) buf.append(',');
     buf.append(s.getUUID()).append(';');
     buf.append(Colors.toHex(s.getColor())).append(';');
     buf.append(s.getLineStyle().name()).append(';');
     buf.append(s.isShowArea());
   }
   return buf.toString();
 }
Exemplo n.º 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);
    }
Exemplo n.º 3
0
    private void paintControl(Event e) {
      Color oldForeground = e.gc.getForeground();
      Color oldBackground = e.gc.getBackground();

      Point size = getSize();
      Rectangle r = new Rectangle(0, 0, size.x, size.y);

      renderer.drawRectangle(rootItem, item, e.gc, r);

      String text = item.getName();
      String info = getInfo();

      GC gc = e.gc;
      gc.setForeground(Colors.getTextColor(gc.getBackground()));
      gc.drawString(text, 2, 2, true);
      Point extent = gc.stringExtent(text);
      gc.drawString(info, 2, extent.y + 1, true);

      e.gc.setForeground(oldForeground);
      e.gc.setBackground(oldBackground);
    }
Exemplo n.º 4
0
  private void load(DataSeriesSet set, String config, List<DataSeries> series) {
    Map<String, DataSeries> uuid2series =
        set.getAvailableSeries().stream().collect(Collectors.toMap(s -> s.getUUID(), s -> s));

    String[] items = config.split(","); // $NON-NLS-1$
    for (String item : items) {
      String[] data = item.split(";"); // $NON-NLS-1$

      String uuid = data[0];
      DataSeries s = uuid2series.get(uuid);
      if (s != null) {
        series.add(s);

        if (data.length == 4) {
          s.setColor(Colors.toRGB(data[1]));
          s.setLineStyle(LineStyle.valueOf(data[2]));
          s.setShowArea(Boolean.parseBoolean(data[3]));
        }
      }
    }
  }