OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 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.ui.preferences;
15
 
73 ilm 16
import org.openconcerto.ui.TM;
17
 
17 ilm 18
import java.awt.Dimension;
19
import java.awt.GridBagConstraints;
20
import java.awt.GridBagLayout;
21
import java.awt.Toolkit;
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24
import java.awt.event.WindowAdapter;
25
import java.awt.event.WindowEvent;
26
 
27
import javax.swing.JButton;
28
import javax.swing.JFrame;
29
import javax.swing.JOptionPane;
30
import javax.swing.JPanel;
31
import javax.swing.JSeparator;
32
import javax.swing.tree.DefaultMutableTreeNode;
33
 
34
public class PreferenceFrame extends JFrame {
35
 
36
    MainPrefPanel mainPrefPanel;
37
 
38
    public PreferenceFrame(DefaultMutableTreeNode root) {
39
        super();
73 ilm 40
        this.setTitle(TM.tr("prefs.title"));
17 ilm 41
        Toolkit.getDefaultToolkit().setDynamicLayout(true);
42
 
43
        this.getContentPane().setLayout(new GridBagLayout());
44
        GridBagConstraints c = new GridBagConstraints();
45
        c.gridx = 0;
46
        c.gridy = 0;
47
        c.gridwidth = 1;
48
        c.fill = GridBagConstraints.BOTH;
49
        c.weightx = 0;
50
        c.weighty = 1;
51
 
52
        PrefTree prefTree = new PrefTree(root);
151 ilm 53
        final int fontSize = prefTree.getFont().getSize();
54
        prefTree.setMinimumSize(new Dimension(fontSize * 23, fontSize * 18));
55
        prefTree.setPreferredSize(new Dimension(fontSize * 23, fontSize * 18));
17 ilm 56
        this.getContentPane().add(prefTree, c);
57
 
58
        c.gridx++;
59
        c.weightx = 0;
60
        this.getContentPane().add(new JSeparator(JSeparator.VERTICAL), c);
61
 
62
        c.gridx++;
63
        c.weightx = 1;
64
        this.mainPrefPanel = new MainPrefPanel(prefTree);
65
        this.getContentPane().add(this.mainPrefPanel, c);
66
 
67
        c.gridx = 0;
68
        c.gridy++;
69
        c.fill = GridBagConstraints.BOTH;
70
        c.weightx = 1;
71
        c.weighty = 0;
72
        c.gridwidth = 3;
73
        this.getContentPane().add(new JSeparator(JSeparator.HORIZONTAL), c);
74
 
75
        JPanel p1 = new JPanel();
73 ilm 76
        JButton buttonClose = new JButton(TM.tr("toClose"));
17 ilm 77
        p1.setOpaque(true);
78
        p1.add(buttonClose);
79
 
80
        c.gridx = 0;
81
        c.gridy++;
82
        c.gridwidth = 3;
83
        c.weighty = 0;
84
        c.fill = GridBagConstraints.NONE;
85
        c.anchor = GridBagConstraints.EAST;
86
        this.getContentPane().add(p1, c);
87
        this.setBackground(p1.getBackground());
88
        this.getContentPane().setBackground(p1.getBackground());
151 ilm 89
        this.setMinimumSize(new Dimension(fontSize * 80, fontSize * 62));
90
        this.setPreferredSize(new Dimension(fontSize * 80, fontSize * 62));
17 ilm 91
        prefTree.addTreeSelectionListener(this.mainPrefPanel);
92
        buttonClose.addActionListener(new ActionListener() {
93
            public void actionPerformed(ActionEvent e) {
94
                doOnClose();
95
                PreferenceFrame.this.dispose();
96
            }
97
        });
98
 
99
        this.addWindowListener(new WindowAdapter() {
100
 
101
            public void windowClosing(WindowEvent e) {
102
                doOnClose();
103
            };
104
        });
105
    }
106
 
107
    private void doOnClose() {
108
        PreferencePanel currentPanel = this.mainPrefPanel.getCurrentPanel();
109
        if (currentPanel.isModified()) {
73 ilm 110
            if (JOptionPane.showConfirmDialog(null, TM.tr("prefs.applyModif"), TM.tr("prefs.applyModif.title"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
17 ilm 111
                currentPanel.apply();
112
            }
113
        }
114
    }
115
 
116
}