KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > xmleditor > XmlEditorConnectionPane


1 package com.calipso.xmleditor;
2
3 import com.calipso.reportgenerator.common.LanguageTraslator;
4
5 import javax.swing.*;
6 import javax.swing.text.JTextComponent JavaDoc;
7 import javax.swing.text.Document JavaDoc;
8 import java.awt.event.*;
9 import java.awt.*;
10 import java.util.Map JavaDoc;
11
12 /**
13  *
14  * User: jbassino
15  * Date: 17/06/2004
16  * Time: 15:56:50
17  *
18  */

19 public class XmlEditorConnectionPane extends JDialog implements ActionListener, WindowListener {
20   JButton btnAccept;
21   JButton btnCancel;
22   JTextField txtDriverName;
23   JTextField txtUrl;
24   JTextField txtUser;
25   JPasswordField pswPassword;
26   JTextArea txtQuery;
27   JTextField txtReportName;
28   private boolean cancelled = false;
29
30   /**
31    * Obtiene la variable que indica si el panel ha sido cancelado.
32    * @return
33    */

34   public boolean isCancelled() {
35     return cancelled;
36   }
37
38   /**
39    * Genera el panel de carga de parametros.
40    * @param component
41    */

42   public XmlEditorConnectionPane(Frame component, boolean modal, Map JavaDoc defaultParams){
43     super(component, modal);
44     addWindowListener(this);
45     setTitle(LanguageTraslator.traslate("549"));
46     getContentPane().setLayout(new GridBagLayout());
47     GridBagConstraints constrain = new GridBagConstraints();
48
49     txtReportName = new JTextField(LanguageTraslator.traslate("550"), 50);
50     addComponent(constrain, new JLabel(LanguageTraslator.traslate("550")), 0, 0, 1, 1);
51     addComponent(constrain, txtReportName, 0,1,1,5);
52
53
54     txtQuery = new JTextArea("Query");
55     txtQuery.setAutoscrolls(false);
56     txtQuery.setRows(15);
57     txtQuery.setLineWrap(true);
58     JScrollPane jScrollPane = new JScrollPane(txtQuery);
59     addComponent(constrain, new JLabel("Query "), 2, 0, 1, 1);
60     addComponent(constrain, jScrollPane, 2,1,5,10);
61
62     txtDriverName = new JTextField("Class Name ");
63     if (defaultParams.containsKey(new String JavaDoc("DefaultConnectionClassName"))){
64       txtDriverName.setText(defaultParams.get(new String JavaDoc("DefaultConnectionClassName")).toString());
65     }
66     addComponent(constrain, new JLabel("Class Name "), 7, 0, 1, 1);
67     addComponent(constrain, txtDriverName, 7, 1, 1, 5);
68
69     txtUrl = new JTextField("Local Url", 50);
70     if (defaultParams.containsKey(new String JavaDoc("DefaultConnectionLocalUrl"))){
71       txtUrl.setText(defaultParams.get(new String JavaDoc("DefaultConnectionLocalUrl")).toString());
72     }
73     addComponent(constrain, new JLabel("Local Url "), 8, 0, 1, 1);
74     addComponent(constrain, txtUrl, 8, 1, 1, 5);
75
76     txtUser = new JTextField("User");
77     if (defaultParams.containsKey(new String JavaDoc("DefaultConnectionUser"))){
78       txtUser.setText(defaultParams.get(new String JavaDoc("DefaultConnectionUser")).toString());
79     }
80     addComponent(constrain, new JLabel("User "), 9, 0, 1, 1);
81     addComponent(constrain, txtUser, 9, 1, 1, 5);
82
83     pswPassword = new JPasswordField("Password", 25);
84     if (defaultParams.containsKey(new String JavaDoc("DefaultConnectionPassword"))){
85       pswPassword.setText(defaultParams.get(new String JavaDoc("DefaultConnectionPassword")).toString());
86     }
87     addComponent(constrain, new JLabel("Password "), 10, 0, 1, 1);
88     addComponent(constrain, pswPassword, 10, 1, 1, 5);
89
90     JPanel pnlButton = new JPanel(new FlowLayout(FlowLayout.RIGHT));
91     btnAccept = new JButton(LanguageTraslator.traslate("112"));
92     btnAccept.addActionListener(this);
93     pnlButton.add(btnAccept);
94     btnCancel = new JButton(LanguageTraslator.traslate("113"));
95     btnCancel.addActionListener(this);
96     pnlButton.add(btnCancel);
97     addComponent(constrain, pnlButton, 11, 4, 1,2);
98     setResizable(false);
99     pack();
100   }
101
102   /**
103    * Agrega el item al panel con los parametros pasados para la GridBagConstraints.
104    * @param constrain
105    * @param component: el componente a agregar
106    * @param row: el numero de fila en el que se agregara
107    * @param col: el numero de columna en el que se agregara
108    * @param height: las filas que ocupara
109    * @param width: el numero de columnas que ocupara
110    */

111   private void addComponent(GridBagConstraints constrain, Component JavaDoc component, int row, int col, int height, int width) {
112     if(!(component instanceof JButton)){
113       constrain.fill = GridBagConstraints.HORIZONTAL;
114     }else{
115       constrain.anchor = GridBagConstraints.WEST;
116     }
117     constrain.gridy = row;
118     constrain.gridx = col;
119     constrain.gridheight = height;
120     constrain.gridwidth = width;
121     ((GridBagLayout)getContentPane().getLayout()).setConstraints(component, constrain);
122     getContentPane().add(component);
123   }
124
125   public void actionPerformed(ActionEvent e) {
126
127     this.dispose();
128     if(e.getSource() == btnAccept){
129      setCancelled(false);
130       }else{
131       setCancelled(true);
132     }
133     /*}else if(e.getSource() == btnAccept){
134       listener.createReportDefinitionsFromSql(txtReportName.getText(),
135                                       txtDriverName.getText(),
136                                       txtUrl.getText(),
137                                       txtUser.getText(),
138                                       String.valueOf(pswPassword.getPassword()),
139                                       txtQuery.getText(),
140                                       Integer.valueOf(txtMetricStart.getText()).intValue());
141     }*/

142   }
143
144   private void setCancelled(boolean b) {
145     this.cancelled = b;
146   }
147
148   public String JavaDoc getReportName() {
149     return txtReportName.getText();
150   }
151
152   public String JavaDoc getClassName() {
153     return txtDriverName.getText();
154   }
155
156   public String JavaDoc getLocalUrl() {
157     return txtUrl.getText();
158   }
159
160   public String JavaDoc getUser() {
161     return txtUser.getText();
162   }
163
164   public char[] getPassword() {
165     return pswPassword.getPassword();
166   }
167
168   public String JavaDoc getSqlText() {
169     return txtQuery.getText();
170   }
171
172   public void windowActivated(WindowEvent e) {
173   }
174
175   public void windowClosed(WindowEvent e) {
176   }
177
178   public void windowClosing(WindowEvent e) {
179     setCancelled(true);
180   }
181
182   public void windowDeactivated(WindowEvent e) {
183   }
184
185   public void windowDeiconified(WindowEvent e) {
186   }
187
188   public void windowIconified(WindowEvent e) {
189   }
190
191   public void windowOpened(WindowEvent e) {
192   }
193
194 }
195
Popular Tags