PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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