KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > sheet > ExpressionSheetPropertyComponent


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * ExpressionSheetPropertyComponent.java
28  *
29  * Created on 15 agosto 2005, 13.32
30  *
31  */

32
33 package it.businesslogic.ireport.gui.sheet;
34
35 import it.businesslogic.ireport.ExpressionContext;
36 import it.businesslogic.ireport.gui.MainFrame;
37 import it.businesslogic.ireport.util.I18n;
38
39 /**
40  *
41  * @author Administrator
42  */

43 public class ExpressionSheetPropertyComponent extends javax.swing.JPanel JavaDoc {
44     
45     String JavaDoc expression = "";
46     
47     private ExpressionContext expressionContext = new ExpressionContext();
48     
49     private boolean init = false;
50     
51     private boolean plainTextEditor = false;
52      
53     /**
54      * Show a text without changing the real expression stored
55      */

56     public void setText(String JavaDoc fakeExpression)
57     {
58         setInit(true);
59         jTextArea1.setText(fakeExpression);
60         jTextArea1.setCaretPosition(0);
61         setInit(false);
62     }
63        
64     public void setExpression(String JavaDoc expression)
65     {
66         this.expression = expression;
67         setInit(true);
68         jTextArea1.setText(expression);
69         jTextArea1.setCaretPosition(0);
70         setInit(false);
71     }
72     
73     public String JavaDoc getExpression()
74     {
75         return expression;
76     }
77     
78     /** Creates new form ExpressionSheetPanel */
79     public ExpressionSheetPropertyComponent() {
80         initComponents();
81         
82         jTextArea1.getDocument().addDocumentListener( new javax.swing.event.DocumentListener JavaDoc() {
83             public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
84                 try {
85                    actionPerformed( evt.getDocument().getText(0, evt.getDocument().getLength() ));
86                 } catch (Exception JavaDoc ex){}
87             }
88             public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
89                 try {
90                     actionPerformed( evt.getDocument().getText(0, evt.getDocument().getLength() ));
91                 } catch (Exception JavaDoc ex){}
92             }
93             public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
94                 try {
95                     actionPerformed( evt.getDocument().getText(0, evt.getDocument().getLength() ));
96                 } catch (Exception JavaDoc ex){}
97             }
98         });
99         
100         applyI18n();
101          
102     }
103     
104     public void actionPerformed(String JavaDoc newText)
105     {
106         if (isInit()) return;
107         expression = newText;
108         java.awt.event.ActionEvent JavaDoc event = new java.awt.event.ActionEvent JavaDoc(this,0,expression);
109         fireActionListenerActionPerformed(event);
110     }
111     
112     /** This method is called from within the constructor to
113      * initialize the form.
114      * WARNING: Do NOT modify this code. The content of this method is
115      * always regenerated by the Form Editor.
116      */

117     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
118
private void initComponents() {
119         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
120
121         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
122         jTextArea1 = new javax.swing.JTextField JavaDoc();
123         jButton1 = new javax.swing.JButton JavaDoc();
124
125         setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
128         jScrollPane1.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
129         jScrollPane1.setBorder(null);
130         jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
131         jScrollPane1.setOpaque(false);
132         jTextArea1.setDisabledTextColor(new java.awt.Color JavaDoc(0, 0, 0));
133         jScrollPane1.setViewportView(jTextArea1);
134
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
137         gridBagConstraints.weightx = 1.0;
138         gridBagConstraints.weighty = 1.0;
139         add(jScrollPane1, gridBagConstraints);
140
141         jButton1.setText("...");
142         jButton1.setMaximumSize(new java.awt.Dimension JavaDoc(19, 10));
143         jButton1.setMinimumSize(new java.awt.Dimension JavaDoc(19, 10));
144         jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(19, 10));
145         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
146             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
147                 jButton1ActionPerformed(evt);
148             }
149         });
150
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
153         gridBagConstraints.weighty = 1.0;
154         add(jButton1, gridBagConstraints);
155
156     }// </editor-fold>//GEN-END:initComponents
157

158     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
159

160         if (isPlainTextEditor())
161         {
162             PlainTextDialog ptd = new PlainTextDialog(MainFrame.getMainInstance(), true);
163             ptd.setText( expression );
164             ptd.setVisible(true);
165             if (ptd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
166             {
167                 setInit(true);
168                 setExpression( ptd.getText() );
169                 //jTextArea1.setText( ptd.getText() );
170
//jTextArea1.setCaretPosition(0);
171
setInit(false);
172                 actionPerformed( ptd.getText());
173             }
174         }
175         else
176         {
177             // We show the expression editor...
178
it.businesslogic.ireport.gui.ExpressionEditor ed = new it.businesslogic.ireport.gui.ExpressionEditor();
179             ed.setSubDataset( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport() );
180             ed.setExpression( expression );
181
182             ed.setExpressionContext( getExpressionContext() );
183
184             ed.setVisible(true);
185             if (ed.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
186             {
187                 setInit(true);
188                 setExpression( ed.getExpression() );
189                 //jTextArea1.setText( );
190
//jTextArea1.setCaretPosition(0);
191
setInit(false);
192                 actionPerformed( ed.getExpression());
193             }
194         }
195     }//GEN-LAST:event_jButton1ActionPerformed
196

197     
198     // Variables declaration - do not modify//GEN-BEGIN:variables
199
private javax.swing.JButton JavaDoc jButton1;
200     private javax.swing.JScrollPane JavaDoc jScrollPane1;
201     private javax.swing.JTextField JavaDoc jTextArea1;
202     // End of variables declaration//GEN-END:variables
203

204     /**
205      * Utility field used by event firing mechanism.
206      */

207     private javax.swing.event.EventListenerList JavaDoc listenerList = null;
208
209     /**
210      * Registers ActionListener to receive events.
211      * @param listener The listener to register.
212      */

213     public synchronized void addActionListener(java.awt.event.ActionListener JavaDoc listener) {
214
215         if (listenerList == null ) {
216             listenerList = new javax.swing.event.EventListenerList JavaDoc();
217         }
218         listenerList.add (java.awt.event.ActionListener JavaDoc.class, listener);
219     }
220
221     /**
222      * Removes ActionListener from the list of listeners.
223      * @param listener The listener to remove.
224      */

225     public synchronized void removeActionListener(java.awt.event.ActionListener JavaDoc listener) {
226
227         listenerList.remove (java.awt.event.ActionListener JavaDoc.class, listener);
228     }
229
230     /**
231      * Notifies all registered listeners about the event.
232      *
233      * @param event The event to be fired
234      */

235     private void fireActionListenerActionPerformed(java.awt.event.ActionEvent JavaDoc event) {
236
237         if (listenerList == null) return;
238         Object JavaDoc[] listeners = listenerList.getListenerList ();
239         for (int i = listeners.length - 2; i >= 0; i -= 2) {
240             if (listeners[i]==java.awt.event.ActionListener JavaDoc.class) {
241                 ((java.awt.event.ActionListener JavaDoc)listeners[i+1]).actionPerformed (event);
242             }
243         }
244     }
245
246     public boolean isInit() {
247         return init;
248     }
249
250     public void setInit(boolean init) {
251         this.init = init;
252     }
253
254     public ExpressionContext getExpressionContext() {
255         return expressionContext;
256     }
257
258     public void setExpressionContext(ExpressionContext expressionContext) {
259         this.expressionContext = expressionContext;
260     }
261
262     public boolean isPlainTextEditor() {
263         return plainTextEditor;
264     }
265
266     public void setPlainTextEditor(boolean plainTextEditor) {
267         this.plainTextEditor = plainTextEditor;
268     }
269
270     
271     
272     public void applyI18n(){
273                 // Start autogenerated code ----------------------
274
jButton1.setText(I18n.getString("expressionSheetPropertyComponent.button1","..."));
275                 // End autogenerated code ----------------------
276
}
277 }
278
Popular Tags