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: * ReportSeriesDialog.java
028: *
029: * Created on 29 settembre 2004, 0.56
030: *
031: */
032:
033: package it.businesslogic.ireport.chart.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 ReportSeriesDialog extends javax.swing.JDialog {
049:
050: private int dialogResult = javax.swing.JOptionPane.OK_OPTION;
051: private JReportFrame jReportFrame = null;
052:
053: /** Creates new form IReportChartDialog */
054: public ReportSeriesDialog(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:
084: //to make the default button ...
085: this .getRootPane().setDefaultButton(this .jButtonClose);
086:
087: }
088:
089: public ReportSeriesDialog(java.awt.Frame parent, boolean modal) {
090: super (parent, modal);
091: initComponents();
092: initFrame();
093:
094: }
095:
096: public void updateSeriesList() {
097:
098: Vector values = new Vector();
099:
100: javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel) jList1
101: .getModel();
102: dlm.removeAllElements();
103:
104: if (getJReportFrame() == null) {
105: jList1.updateUI();
106: return;
107: }
108:
109: // Look for variables that starts with SERIE_
110:
111: Enumeration var_enum = getJReportFrame().getReport()
112: .getVariables().elements();
113: while (var_enum.hasMoreElements()) {
114: JRVariable var = (JRVariable) var_enum.nextElement();
115: if (var.getName().startsWith("SERIE_")) {
116: dlm.addElement(var);
117: }
118: }
119: jList1.updateUI();
120: }
121:
122: public JReportFrame getJReportFrame() {
123:
124: return jReportFrame;
125: }
126:
127: public void setJReportFrame(JReportFrame jReportFrame) {
128:
129: this .jReportFrame = jReportFrame;
130: updateSeriesList();
131: }
132:
133: public int getDialogResult() {
134: return dialogResult;
135: }
136:
137: public void setDialogResult(int dialogResult) {
138: this .dialogResult = dialogResult;
139: }
140:
141: /** This method is called from within the constructor to
142: * initialize the form.
143: * WARNING: Do NOT modify this code. The content of this method is
144: * always regenerated by the Form Editor.
145: */
146: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
147: private void initComponents() {
148: java.awt.GridBagConstraints gridBagConstraints;
149:
150: jPanelData = new javax.swing.JPanel();
151: jScrollPane3 = new javax.swing.JScrollPane();
152: jList1 = new javax.swing.JList();
153: jPanel2 = new javax.swing.JPanel();
154: jButtonNewSerie = new javax.swing.JButton();
155: jButtonModifySerie = new javax.swing.JButton();
156: jButtonDeleteSerie = new javax.swing.JButton();
157: jPanel3 = new javax.swing.JPanel();
158: jButtonClose = new javax.swing.JButton();
159:
160: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
161: setTitle("Report Series");
162: jPanelData.setLayout(new java.awt.GridBagLayout());
163:
164: jList1
165: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
166: public void valueChanged(
167: javax.swing.event.ListSelectionEvent evt) {
168: jList1ValueChanged(evt);
169: }
170: });
171:
172: jScrollPane3.setViewportView(jList1);
173:
174: gridBagConstraints = new java.awt.GridBagConstraints();
175: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
176: gridBagConstraints.weightx = 1.0;
177: gridBagConstraints.weighty = 1.0;
178: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
179: jPanelData.add(jScrollPane3, gridBagConstraints);
180:
181: jPanel2.setLayout(new java.awt.GridBagLayout());
182:
183: jPanel2.setMinimumSize(new java.awt.Dimension(100, 151));
184: jPanel2.setPreferredSize(new java.awt.Dimension(140, 100));
185: jButtonNewSerie.setText("New serie");
186: jButtonNewSerie
187: .addActionListener(new java.awt.event.ActionListener() {
188: public void actionPerformed(
189: java.awt.event.ActionEvent evt) {
190: jButtonNewSerieActionPerformed(evt);
191: }
192: });
193:
194: gridBagConstraints = new java.awt.GridBagConstraints();
195: gridBagConstraints.gridx = 0;
196: gridBagConstraints.gridy = 1;
197: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
198: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
199: gridBagConstraints.weightx = 1.0;
200: jPanel2.add(jButtonNewSerie, gridBagConstraints);
201:
202: jButtonModifySerie.setEnabled(false);
203: jButtonModifySerie.setLabel("Modify serie");
204: jButtonModifySerie
205: .addActionListener(new java.awt.event.ActionListener() {
206: public void actionPerformed(
207: java.awt.event.ActionEvent evt) {
208: jButtonModifySerieActionPerformed(evt);
209: }
210: });
211:
212: gridBagConstraints = new java.awt.GridBagConstraints();
213: gridBagConstraints.gridx = 0;
214: gridBagConstraints.gridy = 2;
215: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
216: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
217: gridBagConstraints.weightx = 1.0;
218: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
219: jPanel2.add(jButtonModifySerie, gridBagConstraints);
220:
221: jButtonDeleteSerie.setEnabled(false);
222: jButtonDeleteSerie.setLabel("Remove serie");
223: jButtonDeleteSerie
224: .addActionListener(new java.awt.event.ActionListener() {
225: public void actionPerformed(
226: java.awt.event.ActionEvent evt) {
227: jButtonDeleteSerieActionPerformed(evt);
228: }
229: });
230:
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.gridx = 0;
233: gridBagConstraints.gridy = 3;
234: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
235: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
236: gridBagConstraints.weightx = 1.0;
237: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
238: jPanel2.add(jButtonDeleteSerie, gridBagConstraints);
239:
240: gridBagConstraints = new java.awt.GridBagConstraints();
241: gridBagConstraints.gridx = 0;
242: gridBagConstraints.gridy = 10;
243: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
244: gridBagConstraints.weightx = 1.0;
245: gridBagConstraints.weighty = 1.0;
246: jPanel2.add(jPanel3, gridBagConstraints);
247:
248: jButtonClose.setText("Close");
249: jButtonClose
250: .addActionListener(new java.awt.event.ActionListener() {
251: public void actionPerformed(
252: java.awt.event.ActionEvent evt) {
253: jButtonCloseActionPerformed(evt);
254: }
255: });
256:
257: gridBagConstraints = new java.awt.GridBagConstraints();
258: gridBagConstraints.gridx = 0;
259: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
260: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
261: gridBagConstraints.weightx = 1.0;
262: jPanel2.add(jButtonClose, gridBagConstraints);
263:
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
266: gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4);
267: jPanelData.add(jPanel2, gridBagConstraints);
268:
269: getContentPane().add(jPanelData, java.awt.BorderLayout.CENTER);
270:
271: pack();
272: }// </editor-fold>//GEN-END:initComponents
273:
274: private void jButtonDeleteSerieActionPerformed(
275: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteSerieActionPerformed
276:
277: Object[] vars = jList1.getSelectedValues();
278:
279: for (int i = 0; i < vars.length; ++i) {
280: JRVariable var = (JRVariable) vars[i];
281: this .getJReportFrame().getReport().removeVariable(var);
282: }
283:
284: this .updateSeriesList();
285: this .getJReportFrame().getMainFrame().getValuesDialog()
286: .getValuesPanel().updateVariables();
287:
288: }//GEN-LAST:event_jButtonDeleteSerieActionPerformed
289:
290: private void jButtonModifySerieActionPerformed(
291: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifySerieActionPerformed
292:
293: SerieDialog sd = new SerieDialog(this , true);
294: sd.setJrf(this .getJReportFrame());
295: JRVariable var = (JRVariable) jList1.getSelectedValue();
296: sd.setVariable(var);
297: sd.setVisible(true);
298: if (sd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
299: String var_name = "SERIE_";
300: if (!sd.getSerieReset().equals("")) {
301: var_name += "G_" + sd.getSerieReset() + "_";
302: }
303: var_name += sd.getSerieName();
304:
305: var.setName(var_name);
306: var.setResetType("Report");
307: var.setCalculation("Nothing");
308: var.setClassType(sd.getSerieType());
309: var.setExpression(sd.getSerieExpression());
310:
311: this .updateSeriesList();
312: this .getJReportFrame().getMainFrame().getValuesDialog()
313: .getValuesPanel().updateVariables();
314: }
315:
316: }//GEN-LAST:event_jButtonModifySerieActionPerformed
317:
318: private void jButtonNewSerieActionPerformed(
319: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewSerieActionPerformed
320:
321: SerieDialog sd = new SerieDialog(this , true);
322: sd.setJrf(this .getJReportFrame());
323: sd.setVisible(true);
324: if (sd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
325: String var_name = "SERIE_";
326: if (!sd.getSerieReset().equals("")) {
327: var_name += "G_" + sd.getSerieReset() + "_";
328: }
329: var_name += sd.getSerieName();
330:
331: JRVariable var = new JRVariable(var_name, false);
332: var.setResetType("Report");
333: var.setCalculation("Nothing");
334: var.setClassType(sd.getSerieType());
335: var.setExpression(sd.getSerieExpression());
336: this .getJReportFrame().getReport().addVariable(var);
337:
338: this .updateSeriesList();
339: this .getJReportFrame().getMainFrame().getValuesDialog()
340: .getValuesPanel().updateVariables();
341: }
342:
343: }//GEN-LAST:event_jButtonNewSerieActionPerformed
344:
345: private void jList1ValueChanged(
346: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
347:
348: if (this .jList1.getSelectedIndex() >= 0) {
349: this .jButtonModifySerie.setEnabled(true);
350: this .jButtonDeleteSerie.setEnabled(true);
351: } else {
352: this .jButtonModifySerie.setEnabled(false);
353: this .jButtonDeleteSerie.setEnabled(false);
354: }
355:
356: }//GEN-LAST:event_jList1ValueChanged
357:
358: private void jButtonCloseActionPerformed(
359: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
360:
361: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
362: this .setVisible(false);
363: }//GEN-LAST:event_jButtonCloseActionPerformed
364:
365: // Variables declaration - do not modify//GEN-BEGIN:variables
366: private javax.swing.JButton jButtonClose;
367: private javax.swing.JButton jButtonDeleteSerie;
368: private javax.swing.JButton jButtonModifySerie;
369: private javax.swing.JButton jButtonNewSerie;
370: private javax.swing.JList jList1;
371: private javax.swing.JPanel jPanel2;
372: private javax.swing.JPanel jPanel3;
373: private javax.swing.JPanel jPanelData;
374: private javax.swing.JScrollPane jScrollPane3;
375:
376: // End of variables declaration//GEN-END:variables
377:
378: public void applyI18n() {
379: // Start autogenerated code ----------------------
380: jButtonClose.setText(I18n.getString(
381: "reportSeriesDialog.buttonClose", "Close"));
382: jButtonNewSerie.setText(I18n.getString(
383: "reportSeriesDialog.buttonNewSerie", "New serie"));
384: // End autogenerated code ----------------------
385:
386: this .setTitle(I18n.getString("reportSeriesDialog.title",
387: "Report Series"));
388: jButtonModifySerie
389: .setText(I18n.getString(
390: "reportSeriesDialog.buttonModifySerie",
391: "Modify serie"));
392: jButtonDeleteSerie
393: .setText(I18n.getString(
394: "reportSeriesDialog.buttonRemoveSerie",
395: "Remove serie"));
396: }
397: }
|