| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 
 |  
public int print(Graphics g, PageFormat pf, int pageIndex)throws PrinterException {
      int retValue = Printable.PAGE_EXISTS;
      Graphics2D g2d = (Graphics2D)g;
      totalNumPages = 5 + numberPageToPrint;
 
      switch(pageIndex){
         case 0 : 
            retValue = printPreviewPage(g, pf);
            break;
         case 1:
             retValue = printFirstPage(g);
             pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
             pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
             break;
         case 2:
            retValue = printChartPage(panel, g2d, pf, pageIndex);
            break;
         case 3:
            retValue = printChartPage(panel2, g2d, pf, pageIndex);
            break;
         case 4:
            retValue = printChartPage(panel3, g2d, pf, pageIndex);
            pf.setOrientation(PageFormat.PORTRAIT);
            pageFormat.setOrientation(PageFormat.PORTRAIT);
            break;
         default:
                  if(lastPageIndex == pageIndex){
                     endData = printDataPage(g);
                     if(endData)
                        retValue = Printable.NO_SUCH_PAGE;
                     else
                        numberPageToPrint++;
                  }else {
                    lastPageIndex = pageIndex;
                    if(endData)
                        retValue = Printable.NO_SUCH_PAGE;
                  }
             break;
      }
      return retValue;
    }
 
    private int printPreviewPage(Graphics g, PageFormat pf){
            double width = 0;
            double height = 0;
            if(pf.getOrientation() ==1) {
                width  = pf.getImageableWidth();
                height = pf.getImageableHeight();
            }else {
                width  = pf.getImageableHeight();
                height = pf.getImageableWidth();
            }
            g.setColor(Color.BLACK);
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Image img = toolkit.getImage(getClass().getResource("/images/logo_fnh_black_v_1.jpg"));
            g.drawImage(img, (int)width /10, 0, null);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ex) {
                Logger.getLogger(MPrintTableTir.class.getName()).log(Level.SEVERE, null, ex);
            }
            g.drawString("adresse", (int) width/2 - 20, (int)height - 50);
            g.drawString("adresse", (int) width/2 - 20, (int)height - 35);
            g.drawString("pays", (int) width/2 - 20, (int)height - 20);
            DateFormat datedujour = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE);
            g.drawString(datedujour.format(new Date()), (int)width-75, 25);
            datedujour = new SimpleDateFormat("HH'h'mm");
            g.drawString(datedujour.format(new Date()), (int)width-75, 40);
            Font font = new Font("Arial", 1, 42);
            g.setFont(font);
            String msg = "RANGE TABLE";
            width = width -100;
            g.drawString(msg, (int) width/3,(int) ((int) height / 1.7));
            g.drawRect((int) width/5-20, (int) ((int) height / 1.85)-5, 470, 60);
            g.drawRect((int) width/5-21, (int) ((int) height / 1.85)-6, 472, 62);
            g.drawRect((int) width/5-22, (int) ((int) height / 1.85)-7, 474, 64);
            g.drawRect((int) width/5-23, (int) ((int) height / 1.85)-8, 476, 66);
            font = new Font("Arial", 1, 26);
            g.setFont(font);
            int poxX = 200;
            if (documentTitle.length()<10)
                 poxX = 250;
            else if (documentTitle.length()>20)
                 poxX = 150;
            g.drawString(documentTitle, poxX, (int) ((int) height / 1.5));
            font = new Font("Arial", 1, 8);
            g.setFont(font);
            g.drawString("******", 50, 825);
            return Printable.PAGE_EXISTS;
    } | 
Partager