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: * JRFieldDialog.java
028: *
029: * Created on 9 maggio 2003, 17.25
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.util.*;
036: import it.businesslogic.ireport.*;
037: import java.util.Iterator;
038: import javax.swing.JOptionPane;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class JRFieldDialog extends javax.swing.JDialog {
045: /** Creates new form JRParameterDialog */
046: JRField tmpField = null;
047: private SubDataset subDataset = null;
048: private String originalName = null;
049: private java.util.List properties = new java.util.ArrayList();
050:
051: public JRFieldDialog(java.awt.Frame parent, boolean modal) {
052: super (parent, modal);
053: initComponents();
054: applyI18n();
055: setClassTypes();
056: this .jComboBoxType.setSelectedItem("java.lang.String");
057:
058: javax.swing.KeyStroke escape = javax.swing.KeyStroke
059: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
060: false);
061: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
062: public void actionPerformed(java.awt.event.ActionEvent e) {
063: jButtonCancelActionPerformed(e);
064: }
065: };
066:
067: getRootPane().getInputMap(
068: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
069: escape, "ESCAPE");
070: getRootPane().getActionMap().put("ESCAPE", escapeAction);
071:
072: //to make the default button ...
073: this .getRootPane().setDefaultButton(this .jButtonOK);
074: }
075:
076: public void setClassTypes() {
077: this .jComboBoxType.addItem("java.lang.String");
078: this .jComboBoxType.addItem("java.lang.Object");
079: this .jComboBoxType.addItem("java.lang.Boolean");
080: this .jComboBoxType.addItem("java.lang.Byte");
081: this .jComboBoxType.addItem("java.util.Date");
082: this .jComboBoxType.addItem("java.sql.Timestamp");
083: this .jComboBoxType.addItem("java.sql.Time");
084: this .jComboBoxType.addItem("java.lang.Double");
085: this .jComboBoxType.addItem("java.lang.Float");
086: this .jComboBoxType.addItem("java.lang.Integer");
087: this .jComboBoxType.addItem("java.io.InputStream");
088: this .jComboBoxType.addItem("java.lang.Long");
089: this .jComboBoxType.addItem("java.lang.Short");
090: this .jComboBoxType.addItem("java.math.BigDecimal");
091: }
092:
093: /** This method is called from within the constructor to
094: * initialize the form.
095: * WARNING: Do NOT modify this code. The content of this method is
096: * always regenerated by the Form Editor.
097: */
098: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
099: private void initComponents() {
100: java.awt.GridBagConstraints gridBagConstraints;
101:
102: jLabel1 = new javax.swing.JLabel();
103: jTextFieldName = new javax.swing.JTextField();
104: jLabel2 = new javax.swing.JLabel();
105: jComboBoxType = new javax.swing.JComboBox();
106: jLabel4 = new javax.swing.JLabel();
107: jScrollPane1 = new javax.swing.JScrollPane();
108: jTextAreaDescription = new javax.swing.JTextArea();
109: jButtonFieldProperties = new javax.swing.JButton();
110: jPanel1 = new javax.swing.JPanel();
111: jSeparator1 = new javax.swing.JSeparator();
112: jButtonOK = new javax.swing.JButton();
113: jButtonCancel = new javax.swing.JButton();
114:
115: getContentPane().setLayout(new java.awt.GridBagLayout());
116:
117: setTitle("Add/modify field");
118: setModal(true);
119: addWindowListener(new java.awt.event.WindowAdapter() {
120: public void windowClosing(java.awt.event.WindowEvent evt) {
121: closeDialog(evt);
122: }
123: });
124:
125: jLabel1.setText("Field name");
126: gridBagConstraints = new java.awt.GridBagConstraints();
127: gridBagConstraints.gridx = 0;
128: gridBagConstraints.gridy = 0;
129: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
130: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
131: getContentPane().add(jLabel1, gridBagConstraints);
132:
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.gridx = 0;
135: gridBagConstraints.gridy = 1;
136: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
138: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
139: getContentPane().add(jTextFieldName, gridBagConstraints);
140:
141: jLabel2.setText("Field class type");
142: gridBagConstraints = new java.awt.GridBagConstraints();
143: gridBagConstraints.gridx = 0;
144: gridBagConstraints.gridy = 2;
145: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
147: getContentPane().add(jLabel2, gridBagConstraints);
148:
149: jComboBoxType.setEditable(true);
150: gridBagConstraints = new java.awt.GridBagConstraints();
151: gridBagConstraints.gridx = 0;
152: gridBagConstraints.gridy = 3;
153: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
155: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
156: getContentPane().add(jComboBoxType, gridBagConstraints);
157:
158: jLabel4.setText("Field description");
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 0;
161: gridBagConstraints.gridy = 4;
162: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
163: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
164: getContentPane().add(jLabel4, gridBagConstraints);
165:
166: jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 80));
167: jScrollPane1.setViewportView(jTextAreaDescription);
168:
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 0;
171: gridBagConstraints.gridy = 6;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
173: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
174: gridBagConstraints.weightx = 1.0;
175: gridBagConstraints.weighty = 1.0;
176: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
177: getContentPane().add(jScrollPane1, gridBagConstraints);
178:
179: jButtonFieldProperties.setText("Ediit field properties...");
180: jButtonFieldProperties
181: .addActionListener(new java.awt.event.ActionListener() {
182: public void actionPerformed(
183: java.awt.event.ActionEvent evt) {
184: jButtonFieldPropertiesActionPerformed(evt);
185: }
186: });
187:
188: gridBagConstraints = new java.awt.GridBagConstraints();
189: gridBagConstraints.gridx = 0;
190: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
191: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
192: getContentPane()
193: .add(jButtonFieldProperties, gridBagConstraints);
194:
195: jPanel1.setLayout(new java.awt.GridBagLayout());
196:
197: jSeparator1.setMinimumSize(new java.awt.Dimension(2, 2));
198: jSeparator1.setPreferredSize(new java.awt.Dimension(2, 2));
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridwidth = 2;
201: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
203: gridBagConstraints.weightx = 1.0;
204: gridBagConstraints.insets = new java.awt.Insets(8, 0, 4, 0);
205: jPanel1.add(jSeparator1, gridBagConstraints);
206:
207: jButtonOK.setMnemonic('o');
208: jButtonOK.setText("OK");
209: jButtonOK
210: .addActionListener(new java.awt.event.ActionListener() {
211: public void actionPerformed(
212: java.awt.event.ActionEvent evt) {
213: jButtonOKActionPerformed(evt);
214: }
215: });
216:
217: gridBagConstraints = new java.awt.GridBagConstraints();
218: gridBagConstraints.gridy = 1;
219: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
220: gridBagConstraints.weightx = 1.0;
221: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
222: jPanel1.add(jButtonOK, gridBagConstraints);
223:
224: jButtonCancel.setMnemonic('c');
225: jButtonCancel.setText("Cancel");
226: jButtonCancel
227: .addActionListener(new java.awt.event.ActionListener() {
228: public void actionPerformed(
229: java.awt.event.ActionEvent evt) {
230: jButtonCancelActionPerformed(evt);
231: }
232: });
233:
234: gridBagConstraints = new java.awt.GridBagConstraints();
235: gridBagConstraints.gridy = 1;
236: jPanel1.add(jButtonCancel, gridBagConstraints);
237:
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 0;
240: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
241: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
242: gridBagConstraints.weightx = 1.0;
243: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
244: getContentPane().add(jPanel1, gridBagConstraints);
245:
246: pack();
247: java.awt.Dimension screenSize = java.awt.Toolkit
248: .getDefaultToolkit().getScreenSize();
249: java.awt.Dimension dialogSize = getSize();
250: setLocation((screenSize.width - dialogSize.width) / 2,
251: (screenSize.height - dialogSize.height) / 2);
252: }// </editor-fold>//GEN-END:initComponents
253:
254: private void jButtonFieldPropertiesActionPerformed(
255: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFieldPropertiesActionPerformed
256:
257: PropertiesDialog pd = new PropertiesDialog(this , true);
258: pd.setProperties(getProperties());
259: pd.setVisible(true);
260:
261: if (pd.getDialogResult() == JOptionPane.OK_OPTION) {
262: this .properties = pd.getProperties();
263: }
264:
265: }//GEN-LAST:event_jButtonFieldPropertiesActionPerformed
266:
267: private void jButtonCancelActionPerformed(
268: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
269: setVisible(false);
270: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
271: dispose();
272: }//GEN-LAST:event_jButtonCancelActionPerformed
273:
274: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
275:
276: if (this .jTextFieldName.getText().trim().length() <= 0) {
277: javax.swing.JOptionPane
278: .showMessageDialog(
279: this ,
280: I18n
281: .getString(
282: "messages.jRFieldDialog.notValidFieldName",
283: "Please insert a valid field name!"),
284: I18n
285: .getString(
286: "messages.jRFieldDialog.notValidFieldNameCaption",
287: "Invalid field!"),
288: javax.swing.JOptionPane.WARNING_MESSAGE);
289: return;
290: }
291:
292: if (getSubDataset() != null) {
293: //check unique name...
294: String newName = this .jTextFieldName.getText();
295: if (getOriginalName() == null
296: || !getOriginalName().equals(newName)) {
297: for (int i = 0; i < getSubDataset().getFields().size(); ++i) {
298: JRField f = (JRField) getSubDataset().getFields()
299: .get(i);
300: if (f.getName().equals(newName)) {
301: javax.swing.JOptionPane
302: .showMessageDialog(
303: this ,
304: I18n
305: .getString(
306: "messages.JRFieldDialog.DuplicatedFieldName",
307: "A field with this name already exists!"),
308: I18n
309: .getString(
310: "messages.JRFieldDialog.notValidFieldNameCaption",
311: "Invalid field!"),
312: javax.swing.JOptionPane.WARNING_MESSAGE);
313: return;
314: }
315: }
316: }
317: }
318:
319: tmpField = new JRField(this .jTextFieldName.getText(),
320: "java.lang.String");
321: tmpField.setProperties(this .properties);
322:
323: if (this .jComboBoxType.getSelectedItem().toString().trim()
324: .length() != 0) {
325: tmpField.setClassType(this .jComboBoxType.getSelectedItem()
326: .toString().trim());
327: }
328: tmpField.setDescription(this .jTextAreaDescription.getText());
329: setVisible(false);
330: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
331: dispose();
332: }//GEN-LAST:event_jButtonOKActionPerformed
333:
334: /** Closes the dialog */
335: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
336: setVisible(false);
337: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
338: dispose();
339: }//GEN-LAST:event_closeDialog
340:
341: /**
342: * @param args the command line arguments
343: */
344: public static void main(String args[]) {
345: new JRParameterDialog(new javax.swing.JFrame(), true)
346: .setVisible(true);
347: }
348:
349: /** Getter for property tmpParameter.
350: * @return Value of property tmpParameter.
351: *
352: */
353: public it.businesslogic.ireport.JRField getField() {
354: return tmpField;
355: }
356:
357: /** Setter for property tmpParameter.
358: * @param tmpParameter New value of property tmpParameter.
359: *
360: */
361: public void setField(it.businesslogic.ireport.JRField tmpField) {
362: originalName = tmpField.getName();
363: this .jTextFieldName.setText(new String(tmpField.getName()));
364: this .jComboBoxType.setSelectedItem(new String(tmpField
365: .getClassType()));
366: this .jTextAreaDescription.setText(new String(tmpField
367: .getDescription()));
368: this .properties = new java.util.ArrayList();
369:
370: Iterator iter = tmpField.getProperties().iterator();
371: while (iter.hasNext()) {
372: JRProperty p = (JRProperty) iter.next();
373: this .properties.add(p.cloneMe());
374: }
375: }
376:
377: /** Getter for property dialogResult.
378: * @return Value of property dialogResult.
379: *
380: */
381: public int getDialogResult() {
382: return dialogResult;
383: }
384:
385: /** Setter for property dialogResult.
386: * @param dialogResult New value of property dialogResult.
387: *
388: */
389: public void setDialogResult(int dialogResult) {
390: this .dialogResult = dialogResult;
391: }
392:
393: // Variables declaration - do not modify//GEN-BEGIN:variables
394: private javax.swing.JButton jButtonCancel;
395: private javax.swing.JButton jButtonFieldProperties;
396: private javax.swing.JButton jButtonOK;
397: private javax.swing.JComboBox jComboBoxType;
398: private javax.swing.JLabel jLabel1;
399: private javax.swing.JLabel jLabel2;
400: private javax.swing.JLabel jLabel4;
401: private javax.swing.JPanel jPanel1;
402: private javax.swing.JScrollPane jScrollPane1;
403: private javax.swing.JSeparator jSeparator1;
404: private javax.swing.JTextArea jTextAreaDescription;
405: private javax.swing.JTextField jTextFieldName;
406: // End of variables declaration//GEN-END:variables
407:
408: private int dialogResult;
409:
410: public void applyI18n() {
411: // Start autogenerated code ----------------------
412: jButtonCancel.setText(I18n.getString(
413: "jRFieldDialog.buttonCancel", "Cancel"));
414: jButtonOK.setText(I18n
415: .getString("jRFieldDialog.buttonOK", "OK"));
416:
417: jButtonFieldProperties.setText(I18n.getString(
418: "jRFieldDialog.buttonFieldProperties",
419: "Edit field properties..."));
420:
421: jLabel1.setText(I18n.getString("jRFieldDialog.label1",
422: "Field name"));
423: jLabel2.setText(I18n.getString("jRFieldDialog.label2",
424: "Field class type"));
425: jLabel4.setText(I18n.getString("jRFieldDialog.label4",
426: "Field description"));
427: // End autogenerated code ----------------------
428: this .setTitle(I18n.getString("jRFieldDialog.title",
429: "Add/modify field"));
430: jButtonCancel.setMnemonic(I18n.getString(
431: "jRFieldDialog.buttonCancelMnemonic", "c").charAt(0));
432: jButtonOK.setMnemonic(I18n.getString(
433: "jRFieldDialog.buttonOKMnemonic", "o").charAt(0));
434: }
435:
436: public SubDataset getSubDataset() {
437: return subDataset;
438: }
439:
440: public void setSubDataset(SubDataset subDataset) {
441: this .subDataset = subDataset;
442: }
443:
444: public String getOriginalName() {
445: return originalName;
446: }
447:
448: public void setOriginalName(String originalName) {
449: this .originalName = originalName;
450: }
451:
452: public java.util.List getProperties() {
453: return properties;
454: }
455:
456: public void setProperties(java.util.List properties) {
457: this.properties = properties;
458: }
459: }
|