protected int addLabelBox(
      String text,
      int xPos,
      int yPos,
      int labelWidth,
      int labelHeight,
      int fontSize,
      float scaleFactor) {
    Box labelBox = ModelFactory.eINSTANCE.createBox();
    labelBox.setSize(new Dimension(labelWidth, labelHeight));
    labelBox.setLocation(new Point(xPos, yPos));
    LabelBoxPrinter labelBoxPrinter = new LabelBoxPrinter(scaleFactor);
    labelBox.setBoxPrinter(labelBoxPrinter);

    labelBox.setID("Standard Label"); // $NON-NLS-1$
    labelBoxPrinter.setText(text);
    labelBoxPrinter.setHorizontalAlignment(SWT.CENTER);
    try {
      FontData data = Display.getDefault().getSystemFont().getFontData()[0];

      data.setHeight(fontSize);
      data.setStyle(SWT.BOLD);

      Font font = AWTSWTImageUtils.swtFontToAwt(data);
      labelBoxPrinter.setFont(font);

    } catch (Exception e) {
      // oh well don't have that font type
    }
    boxes.add(labelBox);
    return labelHeight;
  }
예제 #2
0
  /**
   * Iterates through the Page's Boxes, drawing to the provided Graphics object
   *
   * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
   */
  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
      throws PrinterException {

    if (pageIndex >= 1) {
      return Printable.NO_SUCH_PAGE;
    }

    Graphics2D graphics2d = (Graphics2D) graphics;

    AffineTransform at = graphics2d.getTransform();
    double dpi = at.getScaleX() * 72;

    if (PrintingPlugin.isDebugging(TRACE_PRINTING)) {
      PrintingPlugin.log("Printing page " + pageIndex, null); // $NON-NLS-1$
      System.out.println("PageFormat: " + pageFormat); // $NON-NLS-1$
      System.out.println("PageFormat height: " + pageFormat.getHeight()); // $NON-NLS-1$
      System.out.println("PageFormat width: " + pageFormat.getWidth()); // $NON-NLS-1$
      System.out.println(
          "PageFormat imageableX,Y "
              + pageFormat.getImageableX()
              + ", "
              + pageFormat.getImageableY()); // $NON-NLS-1$ //$NON-NLS-2$
      System.out.println(
          "PageFormat imageable height: " + pageFormat.getImageableHeight()); // $NON-NLS-1$
      System.out.println(
          "PageFormat imageable width: " + pageFormat.getImageableWidth()); // $NON-NLS-1$
      System.out.println(
          "PageFormat orientation (LANDSCAPE="
              + PageFormat.LANDSCAPE
              + ", PORTRAIT="
              + PageFormat.PORTRAIT
              + "): "
              + pageFormat.getOrientation()); // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$

      System.out.println("Graphics: clip bounds: " + graphics2d.getClipBounds()); // $NON-NLS-1$
      System.out.println("Transform: scaleX: " + at.getScaleX()); // $NON-NLS-1$
      System.out.println("Transform: scaleY: " + at.getScaleY()); // $NON-NLS-1$
      System.out.println("DPI?? : " + dpi); // $NON-NLS-1$
    }

    graphics2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

    Iterator<Box> iter = diagram.getBoxes().iterator();
    while (iter.hasNext()) {

      Box box = iter.next();
      graphics2d =
          (Graphics2D)
              graphics.create(
                  box.getLocation().x,
                  box.getLocation().y,
                  box.getSize().width,
                  box.getSize().height);

      box.getBoxPrinter().draw(graphics2d, monitor);
    }

    return Printable.PAGE_EXISTS;
  }
 protected void addLegendBox(int xPos, int yPos, int legendWidth, int legendHeight) {
   Box legendBox = ModelFactory.eINSTANCE.createBox();
   MapGraphicBoxPrinter legend = new MapGraphicBoxPrinter(page);
   legend.setMapGraphic(MapGraphicChooserDialog.findResource(LegendGraphic.class));
   legendBox.setBoxPrinter(legend);
   legendBox.setID("Legend Box"); // $NON-NLS-1$
   legendBox.setLocation(new Point(xPos, yPos));
   legendBox.setSize(new Dimension(legendWidth, legendHeight));
   boxes.add(legendBox);
 }
 protected void addScale(int xPos, int yPos, int scaleWidth, int scaleHeight) {
   Box scaleBox = ModelFactory.eINSTANCE.createBox();
   MapGraphicBoxPrinter scale = new MapGraphicBoxPrinter(page);
   scale.setMapGraphic(MapGraphicChooserDialog.findResource(ScalebarMapGraphic.class));
   scaleBox.setBoxPrinter(scale);
   scaleBox.setID("Scalebar Box"); // $NON-NLS-1$
   scaleBox.setLocation(new Point(xPos, yPos));
   scaleBox.setSize(new Dimension(scaleWidth, scaleHeight));
   boxes.add(scaleBox);
 }
  protected Rectangle addMapBox(
      Map map, int xPos, int yPos, int mapWidth, int mapHeight, Dimension paperSize) {
    Box mapBox = ModelFactory.eINSTANCE.createBox();
    MapBoxPrinter mapBoxPrinter = new MapBoxPrinter();
    mapBox.setID("Standard Map Box"); // $NON-NLS-1$
    mapBox.setBoxPrinter(mapBoxPrinter);
    mapBoxPrinter.setMap(map);

    Rectangle mapBounds = new Rectangle(xPos, yPos, mapWidth, mapHeight);
    mapBox.setSize(new Dimension(mapBounds.width, mapBounds.height));
    mapBox.setPaperSize(paperSize);

    mapBox.setLocation(new Point(mapBounds.x, mapBounds.y));
    boxes.add(mapBox);
    return mapBounds;
  }