KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PatternSheetPropertyComponent.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.gui.FieldPatternDialog;
36 import it.businesslogic.ireport.gui.MainFrame;
37 import it.businesslogic.ireport.util.I18n;
38
39 /**
40  *
41  * @author Administrator
42  */

43 public class PatternSheetPropertyComponent extends javax.swing.JPanel JavaDoc {
44     
45     String JavaDoc expression = "";
46         
47     private boolean init = false;
48      
49     /**
50      * Show a text without changing the real expression stored
51      */

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

111     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
112
private void initComponents() {
113         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
114
115         jTextField1 = new javax.swing.JTextField JavaDoc();
116         jButton1 = new javax.swing.JButton JavaDoc();
117
118         setLayout(new java.awt.GridBagLayout JavaDoc());
119
120         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
121         jTextField1.setBorder(null);
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.weightx = 1.0;
125         add(jTextField1, gridBagConstraints);
126
127         jButton1.setText("...");
128         jButton1.setMaximumSize(new java.awt.Dimension JavaDoc(19, 10));
129         jButton1.setMinimumSize(new java.awt.Dimension JavaDoc(19, 10));
130         jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(19, 10));
131         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
132             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
133                 jButton1ActionPerformed(evt);
134             }
135         });
136
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
139         gridBagConstraints.weighty = 1.0;
140         add(jButton1, gridBagConstraints);
141
142     }// </editor-fold>//GEN-END:initComponents
143

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

146         FieldPatternDialog ptd = new FieldPatternDialog(MainFrame.getMainInstance(), true);
147         ptd.setPattern( expression );
148         ptd.setVisible(true);
149         if (ptd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
150         {
151           setInit(true);
152           setExpression( ptd.getPattern() );
153           setInit(false);
154           actionPerformed( ptd.getPattern());
155         }
156         
157     }//GEN-LAST:event_jButton1ActionPerformed
158

159     
160     // Variables declaration - do not modify//GEN-BEGIN:variables
161
private javax.swing.JButton JavaDoc jButton1;
162     private javax.swing.JTextField JavaDoc jTextField1;
163     // End of variables declaration//GEN-END:variables
164

165     /**
166      * Utility field used by event firing mechanism.
167      */

168     private javax.swing.event.EventListenerList JavaDoc listenerList = null;
169
170     /**
171      * Registers ActionListener to receive events.
172      * @param listener The listener to register.
173      */

174     public synchronized void addActionListener(java.awt.event.ActionListener JavaDoc listener) {
175
176         if (listenerList == null ) {
177             listenerList = new javax.swing.event.EventListenerList JavaDoc();
178         }
179         listenerList.add (java.awt.event.ActionListener JavaDoc.class, listener);
180     }
181
182     /**
183      * Removes ActionListener from the list of listeners.
184      * @param listener The listener to remove.
185      */

186     public synchronized void removeActionListener(java.awt.event.ActionListener JavaDoc listener) {
187
188         listenerList.remove (java.awt.event.ActionListener JavaDoc.class, listener);
189     }
190
191     /**
192      * Notifies all registered listeners about the event.
193      *
194      * @param event The event to be fired
195      */

196     private void fireActionListenerActionPerformed(java.awt.event.ActionEvent JavaDoc event) {
197
198         if (listenerList == null) return;
199         Object JavaDoc[] listeners = listenerList.getListenerList ();
200         for (int i = listeners.length - 2; i >= 0; i -= 2) {
201             if (listeners[i]==java.awt.event.ActionListener JavaDoc.class) {
202                 ((java.awt.event.ActionListener JavaDoc)listeners[i+1]).actionPerformed (event);
203             }
204         }
205     }
206
207     public boolean isInit() {
208         return init;
209     }
210
211     public void setInit(boolean init) {
212         this.init = init;
213     }
214     
215     public void applyI18n(){
216                 // Start autogenerated code ----------------------
217
jButton1.setText(I18n.getString("patternSheetPropertyComponent.button1","..."));
218                 // End autogenerated code ----------------------
219
}
220 }
221
Popular Tags