/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright (C) 2013 Marchand Eric <ricoh51@free.fr>
This file is part of Freegressi.
Freegressi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Freegressi 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Freegressi. If not, see <http://www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package freegressi.fit;
import freegressi.parser.Verificateur;
import freegressi.tableur.Noeud;
import freegressi.tableur.Sym;
import freegressi.utils.Utils;
/**
*
* @author marchand, 10 mai 2013, 17:04:10
*/
public class JDialogFit extends javax.swing.JDialog {
private boolean ok = false;
private final String yName;
private final String xName;
/** Creates new form JDialogFit */
public JDialogFit(java.awt.Frame parent, String title, String yName, String xName, String expr) {
super(parent, true);
initComponents();
this.yName = yName;
this.xName = xName;
jlY.setText(yName + " =");
jbGreek.setToolTipText("Insérer un caractère grec");
jbFunction.setToolTipText("Insérer une fonction");
jtfs.setText(expr);
setTitle(title);
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
pack();
setLocationRelativeTo(null);
jtfsKeyReleased(null);
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jToolBar1 = new javax.swing.JToolBar();
jbGreek = new javax.swing.JButton();
jbFunction = new javax.swing.JButton();
jlY = new javax.swing.JLabel();
jtfs = new beans.JTextFieldSouligne();
jlError = new javax.swing.JLabel();
jbOk = new javax.swing.JButton();
jbCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jToolBar1.setRollover(true);
jbGreek.setIcon(new javax.swing.ImageIcon(getClass().getResource("/freegressi/img/insertsymbol_26x26.png"))); // NOI18N
jbGreek.setFocusable(false);
jbGreek.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jbGreek.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jbGreek.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbGreekActionPerformed(evt);
}
});
jToolBar1.add(jbGreek);
jbFunction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/freegressi/img/insertformula_26x26.png"))); // NOI18N
jbFunction.setFocusable(false);
jbFunction.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jbFunction.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jbFunction.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbFunctionActionPerformed(evt);
}
});
jToolBar1.add(jbFunction);
jlY.setText("jLabel1");
jtfs.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jtfsKeyReleased(evt);
}
});
jlError.setForeground(new java.awt.Color(249, 10, 10));
jbOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/freegressi/img/Crystal_Clear_app_clean-24.png"))); // NOI18N
jbOk.setText("Ok");
jbOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbOkActionPerformed(evt);
}
});
jbCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/freegressi/img/Crystal_Clear_action_button_cancel-24.png"))); // NOI18N
jbCancel.setText("Annuler");
jbCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbCancelActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jlY)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtfs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jlError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 212, Short.MAX_VALUE)
.addComponent(jbCancel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbOk)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jlY)
.addComponent(jtfs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jlError, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jbOk)
.addComponent(jbCancel))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jbOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbOkActionPerformed
ok = true;
setVisible(false);
}//GEN-LAST:event_jbOkActionPerformed
private void jbCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelActionPerformed
setVisible(false);
}//GEN-LAST:event_jbCancelActionPerformed
private void jbGreekActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGreekActionPerformed
Utils.insertGreekCaracter(jtfs);
jtfsKeyReleased(null);
}//GEN-LAST:event_jbGreekActionPerformed
private void jbFunctionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbFunctionActionPerformed
Utils.insertFunction(jtfs);
jtfsKeyReleased(null);
}//GEN-LAST:event_jbFunctionActionPerformed
private void jtfsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfsKeyReleased
Noeud noeud;
noeud = Verificateur.parseExpressionTendance(jtfs.getText(), xName);
if (noeud == null) {
jlError.setText("Vous devez entrer une expression!");
jtfs.effaceTout();
} else {
if (noeud.getType() == Sym.ERROR || noeud.getType() == Sym.PARSER_ERROR || noeud.getType() == Sym.PARSER_COHERENCE_ERROR) {
jlError.setText(noeud.getTexteErreur());
jtfs.souligne(noeud.getColonne(), noeud.getColonne() + 1);
} else {
jlError.setText("");
jtfs.effaceTout();
}
}
checkOkButton();
}//GEN-LAST:event_jtfsKeyReleased
private void checkOkButton(){
jbOk.setEnabled(jlError.getText().equals(""));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JToolBar jToolBar1;
private javax.swing.JButton jbCancel;
private javax.swing.JButton jbFunction;
private javax.swing.JButton jbGreek;
private javax.swing.JButton jbOk;
private javax.swing.JLabel jlError;
private javax.swing.JLabel jlY;
private beans.JTextFieldSouligne jtfs;
// End of variables declaration//GEN-END:variables
/**
*
* @return true si le dialog s'est terminé avec Ok false sinon
*/
public boolean isOk() {
return ok;
}
public String getExpression(){
return jtfs.getText();
}
}