Esempio n. 1
0
  @Override
  protected void paintFigure(final org.eclipse.draw2d.Graphics graphics) {
    if (!getBackgroundColor().isDisposed()) {
      graphics.setBackgroundColor(getBackgroundColor());
    }
    final int boxWidth = getBounds().height / HALF;
    final int laneYStart = getBounds().y;
    final int y = laneYStart + boxWidth / HALF;
    graphics.fillRectangle(3, y, boxWidth, boxWidth);
    graphics.drawRectangle(3, y, boxWidth, boxWidth);

    final int textXOffset = getBounds().height;
    graphics.drawString(user.getName(), textXOffset, laneYStart);
  }
  @SuppressWarnings("unchecked")
  GanttDraw draw(final GanttRenderingData data, final boolean drawB) {

    // Check pre-conditions JEKB ugly fix data.getDurations() == null
    if ((data.getDurations() == null) || (data.getDurations().size() < 1)) {
      drawEmpty(data);
      return ClassicGantRenderer.EMPTY_GANTT_DRAW;
    }

    Collections.sort(data.getDurations());

    // compute a ruler only when drawB is drawn.
    if (drawB) {
      ruler = computeScaler(data);
    }

    // Graphics Setup
    data.getGraphics().setAntialias(SWT.OFF);
    data.getGraphics().setFont(font);
    final GanttDraw ganttDrawData = new GanttDraw(data.getGraphics(), ruler);
    lanes.clear();
    int laneIndex = 0;
    for (final IArtifact user : data.getTasks()) {
      final TaskLaneEntry entry = new TaskLaneEntry(user);
      entry.setLane(laneIndex++);
      lanes.put(user.getName(), entry);
    }

    drawColumnNames(data, lanes, ganttDrawData);
    drawGrid(data, laneIndex);

    final Rectangle clipping = data.getGraphics().getClipping();
    data.getGraphics()
        .setClipping(
            new Rectangle(
                data.getBounds().x,
                data.getBounds().y,
                data.getBounds().width,
                data.getBounds().height));

    this.typeReg = TypeRegistry.getInstance();

    data.getGraphics().setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));

    data.getGraphics().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));

    if (drawB) {
      drawDurations(data, ganttDrawData);
      drawMarker(data);
      drawRuler(data);
      LegendRenderer r = new LegendRenderer();
      r.drawLegend(
          data.getGraphics().getClipping().width / 2,
          Graphics.valueOf(data.getGraphics()),
          colorByTypeMap,
          false);
    }

    data.getGraphics().setClipping(clipping);

    data.setDrawnSize(
        new Point(
            data.getBounds().width,
            ClassicGantRenderer.LANE_START + (lanes.size() + 1) * ClassicGantRenderer.LANE_HEIGHT));

    // if (drawB) {
    ganttDrawData.setBounds(SWTUtil.convert(data.getBounds()));
    // } else {
    // }
    return ganttDrawData;
  }