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: * CrosstabParameterDialog.java
028: *
029: * Created on 9 maggio 2003, 17.25
030: *
031: */
032:
033: package it.businesslogic.ireport.crosstab.gui;
034:
035: import it.businesslogic.ireport.util.*;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.crosstab.*;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class CrosstabParameterDialog extends javax.swing.JDialog {
044: /** Creates new form JRParameterDialog */
045: CrosstabParameter tmpParameter = null;
046:
047: public CrosstabParameterDialog(java.awt.Frame parent, boolean modal) {
048:
049: super (parent, modal);
050: initAll();
051: }
052:
053: public CrosstabParameterDialog(java.awt.Dialog parent, boolean modal) {
054:
055: super (parent, modal);
056: initAll();
057: }
058:
059: public void initAll() {
060: initComponents();
061: this .jRTextExpressionAreaDefaultExpression.setText("");
062: setClassTypes();
063: this .jComboBoxType.setSelectedItem("java.lang.String");
064:
065: javax.swing.KeyStroke escape = javax.swing.KeyStroke
066: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
067: false);
068: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
069: public void actionPerformed(java.awt.event.ActionEvent e) {
070: jButtonCancelActionPerformed(e);
071: }
072: };
073:
074: getRootPane().getInputMap(
075: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
076: escape, "ESCAPE");
077: getRootPane().getActionMap().put("ESCAPE", escapeAction);
078:
079: //to make the default button ...
080: this .getRootPane().setDefaultButton(this .jButtonOK);
081: applyI18n();
082: }
083:
084: public void setClassTypes() {
085: this .jComboBoxType.addItem("java.lang.String");
086: this .jComboBoxType.addItem("java.lang.Object");
087: this .jComboBoxType.addItem("java.lang.Boolean");
088: this .jComboBoxType.addItem("java.lang.Byte");
089: this .jComboBoxType.addItem("java.util.Date");
090: this .jComboBoxType.addItem("java.sql.Timestamp");
091: this .jComboBoxType.addItem("java.sql.Time");
092: this .jComboBoxType.addItem("java.lang.Double");
093: this .jComboBoxType.addItem("java.lang.Float");
094: this .jComboBoxType.addItem("java.lang.Integer");
095: this .jComboBoxType.addItem("java.io.InputStream");
096: this .jComboBoxType.addItem("java.lang.Long");
097: this .jComboBoxType.addItem("java.lang.Short");
098: this .jComboBoxType.addItem("java.math.BigDecimal");
099: this .jComboBoxType
100: .addItem("net.sf.jasperreports.engine.JREmptyDataSource");
101: }
102:
103: /** This method is called from within the constructor to
104: * initialize the form.
105: * WARNING: Do NOT modify this code. The content of this method is
106: * always regenerated by the Form Editor.
107: */
108: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
109: private void initComponents() {
110: java.awt.GridBagConstraints gridBagConstraints;
111:
112: jLabel1 = new javax.swing.JLabel();
113: jTextFieldName = new javax.swing.JTextField();
114: jLabel2 = new javax.swing.JLabel();
115: jComboBoxType = new javax.swing.JComboBox();
116: jLabel3 = new javax.swing.JLabel();
117: jRTextExpressionAreaDefaultExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
118: jPanel1 = new javax.swing.JPanel();
119: jButtonOK = new javax.swing.JButton();
120: jButtonCancel = new javax.swing.JButton();
121:
122: getContentPane().setLayout(new java.awt.GridBagLayout());
123:
124: setTitle("Add/modify crosstab parameter");
125: setModal(true);
126: addWindowListener(new java.awt.event.WindowAdapter() {
127: public void windowClosing(java.awt.event.WindowEvent evt) {
128: closeDialog(evt);
129: }
130: });
131:
132: jLabel1.setText("Parameter name");
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.gridx = 0;
135: gridBagConstraints.gridy = 0;
136: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
137: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
138: getContentPane().add(jLabel1, gridBagConstraints);
139:
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 0;
142: gridBagConstraints.gridy = 1;
143: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
145: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
146: getContentPane().add(jTextFieldName, gridBagConstraints);
147:
148: jLabel2.setText("Parameter class type");
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridx = 0;
151: gridBagConstraints.gridy = 2;
152: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
153: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
154: getContentPane().add(jLabel2, gridBagConstraints);
155:
156: jComboBoxType.setEditable(true);
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.gridx = 0;
159: gridBagConstraints.gridy = 3;
160: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
162: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
163: getContentPane().add(jComboBoxType, gridBagConstraints);
164:
165: jLabel3.setText("Value expression");
166: gridBagConstraints = new java.awt.GridBagConstraints();
167: gridBagConstraints.gridx = 0;
168: gridBagConstraints.gridy = 5;
169: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
170: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
171: getContentPane().add(jLabel3, gridBagConstraints);
172:
173: jRTextExpressionAreaDefaultExpression
174: .setBorder(javax.swing.BorderFactory
175: .createEtchedBorder());
176: jRTextExpressionAreaDefaultExpression.setCaretVisible(false);
177: jRTextExpressionAreaDefaultExpression.setElectricScroll(0);
178: jRTextExpressionAreaDefaultExpression
179: .setMinimumSize(new java.awt.Dimension(0, 60));
180: jRTextExpressionAreaDefaultExpression
181: .setPreferredSize(new java.awt.Dimension(310, 60));
182: gridBagConstraints = new java.awt.GridBagConstraints();
183: gridBagConstraints.gridx = 0;
184: gridBagConstraints.gridy = 6;
185: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
186: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
187: gridBagConstraints.weighty = 1.0;
188: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
189: getContentPane().add(jRTextExpressionAreaDefaultExpression,
190: gridBagConstraints);
191:
192: jPanel1.setLayout(new java.awt.FlowLayout(
193: java.awt.FlowLayout.RIGHT));
194:
195: jButtonOK.setMnemonic('o');
196: jButtonOK.setText("OK");
197: jButtonOK
198: .addActionListener(new java.awt.event.ActionListener() {
199: public void actionPerformed(
200: java.awt.event.ActionEvent evt) {
201: jButtonOKActionPerformed(evt);
202: }
203: });
204:
205: jPanel1.add(jButtonOK);
206:
207: jButtonCancel.setMnemonic('c');
208: jButtonCancel.setText("Cancel");
209: jButtonCancel
210: .addActionListener(new java.awt.event.ActionListener() {
211: public void actionPerformed(
212: java.awt.event.ActionEvent evt) {
213: jButtonCancelActionPerformed(evt);
214: }
215: });
216:
217: jPanel1.add(jButtonCancel);
218:
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 9;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224: gridBagConstraints.weightx = 1.0;
225: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
226: getContentPane().add(jPanel1, gridBagConstraints);
227:
228: pack();
229: java.awt.Dimension screenSize = java.awt.Toolkit
230: .getDefaultToolkit().getScreenSize();
231: java.awt.Dimension dialogSize = getSize();
232: setLocation((screenSize.width - dialogSize.width) / 2,
233: (screenSize.height - dialogSize.height) / 2);
234: }// </editor-fold>//GEN-END:initComponents
235:
236: private void jButtonCancelActionPerformed(
237: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
238: setVisible(false);
239: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
240: dispose();
241: }//GEN-LAST:event_jButtonCancelActionPerformed
242:
243: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
244: if (this .jTextFieldName.getText().trim().length() <= 0) {
245: javax.swing.JOptionPane
246: .showMessageDialog(
247: this ,
248: I18n
249: .getString(
250: "messages.crosstabParameterDialog.invalidParameterName",
251: "Please insert a valid parameter name!"),
252: I18n
253: .getString(
254: "messages.crosstabParameterDialog.invalidParameterNameCaption",
255: "Invalid parameter!"),
256: javax.swing.JOptionPane.WARNING_MESSAGE);
257: return;
258: }
259:
260: tmpParameter = new CrosstabParameter(this .jTextFieldName
261: .getText(), "java.lang.String",
262: this .jRTextExpressionAreaDefaultExpression.getText());
263: if (this .jComboBoxType.getSelectedItem().toString().trim()
264: .length() != 0) {
265: tmpParameter.setClassType(this .jComboBoxType
266: .getSelectedItem().toString().trim());
267: }
268:
269: setVisible(false);
270: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
271: dispose();
272: }//GEN-LAST:event_jButtonOKActionPerformed
273:
274: /** Closes the dialog */
275: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
276: setVisible(false);
277: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
278: dispose();
279: }//GEN-LAST:event_closeDialog
280:
281: /** Getter for property tmpParameter.
282: * @return Value of property tmpParameter.
283: *
284: */
285: public it.businesslogic.ireport.crosstab.CrosstabParameter getParameter() {
286: return tmpParameter;
287: }
288:
289: /** Setter for property tmpParameter.
290: * @param tmpParameter New value of property tmpParameter.
291: *
292: */
293: public void setParameter(
294: it.businesslogic.ireport.crosstab.CrosstabParameter tmpParameter) {
295: this .jTextFieldName.setText(new String(tmpParameter.getName()));
296: this .jComboBoxType.setSelectedItem(new String(tmpParameter
297: .getClassType()));
298: this .jRTextExpressionAreaDefaultExpression.setText(new String(
299: tmpParameter.getParameterValueExpression()));
300: }
301:
302: /** Getter for property dialogResult.
303: * @return Value of property dialogResult.
304: *
305: */
306: public int getDialogResult() {
307: return dialogResult;
308: }
309:
310: /** Setter for property dialogResult.
311: * @param dialogResult New value of property dialogResult.
312: *
313: */
314: public void setDialogResult(int dialogResult) {
315: this .dialogResult = dialogResult;
316: }
317:
318: // Variables declaration - do not modify//GEN-BEGIN:variables
319: private javax.swing.JButton jButtonCancel;
320: private javax.swing.JButton jButtonOK;
321: private javax.swing.JComboBox jComboBoxType;
322: private javax.swing.JLabel jLabel1;
323: private javax.swing.JLabel jLabel2;
324: private javax.swing.JLabel jLabel3;
325: private javax.swing.JPanel jPanel1;
326: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDefaultExpression;
327: private javax.swing.JTextField jTextFieldName;
328: // End of variables declaration//GEN-END:variables
329:
330: private int dialogResult;
331:
332: public void setSubDataset(SubDataset subDataset) {
333:
334: jRTextExpressionAreaDefaultExpression.setSubDataset(subDataset);
335: jRTextExpressionAreaDefaultExpression.getTokenMarker()
336: .setKeywordLookup(subDataset.getKeywordLookup());
337: }
338:
339: public void applyI18n() {
340: // Start autogenerated code ----------------------
341: jButtonCancel.setText(I18n.getString(
342: "crosstabParameterDialog.buttonCancel", "Cancel"));
343: jButtonOK.setText(I18n.getString(
344: "crosstabParameterDialog.buttonOK", "OK"));
345: jLabel1.setText(I18n.getString(
346: "crosstabParameterDialog.label1", "Parameter name"));
347: jLabel2.setText(I18n.getString(
348: "crosstabParameterDialog.label2",
349: "Parameter class type"));
350: jLabel3.setText(I18n.getString(
351: "crosstabParameterDialog.label3", "Value expression"));
352: // End autogenerated code ----------------------
353:
354: this .setTitle(I18n.getString("crosstabParameterDialog.title",
355: "Add/modify crosstab parameter"));
356: jButtonCancel.setMnemonic(I18n.getString(
357: "crosstabParameterDialog.buttonCancelMnemonic", "c")
358: .charAt(0));
359: jButtonOK.setMnemonic(I18n.getString(
360: "crosstabParameterDialog.buttonOKMnemonic", "o")
361: .charAt(0));
362: }
363:
364: public static final int COMPONENT_NONE = 0;
365: public static final int COMPONENT_PARAM_NAME = 1;
366: public static final int COMPONENT_PARAM_EXPRESSION = 2;
367:
368: /**
369: * This method set the focus on a specific component.
370: * Valid constants are something like:
371: * COMPONENT_NONE, COMPONENT_PARAM_NAME, ...
372: *
373: */
374: public void setFocusedExpression(int expID) {
375: try {
376: switch (expID) {
377: case COMPONENT_PARAM_EXPRESSION:
378: Misc
379: .selectTextAndFocusArea(jRTextExpressionAreaDefaultExpression);
380: break;
381: case COMPONENT_PARAM_NAME:
382: Misc.selectTextAndFocusArea(jTextFieldName);
383: break;
384: }
385: } catch (Exception ex) {
386: }
387: }
388: }
|