Co-authored-by: Fastium <Fastium@users.noreply.github.com>
This commit is contained in:
@ -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){};
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ public class HesSoGarage {
|
||||
//Create a new garage
|
||||
GarageManager garageManager = new GarageManager();
|
||||
String name = "<html><body><i>Garage manager</i><br>Prestations</body></html>";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Row> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user