OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Rev 156 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 142
Line 37... Line 37...
37
import java.awt.event.ItemListener;
37
import java.awt.event.ItemListener;
38
import java.util.ArrayList;
38
import java.util.ArrayList;
39
import java.util.List;
39
import java.util.List;
40
import java.util.Vector;
40
import java.util.Vector;
41
 
41
 
-
 
42
import javax.print.PrintService;
-
 
43
import javax.print.PrintServiceLookup;
42
import javax.swing.ComboBoxModel;
44
import javax.swing.ComboBoxModel;
43
import javax.swing.DefaultComboBoxModel;
45
import javax.swing.DefaultComboBoxModel;
44
import javax.swing.DefaultListCellRenderer;
46
import javax.swing.DefaultListCellRenderer;
45
import javax.swing.JButton;
47
import javax.swing.JButton;
46
import javax.swing.JComboBox;
48
import javax.swing.JComboBox;
Line 53... Line 55...
53
import javax.swing.SwingConstants;
55
import javax.swing.SwingConstants;
54
import javax.swing.SwingUtilities;
56
import javax.swing.SwingUtilities;
55
 
57
 
56
public class ConfigCaissePanel extends JPanel {
58
public class ConfigCaissePanel extends JPanel {
57
 
59
 
-
 
60
    private final POSConfiguration configuration = POSConfiguration.getInstance();
58
    private int userId;
61
    private int userId;
59
    private int societeId;
62
    private int societeId;
60
    private int caisseId;
63
    private int caisseId;
61
    private final ServerFinderPanel serverFinderPanel;
64
    private final ServerFinderPanel serverFinderPanel;
62
    private final JComboBox comboSociete;
65
    private final JComboBox comboSociete;
Line 68... Line 71...
68
 
71
 
69
    // Ticket printers
72
    // Ticket printers
70
    private final TicketPrinterConfigPanel ticketPanel1;
73
    private final TicketPrinterConfigPanel ticketPanel1;
71
    private final TicketPrinterConfigPanel ticketPanel2;
74
    private final TicketPrinterConfigPanel ticketPanel2;
72
    // LCD
75
    // LCD
-
 
76
    private JComboBox comboLCDType;
73
    private JTextField textLCDSerialPort;
77
    private JTextField textLCDPort;
74
    private JTextField textLCDLine1;
78
    private JTextField textLCDLine1;
75
    private JTextField textLCDLine2;
79
    private JTextField textLCDLine2;
76
 
80
 
77
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
81
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
78
        this.serverFinderPanel = serverFinderPanel;
82
        this.serverFinderPanel = serverFinderPanel;
Line 87... Line 91...
87
        this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
91
        this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
88
        c.gridx++;
92
        c.gridx++;
89
        c.gridwidth = 3;
93
        c.gridwidth = 3;
90
        c.weightx = 1;
94
        c.weightx = 1;
91
        JTextField textConfigurationFile = new JTextField("");
95
        JTextField textConfigurationFile = new JTextField("");
92
        if (POSConfiguration.getConfigFile() != null) {
96
        if (this.configuration.getConfigFile() != null) {
93
            textConfigurationFile.setText(POSConfiguration.getConfigFile().getAbsolutePath());
97
            textConfigurationFile.setText(this.configuration.getConfigFile().getAbsolutePath());
94
        }
98
        }
95
        textConfigurationFile.setEditable(false);
99
        textConfigurationFile.setEditable(false);
96
        this.add(textConfigurationFile, c);
100
        this.add(textConfigurationFile, c);
97
 
101
 
98
        // Connexion
102
        // Connexion
Line 250... Line 254...
250
        c.gridy++;
254
        c.gridy++;
251
        c.weightx = 0;
255
        c.weightx = 0;
252
        c.gridwidth = 1;
256
        c.gridwidth = 1;
253
        c.anchor = GridBagConstraints.EAST;
257
        c.anchor = GridBagConstraints.EAST;
254
        c.fill = GridBagConstraints.NONE;
258
        c.fill = GridBagConstraints.NONE;
255
        p.add(new JLabel("Port série", SwingConstants.RIGHT), c);
259
        p.add(new JLabel("Type", SwingConstants.RIGHT), c);
-
 
260
        c.gridx++;
-
 
261
        c.weightx = 0;
-
 
262
        c.fill = GridBagConstraints.NONE;
-
 
263
        c.anchor = GridBagConstraints.WEST;
-
 
264
        comboLCDType = new JComboBox(new String[] { "Port série", "Emulation imprimante" });
-
 
265
 
-
 
266
        p.add(comboLCDType, c);
-
 
267
        c.gridy++;
-
 
268
        c.gridx = 0;
-
 
269
        c.anchor = GridBagConstraints.EAST;
-
 
270
        final JLabel labelType = new JLabel("Port", SwingConstants.RIGHT);
-
 
271
        p.add(labelType, c);
256
        c.gridx++;
272
        c.gridx++;
257
        c.weightx = 1;
273
        c.weightx = 1;
258
        c.fill = GridBagConstraints.HORIZONTAL;
274
        c.fill = GridBagConstraints.HORIZONTAL;
259
 
275
 
260
        this.textLCDSerialPort = new JTextField(20);
276
        this.textLCDPort = new JTextField(20);
261
        p.add(this.textLCDSerialPort, c);
277
        p.add(this.textLCDPort, c);
262
        c.weightx = 0;
278
        c.weightx = 0;
263
        c.gridx++;
279
        c.gridx++;
264
        final JButton selectPortButton = new JButton("Sélectionner");
280
        final JButton selectPortButton = new JButton("Sélectionner");
265
        selectPortButton.addActionListener(new ActionListener() {
281
        selectPortButton.addActionListener(new ActionListener() {
266
 
282
 
267
            @Override
283
            @Override
268
            public void actionPerformed(ActionEvent e) {
284
            public void actionPerformed(ActionEvent e) {
269
                List<String> choices = new ArrayList<String>();
285
                List<String> choices = new ArrayList<String>();
270
                final String title;
286
                final String title;
271
                final String message;
287
                final String message;
-
 
288
                if (comboLCDType.getSelectedIndex() == 1) {
-
 
289
                    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
-
 
290
                    for (PrintService printer : printServices) {
-
 
291
                        choices.add(printer.getName());
-
 
292
                    }
-
 
293
                    title = "Afficheur LCD";
272
 
-
 
-
 
294
                    message = "Choisissez l'imprimante correspondante à l'afficheur LCD";
-
 
295
                } else if (comboLCDType.getSelectedIndex() == 0) {
273
                choices.addAll(ESCSerialPrinter.getSerialPortNames());
296
                    choices.addAll(ESCSerialPrinter.getSerialPortNames());
274
                title = "Port série";
297
                    title = "Port série";
275
                message = "Choisissez le port série lié à l'afficheur";
298
                    message = "Choisissez le port série lié à l'afficheur LCD";
-
 
299
                } else {
-
 
300
                    return;
-
 
301
                }
276
                if (choices.isEmpty()) {
302
                if (choices.isEmpty()) {
277
                    return;
303
                    return;
278
                }
304
                }
279
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
305
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
-
 
306
 
280
                // If a string was returned
307
                // If a string was returned
281
                if ((s != null) && (s.length() > 0)) {
308
                if ((s != null) && (s.length() > 0)) {
282
                    textLCDSerialPort.setText(s);
309
                    textLCDPort.setText(s);
283
                }
310
                }
-
 
311
 
284
            }
312
            }
285
        });
313
        });
286
        p.add(selectPortButton, c);
314
        p.add(selectPortButton, c);
287
        //
-
 
288
 
315
 
289
        c.gridx = 0;
316
        c.gridx = 0;
290
        c.gridy++;
317
        c.gridy++;
291
        c.gridwidth = 3;
318
        c.gridwidth = 3;
292
        p.add(new JLabel("Message d'accueil de l'afficheur"), c);
319
        p.add(new JLabel("Message d'accueil de l'afficheur"), c);
Line 427... Line 454...
427
        }
454
        }
428
    }
455
    }
429
 
456
 
430
    public void loadConfiguration() {
457
    public void loadConfiguration() {
431
 
458
 
432
        final POSConfiguration configuration = POSConfiguration.getInstance();
459
        final POSConfiguration configuration = this.configuration;
433
        // Terminal CB
460
        // Terminal CB
434
        this.textTerminalCB.setText(configuration.getCreditCardPort());
461
        this.textTerminalCB.setText(configuration.getCreditCardPort());
435
        // Afficheur LCD
462
        // Afficheur LCD
-
 
463
        final String lcdType = configuration.getLCDType();
-
 
464
        if (lcdType.equals("serial")) {
-
 
465
            this.comboLCDType.setSelectedIndex(0);
-
 
466
        } else {
-
 
467
            this.comboLCDType.setSelectedIndex(1);
-
 
468
        }
-
 
469
 
436
        this.textLCDSerialPort.setText(configuration.getLCDSerialPort());
470
        this.textLCDPort.setText(configuration.getLCDPort());
437
        this.textLCDLine1.setText(configuration.getLCDLine1());
471
        this.textLCDLine1.setText(configuration.getLCDLine1());
438
        this.textLCDLine2.setText(configuration.getLCDLine2());
472
        this.textLCDLine2.setText(configuration.getLCDLine2());
439
 
473
 
440
        this.userId = configuration.getUserID();
474
        this.userId = configuration.getUserID();
441
        this.societeId = configuration.getCompanyID();
475
        this.societeId = configuration.getCompanyID();
Line 560... Line 594...
560
        System.out.println("Caisse: id:" + this.caisseId);
594
        System.out.println("Caisse: id:" + this.caisseId);
561
        System.out.println("Utilisateur:  id:" + this.userId);
595
        System.out.println("Utilisateur:  id:" + this.userId);
562
    }
596
    }
563
 
597
 
564
    public void saveConfiguration() {
598
    public void saveConfiguration() {
565
        POSConfiguration configuration = POSConfiguration.getInstance();
599
        final POSConfiguration configuration = this.configuration;
566
        this.ticketPanel1.commitValues();
600
        this.ticketPanel1.commitValues();
567
        this.ticketPanel2.commitValues();
601
        this.ticketPanel2.commitValues();
568
        configuration.setUserID(this.userId);
602
        configuration.setUserID(this.userId);
569
        configuration.setCompanyID(this.societeId);
603
        configuration.setCompanyID(this.societeId);
570
        configuration.setPosID(this.caisseId);
604
        configuration.setPosID(this.caisseId);
571
        configuration.setHeaderLines(this.headerTable.getLines());
605
        configuration.setHeaderLines(this.headerTable.getLines());
572
        configuration.setFooterLines(this.footerTable.getLines());
606
        configuration.setFooterLines(this.footerTable.getLines());
573
        // Terminal CB
607
        // Terminal CB
574
        configuration.setCreditCardPort(this.textTerminalCB.getText());
608
        configuration.setCreditCardPort(this.textTerminalCB.getText());
575
        // LCD
609
        // LCD
-
 
610
        final int selectedIndex = this.comboLCDType.getSelectedIndex();
-
 
611
        if (selectedIndex == 0) {
-
 
612
            configuration.setLCDType("serial");
-
 
613
        } else {
-
 
614
            configuration.setLCDType("printer");
-
 
615
        }
576
        configuration.setLCDSerialPort(this.textLCDSerialPort.getText());
616
        configuration.setLCDPort(this.textLCDPort.getText());
577
        configuration.setLCDLine1(this.textLCDLine1.getText());
617
        configuration.setLCDLine1(this.textLCDLine1.getText());
578
        configuration.setLCDLine2(this.textLCDLine2.getText());
618
        configuration.setLCDLine2(this.textLCDLine2.getText());
579
        // Save
619
        // Save
580
        configuration.saveConfiguration();
620
        configuration.saveConfiguration();
581
    }
621
    }