KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > ActiveConnectionDialog


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * ActiveConnectionDialog.java
28  *
29  * Created on 5 giugno 2003, 23.40
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34 import it.businesslogic.ireport.*;
35 import it.businesslogic.ireport.util.*;
36
37 import javax.swing.*;
38 import java.util.*;
39
40 /**
41  *
42  * @author Administrator
43  */

44 public class ActiveConnectionDialog extends javax.swing.JDialog JavaDoc {
45     
46     /** Creates new form ActiveConnectionDialog */
47     public ActiveConnectionDialog(java.awt.Frame JavaDoc parent, boolean modal) {
48         super(parent, modal);
49         initComponents();
50         applyI18n();
51         Misc.centerFrame(this);
52          
53         DefaultListModel lm = new DefaultListModel();
54         this.jListConnections.setModel(lm );
55
56     Enumeration e = ((MainFrame)parent).getConnections().elements();
57         
58         while (e.hasMoreElements())
59         {
60             lm.addElement(e.nextElement());
61         }
62         
63         if (((MainFrame)parent).getProperties().get("DefaultConnection") != null)
64         {
65             jListConnections.setSelectedValue( ((MainFrame)parent).getProperties().get("DefaultConnection"), true);
66         }
67         
68         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
69         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
70             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
71                 jButtonCancelActionPerformed(e);
72             }
73         };
74        
75         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
76         getRootPane().getActionMap().put("ESCAPE", escapeAction);
77
78
79         //to make the default button ...
80
this.getRootPane().setDefaultButton(this.jButtonOK);
81     }
82     
83     /** This method is called from within the constructor to
84      * initialize the form.
85      * WARNING: Do NOT modify this code. The content of this method is
86      * always regenerated by the Form Editor.
87      */

88     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
89
private void initComponents() {
90         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
91
92         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
93         jListConnections = new javax.swing.JList JavaDoc();
94         jLabel1 = new javax.swing.JLabel JavaDoc();
95         jPanel1 = new javax.swing.JPanel JavaDoc();
96         jButtonOK = new javax.swing.JButton JavaDoc();
97         jButtonCancel = new javax.swing.JButton JavaDoc();
98
99         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
100
101         setTitle("Set active connection...");
102         setResizable(false);
103         setModal(true);
104         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
105             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
106                 closeDialog(evt);
107             }
108         });
109
110         jListConnections.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
111             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
112                 jListConnectionsValueChanged(evt);
113             }
114         });
115
116         jScrollPane1.setViewportView(jListConnections);
117
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 1;
121         gridBagConstraints.gridheight = 3;
122         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
124         gridBagConstraints.weightx = 1000.0;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 5, 3, 3);
126         getContentPane().add(jScrollPane1, gridBagConstraints);
127
128         jLabel1.setText("Available connections");
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 0;
132         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
134         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 5, 3, 3);
135         getContentPane().add(jLabel1, gridBagConstraints);
136
137         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
138
139         jButtonOK.setText("OK");
140         jButtonOK.setMnemonic('o');
141         jButtonOK.setEnabled(false);
142         jButtonOK.addActionListener(new java.awt.event.ActionListener JavaDoc() {
143             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
144                 jButtonOKActionPerformed(evt);
145             }
146         });
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 0, 0, 0);
152         jPanel1.add(jButtonOK, gridBagConstraints);
153
154         jButtonCancel.setText("Cancel");
155         jButtonCancel.setMnemonic('c');
156         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
157             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
158                 jButtonCancelActionPerformed(evt);
159             }
160         });
161
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
167         gridBagConstraints.weightx = 1.0;
168         gridBagConstraints.weighty = 1.0;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
170         jPanel1.add(jButtonCancel, gridBagConstraints);
171
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 1;
174         gridBagConstraints.gridy = 0;
175         gridBagConstraints.gridheight = 2;
176         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
178         gridBagConstraints.weightx = 1.0;
179         gridBagConstraints.weighty = 1.0;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
181         getContentPane().add(jPanel1, gridBagConstraints);
182
183         pack();
184     }// </editor-fold>//GEN-END:initComponents
185

186     private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
187
this.setDialogResult(JOptionPane.CANCEL_OPTION);
188         this.setVisible(false);
189         this.dispose();
190     }//GEN-LAST:event_jButtonCancelActionPerformed
191

192     private void jListConnectionsValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_jListConnectionsValueChanged
193
if (jListConnections.getSelectedValue() != null)
194             jButtonOK.setEnabled(true);
195         else
196             jButtonOK.setEnabled(false);
197     }//GEN-LAST:event_jListConnectionsValueChanged
198

199     private void jButtonOKActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonOKActionPerformed
200
iReportConnection = (IReportConnection)jListConnections.getSelectedValue();
201        this.setVisible(false);
202        this.setDialogResult(JOptionPane.OK_OPTION);
203        this.dispose();
204     }//GEN-LAST:event_jButtonOKActionPerformed
205

206     /** Closes the dialog */
207     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
208
setVisible(false);
209         this.setDialogResult(JOptionPane.CLOSED_OPTION);
210         dispose();
211     }//GEN-LAST:event_closeDialog
212

213     /**
214      * @param args the command line arguments
215      */

216     public static void main(String JavaDoc args[]) {
217         new ActiveConnectionDialog(new javax.swing.JFrame JavaDoc(), true).setVisible(true);
218     }
219     
220     /** Getter for property iReportConnection.
221      * @return Value of property iReportConnection.
222      *
223      */

224     public IReportConnection getIReportConnection() {
225         return iReportConnection;
226     }
227     
228     /** Setter for property iReportConnection.
229      * @param iReportConnection New value of property iReportConnection.
230      *
231      */

232     public void setIReportConnection(IReportConnection iReportConnection) {
233         this.iReportConnection = iReportConnection;
234     }
235     
236     /** Getter for property dialogResult.
237      * @return Value of property dialogResult.
238      *
239      */

240     public int getDialogResult() {
241         return dialogResult;
242     }
243     
244     /** Setter for property dialogResult.
245      * @param dialogResult New value of property dialogResult.
246      *
247      */

248     public void setDialogResult(int dialogResult) {
249         this.dialogResult = dialogResult;
250     }
251     
252     // Variables declaration - do not modify//GEN-BEGIN:variables
253
private javax.swing.JButton JavaDoc jButtonCancel;
254     private javax.swing.JButton JavaDoc jButtonOK;
255     private javax.swing.JLabel JavaDoc jLabel1;
256     private javax.swing.JList JavaDoc jListConnections;
257     private javax.swing.JPanel JavaDoc jPanel1;
258     private javax.swing.JScrollPane JavaDoc jScrollPane1;
259     // End of variables declaration//GEN-END:variables
260

261     private IReportConnection iReportConnection;
262     
263     private int dialogResult;
264     
265     public void applyI18n(){
266                 // Start autogenerated code ----------------------
267
jButtonCancel.setText(I18n.getString("activeConnectionDialog.buttonCancel","Cancel"));
268                 jButtonOK.setText(I18n.getString("activeConnectionDialog.buttonOK","OK"));
269                 jLabel1.setText(I18n.getString("activeConnectionDialog.label1","Available connections"));
270                 // End autogenerated code ----------------------
271
}
272 }
273
Popular Tags