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: * PatternSheetPropertyComponent.java
028: *
029: * Created on 15 agosto 2005, 13.32
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.gui.FieldPatternDialog;
036: import it.businesslogic.ireport.gui.MainFrame;
037: import it.businesslogic.ireport.util.I18n;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class PatternSheetPropertyComponent extends javax.swing.JPanel {
044:
045: String expression = "";
046:
047: private boolean init = false;
048:
049: /**
050: * Show a text without changing the real expression stored
051: */
052: public void setText(String fakeExpression) {
053: setInit(true);
054: jTextField1.setText(fakeExpression);
055: jTextField1.setCaretPosition(0);
056: setInit(false);
057: }
058:
059: public void setExpression(String expression) {
060: this .expression = expression;
061: setInit(true);
062: jTextField1.setText(expression);
063: jTextField1.setCaretPosition(0);
064: setInit(false);
065: }
066:
067: public String getExpression() {
068: return expression;
069: }
070:
071: /** Creates new form ExpressionSheetPanel */
072: public PatternSheetPropertyComponent() {
073: initComponents();
074:
075: jTextField1.getDocument().addDocumentListener(
076: new javax.swing.event.DocumentListener() {
077: public void changedUpdate(
078: javax.swing.event.DocumentEvent evt) {
079: try {
080: actionPerformed(evt.getDocument().getText(
081: 0, evt.getDocument().getLength()));
082: } catch (Exception ex) {
083: }
084: }
085:
086: public void insertUpdate(
087: javax.swing.event.DocumentEvent evt) {
088: try {
089: actionPerformed(evt.getDocument().getText(
090: 0, evt.getDocument().getLength()));
091: } catch (Exception ex) {
092: }
093: }
094:
095: public void removeUpdate(
096: javax.swing.event.DocumentEvent evt) {
097: try {
098: actionPerformed(evt.getDocument().getText(
099: 0, evt.getDocument().getLength()));
100: } catch (Exception ex) {
101: }
102: }
103: });
104: applyI18n();
105: }
106:
107: public void actionPerformed(String newText) {
108: if (isInit())
109: return;
110: expression = newText;
111: java.awt.event.ActionEvent event = new java.awt.event.ActionEvent(
112: this , 0, expression);
113: fireActionListenerActionPerformed(event);
114: }
115:
116: /** This method is called from within the constructor to
117: * initialize the form.
118: * WARNING: Do NOT modify this code. The content of this method is
119: * always regenerated by the Form Editor.
120: */
121: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
122: private void initComponents() {
123: java.awt.GridBagConstraints gridBagConstraints;
124:
125: jTextField1 = new javax.swing.JTextField();
126: jButton1 = new javax.swing.JButton();
127:
128: setLayout(new java.awt.GridBagLayout());
129:
130: setBackground(new java.awt.Color(255, 255, 255));
131: jTextField1.setBorder(null);
132: gridBagConstraints = new java.awt.GridBagConstraints();
133: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134: gridBagConstraints.weightx = 1.0;
135: add(jTextField1, gridBagConstraints);
136:
137: jButton1.setText("...");
138: jButton1.setMaximumSize(new java.awt.Dimension(19, 10));
139: jButton1.setMinimumSize(new java.awt.Dimension(19, 10));
140: jButton1.setPreferredSize(new java.awt.Dimension(19, 10));
141: jButton1.addActionListener(new java.awt.event.ActionListener() {
142: public void actionPerformed(java.awt.event.ActionEvent evt) {
143: jButton1ActionPerformed(evt);
144: }
145: });
146:
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
149: gridBagConstraints.weighty = 1.0;
150: add(jButton1, gridBagConstraints);
151:
152: }// </editor-fold>//GEN-END:initComponents
153:
154: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
155:
156: FieldPatternDialog ptd = new FieldPatternDialog(MainFrame
157: .getMainInstance(), true);
158: ptd.setPattern(expression);
159: ptd.setVisible(true);
160: if (ptd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
161: setInit(true);
162: setExpression(ptd.getPattern());
163: setInit(false);
164: actionPerformed(ptd.getPattern());
165: }
166:
167: }//GEN-LAST:event_jButton1ActionPerformed
168:
169: // Variables declaration - do not modify//GEN-BEGIN:variables
170: private javax.swing.JButton jButton1;
171: private javax.swing.JTextField jTextField1;
172: // End of variables declaration//GEN-END:variables
173:
174: /**
175: * Utility field used by event firing mechanism.
176: */
177: private javax.swing.event.EventListenerList listenerList = null;
178:
179: /**
180: * Registers ActionListener to receive events.
181: * @param listener The listener to register.
182: */
183: public synchronized void addActionListener(
184: java.awt.event.ActionListener listener) {
185:
186: if (listenerList == null) {
187: listenerList = new javax.swing.event.EventListenerList();
188: }
189: listenerList.add(java.awt.event.ActionListener.class, listener);
190: }
191:
192: /**
193: * Removes ActionListener from the list of listeners.
194: * @param listener The listener to remove.
195: */
196: public synchronized void removeActionListener(
197: java.awt.event.ActionListener listener) {
198:
199: listenerList.remove(java.awt.event.ActionListener.class,
200: listener);
201: }
202:
203: /**
204: * Notifies all registered listeners about the event.
205: *
206: * @param event The event to be fired
207: */
208: private void fireActionListenerActionPerformed(
209: java.awt.event.ActionEvent event) {
210:
211: if (listenerList == null)
212: return;
213: Object[] listeners = listenerList.getListenerList();
214: for (int i = listeners.length - 2; i >= 0; i -= 2) {
215: if (listeners[i] == java.awt.event.ActionListener.class) {
216: ((java.awt.event.ActionListener) listeners[i + 1])
217: .actionPerformed(event);
218: }
219: }
220: }
221:
222: public boolean isInit() {
223: return init;
224: }
225:
226: public void setInit(boolean init) {
227: this .init = init;
228: }
229:
230: public void applyI18n() {
231: // Start autogenerated code ----------------------
232: jButton1.setText(I18n.getString(
233: "patternSheetPropertyComponent.button1", "..."));
234: // End autogenerated code ----------------------
235: }
236: }
|