OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.State;
18
import org.openconcerto.ui.state.WindowStateManager;
19
 
20
import java.awt.DisplayMode;
21
import java.awt.GraphicsEnvironment;
22
import java.awt.GridLayout;
23
import java.awt.event.ComponentAdapter;
24
import java.awt.event.ComponentEvent;
25
import java.io.File;
26
 
27
import javax.swing.JFrame;
28
import javax.swing.event.TableModelEvent;
29
import javax.swing.event.TableModelListener;
30
 
31
 
32
public class ConsultationCompteFrame extends JFrame {
33
    // panel contenant la liste des ecritures
34
    private final ListPanelEcritures panelEcritures;
35
    // panel complet liste des ecritures + totaux
36
    private final ListeDesEcrituresPanel panel;
37
 
38
    private String titre;
39
 
40
    public ConsultationCompteFrame(ListeDesEcrituresPanel panel, String titre) {
41
        super();
42
        this.panel = panel;
43
        this.panelEcritures = panel.getListPanelEcritures();
44
        this.titre = titre;
45
 
46
        // rafraichir le titre à chaque changement de la liste
47
        this.panelEcritures.getListe().addListener(new TableModelListener() {
48
            public void tableChanged(TableModelEvent e) {
49
                setTitle();
50
            }
51
        });
52
 
53
        this.uiInit();
54
        if (State.DEBUG) {
55
            State.INSTANCE.frameCreated();
56
            this.addComponentListener(new ComponentAdapter() {
57
                public void componentHidden(ComponentEvent e) {
58
                    State.INSTANCE.frameHidden();
59
                }
60
 
61
                public void componentShown(ComponentEvent e) {
62
                    State.INSTANCE.frameShown();
63
                }
64
            });
65
        }
66
    }
67
 
68
    private String getPlural(String s, int nb) {
69
        return nb + " " + s + (nb > 1 ? "s" : "");
70
    }
71
 
72
    private void setTitle(boolean displayRowCount, boolean displayItemCount) {
73
 
74
        String title = this.titre;
75
 
76
        if (displayRowCount) {
77
            final int rowCount = this.panelEcritures.getListe().getRowCount();
78
            title += ", " + getPlural("ligne", rowCount);
79
            final int total = this.panelEcritures.getListe().getTotalRowCount();
80
            if (total != rowCount)
81
                title += " / " + total;
82
        }
83
        if (displayItemCount) {
84
            int count = this.panelEcritures.getListe().getItemCount();
85
            if (count >= 0)
86
                title += ", " + this.getPlural("élément", count);
87
        }
88
        this.setTitle(title);
89
    }
90
 
91
    public void setTitle() {
92
        this.setTitle(true, true);
93
    }
94
 
95
    final private void uiInit() {
96
        this.setTitle();
97
        this.getContentPane().setLayout(new GridLayout());
98
        this.getContentPane().add(this.panel);
99
        this.setBounds();
100
        final File configFile = new File(Configuration.getInstance().getConfDir(), this.panelEcritures.getElement().getPluralName() + "-window.xml");
101
        new WindowStateManager(this, configFile).loadState();
102
    }
103
 
104
    final protected void setBounds() {
105
        // TODO use getMaximiumWindowBounds
106
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
107
        DisplayMode dm = ge.getDefaultScreenDevice().getDisplayMode();
108
 
109
        final int topOffset = 50;
110
        if (dm.getWidth() <= 800 || dm.getHeight() <= 600) {
111
            this.setLocation(0, topOffset);
112
            this.setSize(dm.getWidth(), dm.getHeight() - topOffset);
113
        } else {
114
            this.setLocation(10, topOffset);
115
            this.setSize(dm.getWidth() - 50, dm.getHeight() - 20 - topOffset);
116
        }
117
    }
118
 
119
    public final ListPanelEcritures getPanel() {
120
        return this.panelEcritures;
121
    }
122
 
123
}