OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 112 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 112 Rev 158
Line 5... Line 5...
5
import java.awt.GridBagLayout;
5
import java.awt.GridBagLayout;
6
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
7
import java.awt.event.ActionListener;
8
import java.awt.print.PageFormat;
8
import java.awt.print.PageFormat;
9
import java.awt.print.Pageable;
9
import java.awt.print.Pageable;
-
 
10
import java.awt.print.Paper;
10
import java.awt.print.PrinterException;
11
import java.awt.print.PrinterException;
11
import java.awt.print.PrinterJob;
12
import java.awt.print.PrinterJob;
12
import java.util.ArrayList;
13
import java.util.ArrayList;
13
import java.util.Calendar;
14
import java.util.Calendar;
14
import java.util.Collections;
15
import java.util.Collections;
15
import java.util.Comparator;
16
import java.util.Comparator;
16
import java.util.List;
17
import java.util.List;
17
 
18
 
-
 
19
import javax.print.attribute.HashPrintRequestAttributeSet;
-
 
20
import javax.print.attribute.PrintRequestAttributeSet;
-
 
21
import javax.print.attribute.Size2DSyntax;
-
 
22
import javax.print.attribute.standard.MediaPrintableArea;
-
 
23
import javax.print.attribute.standard.MediaSizeName;
18
import javax.swing.JButton;
24
import javax.swing.JButton;
19
import javax.swing.JCheckBox;
25
import javax.swing.JCheckBox;
20
import javax.swing.JLabel;
26
import javax.swing.JLabel;
21
import javax.swing.JOptionPane;
27
import javax.swing.JOptionPane;
22
import javax.swing.JPanel;
28
import javax.swing.JPanel;
23
import javax.swing.SwingConstants;
29
import javax.swing.SwingConstants;
24
import javax.swing.SwingUtilities;
30
import javax.swing.SwingUtilities;
25
 
31
 
26
import org.jopencalendar.model.JCalendarItem;
32
import org.jopencalendar.model.JCalendarItem;
27
import org.jopencalendar.print.CalendarItemPrinter;
33
import org.jopencalendar.print.CalendarItemPrinter;
-
 
34
import org.openconcerto.erp.generationDoc.A4;
28
import org.openconcerto.sql.users.User;
35
import org.openconcerto.sql.users.User;
29
import org.openconcerto.ui.DefaultGridBagConstraints;
36
import org.openconcerto.ui.DefaultGridBagConstraints;
30
import org.openconcerto.ui.JDate;
37
import org.openconcerto.ui.JDate;
31
import org.openconcerto.ui.PrintPreviewFrame;
38
import org.openconcerto.ui.PrintPreviewFrame;
32
 
39
 
33
public class CalendarPrintPanel extends JPanel {
40
public class CalendarPrintPanel extends JPanel {
34
    final JCheckBox preview = new JCheckBox("Aperçu");
41
    final JCheckBox preview = new JCheckBox("Aperçu");
35
    final JButton bPrint = new JButton("Imprimer");
42
    final JButton bPrint = new JButton("Imprimer");
-
 
43
    private static final double POINTS_PER_INCH = 72.0;
36
 
44
 
37
    public CalendarPrintPanel(final OperationCalendarManager manager, final int week, final int year, final List<User> selectedUsers, final List<String> selectedStates) {
45
    public CalendarPrintPanel(final OperationCalendarManager manager, final int week, final int year, final List<User> selectedUsers, final List<String> selectedStates) {
38
        preview.setSelected(true);
46
        preview.setSelected(true);
39
        //
47
        //
40
        this.setLayout(new GridBagLayout());
48
        this.setLayout(new GridBagLayout());
Line 84... Line 92...
84
            public void actionPerformed(ActionEvent e) {
92
            public void actionPerformed(ActionEvent e) {
85
                if (d1.getDate().after(d2.getDate())) {
93
                if (d1.getDate().after(d2.getDate())) {
86
                    return;
94
                    return;
87
                }
95
                }
88
 
96
 
89
                final List<Pageable> p = new ArrayList<Pageable>();
97
                final List<Pageable> p = new ArrayList<>();
90
 
98
 
91
                for (User user : selectedUsers) {
99
                for (User user : selectedUsers) {
92
                    final List<User> l = new ArrayList<User>();
100
                    final List<User> l = new ArrayList<>();
93
                    l.add(user);
101
                    l.add(user);
94
                    final List<JCalendarItem> itemInWeek = manager.getItemIn(d1.getDate(), d2.getDate(), l, selectedStates);
102
                    final List<JCalendarItem> itemInWeek = manager.getItemIn(d1.getDate(), d2.getDate(), l, selectedStates);
95
                    if (!itemInWeek.isEmpty()) {
103
                    if (!itemInWeek.isEmpty()) {
96
                        Collections.sort(itemInWeek, new Comparator<JCalendarItem>() {
104
                        Collections.sort(itemInWeek, new Comparator<JCalendarItem>() {
97
                            @Override
105
                            @Override
Line 137... Line 145...
137
 
145
 
138
    public void printPages(final List<Pageable> pageables) {
146
    public void printPages(final List<Pageable> pageables) {
139
        PrinterJob job = PrinterJob.getPrinterJob();
147
        PrinterJob job = PrinterJob.getPrinterJob();
140
        boolean ok = job.printDialog();
148
        boolean ok = job.printDialog();
141
        if (ok) {
149
        if (ok) {
-
 
150
            final PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
-
 
151
            final MediaSizeName media = MediaSizeName.ISO_A4;
-
 
152
            attributes.add(media);
-
 
153
            final Paper paper = new A4();
-
 
154
 
-
 
155
            final MediaPrintableArea printableArea = new MediaPrintableArea((float) (paper.getImageableX() / POINTS_PER_INCH), (float) (paper.getImageableY() / POINTS_PER_INCH),
-
 
156
                    (float) (paper.getImageableWidth() / POINTS_PER_INCH), (float) (paper.getImageableHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
-
 
157
            attributes.add(printableArea);
-
 
158
 
142
            for (Pageable document : pageables) {
159
            for (Pageable document : pageables) {
143
                PageFormat p = job.getPageFormat(null);
160
                PageFormat p = job.getPageFormat(null);
144
                System.err.println("CalendarPrintPanel.printPages():Size: " + p.getWidth() + " x " + p.getHeight());
-
 
145
                System.err.println("CalendarPrintPanel.printPages():Imagageable: " + p.getImageableWidth() + " x " + p.getImageableHeight());
-
 
146
                job.getPageFormat(null).getImageableHeight();
161
                job.getPageFormat(null).getImageableHeight();
147
                job.setPageable(document);
162
                job.setPageable(document);
148
                try {
163
                try {
149
                    job.print();
164
                    job.print(attributes);
150
                } catch (PrinterException e) {
165
                } catch (PrinterException e) {
151
                    e.printStackTrace();
166
                    e.printStackTrace();
152
                }
167
                }
153
            }
168
            }
154
        }
169
        }