import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.tree.*;
import java.util.*;
import ketUI.chord.Chord;
import java.awt.event.*;
import ket.*;
import ket.Calculate;
import ket.display.ColourScheme;
import ket.display.ColourSchemeDecorator;
import ket.math.*;
import ket.math.purpose.DoubleValue;
import ket.math.purpose.NumberValue;
import ket.math.purpose.Word;
import ketUI.Document;
import ketUI.DocumentManager;
import ketUI.panel.KetPanel;
public class Graph
extends JFrame
implements KeyListener {
// TODO: Check for and remove excessive noise from the graph based on a finite difference estimate of gradient changes: i.e. acceleration.
// TODO: Restrict the scale of the graph to remove extremal values.
JButton ok;
GraphPanel graphPanel;
KetPanel ketPanel;
Document document;
public static class GuiThread implements Runnable {
public void run() {
new Graph();
}
}
public Graph() {
super("Example Ket container application");
GridLayout layout = new GridLayout(
1, 1, // Alignment
5, 5); // Gaps
setLayout(layout);
Container contentPane = this.getContentPane();
DocumentManager dm = new DocumentManager(new String[]{});
document = new Document(dm, (JFrame) this, null);
ketPanel = document.getKetPanel();
ketPanel.setSize(420, 300);
ketPanel.addKeyListener(this);
//:) boolean multiple = ketPanel.cygleDisplayMode(); // i.e. Animated display mode.
graphPanel = new GraphPanel(document);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, ketPanel, graphPanel);
add(splitPane);
pack();
splitPane.setDividerLocation(0.3);
Argument a = document.parseArgument("7*sin(x)");
setEquation(a);
Argument b = document.parseArgument("[7*cos(6.3*t), 7*sin(6.3*t)]");
addEquation(b);
Argument c = document.parseArgument("[7*cos(63.0*t), 7*sin(63.0*t), 10*t-5]");
addEquation(c);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(640, 480);
setVisible(true);
ketPanel.setMinimumSize(ketPanel.getSize());
ketPanel.setMaximumSize(ketPanel.getSize());
ketPanel.requestFocus();
graphPanel.calc();
}
public void setEquation(Argument a) {
Document d = ketPanel.getDocument();
Selection s = d.getSelection();
s.replace(a);
}
public void addEquation(Argument a) {
Document d = ketPanel.getDocument();
d.getEquationList().addLast(new Equation(a));
}
public static void main(final String[] args) {
try {
String name = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(name);
} catch(Exception e) {
System.out.println(" !!! Error changing the look and feel !!! " + e);
}
SwingUtilities.invokeLater(new GuiThread());
}
/*
* Invoked when a key has been pressed.
*/
@Override
public void keyPressed(KeyEvent keyEvent) {
char c = keyEvent.getKeyChar();
switch (keyEvent.getKeyCode()) {
case KeyEvent.VK_CONTROL:
case KeyEvent.VK_ENTER:
graphPanel.calc();
return;
}
}
/*
* Invoked when a key has been released.
*/
@Override
public void keyReleased(KeyEvent keyEvent) { }
/*
* Invoked when a key has been typed.
*/
@Override
public void keyTyped(KeyEvent keyEvent) { }
}