Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.HomePrint


    Graphics2D g2D = (Graphics2D)g;
    g2D.setFont(this.defaultFont);
    g2D.setColor(Color.WHITE);
    g2D.fill(new Rectangle2D.Double(0, 0, pageFormat.getWidth(), pageFormat.getHeight()));
    int pageExists = NO_SUCH_PAGE;
    HomePrint homePrint = this.home.getPrint();
   
    // Prepare header and footer
    float imageableY = (float)pageFormat.getImageableY();
    float imageableHeight = (float)pageFormat.getImageableHeight();
    String header = null;
    float  xHeader = 0;
    float  yHeader = 0;
    float  xFixedHeader = 0;
    float  yFixedHeader = 0;
    String footer = null;
    float  xFooter = 0;
    float  yFooter = 0;
    float  xFixedFooter = 0;
    float  yFixedFooter = 0;
   
    if (this.fixedHeaderLabel != null) {
      this.fixedHeaderLabel.setSize((int)pageFormat.getImageableWidth(), this.fixedHeaderLabel.getPreferredSize().height);
      imageableHeight -= this.fixedHeaderLabel.getHeight() + HEADER_FOOTER_MARGIN;
      imageableY += this.fixedHeaderLabel.getHeight() + HEADER_FOOTER_MARGIN;
      xFixedHeader = (float)pageFormat.getImageableX();
      yFixedHeader = (float)pageFormat.getImageableY();
    }
   
    if (this.fixedFooterLabel != null) {
      this.fixedFooterLabel.setSize((int)pageFormat.getImageableWidth(), this.fixedFooterLabel.getPreferredSize().height);
      imageableHeight -= this.fixedFooterLabel.getHeight() + HEADER_FOOTER_MARGIN;
      xFixedFooter = (float)pageFormat.getImageableX();
      yFixedFooter = (float)(pageFormat.getImageableY() + pageFormat.getImageableHeight()) - this.fixedFooterLabel.getHeight();
    }
   
    Rectangle clipBounds = g2D.getClipBounds();
    AffineTransform oldTransform = g2D.getTransform();
    Paper oldPaper = pageFormat.getPaper();
    final PlanView planView = this.controller.getPlanController().getView();
    if (homePrint != null
        || this.fixedHeaderLabel != null
        || this.fixedFooterLabel != null) {
      if (homePrint != null) {
        FontMetrics fontMetrics = g2D.getFontMetrics(this.headerFooterFont);
        float headerFooterHeight = fontMetrics.getAscent() + fontMetrics.getDescent()
        + HEADER_FOOTER_MARGIN;
       
        // Retrieve variable values
        int pageNumber = page + 1;
        int pageCount = getPageCount();
        String planScale = "?";
        if (homePrint.getPlanScale() != null) {
          planScale = "1/" + Math.round(1 / homePrint.getPlanScale());
        } else {
          if (planView instanceof PlanComponent) {
            planScale = "1/" + Math.round(1 / ((PlanComponent)planView).getPrintPreferredScale(g, pageFormat));
          }       
        }         
        if (page == 0) {
          this.printDate = new Date();
        }
        String homeName = this.home.getName();
        if (homeName == null) {
          homeName = "";
        }
        String homePresentationName = this.controller.getContentManager().getPresentationName(
             homeName, ContentManager.ContentType.SWEET_HOME_3D);
        Object [] variableValues = new Object [] {
            pageNumber, pageCount, planScale, this.printDate, homePresentationName, homeName};
       
        // Create header text
        String headerFormat = homePrint.getHeaderFormat();     
        if (headerFormat != null) {
          header = Variable.getMessageFormat(headerFormat).format(variableValues).trim();
          if (header.length() > 0) {
            xHeader = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(header)) / 2;
            yHeader = imageableY + fontMetrics.getAscent();
            imageableY += headerFooterHeight;
            imageableHeight -= headerFooterHeight;
          } else {
            header = null;
          }
        }
       
        // Create footer text
        String footerFormat = homePrint.getFooterFormat();
        if (footerFormat != null) {
          footer = Variable.getMessageFormat(footerFormat).format(variableValues).trim();
          if (footer.length() > 0) {
            xFooter = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(footer)) / 2;
            yFooter = imageableY + imageableHeight - fontMetrics.getDescent();
            imageableHeight -= headerFooterHeight;
          } else {
            footer = null;
          }
        }
      }
     
      // Update page format paper margins depending on paper orientation
      Paper paper = pageFormat.getPaper();
      switch (pageFormat.getOrientation()) {
        case PageFormat.PORTRAIT:
          paper.setImageableArea(paper.getImageableX(), imageableY,
              paper.getImageableWidth(), imageableHeight);
          break;
        case PageFormat.LANDSCAPE :
          paper.setImageableArea(paper.getWidth() - (imageableHeight + imageableY),
              paper.getImageableY(),
              imageableHeight, paper.getImageableHeight());
        case PageFormat.REVERSE_LANDSCAPE:
          paper.setImageableArea(imageableY, paper.getImageableY(),
              imageableHeight, paper.getImageableHeight());
          break;
      }
      pageFormat.setPaper(paper);
      if (clipBounds == null) {
        g2D.clipRect((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY(),
            (int)pageFormat.getImageableWidth(), (int)pageFormat.getImageableHeight());
      } else
        g2D.clipRect(clipBounds.x, (int)pageFormat.getImageableY(),
            clipBounds.width, (int)pageFormat.getImageableHeight());
      }
    }
   
    if (page == 0) {
      this.furniturePageCount = 0;
      this.planPageCount = 0;
    }
    View furnitureView = this.controller.getFurnitureController().getView();
    if (furnitureView != null
        && (homePrint == null || homePrint.isFurniturePrinted())) {
      // Try to print next furniture view page
      pageExists = ((Printable)furnitureView).print(g2D, pageFormat, page);
      if (pageExists == PAGE_EXISTS) {
        this.furniturePageCount++;
      }
    }
    if (pageExists == NO_SUCH_PAGE
        && planView != null
        && (homePrint == null || homePrint.isPlanPrinted())) {
      // Try to print next plan view page
      pageExists = ((Printable)planView).print(g2D, pageFormat, page - this.furniturePageCount);
      if (pageExists == PAGE_EXISTS) {
        this.planPageCount++;
      }
    }
    View view3D = this.controller.getHomeController3D().getView();
    if (pageExists == NO_SUCH_PAGE
        && view3D != null
        && (homePrint == null || homePrint.isView3DPrinted())) {
      pageExists = ((Printable)view3D).print(g2D, pageFormat, page - this.planPageCount - this.furniturePageCount);
    }
   
    // Print header and footer
    if (pageExists == PAGE_EXISTS) {
View Full Code Here


  /**
   * Sets the edited print attributes.
   */
  public void setPrint(HomePrint print) {
    if (print != this.print) {
      HomePrint oldPrint = this.print;
      this.print = print;
      this.propertyChangeSupport.firePropertyChange(Property.PRINT.name(), oldPrint, print);
    }
  }
View Full Code Here

  /**
   * Controls the modification of home print attributes.
   */
  public void modifyPageSetup() {
    HomePrint oldHomePrint = this.home.getPrint();
    HomePrint homePrint = getPrint();
    this.home.setPrint(homePrint);
    UndoableEdit undoableEdit = new HomePrintModificationUndoableEdit(
        this.home, this.preferences,oldHomePrint, homePrint);
    this.undoSupport.postEdit(undoableEdit);
  }
View Full Code Here

  private void assertHomePrintEqualPrintAttributes(PageFormat pageFormat,
                                                   boolean furniturePrinted,
                                                   boolean planPrinted,
                                                   boolean view3DPrinted,
                                                   Home home) {
    HomePrint homePrint = home.getPrint();
    assertEquals("Wrong paper width", (float)pageFormat.getWidth(), homePrint.getPaperWidth());
    assertEquals("Wrong paper height", (float)pageFormat.getHeight(), homePrint.getPaperHeight());
    assertEquals("Wrong paper left margin", (float)pageFormat.getImageableX(), homePrint.getPaperLeftMargin());
    assertEquals("Wrong paper top margin", (float)pageFormat.getImageableY(), homePrint.getPaperTopMargin());
    assertEquals("Wrong paper right margin",
        (float)(pageFormat.getWidth() - pageFormat.getImageableX() - pageFormat.getImageableWidth()),
        homePrint.getPaperRightMargin());
    assertEquals("Wrong paper bottom margin",
        (float)(pageFormat.getHeight() - pageFormat.getImageableY() - pageFormat.getImageableHeight()),
        homePrint.getPaperBottomMargin());
    switch (pageFormat.getOrientation()) {
      case PageFormat.PORTRAIT :
        assertEquals("Wrong paper orientation",
            HomePrint.PaperOrientation.PORTRAIT, homePrint.getPaperOrientation());
        break;
      case PageFormat.LANDSCAPE :
        assertEquals("Wrong paper orientation",
            HomePrint.PaperOrientation.LANDSCAPE, homePrint.getPaperOrientation());
        break;
      case PageFormat.REVERSE_LANDSCAPE :
        assertEquals("Wrong paper orientation",
            HomePrint.PaperOrientation.REVERSE_LANDSCAPE, homePrint.getPaperOrientation());
        break;
    }
    assertEquals("Wrong furniture printed", furniturePrinted, homePrint.isFurniturePrinted());
    assertEquals("Wrong plan printed", planPrinted, homePrint.isPlanPrinted());
    assertEquals("Wrong view 3D printed", view3DPrinted, homePrint.isView3DPrinted());
  }
View Full Code Here

      default :
        paperOrientation = HomePrint.PaperOrientation.PORTRAIT;
        break;
    }
    Paper paper = this.pageFormat.getPaper();
    HomePrint homePrint = new HomePrint(paperOrientation, (float)paper.getWidth(), (float)paper.getHeight(),
        (float)paper.getImageableY(), (float)paper.getImageableX(),
        (float)(paper.getHeight() - paper.getImageableHeight() - paper.getImageableY()),
        (float)(paper.getWidth() - paper.getImageableWidth() - paper.getImageableX()),
        this.furniturePrintedCheckBox.isSelected(),
        this.planPrintedCheckBox.isSelected(),
View Full Code Here

TOP

Related Classes of com.eteks.sweethome3d.model.HomePrint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.