diff --git a/.vscode/launch.json b/.vscode/launch.json index aa60619..8656dcd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,10 +1,18 @@ { "configurations": [ + { + "type": "java", + "name": "Launch CompleteBankController", + "request": "launch", + "mainClass": "bank.CompleteBankController", + "projectName": "Lab15_OOP_90898795", + "vmArgs": "-enableassertions" + }, { "type": "java", "name": "Launch BankController", "request": "launch", - "mainClass": "bank.BankController", + "mainClass": "bank.CompleteBankController", "projectName": "Lab15_OOP_fc166bd2", "vmArgs": "-enableassertions" }, @@ -57,8 +65,7 @@ "mainClass": "GUI.GUI1", "projectName": "Lab15_OOP_90898795", "liveshare.allowGuestDebugControl": true - }, - + } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 37d5d4a..39a1b51 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,10 @@ "lib/**/*.jar" ], "liveshare.shareExternalFiles": false, - "liveshare.allowGuestDebugControl": true + "liveshare.allowGuestDebugControl": true, + "cSpell.words": [ + "Jframe", + "Jlogo", + "Jname" + ] } diff --git a/bin/BillGUI/BillGui$1$1.class b/bin/BillGUI/BillGui$1$1.class index 3897c85..b912c87 100644 Binary files a/bin/BillGUI/BillGui$1$1.class and b/bin/BillGUI/BillGui$1$1.class differ diff --git a/bin/BillGUI/BillGui$1.class b/bin/BillGUI/BillGui$1.class index af6dc64..21fed41 100644 Binary files a/bin/BillGUI/BillGui$1.class and b/bin/BillGUI/BillGui$1.class differ diff --git a/bin/BillGUI/BillGui.class b/bin/BillGUI/BillGui.class index 707547b..a6ca7b0 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 5bf7ed9..18b5d58 100644 Binary files a/bin/BillGUI/ButtonListenerBill.class and b/bin/BillGUI/ButtonListenerBill.class differ diff --git a/bin/BillGUI/ButtonListenerManager.class b/bin/BillGUI/ButtonListenerManager.class index bbff05f..09bbe43 100644 Binary files a/bin/BillGUI/ButtonListenerManager.class and b/bin/BillGUI/ButtonListenerManager.class differ diff --git a/bin/BillGUI/ManagerGui$1.class b/bin/BillGUI/ManagerGui$1.class index 9db698e..c4e8052 100644 Binary files a/bin/BillGUI/ManagerGui$1.class and b/bin/BillGUI/ManagerGui$1.class differ diff --git a/bin/BillGUI/ManagerGui$2.class b/bin/BillGUI/ManagerGui$2.class index 987e31b..54cbfca 100644 Binary files a/bin/BillGUI/ManagerGui$2.class and b/bin/BillGUI/ManagerGui$2.class differ diff --git a/bin/BillGUI/ManagerGui.class b/bin/BillGUI/ManagerGui.class index 33ba8c4..5f484e2 100644 Binary files a/bin/BillGUI/ManagerGui.class and b/bin/BillGUI/ManagerGui.class differ diff --git a/bin/BillGUI/Row.class b/bin/BillGUI/Row.class index 58322f7..b409d33 100644 Binary files a/bin/BillGUI/Row.class and b/bin/BillGUI/Row.class differ diff --git a/src/BillGUI/BillGui.java b/src/BillGUI/BillGui.java index aebb821..6d64dbe 100644 --- a/src/BillGUI/BillGui.java +++ b/src/BillGUI/BillGui.java @@ -35,17 +35,18 @@ public class BillGui extends JFrame{ //Create the button for print the bill JButton buttonPrint = new JButton("Print"); - buttonPrint.addActionListener(new ButtonListenerBill(this) { - //TODO : describe the prozess to print and resize the bill - /** - * - */ + buttonPrint.addActionListener(new ButtonListenerBill() { + @Override public void actionPerformed(ActionEvent e){ + // Create a new printer Job PrinterJob pj = PrinterJob.getPrinterJob(); pj.setJobName("Bill"); + // Create a printable element from a JPanel. This method is just a copy, it resize but isn't perfect. + // It's just a first test. Should be improved + // TODO : improve this method Printable printable = new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ if (pageNum > 0) return Printable.NO_SUCH_PAGE; @@ -63,24 +64,29 @@ public class BillGui extends JFrame{ } }; + // Create and set a A4 paper 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); + // Set all settings about the printing function pj.setPrintable (printable, format); + // Launch the printer dialog for printing. if (pj.printDialog() == false) return; - try { pj.print(); } catch (PrinterException ex) {} } }); + + this.add(buttonPrint); + + } } @@ -89,14 +95,6 @@ public class BillGui extends JFrame{ * listener to detect the button to print the bill */ class ButtonListenerBill implements ActionListener { - JFrame Jf; - /** - * initialize the listener - * @param Jf //TODO : do we always use the JFrame ? - */ - ButtonListenerBill(JFrame Jf){ - this.Jf = Jf; - } @Override public void actionPerformed(ActionEvent e){}; } diff --git a/src/BillGUI/HesSoGarage.java b/src/BillGUI/HesSoGarage.java index 32e6e9a..0763c33 100644 --- a/src/BillGUI/HesSoGarage.java +++ b/src/BillGUI/HesSoGarage.java @@ -5,9 +5,9 @@ public class HesSoGarage { //Create a new garage GarageManager garageManager = new GarageManager(); String name = "Garage manager
Prestations"; - String logoFilePath = "src/logo_garage.png"; //TODO redimensionnement automatique + String logoFilePath = "src/logo_garage.png"; //Create a new HMI for calculate and print the bill - new ManagerGui(name, logoFilePath, garageManager.getServices(), garageManager); //TODO affichage sans redimensionnement + new ManagerGui(name, logoFilePath, garageManager.getServices(), garageManager); } } diff --git a/src/BillGUI/ManagerGui.java b/src/BillGUI/ManagerGui.java index 60520d9..646e795 100644 --- a/src/BillGUI/ManagerGui.java +++ b/src/BillGUI/ManagerGui.java @@ -15,6 +15,7 @@ public class ManagerGui extends JFrame { ImageIcon logo; String buttonNameQuit = "Quit"; String buttonNameBill = "Show bill"; + double ratio = 207.0 / 163.0; Vector prestations = new Vector<>(); @@ -41,6 +42,10 @@ public class ManagerGui extends JFrame { Jlogo = new JLabel(logo); Jname = new JLabel(name); this.add(Jname); + + //logo = new ImageIcon(new ImageIcon(logoFilePath).getImage().getScaledInstance(207, 163, Image.SCALE_DEFAULT)); + //Jlogo = new JLabel(logo); + Jlogo = resize(Jname, logoFilePath); this.add(Jlogo); //Create rows for prestations @@ -87,6 +92,18 @@ public class ManagerGui extends JFrame { this.add(buttonBill); this.add(buttonQuit); + + this.setVisible(true); + } + + private JLabel resize(JLabel Jlogo, String logoFilePath){ + //TODO put in listener for resize when frame is resized. + int width = (int)Jlogo.getSize().getWidth(); + int height = (int)Jlogo.getSize().getHeight(); + height = height > 0 ? height:65; + System.out.println(width + "x"+ height); + ImageIcon logo = new ImageIcon(new ImageIcon(logoFilePath).getImage().getScaledInstance((int) (height*ratio), height, Image.SCALE_DEFAULT)); + return new JLabel(logo); } }