Rewrite graph system, add commands, add special keywords to shell (ans, clc)

master
skylarmt 10 years ago
parent 3174ab585b
commit 193bf13349

Binary file not shown.

@ -35,6 +35,7 @@ file.reference.autocomplete-2.5.4.jar=lib/autocomplete-2.5.4.jar
file.reference.htmlcleaner-2.10.jar=lib/htmlcleaner-2.10.jar file.reference.htmlcleaner-2.10.jar=lib/htmlcleaner-2.10.jar
file.reference.iText-4.2.0-com.itextpdf.jar=lib/iText-4.2.0-com.itextpdf.jar file.reference.iText-4.2.0-com.itextpdf.jar=lib/iText-4.2.0-com.itextpdf.jar
file.reference.JavaPrettify-1.2.1.jar=lib/JavaPrettify-1.2.1.jar file.reference.JavaPrettify-1.2.1.jar=lib/JavaPrettify-1.2.1.jar
file.reference.jmathplot.jar=lib/jmathplot.jar
file.reference.js-engine.jar=lib/js-engine.jar file.reference.js-engine.jar=lib/js-engine.jar
file.reference.js.jar=lib/js.jar file.reference.js.jar=lib/js.jar
file.reference.jython-standalone-2.7-b3.jar=lib/jython-standalone-2.7-b3.jar file.reference.jython-standalone-2.7-b3.jar=lib/jython-standalone-2.7-b3.jar
@ -55,7 +56,8 @@ javac.classpath=\
${file.reference.js.jar}:\ ${file.reference.js.jar}:\
${file.reference.jython-standalone-2.7-b3.jar}:\ ${file.reference.jython-standalone-2.7-b3.jar}:\
${file.reference.rsyntaxtextarea-2.5.6.jar}:\ ${file.reference.rsyntaxtextarea-2.5.6.jar}:\
${file.reference.autocomplete-2.5.4.jar} ${file.reference.autocomplete-2.5.4.jar}:\
${file.reference.jmathplot.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false

@ -122,15 +122,29 @@ public class Functions {
/* /*
Graphing interfaces Graphing interfaces
*/ */
public void plotrange(double xmin, double xmax) {
graphwin.setRange(xmin, xmax);
}
public void plot(String function) { public void plot(String function) {
showGraph(); showGraph();
graphwin.graphFunction(function); graphwin.graphFunction(function);
} }
public void plot(String function, double xmin, double xmax) {
graphwin.setRange(xmin, xmax);
plot(function);
}
public void ezplot(String f) { public void ezplot(String f) {
plot(f); plot(f);
} }
public void ezplot(String function, double xmin, double xmax) {
plot(function, xmin, xmax);
}
public void graph(String f) { public void graph(String f) {
plot(f); plot(f);
} }
@ -159,11 +173,6 @@ public class Functions {
plotclr(); plotclr();
} }
public void plotscale(int level) {
showGraph();
graphwin.setZoom(level);
}
public void drawdot(double x, double y) { public void drawdot(double x, double y) {
showGraph(); showGraph();
graphwin.drawDot(x, y); graphwin.drawDot(x, y);

@ -9,7 +9,7 @@
<Property name="text" type="java.lang.String" value="File"/> <Property name="text" type="java.lang.String" value="File"/>
</Properties> </Properties>
<SubComponents> <SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem2"> <MenuItem class="javax.swing.JMenuItem" name="exportBtn">
<Properties> <Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor"> <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+S"/> <KeyStroke key="Ctrl+S"/>
@ -17,7 +17,7 @@
<Property name="text" type="java.lang.String" value="Export graph..."/> <Property name="text" type="java.lang.String" value="Export graph..."/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem2ActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exportBtnActionPerformed"/>
</Events> </Events>
</MenuItem> </MenuItem>
</SubComponents> </SubComponents>
@ -38,15 +38,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clrGraphBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clrGraphBtnActionPerformed"/>
</Events> </Events>
</MenuItem> </MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem6"> <MenuItem class="javax.swing.JMenuItem" name="setTitleBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Scale..."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem6ActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem3">
<Properties> <Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor"> <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+T"/> <KeyStroke key="Ctrl+T"/>
@ -54,20 +46,11 @@
<Property name="text" type="java.lang.String" value="Set Title..."/> <Property name="text" type="java.lang.String" value="Set Title..."/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem3ActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="setTitleBtnActionPerformed"/>
</Events> </Events>
</MenuItem> </MenuItem>
</SubComponents> </SubComponents>
</Menu> </Menu>
<Menu class="javax.swing.JMenu" name="scaleLbl">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="0" id="blue" palette="1" red="0" type="palette"/>
</Property>
<Property name="text" type="java.lang.String" value="Scale: 1 to 1"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Menu>
</SubComponents> </SubComponents>
</Menu> </Menu>
</NonVisualComponents> </NonVisualComponents>
@ -75,17 +58,13 @@
<Property name="closable" type="boolean" value="true"/> <Property name="closable" type="boolean" value="true"/>
<Property name="defaultCloseOperation" type="int" value="1"/> <Property name="defaultCloseOperation" type="int" value="1"/>
<Property name="iconifiable" type="boolean" value="true"/> <Property name="iconifiable" type="boolean" value="true"/>
<Property name="maximizable" type="boolean" value="true"/>
<Property name="resizable" type="boolean" value="true"/>
<Property name="title" type="java.lang.String" value="Graph"/> <Property name="title" type="java.lang.String" value="Graph"/>
<Property name="toolTipText" type="java.lang.String" value=""/> <Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="frameIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> <Property name="frameIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/net/apocalypselabs/symat/icons/graph.png"/> <Image iconType="3" name="/net/apocalypselabs/symat/icons/graph.png"/>
</Property> </Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[326, 402]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[326, 402]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[326, 402]"/> <Dimension value="[326, 402]"/>
</Property> </Property>
@ -112,27 +91,22 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="inBox" min="-2" pref="215" max="-2" attributes="0"/> <Component id="inBox" pref="215" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="plotBtn" min="-2" max="-2" attributes="0"/> <Component id="plotBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
</Group> </Group>
<Component id="gLbl" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="plot" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <Component id="plot" pref="311" max="32767" attributes="0"/>
<Component id="gLbl" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="inBox" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="inBox" alignment="3" min="-2" max="-2" attributes="0"/>
@ -164,26 +138,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="plotBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="plotBtnActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="gLbl"> <Component class="org.math.plot.Plot2DPanel" name="plot">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;&quot;" type="code"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 300]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 300]"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 300]"/>
</Property>
</Properties>
</Component> </Component>
</SubComponents> </SubComponents>
</Form> </Form>

@ -41,6 +41,7 @@ import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import org.math.plot.Plot2DPanel;
import org.matheclipse.core.eval.EvalUtilities; import org.matheclipse.core.eval.EvalUtilities;
import org.matheclipse.parser.client.math.MathException; import org.matheclipse.parser.client.math.MathException;
@ -51,8 +52,7 @@ import org.matheclipse.parser.client.math.MathException;
public class Graph extends javax.swing.JInternalFrame { public class Graph extends javax.swing.JInternalFrame {
private final JFileChooser fc = new JFileChooser(); private final JFileChooser fc = new JFileChooser();
private BufferedImage gpnl;
private Graphics gg; // Main graphics object
private boolean standalone = true; private boolean standalone = true;
private boolean customName = false; private boolean customName = false;
@ -62,13 +62,9 @@ public class Graph extends javax.swing.JInternalFrame {
// If a graph is being drawn, set to true, else false // If a graph is being drawn, set to true, else false
boolean graphing = false; boolean graphing = false;
// Graph scaling data. // Graph min and max
private double xtimes = 15; private double xmin = -10;
private double ytimes = 15; private double xmax = 10;
private double scale = 1;
// The current value for the zoom/scale, as entered by the user
private int scaleLevel = 0;
/** /**
* Creates new form Graph * Creates new form Graph
@ -84,12 +80,12 @@ public class Graph extends javax.swing.JInternalFrame {
private void init() { private void init() {
initComponents(); initComponents();
gpnl = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
FileFilter filter = new FileNameExtensionFilter("PNG image (.png)", "png"); FileFilter filter = new FileNameExtensionFilter("PNG image (.png)", "png");
fc.setFileFilter(filter); fc.setFileFilter(filter);
fc.addChoosableFileFilter(filter); fc.addChoosableFileFilter(filter);
filter = new FileNameExtensionFilter("JPEG image (.jpg)", "jpg"); plot.plotToolBar.remove(5);
fc.addChoosableFileFilter(filter); plot.plotToolBar.remove(4);
plot.plotToolBar.remove(3);
} }
@Override @Override
@ -117,24 +113,22 @@ public class Graph extends javax.swing.JInternalFrame {
inBox = new javax.swing.JTextField(); inBox = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
plotBtn = new javax.swing.JButton(); plotBtn = new javax.swing.JButton();
gLbl = new javax.swing.JLabel(); plot = new org.math.plot.Plot2DPanel();
jMenuBar1 = new javax.swing.JMenuBar(); jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu(); jMenu1 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem(); exportBtn = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu();
clrGraphBtn = new javax.swing.JMenuItem(); clrGraphBtn = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem(); setTitleBtn = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
scaleLbl = new javax.swing.JMenu();
setClosable(true); setClosable(true);
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
setIconifiable(true); setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Graph"); setTitle("Graph");
setToolTipText(""); setToolTipText("");
setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/graph.png"))); // NOI18N setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/graph.png"))); // NOI18N
setMaximumSize(new java.awt.Dimension(326, 402));
setMinimumSize(new java.awt.Dimension(326, 402));
setPreferredSize(new java.awt.Dimension(326, 402)); setPreferredSize(new java.awt.Dimension(326, 402));
addComponentListener(new java.awt.event.ComponentAdapter() { addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(java.awt.event.ComponentEvent evt) { public void componentShown(java.awt.event.ComponentEvent evt) {
@ -158,24 +152,16 @@ public class Graph extends javax.swing.JInternalFrame {
} }
}); });
gLbl.setBackground(new java.awt.Color(255, 255, 255));
gLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
gLbl.setToolTipText("");
gLbl.setMaximumSize(new java.awt.Dimension(300, 300));
gLbl.setMinimumSize(new java.awt.Dimension(300, 300));
gLbl.setOpaque(true);
gLbl.setPreferredSize(new java.awt.Dimension(300, 300));
jMenu1.setText("File"); jMenu1.setText("File");
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); exportBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("Export graph..."); exportBtn.setText("Export graph...");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() { exportBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt); exportBtnActionPerformed(evt);
} }
}); });
jMenu1.add(jMenuItem2); jMenu1.add(exportBtn);
jMenuBar1.add(jMenu1); jMenuBar1.add(jMenu1);
@ -190,30 +176,17 @@ public class Graph extends javax.swing.JInternalFrame {
}); });
jMenu2.add(clrGraphBtn); jMenu2.add(clrGraphBtn);
jMenuItem6.setText("Scale..."); setTitleBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem6.addActionListener(new java.awt.event.ActionListener() { setTitleBtn.setText("Set Title...");
setTitleBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem6ActionPerformed(evt); setTitleBtnActionPerformed(evt);
} }
}); });
jMenu2.add(jMenuItem6); jMenu2.add(setTitleBtn);
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setText("Set Title...");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);
jMenuBar1.add(jMenu2); jMenuBar1.add(jMenu2);
scaleLbl.setForeground(java.awt.Color.blue);
scaleLbl.setText("Scale: 1 to 1");
scaleLbl.setEnabled(false);
jMenuBar1.add(scaleLbl);
setJMenuBar(jMenuBar1); setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@ -222,21 +195,18 @@ public class Graph extends javax.swing.JInternalFrame {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1) .addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(inBox, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(inBox, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(plotBtn)) .addComponent(plotBtn)
.addComponent(gLbl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(10, 10, 10))
.addGap(0, 0, 0)) .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addComponent(gLbl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(inBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(inBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -281,44 +251,61 @@ public class Graph extends javax.swing.JInternalFrame {
} }
}); });
for (String formula : frmlas) { for (String formula : frmlas) {
String niceformula = formula;
CodeRunner cr = new CodeRunner(); CodeRunner cr = new CodeRunner();
formula = formula.replaceAll("x", "\\$x"); formula = formula.replaceAll("x", "\\$x");
EvalUtilities solver = new EvalUtilities(); EvalUtilities solver = new EvalUtilities();
double xx, yy, xo, yo, x; String xx = "";
xo = 0; String yy = "";
yo = 0; double x;
gg = gpnl.getGraphics(); for (x = xmin; x <= xmax; x += ((xmax - xmin) / 40.0)) {
drawAxes();
gg.setColor(Color.BLUE);
for (x = (-10 * scale); x <= (10 * scale); x += (10 * scale * .01)) {
try { try {
cr.setVar("x", x); cr.setVar("x", x);
yy = (-(Double.parseDouble(solver.evaluate("$x=" + x + ";N[" + formula + "]").toString())) * ytimes) + (gpnl.getHeight() / 2); yy += solver.evaluate("$x=" + x + ";N[" + formula + "]").toString() + " ";
//System.err.println(solver.evaluate("$x="+x+";N["+formula+"]").toString()); xx += String.valueOf(x) + " ";
xx = (x * xtimes) + (gpnl.getWidth() / 2);
//gg.drawOval(xx-1, yy-1, 2, 2);
if (x != (-10 * scale)) {
gg.drawLine((int) xo, (int) yo, (int) xx, (int) yy);
}
xo = xx;
yo = yy;
} catch (MathException | NumberFormatException ex) { } catch (MathException | NumberFormatException ex) {
} }
} }
gg.translate(gpnl.getWidth() / 2, gpnl.getHeight() / 2); Debug.println(xx);
SwingUtilities.invokeLater(new Runnable() { Debug.println(yy);
String[] xs = xx.trim().split(" ");
String[] ys = yy.trim().split(" ");
double[] xd = new double[xs.length];
double[] yd = new double[ys.length];
for (int i = 0; i < xs.length; i++) {
xd[i] = Double.parseDouble(xs[i]);
}
for (int i = 0; i < ys.length; i++) {
yd[i] = Double.parseDouble(ys[i]);
}
SwingUtilities.invokeLater(new Updater(niceformula, xd, yd));
}
SwingUtilities.invokeLater(new Finisher());
}
private class Updater implements Runnable {
final double[] xd;
final double[] yd;
final String formula;
public Updater(String frmla, double[] x, double[] y) {
xd = x;
yd = y;
formula = frmla;
}
@Override @Override
public void run() { public void run() {
dispGraph(); plot.addLinePlot(formula, xd, yd);
if (!customName) { history += formula + "\n";
setTitle("Graph | " + inBox.getText());
}
history += inBox.getText() + "\n";
} }
});
} }
SwingUtilities.invokeLater(new Runnable() {
private class Finisher implements Runnable {
@Override @Override
public void run() { public void run() {
inBox.setEnabled(true); inBox.setEnabled(true);
@ -327,15 +314,11 @@ public class Graph extends javax.swing.JInternalFrame {
mu.setEnabled(true); mu.setEnabled(true);
} }
} }
});
} }
} }
private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
gg = gpnl.getGraphics();
drawAxes();
gg.translate(gpnl.getWidth() / 2, gpnl.getHeight() / 2);
dispGraph();
}//GEN-LAST:event_formComponentShown }//GEN-LAST:event_formComponentShown
/** /**
@ -354,46 +337,8 @@ public class Graph extends javax.swing.JInternalFrame {
return gscale; return gscale;
} }
/**
* Set the zoom level. The larger the int, the more zoomed it is.
*
* @param zoomLevel Level to zoom. 0 is default (10x10).
*/
public void setZoom(int zoomLevel) {
scaleLevel = zoomLevel;
if (zoomLevel >= 0) {
xtimes = 15.0 * (zoomLevel + 1.0);
ytimes = 15.0 * (zoomLevel + 1.0);
} else {
xtimes = 15.0 / (abs(zoomLevel) + 1.0);
ytimes = 15.0 / (abs(zoomLevel) + 1.0);
}
scale = getScale(zoomLevel);
scaleLbl.setText("Scale: 1 to " + scale);
Debug.println("Scaled to xtimes=" + xtimes + ", ytimes=" + ytimes + ", scale=1to" + scale);
clearDraw(false);
if (!history.trim().equals("")) {
String temp = "";
for (String cmd : history.trim().split("\n")) {
cmd = cmd.trim();
if (!cmd.equals("")) {
temp += cmd + "\n";
}
}
history = temp.trim();
new GraphThread(history.split("\n")).start();
inBox.setText("");
}
}
private void dispGraph() {
gLbl.setIcon(new ImageIcon(gpnl));
}
public void drawDot(double x, double y) { public void drawDot(double x, double y) {
gg.setColor(Color.RED); // TODO: implement this
gg.drawOval((int) (x * xtimes - 2), (int) (y * -ytimes - 2), 4, 4);
dispGraph();
} }
private void inBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inBoxKeyTyped private void inBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_inBoxKeyTyped
@ -406,23 +351,11 @@ public class Graph extends javax.swing.JInternalFrame {
clearDraw(); clearDraw();
}//GEN-LAST:event_clrGraphBtnActionPerformed }//GEN-LAST:event_clrGraphBtnActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBtnActionPerformed
int r = fc.showSaveDialog(this);
if (r == JFileChooser.APPROVE_OPTION) { }//GEN-LAST:event_exportBtnActionPerformed
try {
File file = new File(addSaveExt(fc.getSelectedFile().toString()));
if (file.toString().endsWith("png")) {
ImageIO.write(gpnl, "png", file);
} else if (file.toString().endsWith("jpg")) {
ImageIO.write(gpnl, "jpg", file);
}
} catch (IOException ex) {
JOptionPane.showInternalMessageDialog(this, "Error: Cannot save file: " + ex.getMessage());
}
}
}//GEN-LAST:event_jMenuItem2ActionPerformed
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed private void setTitleBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setTitleBtnActionPerformed
String wintitle = JOptionPane.showInternalInputDialog(this, String wintitle = JOptionPane.showInternalInputDialog(this,
"New window title:", "New window title:",
"Rename", "Rename",
@ -430,22 +363,36 @@ public class Graph extends javax.swing.JInternalFrame {
if (wintitle != null && !wintitle.equals("")) { if (wintitle != null && !wintitle.equals("")) {
setWindowTitle(wintitle); setWindowTitle(wintitle);
} }
}//GEN-LAST:event_jMenuItem3ActionPerformed }//GEN-LAST:event_setTitleBtnActionPerformed
/**
* Get the range of the graph.
*
* @return {xmin, xmax}
*/
public double[] getRange() {
double[] range = {xmin, xmax};
return range;
}
public void setRange(double min, double max) {
xmin = min;
xmax = max;
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed clearDraw(false);
GraphScale gs = new GraphScale(scaleLevel); if (!history.trim().equals("")) {
int size = 0; String temp = "";
int result = JOptionPane.showInternalConfirmDialog(this, for (String cmd : history.trim().split("\n")) {
gs, cmd = cmd.trim();
"Graph Scale", if (!cmd.equals("")) {
JOptionPane.OK_CANCEL_OPTION, temp += cmd + "\n";
JOptionPane.PLAIN_MESSAGE); }
if (result == JOptionPane.OK_OPTION) { }
size = gs.getScale(); history = temp.trim();
Debug.println("Scaling to: " + size); new GraphThread(history.split("\n")).start();
setZoom(size); inBox.setText("");
}
} }
}//GEN-LAST:event_jMenuItem6ActionPerformed
/** /**
* Graph the given function. Same as typing into input box and pressing * Graph the given function. Same as typing into input box and pressing
@ -459,7 +406,7 @@ public class Graph extends javax.swing.JInternalFrame {
} }
private String addSaveExt(String path) { private String addSaveExt(String path) {
if (!path.matches(".*\\.(png|jpg)")) { if (!path.matches(".*\\.(png)")) {
path += ".png"; path += ".png";
} }
return path; return path;
@ -497,41 +444,22 @@ public class Graph extends javax.swing.JInternalFrame {
* @param alsoHistory True if history should be removed * @param alsoHistory True if history should be removed
*/ */
public void clearDraw(boolean alsoHistory) { public void clearDraw(boolean alsoHistory) {
gpnl = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
gg = gpnl.getGraphics();
drawAxes();
gg.translate(gpnl.getWidth() / 2, gpnl.getHeight() / 2);
dispGraph();
setTitle("Graph");
if (alsoHistory) { if (alsoHistory) {
history = ""; history = "";
} }
} plot.removeAllPlots();
private void drawAxes() {
gg.setColor(Color.GRAY);
gg.drawLine(150, 0, 150, 300);
gg.drawLine(0, 150, 300, 150);
// Draw points
for (int i = 0; i <= 315; i += 15) {
gg.drawOval(150 - 1, i - 1, 2, 2);
gg.drawOval(i - 1, 150 - 1, 2, 2);
}
gg.setColor(Color.BLUE);
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem clrGraphBtn; private javax.swing.JMenuItem clrGraphBtn;
private javax.swing.JLabel gLbl; private javax.swing.JMenuItem exportBtn;
private javax.swing.JTextField inBox; private javax.swing.JTextField inBox;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem2; private org.math.plot.Plot2DPanel plot;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JButton plotBtn; private javax.swing.JButton plotBtn;
private javax.swing.JMenu scaleLbl; private javax.swing.JMenuItem setTitleBtn;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

@ -44,6 +44,7 @@ public class Interpreter extends javax.swing.JInternalFrame {
private String[] history = new String[10]; // Command history buffer private String[] history = new String[10]; // Command history buffer
private int historyIndex = 0; // For going back in time and keeping things straight private int historyIndex = 0; // For going back in time and keeping things straight
private String lang = "javascript"; private String lang = "javascript";
private Object ans = 0;
/** /**
* Creates new form Interpreter * Creates new form Interpreter
@ -362,11 +363,39 @@ public class Interpreter extends javax.swing.JInternalFrame {
code = cmd; code = cmd;
} }
/**
* Process control commands.
*
* @return True if the modified code should be executed, false if not.
*/
private boolean doSpecialCommands() {
switch (code) {
case "clc":
clrOutput();
return false;
}
// Implement ans command
String ansfill = "";
try {
ansfill = String.valueOf(Double.parseDouble(ans.toString()));
} catch (NumberFormatException ex) {
ansfill = "\"" + ans.toString() + "\"";
}
code = code.replace("ans", ansfill);
return true;
}
@Override @Override
public void run() { public void run() {
try { try {
if (doSpecialCommands()) {
append(cr.evalString(code).toString() + "\n"); Object result = cr.evalString(code);
if (result != null && !result.toString().trim().equals("")) {
ans = result;
}
append(result.toString() + "\n");
}
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
} }
@ -388,12 +417,22 @@ public class Interpreter extends javax.swing.JInternalFrame {
}); });
} }
private void clrOutput() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
mainBox.setText("");
}
});
}
private void append(String out) { private void append(String out) {
final String output = out; final String output = out;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
mainBox.append(output); mainBox.append(output);
mainBox.setCaretPosition(mainBox.getText().length());
} }
}); });
} }

@ -49,9 +49,9 @@ import javax.swing.JInternalFrame;
*/ */
public class MainGUI extends javax.swing.JFrame { public class MainGUI extends javax.swing.JFrame {
// TODO: Add more code comments and stuff in case anybody else reads this // TODO: Add more code comments and stuff in case anybody else reads this
public static final String APP_NAME = "SyMAT 0.9.1"; public static final String APP_NAME = "SyMAT 1.0";
public static final double APP_CODE = 11; public static final double APP_CODE = 12;
public static final String VERSION_NAME = "0.9.1"; public static final String VERSION_NAME = "1.0";
public static final String API_URL = "https://apis.symatapp.com/"; public static final String API_URL = "https://apis.symatapp.com/";
public static String argfile = ""; public static String argfile = "";
public static boolean skipPython = false; // Skip python init on start? public static boolean skipPython = false; // Skip python init on start?

@ -110,6 +110,37 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
<br> <br>
<p><b>JMathPlot</b></p><br>
<p>Copyright (c) 2009, µ-Labs
All rights reserved.<br><br>
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:</p>
<ol>
<li>Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.</li>
<li>Neither the name of the copyright holder nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.</li>
</ol><p>
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.</p>
<p><b>HtmlCleaner</b></p><br> <p><b>HtmlCleaner</b></p><br>
<p>Copyright (c) 2006-2014, HtmlCleaner team.<br> <p>Copyright (c) 2006-2014, HtmlCleaner team.<br>
All rights reserved.<br> All rights reserved.<br>
@ -987,4 +1018,4 @@
http://www.gnu.org/philosophy/why-not-lgpl.html .<br> http://www.gnu.org/philosophy/why-not-lgpl.html .<br>
</p> </p>
</body> </body>
</html> </html>

Loading…
Cancel
Save