-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
krasko
committed
Nov 14, 2012
1 parent
a87c14c
commit 2d2b9d4
Showing
11 changed files
with
419 additions
and
325 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package gui; | ||
|
||
import latex.calculator.TeXCalculator; | ||
import latex.formulaextractor.FormulaExtractor; | ||
import latex.parser.ExpressionParser; | ||
import latex.structure.Node; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
import java.util.Arrays; | ||
|
||
import static gui.GuiUtils.INSETS; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Evgeniy | ||
* Date: 14.11.12 | ||
* Time: 23:47 | ||
*/ | ||
public class EvaluationFrame extends JFrame { | ||
private JLabel formulaLabel = new JLabel(); | ||
private String formula; | ||
private Node formulaAST; | ||
|
||
private String[] names; | ||
private double[] values; | ||
|
||
private TeXCalculator calc = new TeXCalculator(); | ||
|
||
public EvaluationFrame(final SingleFormulaPanel parent, final String formula) { | ||
this.formula = formula; | ||
formulaAST = GuiUtils.PARSER_FOR_GUI.parse(formula); | ||
setTitle("Formula evaluation"); | ||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | ||
setLayout(new GridBagLayout()); | ||
|
||
formulaLabel.setIcon(GuiUtils.generateIcon(formula)); | ||
|
||
addWindowListener(new WindowAdapter() { | ||
public void windowClosing(WindowEvent e) { | ||
parent.resetEvaluationFrame(); | ||
dispose(); | ||
} | ||
}); | ||
|
||
add(formulaLabel, new GridBagConstraints(0, 0, 2, 1, 1, 0, | ||
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(20, 50, 20, 50), 0, 0)); | ||
|
||
names = calc.valsRequiredAsArray(formulaAST); | ||
values = new double[names.length]; | ||
|
||
for (int i = 0; i < names.length; ++i) { | ||
final JLabel variableLabel = new JLabel(); | ||
variableLabel.setIcon(GuiUtils.generateIcon(names[i] + " =")); | ||
|
||
final JTextField valueText = new JTextField(); | ||
valueText.setText(String.valueOf(values[i] = calc.getVal(names[i]))); | ||
calc.setVal(names[i], calc.getVal(names[i])); | ||
|
||
add(variableLabel, new GridBagConstraints(0, i + 1, 1, 1, 0, 0, | ||
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, GuiUtils.INSETS, 0, 0)); | ||
add(valueText, new GridBagConstraints(1, i + 1, 1, 1, 0, 0, | ||
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, GuiUtils.INSETS, 0, 0)); | ||
|
||
final int _i = i; | ||
valueText.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
values[_i] = Double.parseDouble(valueText.getText()); | ||
updateResult(); | ||
} catch (Exception ex) { | ||
} | ||
} | ||
}); | ||
|
||
} | ||
|
||
updateResult(); | ||
|
||
setMinimumSize(new Dimension(400, 50)); | ||
setLocationRelativeTo(null); | ||
pack(); | ||
setVisible(true); | ||
} | ||
|
||
private void updateResult() { | ||
try { | ||
calc.setContext(names, values); | ||
formulaLabel.setIcon(GuiUtils.generateIcon(formula + " = " + calc.calculate(formulaAST))); | ||
} catch (Exception e) { | ||
formulaLabel.setIcon(GuiUtils.generateIcon(formula + " = ?")); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gui; | ||
|
||
import latex.parser.ExpressionParser; | ||
import org.scilab.forge.jlatexmath.TeXConstants; | ||
import org.scilab.forge.jlatexmath.TeXFormula; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Evgeniy | ||
* Date: 15.11.12 | ||
* Time: 0:03 | ||
*/ | ||
public class GuiUtils { | ||
public static final Insets INSETS = new Insets(5, 5, 5, 5); | ||
public static final ExpressionParser PARSER_FOR_GUI = new ExpressionParser(); | ||
|
||
public static Icon generateIcon(String formula) { | ||
return new TeXFormula(formula).createTeXIcon(TeXConstants.STYLE_DISPLAY, 20); | ||
} | ||
} |
Oops, something went wrong.