PageRenderTime 5ms CodeModel.GetById 110ms app.highlight 180ms RepoModel.GetById 36ms app.codeStats 0ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_Locale.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 670 lines | 579 code | 78 blank | 13 comment | 18 complexity | 79b2c9d106139016ece2b0953c3822d7 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.io.BufferedWriter;
  4import java.io.File;
  5import java.io.FileOutputStream;
  6import java.io.FileWriter;
  7import java.io.OutputStreamWriter;
  8import java.sql.SQLException;
  9import java.util.Collections;
 10import java.util.Enumeration;
 11import java.util.List;
 12import java.util.Locale;
 13import java.util.ResourceBundle;
 14import javax.swing.ComboBoxModel;
 15import javax.swing.DefaultComboBoxModel;
 16
 17import javax.swing.JFileChooser;
 18import javax.swing.JTextField;
 19import javax.swing.plaf.TextUI;
 20import mpv5.data.PropertyStore;
 21import mpv5.db.common.*;
 22import mpv5.db.objects.User;
 23import mpv5.globals.Constants;
 24import mpv5.globals.Messages;
 25import mpv5.i18n.LanguageManager;
 26import mpv5.logging.Log;
 27import mpv5.ui.dialogs.ControlApplet;
 28import mpv5.ui.dialogs.DialogForFile;
 29import mpv5.ui.dialogs.Notificator;
 30import mpv5.ui.dialogs.Popup;
 31import mpv5.ui.misc.TextFieldUtils;
 32
 33import mpv5.utils.files.FileDirectoryHandler;
 34import mpv5.utils.files.FileReaderWriter;
 35import mpv5.utils.models.MPComboBoxModelItem;
 36import mpv5.utils.text.RandomText;
 37import mpv5.utils.text.TypeConversion;
 38
 39/**
 40 *
 41 *
 42 */
 43public class ControlPanel_Locale extends javax.swing.JPanel implements ControlApplet {
 44
 45    private static final long serialVersionUID = 1L;
 46    /**
 47     * This unique name identifies this control applet
 48     */
 49    public final String UNAME = "locale";
 50    private PropertyStore oldvalues;
 51    private static ControlPanel_Locale ident;
 52
 53    public ControlPanel_Locale() {
 54        initComponents();
 55        locales.setModel(getLocales());
 56        locales.setSelectedIndex(MPComboBoxModelItem.getItemID(Locale.getDefault().toString(),
 57                locales.getModel()));
 58        setLanguageSelection();
 59        isocode.set_ValueClass(java.lang.Integer.class);
 60        countryselect.setModel(LanguageManager.getCountriesAsComboBoxModel());
 61        setVisible(true);
 62    }
 63
 64    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 65    private void initComponents() {
 66
 67        jPanel5 = new javax.swing.JPanel();
 68        jLabel8 = new javax.swing.JLabel();
 69        jLabel9 = new javax.swing.JLabel();
 70        labeledTextChooser2 = new mpv5.ui.beans.LabeledTextChooser();
 71        jButton4 = new javax.swing.JButton();
 72        jPanel1 = new javax.swing.JPanel();
 73        isocode = new mpv5.ui.beans.LabeledTextField();
 74        countryname = new mpv5.ui.beans.LabeledTextField();
 75        jButton7 = new javax.swing.JButton();
 76        jPanel7 = new javax.swing.JPanel();
 77        jButton8 = new javax.swing.JButton();
 78        countryselect = new mpv5.ui.beans.LabeledCombobox();
 79        jPanel4 = new javax.swing.JPanel();
 80        jLabel5 = new javax.swing.JLabel();
 81        jLabel6 = new javax.swing.JLabel();
 82        labeledTextChooser1 = new mpv5.ui.beans.LabeledTextChooser();
 83        jButton3 = new javax.swing.JButton();
 84        langName = new mpv5.ui.beans.LabeledTextField();
 85        jLabel7 = new javax.swing.JLabel();
 86        jPanel3 = new javax.swing.JPanel();
 87        jLabel3 = new javax.swing.JLabel();
 88        jLabel4 = new javax.swing.JLabel();
 89        languages = new javax.swing.JComboBox();
 90        jButton5 = new javax.swing.JButton();
 91        jButton6 = new javax.swing.JButton();
 92        jPanel2 = new javax.swing.JPanel();
 93        jLabel2 = new javax.swing.JLabel();
 94        jLabel1 = new javax.swing.JLabel();
 95        locales = new javax.swing.JComboBox();
 96        jPanel6 = new javax.swing.JPanel();
 97        jButton2 = new javax.swing.JButton();
 98        jButton1 = new javax.swing.JButton();
 99
100        setBackground(new java.awt.Color(255, 255, 255));
101        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
102        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Locale.border.title"))); // NOI18N
103        setName("Form"); // NOI18N
104        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
105
106        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
107        jPanel5.setName("jPanel5"); // NOI18N
108
109        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
110        jLabel8.setText(bundle.getString("ControlPanel_Locale.jLabel8.text")); // NOI18N
111        jLabel8.setName("jLabel8"); // NOI18N
112
113        jLabel9.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
114        jLabel9.setText(bundle.getString("ControlPanel_Locale.jLabel9.text")); // NOI18N
115        jLabel9.setName("jLabel9"); // NOI18N
116
117        labeledTextChooser2.set_Label(bundle.getString("ControlPanel_Locale.labeledTextChooser2._Label")); // NOI18N
118        labeledTextChooser2.set_LabelFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
119        labeledTextChooser2.setName("labeledTextChooser2"); // NOI18N
120
121        jButton4.setText(bundle.getString("ControlPanel_Locale.jButton4.text")); // NOI18N
122        jButton4.setName("jButton4"); // NOI18N
123        jButton4.addActionListener(new java.awt.event.ActionListener() {
124            public void actionPerformed(java.awt.event.ActionEvent evt) {
125                jButton4ActionPerformed(evt);
126            }
127        });
128
129        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Locale.jPanel1.border.title"))); // NOI18N
130        jPanel1.setName(bundle.getString("ControlPanel_Locale.jPanel1.name")); // NOI18N
131
132        isocode.set_Label(bundle.getString("ControlPanel_Locale.isocode._Label")); // NOI18N
133        isocode.setName(bundle.getString("ControlPanel_Locale.isocode.name")); // NOI18N
134
135        countryname.set_Label(bundle.getString("ControlPanel_Locale.countryname._Label")); // NOI18N
136        countryname.setName(bundle.getString("ControlPanel_Locale.countryname.name")); // NOI18N
137
138        jButton7.setText(bundle.getString("ControlPanel_Locale.jButton7.text")); // NOI18N
139        jButton7.setName(bundle.getString("ControlPanel_Locale.jButton7.name")); // NOI18N
140        jButton7.addActionListener(new java.awt.event.ActionListener() {
141            public void actionPerformed(java.awt.event.ActionEvent evt) {
142                jButton7ActionPerformed(evt);
143            }
144        });
145
146        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
147        jPanel1.setLayout(jPanel1Layout);
148        jPanel1Layout.setHorizontalGroup(
149            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150            .addGroup(jPanel1Layout.createSequentialGroup()
151                .addComponent(isocode, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
152                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
153                .addComponent(countryname, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
154                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
155                .addComponent(jButton7)
156                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
157        );
158        jPanel1Layout.setVerticalGroup(
159            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160            .addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING)
161            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162                .addComponent(isocode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
163                .addComponent(countryname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
164        );
165
166        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Locale.jPanel7.border.title"))); // NOI18N
167        jPanel7.setName(bundle.getString("ControlPanel_Locale.jPanel7.name")); // NOI18N
168
169        jButton8.setText(bundle.getString("ControlPanel_Locale.jButton8.text")); // NOI18N
170        jButton8.setName(bundle.getString("ControlPanel_Locale.jButton8.name")); // NOI18N
171        jButton8.addActionListener(new java.awt.event.ActionListener() {
172            public void actionPerformed(java.awt.event.ActionEvent evt) {
173                jButton8ActionPerformed(evt);
174            }
175        });
176
177        countryselect.set_Label(bundle.getString("ControlPanel_Locale.countryselect._Label")); // NOI18N
178        countryselect.setName(bundle.getString("ControlPanel_Locale.countryselect.name")); // NOI18N
179
180        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
181        jPanel7.setLayout(jPanel7Layout);
182        jPanel7Layout.setHorizontalGroup(
183            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184            .addGroup(jPanel7Layout.createSequentialGroup()
185                .addComponent(countryselect, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)
186                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
187                .addComponent(jButton8)
188                .addContainerGap(28, Short.MAX_VALUE))
189        );
190        jPanel7Layout.setVerticalGroup(
191            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
193                .addComponent(jButton8)
194                .addComponent(countryselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
195        );
196
197        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
198        jPanel5.setLayout(jPanel5Layout);
199        jPanel5Layout.setHorizontalGroup(
200            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201            .addGroup(jPanel5Layout.createSequentialGroup()
202                .addContainerGap()
203                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
205                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
206                    .addGroup(jPanel5Layout.createSequentialGroup()
207                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
208                            .addGroup(jPanel5Layout.createSequentialGroup()
209                                .addComponent(labeledTextChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
210                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211                                .addComponent(jButton4))
212                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
213                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
214                        .addGap(0, 0, Short.MAX_VALUE)))
215                .addContainerGap())
216        );
217        jPanel5Layout.setVerticalGroup(
218            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219            .addGroup(jPanel5Layout.createSequentialGroup()
220                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
221                .addComponent(jLabel8)
222                .addGap(7, 7, 7)
223                .addComponent(jLabel9)
224                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
226                    .addComponent(labeledTextChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
227                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
228                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
229                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
230                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
231                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
232        );
233
234        add(jPanel5);
235
236        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
237        jPanel4.setName("jPanel4"); // NOI18N
238
239        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
240        jLabel5.setText(bundle.getString("ControlPanel_Locale.jLabel5.text")); // NOI18N
241        jLabel5.setName("jLabel5"); // NOI18N
242
243        jLabel6.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
244        jLabel6.setText(bundle.getString("ControlPanel_Locale.jLabel6.text")); // NOI18N
245        jLabel6.setName("jLabel6"); // NOI18N
246
247        labeledTextChooser1.set_Label(bundle.getString("ControlPanel_Locale.labeledTextChooser1._Label")); // NOI18N
248        labeledTextChooser1.set_LabelFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
249        labeledTextChooser1.setName("labeledTextChooser1"); // NOI18N
250
251        jButton3.setText(bundle.getString("ControlPanel_Locale.jButton3.text")); // NOI18N
252        jButton3.setName("jButton3"); // NOI18N
253        jButton3.addActionListener(new java.awt.event.ActionListener() {
254            public void actionPerformed(java.awt.event.ActionEvent evt) {
255                jButton3ActionPerformed(evt);
256            }
257        });
258
259        langName.set_Label(bundle.getString("ControlPanel_Locale.langName._Label")); // NOI18N
260        langName.set_LabelFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
261        langName.setName("langName"); // NOI18N
262
263        jLabel7.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
264        jLabel7.setText(bundle.getString("ControlPanel_Locale.jLabel7.text")); // NOI18N
265        jLabel7.setName("jLabel7"); // NOI18N
266
267        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
268        jPanel4.setLayout(jPanel4Layout);
269        jPanel4Layout.setHorizontalGroup(
270            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
272                .addContainerGap()
273                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
274                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
275                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
276                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
277                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278                            .addComponent(langName, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
279                            .addGroup(jPanel4Layout.createSequentialGroup()
280                                .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
281                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282                                .addComponent(jButton3)))
283                        .addGap(0, 0, Short.MAX_VALUE))
284                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
285                .addContainerGap())
286        );
287        jPanel4Layout.setVerticalGroup(
288            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
290                .addContainerGap()
291                .addComponent(jLabel5)
292                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293                .addComponent(jLabel7)
294                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
295                .addComponent(langName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
296                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
297                .addComponent(jLabel6)
298                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
299                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
300                    .addComponent(jButton3)
301                    .addGroup(jPanel4Layout.createSequentialGroup()
302                        .addGap(1, 1, 1)
303                        .addComponent(labeledTextChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
304                .addContainerGap())
305        );
306
307        add(jPanel4);
308
309        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
310        jPanel3.setName("jPanel3"); // NOI18N
311
312        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
313        jLabel3.setText(bundle.getString("ControlPanel_Locale.jLabel3.text")); // NOI18N
314        jLabel3.setName("jLabel3"); // NOI18N
315
316        jLabel4.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
317        jLabel4.setText(bundle.getString("ControlPanel_Locale.jLabel4.text")); // NOI18N
318        jLabel4.setName("jLabel4"); // NOI18N
319
320        languages.setName("languages"); // NOI18N
321
322        jButton5.setText(bundle.getString("ControlPanel_Locale.jButton5.text")); // NOI18N
323        jButton5.setName("jButton5"); // NOI18N
324        jButton5.addActionListener(new java.awt.event.ActionListener() {
325            public void actionPerformed(java.awt.event.ActionEvent evt) {
326                jButton5ActionPerformed(evt);
327            }
328        });
329
330        jButton6.setText(bundle.getString("ControlPanel_Locale.jButton6.text")); // NOI18N
331        jButton6.setName("jButton6"); // NOI18N
332        jButton6.addActionListener(new java.awt.event.ActionListener() {
333            public void actionPerformed(java.awt.event.ActionEvent evt) {
334                jButton6ActionPerformed(evt);
335            }
336        });
337
338        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
339        jPanel3.setLayout(jPanel3Layout);
340        jPanel3Layout.setHorizontalGroup(
341            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342            .addGroup(jPanel3Layout.createSequentialGroup()
343                .addContainerGap()
344                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
345                    .addGroup(jPanel3Layout.createSequentialGroup()
346                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347                            .addComponent(languages, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
348                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
349                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
351                            .addComponent(jButton6)
352                            .addComponent(jButton5)))
353                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
354                .addContainerGap(27, Short.MAX_VALUE))
355        );
356        jPanel3Layout.setVerticalGroup(
357            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
358            .addGroup(jPanel3Layout.createSequentialGroup()
359                .addContainerGap()
360                .addComponent(jLabel3)
361                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
362                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
363                    .addComponent(jLabel4)
364                    .addComponent(jButton6))
365                .addGap(18, 18, 18)
366                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
367                    .addComponent(languages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
368                    .addComponent(jButton5))
369                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
370        );
371
372        add(jPanel3);
373
374        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
375        jPanel2.setName("jPanel2"); // NOI18N
376
377        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
378        jLabel2.setText(bundle.getString("ControlPanel_Locale.jLabel2.text")); // NOI18N
379        jLabel2.setName("jLabel2"); // NOI18N
380
381        jLabel1.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
382        jLabel1.setText(bundle.getString("ControlPanel_Locale.jLabel1.text")); // NOI18N
383        jLabel1.setName("jLabel1"); // NOI18N
384
385        locales.setName("locales"); // NOI18N
386
387        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
388        jPanel2.setLayout(jPanel2Layout);
389        jPanel2Layout.setHorizontalGroup(
390            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
391            .addGroup(jPanel2Layout.createSequentialGroup()
392                .addContainerGap()
393                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
394                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
395                    .addComponent(jLabel2)
396                    .addComponent(locales, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
397                .addContainerGap())
398        );
399        jPanel2Layout.setVerticalGroup(
400            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401            .addGroup(jPanel2Layout.createSequentialGroup()
402                .addContainerGap()
403                .addComponent(jLabel2)
404                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
405                .addComponent(jLabel1)
406                .addGap(18, 18, 18)
407                .addComponent(locales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
408                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
409        );
410
411        add(jPanel2);
412
413        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
414        jPanel6.setName("jPanel6"); // NOI18N
415        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
416
417        jButton2.setText(bundle.getString("ControlPanel_Locale.jButton2.text")); // NOI18N
418        jButton2.setName("jButton2"); // NOI18N
419        jButton2.addActionListener(new java.awt.event.ActionListener() {
420            public void actionPerformed(java.awt.event.ActionEvent evt) {
421                jButton2ActionPerformed(evt);
422            }
423        });
424        jPanel6.add(jButton2);
425
426        jButton1.setText(bundle.getString("ControlPanel_Locale.jButton1.text")); // NOI18N
427        jButton1.setName("jButton1"); // NOI18N
428        jButton1.addActionListener(new java.awt.event.ActionListener() {
429            public void actionPerformed(java.awt.event.ActionEvent evt) {
430                jButton1ActionPerformed(evt);
431            }
432        });
433        jPanel6.add(jButton1);
434
435        add(jPanel6);
436    }// </editor-fold>//GEN-END:initComponents
437
438    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
439        setSettings();
440    }//GEN-LAST:event_jButton2ActionPerformed
441
442    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
443        setSettings();
444        mpv5.db.objects.User.getCurrentUser().save();
445        cleanup();
446//        mpv5.YabsViewProxy.instance().resetTables();
447        Popup.notice(Messages.RESTART_REQUIRED);
448    }//GEN-LAST:event_jButton1ActionPerformed
449
450    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
451
452        if (QueryHandler.instanceOf().clone(Context.getLanguage()).checkUniqueness("longname", new JTextField[]{langName.getTextField()})) {
453            if (!langName.hasText()) {
454                langName.setText(new File(labeledTextChooser1.get_Text(false)).getName());
455            }
456            Runnable runnable = new Runnable() {
457
458                @Override
459                public void run() {
460                    try {
461                        mpv5.YabsViewProxy.instance().setWaiting(true);
462                        LanguageManager.importLanguage(langName.get_Text(), new File(labeledTextChooser1.get_Text(true)));
463                        setLanguageSelection();
464                    } catch (Exception e) {
465                        Log.Debug(e);
466                    } finally {
467                        cleanup();
468
469                        mpv5.YabsViewProxy.instance().setWaiting(false);
470                    }
471                }
472            };
473            new Thread(runnable).start();
474        }
475    }//GEN-LAST:event_jButton3ActionPerformed
476
477    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
478        if (labeledTextChooser2.hasText()) {
479            LanguageManager.importCountries(new File(labeledTextChooser2.get_Text(true)));
480            LanguageManager.COUNTRIES = null;
481            countryselect.setModel(LanguageManager.getCountriesAsComboBoxModel());
482        }
483    }//GEN-LAST:event_jButton4ActionPerformed
484
485    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
486        if (languages.getSelectedIndex() == -1) {
487            Popup.warn(Messages.LANG_EMPTY.toString());
488        } else {
489            String languagestring = ((MPComboBoxModelItem) languages.getSelectedItem()).getId();
490            try {
491                int rows = QueryHandler.instanceOf().
492                        clone(Context.getUser()).
493                        selectCount("LANGUAGE=",
494                        "'" + languagestring + "'");
495                if (rows != 0) {
496                    Popup.notice(Messages.LANG_USED.toString());
497                } else {
498                    try {
499                        LanguageManager.removeLanguage(languagestring);
500                        setLanguageSelection();
501                    } catch (NodataFoundException ex) {
502                        Log.Debug(ex);
503                    }
504
505                }
506            } catch (SQLException ex) {
507                Log.Debug(ex);
508            }
509        }
510    }//GEN-LAST:event_jButton5ActionPerformed
511
512    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
513        File f = null;
514        String key;
515        String lang_long = "export";
516        if (languages.getSelectedIndex() == -1) {
517            Popup.warn(Messages.LANG_EMPTY.toString());
518        } else {
519            try {
520                lang_long = ((MPComboBoxModelItem) languages.getSelectedItem()).toString();
521                f = FileDirectoryHandler.getTempFile(lang_long + "_" + Constants.VERSION, "yabs");
522                FileReaderWriter rw = new FileReaderWriter(f, "utf-8");
523
524                String lang = ((MPComboBoxModelItem) languages.getSelectedItem()).getId();
525                ResourceBundle bundle = LanguageManager.getBundle(lang);
526                Enumeration<String> keys = bundle.getKeys();
527                List<String> list = Collections.list(keys);
528                Collections.sort(list);
529                String[] data = new String[list.size()];
530                for (int i = 0; i < list.size(); i++) {
531                    key = list.get(i);
532                    data[i] = key + "=" + bundle.getString(key);
533                }
534                rw.write0WCharset(data);
535                DialogForFile df = new DialogForFile(JFileChooser.FILES_AND_DIRECTORIES);
536                df.saveFile(f);
537
538            } catch (Exception ex) {
539                Log.Debug(this, ex.getLocalizedMessage());
540            }
541        }
542    }//GEN-LAST:event_jButton6ActionPerformed
543
544    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
545        if (!isocode.hasText()) {
546            TextFieldUtils.blinkerRed(isocode);
547        }
548        if (!countryname.hasText()) {
549            TextFieldUtils.blinkerRed(countryname);
550        } else {
551            try {
552                QueryData t = new QueryData();
553                t.add("cname", countryname.getText());
554                t.add("iso", isocode.getValue(0));
555                t.add("groupsids", User.getCurrentUser().__getGroupsids());
556                QueryHandler.instanceOf().clone(Context.getCountries()).insert(t, Messages.DONE.toString());
557                Notificator.raiseNotification(Messages.DONE);
558                LanguageManager.COUNTRIES = null;
559                countryselect.setModel(LanguageManager.getCountriesAsComboBoxModel());
560            } catch (Exception exception) {
561                Log.Debug(LanguageManager.class, exception.getMessage());
562                Notificator.raiseNotification("Isocode must be unique!");
563            }
564        }
565    }//GEN-LAST:event_jButton7ActionPerformed
566
567    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
568        String country_ = countryselect.getSelectedItem().getId();
569        QueryCriteria2 q = new QueryCriteria2();
570        q.and(new QueryParameter(Context.getCountries(), "iso", Integer.valueOf(country_), QueryParameter.EQUALS));
571        QueryHandler.instanceOf().clone(Context.getCountries()).delete(q);
572        LanguageManager.COUNTRIES = null;
573        countryselect.setModel(LanguageManager.getCountriesAsComboBoxModel());
574        Notificator.raiseNotification(Messages.DONE);
575    }//GEN-LAST:event_jButton8ActionPerformed
576
577    public void setValues(PropertyStore values) {
578        oldvalues = values;
579    }
580
581    public String getUname() {
582        return UNAME;
583    }
584
585    public void reset() {
586        setValues(oldvalues);
587    }
588    // Variables declaration - do not modify//GEN-BEGIN:variables
589    private mpv5.ui.beans.LabeledTextField countryname;
590    private mpv5.ui.beans.LabeledCombobox countryselect;
591    private mpv5.ui.beans.LabeledTextField isocode;
592    private javax.swing.JButton jButton1;
593    private javax.swing.JButton jButton2;
594    private javax.swing.JButton jButton3;
595    private javax.swing.JButton jButton4;
596    private javax.swing.JButton jButton5;
597    private javax.swing.JButton jButton6;
598    private javax.swing.JButton jButton7;
599    private javax.swing.JButton jButton8;
600    private javax.swing.JLabel jLabel1;
601    private javax.swing.JLabel jLabel2;
602    private javax.swing.JLabel jLabel3;
603    private javax.swing.JLabel jLabel4;
604    private javax.swing.JLabel jLabel5;
605    private javax.swing.JLabel jLabel6;
606    private javax.swing.JLabel jLabel7;
607    private javax.swing.JLabel jLabel8;
608    private javax.swing.JLabel jLabel9;
609    private javax.swing.JPanel jPanel1;
610    private javax.swing.JPanel jPanel2;
611    private javax.swing.JPanel jPanel3;
612    private javax.swing.JPanel jPanel4;
613    private javax.swing.JPanel jPanel5;
614    private javax.swing.JPanel jPanel6;
615    private javax.swing.JPanel jPanel7;
616    private mpv5.ui.beans.LabeledTextChooser labeledTextChooser1;
617    private mpv5.ui.beans.LabeledTextChooser labeledTextChooser2;
618    private mpv5.ui.beans.LabeledTextField langName;
619    private javax.swing.JComboBox languages;
620    private javax.swing.JComboBox locales;
621    // End of variables declaration//GEN-END:variables
622
623    // End of variables declaration
624    private void setLanguageSelection() {
625        languages.setModel(getLanguages());
626        languages.setSelectedIndex(MPComboBoxModelItem.getItemID(mpv5.db.objects.User.getCurrentUser().__getLanguage(),
627                languages.getModel()));
628    }
629    // End of variables declaration
630
631    private void setSettings() {
632
633        String localestring = ((MPComboBoxModelItem) locales.getSelectedItem()).getId();
634        String languagestring = ((MPComboBoxModelItem) languages.getSelectedItem()).getId();
635        mpv5.db.objects.User.getCurrentUser().setLocale(localestring);
636        mpv5.db.objects.User.getCurrentUser().setLanguage(languagestring);
637        Locale.setDefault(TypeConversion.stringToLocale(localestring));
638
639    }
640
641    private DefaultComboBoxModel getLocales() {
642        return LanguageManager.getLocalesAsComboBoxModel();
643    }
644
645    private ComboBoxModel getLanguages() {
646        return LanguageManager.getLanguagesAsComboBoxModel();
647    }
648
649    private ComboBoxModel getCountries() {
650        return LanguageManager.getCountriesAsComboBoxModel();
651    }
652
653    @Override
654    public java.awt.Component getAndRemoveActionPanel() {
655        this.remove(jPanel6);
656        validate();
657        return jPanel6;
658    }
659
660    private void cleanup() {
661        try {
662            for (File f : new File(FileDirectoryHandler.getTempDir2()).listFiles()) {
663                if (f.getName().endsWith(".properties")) {
664                    f.deleteOnExit();
665                }
666            }
667        } catch (Exception ex) {
668        }
669    }
670}