Пример #1
0
public class GanttDiagram2 {

	private final Project2 project;
	private final double dayWith = 20;

	public GanttDiagram2(Project2 project) {
		this.project = project;
	}

	private final UFont font = new UFont("Serif", Font.PLAIN, 9);
	private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font);

	public void draw(UGraphic ug, double x, double y) {

		final TextBlock timeHeader = project.getTimeHeader(dayWith);
		final Row row = getMainRow();
		final TextBlock headers = row.header();

		final double deltaX = headers.calculateDimension(ug.getStringBounder()).getWidth();
		final double deltaY = timeHeader.calculateDimension(ug.getStringBounder()).getHeight();

		headers.drawU(ug.apply(new UTranslate(x, (y + deltaY))));
		final TextBlock tbRow = row.asTextBloc(project.getTimeConverter(dayWith));
		tbRow.drawU(ug.apply(new UTranslate((x + deltaX), (y + deltaY))));

		timeHeader.drawU(ug.apply(new UTranslate((x + deltaX), y)));
	}

	private Row getMainRow() {
		final List<Task> tasks = project.getTasks();
		final List<Row> rows = new ArrayList<Row>();
		for (Task t : tasks) {
			final String text = t.getCode();
			final TextBlock label = Display.create(text).create(fontConfig, HorizontalAlignment.LEFT,
					new SpriteContainerEmpty());
			rows.add(new RowSimple((Day) t.getStart(), (Day) t.getEnd(), HtmlColorUtils.BLACK, TextBlockUtils
					.withMargin(label, 3, 3)));
		}
		final Row row = RowUtils.merge(rows);
		return row;
	}

	public double getWidth(StringBounder stringBounder) {
		final TextBlock timeHeader = project.getTimeHeader(dayWith);
		final Row row = getMainRow();
		final TextBlock headers = row.header();
		return headers.calculateDimension(stringBounder).getWidth()
				+ timeHeader.calculateDimension(stringBounder).getWidth() + 1;
	}

	public double getHeight(StringBounder stringBounder) {
		final TextBlock timeHeader = project.getTimeHeader(dayWith);
		final Row row = getMainRow();
		final TextBlock headers = row.header();
		return headers.calculateDimension(stringBounder).getHeight()
				+ timeHeader.calculateDimension(stringBounder).getHeight();
	}

}
Пример #2
0
class ItemHeader {

  private final UFont font = new UFont("Serif", Font.PLAIN, 9);
  private final Project project;
  private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font);

  public ItemHeader(Project project) {
    this.project = project;
  }

  public void draw(UGraphic ug, double x, double y) {

    final StringBounder stringBounder = ug.getStringBounder();

    ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK));
    ug.apply(new UTranslate(x, y))
        .draw(new URectangle(getWidth(stringBounder), getHeight(stringBounder)));

    for (Item it : project.getValidItems()) {
      final TextBlock b =
          Display.create("" + it.getCode())
              .create(fontConfig, HorizontalAlignment.LEFT, new SpriteContainerEmpty());
      final Dimension2D dim = b.calculateDimension(stringBounder);
      b.drawU(ug.apply(new UTranslate(x, y)));
      y += dim.getHeight();
      ug.apply(new UTranslate(x, y)).draw(new ULine(getWidth(stringBounder), 0));
    }
  }

  public double getWidth(StringBounder stringBounder) {
    double width = 0;
    for (Item it : project.getValidItems()) {
      final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode());
      width = Math.max(width, dim.getWidth());
    }
    return width;
  }

  public double getHeight(StringBounder stringBounder) {
    double height = 0;
    for (Item it : project.getValidItems()) {
      final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode());
      height += dim.getHeight();
    }
    return height;
  }

  public double getPosition(StringBounder stringBounder, Item item) {
    double pos = 0;
    for (Item it : project.getValidItems()) {
      if (it == item) {
        return pos;
      }
      final Dimension2D dim = stringBounder.calculateDimension(font, it.getCode());
      pos += dim.getHeight();
    }
    throw new IllegalArgumentException();
  }
}
Пример #3
0
 public EntityImageDefault(IEntity entity) {
   super(entity);
   this.textBlock =
       entity
           .getDisplay()
           .create(
               FontConfiguration.blackBlueTrue(getFont14()),
               HorizontalAlignment.CENTER,
               new SpriteContainerEmpty());
 }
Пример #4
0
  public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat)
      throws IOException {
    final Display display = Display.create(lines);
    final UFont font = new UFont("Serif", Font.PLAIN, 14);
    final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(font);
    final Sheet sheet =
        new CreoleParser(fontConfiguration, HorizontalAlignment.LEFT, null, CreoleMode.FULL)
            .createSheet(display);
    final SheetBlock1 sheetBlock = new SheetBlock1(sheet, 0, 0);

    final ImageBuilder builder =
        new ImageBuilder(new ColorMapperIdentity(), 1.0, null, null, null, 0, 0, null, false);
    builder.setUDrawable(sheetBlock);
    return builder.writeImageTOBEMOVED(fileFormat, os);

    // final Dimension2D dim = TextBlockUtils.getDimension(sheetBlock);
    // final UGraphic2 ug = fileFormat.createUGraphic(new ColorMapperIdentity(), 1, dim, null,
    // false);
    // // sheetBlock.drawU(ug.apply(new UTranslate(0, 10)));
    // sheetBlock.drawU(ug);
    // ug.writeImageTOBEMOVED(os, null, 96);
    // return new ImageDataSimple(dim);
  }
Пример #5
0
public class TimeHeaderMonth extends AbstractTextBlock implements TextBlock {

  private final Day start;
  private final Day end;
  private final TimeLine timeline;
  private final double dayWidth;

  private final UFont font = new UFont("Serif", Font.PLAIN, 9);
  private final FontConfiguration fontConfig = FontConfiguration.blackBlueTrue(font);

  public TimeHeaderMonth(Day start, Day end, TimeLine timeline, double dayWidth) {
    this.start = start;
    this.end = end;
    this.timeline = timeline;
    this.dayWidth = dayWidth;
  }

  public void drawU(UGraphic ug) {
    int n = 0;
    String last = null;

    double pendingX = -1;
    for (Day d = start; d.compareTo(end) <= 0; d = (Day) timeline.next(d)) {
      final String text = "" + d.getMonth().name();
      if (pendingX == -1) {
        pendingX = n * dayWidth;
        last = text;
      }
      ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK));
      ug = ug.apply(new UChangeBackColor(HtmlColorUtils.WHITE));
      if (text.equals(last) == false) {
        manage(ug, 0, 0, n, last, pendingX);
        pendingX = n * dayWidth;
      }
      last = text;
      n++;
    }
    manage(ug, 0, 0, n, last, pendingX);
  }

  private void manage(UGraphic ug, double x, double y, int n, String last, double pendingX) {
    final double width = n * dayWidth - pendingX;
    ug.apply(new UTranslate(x + pendingX, y)).draw(new URectangle(width, getHeight()));
    final TextBlock b =
        Display.create(last)
            .create(fontConfig, HorizontalAlignment.LEFT, new SpriteContainerEmpty());
    final Dimension2D dimText = b.calculateDimension(ug.getStringBounder());
    final double diffX = width - dimText.getWidth();
    final double diffY = getHeight() - dimText.getHeight();
    b.drawU(ug.apply(new UTranslate((x + pendingX + diffX / 2), (y + diffY / 2))));
  }

  private double getHeight() {
    return 20;
  }

  public Dimension2D calculateDimension(StringBounder stringBounder) {
    int n = 0;
    for (Day d = start; d.compareTo(end) <= 0; d = (Day) timeline.next(d)) {
      n++;
    }
    return new Dimension2DDouble(n * dayWidth, getHeight());
  }
}