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: * ReportImportsDialog.java
028: *
029: * Created on 29 settembre 2004, 0.56
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.gui.*;
036: import it.businesslogic.ireport.*;
037: import javax.swing.tree.*;
038: import javax.swing.table.*;
039: import javax.swing.*;
040: import it.businesslogic.ireport.chart.*;
041: import java.util.*;
042: import it.businesslogic.ireport.util.I18n;
043:
044: /**
045: *
046: * @author Administrator
047: */
048: public class ReportImportsDialog extends javax.swing.JDialog {
049:
050: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
051: private JReportFrame jReportFrame = null;
052:
053: /** Creates new form IReportChartDialog */
054: public ReportImportsDialog(java.awt.Dialog parent, boolean modal) {
055: super (parent, modal);
056: initComponents();
057: initFrame();
058: }
059:
060: public void initFrame() {
061: javax.swing.DefaultListModel dlm = new javax.swing.DefaultListModel();
062: jList1.setModel(dlm);
063: jList1.updateUI();
064:
065: this .setSize(500, 400);
066: it.businesslogic.ireport.util.Misc.centerFrame(this );
067:
068: javax.swing.KeyStroke escape = javax.swing.KeyStroke
069: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
070: false);
071: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
072: public void actionPerformed(java.awt.event.ActionEvent e) {
073: jButtonCloseActionPerformed(e);
074: }
075: };
076:
077: getRootPane().getInputMap(
078: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
079: escape, "ESCAPE");
080: getRootPane().getActionMap().put("ESCAPE", escapeAction);
081:
082: applyI18n();
083: //to make the default button ...
084: this .getRootPane().setDefaultButton(this .jButtonClose);
085:
086: }
087:
088: public ReportImportsDialog(java.awt.Frame parent, boolean modal) {
089: super (parent, modal);
090: initComponents();
091: initFrame();
092:
093: }
094:
095: public void updateImportsList() {
096:
097: Vector values = new Vector();
098:
099: javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel) jList1
100: .getModel();
101: dlm.removeAllElements();
102:
103: if (getJReportFrame() == null) {
104: jList1.updateUI();
105: return;
106: }
107:
108: Enumeration var_enum = getJReportFrame().getReport()
109: .getImports().elements();
110: while (var_enum.hasMoreElements()) {
111: String var = (String) var_enum.nextElement();
112: dlm.addElement(var);
113: }
114: jList1.updateUI();
115: }
116:
117: public JReportFrame getJReportFrame() {
118:
119: return jReportFrame;
120: }
121:
122: public void setJReportFrame(JReportFrame jReportFrame) {
123:
124: this .jReportFrame = jReportFrame;
125: updateImportsList();
126: }
127:
128: public int getDialogResult() {
129: return dialogResult;
130: }
131:
132: public void setDialogResult(int dialogResult) {
133: this .dialogResult = dialogResult;
134: }
135:
136: /** This method is called from within the constructor to
137: * initialize the form.
138: * WARNING: Do NOT modify this code. The content of this method is
139: * always regenerated by the Form Editor.
140: */
141: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
142: private void initComponents() {
143: java.awt.GridBagConstraints gridBagConstraints;
144:
145: jPanelData = new javax.swing.JPanel();
146: jScrollPane3 = new javax.swing.JScrollPane();
147: jList1 = new javax.swing.JList();
148: jPanel2 = new javax.swing.JPanel();
149: jButtonNewImport = new javax.swing.JButton();
150: jButtonModifyImport = new javax.swing.JButton();
151: jButtonDeleteImport = new javax.swing.JButton();
152: jPanel3 = new javax.swing.JPanel();
153: jButtonClose = new javax.swing.JButton();
154:
155: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
156: setTitle("Report Imports");
157: jPanelData.setLayout(new java.awt.GridBagLayout());
158:
159: jList1
160: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
161: public void valueChanged(
162: javax.swing.event.ListSelectionEvent evt) {
163: jList1ValueChanged(evt);
164: }
165: });
166:
167: jScrollPane3.setViewportView(jList1);
168:
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
171: gridBagConstraints.weightx = 1.0;
172: gridBagConstraints.weighty = 1.0;
173: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
174: jPanelData.add(jScrollPane3, gridBagConstraints);
175:
176: jPanel2.setLayout(new java.awt.GridBagLayout());
177:
178: jPanel2.setMinimumSize(new java.awt.Dimension(100, 151));
179: jPanel2.setPreferredSize(new java.awt.Dimension(140, 100));
180: jButtonNewImport.setText("New import");
181: jButtonNewImport
182: .addActionListener(new java.awt.event.ActionListener() {
183: public void actionPerformed(
184: java.awt.event.ActionEvent evt) {
185: jButtonNewImportActionPerformed(evt);
186: }
187: });
188:
189: gridBagConstraints = new java.awt.GridBagConstraints();
190: gridBagConstraints.gridx = 0;
191: gridBagConstraints.gridy = 1;
192: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
194: gridBagConstraints.weightx = 1.0;
195: jPanel2.add(jButtonNewImport, gridBagConstraints);
196:
197: jButtonModifyImport.setText("Modify import");
198: jButtonModifyImport.setEnabled(false);
199: jButtonModifyImport
200: .addActionListener(new java.awt.event.ActionListener() {
201: public void actionPerformed(
202: java.awt.event.ActionEvent evt) {
203: jButtonModifyImportActionPerformed(evt);
204: }
205: });
206:
207: gridBagConstraints = new java.awt.GridBagConstraints();
208: gridBagConstraints.gridx = 0;
209: gridBagConstraints.gridy = 2;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
212: gridBagConstraints.weightx = 1.0;
213: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
214: jPanel2.add(jButtonModifyImport, gridBagConstraints);
215:
216: jButtonDeleteImport.setText("Remove import");
217: jButtonDeleteImport.setEnabled(false);
218: jButtonDeleteImport
219: .addActionListener(new java.awt.event.ActionListener() {
220: public void actionPerformed(
221: java.awt.event.ActionEvent evt) {
222: jButtonDeleteImportActionPerformed(evt);
223: }
224: });
225:
226: gridBagConstraints = new java.awt.GridBagConstraints();
227: gridBagConstraints.gridx = 0;
228: gridBagConstraints.gridy = 3;
229: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
231: gridBagConstraints.weightx = 1.0;
232: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
233: jPanel2.add(jButtonDeleteImport, gridBagConstraints);
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridx = 0;
237: gridBagConstraints.gridy = 10;
238: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
239: gridBagConstraints.weightx = 1.0;
240: gridBagConstraints.weighty = 1.0;
241: jPanel2.add(jPanel3, gridBagConstraints);
242:
243: jButtonClose.setText("Close");
244: jButtonClose
245: .addActionListener(new java.awt.event.ActionListener() {
246: public void actionPerformed(
247: java.awt.event.ActionEvent evt) {
248: jButtonCloseActionPerformed(evt);
249: }
250: });
251:
252: gridBagConstraints = new java.awt.GridBagConstraints();
253: gridBagConstraints.gridx = 0;
254: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
255: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
256: gridBagConstraints.weightx = 1.0;
257: jPanel2.add(jButtonClose, gridBagConstraints);
258:
259: gridBagConstraints = new java.awt.GridBagConstraints();
260: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
261: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4);
262: jPanelData.add(jPanel2, gridBagConstraints);
263:
264: getContentPane().add(jPanelData, java.awt.BorderLayout.CENTER);
265:
266: pack();
267: }// </editor-fold>//GEN-END:initComponents
268:
269: private void jButtonDeleteImportActionPerformed(
270: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteImportActionPerformed
271:
272: Object[] vars = jList1.getSelectedValues();
273:
274: for (int i = 0; i < vars.length; ++i) {
275: String var = (String) vars[i];
276: this .getJReportFrame().getReport().getImports().remove(var);
277: }
278:
279: this .updateImportsList();
280:
281: }//GEN-LAST:event_jButtonDeleteImportActionPerformed
282:
283: private void jButtonModifyImportActionPerformed(
284: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyImportActionPerformed
285:
286: ImportDialog idialog = new ImportDialog(this , true);
287: String var = (String) jList1.getSelectedValue();
288: idialog.setImport(var);
289: idialog.setVisible(true);
290: if (idialog.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
291: this .getJReportFrame().getReport().getImports().remove(var);
292: String var_new = idialog.getImport();
293: if (!this .getJReportFrame().getReport().getImports()
294: .contains(var_new)) {
295: this .getJReportFrame().getReport().getImports().add(
296: var_new);
297: }
298: this .updateImportsList();
299: }
300:
301: }//GEN-LAST:event_jButtonModifyImportActionPerformed
302:
303: private void jButtonNewImportActionPerformed(
304: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewImportActionPerformed
305: ImportDialog idialog = new ImportDialog(this , true);
306: idialog.setVisible(true);
307: if (idialog.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
308: String var_new = idialog.getImport();
309: if (!this .getJReportFrame().getReport().getImports()
310: .contains(var_new)) {
311: this .getJReportFrame().getReport().getImports().add(
312: var_new);
313: }
314: this .updateImportsList();
315: }
316:
317: }//GEN-LAST:event_jButtonNewImportActionPerformed
318:
319: private void jList1ValueChanged(
320: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
321:
322: if (this .jList1.getSelectedIndex() >= 0) {
323: this .jButtonModifyImport.setEnabled(true);
324: this .jButtonDeleteImport.setEnabled(true);
325: } else {
326: this .jButtonModifyImport.setEnabled(false);
327: this .jButtonDeleteImport.setEnabled(false);
328: }
329:
330: }//GEN-LAST:event_jList1ValueChanged
331:
332: private void jButtonCloseActionPerformed(
333: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
334:
335: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
336: this .setVisible(false);
337: }//GEN-LAST:event_jButtonCloseActionPerformed
338:
339: // Variables declaration - do not modify//GEN-BEGIN:variables
340: private javax.swing.JButton jButtonClose;
341: private javax.swing.JButton jButtonDeleteImport;
342: private javax.swing.JButton jButtonModifyImport;
343: private javax.swing.JButton jButtonNewImport;
344: private javax.swing.JList jList1;
345: private javax.swing.JPanel jPanel2;
346: private javax.swing.JPanel jPanel3;
347: private javax.swing.JPanel jPanelData;
348: private javax.swing.JScrollPane jScrollPane3;
349:
350: // End of variables declaration//GEN-END:variables
351:
352: public void applyI18n() {
353: // Start autogenerated code ----------------------
354: jButtonClose.setText(I18n.getString(
355: "reportImportsDialog.buttonClose", "Close"));
356: jButtonDeleteImport.setText(I18n.getString(
357: "reportImportsDialog.buttonDeleteImport",
358: "Remove import"));
359: jButtonModifyImport.setText(I18n.getString(
360: "reportImportsDialog.buttonModifyImport",
361: "Modify import"));
362: jButtonNewImport.setText(I18n.getString(
363: "reportImportsDialog.buttonNewImport", "New import"));
364: // End autogenerated code ----------------------
365: this .setTitle(I18n.getString("reportImportsDialog.title",
366: "Report Imports"));
367: }
368: }
|