001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * ActiveConnectionDialog.java
028: *
029: * Created on 5 giugno 2003, 23.40
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.util.*;
037:
038: import javax.swing.*;
039: import java.util.*;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class ActiveConnectionDialog extends javax.swing.JDialog {
046:
047: /** Creates new form ActiveConnectionDialog */
048: public ActiveConnectionDialog(java.awt.Frame parent, boolean modal) {
049: super (parent, modal);
050: initComponents();
051: applyI18n();
052: Misc.centerFrame(this );
053:
054: DefaultListModel lm = new DefaultListModel();
055: this .jListConnections.setModel(lm);
056:
057: Enumeration e = ((MainFrame) parent).getConnections()
058: .elements();
059:
060: while (e.hasMoreElements()) {
061: lm.addElement(e.nextElement());
062: }
063:
064: if (((MainFrame) parent).getProperties().get(
065: "DefaultConnection") != null) {
066: jListConnections.setSelectedValue(((MainFrame) parent)
067: .getProperties().get("DefaultConnection"), true);
068: }
069:
070: javax.swing.KeyStroke escape = javax.swing.KeyStroke
071: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
072: false);
073: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
074: public void actionPerformed(java.awt.event.ActionEvent e) {
075: jButtonCancelActionPerformed(e);
076: }
077: };
078:
079: getRootPane().getInputMap(
080: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
081: escape, "ESCAPE");
082: getRootPane().getActionMap().put("ESCAPE", escapeAction);
083:
084: //to make the default button ...
085: this .getRootPane().setDefaultButton(this .jButtonOK);
086: }
087:
088: /** This method is called from within the constructor to
089: * initialize the form.
090: * WARNING: Do NOT modify this code. The content of this method is
091: * always regenerated by the Form Editor.
092: */
093: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
094: private void initComponents() {
095: java.awt.GridBagConstraints gridBagConstraints;
096:
097: jScrollPane1 = new javax.swing.JScrollPane();
098: jListConnections = new javax.swing.JList();
099: jLabel1 = new javax.swing.JLabel();
100: jPanel1 = new javax.swing.JPanel();
101: jButtonOK = new javax.swing.JButton();
102: jButtonCancel = new javax.swing.JButton();
103:
104: getContentPane().setLayout(new java.awt.GridBagLayout());
105:
106: setTitle("Set active connection...");
107: setResizable(false);
108: setModal(true);
109: addWindowListener(new java.awt.event.WindowAdapter() {
110: public void windowClosing(java.awt.event.WindowEvent evt) {
111: closeDialog(evt);
112: }
113: });
114:
115: jListConnections
116: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
117: public void valueChanged(
118: javax.swing.event.ListSelectionEvent evt) {
119: jListConnectionsValueChanged(evt);
120: }
121: });
122:
123: jScrollPane1.setViewportView(jListConnections);
124:
125: gridBagConstraints = new java.awt.GridBagConstraints();
126: gridBagConstraints.gridx = 0;
127: gridBagConstraints.gridy = 1;
128: gridBagConstraints.gridheight = 3;
129: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
130: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
131: gridBagConstraints.weightx = 1000.0;
132: gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
133: getContentPane().add(jScrollPane1, gridBagConstraints);
134:
135: jLabel1.setText("Available connections");
136: gridBagConstraints = new java.awt.GridBagConstraints();
137: gridBagConstraints.gridx = 0;
138: gridBagConstraints.gridy = 0;
139: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
141: gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
142: getContentPane().add(jLabel1, gridBagConstraints);
143:
144: jPanel1.setLayout(new java.awt.GridBagLayout());
145:
146: jButtonOK.setText("OK");
147: jButtonOK.setMnemonic('o');
148: jButtonOK.setEnabled(false);
149: jButtonOK
150: .addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(
152: java.awt.event.ActionEvent evt) {
153: jButtonOKActionPerformed(evt);
154: }
155: });
156:
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
160: gridBagConstraints.insets = new java.awt.Insets(3, 0, 0, 0);
161: jPanel1.add(jButtonOK, gridBagConstraints);
162:
163: jButtonCancel.setText("Cancel");
164: jButtonCancel.setMnemonic('c');
165: jButtonCancel
166: .addActionListener(new java.awt.event.ActionListener() {
167: public void actionPerformed(
168: java.awt.event.ActionEvent evt) {
169: jButtonCancelActionPerformed(evt);
170: }
171: });
172:
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 1;
176: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
177: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
178: gridBagConstraints.weightx = 1.0;
179: gridBagConstraints.weighty = 1.0;
180: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
181: jPanel1.add(jButtonCancel, gridBagConstraints);
182:
183: gridBagConstraints = new java.awt.GridBagConstraints();
184: gridBagConstraints.gridx = 1;
185: gridBagConstraints.gridy = 0;
186: gridBagConstraints.gridheight = 2;
187: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
188: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
189: gridBagConstraints.weightx = 1.0;
190: gridBagConstraints.weighty = 1.0;
191: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
192: getContentPane().add(jPanel1, gridBagConstraints);
193:
194: pack();
195: }// </editor-fold>//GEN-END:initComponents
196:
197: private void jButtonCancelActionPerformed(
198: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
199: this .setDialogResult(JOptionPane.CANCEL_OPTION);
200: this .setVisible(false);
201: this .dispose();
202: }//GEN-LAST:event_jButtonCancelActionPerformed
203:
204: private void jListConnectionsValueChanged(
205: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListConnectionsValueChanged
206: if (jListConnections.getSelectedValue() != null)
207: jButtonOK.setEnabled(true);
208: else
209: jButtonOK.setEnabled(false);
210: }//GEN-LAST:event_jListConnectionsValueChanged
211:
212: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
213: iReportConnection = (IReportConnection) jListConnections
214: .getSelectedValue();
215: this .setVisible(false);
216: this .setDialogResult(JOptionPane.OK_OPTION);
217: this .dispose();
218: }//GEN-LAST:event_jButtonOKActionPerformed
219:
220: /** Closes the dialog */
221: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
222: setVisible(false);
223: this .setDialogResult(JOptionPane.CLOSED_OPTION);
224: dispose();
225: }//GEN-LAST:event_closeDialog
226:
227: /**
228: * @param args the command line arguments
229: */
230: public static void main(String args[]) {
231: new ActiveConnectionDialog(new javax.swing.JFrame(), true)
232: .setVisible(true);
233: }
234:
235: /** Getter for property iReportConnection.
236: * @return Value of property iReportConnection.
237: *
238: */
239: public IReportConnection getIReportConnection() {
240: return iReportConnection;
241: }
242:
243: /** Setter for property iReportConnection.
244: * @param iReportConnection New value of property iReportConnection.
245: *
246: */
247: public void setIReportConnection(IReportConnection iReportConnection) {
248: this .iReportConnection = iReportConnection;
249: }
250:
251: /** Getter for property dialogResult.
252: * @return Value of property dialogResult.
253: *
254: */
255: public int getDialogResult() {
256: return dialogResult;
257: }
258:
259: /** Setter for property dialogResult.
260: * @param dialogResult New value of property dialogResult.
261: *
262: */
263: public void setDialogResult(int dialogResult) {
264: this .dialogResult = dialogResult;
265: }
266:
267: // Variables declaration - do not modify//GEN-BEGIN:variables
268: private javax.swing.JButton jButtonCancel;
269: private javax.swing.JButton jButtonOK;
270: private javax.swing.JLabel jLabel1;
271: private javax.swing.JList jListConnections;
272: private javax.swing.JPanel jPanel1;
273: private javax.swing.JScrollPane jScrollPane1;
274: // End of variables declaration//GEN-END:variables
275:
276: private IReportConnection iReportConnection;
277:
278: private int dialogResult;
279:
280: public void applyI18n() {
281: // Start autogenerated code ----------------------
282: jButtonCancel.setText(I18n.getString(
283: "activeConnectionDialog.buttonCancel", "Cancel"));
284: jButtonOK.setText(I18n.getString(
285: "activeConnectionDialog.buttonOK", "OK"));
286: jLabel1.setText(I18n.getString("activeConnectionDialog.label1",
287: "Available connections"));
288: // End autogenerated code ----------------------
289: this .setTitle(I18n.getString("activeConnectionDialog.title",
290: "Set active connection..."));
291: jButtonCancel.setMnemonic(I18n.getString(
292: "activeConnectionDialog.buttonCancelMnemonic", "c")
293: .charAt(0));
294: jButtonOK.setMnemonic(I18n.getString(
295: "activeConnectionDialog.buttonOKMnemonic", "o").charAt(
296: 0));
297: }
298: }
|