diff --git a/.vscode/launch.json b/.vscode/launch.json index 56147c4..bbb66eb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,5 +1,12 @@ { "configurations": [ + { + "type": "java", + "name": "Launch HesSoGarage", + "request": "launch", + "mainClass": "BillGUI.HesSoGarage", + "projectName": "Lab15_OOP_90898795" + }, { "type": "java", "name": "Launch HesSoGarage", diff --git a/bin/BillGUI/BillGui$1$1.class b/bin/BillGUI/BillGui$1$1.class new file mode 100644 index 0000000..b28fa7a Binary files /dev/null and b/bin/BillGUI/BillGui$1$1.class differ diff --git a/bin/BillGUI/BillGui$1.class b/bin/BillGUI/BillGui$1.class new file mode 100644 index 0000000..59c85ae Binary files /dev/null and b/bin/BillGUI/BillGui$1.class differ diff --git a/bin/BillGUI/BillGui.class b/bin/BillGUI/BillGui.class index e031975..eb0dd1b 100644 Binary files a/bin/BillGUI/BillGui.class and b/bin/BillGUI/BillGui.class differ diff --git a/bin/BillGUI/ButtonListenerBill.class b/bin/BillGUI/ButtonListenerBill.class index c00f559..5a6bbaa 100644 Binary files a/bin/BillGUI/ButtonListenerBill.class and b/bin/BillGUI/ButtonListenerBill.class differ diff --git a/bin/BillGUI/HesSoGarage.class b/bin/BillGUI/HesSoGarage.class index afe39d3..427941a 100644 Binary files a/bin/BillGUI/HesSoGarage.class and b/bin/BillGUI/HesSoGarage.class differ diff --git a/bin/BillGUI/Impression1.class b/bin/BillGUI/Impression1.class deleted file mode 100644 index 10a72e2..0000000 Binary files a/bin/BillGUI/Impression1.class and /dev/null differ diff --git a/src/BillGUI/BillGui.java b/src/BillGUI/BillGui.java index d9bc9ae..d7e3b3d 100644 --- a/src/BillGUI/BillGui.java +++ b/src/BillGUI/BillGui.java @@ -3,6 +3,8 @@ package BillGUI; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import java.awt.print.*; +import java.awt.image.BufferedImage; public class BillGui extends JFrame{ String bill; @@ -26,18 +28,52 @@ public class BillGui extends JFrame{ this.add(jP); JButton buttonPrint = new JButton("Print"); - buttonPrint.addActionListener(new Impression1(jP)); - /* + buttonPrint.addActionListener( + new ButtonListenerBill(this) { @Override public void actionPerformed(ActionEvent e){ - // TO-DO : print the pdf - }; - });*/ + + PrinterJob pj = PrinterJob.getPrinterJob(); + pj.setJobName("Bill"); + + Printable printable = new Printable() { + public int print(Graphics pg, PageFormat pf, int pageNum){ + if (pageNum > 0) return Printable.NO_SUCH_PAGE; + + Dimension size = jP.getSize(); + BufferedImage bufferedImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); + + jP.print(bufferedImage.getGraphics()); + + Graphics2D g2 = (Graphics2D) pg; + g2.translate(pf.getImageableX(), pf.getImageableY()); + g2.drawImage(bufferedImage, 0, 0, (int) pf.getWidth(), (int) pf.getHeight(), null); + + return Printable.PAGE_EXISTS; + } + }; + + Paper paper = new Paper(); + paper.setImageableArea(0, 0,2480,3508); + paper.setSize(2480,3508); + + PageFormat format = new PageFormat(); + format.setPaper(paper); + format.setOrientation(PageFormat.PORTRAIT); + + pj.setPrintable (printable, format); + + if (pj.printDialog() == false) return; + + try { + pj.print(); + } catch (PrinterException ex) {} + } + }); this.add(buttonPrint); - - } + } /** @@ -51,8 +87,12 @@ class ButtonListenerBill implements ActionListener { } @Override - public void actionPerformed(ActionEvent e){ - - }; - + public void actionPerformed(ActionEvent e){ }; } + + + + + + + diff --git a/src/BillGUI/HesSoGarage.java b/src/BillGUI/HesSoGarage.java index 4721167..ca1569d 100644 --- a/src/BillGUI/HesSoGarage.java +++ b/src/BillGUI/HesSoGarage.java @@ -3,10 +3,9 @@ package BillGUI; public class HesSoGarage { public static void main(String[] args) { GarageManager garageManager = new GarageManager(); - ManagerGui managerGui; String name = "\033[3mGarage manager\033[0m\nPrestations"; //TODO résoudre en italique String logoFilePath = "src/logo_garage.png"; //TODO redimensionnement automatique - managerGui = new ManagerGui(name, logoFilePath, garageManager.getServices(), garageManager); //TODO affichage sans redimmensionnement + new ManagerGui(name, logoFilePath, garageManager.getServices(), garageManager); //TODO affichage sans redimensionnement } } diff --git a/src/BillGUI/Impression1.java b/src/BillGUI/Impression1.java deleted file mode 100644 index 770ad96..0000000 --- a/src/BillGUI/Impression1.java +++ /dev/null @@ -1,47 +0,0 @@ -package BillGUI; -//TODO all - -import java.awt.*; -import java.awt.event.*; -import java.awt.print.*; -import javax.swing.*; - - -public class Impression1 extends JPanel implements Printable, ActionListener{ - - /** **/ - -JPanel frameToPrint; - - public int print(Graphics g, PageFormat pf, int page) throws PrinterException { - - if (page > 0) { - return NO_SUCH_PAGE; - } - - Graphics2D g2d = (Graphics2D) g; - g2d.translate(pf.getImageableX(), pf.getImageableY()); - - frameToPrint.printAll(g); - - return PAGE_EXISTS; - } - - public void actionPerformed(ActionEvent e) { - PrinterJob job = PrinterJob.getPrinterJob(); - job.setPrintable(this); - boolean ok = job.printDialog(); - if (ok) { - try { - job.print(); - } catch (PrinterException ex) { - } - } - } - - public Impression1(JPanel f) { - frameToPrint = f; - } - - } -