001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * CheckUpdateDialog.java
028: *
029: * Created on 22 maggio 2005, 0.39
030: *
031: */
032:
033: package it.businesslogic.ireport.plugin.checkupdate;
034:
035: import it.businesslogic.ireport.util.I18n;
036: import it.businesslogic.ireport.util.Misc;
037: import java.net.URL;
038: import java.util.Properties;
039: import javax.swing.JOptionPane;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class CheckUpdateDialog extends javax.swing.JDialog {
046:
047: /** Creates new form CheckUpdateDialog */
048: public CheckUpdateDialog(java.awt.Frame parent, boolean modal) {
049: super (parent, modal);
050: initComponents();
051: applyI18n();
052:
053: Properties props = it.businesslogic.ireport.gui.MainFrame
054: .getMainInstance().getProperties();
055: this .jCheckBox1.setSelected(props.getProperty(
056: "updateOnStartup", "true").equals("true"));
057: this .jCheckBoxEnableProxy.setSelected(props.getProperty(
058: "update.useProxy", "false").equals("true"));
059: this .jTextFieldURL.setText(props.getProperty("update.proxyUrl",
060: ""));
061: this .jCheckBoxEnableAuth.setSelected(props.getProperty(
062: "update.useAuth", "false").equals("true"));
063: this .jTextFieldUsername.setText(props.getProperty(
064: "update.username", ""));
065: this .jPasswordField1.setText(props.getProperty(
066: "update.password", ""));
067:
068: updateProxyUse();
069:
070: it.businesslogic.ireport.util.Misc.centerFrame(this );
071:
072: javax.swing.KeyStroke escape = javax.swing.KeyStroke
073: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
074: false);
075: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
076: public void actionPerformed(java.awt.event.ActionEvent e) {
077: jButton2ActionPerformed(e);
078: }
079: };
080:
081: getRootPane().getInputMap(
082: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
083: escape, "ESCAPE");
084: getRootPane().getActionMap().put("ESCAPE", escapeAction);
085:
086: //to make the default button ...
087: this .getRootPane().setDefaultButton(this .jButton1);
088: this .pack();
089: }
090:
091: /** This method is called from within the constructor to
092: * initialize the form.
093: * WARNING: Do NOT modify this code. The content of this method is
094: * always regenerated by the Form Editor.
095: */
096: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
097: private void initComponents() {
098: java.awt.GridBagConstraints gridBagConstraints;
099:
100: jCheckBox1 = new javax.swing.JCheckBox();
101: jPanel3 = new javax.swing.JPanel();
102: jLabelProxy = new javax.swing.JLabel();
103: jCheckBoxEnableProxy = new javax.swing.JCheckBox();
104: jLabelProxyURL = new javax.swing.JLabel();
105: jTextFieldURL = new javax.swing.JTextField();
106: jCheckBoxEnableAuth = new javax.swing.JCheckBox();
107: jLabelUsername = new javax.swing.JLabel();
108: jTextFieldUsername = new javax.swing.JTextField();
109: jLabelPassword = new javax.swing.JLabel();
110: jPasswordField1 = new javax.swing.JPasswordField();
111: jSeparator1 = new javax.swing.JSeparator();
112: jPanel1 = new javax.swing.JPanel();
113: jPanel2 = new javax.swing.JPanel();
114: jButton1 = new javax.swing.JButton();
115: jButton2 = new javax.swing.JButton();
116:
117: getContentPane().setLayout(new java.awt.GridBagLayout());
118:
119: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
120: addWindowListener(new java.awt.event.WindowAdapter() {
121: public void windowOpened(java.awt.event.WindowEvent evt) {
122: formWindowOpened(evt);
123: }
124: });
125:
126: jCheckBox1.setText("Check for update on iReport startup");
127: jCheckBox1.setMinimumSize(new java.awt.Dimension(350, 50));
128: jCheckBox1.setPreferredSize(new java.awt.Dimension(350, 24));
129: gridBagConstraints = new java.awt.GridBagConstraints();
130: gridBagConstraints.gridx = 0;
131: gridBagConstraints.gridy = 0;
132: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
134: getContentPane().add(jCheckBox1, gridBagConstraints);
135:
136: jPanel3.setLayout(new java.awt.GridBagLayout());
137:
138: jPanel3.setBorder(javax.swing.BorderFactory
139: .createTitledBorder("Proxy configuration"));
140: jLabelProxy
141: .setText("<html>If you need a HTTP proxy, enter it here in the format HOST:PORT<br>e.g. squid.mysite.com:3128");
142: gridBagConstraints = new java.awt.GridBagConstraints();
143: gridBagConstraints.gridx = 0;
144: gridBagConstraints.gridwidth = 2;
145: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
147: jPanel3.add(jLabelProxy, gridBagConstraints);
148:
149: jCheckBoxEnableProxy.setText("Enable HTTP Proxy");
150: jCheckBoxEnableProxy.setActionCommand("Enable HTTP Proxy");
151: jCheckBoxEnableProxy.setBorder(javax.swing.BorderFactory
152: .createEmptyBorder(0, 0, 0, 0));
153: jCheckBoxEnableProxy.setMargin(new java.awt.Insets(0, 0, 0, 0));
154: jCheckBoxEnableProxy
155: .addActionListener(new java.awt.event.ActionListener() {
156: public void actionPerformed(
157: java.awt.event.ActionEvent evt) {
158: jCheckBoxEnableProxyActionPerformed(evt);
159: }
160: });
161: jCheckBoxEnableProxy
162: .addChangeListener(new javax.swing.event.ChangeListener() {
163: public void stateChanged(
164: javax.swing.event.ChangeEvent evt) {
165: jCheckBoxEnableProxyStateChanged(evt);
166: }
167: });
168:
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 0;
171: gridBagConstraints.gridwidth = 2;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173: gridBagConstraints.weightx = 1.0;
174: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
175: jPanel3.add(jCheckBoxEnableProxy, gridBagConstraints);
176:
177: jLabelProxyURL.setText("Proxy address");
178: jLabelProxyURL.setEnabled(false);
179: gridBagConstraints = new java.awt.GridBagConstraints();
180: gridBagConstraints.gridx = 0;
181: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
183: jPanel3.add(jLabelProxyURL, gridBagConstraints);
184:
185: jTextFieldURL.setEnabled(false);
186: gridBagConstraints = new java.awt.GridBagConstraints();
187: gridBagConstraints.gridx = 1;
188: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189: gridBagConstraints.weightx = 1.0;
190: jPanel3.add(jTextFieldURL, gridBagConstraints);
191:
192: jCheckBoxEnableAuth.setText("Use Authentication");
193: jCheckBoxEnableAuth.setBorder(javax.swing.BorderFactory
194: .createEmptyBorder(0, 0, 0, 0));
195: jCheckBoxEnableAuth.setEnabled(false);
196: jCheckBoxEnableAuth.setMargin(new java.awt.Insets(0, 0, 0, 0));
197: jCheckBoxEnableAuth
198: .addChangeListener(new javax.swing.event.ChangeListener() {
199: public void stateChanged(
200: javax.swing.event.ChangeEvent evt) {
201: jCheckBoxEnableAuthStateChanged(evt);
202: }
203: });
204:
205: gridBagConstraints = new java.awt.GridBagConstraints();
206: gridBagConstraints.gridx = 0;
207: gridBagConstraints.gridwidth = 2;
208: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209: gridBagConstraints.weightx = 1.0;
210: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
211: jPanel3.add(jCheckBoxEnableAuth, gridBagConstraints);
212:
213: jLabelUsername.setText("Username");
214: jLabelUsername.setEnabled(false);
215: gridBagConstraints = new java.awt.GridBagConstraints();
216: gridBagConstraints.gridx = 0;
217: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
219: jPanel3.add(jLabelUsername, gridBagConstraints);
220:
221: jTextFieldUsername.setEnabled(false);
222: gridBagConstraints = new java.awt.GridBagConstraints();
223: gridBagConstraints.gridx = 1;
224: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
225: gridBagConstraints.weightx = 1.0;
226: jPanel3.add(jTextFieldUsername, gridBagConstraints);
227:
228: jLabelPassword.setText("Password");
229: jLabelPassword.setEnabled(false);
230: gridBagConstraints = new java.awt.GridBagConstraints();
231: gridBagConstraints.gridx = 0;
232: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
233: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
234: jPanel3.add(jLabelPassword, gridBagConstraints);
235:
236: jPasswordField1.setText("jPasswordField1");
237: jPasswordField1.setEnabled(false);
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 1;
240: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
241: gridBagConstraints.weightx = 1.0;
242: jPanel3.add(jPasswordField1, gridBagConstraints);
243:
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridx = 0;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
247: gridBagConstraints.weightx = 1.0;
248: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
249: getContentPane().add(jPanel3, gridBagConstraints);
250:
251: jSeparator1.setMinimumSize(new java.awt.Dimension(0, 4));
252: jSeparator1.setPreferredSize(new java.awt.Dimension(0, 4));
253: gridBagConstraints = new java.awt.GridBagConstraints();
254: gridBagConstraints.gridx = 0;
255: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
256: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
257: gridBagConstraints.weightx = 1.0;
258: gridBagConstraints.weighty = 1.0;
259: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0);
260: getContentPane().add(jSeparator1, gridBagConstraints);
261:
262: jPanel1.setLayout(new java.awt.GridBagLayout());
263:
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.weightx = 1.0;
266: jPanel1.add(jPanel2, gridBagConstraints);
267:
268: jButton1.setText("Save");
269: jButton1.addActionListener(new java.awt.event.ActionListener() {
270: public void actionPerformed(java.awt.event.ActionEvent evt) {
271: jButton1ActionPerformed(evt);
272: }
273: });
274:
275: gridBagConstraints = new java.awt.GridBagConstraints();
276: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4);
277: jPanel1.add(jButton1, gridBagConstraints);
278:
279: jButton2.setText("Cancel");
280: jButton2.addActionListener(new java.awt.event.ActionListener() {
281: public void actionPerformed(java.awt.event.ActionEvent evt) {
282: jButton2ActionPerformed(evt);
283: }
284: });
285:
286: gridBagConstraints = new java.awt.GridBagConstraints();
287: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 10);
288: jPanel1.add(jButton2, gridBagConstraints);
289:
290: gridBagConstraints = new java.awt.GridBagConstraints();
291: gridBagConstraints.gridx = 0;
292: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293: gridBagConstraints.weightx = 1.0;
294: getContentPane().add(jPanel1, gridBagConstraints);
295:
296: pack();
297: }// </editor-fold>//GEN-END:initComponents
298:
299: private void jCheckBoxEnableAuthStateChanged(
300: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxEnableAuthStateChanged
301: updateAuthUse();
302: }//GEN-LAST:event_jCheckBoxEnableAuthStateChanged
303:
304: private void jCheckBoxEnableProxyStateChanged(
305: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBoxEnableProxyStateChanged
306: updateProxyUse();
307: }//GEN-LAST:event_jCheckBoxEnableProxyStateChanged
308:
309: private void jCheckBoxEnableProxyActionPerformed(
310: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEnableProxyActionPerformed
311:
312: }//GEN-LAST:event_jCheckBoxEnableProxyActionPerformed
313:
314: private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
315: setVisible(false);
316: dispose();
317: }//GEN-LAST:event_jButton2ActionPerformed
318:
319: private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
320:
321: }//GEN-LAST:event_formWindowOpened
322:
323: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
324:
325: Properties props = it.businesslogic.ireport.gui.MainFrame
326: .getMainInstance().getProperties();
327:
328: if (jCheckBoxEnableProxy.isSelected()) {
329: String urlStr = jTextFieldURL.getText();
330: if (urlStr.length() == 0) {
331: JOptionPane.showMessageDialog(this ,
332: "Invalid proxy url", "",
333: JOptionPane.ERROR_MESSAGE);
334: return;
335: }
336:
337: if (!Misc.isValidUrl(jTextFieldURL.getText())) {
338: JOptionPane.showMessageDialog(this , I18n.getString(
339: "checkUpdateDialog.message.invalidUrl",
340: "Invalid proxy url"), "",
341: JOptionPane.ERROR_MESSAGE);
342: return;
343: }
344:
345: if (jCheckBoxEnableAuth.isSelected()) {
346: if (jTextFieldUsername.getText().length() == 0) {
347: JOptionPane
348: .showMessageDialog(
349: this ,
350: I18n
351: .getString(
352: "checkUpdateDialog.message.invalidUsername",
353: "Invalid username"),
354: "", JOptionPane.ERROR_MESSAGE);
355: return;
356: }
357: }
358: }
359:
360: props.setProperty("updateOnStartup", ""
361: + jCheckBox1.isSelected());
362: props.setProperty("update.useProxy", ""
363: + jCheckBoxEnableProxy.isSelected());
364: props.setProperty("update.proxyUrl", ""
365: + jTextFieldURL.getText());
366: props.setProperty("update.useAuth", ""
367: + jCheckBoxEnableAuth.isSelected());
368: props.setProperty("update.username", ""
369: + jTextFieldUsername.getText());
370: props.setProperty("update.password", ""
371: + new String(jPasswordField1.getPassword()));
372:
373: it.businesslogic.ireport.gui.MainFrame.getMainInstance()
374: .saveiReportConfiguration();
375: setVisible(false);
376: dispose();
377:
378: }//GEN-LAST:event_jButton1ActionPerformed
379:
380: // Variables declaration - do not modify//GEN-BEGIN:variables
381: private javax.swing.JButton jButton1;
382: private javax.swing.JButton jButton2;
383: private javax.swing.JCheckBox jCheckBox1;
384: private javax.swing.JCheckBox jCheckBoxEnableAuth;
385: private javax.swing.JCheckBox jCheckBoxEnableProxy;
386: private javax.swing.JLabel jLabelPassword;
387: private javax.swing.JLabel jLabelProxy;
388: private javax.swing.JLabel jLabelProxyURL;
389: private javax.swing.JLabel jLabelUsername;
390: private javax.swing.JPanel jPanel1;
391: private javax.swing.JPanel jPanel2;
392: private javax.swing.JPanel jPanel3;
393: private javax.swing.JPasswordField jPasswordField1;
394: private javax.swing.JSeparator jSeparator1;
395: private javax.swing.JTextField jTextFieldURL;
396: private javax.swing.JTextField jTextFieldUsername;
397:
398: // End of variables declaration//GEN-END:variables
399:
400: public void applyI18n() {
401: // Start autogenerated code ----------------------
402: jCheckBox1.setText(I18n.getString(
403: "checkUpdateDialog.checkBox1",
404: "Check for update on iReport startup"));
405: // End autogenerated code ----------------------
406: // Start autogenerated code ----------------------
407: jButton1.setText(I18n.getString("checkUpdateDialog.button1",
408: "Save"));
409: jButton2.setText(I18n.getString("checkUpdateDialog.button2",
410: "Cancel"));
411:
412: jCheckBoxEnableProxy.setText(I18n.getString(
413: "checkUpdateDialog.enableProxy", "Enable HTTP Proxy"));
414: jCheckBoxEnableAuth.setText(I18n.getString(
415: "checkUpdateDialog.useAuthentication",
416: "Use Authentication"));
417: jLabelProxyURL.setText(I18n.getString(
418: "checkUpdateDialog.jLabelProxyURL", "Proxy address"));
419: jLabelUsername.setText(I18n.getString(
420: "checkUpdateDialog.jLabelUsername", "Username"));
421: jLabelPassword.setText(I18n.getString(
422: "checkUpdateDialog.jLabelPassword", "Password"));
423: jLabelProxy
424: .setText("<html>"
425: + I18n
426: .getString(
427: "checkUpdateDialog.jLabelProxy",
428: "If you need a HTTP proxy, enter it here in the format HOST:PORT<br>e.g. squid.mysite.com:3128"));
429:
430: // End autogenerated code ----------------------
431: jButton1.setMnemonic(I18n.getString(
432: "checkUpdateDialog.button1Mnemonic", "s").charAt(0));
433: jButton2.setMnemonic(I18n.getString(
434: "checkUpdateDialog.button2Mnemonic", "c").charAt(0));
435: }
436:
437: private void updateProxyUse() {
438:
439: boolean enabled = jCheckBoxEnableProxy.isSelected();
440: this .jTextFieldURL.setEnabled(enabled);
441: this .jLabelProxyURL.setEnabled(enabled);
442: this .jCheckBoxEnableAuth.setEnabled(enabled);
443:
444: updateAuthUse();
445: }
446:
447: private void updateAuthUse() {
448:
449: boolean authEnabled = jCheckBoxEnableProxy.isSelected()
450: && jCheckBoxEnableAuth.isSelected();
451: this.jLabelUsername.setEnabled(authEnabled);
452: this.jLabelPassword.setEnabled(authEnabled);
453: this.jTextFieldUsername.setEnabled(authEnabled);
454: this.jPasswordField1.setEnabled(authEnabled);
455: }
456: }
|