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: * CustomExpressionsDialog.java
028: *
029: * Created on 22 aprile 2005, 18.05
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.ExpressionContext;
036: import javax.swing.DefaultListModel;
037: import java.util.*;
038: import javax.swing.JOptionPane;
039: import it.businesslogic.ireport.util.I18n;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class CustomExpressionsDialog extends javax.swing.JDialog {
046:
047: private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION;
048: private boolean modifiedPath = false;
049:
050: /** Creates new form ClassPathDialog */
051: public CustomExpressionsDialog(java.awt.Frame parent, boolean modal) {
052: super (parent, modal);
053: initComponents();
054:
055: jList1.setModel(new DefaultListModel());
056: it.businesslogic.ireport.util.Misc.centerFrame(this );
057: /*
058: for (int i=0; i<ExpressionEditor.defaultExpressions.length; ++i)
059: {
060: ( (DefaultListModel)jList1.getModel()).addElement( ExpressionEditor.defaultExpressions[i] );
061: }
062: */
063: jList1ValueChanged(null);
064: applyI18n();
065: }
066:
067: /** This method is called from within the constructor to
068: * initialize the form.
069: * WARNING: Do NOT modify this code. The content of this method is
070: * always regenerated by the Form Editor.
071: */
072: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
073: private void initComponents() {
074: java.awt.GridBagConstraints gridBagConstraints;
075:
076: jLabelClasspath = new javax.swing.JLabel();
077: jScrollPane1 = new javax.swing.JScrollPane();
078: jList1 = new javax.swing.JList();
079: jPanel1 = new javax.swing.JPanel();
080: jButtonAdd = new javax.swing.JButton();
081: jButtonAdd1 = new javax.swing.JButton();
082: jButtonRemove = new javax.swing.JButton();
083: jButtonMoveUp = new javax.swing.JButton();
084: jButtonMoveDown = new javax.swing.JButton();
085: jPanel2 = new javax.swing.JPanel();
086: jButtonSave = new javax.swing.JButton();
087: jButtonCancel = new javax.swing.JButton();
088:
089: getContentPane().setLayout(new java.awt.GridBagLayout());
090:
091: setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
092: setTitle(it.businesslogic.ireport.util.I18n.getString(
093: "customExpressions", "Custom expressions"));
094: addWindowListener(new java.awt.event.WindowAdapter() {
095: public void windowClosed(java.awt.event.WindowEvent evt) {
096: formWindowClosed(evt);
097: }
098:
099: public void windowClosing(java.awt.event.WindowEvent evt) {
100: formWindowClosing(evt);
101: }
102: });
103:
104: jLabelClasspath
105: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
106: jLabelClasspath.setText(it.businesslogic.ireport.util.I18n
107: .getString("formulasAndExpressions",
108: "Formulas and expressions"));
109: gridBagConstraints = new java.awt.GridBagConstraints();
110: gridBagConstraints.gridx = 0;
111: gridBagConstraints.gridy = 0;
112: gridBagConstraints.gridwidth = 2;
113: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
114: gridBagConstraints.ipadx = 1;
115: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
116: getContentPane().add(jLabelClasspath, gridBagConstraints);
117:
118: jScrollPane1.setPreferredSize(new java.awt.Dimension(359, 260));
119: jList1
120: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
121: public void valueChanged(
122: javax.swing.event.ListSelectionEvent evt) {
123: jList1ValueChanged(evt);
124: }
125: });
126: jList1.addMouseListener(new java.awt.event.MouseAdapter() {
127: public void mouseClicked(java.awt.event.MouseEvent evt) {
128: jList1MouseClicked(evt);
129: }
130: });
131:
132: jScrollPane1.setViewportView(jList1);
133:
134: gridBagConstraints = new java.awt.GridBagConstraints();
135: gridBagConstraints.gridx = 0;
136: gridBagConstraints.gridy = 1;
137: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
138: gridBagConstraints.weightx = 1.0;
139: gridBagConstraints.weighty = 1.0;
140: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
141: getContentPane().add(jScrollPane1, gridBagConstraints);
142:
143: jPanel1.setLayout(new java.awt.GridBagLayout());
144:
145: jPanel1.setMinimumSize(new java.awt.Dimension(120, 10));
146: jPanel1.setPreferredSize(new java.awt.Dimension(120, 10));
147: jButtonAdd.setText(it.businesslogic.ireport.util.I18n
148: .getString("new", "New"));
149: jButtonAdd.setMaximumSize(new java.awt.Dimension(200, 26));
150: jButtonAdd.setMinimumSize(new java.awt.Dimension(90, 26));
151: jButtonAdd.setPreferredSize(new java.awt.Dimension(120, 26));
152: jButtonAdd
153: .addActionListener(new java.awt.event.ActionListener() {
154: public void actionPerformed(
155: java.awt.event.ActionEvent evt) {
156: jButtonAddActionPerformed(evt);
157: }
158: });
159:
160: gridBagConstraints = new java.awt.GridBagConstraints();
161: gridBagConstraints.gridx = 0;
162: gridBagConstraints.gridy = 0;
163: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
164: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
165: jPanel1.add(jButtonAdd, gridBagConstraints);
166:
167: jButtonAdd1.setText(it.businesslogic.ireport.util.I18n
168: .getString("modify", "Modify"));
169: jButtonAdd1.setMaximumSize(new java.awt.Dimension(200, 26));
170: jButtonAdd1.setMinimumSize(new java.awt.Dimension(90, 26));
171: jButtonAdd1.setPreferredSize(new java.awt.Dimension(120, 26));
172: jButtonAdd1
173: .addActionListener(new java.awt.event.ActionListener() {
174: public void actionPerformed(
175: java.awt.event.ActionEvent evt) {
176: jButtonAddActionPerformed1(evt);
177: }
178: });
179:
180: gridBagConstraints = new java.awt.GridBagConstraints();
181: gridBagConstraints.gridx = 0;
182: gridBagConstraints.gridy = 1;
183: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
184: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
185: jPanel1.add(jButtonAdd1, gridBagConstraints);
186:
187: jButtonRemove.setText(it.businesslogic.ireport.util.I18n
188: .getString("remove", "Remove"));
189: jButtonRemove.setMaximumSize(new java.awt.Dimension(200, 26));
190: jButtonRemove.setMinimumSize(new java.awt.Dimension(90, 26));
191: jButtonRemove.setPreferredSize(new java.awt.Dimension(120, 26));
192: jButtonRemove
193: .addActionListener(new java.awt.event.ActionListener() {
194: public void actionPerformed(
195: java.awt.event.ActionEvent evt) {
196: jButtonRemoveActionPerformed(evt);
197: }
198: });
199:
200: gridBagConstraints = new java.awt.GridBagConstraints();
201: gridBagConstraints.gridx = 0;
202: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
204: jPanel1.add(jButtonRemove, gridBagConstraints);
205:
206: jButtonMoveUp.setText(it.businesslogic.ireport.util.I18n
207: .getString("moveUp", "Move up"));
208: jButtonMoveUp.setMaximumSize(new java.awt.Dimension(200, 26));
209: jButtonMoveUp.setMinimumSize(new java.awt.Dimension(90, 26));
210: jButtonMoveUp.setPreferredSize(new java.awt.Dimension(120, 26));
211: jButtonMoveUp
212: .addActionListener(new java.awt.event.ActionListener() {
213: public void actionPerformed(
214: java.awt.event.ActionEvent evt) {
215: jButtonMoveUpActionPerformed(evt);
216: }
217: });
218:
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
223: jPanel1.add(jButtonMoveUp, gridBagConstraints);
224: jButtonMoveDown.setText(it.businesslogic.ireport.util.I18n
225: .getString("moveDown", "Move down"));
226: jButtonMoveDown.setMaximumSize(new java.awt.Dimension(200, 26));
227: jButtonMoveDown.setMinimumSize(new java.awt.Dimension(90, 26));
228: jButtonMoveDown
229: .setPreferredSize(new java.awt.Dimension(120, 26));
230: jButtonMoveDown
231: .addActionListener(new java.awt.event.ActionListener() {
232: public void actionPerformed(
233: java.awt.event.ActionEvent evt) {
234: jButtonMoveDownActionPerformed(evt);
235: }
236: });
237:
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 0;
240: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
241: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
242: jPanel1.add(jButtonMoveDown, gridBagConstraints);
243:
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridx = 0;
246: gridBagConstraints.weighty = 1.0;
247: jPanel1.add(jPanel2, gridBagConstraints);
248:
249: jButtonSave.setText(it.businesslogic.ireport.util.I18n
250: .getString("save", "Save"));
251: jButtonSave.setMaximumSize(new java.awt.Dimension(200, 26));
252: jButtonSave.setMinimumSize(new java.awt.Dimension(90, 26));
253: jButtonSave.setPreferredSize(new java.awt.Dimension(120, 26));
254: jButtonSave
255: .addActionListener(new java.awt.event.ActionListener() {
256: public void actionPerformed(
257: java.awt.event.ActionEvent evt) {
258: jButtonSaveActionPerformed(evt);
259: }
260: });
261:
262: gridBagConstraints = new java.awt.GridBagConstraints();
263: gridBagConstraints.gridx = 0;
264: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
266: jPanel1.add(jButtonSave, gridBagConstraints);
267:
268: jButtonCancel.setText(it.businesslogic.ireport.util.I18n
269: .getString("cancel", "Cancel"));
270: jButtonCancel.setMaximumSize(new java.awt.Dimension(200, 26));
271: jButtonCancel.setMinimumSize(new java.awt.Dimension(90, 26));
272: jButtonCancel.setPreferredSize(new java.awt.Dimension(120, 26));
273: jButtonCancel
274: .addActionListener(new java.awt.event.ActionListener() {
275: public void actionPerformed(
276: java.awt.event.ActionEvent evt) {
277: jButtonCancelActionPerformed(evt);
278: }
279: });
280:
281: gridBagConstraints = new java.awt.GridBagConstraints();
282: gridBagConstraints.gridx = 0;
283: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
284: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
285: jPanel1.add(jButtonCancel, gridBagConstraints);
286:
287: gridBagConstraints = new java.awt.GridBagConstraints();
288: gridBagConstraints.gridx = 1;
289: gridBagConstraints.gridy = 1;
290: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
291: gridBagConstraints.weighty = 1.0;
292: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 4);
293: getContentPane().add(jPanel1, gridBagConstraints);
294:
295: pack();
296: }// </editor-fold>//GEN-END:initComponents
297:
298: private void jList1ValueChanged(
299: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
300:
301: if (jList1.getSelectedIndex() >= 0) {
302: jButtonAdd1.setEnabled(true);
303: jButtonRemove.setEnabled(true);
304: jButtonMoveUp.setEnabled(jList1.getSelectedIndex() > 0);
305: jButtonMoveDown
306: .setEnabled(jList1.getSelectedIndex() < ((DefaultListModel) jList1
307: .getModel()).size() - 1);
308: } else {
309: jButtonAdd1.setEnabled(false);
310: jButtonRemove.setEnabled(false);
311: jButtonMoveUp.setEnabled(false);
312: jButtonMoveDown.setEnabled(false);
313: }
314:
315: }//GEN-LAST:event_jList1ValueChanged
316:
317: private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
318:
319: if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
320: jButtonAddActionPerformed1(null);
321: }
322:
323: }//GEN-LAST:event_jList1MouseClicked
324:
325: private void jButtonAddActionPerformed1(
326: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed1
327:
328: if (jList1.getSelectedIndex() < 0)
329: return;
330:
331: ExpressionEditor ed = new ExpressionEditor();
332: ed.setExpression("" + jList1.getSelectedValue());
333: ed.setExpressionContext(new ExpressionContext());
334: ed.setVisible(true);
335:
336: if (ed.getDialogResult() == JOptionPane.OK_OPTION) {
337: int i = jList1.getSelectedIndex();
338: ((DefaultListModel) jList1.getModel()).setElementAt(ed
339: .getExpression(), i);
340: }
341: }//GEN-LAST:event_jButtonAddActionPerformed1
342:
343: private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
344:
345: }//GEN-LAST:event_formWindowClosed
346:
347: private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
348:
349: if (modifiedPath) {
350: int ret = javax.swing.JOptionPane
351: .showConfirmDialog(
352: this ,
353: I18n
354: .getString(
355: "messages.customExpressionsDialog.saveList",
356: "Do you want save the list ?"));
357:
358: if (ret == javax.swing.JOptionPane.CANCEL_OPTION) {
359: return;
360: }
361:
362: if (ret == javax.swing.JOptionPane.OK_OPTION) {
363: setDialogResult(javax.swing.JOptionPane.OK_OPTION);
364: }
365: }
366: setVisible(false);
367: }//GEN-LAST:event_formWindowClosing
368:
369: private void jButtonCancelActionPerformed(
370: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
371: setVisible(false);
372: }//GEN-LAST:event_jButtonCancelActionPerformed
373:
374: private void jButtonSaveActionPerformed(
375: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
376: setDialogResult(javax.swing.JOptionPane.OK_OPTION);
377: setVisible(false);
378: }//GEN-LAST:event_jButtonSaveActionPerformed
379:
380: private void jButtonMoveUpActionPerformed(
381: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveUpActionPerformed
382:
383: if (jList1.getSelectedValues() != null) {
384: int[] indices = jList1.getSelectedIndices();
385: for (int i = 0; i < indices.length; ++i) {
386: if (indices[i] == 0)
387: continue;
388: Object val = ((DefaultListModel) jList1.getModel())
389: .remove(indices[i]);
390: ((DefaultListModel) jList1.getModel()).insertElementAt(
391: val, indices[i] - 1);
392: indices[i]--;
393: }
394: jList1.setSelectedIndices(indices);
395: modifiedPath = true;
396: }
397:
398: }//GEN-LAST:event_jButtonMoveUpActionPerformed
399:
400: private void jButtonMoveDownActionPerformed(
401: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveDownActionPerformed
402: if (jList1.getSelectedValues() != null) {
403: int[] indices = jList1.getSelectedIndices();
404: for (int i = indices.length - 1; i >= 0; --i) {
405: if (indices[i] >= ((DefaultListModel) jList1.getModel())
406: .size() - 1)
407: continue;
408:
409: Object val = ((DefaultListModel) jList1.getModel())
410: .remove(indices[i]);
411: ((DefaultListModel) jList1.getModel()).insertElementAt(
412: val, indices[i] + 1);
413: indices[i]++;
414: }
415: jList1.setSelectedIndices(indices);
416: modifiedPath = true;
417: }
418: }//GEN-LAST:event_jButtonMoveDownActionPerformed
419:
420: private void jButtonRemoveActionPerformed(
421: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveActionPerformed
422:
423: if (jList1.getSelectedValues() != null) {
424: Object[] values = jList1.getSelectedValues();
425: for (int i = 0; i < values.length; ++i) {
426: ((DefaultListModel) jList1.getModel())
427: .removeElement(values[i]);
428: }
429: modifiedPath = true;
430: }
431: }//GEN-LAST:event_jButtonRemoveActionPerformed
432:
433: private void jButtonAddActionPerformed(
434: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed
435:
436: ExpressionEditor ed = new ExpressionEditor();
437: ed.setExpression("");
438: ed.setExpressionContext(new ExpressionContext());
439: ed.setVisible(true);
440:
441: if (ed.getDialogResult() == JOptionPane.OK_OPTION) {
442: ((DefaultListModel) jList1.getModel()).addElement(ed
443: .getExpression());
444: }
445:
446: }//GEN-LAST:event_jButtonAddActionPerformed
447:
448: /**
449: * @param args the command line arguments
450: */
451: public static void main(String args[]) {
452: java.awt.EventQueue.invokeLater(new Runnable() {
453: public void run() {
454: new ClassPathDialog(new javax.swing.JFrame(), true)
455: .setVisible(true);
456: }
457: });
458: }
459:
460: public void setExpressions(Vector cp) {
461: for (int i = 0; i < cp.size(); ++i) {
462: ((DefaultListModel) jList1.getModel()).addElement(cp
463: .elementAt(i));
464: }
465: if (((DefaultListModel) jList1.getModel()).size() > 0) {
466: jList1.setSelectedIndex(0);
467: }
468: }
469:
470: public Vector getExpressions() {
471: Vector cp = new Vector();
472: for (int i = 0; i < ((DefaultListModel) jList1.getModel())
473: .size(); ++i) {
474: cp.addElement(""
475: + ((DefaultListModel) jList1.getModel())
476: .elementAt(i));
477: }
478:
479: return cp;
480: }
481:
482: public int getDialogResult() {
483: return dialogResult;
484: }
485:
486: public void setDialogResult(int dialogResult) {
487: this .dialogResult = dialogResult;
488: }
489:
490: // Variables declaration - do not modify//GEN-BEGIN:variables
491: private javax.swing.JButton jButtonAdd;
492: private javax.swing.JButton jButtonAdd1;
493: private javax.swing.JButton jButtonCancel;
494: private javax.swing.JButton jButtonMoveDown;
495: private javax.swing.JButton jButtonMoveUp;
496: private javax.swing.JButton jButtonRemove;
497: private javax.swing.JButton jButtonSave;
498: private javax.swing.JLabel jLabelClasspath;
499: private javax.swing.JList jList1;
500: private javax.swing.JPanel jPanel1;
501: private javax.swing.JPanel jPanel2;
502: private javax.swing.JScrollPane jScrollPane1;
503:
504: // End of variables declaration//GEN-END:variables
505:
506: public void applyI18n() {
507: // Start autogenerated code ----------------------
508: // End autogenerated code ----------------------
509: }
510: }
|