public class fct_calculate_data implements Calculation, Cloneable
{
/*
Das ist die initialisierte Funktion. hier kommt die Funktion, die gezeichnet wird, oder besser gesagt: hier
sollen die Funktionen sein, die gezeichnet werden sollen (mehrere).
*/
String valueCalc ="y=t";
double tmin = 0; // Anfangszeit
double tmax = 10; //Endzeit
TischRechner tr; // Das ist mein Parser
private class ConfigDia extends JDialog {
JTextArea tfvalueCalc; // TextArea für die Funktionen
JFormattedTextField tfTmin; // Textfield für tmin
JFormattedTextField tfTmax; // Textfield für tmax
ConfigDia(Dialog parent) {
super(parent,calcName,true);
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane,BoxLayout.PAGE_AXIS));
label = new JLabel("Eingabefeld für Funktionen");
pane.add(label);
tfvalueCalc = new JTextArea(new String(valueCalc),5,10);
scrollpane = new JScrollPane(tfvalueCalc);
pane.add(scrollpane);
label = new JLabel("T_Min");
pane.add(label);
tfTmin = new JFormattedTextField(new Double(tmin));
pane.add(tfTmin);
label = new JLabel("T_Max");
pane.add(label);
tfTmax = new JFormattedTextField(new Double(tmax));
pane.add(tfTmax);
JButton bok = new JButton("Ok");
bok.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent e) {
valueCalc = Utils.getString(tfvalueCalc);
tmin = Utils.getDouble(tfTmin);
tmax = Utils.getDouble(tfTmax);
dispose();
}
});
pane.add(bok);
setContentPane(pane);
pack();
setLocationRelativeTo(null);
setVisible(true);
}
}
public JPanel createPanelPart()
{
XYItemRenderer renderer = new StandardXYItemRenderer();
NumberAxis rangeAxis1 = new NumberAxis("Y-Axis");
NumberAxis rangeAxis1x = new NumberAxis("X-Axis");
dataSeries = new XYSeries("");
tr = new TischRechner();
try {
tr.init();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(double t = tmin; t<=tmax; t++)
{
String in = new String(),out;
double out_double = 0;
in = "t="+t;
try {
tr.main(in);
out = tr.main(valueCalc); // das ist eine sehr wichtiger teil. Hier wird die Eingaben geparst
out_double = Double.parseDouble(out);
// System.out.println(out);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dataSeries.add(t, out_double);
dataset = new XYSeriesCollection(dataSeries);
}
plot = new XYPlot(dataset,
rangeAxis1x,
rangeAxis1,
renderer);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT,plot,true);
chartpanel = new ChartPanel(chart, true, true, true, true, true);
dim = new Dimension(400,200);
chartpanel.setPreferredSize(dim);
panel = new JPanel();
panel.add(chartpanel);
return panel;
}
}