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: * ExpressionSheetPropertyComponent.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.ExpressionContext;
036: import it.businesslogic.ireport.gui.MainFrame;
037: import it.businesslogic.ireport.util.I18n;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class ExpressionSheetPropertyComponent extends
044: javax.swing.JPanel {
045:
046: String expression = "";
047:
048: private ExpressionContext expressionContext = new ExpressionContext();
049:
050: private boolean init = false;
051:
052: private boolean plainTextEditor = false;
053:
054: /**
055: * Show a text without changing the real expression stored
056: */
057: public void setText(String fakeExpression) {
058: setInit(true);
059: jTextArea1.setText(fakeExpression);
060: jTextArea1.setCaretPosition(0);
061: setInit(false);
062: }
063:
064: public void setExpression(String expression) {
065: this .expression = expression;
066: setInit(true);
067: jTextArea1.setText(expression);
068: jTextArea1.setCaretPosition(0);
069: setInit(false);
070: }
071:
072: public String getExpression() {
073: return expression;
074: }
075:
076: /** Creates new form ExpressionSheetPanel */
077: public ExpressionSheetPropertyComponent() {
078: initComponents();
079:
080: jTextArea1.getDocument().addDocumentListener(
081: new javax.swing.event.DocumentListener() {
082: public void changedUpdate(
083: javax.swing.event.DocumentEvent evt) {
084: try {
085: actionPerformed(evt.getDocument().getText(
086: 0, evt.getDocument().getLength()));
087: } catch (Exception ex) {
088: }
089: }
090:
091: public void insertUpdate(
092: javax.swing.event.DocumentEvent evt) {
093: try {
094: actionPerformed(evt.getDocument().getText(
095: 0, evt.getDocument().getLength()));
096: } catch (Exception ex) {
097: }
098: }
099:
100: public void removeUpdate(
101: javax.swing.event.DocumentEvent evt) {
102: try {
103: actionPerformed(evt.getDocument().getText(
104: 0, evt.getDocument().getLength()));
105: } catch (Exception ex) {
106: }
107: }
108: });
109:
110: applyI18n();
111:
112: }
113:
114: public void actionPerformed(String newText) {
115: if (isInit())
116: return;
117: expression = newText;
118: java.awt.event.ActionEvent event = new java.awt.event.ActionEvent(
119: this , 0, expression);
120: fireActionListenerActionPerformed(event);
121: }
122:
123: /** This method is called from within the constructor to
124: * initialize the form.
125: * WARNING: Do NOT modify this code. The content of this method is
126: * always regenerated by the Form Editor.
127: */
128: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
129: private void initComponents() {
130: java.awt.GridBagConstraints gridBagConstraints;
131:
132: jScrollPane1 = new javax.swing.JScrollPane();
133: jTextArea1 = new javax.swing.JTextField();
134: jButton1 = new javax.swing.JButton();
135:
136: setLayout(new java.awt.GridBagLayout());
137:
138: setBackground(new java.awt.Color(255, 255, 255));
139: jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
140: jScrollPane1.setBorder(null);
141: jScrollPane1
142: .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
143: jScrollPane1.setOpaque(false);
144: jTextArea1.setDisabledTextColor(new java.awt.Color(0, 0, 0));
145: jScrollPane1.setViewportView(jTextArea1);
146:
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
149: gridBagConstraints.weightx = 1.0;
150: gridBagConstraints.weighty = 1.0;
151: add(jScrollPane1, gridBagConstraints);
152:
153: jButton1.setText("...");
154: jButton1.setMaximumSize(new java.awt.Dimension(19, 10));
155: jButton1.setMinimumSize(new java.awt.Dimension(19, 10));
156: jButton1.setPreferredSize(new java.awt.Dimension(19, 10));
157: jButton1.addActionListener(new java.awt.event.ActionListener() {
158: public void actionPerformed(java.awt.event.ActionEvent evt) {
159: jButton1ActionPerformed(evt);
160: }
161: });
162:
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165: gridBagConstraints.weighty = 1.0;
166: add(jButton1, gridBagConstraints);
167:
168: }// </editor-fold>//GEN-END:initComponents
169:
170: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
171:
172: if (isPlainTextEditor()) {
173: PlainTextDialog ptd = new PlainTextDialog(MainFrame
174: .getMainInstance(), true);
175: ptd.setText(expression);
176: ptd.setVisible(true);
177: if (ptd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
178: setInit(true);
179: setExpression(ptd.getText());
180: //jTextArea1.setText( ptd.getText() );
181: //jTextArea1.setCaretPosition(0);
182: setInit(false);
183: actionPerformed(ptd.getText());
184: }
185: } else {
186: // We show the expression editor...
187: it.businesslogic.ireport.gui.ExpressionEditor ed = new it.businesslogic.ireport.gui.ExpressionEditor();
188: ed.setSubDataset(it.businesslogic.ireport.gui.MainFrame
189: .getMainInstance().getActiveReportFrame()
190: .getReport());
191: ed.setExpression(expression);
192:
193: ed.setExpressionContext(getExpressionContext());
194:
195: ed.setVisible(true);
196: if (ed.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
197: setInit(true);
198: setExpression(ed.getExpression());
199: //jTextArea1.setText( );
200: //jTextArea1.setCaretPosition(0);
201: setInit(false);
202: actionPerformed(ed.getExpression());
203: }
204: }
205: }//GEN-LAST:event_jButton1ActionPerformed
206:
207: // Variables declaration - do not modify//GEN-BEGIN:variables
208: private javax.swing.JButton jButton1;
209: private javax.swing.JScrollPane jScrollPane1;
210: private javax.swing.JTextField jTextArea1;
211: // End of variables declaration//GEN-END:variables
212:
213: /**
214: * Utility field used by event firing mechanism.
215: */
216: private javax.swing.event.EventListenerList listenerList = null;
217:
218: /**
219: * Registers ActionListener to receive events.
220: * @param listener The listener to register.
221: */
222: public synchronized void addActionListener(
223: java.awt.event.ActionListener listener) {
224:
225: if (listenerList == null) {
226: listenerList = new javax.swing.event.EventListenerList();
227: }
228: listenerList.add(java.awt.event.ActionListener.class, listener);
229: }
230:
231: /**
232: * Removes ActionListener from the list of listeners.
233: * @param listener The listener to remove.
234: */
235: public synchronized void removeActionListener(
236: java.awt.event.ActionListener listener) {
237:
238: listenerList.remove(java.awt.event.ActionListener.class,
239: listener);
240: }
241:
242: /**
243: * Notifies all registered listeners about the event.
244: *
245: * @param event The event to be fired
246: */
247: private void fireActionListenerActionPerformed(
248: java.awt.event.ActionEvent event) {
249:
250: if (listenerList == null)
251: return;
252: Object[] listeners = listenerList.getListenerList();
253: for (int i = listeners.length - 2; i >= 0; i -= 2) {
254: if (listeners[i] == java.awt.event.ActionListener.class) {
255: ((java.awt.event.ActionListener) listeners[i + 1])
256: .actionPerformed(event);
257: }
258: }
259: }
260:
261: public boolean isInit() {
262: return init;
263: }
264:
265: public void setInit(boolean init) {
266: this .init = init;
267: }
268:
269: public ExpressionContext getExpressionContext() {
270: return expressionContext;
271: }
272:
273: public void setExpressionContext(ExpressionContext expressionContext) {
274: this .expressionContext = expressionContext;
275: }
276:
277: public boolean isPlainTextEditor() {
278: return plainTextEditor;
279: }
280:
281: public void setPlainTextEditor(boolean plainTextEditor) {
282: this .plainTextEditor = plainTextEditor;
283: }
284:
285: public void applyI18n() {
286: // Start autogenerated code ----------------------
287: jButton1.setText(I18n.getString(
288: "expressionSheetPropertyComponent.button1", "..."));
289: // End autogenerated code ----------------------
290: }
291: }
|