OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 74 | Rev 120 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
74 ilm 1
package org.openconcerto.modules.extensionbuilder.translation.menu;
2
 
3
import java.awt.GridBagConstraints;
4
import java.awt.GridBagLayout;
5
import java.util.Locale;
6
 
7
import javax.swing.JLabel;
8
import javax.swing.JPanel;
9
import javax.swing.JSeparator;
10
import javax.swing.JTextField;
11
import javax.swing.SwingConstants;
86 ilm 12
import javax.swing.event.DocumentEvent;
13
import javax.swing.event.DocumentListener;
74 ilm 14
 
15
import org.openconcerto.modules.extensionbuilder.Extension;
86 ilm 16
import org.openconcerto.modules.extensionbuilder.menu.mainmenu.MenuDescriptor;
74 ilm 17
import org.openconcerto.modules.extensionbuilder.translation.LocaleSelector;
18
import org.openconcerto.ui.DefaultGridBagConstraints;
19
import org.openconcerto.ui.group.Item;
20
import org.openconcerto.ui.group.LayoutHints;
21
 
22
public class MenuTranslationItemEditor extends JPanel {
23
 
24
    final Extension extension;
25
    private JTextField textId;
26
    private JTextField textTranslation1;
27
    private JTextField textTranslation2;
28
 
29
    public MenuTranslationItemEditor(final Item item, final Extension extension) {
30
        this.extension = extension;
31
        this.setLayout(new GridBagLayout());
32
        GridBagConstraints c = new DefaultGridBagConstraints();
33
 
34
        c.weightx = 0;
35
        c.fill = GridBagConstraints.HORIZONTAL;
36
        this.add(new JLabel("Identifiant", SwingConstants.RIGHT), c);
37
        c.gridx++;
38
        c.fill = GridBagConstraints.HORIZONTAL;
39
        c.weightx = 1;
40
        c.gridwidth = 3;
41
        textId = new JTextField();
42
        this.add(textId, c);
43
 
44
        // Language selector
45
        c.gridx = 0;
46
        c.gridy++;
47
        c.weightx = 0;
48
        c.gridwidth = 1;
49
        c.fill = GridBagConstraints.HORIZONTAL;
50
        this.add(new JLabel("Langue et pays", SwingConstants.RIGHT), c);
51
        final String[] isoLanguages = Locale.getISOLanguages();
52
        System.out.println(isoLanguages.length);
53
 
54
        final LocaleSelector comboLang1 = new LocaleSelector();
55
 
56
        c.weightx = 1;
57
        c.gridx++;
58
        c.fill = GridBagConstraints.NONE;
59
        this.add(comboLang1, c);
60
        c.weightx = 0;
61
        c.gridx++;
62
        c.gridheight = 2;
63
        c.fill = GridBagConstraints.BOTH;
64
        final JSeparator sep = new JSeparator(JSeparator.VERTICAL);
65
        this.add(sep, c);
66
 
67
        c.gridheight = 1;
68
        c.weightx = 1;
69
        c.gridx++;
70
        c.fill = GridBagConstraints.NONE;
71
        final LocaleSelector comboLang2 = new LocaleSelector();
72
 
73
        comboLang2.setLocale(Locale.ENGLISH);
74
        this.add(comboLang2, c);
75
        // Traduction
76
        c.gridx = 0;
77
        c.gridy++;
78
 
79
        c.gridwidth = 1;
80
 
81
        c.weightx = 0;
82
        c.fill = GridBagConstraints.HORIZONTAL;
83
        this.add(new JLabel("Traduction", SwingConstants.RIGHT), c);
84
        c.gridx++;
85
 
86
        c.weightx = 1;
87
 
88
        textTranslation1 = new JTextField(20);
89
 
90
        this.add(textTranslation1, c);
91
 
92
        c.gridx += 2;
93
        c.fill = GridBagConstraints.HORIZONTAL;
94
 
95
        c.weightx = 1;
96
        textTranslation2 = new JTextField(20);
97
        this.add(textTranslation2, c);
98
 
99
        c.gridy++;
100
        c.weighty = 1;
101
        this.add(new JPanel(), c);
102
 
103
        initUIFrom(item);
104
 
86 ilm 105
        textTranslation1.getDocument().addDocumentListener(new DocumentListener() {
106
 
107
            @Override
108
            public void removeUpdate(DocumentEvent e) {
109
                changedUpdate(e);
110
 
111
            }
112
 
113
            @Override
114
            public void insertUpdate(DocumentEvent e) {
115
                changedUpdate(e);
116
            }
117
 
118
            @Override
119
            public void changedUpdate(DocumentEvent e) {
120
                extension.setMenuTranslation(item.getId(), textTranslation1.getText(), comboLang1.getLocale());
121
                extension.setChanged();
122
            }
123
        });
124
        textTranslation2.getDocument().addDocumentListener(new DocumentListener() {
125
 
126
            @Override
127
            public void removeUpdate(DocumentEvent e) {
128
                changedUpdate(e);
129
 
130
            }
131
 
132
            @Override
133
            public void insertUpdate(DocumentEvent e) {
134
                changedUpdate(e);
135
            }
136
 
137
            @Override
138
            public void changedUpdate(DocumentEvent e) {
139
                extension.setMenuTranslation(item.getId(), textTranslation2.getText(), comboLang2.getLocale());
140
                extension.setChanged();
141
            }
142
        });
143
 
74 ilm 144
    }
145
 
146
    private void initUIFrom(Item item) {
147
 
148
        final LayoutHints localHint = item.getLocalHint();
149
        System.out.println("ItemEditor.initUIFrom:" + item + " " + localHint);
150
        textId.setEnabled(false);
151
        if (textId != null) {
152
            textId.setText(item.getId());
153
        }
154
 
155
    }
156
}