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

📄 printablechart.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
字号:
package net.sourceforge.ganttproject.print;import java.awt.*;import java.awt.image.*;import java.awt.print.*;import java.util.*;import net.sourceforge.ganttproject.*;/** * Printable object  *  * @author      jseiler <juliens@actimage.net> * @see         net.sourceforge.ganttproject.print.PrintPreview * @version     0.1 * @since       2.0pre2 */public class PrintableChart implements Printable{    protected GanttProject ganttproject;    protected ChartComponentBase area;    protected GanttImagePanel logo;    protected GanttExportSettings export_settings;        public PrintableChart(ChartComponentBase area)    {        this.ganttproject = Mediator.getGanttProjectSingleton();        //this.area = ganttproject.getArea();        //this.area = ganttproject.getResourcePanel().area;        this.area = area;        this.logo = new GanttImagePanel("big.png", 1024, 44);        this.export_settings = new GanttExportSettings();    }        public void setStartDate(Date date)    {        this.export_settings.setStartDate(date);    }        public void setEndDate(Date date)    {        this.export_settings.setEndDate(date);    }        /**      * Draw the current chart diagram in the given Graphics g     *     * @param g             Graphics to draw in     * @param page_format   PageFormat used by the printer     * @param page_index    Page being printed     * @return              PAGE_EXIST or NO_SUCH_PAGE     */    public int print(Graphics g, PageFormat page_format, int page_index) throws PrinterException    {//      create a BufferedImage for each part of the image (chart, tree and logo)        BufferedImage chart = null;        if(this.area instanceof GanttGraphicArea) {            if(this.ganttproject.getTaskManager().getTaskCount() == 0)                return Printable.NO_SUCH_PAGE;            this.ganttproject.getTree().getTreeTable().getTree().clearSelection();            chart = ((GanttGraphicArea)this.area).getChart(export_settings);        }        else if(this.area instanceof ResourceLoadGraphicArea) {            if(this.ganttproject.getHumanResourceManager().getResources().size() == 0)                return Printable.NO_SUCH_PAGE;            this.ganttproject.getResourcePanel().getResourceTreeTable().getTree().clearSelection();            chart = ((ResourceLoadGraphicArea)this.area).getChart(export_settings);        }        else            return Printable.NO_SUCH_PAGE;                //we asume that the Graphics argument is a 2D Graphics object        Graphics2D g2d = (Graphics2D)g;                //to avoid drawing in marge we translate the drawing area using        //the page_format settings        g2d.translate(page_format.getImageableX(), page_format.getImageableY());                int page_width = (int)page_format.getImageableWidth();        int page_height = (int)page_format.getImageableHeight();         int image_width = chart.getWidth();        int image_height = chart.getHeight();                //count pages number (in a row and in a col)        //we need to print the image        int pages_in_row = image_width/page_width+1;        int pages_in_col = image_height/page_height+1;                //count the total number of required pages        int nb_pages = pages_in_row * pages_in_col;                if(page_index<nb_pages)        {            //determine the page (col, row) corresponding to the            //given page_index            int row = page_index/pages_in_row;            int col = page_index%pages_in_row;                        //determine the part of the image corresponding to the            //current page            int render_x = col*page_width;            int render_y = row*page_height;            int render_width = col+1==pages_in_row ? image_width - (col*page_width) : page_width;            int render_height = row+1==pages_in_col ? image_height - (row*page_height) : page_height;                        //extract the part of the image corresponding to the current page             BufferedImage page_image = chart.getSubimage(render_x, render_y, render_width, render_height);            g2d.drawImage(page_image, 0, 0, render_width, render_height, null);            page_image.flush();            return Printable.PAGE_EXISTS;        }                return Printable.NO_SUCH_PAGE;    }}

⌨️ 快捷键说明

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