001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.gui;
020:
021: import java.io.*;
022: import java.text.*;
023: import java.util.*;
024: import java.awt.*;
025: import javax.swing.*;
026: import javax.swing.text.*;
027: import javax.swing.table.*;
028:
029: import org.apache.log4j.*;
030:
031: import org.homedns.dade.jcgrid.*;
032: import org.homedns.dade.jcgrid.admin.*;
033: import org.homedns.dade.jcgrid.message.*;
034:
035: public class guiJCGridConfig extends javax.swing.JDialog {
036: private final static String className = guiJCGridConfig.class
037: .getName();
038: private static Logger log = Logger.getLogger(className);
039: private static Logger logDetail = Logger.getLogger("DETAIL."
040: + className);
041:
042: private static final long serialVersionUID = 1L;
043:
044: private GridConfig gridConfig;
045:
046: public guiJCGridConfig(GridConfig cfg, java.awt.Frame parent,
047: boolean modal) {
048: super (parent, modal);
049:
050: initComponents();
051:
052: this .refreshConfig(cfg);
053: }
054:
055: public void refreshConfig(GridConfig cfg) {
056: gridConfig = cfg;
057:
058: tServerName.setText(gridConfig.getServerAddress());
059:
060: tClientPort.setText(Integer.toString(gridConfig
061: .getServerClientPort()));
062: tWorkerPort.setText(Integer.toString(gridConfig
063: .getServerWorkerPort()));
064: tAdminPort.setText(Integer.toString(gridConfig
065: .getServerAdminPort()));
066: cbUseCompression.setSelected(gridConfig.getUseCompression());
067: cbUseEnc.setSelected(gridConfig.getUseSecureConnection());
068: }
069:
070: /** This method is called from within the constructor to
071: * initialize the form.
072: * WARNING: Do NOT modify this code. The content of this method is
073: * always regenerated by the Form Editor.
074: */
075: private void initComponents() {//GEN-BEGIN:initComponents
076: java.awt.GridBagConstraints gridBagConstraints;
077:
078: pSettings = new javax.swing.JPanel();
079: jLabel10 = new javax.swing.JLabel();
080: tServerName = new javax.swing.JTextField();
081: jLabel11 = new javax.swing.JLabel();
082: tClientPort = new javax.swing.JTextField();
083: bDefaultClientPort = new javax.swing.JButton();
084: jLabel12 = new javax.swing.JLabel();
085: tWorkerPort = new javax.swing.JTextField();
086: bDefaultWorkerPort = new javax.swing.JButton();
087: jLabel13 = new javax.swing.JLabel();
088: tAdminPort = new javax.swing.JTextField();
089: bDefaultAdminPort = new javax.swing.JButton();
090: jLabel14 = new javax.swing.JLabel();
091: cbUseEnc = new javax.swing.JCheckBox();
092: bDefaultUseEnc = new javax.swing.JButton();
093: jLabel15 = new javax.swing.JLabel();
094: cbUseCompression = new javax.swing.JCheckBox();
095: bDefaultUseCompression = new javax.swing.JButton();
096: jLabel16 = new javax.swing.JLabel();
097: bDefaultPwd = new javax.swing.JButton();
098: pfPwd = new javax.swing.JPasswordField();
099: bApply = new javax.swing.JButton();
100:
101: getContentPane().setLayout(new java.awt.GridBagLayout());
102:
103: setTitle("JCGrid Settings");
104: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
105: pSettings.setLayout(new java.awt.GridBagLayout());
106:
107: pSettings.setBorder(new javax.swing.border.TitledBorder(
108: "JCGrid Settings"));
109: jLabel10
110: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
111: jLabel10.setText("Host name:");
112: gridBagConstraints = new java.awt.GridBagConstraints();
113: gridBagConstraints.gridx = 0;
114: gridBagConstraints.gridy = 0;
115: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116: gridBagConstraints.weighty = 1.0;
117: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
118: pSettings.add(jLabel10, gridBagConstraints);
119:
120: gridBagConstraints = new java.awt.GridBagConstraints();
121: gridBagConstraints.gridx = 1;
122: gridBagConstraints.gridy = 0;
123: gridBagConstraints.gridwidth = 2;
124: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125: gridBagConstraints.weightx = 1.0;
126: gridBagConstraints.weighty = 1.0;
127: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
128: pSettings.add(tServerName, gridBagConstraints);
129:
130: jLabel11
131: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
132: jLabel11.setText("Client port:");
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.gridx = 0;
135: gridBagConstraints.gridy = 1;
136: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137: gridBagConstraints.weighty = 1.0;
138: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
139: pSettings.add(jLabel11, gridBagConstraints);
140:
141: gridBagConstraints = new java.awt.GridBagConstraints();
142: gridBagConstraints.gridx = 1;
143: gridBagConstraints.gridy = 1;
144: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145: gridBagConstraints.weightx = 1.0;
146: gridBagConstraints.weighty = 1.0;
147: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
148: pSettings.add(tClientPort, gridBagConstraints);
149:
150: bDefaultClientPort.setText("Default");
151: bDefaultClientPort
152: .addActionListener(new java.awt.event.ActionListener() {
153: public void actionPerformed(
154: java.awt.event.ActionEvent evt) {
155: bDefaultClientPortActionPerformed(evt);
156: }
157: });
158:
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 2;
161: gridBagConstraints.gridy = 1;
162: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
163: pSettings.add(bDefaultClientPort, gridBagConstraints);
164:
165: jLabel12
166: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
167: jLabel12.setText("Worker port:");
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 0;
170: gridBagConstraints.gridy = 2;
171: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gridBagConstraints.weighty = 1.0;
173: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
174: pSettings.add(jLabel12, gridBagConstraints);
175:
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridx = 1;
178: gridBagConstraints.gridy = 2;
179: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180: gridBagConstraints.weightx = 1.0;
181: gridBagConstraints.weighty = 1.0;
182: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
183: pSettings.add(tWorkerPort, gridBagConstraints);
184:
185: bDefaultWorkerPort.setText("Default");
186: bDefaultWorkerPort
187: .addActionListener(new java.awt.event.ActionListener() {
188: public void actionPerformed(
189: java.awt.event.ActionEvent evt) {
190: bDefaultWorkerPortActionPerformed(evt);
191: }
192: });
193:
194: gridBagConstraints = new java.awt.GridBagConstraints();
195: gridBagConstraints.gridx = 2;
196: gridBagConstraints.gridy = 2;
197: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
198: pSettings.add(bDefaultWorkerPort, gridBagConstraints);
199:
200: jLabel13
201: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
202: jLabel13.setText("Admin port:");
203: gridBagConstraints = new java.awt.GridBagConstraints();
204: gridBagConstraints.gridx = 0;
205: gridBagConstraints.gridy = 3;
206: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207: gridBagConstraints.weighty = 1.0;
208: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
209: pSettings.add(jLabel13, gridBagConstraints);
210:
211: gridBagConstraints = new java.awt.GridBagConstraints();
212: gridBagConstraints.gridx = 1;
213: gridBagConstraints.gridy = 3;
214: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215: gridBagConstraints.weightx = 1.0;
216: gridBagConstraints.weighty = 1.0;
217: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
218: pSettings.add(tAdminPort, gridBagConstraints);
219:
220: bDefaultAdminPort.setText("Default");
221: bDefaultAdminPort
222: .addActionListener(new java.awt.event.ActionListener() {
223: public void actionPerformed(
224: java.awt.event.ActionEvent evt) {
225: bDefaultAdminPortActionPerformed(evt);
226: }
227: });
228:
229: gridBagConstraints = new java.awt.GridBagConstraints();
230: gridBagConstraints.gridx = 2;
231: gridBagConstraints.gridy = 3;
232: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
233: pSettings.add(bDefaultAdminPort, gridBagConstraints);
234:
235: jLabel14
236: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
237: jLabel14.setText("Enable encryption:");
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 0;
240: gridBagConstraints.gridy = 4;
241: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
242: gridBagConstraints.weighty = 1.0;
243: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
244: pSettings.add(jLabel14, gridBagConstraints);
245:
246: gridBagConstraints = new java.awt.GridBagConstraints();
247: gridBagConstraints.gridx = 1;
248: gridBagConstraints.gridy = 4;
249: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
250: gridBagConstraints.weightx = 1.0;
251: gridBagConstraints.weighty = 1.0;
252: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
253: pSettings.add(cbUseEnc, gridBagConstraints);
254:
255: bDefaultUseEnc.setText("Default");
256: bDefaultUseEnc
257: .addActionListener(new java.awt.event.ActionListener() {
258: public void actionPerformed(
259: java.awt.event.ActionEvent evt) {
260: bDefaultUseEncActionPerformed(evt);
261: }
262: });
263:
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.gridx = 2;
266: gridBagConstraints.gridy = 4;
267: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
268: pSettings.add(bDefaultUseEnc, gridBagConstraints);
269:
270: jLabel15
271: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
272: jLabel15.setText("Enable compression:");
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 0;
275: gridBagConstraints.gridy = 5;
276: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
277: gridBagConstraints.weighty = 1.0;
278: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
279: pSettings.add(jLabel15, gridBagConstraints);
280:
281: gridBagConstraints = new java.awt.GridBagConstraints();
282: gridBagConstraints.gridx = 1;
283: gridBagConstraints.gridy = 5;
284: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
285: gridBagConstraints.weightx = 1.0;
286: gridBagConstraints.weighty = 1.0;
287: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
288: pSettings.add(cbUseCompression, gridBagConstraints);
289:
290: bDefaultUseCompression.setText("Default");
291: bDefaultUseCompression
292: .addActionListener(new java.awt.event.ActionListener() {
293: public void actionPerformed(
294: java.awt.event.ActionEvent evt) {
295: bDefaultUseCompressionActionPerformed(evt);
296: }
297: });
298:
299: gridBagConstraints = new java.awt.GridBagConstraints();
300: gridBagConstraints.gridx = 2;
301: gridBagConstraints.gridy = 5;
302: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
303: pSettings.add(bDefaultUseCompression, gridBagConstraints);
304:
305: jLabel16
306: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
307: jLabel16.setText("Server password:");
308: gridBagConstraints = new java.awt.GridBagConstraints();
309: gridBagConstraints.gridx = 0;
310: gridBagConstraints.gridy = 6;
311: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
312: gridBagConstraints.weighty = 1.0;
313: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
314: pSettings.add(jLabel16, gridBagConstraints);
315:
316: bDefaultPwd.setText("Default");
317: gridBagConstraints = new java.awt.GridBagConstraints();
318: gridBagConstraints.gridx = 2;
319: gridBagConstraints.gridy = 6;
320: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
321: pSettings.add(bDefaultPwd, gridBagConstraints);
322:
323: gridBagConstraints = new java.awt.GridBagConstraints();
324: gridBagConstraints.gridx = 1;
325: gridBagConstraints.gridy = 6;
326: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
327: gridBagConstraints.weightx = 1.0;
328: gridBagConstraints.weighty = 1.0;
329: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
330: pSettings.add(pfPwd, gridBagConstraints);
331:
332: bApply.setText("Apply");
333: bApply.addActionListener(new java.awt.event.ActionListener() {
334: public void actionPerformed(java.awt.event.ActionEvent evt) {
335: bApplyActionPerformed(evt);
336: }
337: });
338:
339: gridBagConstraints = new java.awt.GridBagConstraints();
340: gridBagConstraints.gridx = 0;
341: gridBagConstraints.gridy = 10;
342: gridBagConstraints.gridwidth = 3;
343: gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
344: pSettings.add(bApply, gridBagConstraints);
345:
346: gridBagConstraints = new java.awt.GridBagConstraints();
347: gridBagConstraints.gridx = 0;
348: gridBagConstraints.gridy = 0;
349: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
350: gridBagConstraints.weightx = 1.0;
351: gridBagConstraints.weighty = 1.0;
352: getContentPane().add(pSettings, gridBagConstraints);
353:
354: setBounds(10, 10, 400, 300);
355: }//GEN-END:initComponents
356:
357: private void bApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bApplyActionPerformed
358: // Check settings
359:
360: String hostName = tServerName.getText().trim();
361: if (hostName.equals("")) {
362: JOptionPane.showMessageDialog(this ,
363: "You have to set the JCGrid Server host name.",
364: "Settings error", JOptionPane.ERROR_MESSAGE);
365: return;
366: }
367:
368: int clientPort = -1;
369: try {
370: clientPort = Integer.parseInt(tClientPort.getText());
371: } catch (Exception ex) {
372: JOptionPane.showMessageDialog(this ,
373: "Syntax error in the JCGrid Server port.",
374: "Settings error", JOptionPane.ERROR_MESSAGE);
375: return;
376: }
377: if (clientPort <= 1024) {
378: JOptionPane.showMessageDialog(this ,
379: "JCGrid client port must be greater than 1024.",
380: "Settings error", JOptionPane.ERROR_MESSAGE);
381: return;
382: }
383:
384: int workerPort = -1;
385: try {
386: workerPort = Integer.parseInt(tWorkerPort.getText());
387: } catch (Exception ex) {
388: JOptionPane.showMessageDialog(this ,
389: "Syntax error in the JCGrid worker port.",
390: "Settings error", JOptionPane.ERROR_MESSAGE);
391: return;
392: }
393: if (workerPort <= 1024) {
394: JOptionPane.showMessageDialog(this ,
395: "JCGrid worker port must be greater than 1024.",
396: "Settings error", JOptionPane.ERROR_MESSAGE);
397: return;
398: }
399:
400: int adminPort = -1;
401: try {
402: adminPort = Integer.parseInt(tAdminPort.getText());
403: } catch (Exception ex) {
404: JOptionPane.showMessageDialog(this ,
405: "Syntax error in the JCGrid admin. port.",
406: "Settings error", JOptionPane.ERROR_MESSAGE);
407: return;
408: }
409: if (adminPort <= 1024) {
410: JOptionPane.showMessageDialog(this ,
411: "JCGrid admin. port must be greater than 1024.",
412: "Settings error", JOptionPane.ERROR_MESSAGE);
413: return;
414: }
415:
416: boolean useComp = cbUseCompression.isSelected();
417: boolean useEnc = cbUseEnc.isSelected();
418:
419: // Applying settings
420:
421: gridConfig.setServerAddress(hostName);
422: gridConfig.setServerClientPort(clientPort);
423: gridConfig.setServerWorkerPort(workerPort);
424: gridConfig.setServerAdminPort(adminPort);
425: gridConfig.setUseCompression(useComp);
426: gridConfig.setUseSecureConnection(useEnc);
427: }//GEN-LAST:event_bApplyActionPerformed
428:
429: private void bDefaultUseCompressionActionPerformed(
430: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefaultUseCompressionActionPerformed
431: cbUseCompression.setSelected(false);
432: }//GEN-LAST:event_bDefaultUseCompressionActionPerformed
433:
434: private void bDefaultUseEncActionPerformed(
435: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefaultUseEncActionPerformed
436: cbUseEnc.setSelected(false);
437: }//GEN-LAST:event_bDefaultUseEncActionPerformed
438:
439: private void bDefaultAdminPortActionPerformed(
440: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefaultAdminPortActionPerformed
441: tAdminPort.setText(Integer
442: .toString(GridConfig.DEFAULT_ADMIN_PORT));
443: }//GEN-LAST:event_bDefaultAdminPortActionPerformed
444:
445: private void bDefaultWorkerPortActionPerformed(
446: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefaultWorkerPortActionPerformed
447: tWorkerPort.setText(Integer
448: .toString(GridConfig.DEFAULT_WORKER_PORT));
449: }//GEN-LAST:event_bDefaultWorkerPortActionPerformed
450:
451: private void bDefaultClientPortActionPerformed(
452: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDefaultClientPortActionPerformed
453: tClientPort.setText(Integer
454: .toString(GridConfig.DEFAULT_CLIENT_PORT));
455: }//GEN-LAST:event_bDefaultClientPortActionPerformed
456:
457: // Variables declaration - do not modify//GEN-BEGIN:variables
458: private javax.swing.JButton bApply;
459: private javax.swing.JButton bDefaultAdminPort;
460: private javax.swing.JButton bDefaultClientPort;
461: private javax.swing.JButton bDefaultPwd;
462: private javax.swing.JButton bDefaultUseCompression;
463: private javax.swing.JButton bDefaultUseEnc;
464: private javax.swing.JButton bDefaultWorkerPort;
465: private javax.swing.JCheckBox cbUseCompression;
466: private javax.swing.JCheckBox cbUseEnc;
467: private javax.swing.JLabel jLabel10;
468: private javax.swing.JLabel jLabel11;
469: private javax.swing.JLabel jLabel12;
470: private javax.swing.JLabel jLabel13;
471: private javax.swing.JLabel jLabel14;
472: private javax.swing.JLabel jLabel15;
473: private javax.swing.JLabel jLabel16;
474: private javax.swing.JPanel pSettings;
475: private javax.swing.JPasswordField pfPwd;
476: private javax.swing.JTextField tAdminPort;
477: private javax.swing.JTextField tClientPort;
478: private javax.swing.JTextField tServerName;
479: private javax.swing.JTextField tWorkerPort;
480: // End of variables declaration//GEN-END:variables
481:
482: }
|