001package jmri.util.davidflanagan;
002
003import java.awt.Dimension;
004import java.awt.Frame;
005
006import javax.print.attribute.standard.Sides;
007
008public class CompatibleHardcopyWriter extends HardcopyWriter {
009
010    // constructor modified to add print preview parameter
011    public CompatibleHardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin,
012            double topmargin, double bottommargin, boolean isPreview) throws HardcopyWriter.PrintCanceledException {
013        super(frame, jobname, (String) null, (Integer) null, fontsize,
014                leftmargin * 72, rightmargin * 72, topmargin * 72, bottommargin * 72,
015                isPreview, (String) null, (Boolean) null, (Boolean) null, (Sides) null, (Dimension) null);
016    }
017
018    // constructor modified to add default printer name, page orientation, print header, print duplex, and page size
019    public CompatibleHardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin,
020            double topmargin, double bottommargin, boolean isPreview, String printerName, boolean isLandscape,
021            boolean isPrintHeader, Sides sides, Dimension pagesize)
022            throws HardcopyWriter.PrintCanceledException {
023        super(frame, jobname, (String) null, (Integer) null, fontsize,
024                leftmargin * 72, rightmargin * 72, topmargin * 72, bottommargin * 72,
025                isPreview, printerName, isLandscape, isPrintHeader, sides, pagesize);
026    }
027
028    /**
029     * Get the current line number -- this is nasty since it makes the implicit
030     * assumption that the line height is constant over the whole page. Further,
031     * things like images can throw this off.
032     * <p>
033     * We may want to adjust the current v_pos to align it with an integer line
034     * number (when this is called).
035     * 
036     * @return the current line number
037     */
038    public int getCurrentLineNumber() {
039        if (page != null) {
040            return getCurrentVPos() / getLineHeight();
041        }
042        return 0; // new page
043    }
044
045    /**
046     * Get the number of lines per page. Again, this assumes that the line height is constant
047     * over the whole page.
048     * 
049     * @return the number of lines per page
050     */
051    public int getLinesPerPage() {
052        return getPrintablePagesizePoints().height / getLineHeight();
053    }
054
055    /**
056     * This draws a line from the start position to the end position (in characters/lines).
057     * This has the same sort of issues as getCurrentLineNumber(). We may want to tweak this
058     * to behave differently.
059     *  
060     * @param startLine The starting line number
061     * @param startColumn The starting column number
062     * @param endLine The ending line number
063     * @param endColumn The ending column number
064     */
065    public void write(int startLine, int startColumn, int endLine, int endColumn) {
066        int startVPos = startLine * getLineHeight();
067        int endVPos = endLine * getLineHeight();
068        int startHPos = (int) (startColumn * getCharWidth());
069        int endHPos = (int) (endColumn * getCharWidth());
070
071        super.writeLine(startVPos, startHPos, endVPos, endHPos);
072    }
073
074    /**
075     * Set the font style
076        * 
077     * @param style The font style
078     */
079    public void setFontStyle(int style) {
080        super.setFont(null, style, null);
081    }
082
083    /**
084     * Set the font name
085     * 
086     * @param name The font name
087     */
088    public void setFontName(String name) {
089        super.setFont(name, null, null);
090    }
091
092}