001: package com.calipso.xmleditor;
002:
003: import com.calipso.reportgenerator.common.LanguageTraslator;
004:
005: import javax.swing.*;
006: import javax.swing.text.JTextComponent;
007: import javax.swing.text.Document;
008: import java.awt.event.*;
009: import java.awt.*;
010: import java.util.Map;
011:
012: /**
013: *
014: * User: jbassino
015: * Date: 17/06/2004
016: * Time: 15:56:50
017: *
018: */
019: public class XmlEditorConnectionPane extends JDialog implements
020: ActionListener, WindowListener {
021: JButton btnAccept;
022: JButton btnCancel;
023: JTextField txtDriverName;
024: JTextField txtUrl;
025: JTextField txtUser;
026: JPasswordField pswPassword;
027: JTextArea txtQuery;
028: JTextField txtReportName;
029: private boolean cancelled = false;
030:
031: /**
032: * Obtiene la variable que indica si el panel ha sido cancelado.
033: * @return
034: */
035: public boolean isCancelled() {
036: return cancelled;
037: }
038:
039: /**
040: * Genera el panel de carga de parametros.
041: * @param component
042: */
043: public XmlEditorConnectionPane(Frame component, boolean modal,
044: Map defaultParams) {
045: super (component, modal);
046: addWindowListener(this );
047: setTitle(LanguageTraslator.traslate("549"));
048: getContentPane().setLayout(new GridBagLayout());
049: GridBagConstraints constrain = new GridBagConstraints();
050:
051: txtReportName = new JTextField(LanguageTraslator
052: .traslate("550"), 50);
053: addComponent(constrain, new JLabel(LanguageTraslator
054: .traslate("550")), 0, 0, 1, 1);
055: addComponent(constrain, txtReportName, 0, 1, 1, 5);
056:
057: txtQuery = new JTextArea("Query");
058: txtQuery.setAutoscrolls(false);
059: txtQuery.setRows(15);
060: txtQuery.setLineWrap(true);
061: JScrollPane jScrollPane = new JScrollPane(txtQuery);
062: addComponent(constrain, new JLabel("Query "), 2, 0, 1, 1);
063: addComponent(constrain, jScrollPane, 2, 1, 5, 10);
064:
065: txtDriverName = new JTextField("Class Name ");
066: if (defaultParams.containsKey(new String(
067: "DefaultConnectionClassName"))) {
068: txtDriverName.setText(defaultParams.get(
069: new String("DefaultConnectionClassName"))
070: .toString());
071: }
072: addComponent(constrain, new JLabel("Class Name "), 7, 0, 1, 1);
073: addComponent(constrain, txtDriverName, 7, 1, 1, 5);
074:
075: txtUrl = new JTextField("Local Url", 50);
076: if (defaultParams.containsKey(new String(
077: "DefaultConnectionLocalUrl"))) {
078: txtUrl
079: .setText(defaultParams.get(
080: new String("DefaultConnectionLocalUrl"))
081: .toString());
082: }
083: addComponent(constrain, new JLabel("Local Url "), 8, 0, 1, 1);
084: addComponent(constrain, txtUrl, 8, 1, 1, 5);
085:
086: txtUser = new JTextField("User");
087: if (defaultParams.containsKey(new String(
088: "DefaultConnectionUser"))) {
089: txtUser.setText(defaultParams.get(
090: new String("DefaultConnectionUser")).toString());
091: }
092: addComponent(constrain, new JLabel("User "), 9, 0, 1, 1);
093: addComponent(constrain, txtUser, 9, 1, 1, 5);
094:
095: pswPassword = new JPasswordField("Password", 25);
096: if (defaultParams.containsKey(new String(
097: "DefaultConnectionPassword"))) {
098: pswPassword
099: .setText(defaultParams.get(
100: new String("DefaultConnectionPassword"))
101: .toString());
102: }
103: addComponent(constrain, new JLabel("Password "), 10, 0, 1, 1);
104: addComponent(constrain, pswPassword, 10, 1, 1, 5);
105:
106: JPanel pnlButton = new JPanel(new FlowLayout(FlowLayout.RIGHT));
107: btnAccept = new JButton(LanguageTraslator.traslate("112"));
108: btnAccept.addActionListener(this );
109: pnlButton.add(btnAccept);
110: btnCancel = new JButton(LanguageTraslator.traslate("113"));
111: btnCancel.addActionListener(this );
112: pnlButton.add(btnCancel);
113: addComponent(constrain, pnlButton, 11, 4, 1, 2);
114: setResizable(false);
115: pack();
116: }
117:
118: /**
119: * Agrega el item al panel con los parametros pasados para la GridBagConstraints.
120: * @param constrain
121: * @param component: el componente a agregar
122: * @param row: el numero de fila en el que se agregara
123: * @param col: el numero de columna en el que se agregara
124: * @param height: las filas que ocupara
125: * @param width: el numero de columnas que ocupara
126: */
127: private void addComponent(GridBagConstraints constrain,
128: Component component, int row, int col, int height, int width) {
129: if (!(component instanceof JButton)) {
130: constrain.fill = GridBagConstraints.HORIZONTAL;
131: } else {
132: constrain.anchor = GridBagConstraints.WEST;
133: }
134: constrain.gridy = row;
135: constrain.gridx = col;
136: constrain.gridheight = height;
137: constrain.gridwidth = width;
138: ((GridBagLayout) getContentPane().getLayout()).setConstraints(
139: component, constrain);
140: getContentPane().add(component);
141: }
142:
143: public void actionPerformed(ActionEvent e) {
144:
145: this .dispose();
146: if (e.getSource() == btnAccept) {
147: setCancelled(false);
148: } else {
149: setCancelled(true);
150: }
151: /*}else if(e.getSource() == btnAccept){
152: listener.createReportDefinitionsFromSql(txtReportName.getText(),
153: txtDriverName.getText(),
154: txtUrl.getText(),
155: txtUser.getText(),
156: String.valueOf(pswPassword.getPassword()),
157: txtQuery.getText(),
158: Integer.valueOf(txtMetricStart.getText()).intValue());
159: }*/
160: }
161:
162: private void setCancelled(boolean b) {
163: this .cancelled = b;
164: }
165:
166: public String getReportName() {
167: return txtReportName.getText();
168: }
169:
170: public String getClassName() {
171: return txtDriverName.getText();
172: }
173:
174: public String getLocalUrl() {
175: return txtUrl.getText();
176: }
177:
178: public String getUser() {
179: return txtUser.getText();
180: }
181:
182: public char[] getPassword() {
183: return pswPassword.getPassword();
184: }
185:
186: public String getSqlText() {
187: return txtQuery.getText();
188: }
189:
190: public void windowActivated(WindowEvent e) {
191: }
192:
193: public void windowClosed(WindowEvent e) {
194: }
195:
196: public void windowClosing(WindowEvent e) {
197: setCancelled(true);
198: }
199:
200: public void windowDeactivated(WindowEvent e) {
201: }
202:
203: public void windowDeiconified(WindowEvent e) {
204: }
205:
206: public void windowIconified(WindowEvent e) {
207: }
208:
209: public void windowOpened(WindowEvent e) {
210: }
211:
212: }
|