Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sysom.blankiet.gui.projectModules;
- import java.awt.*;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.BufferedImage;
- import java.awt.print.PageFormat;
- import java.awt.print.Printable;
- import java.awt.print.PrinterException;
- import java.util.List;
- import javax.swing.JComponent;
- import com.sysom.blankiet.func.Generator;
- import com.sysom.blankiet.func.MyToolPack;
- import com.sysom.blankiet.lib.Local;
- import com.sysom.env.Sysom;
- import net.sourceforge.barbecue.Barcode;
- import net.sourceforge.barbecue.BarcodeException;
- import net.sourceforge.barbecue.BarcodeFactory;
- import net.sourceforge.barbecue.output.OutputException;
- public class PanelToPrint extends JComponent implements Printable{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- String nrKontaPart1 = "";
- String nrKontaPart2 = "";
- String name = "";
- String surname = "";
- String osiedleSkroconaNazwa = "";
- String osiedleNazwa = "";
- String indeks = "";
- String idPlatnosci = "";
- String adres = "";
- String nazwisko = "";
- int whatToPrint;
- int liczbaStron = 0;
- float wsp = (float) 2.8333;
- List<String> months;
- String dataPlat;
- BufferedImage img;
- String id_lok;
- String id_wej;
- String docType;
- TextArea additionalText;
- public static int REMONT = 0;
- public static int UTRZYMANIE = 1;
- public PanelToPrint(List<String> months, int page, Local local, TextArea additionalText, int printName) {
- this.adres = local.address;
- this.indeks = local.index;
- if(printName == 1 && local.mainClient.name.length() > 0) {
- this.nazwisko = local.mainClient.name;
- int i = local.mainClient.name.indexOf(" ");
- this.name = nazwisko.substring(0,i);
- this.surname = nazwisko.substring(i+1);
- }
- this.osiedleNazwa = local.osiedle;
- this.osiedleSkroconaNazwa = local.osiedleShort;
- if(local.nrb.length() > 10) {
- this.nrKontaPart1 = MyToolPack.formattedNRB(local.nrb).substring(0,12);
- this.nrKontaPart2 = MyToolPack.formattedNRB(local.nrb).substring(12,32);
- }
- this.months = months;
- this.liczbaStron = page;
- if(local.paymentDay.equals("0")) {
- if(local.localType.equals("X") || local.localType.equals("U")) {
- this.dataPlat = "20";
- }
- else {
- this.dataPlat = "15";
- }
- }
- else {
- this.dataPlat = local.paymentDay;
- }
- img = Generator.barcode(indeks);
- this.id_lok = local.locId;
- this.id_wej = local.entranceId;
- if(local.localType.equals("X") || local.localType.equals("U")){
- docType = "FAKTURA za ";
- }
- else {
- docType = "OPŁATA za ";
- }
- this.additionalText = additionalText;
- }
- public PanelToPrint(List<String> months, int page, Local local, TextArea additionalText, int printName, int costType) {
- this.adres = local.address;
- this.indeks = local.index;
- if(printName == 1 && local.mainClient.name.length() > 0) {
- this.nazwisko = local.mainClient.name;
- int i = local.mainClient.name.indexOf(" ");
- this.name = nazwisko.substring(0,i);
- this.surname = nazwisko.substring(i+1);
- }
- this.osiedleNazwa = local.osiedle;
- this.osiedleSkroconaNazwa = local.osiedleShort;
- if(costType == REMONT) {
- this.nrKontaPart1 = MyToolPack.formattedNRB("77102040270000190200469247").substring(0,12);
- this.nrKontaPart2 = MyToolPack.formattedNRB("77102040270000190200469247").substring(12,32);
- }
- else {
- this.nrKontaPart1 = MyToolPack.formattedNRB("62102040270000150200331876").substring(0,12);
- this.nrKontaPart2 = MyToolPack.formattedNRB("62102040270000150200331876").substring(12,32);
- }
- this.months = months;
- this.liczbaStron = page;
- if(local.paymentDay.equals("0")) {
- if(local.localType.equals("X") || local.localType.equals("U")) {
- this.dataPlat = "20";
- }
- else {
- this.dataPlat = "15";
- }
- }
- else {
- this.dataPlat = local.paymentDay;
- }
- img = Generator.barcode(indeks);
- this.id_lok = local.locId;
- this.id_wej = local.entranceId;
- if(costType == REMONT){
- docType = "Fundusz Remontowy - opłata za ";
- }
- else {
- docType = "Koszty utrzymania - opłata za ";
- }
- this.additionalText = additionalText;
- }
- @Override
- public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
- throws PrinterException {
- if (pageIndex > liczbaStron) {
- return Printable.NO_SUCH_PAGE;
- }
- else {
- Graphics2D g2 = (Graphics2D) graphics;
- additionalText.paintAll(g2);
- if(months.size() == 2) {
- drukBezNazwiska(g2, wsp * 200, months.get(0));
- drukBezNazwiska(g2, wsp * 93, months.get(1));
- }
- else {
- drukBezNazwiska(g2, wsp * 200, months.get(0));
- }
- return Printable.PAGE_EXISTS;
- }
- }
- /**
- * metoda określa parametry i tekst wydruku dla druku bez nazwiska
- * @param g2
- * @param y - określa początek drukowanego tekstu
- */
- private void drukBezNazwiska(Graphics2D g2, float y, String month) {
- g2.setFont(new Font("Arial Narrow", Font.PLAIN, 12));
- g2.drawString(nrKontaPart1,(float) wsp * 12, y);
- if(Sysom.WERSJA.equals("1.00")) {
- g2.drawString("SPÓŁDZIELNIA MIESZKANIOWA OSIEDLE MŁODYCH W POZNANIU", wsp * 72, y);
- }
- else {
- g2.drawString("Wspólnota Mieszkaniowa przy os. Tysiąclecia 55-62", wsp * 72, y);
- }
- y += (wsp * 8);
- g2.drawString(nrKontaPart2, wsp * 12, y);
- if(Sysom.WERSJA.equals("1.00")) {
- g2.drawString("KIER. OS. "+ osiedleNazwa.toUpperCase(), wsp * 72, y);
- }
- else {
- g2.drawString("61-255 Poznań, os. Tysiąclecia 58/1", wsp * 72, y);
- }
- y += (wsp * 9);
- if(Sysom.WERSJA.equals("1.00")) {
- g2.drawString("SM \"OSIEDLE MŁODYCH\"", wsp * 12, y);
- }
- else {
- g2.drawString("\"Wspólnota Mieszkaniowa\"", wsp * 12, y);
- }
- g2.drawString(nrKontaPart1+nrKontaPart2, wsp * 72, y);
- y = y + (wsp * 4);
- if(Sysom.WERSJA.equals("1.00")) {
- g2.drawString("Kierownictwo Os.", wsp * 12, y);
- y = y + (wsp * 4);
- g2.drawString(osiedleSkroconaNazwa, wsp * 12, y);
- }
- else {
- g2.drawString("przy os. Tysiąclecia 55-62", wsp * 12, y);
- y = y + (wsp * 4);
- }
- g2.drawString("PLN", wsp * 127, y);
- y = y + (wsp * 14);
- int yy= (int) y;
- rysujKodKreskowy(35, yy-30, g2);
- // g2.drawImage(img, 35, yy - 2, 110, 20, null);
- g2.drawString(name, wsp * 12, y + 35);
- g2.drawString(surname, wsp * 12, y + 50);
- y = y + (wsp * 12);
- g2.drawString(nazwisko, wsp * 72, y- 20);
- g2.drawString(adres, wsp * 72, y);
- y = y + (wsp * 8);
- g2.drawString(Generator.getPaymentId(indeks, month) + " " + docType + month.substring(0, 2) + "." + month.substring(2,6), wsp * 72, y);
- y = y + (wsp * 4);
- rysujKodKreskowy(440,(int)(y) - 10,g2);
- // g2.drawImage(img, 460, (int)(y) - 10, 90, 25, null); //110
- y = y + (wsp * 3);
- g2.drawString("Płatne do "+dataPlat+"."+ month.substring(0, 2) + "." + month.substring(2,6), wsp * 72, y+5);
- y = y + (wsp * 4);
- int addy = (int) (y + 5);
- g2.drawString(Generator.getPaymentId(indeks, month).substring(0, 9), wsp * 12, y);
- y = y + (wsp * 4);
- g2.drawString(docType + month.substring(0, 2) + "." + month.substring(2,6), wsp * 12, y);
- g2.setFont(new Font("Arial Narrow", Font.PLAIN, 5));
- g2.drawString("Prowizję od wpłat", 400, addy);
- g2.drawString("w PKO uiszcza", 400, addy + 7);
- g2.drawString("posiadacz rachunku", 400, addy + 14);
- }
- private void rysujKodKreskowy(int x, int y, Graphics2D g2d) {
- Barcode b = null;
- try {
- b = BarcodeFactory.createCode128(indeks);
- } catch (BarcodeException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- b.setBarHeight(5);
- b.setBarWidth(1);
- Font deriveFont = g2d.getFont().deriveFont(7.0f); // copy of original Font with given size
- b.setFont(deriveFont);
- try {
- b.draw(g2d, x, y);
- g2d.setPaint(Color.WHITE);
- g2d.fill(new Rectangle2D.Double(x, y, b.getWidth(), b.getHeight() / 2.5d));
- g2d.setPaint(Color.BLACK);
- } catch (OutputException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement