/*
 * iReport - Visual Designer for JasperReports.
 * Copyright (C) 2002 - 2009 Jaspersoft Corporation. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of iReport.
 *
 * iReport is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * iReport is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with iReport. If not, see <http://www.gnu.org/licenses/>.
 */
package com.jaspersoft.ireport.designer.editor;

import com.jaspersoft.ireport.locale.I18n;
import javax.swing.JOptionPane;

/**
 *
 * @author  gtoffoli
 */
public class ExpressionEditorArea extends javax.swing.JPanel {
    
    public ExpressionContext getExpressionContext() {
        return this.expressionEditorPane1.getExpressionContext();
    }

    public void setExpressionContext(ExpressionContext expressionContext) {
        this.expressionEditorPane1.setExpressionContext(expressionContext);
    }
    
    public void setText(String text) {
        this.expressionEditorPane1.setText(text);
    }
    
    public String getText( ) {
        return this.expressionEditorPane1.getText();
    }
    
    /** Creates new form ExpressionEditorArea */
    public ExpressionEditorArea() {
        initComponents();
    }
    
    public ExpressionEditorPane getExpressionEditorPane()
    {
        return this.expressionEditorPane1;
    }
    
    public void setEnabled(boolean b)
    {
        super.setEnabled(b);
        this.expressionEditorPane1.setEnabled(b);
        this.jButton1.setEnabled(b);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jScrollPane1 = new javax.swing.JScrollPane();
        expressionEditorPane1 = new com.jaspersoft.ireport.designer.editor.ExpressionEditorPane();
        jButton1 = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());

        jScrollPane1.setViewportView(expressionEditorPane1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jScrollPane1, gridBagConstraints);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jaspersoft/ireport/designer/editor/text_edit.png"))); // NOI18N
        jButton1.setText(I18n.getString("ExpressionEditorArea.jButton1.text")); // NOI18N
        jButton1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.weighty = 1.0;
        add(jButton1, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       
        ExpressionEditor ed = new ExpressionEditor();
        ed.setExpressionContext( this.expressionEditorPane1.getExpressionContext() );
        ed.setExpression( this.expressionEditorPane1.getText() );    
        if (ed.showDialog(this) == JOptionPane.OK_OPTION)
        {
            this.expressionEditorPane1.setText( ed.getExpression() );
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.jaspersoft.ireport.designer.editor.ExpressionEditorPane expressionEditorPane1;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
}
