⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plaintextoutputtarget.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }
    open = true;
  }

  /**
   * Returns true if the target is open, and false otherwise.
   *
   * @return true or false.
   */
  public boolean isOpen()
  {
    return open;
  }

  /**
   * Closes the target.
   */
  public void close()
  {
    open = false;
  }

  /**
   * Signals that a page is being started.  Stores the state of the target to
   * make it possible to restore the complete output target.
   *
   * @param page  the physical page.
   */
  public void beginPage(final PhysicalPage page)
  {
    final PageFormat pf = page.getPageFormat();
    // the page must contain the space for the border, or it is invalid
    // the left and top border is always included when performing the layout
    currentPageHeight = correctedDivisionFloor
        ((float) (pf.getImageableHeight() + pf.getImageableY()), characterHeight);
    currentPageWidth = correctedDivisionFloor
        ((float) (pf.getImageableWidth()), characterWidth);
    final int currentPageLeft = correctedDivisionFloor
        ((float) (pf.getImageableX()), characterWidth);

    this.pageBuffer = new PlainTextPage(currentPageLeft, currentPageWidth, currentPageHeight,
        getCommandSet(), getDocumentEncoding());
    savedState = new PlainTextState(this);
  }

  /**
   * Signals that the current page is ended.  Writes the page buffer to the
   * printer.
   *
   * @throws OutputTargetException if there is some problem with the target.
   */
  public void endPage() throws OutputTargetException
  {
    try
    {
      pageBuffer.writePage();
    }
    catch (IOException ioe)
    {
      throw new OutputTargetException("Failed to write the page", ioe);
    }
    pageBuffer = null;
  }

  /**
   * Restores the state of this graphics.
   *
   * @throws OutputTargetException if the argument is not an instance of G2State.
   */
  public void restoreState() throws OutputTargetException
  {
    savedState.restore(this);
  }

  /**
   * Returns the current font.
   *
   * @return the current font.
   */
  public FontDefinition getFont()
  {
    return font;
  }

  /**
   * Sets the font. This has no influence on the generated output.
   *
   * @param font  the font.
   *
   * @throws OutputTargetException if there is a problem setting the font.
   */
  public void setFont(final FontDefinition font) throws OutputTargetException
  {
    this.font = font;
  }

  /**
   * Returns the current stroke.
   *
   * @return the stroke.
   */
  public Stroke getStroke()
  {
    return stroke;
  }

  /**
   * Defines the current stroke for the target.  This has no influence on the generated output.
   *
   * @param stroke  the stroke.
   *
   * @throws OutputTargetException if there is a problem setting the stroke.
   */
  public void setStroke(final Stroke stroke) throws OutputTargetException
  {
    this.stroke = stroke;
  }

  /**
   * Returns the current paint.
   *
   * @return the paint.
   */
  public Paint getPaint()
  {
    return paint;
  }

  /**
   * Sets the paint.  This has no influence on the generated output.
   *
   * @param paint The paint.
   *
   * @throws OutputTargetException if there is a problem setting the paint.
   */
  public void setPaint(final Paint paint) throws OutputTargetException
  {
    this.paint = paint;
  }

  /**
   * Draws a string at the current cursor position.
   *
   * @param text  the text.
   */
  public void drawString(final String text)
  {
    final Rectangle2D bounds = getOperationBounds();

    final int x = correctedDivisionFloor((float) bounds.getX(), characterWidth);
    final int y = correctedDivisionFloor((float) bounds.getY(), characterHeight);
    final int w = correctedDivisionFloor((float) bounds.getWidth(), characterWidth);
    pageBuffer.addTextChunk(x, y, w, text, getFont());
  }

  /**
   * Fixes some floating point errors when calculating positions.
   *
   * @param c the divisor
   * @param d the divident
   * @return the corrected division result.
   */
  private int correctedDivisionFloor(float c, float d)
  {
    c = Math.round(c * 100f);
    d = Math.round(d * 100f);
    return (int) Math.floor(c / d);
  }

  /**
   * This method is empty, as the PlainTextOutputTarget does not support
   * shapes.
   *
   * @param shape  the shape to draw.
   */
  public void drawShape(final Shape shape)
  {
    // this is not supported, does nothing ...
  }

  /**
   * This method is empty, as the PlainTextOutputTarget does not support
   * shapes.
   *
   * @param shape  the shape to draw.
   */
  public void fillShape(final Shape shape)
  {
    // this is not supported, does nothing ...
  }

  /**
   * This method is empty, as the PlainTextOutputTarget does not support
   * images.
   *
   * @param image The image to draw (as ImageReference for possible embedding of raw data).
   *
   * @throws OutputTargetException if there is a problem setting the paint.
   */
  public void drawImage(final ImageReference image) throws OutputTargetException
  {
  }

  /**
   * Creates an output target that mimics a real output target, but produces no output.
   * This is used by the reporting engine when it makes its first pass through the report,
   * calculating page boundaries etc.  The second pass will use a real output target.
   *
   * @return a dummy output target.
   */
  public OutputTarget createDummyWriter()
  {
    return new DummyOutputTarget(this);
  }

  /**
   * Configures the encoding of the plain text output, if not already set.
   * The OutputTarget is also configured by supplying a valid
   * PrinterCommand set.
   *
   * @param config  the configuration.
   */
  public void configure(final ReportConfiguration config)
  {
    if (getDocumentEncoding() == null)
    {
      setDocumentEncoding(getTextTargetEncoding(config));
    }
  }

  /**
   * Returns the plain text encoding property value.
   *
   * @param config the report configuration from where to read the encoding property.
   * @return the plain text encoding property value.
   */
  public static String getTextTargetEncoding(ReportConfiguration config)
  {
    if (config == null)
    {
      config = ReportConfiguration.getGlobalConfig();
    }
    return config.getConfigProperty(TEXT_OUTPUT_ENCODING, TEXT_OUTPUT_ENCODING_DEFAULT);
  }


  /**
   * Creates a size calculator for the current state of the output target.  The calculator
   * is used to calculate the string width and line height and later maybe more...
   *
   * @param font  the font.
   *
   * @return the size calculator.
   *
   * @throws OutputTargetException if there is a problem with the output target.
   */
  public SizeCalculator createTextSizeCalculator(final FontDefinition font)
      throws OutputTargetException
  {
    return new PlainTextSizeCalculator(characterWidth, characterHeight);
  }

  /**
   * Returns the element alignment. Elements will be layouted aligned to this
   * border, so that <code>mod(X, horizontalAlignment) == 0</code> and
   * <code>mod(Y, verticalAlignment) == 0</code>
   *
   * @return the vertical alignment grid boundry
   */
  public float getHorizontalAlignmentBorder()
  {
    return characterWidth;
  }

  /**
   * Returns the element alignment. Elements will be layouted aligned to this
   * border, so that <code>mod(X, horizontalAlignment) == 0</code> and
   * <code>mod(Y, verticalAlignment) == 0</code>
   *
   * @return the vertical alignment grid boundry
   */
  public float getVerticalAlignmentBorder()
  {
    return characterHeight;
  }

  /**
   * Creates a content factory. The factory does only support TextContent.
   *
   * @return the created content factory.
   */
  protected ContentFactory createContentFactory()
  {
    final DefaultContentFactory contentFactory = new DefaultContentFactory();
    contentFactory.addModule(new TextContentFactoryModule());
    return contentFactory;
  }

  /**
   * Draws a drawable relative to the current position. Drawables are not
   * supported, they do not provide text information...
   *
   * @param drawable the drawable to draw.
   */
  public void drawDrawable(final DrawableContainer drawable)
  {
  }

  /**
   * Returns the current document encoding.
   *
   * @return the document encoding.
   */
  public String getDocumentEncoding()
  {
    return getProperty(ENCODING_PROPERTY);
  }

  /**
   * Defines the document encoding for the plain text output.
   * The specified encoding must be supported by the assigned PrinterCommandSet.
   *
   * @param documentEncoding the character encoding of the target text.
   */
  public void setDocumentEncoding(final String documentEncoding)
  {
    if (documentEncoding == null)
    {
      throw new NullPointerException("DocumentEncoding must not be null.");
    }
    if (getCommandSet().isEncodingSupported(documentEncoding))
    {
      setProperty(ENCODING_PROPERTY, documentEncoding);
    }
    else
    {
      throw new IllegalArgumentException
          ("This encoding is not supported by the printer. : " + documentEncoding);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -