PageRenderTime 116ms CodeModel.GetById 30ms app.highlight 67ms RepoModel.GetById 14ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 418 lines | 346 code | 62 blank | 10 comment | 2 complexity | 8c19d5b4331e02e97af3ce500a978e2b MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Component;
  4import mpv5.data.PropertyStore;
  5import mpv5.db.common.QueryHandler;
  6import mpv5.globals.LocalSettings;
  7import mpv5.logging.Log;
  8import mpv5.ui.dialogs.ControlApplet;
  9import mpv5.ui.panels.MPControlPanel;
 10import mpv5.utils.text.TypeConversion;
 11import mpv5.utils.ui.PanelUtils;
 12
 13/**
 14 *
 15 * 
 16 */
 17public class ControlPanel_Local extends javax.swing.JPanel implements ControlApplet {
 18
 19    private static final long serialVersionUID = 1L;
 20    /**
 21     * This unique name identifies this control applet
 22     */
 23    public final String UNAME = "localsettings";
 24    private PropertyStore oldvalues;
 25
 26    public ControlPanel_Local() {
 27        initComponents();
 28        setVisible(true);
 29        setValues(LocalSettings.getPropertyStore());
 30    }
 31
 32    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 33    private void initComponents() {
 34
 35        jPanel2 = new javax.swing.JPanel();
 36        jLabel1 = new javax.swing.JLabel();
 37        jLabel2 = new javax.swing.JLabel();
 38        proxy = new javax.swing.JTextField();
 39        port = new javax.swing.JTextField();
 40        jLabel3 = new javax.swing.JLabel();
 41        auth = new javax.swing.JCheckBox();
 42        authpanel = new javax.swing.JPanel();
 43        jLabel5 = new javax.swing.JLabel();
 44        user = new javax.swing.JTextField();
 45        jLabel4 = new javax.swing.JLabel();
 46        password = new javax.swing.JPasswordField();
 47        jPanel3 = new javax.swing.JPanel();
 48        printdev = new javax.swing.JCheckBox();
 49        jPanel4 = new javax.swing.JPanel();
 50        rowlimit = new mpv5.ui.beans.LabeledTextField();
 51        autolock = new javax.swing.JCheckBox();
 52        escape = new javax.swing.JCheckBox();
 53        jPanel5 = new javax.swing.JPanel();
 54        backupbasedir = new mpv5.ui.beans.LabeledTextChooser();
 55        savebasedir = new mpv5.ui.beans.LabeledTextChooser();
 56        jPanel1 = new javax.swing.JPanel();
 57        jButton1 = new javax.swing.JButton();
 58        jButton2 = new javax.swing.JButton();
 59        jButton3 = new javax.swing.JButton();
 60        jButton4 = new javax.swing.JButton();
 61
 62        setBackground(new java.awt.Color(255, 255, 255));
 63        setName("Form"); // NOI18N
 64        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
 65
 66        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N // NOI18N
 67        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Local.jPanel2.border.title"))); // NOI18N
 68        jPanel2.setName("jPanel2"); // NOI18N
 69
 70        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
 71        jLabel1.setText(bundle.getString("ControlPanel_Local.jLabel1.text")); // NOI18N
 72        jLabel1.setName("jLabel1"); // NOI18N
 73
 74        jLabel2.setText(bundle.getString("ControlPanel_Local.jLabel2.text")); // NOI18N
 75        jLabel2.setName("jLabel2"); // NOI18N
 76
 77        proxy.setName("proxy"); // NOI18N
 78
 79        port.setName("port"); // NOI18N
 80
 81        jLabel3.setText(bundle.getString("ControlPanel_Local.jLabel3.text")); // NOI18N
 82        jLabel3.setName("jLabel3"); // NOI18N
 83
 84        auth.setText(bundle.getString("ControlPanel_Local.auth.text")); // NOI18N
 85        auth.setName("auth"); // NOI18N
 86        auth.addItemListener(new java.awt.event.ItemListener() {
 87            public void itemStateChanged(java.awt.event.ItemEvent evt) {
 88                authItemStateChanged(evt);
 89            }
 90        });
 91
 92        authpanel.setBackground(new java.awt.Color(255, 255, 255));
 93        authpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 94        authpanel.setName("authpanel"); // NOI18N
 95
 96        jLabel5.setText(bundle.getString("ControlPanel_Local.jLabel5.text")); // NOI18N
 97        jLabel5.setEnabled(false);
 98        jLabel5.setName("jLabel5"); // NOI18N
 99
100        user.setEnabled(false);
101        user.setName("user"); // NOI18N
102
103        jLabel4.setText(bundle.getString("ControlPanel_Local.jLabel4.text")); // NOI18N
104        jLabel4.setEnabled(false);
105        jLabel4.setName("jLabel4"); // NOI18N
106
107        password.setText(bundle.getString("ControlPanel_Local.password.text")); // NOI18N
108        password.setEnabled(false);
109        password.setName("password"); // NOI18N
110
111        javax.swing.GroupLayout authpanelLayout = new javax.swing.GroupLayout(authpanel);
112        authpanel.setLayout(authpanelLayout);
113        authpanelLayout.setHorizontalGroup(
114            authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
115            .addGroup(authpanelLayout.createSequentialGroup()
116                .addContainerGap()
117                .addGroup(authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118                    .addComponent(jLabel4)
119                    .addComponent(jLabel5))
120                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
121                .addGroup(authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122                    .addComponent(user, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
123                    .addComponent(password, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE))
124                .addContainerGap())
125        );
126        authpanelLayout.setVerticalGroup(
127            authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128            .addGroup(authpanelLayout.createSequentialGroup()
129                .addContainerGap()
130                .addGroup(authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
131                    .addComponent(jLabel5)
132                    .addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
133                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
134                .addGroup(authpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
135                    .addComponent(jLabel4)
136                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
137                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
138        );
139
140        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
141        jPanel2.setLayout(jPanel2Layout);
142        jPanel2Layout.setHorizontalGroup(
143            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144            .addGroup(jPanel2Layout.createSequentialGroup()
145                .addContainerGap()
146                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147                    .addComponent(authpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
148                    .addComponent(auth)
149                    .addComponent(jLabel1)
150                    .addGroup(jPanel2Layout.createSequentialGroup()
151                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152                            .addComponent(jLabel2)
153                            .addComponent(jLabel3))
154                        .addGap(18, 18, 18)
155                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
156                            .addComponent(proxy)
157                            .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))))
158                .addContainerGap(78, Short.MAX_VALUE))
159        );
160        jPanel2Layout.setVerticalGroup(
161            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
163                .addComponent(jLabel1)
164                .addGap(12, 12, 12)
165                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167                        .addComponent(jLabel2)
168                        .addComponent(proxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
169                    .addGroup(jPanel2Layout.createSequentialGroup()
170                        .addGap(26, 26, 26)
171                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
172                            .addComponent(jLabel3)
173                            .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
174                .addGap(13, 13, 13)
175                .addComponent(auth)
176                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
177                .addComponent(authpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
178        );
179
180        add(jPanel2);
181
182        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Local.jPanel3.border.title"))); // NOI18N
183        jPanel3.setName("jPanel3"); // NOI18N
184
185        printdev.setText(bundle.getString("ControlPanel_Local.printdev.text")); // NOI18N
186        printdev.setName("printdev"); // NOI18N
187
188        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
189        jPanel3.setLayout(jPanel3Layout);
190        jPanel3Layout.setHorizontalGroup(
191            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
193                .addComponent(printdev, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
194                .addContainerGap(84, Short.MAX_VALUE))
195        );
196        jPanel3Layout.setVerticalGroup(
197            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198            .addGroup(jPanel3Layout.createSequentialGroup()
199                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
200                .addComponent(printdev))
201        );
202
203        add(jPanel3);
204
205        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Local.jPanel4.border.title"))); // NOI18N
206        jPanel4.setName("jPanel4"); // NOI18N
207
208        rowlimit.set_Label(bundle.getString("ControlPanel_Local.rowlimit._Label")); // NOI18N
209        rowlimit.setEnabled(false);
210        rowlimit.setName("rowlimit"); // NOI18N
211
212        autolock.setText(bundle.getString("ControlPanel_Local.autolock.text")); // NOI18N
213        autolock.setName("autolock"); // NOI18N
214
215        escape.setText(bundle.getString("ControlPanel_Local.escape.text")); // NOI18N
216        escape.setName("escape"); // NOI18N
217
218        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
219        jPanel4.setLayout(jPanel4Layout);
220        jPanel4Layout.setHorizontalGroup(
221            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
222            .addGroup(jPanel4Layout.createSequentialGroup()
223                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224                    .addGroup(jPanel4Layout.createSequentialGroup()
225                        .addContainerGap()
226                        .addComponent(rowlimit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
227                    .addComponent(autolock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
228                    .addComponent(escape, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))
229                .addContainerGap())
230        );
231        jPanel4Layout.setVerticalGroup(
232            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233            .addGroup(jPanel4Layout.createSequentialGroup()
234                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
235                .addComponent(rowlimit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
236                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
237                .addComponent(autolock)
238                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239                .addComponent(escape)
240                .addContainerGap())
241        );
242
243        add(jPanel4);
244
245        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Local.jPanel5.border.title"))); // NOI18N
246        jPanel5.setName("jPanel5"); // NOI18N
247        jPanel5.setLayout(new java.awt.BorderLayout());
248
249        backupbasedir.set_Label(bundle.getString("ControlPanel_Local.backupbasedir._Label")); // NOI18N
250        backupbasedir.setName("backupbasedir"); // NOI18N
251        jPanel5.add(backupbasedir, java.awt.BorderLayout.PAGE_END);
252
253        savebasedir.set_Label(bundle.getString("ControlPanel_Local.savebasedir._Label")); // NOI18N
254        savebasedir.setName("savebasedir"); // NOI18N
255        jPanel5.add(savebasedir, java.awt.BorderLayout.PAGE_START);
256
257        add(jPanel5);
258
259        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
260        jPanel1.setName("jPanel1"); // NOI18N
261        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
262
263        jButton1.setText(bundle.getString("ControlPanel_Local.jButton1.text")); // NOI18N
264        jButton1.setName("jButton1"); // NOI18N
265        jButton1.addActionListener(new java.awt.event.ActionListener() {
266            public void actionPerformed(java.awt.event.ActionEvent evt) {
267                jButton1ActionPerformed(evt);
268            }
269        });
270        jPanel1.add(jButton1);
271
272        jButton2.setText(bundle.getString("ControlPanel_Local.jButton2.text")); // NOI18N
273        jButton2.setName("jButton2"); // NOI18N
274        jButton2.addActionListener(new java.awt.event.ActionListener() {
275            public void actionPerformed(java.awt.event.ActionEvent evt) {
276                jButton2ActionPerformed(evt);
277            }
278        });
279        jPanel1.add(jButton2);
280
281        jButton3.setText(bundle.getString("ControlPanel_Local.jButton3.text")); // NOI18N
282        jButton3.setName("jButton3"); // NOI18N
283        jButton3.addActionListener(new java.awt.event.ActionListener() {
284            public void actionPerformed(java.awt.event.ActionEvent evt) {
285                jButton3ActionPerformed(evt);
286            }
287        });
288        jPanel1.add(jButton3);
289
290        jButton4.setText(bundle.getString("ControlPanel_Local.jButton4.text")); // NOI18N
291        jButton4.setName("jButton4"); // NOI18N
292        jButton4.addActionListener(new java.awt.event.ActionListener() {
293            public void actionPerformed(java.awt.event.ActionEvent evt) {
294                jButton4ActionPerformed(evt);
295            }
296        });
297        jPanel1.add(jButton4);
298
299        add(jPanel1);
300    }// </editor-fold>//GEN-END:initComponents
301
302    private void authItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_authItemStateChanged
303        PanelUtils.enableSubComponents(authpanel, auth.isSelected());
304}//GEN-LAST:event_authItemStateChanged
305
306    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
307
308        setSettings();
309    }//GEN-LAST:event_jButton2ActionPerformed
310
311    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
312
313        setSettings();
314        LocalSettings.save();
315    }//GEN-LAST:event_jButton1ActionPerformed
316
317    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
318        reset();
319    }//GEN-LAST:event_jButton3ActionPerformed
320
321    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
322
323        ControlPanel_AdvancedLocalProperties c = new ControlPanel_AdvancedLocalProperties();
324        MPControlPanel.instanceOf().openDetails(c);
325    }//GEN-LAST:event_jButton4ActionPerformed
326
327    @Override
328    public final void setValues(PropertyStore values) {
329        oldvalues = values;
330        proxy.setText(values.getProperty("proxy"));
331        port.setText(values.getProperty("proxy"));
332        auth.setSelected(TypeConversion.stringToBoolean(values.getProperty("useproxy")));
333        user.setText(values.getProperty("username"));
334        password.setText(values.getProperty("password"));
335        printdev.setSelected(TypeConversion.stringToBoolean(values.getProperty("devappprint")));
336        rowlimit.set_Text(values.getProperty(LocalSettings.DBROW_LIMIT));
337        autolock.setSelected(TypeConversion.stringToBoolean(values.getProperty(LocalSettings.DBAUTOLOCK)));
338        escape.setSelected(TypeConversion.stringToBoolean(values.getProperty(LocalSettings.DBESCAPE)));
339
340        savebasedir.set_Text(values.getProperty(LocalSettings.BASE_DIR));
341        backupbasedir.set_Text(values.getProperty(LocalSettings.BACKUP_DIR));
342    }
343
344    @Override
345    public String getUname() {
346        return UNAME;
347    }
348
349    @Override
350    public void reset() {
351        setValues(oldvalues);
352    }
353    // Variables declaration - do not modify//GEN-BEGIN:variables
354    private javax.swing.JCheckBox auth;
355    private javax.swing.JPanel authpanel;
356    private javax.swing.JCheckBox autolock;
357    private mpv5.ui.beans.LabeledTextChooser backupbasedir;
358    private javax.swing.JCheckBox escape;
359    private javax.swing.JButton jButton1;
360    private javax.swing.JButton jButton2;
361    private javax.swing.JButton jButton3;
362    private javax.swing.JButton jButton4;
363    private javax.swing.JLabel jLabel1;
364    private javax.swing.JLabel jLabel2;
365    private javax.swing.JLabel jLabel3;
366    private javax.swing.JLabel jLabel4;
367    private javax.swing.JLabel jLabel5;
368    private javax.swing.JPanel jPanel1;
369    private javax.swing.JPanel jPanel2;
370    private javax.swing.JPanel jPanel3;
371    private javax.swing.JPanel jPanel4;
372    private javax.swing.JPanel jPanel5;
373    private javax.swing.JPasswordField password;
374    private javax.swing.JTextField port;
375    private javax.swing.JCheckBox printdev;
376    private javax.swing.JTextField proxy;
377    private mpv5.ui.beans.LabeledTextField rowlimit;
378    private mpv5.ui.beans.LabeledTextChooser savebasedir;
379    private javax.swing.JTextField user;
380    // End of variables declaration//GEN-END:variables
381
382    private void setSettings() {
383        LocalSettings.setProperty(LocalSettings.PROXYHOST, proxy.getText());
384        LocalSettings.setProperty(LocalSettings.PROXYPORT, port.getText());
385        LocalSettings.setProperty(LocalSettings.DBESCAPE, TypeConversion.booleanToString(escape.isSelected()));
386
387        if (auth.isSelected()) {
388            LocalSettings.setProperty(LocalSettings.PROXYUSE, TypeConversion.booleanToString(true));
389            LocalSettings.setProperty(LocalSettings.PROXYUSER, user.getText());
390            LocalSettings.setProperty(LocalSettings.PROXYPASSWORD, new String(password.getPassword()));
391        }
392
393        LocalSettings.setProperty(LocalSettings.PRINT_DEVAPP, TypeConversion.booleanToString(printdev.isSelected()));
394
395        try {
396            if (Integer.valueOf(rowlimit.get_Text()).intValue() >= 0) {
397                LocalSettings.setProperty(LocalSettings.DBROW_LIMIT, Integer.valueOf(rowlimit.get_Text()).toString());
398                QueryHandler.setRowLimit(Integer.valueOf(rowlimit.get_Text()).intValue());
399            }
400        } catch (NumberFormatException numberFormatException) {
401            Log.Debug(numberFormatException);
402        }
403
404        LocalSettings.setProperty(LocalSettings.DBAUTOLOCK, TypeConversion.booleanToString(autolock.isSelected()));
405
406        LocalSettings.setProperty(LocalSettings.BASE_DIR, savebasedir.get_Text(true));
407         LocalSettings.setProperty(LocalSettings.BACKUP_DIR, backupbasedir.get_Text(true));
408
409        LocalSettings.apply();
410    }
411
412    @Override
413    public Component getAndRemoveActionPanel() {
414        this.remove(jPanel1);
415        validate();
416        return jPanel1;
417    }
418}