Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.50 KB | None | 0 0
  1. package com.sysom.blankiet.gui.projectModules;
  2.  
  3. import java.awt.*;
  4. import java.awt.geom.Rectangle2D;
  5. import java.awt.image.BufferedImage;
  6. import java.awt.print.PageFormat;
  7. import java.awt.print.Printable;
  8. import java.awt.print.PrinterException;
  9. import java.util.List;
  10.  
  11. import javax.swing.JComponent;
  12.  
  13. import com.sysom.blankiet.func.Generator;
  14. import com.sysom.blankiet.func.MyToolPack;
  15. import com.sysom.blankiet.lib.Local;
  16. import com.sysom.env.Sysom;
  17. import net.sourceforge.barbecue.Barcode;
  18. import net.sourceforge.barbecue.BarcodeException;
  19. import net.sourceforge.barbecue.BarcodeFactory;
  20. import net.sourceforge.barbecue.output.OutputException;
  21.  
  22. public class PanelToPrint extends JComponent implements Printable{
  23.  
  24.   /**
  25.    *
  26.    */
  27.   private static final long serialVersionUID = 1L;
  28.  
  29.   String nrKontaPart1 = "";
  30.   String nrKontaPart2 = "";
  31.   String name = "";
  32.   String surname = "";
  33.   String osiedleSkroconaNazwa = "";
  34.   String osiedleNazwa = "";
  35.   String indeks = "";
  36.   String idPlatnosci = "";
  37.   String adres = "";
  38.   String nazwisko = "";
  39.   int whatToPrint;
  40.   int liczbaStron = 0;
  41.   float wsp = (float) 2.8333;
  42.   List<String> months;
  43.   String dataPlat;
  44.   BufferedImage img;
  45.   String id_lok;
  46.   String id_wej;
  47.   String docType;
  48.   TextArea additionalText;
  49.  
  50.   public static int REMONT = 0;
  51.   public static int UTRZYMANIE = 1;
  52.  
  53.  
  54.  
  55.   public PanelToPrint(List<String> months, int page, Local local, TextArea additionalText, int printName) {
  56.     this.adres = local.address;
  57.     this.indeks = local.index;
  58.     if(printName == 1 && local.mainClient.name.length() > 0) {
  59.       this.nazwisko = local.mainClient.name;
  60.       int i = local.mainClient.name.indexOf(" ");
  61.       this.name = nazwisko.substring(0,i);
  62.       this.surname = nazwisko.substring(i+1);
  63.     }
  64.     this.osiedleNazwa = local.osiedle;
  65.     this.osiedleSkroconaNazwa = local.osiedleShort;
  66.     if(local.nrb.length() > 10) {
  67.       this.nrKontaPart1 = MyToolPack.formattedNRB(local.nrb).substring(0,12);
  68.       this.nrKontaPart2 = MyToolPack.formattedNRB(local.nrb).substring(12,32);
  69.     }
  70.     this.months = months;
  71.     this.liczbaStron = page;
  72.     if(local.paymentDay.equals("0")) {
  73.       if(local.localType.equals("X") || local.localType.equals("U")) {
  74.         this.dataPlat = "20";
  75.       }
  76.       else {
  77.         this.dataPlat = "15";
  78.       }
  79.     }
  80.     else {
  81.       this.dataPlat = local.paymentDay;
  82.     }  
  83.     img = Generator.barcode(indeks);
  84.     this.id_lok = local.locId;
  85.     this.id_wej = local.entranceId;
  86.     if(local.localType.equals("X") || local.localType.equals("U")){
  87.       docType = "FAKTURA za ";
  88.     }
  89.     else {
  90.       docType = "OPŁATA za ";
  91.     }
  92.     this.additionalText = additionalText;
  93.   }
  94.  
  95.  
  96.   public PanelToPrint(List<String> months, int page, Local local, TextArea additionalText, int printName, int costType) {
  97.     this.adres = local.address;
  98.     this.indeks = local.index;
  99.     if(printName == 1 && local.mainClient.name.length() > 0) {
  100.       this.nazwisko = local.mainClient.name;
  101.       int i = local.mainClient.name.indexOf(" ");
  102.       this.name = nazwisko.substring(0,i);
  103.       this.surname = nazwisko.substring(i+1);
  104.     }
  105.     this.osiedleNazwa = local.osiedle;
  106.     this.osiedleSkroconaNazwa = local.osiedleShort;
  107.     if(costType == REMONT) {
  108.       this.nrKontaPart1 = MyToolPack.formattedNRB("77102040270000190200469247").substring(0,12);
  109.       this.nrKontaPart2 = MyToolPack.formattedNRB("77102040270000190200469247").substring(12,32);
  110.     }
  111.     else {
  112.       this.nrKontaPart1 = MyToolPack.formattedNRB("62102040270000150200331876").substring(0,12);
  113.       this.nrKontaPart2 = MyToolPack.formattedNRB("62102040270000150200331876").substring(12,32);      
  114.     }
  115.     this.months = months;
  116.     this.liczbaStron = page;
  117.     if(local.paymentDay.equals("0")) {
  118.       if(local.localType.equals("X") || local.localType.equals("U")) {
  119.         this.dataPlat = "20";
  120.       }
  121.       else {
  122.         this.dataPlat = "15";
  123.       }
  124.     }
  125.     else {
  126.       this.dataPlat = local.paymentDay;
  127.     }  
  128.     img = Generator.barcode(indeks);
  129.     this.id_lok = local.locId;
  130.     this.id_wej = local.entranceId;
  131.     if(costType == REMONT){
  132.       docType = "Fundusz Remontowy - opłata za ";
  133.     }
  134.     else {
  135.       docType = "Koszty utrzymania - opłata za ";
  136.     }
  137.     this.additionalText = additionalText;
  138.   }
  139.  
  140.  
  141.   @Override
  142.   public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
  143.       throws PrinterException {
  144.  
  145.    
  146.    
  147.     if (pageIndex > liczbaStron) {
  148.       return Printable.NO_SUCH_PAGE;
  149.     }
  150.     else {
  151.         Graphics2D g2 = (Graphics2D) graphics;
  152.        
  153.        
  154.         additionalText.paintAll(g2);
  155.        
  156.         if(months.size() == 2) {
  157.           drukBezNazwiska(g2, wsp * 200, months.get(0));
  158.           drukBezNazwiska(g2, wsp * 93, months.get(1));          
  159.         }
  160.         else {
  161.           drukBezNazwiska(g2, wsp * 200, months.get(0));
  162.         }
  163.  
  164.       return Printable.PAGE_EXISTS;
  165.     }
  166.   }
  167.  
  168.  
  169.   /**
  170.    * metoda określa parametry i tekst wydruku dla druku bez nazwiska
  171.    * @param g2
  172.    * @param y - określa początek drukowanego tekstu
  173.    */
  174.   private void drukBezNazwiska(Graphics2D g2, float y, String month) {
  175.     g2.setFont(new Font("Arial Narrow", Font.PLAIN, 12));
  176.    
  177.     g2.drawString(nrKontaPart1,(float) wsp * 12, y);
  178.     if(Sysom.WERSJA.equals("1.00")) {
  179.       g2.drawString("SPÓŁDZIELNIA MIESZKANIOWA OSIEDLE MŁODYCH W POZNANIU", wsp * 72, y);
  180.     }
  181.     else {
  182.       g2.drawString("Wspólnota Mieszkaniowa przy os. Tysiąclecia 55-62", wsp * 72, y);
  183.     }
  184.     y += (wsp * 8);
  185.    
  186.    
  187.     g2.drawString(nrKontaPart2, wsp * 12, y);
  188.     if(Sysom.WERSJA.equals("1.00")) {
  189.       g2.drawString("KIER. OS. "+ osiedleNazwa.toUpperCase(), wsp * 72, y);
  190.     }
  191.     else {
  192.       g2.drawString("61-255 Poznań, os. Tysiąclecia 58/1", wsp * 72, y);
  193.     }
  194.    
  195.  
  196.     y += (wsp * 9);
  197.    
  198.    
  199.    
  200.     if(Sysom.WERSJA.equals("1.00")) {
  201.       g2.drawString("SM \"OSIEDLE MŁODYCH\"", wsp * 12, y);
  202.     }
  203.     else {
  204.       g2.drawString("\"Wspólnota Mieszkaniowa\"", wsp * 12, y);
  205.     }
  206.     g2.drawString(nrKontaPart1+nrKontaPart2, wsp * 72, y);
  207.     y = y + (wsp * 4);
  208.    
  209.     if(Sysom.WERSJA.equals("1.00")) {
  210.       g2.drawString("Kierownictwo Os.", wsp * 12, y);
  211.       y = y + (wsp * 4);
  212.       g2.drawString(osiedleSkroconaNazwa, wsp * 12, y);
  213.     }
  214.     else {
  215.       g2.drawString("przy os. Tysiąclecia 55-62", wsp * 12, y);
  216.       y = y + (wsp * 4);
  217.     }    
  218.    
  219.    
  220.     g2.drawString("PLN", wsp * 127, y);
  221.     y = y + (wsp * 14);
  222.    
  223.    
  224.    
  225.     int yy= (int) y;
  226.     rysujKodKreskowy(35, yy-30, g2);
  227. //    g2.drawImage(img, 35, yy - 2, 110, 20, null);
  228.     g2.drawString(name, wsp * 12, y + 35);
  229.     g2.drawString(surname, wsp * 12, y + 50);
  230.     y = y + (wsp * 12);
  231.    
  232.     g2.drawString(nazwisko, wsp * 72, y- 20);
  233.     g2.drawString(adres, wsp * 72, y);
  234.     y = y + (wsp * 8);
  235.    
  236.     g2.drawString(Generator.getPaymentId(indeks, month) + " " + docType + month.substring(0, 2) + "." + month.substring(2,6), wsp * 72, y);
  237.     y = y + (wsp * 4);
  238.  
  239.     rysujKodKreskowy(440,(int)(y) - 10,g2);
  240. //    g2.drawImage(img, 460, (int)(y) - 10, 90, 25, null); //110
  241.     y = y + (wsp * 3);
  242.        
  243.     g2.drawString("Płatne do "+dataPlat+"."+ month.substring(0, 2) + "." + month.substring(2,6), wsp * 72, y+5);
  244.     y = y + (wsp * 4);
  245.    
  246.     int addy = (int) (y + 5);
  247.     g2.drawString(Generator.getPaymentId(indeks, month).substring(0, 9), wsp * 12, y);
  248.     y = y + (wsp * 4);
  249.     g2.drawString(docType + month.substring(0, 2) + "." + month.substring(2,6), wsp * 12, y);
  250.    
  251.  
  252.     g2.setFont(new Font("Arial Narrow", Font.PLAIN, 5));
  253.     g2.drawString("Prowizję od wpłat", 400, addy);
  254.     g2.drawString("w PKO uiszcza", 400, addy + 7);
  255.     g2.drawString("posiadacz rachunku", 400, addy + 14);
  256.   }
  257.  
  258.   private void rysujKodKreskowy(int x, int y, Graphics2D g2d) {
  259.     Barcode b = null;
  260.     try {
  261.       b = BarcodeFactory.createCode128(indeks);
  262.     } catch (BarcodeException e) {
  263.       // TODO Auto-generated catch block
  264.       e.printStackTrace();
  265.     }
  266.     b.setBarHeight(5);
  267.     b.setBarWidth(1);
  268.  
  269.     Font deriveFont = g2d.getFont().deriveFont(7.0f); // copy of original Font with given size
  270.     b.setFont(deriveFont);
  271.  
  272.     try {
  273.       b.draw(g2d, x, y);
  274.       g2d.setPaint(Color.WHITE);
  275.       g2d.fill(new Rectangle2D.Double(x, y, b.getWidth(), b.getHeight() / 2.5d));
  276.       g2d.setPaint(Color.BLACK);
  277.  
  278.     } catch (OutputException e) {
  279.       e.printStackTrace();
  280.     }
  281.  
  282.   }
  283.  
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement