1 package com.calipso.xmleditor; 2 3 import com.calipso.reportgenerator.common.LanguageTraslator; 4 5 import javax.swing.*; 6 import javax.swing.text.JTextComponent ; 7 import javax.swing.text.Document ; 8 import java.awt.event.*; 9 import java.awt.*; 10 import java.util.Map ; 11 12 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 34 public boolean isCancelled() { 35 return cancelled; 36 } 37 38 42 public XmlEditorConnectionPane(Frame component, boolean modal, Map 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 ("DefaultConnectionClassName"))){ 64 txtDriverName.setText(defaultParams.get(new String ("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 ("DefaultConnectionLocalUrl"))){ 71 txtUrl.setText(defaultParams.get(new String ("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 ("DefaultConnectionUser"))){ 78 txtUser.setText(defaultParams.get(new String ("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 ("DefaultConnectionPassword"))){ 85 pswPassword.setText(defaultParams.get(new String ("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 111 private void addComponent(GridBagConstraints constrain, Component 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 142 } 143 144 private void setCancelled(boolean b) { 145 this.cancelled = b; 146 } 147 148 public String getReportName() { 149 return txtReportName.getText(); 150 } 151 152 public String getClassName() { 153 return txtDriverName.getText(); 154 } 155 156 public String getLocalUrl() { 157 return txtUrl.getText(); 158 } 159 160 public String getUser() { 161 return txtUser.getText(); 162 } 163 164 public char[] getPassword() { 165 return pswPassword.getPassword(); 166 } 167 168 public String 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 |