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.style;
034:
035: import it.businesslogic.ireport.gui.*;
036: import it.businesslogic.ireport.util.*;
037: import it.businesslogic.ireport.*;
038: import java.util.Iterator;
039: import javax.swing.JOptionPane;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class JRTemplateDialog extends javax.swing.JDialog {
046: /** Creates new form JRParameterDialog */
047: Template tmpTemplate = null;
048:
049: public JRTemplateDialog(java.awt.Frame parent, boolean modal) {
050: super (parent, modal);
051: initComponents();
052: applyI18n();
053: setClassTypes();
054: this .jComboBoxType.setSelectedItem("java.lang.String");
055:
056: javax.swing.KeyStroke escape = javax.swing.KeyStroke
057: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
058: false);
059: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
060: public void actionPerformed(java.awt.event.ActionEvent e) {
061: jButtonCancelActionPerformed(e);
062: }
063: };
064:
065: getRootPane().getInputMap(
066: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
067: escape, "ESCAPE");
068: getRootPane().getActionMap().put("ESCAPE", escapeAction);
069:
070: //to make the default button ...
071: this .getRootPane().setDefaultButton(this .jButtonOK);
072: }
073:
074: public void setClassTypes() {
075: jComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(
076: new String[] { "java.lang.String", "java.io.File",
077: "java.net.URL", "java.io.InputStream",
078: "net.sf.jasperreports.engine.JRTemplate" }));
079: }
080:
081: /** This method is called from within the constructor to
082: * initialize the form.
083: * WARNING: Do NOT modify this code. The content of this method is
084: * always regenerated by the Form Editor.
085: */
086: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
087: private void initComponents() {
088: java.awt.GridBagConstraints gridBagConstraints;
089:
090: jLabel2 = new javax.swing.JLabel();
091: jComboBoxType = new javax.swing.JComboBox();
092: jLabel4 = new javax.swing.JLabel();
093: jRTextExpressionArea = new it.businesslogic.ireport.gui.JRTextExpressionArea();
094: jPanel1 = new javax.swing.JPanel();
095: jSeparator1 = new javax.swing.JSeparator();
096: jButtonOK = new javax.swing.JButton();
097: jButtonCancel = new javax.swing.JButton();
098:
099: setTitle("Add/modify field");
100: setModal(true);
101: addWindowListener(new java.awt.event.WindowAdapter() {
102: public void windowClosing(java.awt.event.WindowEvent evt) {
103: closeDialog(evt);
104: }
105: });
106: getContentPane().setLayout(new java.awt.GridBagLayout());
107:
108: jLabel2.setText("Template expression class");
109: gridBagConstraints = new java.awt.GridBagConstraints();
110: gridBagConstraints.gridx = 0;
111: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
112: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
113: getContentPane().add(jLabel2, gridBagConstraints);
114: gridBagConstraints = new java.awt.GridBagConstraints();
115: gridBagConstraints.gridx = 0;
116: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
117: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
118: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
119: getContentPane().add(jComboBoxType, gridBagConstraints);
120:
121: jLabel4.setText("Template expression");
122: gridBagConstraints = new java.awt.GridBagConstraints();
123: gridBagConstraints.gridx = 0;
124: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
125: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
126: getContentPane().add(jLabel4, gridBagConstraints);
127:
128: jRTextExpressionArea.setBorder(javax.swing.BorderFactory
129: .createEtchedBorder());
130: jRTextExpressionArea.setMinimumSize(new java.awt.Dimension(100,
131: 204));
132: jRTextExpressionArea.setPreferredSize(new java.awt.Dimension(
133: 350, 150));
134: gridBagConstraints = new java.awt.GridBagConstraints();
135: gridBagConstraints.gridx = 0;
136: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
137: gridBagConstraints.weighty = 1.0;
138: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
139: getContentPane().add(jRTextExpressionArea, gridBagConstraints);
140:
141: jPanel1.setLayout(new java.awt.GridBagLayout());
142:
143: jSeparator1.setMinimumSize(new java.awt.Dimension(2, 2));
144: jSeparator1.setPreferredSize(new java.awt.Dimension(2, 2));
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridwidth = 2;
147: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
149: gridBagConstraints.weightx = 1.0;
150: gridBagConstraints.insets = new java.awt.Insets(8, 0, 4, 0);
151: jPanel1.add(jSeparator1, gridBagConstraints);
152:
153: jButtonOK.setMnemonic('o');
154: jButtonOK.setText("OK");
155: jButtonOK
156: .addActionListener(new java.awt.event.ActionListener() {
157: public void actionPerformed(
158: java.awt.event.ActionEvent evt) {
159: jButtonOKActionPerformed(evt);
160: }
161: });
162: gridBagConstraints = new java.awt.GridBagConstraints();
163: gridBagConstraints.gridy = 1;
164: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
165: gridBagConstraints.weightx = 1.0;
166: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
167: jPanel1.add(jButtonOK, gridBagConstraints);
168:
169: jButtonCancel.setMnemonic('c');
170: jButtonCancel.setText("Cancel");
171: jButtonCancel
172: .addActionListener(new java.awt.event.ActionListener() {
173: public void actionPerformed(
174: java.awt.event.ActionEvent evt) {
175: jButtonCancelActionPerformed(evt);
176: }
177: });
178: gridBagConstraints = new java.awt.GridBagConstraints();
179: gridBagConstraints.gridy = 1;
180: jPanel1.add(jButtonCancel, gridBagConstraints);
181:
182: gridBagConstraints = new java.awt.GridBagConstraints();
183: gridBagConstraints.gridx = 0;
184: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
186: gridBagConstraints.weightx = 1.0;
187: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
188: getContentPane().add(jPanel1, gridBagConstraints);
189:
190: pack();
191: java.awt.Dimension screenSize = java.awt.Toolkit
192: .getDefaultToolkit().getScreenSize();
193: java.awt.Dimension dialogSize = getSize();
194: setLocation((screenSize.width - dialogSize.width) / 2,
195: (screenSize.height - dialogSize.height) / 2);
196: }// </editor-fold>//GEN-END:initComponents
197:
198: private void jButtonCancelActionPerformed(
199: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
200: setVisible(false);
201: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
202: dispose();
203: }//GEN-LAST:event_jButtonCancelActionPerformed
204:
205: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
206:
207: if (this .jRTextExpressionArea.getText().trim().length() <= 0) {
208: javax.swing.JOptionPane
209: .showMessageDialog(
210: this ,
211: I18n
212: .getString(
213: "messages.jRFieldDialog.notValidTemplateExpression",
214: "Please insert a valid template expression!"),
215: I18n
216: .getString(
217: "messages.jRFieldDialog.notValidTemplateExpressionCaption",
218: "Invalid expression!"),
219: javax.swing.JOptionPane.WARNING_MESSAGE);
220: return;
221: }
222:
223: tmpTemplate = new Template(this .jRTextExpressionArea.getText(),
224: "" + jComboBoxType.getSelectedItem());
225:
226: setVisible(false);
227: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
228: dispose();
229: }//GEN-LAST:event_jButtonOKActionPerformed
230:
231: /** Closes the dialog */
232: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
233: setVisible(false);
234: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
235: dispose();
236: }//GEN-LAST:event_closeDialog
237:
238: /**
239: * @param args the command line arguments
240: */
241: public static void main(String args[]) {
242: new JRParameterDialog(new javax.swing.JFrame(), true)
243: .setVisible(true);
244: }
245:
246: /** Getter for property tmpParameter.
247: * @return Value of property tmpParameter.
248: *
249: */
250: public it.businesslogic.ireport.Template getTemplate() {
251: return tmpTemplate;
252: }
253:
254: /** Setter for property tmpParameter.
255: * @param tmpParameter New value of property tmpParameter.
256: *
257: */
258: public void setTemplate(
259: it.businesslogic.ireport.Template tmpTemplate) {
260:
261: this .jComboBoxType.setSelectedItem(new String(tmpTemplate
262: .getExpressionClass()));
263: this .jRTextExpressionArea.setText(tmpTemplate.getExpression());
264:
265: }
266:
267: /** Getter for property dialogResult.
268: * @return Value of property dialogResult.
269: *
270: */
271: public int getDialogResult() {
272: return dialogResult;
273: }
274:
275: /** Setter for property dialogResult.
276: * @param dialogResult New value of property dialogResult.
277: *
278: */
279: public void setDialogResult(int dialogResult) {
280: this .dialogResult = dialogResult;
281: }
282:
283: // Variables declaration - do not modify//GEN-BEGIN:variables
284: private javax.swing.JButton jButtonCancel;
285: private javax.swing.JButton jButtonOK;
286: private javax.swing.JComboBox jComboBoxType;
287: private javax.swing.JLabel jLabel2;
288: private javax.swing.JLabel jLabel4;
289: private javax.swing.JPanel jPanel1;
290: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionArea;
291: private javax.swing.JSeparator jSeparator1;
292: // End of variables declaration//GEN-END:variables
293:
294: private int dialogResult;
295:
296: public void applyI18n() {
297: // Start autogenerated code ----------------------
298: jButtonCancel.setText(I18n.getString(
299: "jRTemplateDialog.buttonCancel", "Cancel"));
300: jButtonOK.setText(I18n.getString("jRTemplateDialog.buttonOK",
301: "OK"));
302: jLabel2.setText(I18n.getString("jRTemplateDialog.label2",
303: "Template expression class type"));
304: jLabel4.setText(I18n.getString("jRTemplateDialog.label4",
305: "Template expression"));
306: // End autogenerated code ----------------------
307: this .setTitle(I18n.getString("jRTemplateDialog.title",
308: "Add/modify template"));
309: jButtonCancel
310: .setMnemonic(I18n.getString(
311: "jRTemplateDialog.buttonCancelMnemonic", "c")
312: .charAt(0));
313: jButtonOK.setMnemonic(I18n.getString(
314: "jRTemplateDialog.buttonOKMnemonic", "o").charAt(0));
315: }
316:
317: }
|