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: * JRLinkParameterDialog.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.Vector;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class JRLinkParameterDialog extends javax.swing.JDialog {
044: /** Creates new form JRParameterDialog */
045: JRLinkParameter tmpParameter = null;
046:
047: public JRLinkParameterDialog(java.awt.Frame parent, boolean modal) {
048: super (parent, modal);
049: initAll();
050: }
051:
052: public JRLinkParameterDialog(java.awt.Dialog parent, boolean modal) {
053: super (parent, modal);
054: initAll();
055: }
056:
057: public void initAll() {
058: initComponents();
059: applyI18n();
060: this .jRTextExpressionAreaDefaultExpression.setText("");
061:
062: // we have to force the context of the parameter.
063: this .jRTextExpressionAreaDefaultExpression
064: .setCrosstabElements(new Vector());
065: this .jRTextExpressionAreaDefaultExpression
066: .setSubDataset(MainFrame.getMainInstance()
067: .getActiveReportFrame().getReport());
068: Misc.centerFrame(this );
069:
070: javax.swing.KeyStroke escape = javax.swing.KeyStroke
071: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
072: false);
073: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
074: public void actionPerformed(java.awt.event.ActionEvent e) {
075: jButtonCancelActionPerformed(e);
076: }
077: };
078:
079: getRootPane().getInputMap(
080: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
081: escape, "ESCAPE");
082: getRootPane().getActionMap().put("ESCAPE", escapeAction);
083:
084: //to make the default button ...
085: this .getRootPane().setDefaultButton(this .jButtonOK);
086: }
087:
088: /** This method is called from within the constructor to
089: * initialize the form.
090: * WARNING: Do NOT modify this code. The content of this method is
091: * always regenerated by the Form Editor.
092: */
093: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
094: private void initComponents() {
095: java.awt.GridBagConstraints gridBagConstraints;
096:
097: jPanel1 = new javax.swing.JPanel();
098: jButtonOK = new javax.swing.JButton();
099: jButtonCancel = new javax.swing.JButton();
100: jPanel2 = new javax.swing.JPanel();
101: jLabel1 = new javax.swing.JLabel();
102: jTextFieldName = new javax.swing.JTextField();
103: jLabel3 = new javax.swing.JLabel();
104: jRTextExpressionAreaDefaultExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
105:
106: setTitle("Add/modify parameter");
107: setResizable(false);
108: setModal(true);
109: addWindowListener(new java.awt.event.WindowAdapter() {
110: public void windowClosing(java.awt.event.WindowEvent evt) {
111: closeDialog(evt);
112: }
113: });
114:
115: jPanel1.setLayout(new java.awt.FlowLayout(
116: java.awt.FlowLayout.RIGHT));
117:
118: jButtonOK.setMnemonic('o');
119: jButtonOK.setText("OK");
120: jButtonOK
121: .addActionListener(new java.awt.event.ActionListener() {
122: public void actionPerformed(
123: java.awt.event.ActionEvent evt) {
124: jButtonOKActionPerformed(evt);
125: }
126: });
127:
128: jPanel1.add(jButtonOK);
129:
130: jButtonCancel.setMnemonic('c');
131: jButtonCancel.setText("Cancel");
132: jButtonCancel
133: .addActionListener(new java.awt.event.ActionListener() {
134: public void actionPerformed(
135: java.awt.event.ActionEvent evt) {
136: jButtonCancelActionPerformed(evt);
137: }
138: });
139:
140: jPanel1.add(jButtonCancel);
141:
142: getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
143:
144: jPanel2.setLayout(new java.awt.GridBagLayout());
145:
146: jLabel1.setText("Link parameter name");
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
149: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
150: jPanel2.add(jLabel1, gridBagConstraints);
151:
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 1;
155: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
157: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
158: jPanel2.add(jTextFieldName, gridBagConstraints);
159:
160: jLabel3.setText("Value expression");
161: gridBagConstraints = new java.awt.GridBagConstraints();
162: gridBagConstraints.gridx = 0;
163: gridBagConstraints.gridy = 2;
164: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
166: jPanel2.add(jLabel3, gridBagConstraints);
167:
168: jRTextExpressionAreaDefaultExpression
169: .setBorder(javax.swing.BorderFactory
170: .createEtchedBorder());
171: jRTextExpressionAreaDefaultExpression
172: .setPreferredSize(new java.awt.Dimension(300, 80));
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 3;
176: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
177: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
178: gridBagConstraints.weightx = 1.0;
179: gridBagConstraints.weighty = 1.0;
180: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
181: jPanel2.add(jRTextExpressionAreaDefaultExpression,
182: gridBagConstraints);
183:
184: getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
185:
186: setBounds(0, 0, 320, 220);
187: }// </editor-fold>//GEN-END:initComponents
188:
189: private void jButtonCancelActionPerformed(
190: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
191: setVisible(false);
192: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
193: dispose();
194: }//GEN-LAST:event_jButtonCancelActionPerformed
195:
196: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
197:
198: if (this .jTextFieldName.getText().trim().length() <= 0) {
199: javax.swing.JOptionPane
200: .showMessageDialog(
201: this ,
202: I18n
203: .getString(
204: "messages.jRLinkParameterDialog.notValidParameterName",
205: "Please insert a valid parameter name!"),
206: I18n
207: .getString(
208: "messages.jRLinkParameterDialog.notValidParameterNameCaption",
209: "Invalid parameter!"),
210: javax.swing.JOptionPane.WARNING_MESSAGE);
211: return;
212: }
213:
214: tmpParameter = new it.businesslogic.ireport.JRLinkParameter(
215: this .jTextFieldName.getText(),
216: this .jRTextExpressionAreaDefaultExpression.getText());
217: setVisible(false);
218: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
219: dispose();
220: }//GEN-LAST:event_jButtonOKActionPerformed
221:
222: /** Closes the dialog */
223: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
224: setVisible(false);
225: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
226: dispose();
227: }//GEN-LAST:event_closeDialog
228:
229: /**
230: * @param args the command line arguments
231: */
232: public static void main(String args[]) {
233: new JRParameterDialog(new javax.swing.JFrame(), true)
234: .setVisible(true);
235: }
236:
237: /** Getter for property tmpParameter.
238: * @return Value of property tmpParameter.
239: *
240: */
241: public it.businesslogic.ireport.JRLinkParameter getParameter() {
242: return tmpParameter;
243: }
244:
245: /** Setter for property tmpParameter.
246: * @param tmpParameter New value of property tmpParameter.
247: *
248: */
249: public void setParameter(
250: it.businesslogic.ireport.JRLinkParameter tmpParameter) {
251: this .jTextFieldName.setText(new String(tmpParameter.getName()));
252: this .jRTextExpressionAreaDefaultExpression.setText(new String(
253: tmpParameter.getExpression()));
254: }
255:
256: /** Getter for property dialogResult.
257: * @return Value of property dialogResult.
258: *
259: */
260: public int getDialogResult() {
261: return dialogResult;
262: }
263:
264: /** Setter for property dialogResult.
265: * @param dialogResult New value of property dialogResult.
266: *
267: */
268: public void setDialogResult(int dialogResult) {
269: this .dialogResult = dialogResult;
270: }
271:
272: // Variables declaration - do not modify//GEN-BEGIN:variables
273: private javax.swing.JButton jButtonCancel;
274: private javax.swing.JButton jButtonOK;
275: private javax.swing.JLabel jLabel1;
276: private javax.swing.JLabel jLabel3;
277: private javax.swing.JPanel jPanel1;
278: private javax.swing.JPanel jPanel2;
279: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDefaultExpression;
280: private javax.swing.JTextField jTextFieldName;
281: // End of variables declaration//GEN-END:variables
282:
283: private int dialogResult;
284:
285: public void applyI18n() {
286: // Start autogenerated code ----------------------
287: jButtonCancel.setText(I18n.getString(
288: "jRLinkParameterDialog.buttonCancel", "Cancel"));
289: jButtonOK.setText(I18n.getString(
290: "jRLinkParameterDialog.buttonOK", "OK"));
291: jLabel1.setText(I18n.getString("jRLinkParameterDialog.label1",
292: "Link parameter name"));
293: jLabel3.setText(I18n.getString("jRLinkParameterDialog.label3",
294: "Value expression"));
295: // End autogenerated code ----------------------
296: setTitle(I18n.getString("jRLinkParameterDialog.title",
297: "Add/modify parameter"));
298: jButtonCancel.setMnemonic(I18n.getString(
299: "jRLinkParameterDialog.buttonCancelMnemonic", "c")
300: .charAt(0));
301: jButtonOK.setMnemonic(I18n.getString(
302: "jRLinkParameterDialog.buttonOKMnemonic", "o")
303: .charAt(0));
304: }
305:
306: public static final int COMPONENT_NONE = 0;
307: public static final int COMPONENT_PARAM_NAME = 1;
308: public static final int COMPONENT_PARAM_EXPRESSION = 2;
309:
310: /**
311: * This method set the focus on a specific component.
312: * Valid constants are something like:
313: * COMPONENT_NONE, COMPONENT_PARAM_NAME, ...
314: *
315: */
316: public void setFocusedExpression(int expID) {
317: try {
318: switch (expID) {
319: case COMPONENT_PARAM_EXPRESSION:
320: Misc
321: .selectTextAndFocusArea(jRTextExpressionAreaDefaultExpression);
322: break;
323: case COMPONENT_PARAM_NAME:
324: Misc.selectTextAndFocusArea(jTextFieldName);
325: break;
326: }
327: } catch (Exception ex) {
328: }
329: }
330: }
|