/Users/20800/Desktop/IA_Final_Submission_000307-0050/Product/IA_Netbeans_Project/src/mainPackage/MainGUI.java

   1 package mainPackage;

   2 

   3 import java.awt.BasicStroke;

   4 import java.awt.BorderLayout;

   5 import java.awt.Color;

   6 import java.awt.Font;

   7 import java.awt.event.KeyEvent;

   8 import org.jfree.chart.ChartFactory;

   9 import org.jfree.chart.ChartPanel; 

  10 import org.jfree.chart.JFreeChart;

  11 import org.jfree.chart.plot.PlotOrientation;

  12 import org.jfree.chart.plot.XYPlot;

  13 import org.jfree.data.xy.XYDataset;

  14 import org.jfree.data.xy.XYSeries;

  15 import org.jfree.data.xy.XYSeriesCollection;

  16 /**

  17  * @author 20800

  18  */

  19 

  20 /* EXTENSIBILITY LIST

  21  - Make all functions types appear neatly and accurately within the window (for example tangent needs to be split by period to 

  22 avoid vertical lines and custom point entry needs to include lines going to points out of window

  23  - Make a way to save all progress and variables in the program to file so it can be opened from file

  24  - Make clear and easy directions understandable by a beginner in both math and computers do make it easily usable for everyone

  25  - Add more default function types

  26  - Add ability to enter in different math symbols such as e or pi

  27  - Add ability to just directly type in equations (so skip function type) and still be able to use variable sliders

  28  - Make the panels reformat for different window size (for example a teacher might only want it on the left half of the screen)

  29 */

  30 

  31 public class MainGUI extends javax.swing.JFrame {

  32     

  33     Searches search = new Searches(); // creates an instance of SearchFunctions class to be used (dependency)

  34     Function[] functions = new Function[10]; // creates an array of Function objects to be used (dependency)

  35     double xStepInterval = 1.0; //creates a variable used on the display panel

  36 

  37     /**

  38      * Creates new form MainFrm

  39      */

  40     public MainGUI() { //Pre Conditions: Called at the start of the program

  41         initComponents();

  42         this.setLocationRelativeTo(null);

  43         graph.setLayout(new java.awt.BorderLayout());

  44         myInit();

  45     } //Post Conditions: Sets up basic components and calls myInit()

  46     

  47     public void myInit(){ //Pre Conditions: Main GUI has been called and basic components (including Function array and search) have been initiated

  48         for(int i = 0; i < functions.length; i++){

  49             FunctionSettings fs = new FunctionSettings();

  50             functions[i] = new Function(fs);

  51             functions[i].getFunctionSettings().setName("Function " + (i+1));

  52         }

  53         refreshDisplay();

  54         refreshGraph();

  55         refreshSettings();

  56     } //Post Conditions: All Functions in the function array have proper default values set, everything is refreshed, and final component is set up

  57                     

  58     public double calculation(double num){ //Pre Conditions: double x value number to be calculated has been sent as parameter

  59         String functionType = functions[functionElementNumber()].getFunctionSettings().getFunctionType();

  60         if(functionType.equals("Square")){

  61             return Math.pow(num, 2);

  62         }else if(functionType.equals("Square Root")){

  63             return Math.sqrt(num);

  64         }else if(functionType.equals("Sine")){

  65             return Math.sin(num);

  66         }else if(functionType.equals("Cosine")){

  67             return Math.cos(num);

  68         }else if(functionType.equals("Tangent")){

  69             return Math.tan(num);

  70         }else if(functionType.equals("e^x")){

  71             return Math.pow(Math.E, num);

  72         }else if(functionType.equals("Natural Log")){

  73             return Math.log(num);

  74         }else if(functionType.equals("Cubic")){

  75             return Math.pow(num, 3);

  76         }else if(functionType.equals("Arcsine")){

  77             return Math.asin(num);

  78         }else if(functionType.equals("Arccosine")){

  79             return Math.acos(num);

  80         }else if(functionType.equals("Arctangent")){

  81             return Math.atan(num);

  82         }else if(functionType.equals("Absolute Value")){

  83             return Math.abs(num);

  84         }

  85         return num;

  86     } //Post Conditions: selected functions functionType has been found and has been used to correctly calculate the y value from the x value and it is returned

  87     

  88     public double inverseCalculation(double num){ //Pre Conditions: double y value number to be inverse calculated has been sent as parameter (this is only for the finding values y to x text fields)

  89         String functionType = functions[functionElementNumber()].getFunctionSettings().getFunctionType();

  90         if(functionType.equals("Square")){

  91             return Math.sqrt(num);

  92         }else if(functionType.equals("Square Root")){

  93             return Math.pow(num, 2);

  94         }else if(functionType.equals("Sine")){

  95             return Math.asin(num);

  96         }else if(functionType.equals("Cosine")){

  97             return Math.acos(num);

  98         }else if(functionType.equals("Tangent")){

  99             return Math.atan(num);

 100         }else if(functionType.equals("e^x")){

 101             return Math.log(num);

 102         }else if(functionType.equals("Natural Log")){

 103             return Math.pow(Math.E, num);

 104         }else if(functionType.equals("Cubic")){

 105             return Math.pow(num, (1/3.0));

 106         }else if(functionType.equals("Arcsine")){

 107             return Math.sin(num);

 108         }else if(functionType.equals("Arccosine")){

 109             return Math.cos(num);

 110         }else if(functionType.equals("Arctangent")){

 111             return Math.tan(num);

 112         }else if(functionType.equals("Absolute Value")){

 113             return Math.abs(num);

 114         }

 115         return num;

 116     } //Post Conditions: selected functions functionType has been found and has been used to correctly calculate the x value from the y value and it is returned

 117     

 118     public double transformationCalculation(double num){ //Pre Conditions: double x value number to be calculated with transformation has been sent as parameter

 119         double a = functions[functionElementNumber()].getA();

 120         double b = functions[functionElementNumber()].getB();

 121         double h = functions[functionElementNumber()].getH();

 122         double k = functions[functionElementNumber()].getK();

 123         num -= h;

 124         num *= b;

 125         double answer = calculation(num);

 126         answer *= a;

 127         answer += k;

 128         return answer;

 129     } //Post Conditions: transformations and calculations have been applied to the value to get the y value from the x value and it is returned

 130     

 131     public double inverseTransformationCalculation(double num){ //Pre Conditions: double y value number to be inverse calculated with inverse transformation has been sent as parameter (this is only for the finding values y to x text fields)

 132         double a = functions[functionElementNumber()].getA();

 133         double b = functions[functionElementNumber()].getB();

 134         double h = functions[functionElementNumber()].getH();

 135         double k = functions[functionElementNumber()].getK();

 136         num -= k;

 137         num /= a;

 138         double answer = inverseCalculation(num);

 139         answer /= b;

 140         answer += h;

 141         return answer;

 142     } //Post Conditions: inverse transformations and inverse calculations have been applied to the value to get the x value from the y value and it is returned

 143     

 144     public double xTransformation(double num){ //Pre Conditions: double x value is entered to have x value transformations applied (this is only for custom point entry)

 145         double b = functions[functionElementNumber()].getB();

 146         double h = functions[functionElementNumber()].getH();

 147         return (num*b) + h;

 148     } //Post Conditions: x value specific transformations have been applied to the number and it is returned

 149     

 150     public double yTransformation(double num){ //Pre Conditions: double y value is entered to have y value transformations applied (this is only for custom point entry)

 151         double a = functions[functionElementNumber()].getA();

 152         double k = functions[functionElementNumber()].getK();

 153         return (num*a) + k;

 154     } //Post Conditions: y value specific transformations have been applied to the number and it is returned

 155     

 156     public double round(double num){ //Pre Conditions: double to be rounded to the fourth decimal place entered in parameter

 157         double rounded = (Math.round(num*10000))/10000.0;

 158         return rounded;

 159     } //Post Conditions: double has been rounded to the fourth decimal place and returned

 160     

 161     public int functionElementNumber(){ //Pre Conditions: method is called to be used as the main Function array element number of the currently selected function from the functionSelectorComboBox at the top of the selected tab

 162         if(mainTabs.getSelectedIndex()==0){

 163             return search.sequentialSearchFunctionName(functions, displayFunctionSelectorComboBox.getSelectedItem() + "");

 164         }else{

 165             return search.sequentialSearchFunctionName(functions, settingsFunctionSelectorComboBox.getSelectedItem() + "");

 166         }

 167     } //Post Conditions: returns the int main Function array element number of the currently selected function from the functionSelectorComboBox at the top of the selected tab

 168     

 169     public void refreshSettings(){ //Pre Conditions: settings in the Table and Settings tab need to be refreshed

 170         functionTypeSelectorComboBox.setSelectedIndex(search.sequentialSearchFunctionTypeCB(functions[functionElementNumber()].getFunctionSettings().getFunctionType()));

 171         colorSelectorComboBox.setSelectedIndex(search.sequentialSearchFunctionColorCB(functions[functionElementNumber()].getFunctionSettings().getColor()));

 172         xMinTF.setText(functions[functionElementNumber()].getFunctionSettings().getxWindowMin() + "");

 173         xMaxTF.setText(functions[functionElementNumber()].getFunctionSettings().getxWindowMax() + "");

 174         yMinTF.setText(functions[functionElementNumber()].getFunctionSettings().getyWindowMin() + "");

 175         yMaxTF.setText(functions[functionElementNumber()].getFunctionSettings().getyWindowMax() + "");

 176     } //Post Conditions: all settings in the Table and Settings tab have been set to the correct value according to the selected Function

 177     

 178     public void refreshTable(){ //Pre Conditions: the table in the Table and Settings tab needs to be refreshed

 179         double tableRows = (settingsTable.getRowCount()*1.0) - 1;

 180         if(functions[functionElementNumber()].getFunctionSettings().getFunctionType().equals("Custom Point Entry")){ // for Custom Point Entry

 181             int range = functions[functionElementNumber()].getTableOfValues().size();

 182             if(range > tableRows){

 183                 range = (int)tableRows;

 184             }

 185             for(int i = 0; i < range; i++){

 186                 double xValue = functions[functionElementNumber()].getTableOfValues().get(i).getXValue();

 187                 double yValue = functions[functionElementNumber()].getTableOfValues().get(i).getYValue();

 188                 settingsTable.setValueAt(xValue, i, 0);

 189                 settingsTable.setValueAt(yValue, i, 1);

 190                 settingsTable.setValueAt("(" + xTransformation(xValue) + ", " + yTransformation(yValue) + ")", i, 2);

 191             }

 192             for(int i = (range); i <= tableRows; i++){

 193                 settingsTable.setValueAt(null, i, 0);

 194                 settingsTable.setValueAt(null, i, 1);

 195                 settingsTable.setValueAt(null, i, 2);        

 196             }

 197         }else{ // for other functionTypes

 198             int clearAfter = -1;

 199             double max = functions[functionElementNumber()].getFunctionSettings().getxWindowMax();

 200             double current = functions[functionElementNumber()].getFunctionSettings().getxWindowMin();

 201             for(int i = 0; i <= tableRows; i ++){

 202                 settingsTable.setValueAt(current, i, 0);

 203                 settingsTable.setValueAt(round(calculation(current)), i, 1);

 204                 settingsTable.setValueAt(round(transformationCalculation(current)), i, 2);

 205                 current += xStepInterval;

 206                 clearAfter = i;

 207                 if(current > max){

 208                     break;

 209                 }

 210             }

 211             for(int i = (clearAfter+1); i <= tableRows; i++){

 212                 settingsTable.setValueAt(null, i, 0);

 213                 settingsTable.setValueAt(null, i, 1);

 214                 settingsTable.setValueAt(null, i, 2);        

 215             }

 216         }

 217     } //Post Conditions: the table in the Table and Settings tab has been refreshed with all neccesary values entered

 218 

 219     public void refreshDisplay(){ //Pre Conditions: the GUI swing elements in the Display tab other than the functionSelectorComboBox and graph need to be refreshed

 220         aSliderTF.setText(functions[functionElementNumber()].getA() + "");

 221         aSlider.setValue((int)(functions[functionElementNumber()].getA()*100.0));

 222         bSliderTF.setText(functions[functionElementNumber()].getB() + "");

 223         bSlider.setValue((int)(functions[functionElementNumber()].getB()*100.0));

 224         hSliderTF.setText(functions[functionElementNumber()].getH() + "");

 225         hSlider.setValue((int)(functions[functionElementNumber()].getH()*100.0));

 226         kSliderTF.setText(functions[functionElementNumber()].getK() + "");

 227         kSlider.setValue((int)(functions[functionElementNumber()].getK()*100.0));

 228     } //Post Conditions: all the GUI swing elements in the Display tab other than the functionSelectorComboBox and graph are refreshed according to the Function selected

 229 

 230     public void refreshGraph(){ //Pre Conditions: the graph in the Display tab needs to be refreshed

 231         JFreeChart xylineChart = ChartFactory.createXYLineChart(

 232                 "Graph",

 233                 "X-Axis", "Y-Axis",

 234                 functionDataset(),

 235                 PlotOrientation.VERTICAL,

 236                 true, true, false);

 237         

 238         ChartPanel chartPanel = new ChartPanel( xylineChart );

 239         final XYPlot plot = xylineChart.getXYPlot( );

 240         graph.removeAll();    // clear panel before add new chart

 241         graph.add(chartPanel, BorderLayout.CENTER);

 242         graph.validate();       // refresh panel to display new chart

 243         chartPanel.setPreferredSize( new java.awt.Dimension( 625 , 490 ) );

 244         

 245         plot.getRenderer().setSeriesPaint(0, Color.GRAY); //Setting color for axes

 246         plot.getRenderer().setSeriesPaint(1, Color.GRAY);

 247         

 248         String color = functions[functionElementNumber()].getFunctionSettings().getColor();

 249         if(!toggleTransformation.isSelected() && !toggleOriginal.isSelected()){

 250             plot.getRenderer().setSeriesPaint(2, Color.BLACK);

 251             plot.getRenderer().setSeriesStroke( 2, new BasicStroke( 1.0f ));

 252         }else{

 253             plot.getRenderer().setSeriesStroke( 2, new BasicStroke( 2.0f ));

 254             colorFunction(2, plot, color);

 255         }

 256         

 257         plot.getRenderer().setSeriesStroke( 3, new BasicStroke( 2.0f ));

 258         colorFunction(3, plot, color);

 259        

 260         chartPanel.setDomainZoomable(true);

 261         chartPanel.setRangeZoomable(true);

 262     } //Post Conditions: the graph in the display tab have been refreshed with all neccasary values calculated and entered and all settings entered according to the selected Function in the functionSelectorComboBox

 263     

 264     public void colorFunction(int num, XYPlot plot, String color){ //Pre Conditions: (used in refreshGraph() for coloring datasets in graph) int number for the dataset needing coloring is entered, plot is entered, and String color is entered in parameter

 265         if(color.equals("Blue")){

 266             plot.getRenderer().setSeriesPaint(num, Color.BLUE);

 267         }else if(color.equals("Black")){

 268             plot.getRenderer().setSeriesPaint(num, Color.BLACK);

 269         }else if(color.equals("Green")){

 270             plot.getRenderer().setSeriesPaint(num, Color.GREEN);

 271         }else if(color.equals("Orange")){

 272             plot.getRenderer().setSeriesPaint(num, Color.ORANGE);

 273         }else if(color.equals("Purple")){

 274             plot.getRenderer().setSeriesPaint(num, Color.MAGENTA);

 275         }else if(color.equals("Yellow")){

 276             plot.getRenderer().setSeriesPaint(num, Color.YELLOW);

 277         }else if(color.equals("Gray")){

 278             plot.getRenderer().setSeriesPaint(num, Color.DARK_GRAY);

 279         }else if(color.equals("Pink")){

 280             plot.getRenderer().setSeriesPaint(num, Color.PINK);

 281         }else if(color.equals("Cyan")){

 282             plot.getRenderer().setSeriesPaint(num, Color.CYAN);

 283         }else if(color.equals("Red")){

 284             plot.getRenderer().setSeriesPaint(num, Color.RED);

 285         }

 286     } //Post Conditions: the dataset selected in the plot has been colored according to the String color entered

 287 

 288     private XYDataset functionDataset(){ //Pre Conditions: called within the refreshGraph() method to create the whole dataset for the graph

 289         final XYSeriesCollection functionDataset = new XYSeriesCollection(); //initiates collection dataset

 290         

 291         final XYSeries xAxis = new XYSeries("X Axis"); //creates x axis according to window and adds to collection dataset

 292         xAxis.add(functions[functionElementNumber()].getFunctionSettings().getxWindowMin(), 0);

 293         xAxis.add(functions[functionElementNumber()].getFunctionSettings().getxWindowMax(), 0);

 294         functionDataset.addSeries(xAxis);

 295         

 296         final XYSeries yAxis = new XYSeries("Y Axis"); //creates y axis according to window and adds to collection dataset

 297         yAxis.add(0, functions[functionElementNumber()].getFunctionSettings().getyWindowMin());

 298         yAxis.add(0, functions[functionElementNumber()].getFunctionSettings().getyWindowMax());

 299         functionDataset.addSeries(yAxis);        

 300         

 301         

 302         if(functions[functionElementNumber()].getFunctionSettings().getFunctionType().equals("Custom Point Entry")){ //creates and adds custom point entry dataset if the selected Function has that functionType

 303             if(!toggleOriginal.isSelected()){ //creates original if toogleoriginal selected

 304                 final XYSeries original = new XYSeries("Original");

 305                 for(int i = 0; i < functions[functionElementNumber()].getTableOfValues().size(); i++){

 306                     if( (functions[functionElementNumber()].getTableOfValues().get(i).getXValue() >= functions[functionElementNumber()].getFunctionSettings().getxWindowMin()) &&  (functions[functionElementNumber()].getTableOfValues().get(i).getXValue() <= functions[functionElementNumber()].getFunctionSettings().getxWindowMax())){

 307                         if( (functions[functionElementNumber()].getTableOfValues().get(i).getYValue() >= functions[functionElementNumber()].getFunctionSettings().getyWindowMin()) &&  (functions[functionElementNumber()].getTableOfValues().get(i).getYValue() <= functions[functionElementNumber()].getFunctionSettings().getyWindowMax())){

 308                         original.add(functions[functionElementNumber()].getTableOfValues().get(i).getXValue(), functions[functionElementNumber()].getTableOfValues().get(i).getYValue());

 309                         }

 310                     }

 311                 }

 312                 functionDataset.addSeries(original);

 313             }

 314 

 315             if(!toggleTransformation.isSelected()){ //creates transformation if toggleTransformation selected

 316                 final XYSeries transformation = new XYSeries("Transformation");

 317                 for(int i = 0; i < functions[functionElementNumber()].getTableOfValues().size(); i++){

 318                     if( (xTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getXValue()) >= functions[functionElementNumber()].getFunctionSettings().getxWindowMin()) &&  (xTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getXValue()) <= functions[functionElementNumber()].getFunctionSettings().getxWindowMax())){

 319                         if( (yTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getYValue()) >= functions[functionElementNumber()].getFunctionSettings().getyWindowMin()) &&  (yTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getYValue()) <= functions[functionElementNumber()].getFunctionSettings().getyWindowMax())){

 320                         transformation.add(xTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getXValue()), yTransformation(functions[functionElementNumber()].getTableOfValues().get(i).getYValue()));

 321                         }

 322                     }

 323                 }

 324                 functionDataset.addSeries(transformation);

 325             }

 326         }else{ //creates datasets for other functionTypes

 327             double interval = ( functions[functionElementNumber()].getFunctionSettings().getxWindowMax() - functions[functionElementNumber()].getFunctionSettings().getxWindowMin() )/1000.0;

 328             

 329             if(!toggleOriginal.isSelected()){ //creates original if toggleOriginal selected

 330                 final XYSeries original = new XYSeries("Original");

 331                 for(double i = functions[functionElementNumber()].getFunctionSettings().getxWindowMin(); i <= functions[functionElementNumber()].getFunctionSettings().getxWindowMax(); i+= interval){

 332                     if( (calculation(i) >= functions[functionElementNumber()].getFunctionSettings().getyWindowMin()) &&  (calculation(i) <= functions[functionElementNumber()].getFunctionSettings().getyWindowMax())){

 333                         original.add(i, calculation(i));

 334                     }

 335                 }

 336                 functionDataset.addSeries(original);

 337             }

 338 

 339             if(!toggleTransformation.isSelected()){ //creates transformation if otggleTransformation selected

 340                 final XYSeries transformation = new XYSeries("Transformation");

 341                 for(double i = functions[functionElementNumber()].getFunctionSettings().getxWindowMin(); i <= functions[functionElementNumber()].getFunctionSettings().getxWindowMax(); i+= interval){

 342                     if( (transformationCalculation(i) >= functions[functionElementNumber()].getFunctionSettings().getyWindowMin()) &&  (transformationCalculation(i) <= functions[functionElementNumber()].getFunctionSettings().getyWindowMax())){

 343                         transformation.add(i, transformationCalculation(i));

 344                     }

 345                 }

 346                 functionDataset.addSeries(transformation);

 347             }

 348         }

 349         

 350         return functionDataset; //returns colection of datasets

 351     } //Post Conditions: X axis, Y axis, original dataset (if originalToggle is selected), and transformation dataset (if transformationToggle is selected) are all calculated and added to the collection dataset and returned to the refreshGraph() method

 352 

 353     (user generated code)

1312 

1313     private void settingsFunctionSelectorComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                                  

1314         refreshSettings(); //when function selector combo box on the Table and Settings tab is changed the whole tab is refreshed and the Searches are cleared

1315         refreshTable();

1316         enterXTF.setText("");

1317         enterXResultTF.setText("");

1318         enterYTF.setText("");

1319         enterYResultTF.setText("");

1320     }                                                                 

1321 

1322     private void originalRBMouseReleased(java.awt.event.MouseEvent evt) {                                         

1323         transformationRB.setSelected(false); //makes it so only one RB is pressed at a time

1324         

1325         try { //only if possible it (if a number is in the textfields to be calculated), it completes the calculation of the number and puts it in the result text field

1326             double yValue;

1327             if(originalRB.isSelected()){

1328                 yValue = round(calculation(Double.parseDouble(enterXTF.getText())));

1329             }else{

1330                 yValue = round(transformationCalculation(Double.parseDouble(enterXTF.getText())));

1331             }

1332             enterXResultTF.setText(yValue + "");

1333 

1334             double xValue;

1335             if(originalRB.isSelected()){

1336                 xValue = round(inverseCalculation(Double.parseDouble(enterYTF.getText())));

1337             }else{

1338                 xValue = round(inverseTransformationCalculation(Double.parseDouble(enterYTF.getText())));

1339             }

1340             enterYResultTF.setText(xValue + "");

1341         }

1342             catch (NumberFormatException e) {

1343         }

1344     }                                        

1345 

1346     private void transformationRBMouseReleased(java.awt.event.MouseEvent evt) {                                               

1347         originalRB.setSelected(false); //makes it so only one RB is pressed at a time

1348         

1349         try { //only if possible it (if a number is in the textfields to be calculated), it completes the calculation of the number and puts it in the result text field

1350             double yValue;

1351             if(originalRB.isSelected()){

1352                 yValue = round(calculation(Double.parseDouble(enterXTF.getText())));

1353             }else{

1354                 yValue = round(transformationCalculation(Double.parseDouble(enterXTF.getText())));

1355             }

1356             enterXResultTF.setText(yValue + "");

1357 

1358             double xValue;

1359             if(originalRB.isSelected()){

1360                 xValue = round(inverseCalculation(Double.parseDouble(enterYTF.getText())));

1361             }else{

1362                 xValue = round(inverseTransformationCalculation(Double.parseDouble(enterYTF.getText())));

1363             }

1364             enterYResultTF.setText(xValue + "");

1365         }

1366             catch (NumberFormatException e) {

1367         }

1368     }                                              

1369 

1370     private void mainTabsMouseReleased(java.awt.event.MouseEvent evt) {                                       

1371         refreshGraph(); //when tabs are switched the table and graph are reset as their variables might have changed

1372         refreshTable();

1373     }                                      

1374     

1375     private void functionTypeSelectorComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                              

1376         if(functionTypeSelectorComboBox.hasFocus()){ //sets function type when changed

1377             functions[functionElementNumber()].getFunctionSettings().setFunctionType(functionTypeSelectorComboBox.getItemAt(functionTypeSelectorComboBox.getSelectedIndex()));

1378             refreshTable();

1379         }

1380     }                                                             

1381 

1382     private void colorSelectorComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                       

1383         if(colorSelectorComboBox.hasFocus()){ // sets color when changed

1384             functions[functionElementNumber()].getFunctionSettings().setColor(colorSelectorComboBox.getItemAt(colorSelectorComboBox.getSelectedIndex()));

1385             refreshTable();

1386         }

1387     }                                                      

1388 

1389     private void displayFunctionSelectorComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                                 

1390         refreshDisplay(); // resets Display panel tab when a differnt Function is selected

1391         refreshGraph();

1392     }                                                                

1393 

1394     /*For ALL EDITABLE text fields:

1395     When any key other than enter is pressed the text field is bolded to signify it has not been set yet

1396     When enter is pressed the value is then set if possible and if the value does not meet the data type 

1397     (which is usually double), then the text "error" appears in the text field

1398     Regardless, when enter is pressed the text is unbolded to give user feedback confirmation

1399     */

1400     

1401     private void xMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                   

1402         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //sets x window minimum and ensures minimum is less than maximum

1403             try {

1404                 functions[functionElementNumber()].getFunctionSettings().setxWindowMin(Double.parseDouble(xMinTF.getText()));

1405                 if(functions[functionElementNumber()].getFunctionSettings().getxWindowMin() >= functions[functionElementNumber()].getFunctionSettings().getxWindowMax()){

1406                     functions[functionElementNumber()].getFunctionSettings().setxWindowMax(functions[functionElementNumber()].getFunctionSettings().getxWindowMin()+1);

1407                     xMaxTF.setText((functions[functionElementNumber()].getFunctionSettings().getxWindowMin()+1) + "");

1408                 }

1409                 Font font = new Font(xMinTF.getText(), Font.PLAIN, 13);

1410                 xMinTF.setFont(font);

1411                 refreshTable();

1412             }catch (NumberFormatException e) {

1413                 Font font = new Font(xMinTF.getText(), Font.PLAIN, 13);

1414                 xMinTF.setFont(font);

1415                 xMinTF.setText("Error");

1416             }

1417         }else{

1418             Font font = new Font(xMinTF.getText(), Font.BOLD, 13);

1419             xMinTF.setFont(font);

1420         }

1421     }                                  

1422 

1423     private void xMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                   

1424         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //sets x window maximum and ensures maximum is greater than minimum

1425             try {

1426                 functions[functionElementNumber()].getFunctionSettings().setxWindowMax(Double.parseDouble(xMaxTF.getText()));

1427                 if(functions[functionElementNumber()].getFunctionSettings().getxWindowMin() >= functions[functionElementNumber()].getFunctionSettings().getxWindowMax()){

1428                     functions[functionElementNumber()].getFunctionSettings().setxWindowMin(functions[functionElementNumber()].getFunctionSettings().getxWindowMax()-1);

1429                     xMinTF.setText((functions[functionElementNumber()].getFunctionSettings().getxWindowMax()-1) + "");

1430                 }

1431                 Font font = new Font(xMaxTF.getText(), Font.PLAIN, 13);

1432                 xMaxTF.setFont(font);

1433                 refreshTable();

1434             }catch (NumberFormatException e) {

1435                 Font font = new Font(xMaxTF.getText(), Font.PLAIN, 13);

1436                 xMaxTF.setFont(font);

1437                 xMaxTF.setText("Error");

1438             }

1439         }else{

1440             Font font = new Font(xMaxTF.getText(), Font.BOLD, 13);

1441             xMaxTF.setFont(font);

1442         }

1443     }                                  

1444 

1445     private void yMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                   

1446         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //sets y window minimum and ensures minimum is less than maximum

1447             try {

1448                 functions[functionElementNumber()].getFunctionSettings().setyWindowMin(Double.parseDouble(yMinTF.getText()));

1449                 if(functions[functionElementNumber()].getFunctionSettings().getyWindowMin() >= functions[functionElementNumber()].getFunctionSettings().getyWindowMax()){

1450                     functions[functionElementNumber()].getFunctionSettings().setyWindowMax(functions[functionElementNumber()].getFunctionSettings().getyWindowMin()+1);

1451                     yMaxTF.setText((functions[functionElementNumber()].getFunctionSettings().getyWindowMin()+1) + "");

1452                 }

1453                 Font font = new Font(yMinTF.getText(), Font.PLAIN, 13);

1454                 yMinTF.setFont(font);

1455                 refreshTable();

1456             }catch (NumberFormatException e) {

1457                 Font font = new Font(yMinTF.getText(), Font.PLAIN, 13);

1458                 yMinTF.setFont(font);

1459                 yMinTF.setText("Error");

1460             }

1461         }else{

1462             Font font = new Font(yMinTF.getText(), Font.BOLD, 13);

1463             yMinTF.setFont(font);

1464         }

1465     }                                  

1466 

1467     private void yMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                   

1468         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //sets y window maximum and ensures maximum is greater than minimum

1469             try {

1470                 functions[functionElementNumber()].getFunctionSettings().setyWindowMax(Double.parseDouble(yMaxTF.getText()));

1471                 if(functions[functionElementNumber()].getFunctionSettings().getyWindowMin() >= functions[functionElementNumber()].getFunctionSettings().getyWindowMax()){

1472                     functions[functionElementNumber()].getFunctionSettings().setyWindowMin(functions[functionElementNumber()].getFunctionSettings().getyWindowMax()-1);

1473                     yMinTF.setText((functions[functionElementNumber()].getFunctionSettings().getyWindowMax()-1) + "");

1474                 }

1475                 Font font = new Font(yMaxTF.getText(), Font.PLAIN, 13);

1476                 yMaxTF.setFont(font);

1477                 refreshTable();

1478             }catch (NumberFormatException e) {

1479                 Font font = new Font(yMaxTF.getText(), Font.PLAIN, 13);

1480                 yMaxTF.setFont(font);

1481                 yMaxTF.setText("Error");

1482             }

1483         }else{

1484             Font font = new Font(yMaxTF.getText(), Font.BOLD, 13);

1485             yMaxTF.setFont(font);

1486         }

1487     }                                  

1488 

1489     private void enterXTFKeyReleased(java.awt.event.KeyEvent evt) {                                     

1490         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //completes the calculation to find the y value from x value and puts result in the result text field, does either original or transformation dependent on the radio buttons

1491             try {

1492                 if(!functions[functionElementNumber()].getFunctionSettings().getFunctionType().equals("Custom Point Entry")){

1493                     double yValue;

1494                     if(originalRB.isSelected()){

1495                         yValue = round(calculation(Double.parseDouble(enterXTF.getText())));

1496                     }else{

1497                         yValue = round(transformationCalculation(Double.parseDouble(enterXTF.getText())));

1498                     }

1499                     enterXResultTF.setText(yValue + "");

1500                 }else{

1501                     enterXResultTF.setText("Table");

1502                 }

1503                 Font font = new Font(enterXTF.getText(), Font.PLAIN, 13);

1504                 enterXTF.setFont(font);

1505             }catch (NumberFormatException e) {

1506                 Font font = new Font(enterXTF.getText(), Font.PLAIN, 13);

1507                 enterXTF.setFont(font);

1508                 enterXTF.setText("Error");

1509             }

1510         }else{

1511             Font font = new Font(enterXTF.getText(), Font.BOLD, 13);

1512             enterXTF.setFont(font);

1513         }

1514     }                                    

1515 

1516     private void enterYTFKeyReleased(java.awt.event.KeyEvent evt) {                                     

1517         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //completes the calculation to find the x value from y value and puts result in the result text field, does either original or transformation dependent on the radio buttons

1518             try {

1519                 if(!functions[functionElementNumber()].getFunctionSettings().getFunctionType().equals("Custom Point Entry")){

1520                     double xValue;

1521                     if(originalRB.isSelected()){

1522                         xValue = round(inverseCalculation(Double.parseDouble(enterYTF.getText())));

1523                     }else{

1524                         xValue = round(inverseTransformationCalculation(Double.parseDouble(enterYTF.getText())));

1525                     }

1526                     enterYResultTF.setText(xValue + "");

1527                 }else{

1528                     enterYResultTF.setText("Table");

1529                 }

1530                 Font font = new Font(enterYTF.getText(), Font.PLAIN, 13);

1531                 enterYTF.setFont(font);

1532             }catch (NumberFormatException e) {

1533                 Font font = new Font(enterYTF.getText(), Font.PLAIN, 13);

1534                 enterYTF.setFont(font);

1535                 enterYTF.setText("Error");

1536             }

1537         }else{

1538             Font font = new Font(enterYTF.getText(), Font.BOLD, 13);

1539             enterYTF.setFont(font);

1540         }

1541     }                                    

1542 

1543     private void aSliderMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1544         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //changes the aSlider minimum

1545             try {

1546                 double aSliderMin = Double.parseDouble(aSliderMinTF.getText());

1547                 aSlider.setMinimum((int)(aSliderMin*100));

1548                 aSliderMidTF.setText( round( (aSliderMin + Double.parseDouble(aSliderMaxTF.getText()))/2.0 ) + "");

1549                 Font font = new Font(aSliderMinTF.getText(), Font.PLAIN, 11);

1550                 aSliderMinTF.setFont(font);

1551             }catch (NumberFormatException e) {

1552                 Font font = new Font(aSliderMinTF.getText(), Font.PLAIN, 11);

1553                 aSliderMinTF.setFont(font);

1554                 aSliderMinTF.setText("Error");

1555             }

1556         }else{

1557             Font font = new Font(aSliderMinTF.getText(), Font.BOLD, 11);

1558             aSliderMinTF.setFont(font);

1559         }

1560     }                                        

1561 

1562     private void aSliderMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1563         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { //changes the aSlider maximum

1564             try {

1565                 double aSliderMax = Double.parseDouble(aSliderMaxTF.getText());

1566                 aSlider.setMaximum((int)(aSliderMax*100));

1567                 aSliderMidTF.setText( round( (aSliderMax + Double.parseDouble(aSliderMinTF.getText()))/2.0 ) + "");

1568                 Font font = new Font(aSliderMaxTF.getText(), Font.PLAIN, 11);

1569                 aSliderMaxTF.setFont(font);

1570             }catch (NumberFormatException e) {

1571                 Font font = new Font(aSliderMaxTF.getText(), Font.PLAIN, 11);

1572                 aSliderMaxTF.setFont(font);

1573                 aSliderMaxTF.setText("Error");

1574             }

1575         }else{

1576             Font font = new Font(aSliderMaxTF.getText(), Font.BOLD, 11);

1577             aSliderMaxTF.setFont(font);

1578         }

1579     }                                        

1580 

1581     private void bSliderMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1582         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the bSlider minimum

1583             try {

1584                 double bSliderMin = Double.parseDouble(bSliderMinTF.getText());

1585                 bSlider.setMinimum((int)(bSliderMin*100));

1586                 bSliderMidTF.setText( round( (bSliderMin + Double.parseDouble(bSliderMaxTF.getText()))/2.0 ) + "");

1587                 Font font = new Font(bSliderMinTF.getText(), Font.PLAIN, 11);

1588                 bSliderMinTF.setFont(font);

1589             }catch (NumberFormatException e) {

1590                 Font font = new Font(bSliderMinTF.getText(), Font.PLAIN, 11);

1591                 bSliderMinTF.setFont(font);

1592                 bSliderMinTF.setText("Error");

1593             }

1594         }else{

1595             Font font = new Font(bSliderMinTF.getText(), Font.BOLD, 11);

1596             bSliderMinTF.setFont(font);

1597         }

1598     }                                        

1599 

1600     private void bSliderMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1601         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the bSLider maximum

1602             try {

1603                 double bSliderMax = Double.parseDouble(bSliderMaxTF.getText());

1604                 bSlider.setMaximum((int)(bSliderMax*100));

1605                 bSliderMidTF.setText( round( (bSliderMax + Double.parseDouble(bSliderMinTF.getText()))/2.0 ) + "");

1606                 Font font = new Font(bSliderMaxTF.getText(), Font.PLAIN, 11);

1607                 bSliderMaxTF.setFont(font);

1608             }catch (NumberFormatException e) {

1609                 Font font = new Font(bSliderMaxTF.getText(), Font.PLAIN, 11);

1610                 bSliderMaxTF.setFont(font);

1611                 bSliderMaxTF.setText("Error");

1612             }

1613         }else{

1614             Font font = new Font(bSliderMaxTF.getText(), Font.BOLD, 11);

1615             bSliderMaxTF.setFont(font);

1616         }

1617     }                                        

1618 

1619     private void hSliderMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1620         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the hSlider minimum

1621             try {

1622                 double hSliderMin = Double.parseDouble(hSliderMinTF.getText());

1623                 hSlider.setMinimum((int)(hSliderMin*100));

1624                 hSliderMidTF.setText( round( (hSliderMin + Double.parseDouble(hSliderMaxTF.getText()))/2.0 ) + "");

1625                 Font font = new Font(hSliderMinTF.getText(), Font.PLAIN, 11);

1626                 hSliderMinTF.setFont(font);

1627             }catch (NumberFormatException e) {

1628                 Font font = new Font(hSliderMinTF.getText(), Font.PLAIN, 11);

1629                 hSliderMinTF.setFont(font);

1630                 hSliderMinTF.setText("Error");

1631             }

1632         }else{

1633             Font font = new Font(hSliderMinTF.getText(), Font.BOLD, 11);

1634             hSliderMinTF.setFont(font);

1635         }

1636     }                                        

1637 

1638     private void hSliderMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1639         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the hSlider maximum

1640             try {

1641                 double hSliderMax = Double.parseDouble(hSliderMaxTF.getText());

1642                 hSlider.setMaximum((int)(hSliderMax*100));

1643                 hSliderMidTF.setText( round( (hSliderMax + Double.parseDouble(hSliderMinTF.getText()))/2.0 ) + "");

1644                 Font font = new Font(hSliderMaxTF.getText(), Font.PLAIN, 11);

1645                 hSliderMaxTF.setFont(font);

1646             }catch (NumberFormatException e) {

1647                 Font font = new Font(hSliderMaxTF.getText(), Font.PLAIN, 11);

1648                 hSliderMaxTF.setFont(font);

1649                 hSliderMaxTF.setText("Error");

1650             }

1651         }else{

1652             Font font = new Font(hSliderMaxTF.getText(), Font.BOLD, 11);

1653             hSliderMaxTF.setFont(font);

1654         }

1655     }                                        

1656 

1657     private void kSliderMinTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1658         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the kSlider minimum

1659             try {

1660                 double kSliderMin = Double.parseDouble(kSliderMinTF.getText());

1661                 kSlider.setMinimum((int)(kSliderMin*100));

1662                 kSliderMidTF.setText( round( (kSliderMin + Double.parseDouble(kSliderMaxTF.getText()))/2.0 ) + "");

1663                 Font font = new Font(kSliderMinTF.getText(), Font.PLAIN, 11);

1664                 kSliderMinTF.setFont(font);

1665             }catch (NumberFormatException e) {

1666                 Font font = new Font(kSliderMinTF.getText(), Font.PLAIN, 11);

1667                 kSliderMinTF.setFont(font);

1668                 kSliderMinTF.setText("Error");

1669             }

1670         }else{

1671             Font font = new Font(kSliderMinTF.getText(), Font.BOLD, 11);

1672             kSliderMinTF.setFont(font);

1673         }

1674     }                                        

1675 

1676     private void kSliderMaxTFKeyReleased(java.awt.event.KeyEvent evt) {                                         

1677         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // changes the kSlider maximum

1678             try {

1679                 double kSliderMax = Double.parseDouble(kSliderMaxTF.getText());

1680                 kSlider.setMaximum((int)(kSliderMax*100));

1681                 kSliderMidTF.setText( round( (kSliderMax + Double.parseDouble(kSliderMinTF.getText()))/2.0 ) + "");

1682                 Font font = new Font(kSliderMaxTF.getText(), Font.PLAIN, 1112);

1683                 kSliderMaxTF.setFont(font);

1684             }catch (NumberFormatException e) {

1685                 Font font = new Font(kSliderMaxTF.getText(), Font.PLAIN, 11);

1686                 kSliderMaxTF.setFont(font);

1687                 kSliderMaxTF.setText("Error");

1688             }

1689         }else{

1690             Font font = new Font(kSliderMaxTF.getText(), Font.BOLD, 11);

1691             kSliderMaxTF.setFont(font);

1692         }

1693     }                                        

1694 

1695     private void aSliderStateChanged(javax.swing.event.ChangeEvent evt) {                                     

1696         if(aSlider.isFocusOwner()){ // sets a if aSlider changed

1697             functions[functionElementNumber()].setA(aSlider.getValue()/100.0);

1698             aSliderTF.setText(aSlider.getValue()/100.0 + "");

1699             refreshGraph();

1700         }

1701     }                                    

1702 

1703     private void bSliderStateChanged(javax.swing.event.ChangeEvent evt) {                                     

1704         if(bSlider.isFocusOwner()){ // sets b if bSlider changed

1705             functions[functionElementNumber()].setB(bSlider.getValue()/100.0);

1706             bSliderTF.setText(bSlider.getValue()/100.0 + "");

1707             refreshGraph();

1708         }

1709     }                                    

1710 

1711     private void hSliderStateChanged(javax.swing.event.ChangeEvent evt) {                                     

1712         if(hSlider.isFocusOwner()){ // sets h if hSlider changed

1713             functions[functionElementNumber()].setH(hSlider.getValue()/100.0);

1714             hSliderTF.setText(hSlider.getValue()/100.0 + "");

1715             refreshGraph();

1716         }

1717     }                                    

1718 

1719     private void kSliderStateChanged(javax.swing.event.ChangeEvent evt) {                                     

1720         if(kSlider.isFocusOwner()){ // sets k if kSlider changed

1721             functions[functionElementNumber()].setK(kSlider.getValue()/100.0);

1722             kSliderTF.setText(kSlider.getValue()/100.0 + "");

1723             refreshGraph();

1724         }

1725     }                                    

1726 

1727     private void toggleOriginalMouseReleased(java.awt.event.MouseEvent evt) {                                             

1728         refreshGraph(); //refreshes graph when toggleOriginal is switched

1729     }                                            

1730 

1731     private void toggleTransformationMouseReleased(java.awt.event.MouseEvent evt) {                                                   

1732         refreshGraph(); //refreshes graph when toggleTransformation is switched

1733     }                                                  

1734 

1735     private void aSliderTFKeyReleased(java.awt.event.KeyEvent evt) {                                      

1736         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // sets a from the TF and changes the slider appropriately if possible

1737             try {

1738                 functions[functionElementNumber()].setA(Double.parseDouble(aSliderTF.getText()));

1739                 double aNum = 100.0*Double.parseDouble(aSliderTF.getText());

1740                 if(aNum <= (Double.parseDouble(aSliderMinTF.getText())*100)){

1741                     aSlider.setValue((int)(Double.parseDouble(aSliderMinTF.getText())*100));

1742                 }else if(aNum < (Double.parseDouble(aSliderMaxTF.getText())*100)){

1743                     if(Math.abs(aNum % 1.0) < 0.5){

1744                         aSlider.setValue( ((int)aNum) );

1745                     }else{

1746                         if(aNum<0){

1747                             aSlider.setValue( ((int)(aNum - 1)) );

1748                         }else{

1749                             aSlider.setValue( ((int)(aNum + 1)) );

1750                         }

1751                     }

1752                 }else{

1753                     aSlider.setValue((int)(Double.parseDouble(aSliderMaxTF.getText())*100));

1754                 }

1755                 Font font = new Font(aSliderTF.getText(), Font.PLAIN, 13);

1756                 aSliderTF.setFont(font);

1757                 refreshGraph();

1758             }catch (NumberFormatException e){

1759                 Font font = new Font(aSliderTF.getText(), Font.PLAIN, 13);

1760                 aSliderTF.setFont(font);

1761                 aSliderTF.setText("Error");

1762             }

1763         }else{

1764             Font font = new Font(aSliderTF.getText(), Font.BOLD, 13);

1765             aSliderTF.setFont(font);

1766         }

1767     }                                     

1768 

1769     private void bSliderTFKeyReleased(java.awt.event.KeyEvent evt) {                                      

1770         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // sets b from the TF and changes the slider appropriately if possible

1771             try {

1772                 functions[functionElementNumber()].setB(Double.parseDouble(bSliderTF.getText()));

1773                 double bNum = 100.0*Double.parseDouble(bSliderTF.getText());

1774                 if(bNum <= (Double.parseDouble(bSliderMinTF.getText())*100)){

1775                     bSlider.setValue((int)(Double.parseDouble(bSliderMinTF.getText())*100));

1776                 }else if(bNum < (Double.parseDouble(bSliderMaxTF.getText())*100)){

1777                     if(Math.abs(bNum % 1.0) < 0.5){

1778                         bSlider.setValue( ((int)bNum) );

1779                     }else{

1780                         if(bNum<0){

1781                             bSlider.setValue( ((int)(bNum - 1)) );

1782                         }else{

1783                             bSlider.setValue( ((int)(bNum + 1)) );

1784                         }

1785                     }

1786                 }else{

1787                     bSlider.setValue((int)(Double.parseDouble(bSliderMaxTF.getText())*100));

1788                 }

1789                 Font font = new Font(bSliderTF.getText(), Font.PLAIN, 13);

1790                 bSliderTF.setFont(font);

1791                 refreshGraph();

1792             }catch (NumberFormatException e){

1793                 Font font = new Font(bSliderTF.getText(), Font.PLAIN, 13);

1794                 bSliderTF.setFont(font);

1795                 bSliderTF.setText("Error");

1796             }

1797         }else{

1798             Font font = new Font(bSliderTF.getText(), Font.BOLD, 13);

1799             bSliderTF.setFont(font);

1800         }

1801     }                                     

1802 

1803     private void hSliderTFKeyReleased(java.awt.event.KeyEvent evt) {                                      

1804         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // sets h from the TF and changes the slider appropriately if possible

1805             try {

1806                 functions[functionElementNumber()].setH(Double.parseDouble(hSliderTF.getText()));

1807                 double hNum = 100.0*Double.parseDouble(hSliderTF.getText());

1808                 if(hNum <= (Double.parseDouble(hSliderMinTF.getText())*100)){

1809                     hSlider.setValue((int)(Double.parseDouble(hSliderMinTF.getText())*100));

1810                 }else if(hNum < (Double.parseDouble(hSliderMaxTF.getText())*100)){

1811                     if(Math.abs(hNum % 1.0) < 0.5){

1812                         hSlider.setValue(((int)hNum) );

1813                     }else{

1814                         if(hNum<0){

1815                             hSlider.setValue(((int)(hNum - 1)) );

1816                         }else{

1817                             hSlider.setValue(((int)(hNum + 1)) );

1818                         }

1819                     }

1820                 }else{

1821                     hSlider.setValue((int)(Double.parseDouble(hSliderMaxTF.getText())*100));

1822                 }

1823                 Font font = new Font(hSliderTF.getText(), Font.PLAIN, 13);

1824                 hSliderTF.setFont(font);

1825                 refreshGraph();

1826             }catch (NumberFormatException e){

1827                 Font font = new Font(hSliderTF.getText(), Font.PLAIN, 13);

1828                 hSliderTF.setFont(font);

1829                 hSliderTF.setText("Error");

1830             }

1831         }else{

1832             Font font = new Font(hSliderTF.getText(), Font.BOLD, 13);

1833             hSliderTF.setFont(font);

1834         }

1835     }                                     

1836 

1837     private void kSliderTFKeyReleased(java.awt.event.KeyEvent evt) {                                      

1838         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // sets k from the TF and changes the slider appropriately if possible

1839             try {

1840                 functions[functionElementNumber()].setK(Double.parseDouble(kSliderTF.getText()));

1841                 double kNum = 100.0*Double.parseDouble(kSliderTF.getText());

1842                 if(kNum <= (Double.parseDouble(kSliderMinTF.getText())*100)){

1843                     aSlider.setValue((int)(Double.parseDouble(kSliderMinTF.getText())*100));

1844                 }else if(kNum < (Double.parseDouble(kSliderMaxTF.getText())*100)){

1845                     if(Math.abs(kNum % 1.0) < 0.5){

1846                         kSlider.setValue(((int)kNum) );

1847                     }else{

1848                         if(kNum<0){

1849                             kSlider.setValue(((int)(kNum - 1)) );

1850                         }else{

1851                             kSlider.setValue(((int)(kNum + 1)) );

1852                         }

1853                     }

1854                 }else{

1855                     kSlider.setValue((int)(Double.parseDouble(kSliderMaxTF.getText())*100));

1856                 }

1857                 Font font = new Font(kSliderTF.getText(), Font.PLAIN, 13);

1858                 kSliderTF.setFont(font);

1859                 refreshGraph();

1860             }catch (NumberFormatException e){

1861                 Font font = new Font(kSliderTF.getText(), Font.PLAIN, 13);

1862                 kSliderTF.setFont(font);

1863                 kSliderTF.setText("Error");

1864             }

1865         }else{

1866             Font font = new Font(kSliderTF.getText(), Font.BOLD, 13);

1867             kSliderTF.setFont(font);

1868         }

1869     }                                     

1870 

1871     private void addButtonMouseReleased(java.awt.event.MouseEvent evt) {                                        

1872         try { //adds point from x and y textfields for Custom Point Entry, clears text fields, and refreshes graph. If possible.

1873             XYPoint e = new XYPoint();

1874             e.setXValue(Double.parseDouble(xPointEntryTF.getText()));

1875             e.setYValue(Double.parseDouble(yPointEntryTF.getText()));

1876             functions[functionElementNumber()].getTableOfValues().add(e);

1877             xPointEntryTF.setText("");

1878             yPointEntryTF.setText("");

1879 

1880             refreshTable();

1881         }

1882             catch (NumberFormatException e) {

1883         }

1884     }                                       

1885 

1886     private void removeButtonMouseReleased(java.awt.event.MouseEvent evt) {                                           

1887         try { //removes point from x and y textfields for Custom Point Entry, clears text fields, and refreshes graph. If possible.

1888             for(int i = 0; i < functions[functionElementNumber()].getTableOfValues().size(); i++){

1889                 if( functions[functionElementNumber()].getTableOfValues().get(i).getXValue() == Double.parseDouble(xPointEntryTF.getText())){

1890                     if( functions[functionElementNumber()].getTableOfValues().get(i).getYValue() == Double.parseDouble(yPointEntryTF.getText())){

1891                         functions[functionElementNumber()].getTableOfValues().remove(i);

1892                     }

1893                 }

1894             }

1895             xPointEntryTF.setText("");

1896             yPointEntryTF.setText("");

1897 

1898             refreshTable();

1899         }

1900             catch (NumberFormatException e) {

1901         }

1902     }                                          

1903 

1904     private void xStepTFKeyReleased(java.awt.event.KeyEvent evt) {                                    

1905         if(evt.getKeyCode() == KeyEvent.VK_ENTER) { // sets k from the TF and changes the slider appropriately if possible

1906             if(Double.parseDouble(xStepTF.getText()) == 0){

1907                     Font font = new Font(xStepTF.getText(), Font.PLAIN, 13);

1908                     xStepTF.setFont(font);

1909                     xStepTF.setText("Error");

1910             }else{ 

1911                 try {

1912                     if(Double.parseDouble(xStepTF.getText()) < 0){

1913                         xStepTF.setText(-1*Double.parseDouble(xStepTF.getText()) + "");

1914                     }

1915                     xStepInterval = Double.parseDouble(xStepTF.getText());

1916                     Font font = new Font(xStepTF.getText(), Font.PLAIN, 13);

1917                     xStepTF.setFont(font);

1918                     refreshTable();

1919                 }catch (NumberFormatException e){

1920                     Font font = new Font(xStepTF.getText(), Font.PLAIN, 13);

1921                     xStepTF.setFont(font);

1922                     xStepTF.setText("Error");

1923                 }

1924             }

1925         }else{

1926             Font font = new Font(xStepTF.getText(), Font.BOLD, 13);

1927             xStepTF.setFont(font);

1928         }

1929     }                                   

1930 

1931     /**

1932      * @param args the command line arguments

1933      */

1934     public static void main(String args[]) {

1935         /* Set the Nimbus look and feel */

1936         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

1937         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

1938          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 

1939          */

1940         try {

1941             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

1942                 if ("Nimbus".equals(info.getName())) {

1943                     javax.swing.UIManager.setLookAndFeel(info.getClassName());

1944                     break;

1945                 }

1946             }

1947         } catch (ClassNotFoundException ex) {

1948             java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

1949         } catch (InstantiationException ex) {

1950             java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

1951         } catch (IllegalAccessException ex) {

1952             java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

1953         } catch (javax.swing.UnsupportedLookAndFeelException ex) {

1954             java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

1955         }

1956         //</editor-fold>

1957         //</editor-fold>

1958 

1959         /* Create and display the form */

1960         java.awt.EventQueue.invokeLater(new Runnable() {

1961             public void run() {

1962                 new MainGUI().setVisible(true);

1963             }

1964         });

1965     }



SAMPLE OF GENERATED CODE BY NETBEANS




/**

 354      * This method is called from within the constructor to initialize the form.

 355      * WARNING: Do NOT modify this code. The content of this method is always

 356      * regenerated by the Form Editor.

 357      */

 358     @SuppressWarnings("unchecked")

 359     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

 360     private void initComponents() {

 361 

 362         mainTabs = new javax.swing.JTabbedPane();

 363         displayPanel = new javax.swing.JPanel();

 364         graph = new javax.swing.JPanel();

 365         displayFunctionSelectorComboBox = new javax.swing.JComboBox<>();

 366         aValueLabel = new javax.swing.JLabel();

 367         toggleOriginal = new javax.swing.JToggleButton();

 368         aSlider = new javax.swing.JSlider();

 369         aSliderTF = new javax.swing.JTextField();

 370         bValueLabel = new javax.swing.JLabel();

 371         bSliderTF = new javax.swing.JTextField();

 372         hValueLabel = new javax.swing.JLabel();

 373         hSliderTF = new javax.swing.JTextField();

 374         kValueLabel = new javax.swing.JLabel();

 375         kSlider = new javax.swing.JSlider();

 376         kSliderTF = new javax.swing.JTextField();

 377         toggleTransformation = new javax.swing.JToggleButton();

 432 

 433         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 434 

 435         mainTabs.addMouseListener(new java.awt.event.MouseAdapter() {

 436             public void mouseReleased(java.awt.event.MouseEvent evt) {

 437                 mainTabsMouseReleased(evt);

 438             }

 439         });

 440 

 441         graph.setBorder(javax.swing.BorderFactory.createEtchedBorder());

 442 

 443         javax.swing.GroupLayout graphLayout = new javax.swing.GroupLayout(graph);

 444         graph.setLayout(graphLayout);

 445         graphLayout.setHorizontalGroup(

 446             graphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 447             .addGap(0, 532, Short.MAX_VALUE)

 448         );

 449         graphLayout.setVerticalGroup(

 450             graphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 451             .addGap(0, 466, Short.MAX_VALUE)

 452         );

 453 

 454         displayFunctionSelectorComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Function 1", "Function 2", "Function 3", "Function 4 ", "Function 5", "Function 6", "Function 7", "Function 8", "Function 9", "Function 10" }));

 455         displayFunctionSelectorComboBox.addItemListener(new java.awt.event.ItemListener() {

 456             public void itemStateChanged(java.awt.event.ItemEvent evt) {

 457                 displayFunctionSelectorComboBoxItemStateChanged(evt);

 458             }

 459         });

 460 

 461         aValueLabel.setText("a Value");

 462 

 463         toggleOriginal.setText("Toggle Original");

 464         toggleOriginal.addMouseListener(new java.awt.event.MouseAdapter() {

 465             public void mouseReleased(java.awt.event.MouseEvent evt) {

 466                 toggleOriginalMouseReleased(evt);

 467             }

 468         });

 469 

 470         aSlider.setMaximum(300);

 471         aSlider.setMinimum(-300);

 472         aSlider.setMinorTickSpacing(100);

 473         aSlider.setPaintTicks(true);

 474         aSlider.setToolTipText("");

 475         aSlider.setValue(100);

 476         aSlider.setPreferredSize(new java.awt.Dimension(190, 25));

 477         aSlider.addChangeListener(new javax.swing.event.ChangeListener() {

 478             public void stateChanged(javax.swing.event.ChangeEvent evt) {

 479                 aSliderStateChanged(evt);

 480             }

 481         });

 482 

 483         aSliderTF.addKeyListener(new java.awt.event.KeyAdapter() {

 484             public void keyReleased(java.awt.event.KeyEvent evt) {

 485                 aSliderTFKeyReleased(evt);

 486             }

 487         });

 488 

  644 

 645         javax.swing.GroupLayout displayPanelLayout = new javax.swing.GroupLayout(displayPanel);

 646         displayPanel.setLayout(displayPanelLayout);

 647         displayPanelLayout.setHorizontalGroup(

 648             displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 649             .addGroup(displayPanelLayout.createSequentialGroup()

 650                 .addContainerGap()

 651                 .addGroup(displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

 652                     .addGroup(displayPanelLayout.createSequentialGroup()

 653                         .addGap(6, 6, 6)

 654                         .addGroup(displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 655                             .addGroup(displayPanelLayout.createSequentialGroup()

 656                                 .addComponent(bSliderMinTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)

 657                                 .addGap(41, 41, 41)

 658                                 .addComponent(bSliderMidTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))

 659                             .addGroup(displayPanelLayout.createSequentialGroup()

 660                                 .addComponent(kSliderMinTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)

 661                                 .addGap(41, 41, 41)

 662                                 .addComponent(kSliderMidTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)

 663                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

 664                                 .addComponent(kSliderMaxTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))))

 665                     .addGroup(displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

 666                         .addComponent(bSliderMaxTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)

 667                         .addGroup(displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

 668                             .addComponent(toggleTransformation, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)

 669                             .addComponent(aSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)

 670                             .addGroup(displayPanelLayout.createSequentialGroup()

 671                                 .addGap(14, 14, 14)

 672                                 .addGroup(displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

 673                                     .addComponent(transformationGuideLabel)

 674                                     .addGroup(displayPanelLayout.createSequentialGroup()

 675                                         .addComponent(aValueLabel)

 676                                         .addGap(18, 18, 18)

 677                                         .addComponent(aSliderTF, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))

 678                                     .addComponent(displayFunctionSelectorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))

 679                             .addComponent(toggleOriginal, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)

 680                             .addComponent(kSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)

 681                             .addComponent(hSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)

 682                             .addComponent(bSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)

 683                             .addGroup(displayPanelLayout.createSequentialGroup()

 684                                 .addGap(12, 12, 12)

 685                                 .addComponent(bValueLabel)

 686                                 .addGap(18, 18, 18)

 687                                 .addComponent(bSliderTF, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))

 688                             .addGroup(displayPanelLayout.createSequentialGroup()

 689                                 .addGap(12, 12, 12)

 690                                 .addComponent(hValueLabel)

 691                                 .addGap(18, 18, 18)

 692                                 .addComponent(hSliderTF, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))

 693                             .addGroup(displayPanelLayout.createSequentialGroup()

 694                                 .addGap(6, 6, 6)

 695                                 .addComponent(hSliderMinTF, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)

  987         settingsTable.setGridColor(new java.awt.Color(0, 0, 0));

 988         settingsTable.setShowGrid(true);

 989         tableScrollPane.setViewportView(settingsTable);

 990 

 991         functionTypeSelectorComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Square", "Square Root", "Slope Intercept", "Custom Point Entry", "Sine", "Cosine", "Tangent", "e^x", "Natural Log", "Cubic", "Arcsine", "Arccosine", "Arctangent", "Absolute Value" }));

 992         functionTypeSelectorComboBox.addItemListener(new java.awt.event.ItemListener() {

 993             public void itemStateChanged(java.awt.event.ItemEvent evt) {

 994                 functionTypeSelectorComboBoxItemStateChanged(evt);

 995             }

 996         });

 997 

 998         AddRemoveFunctionLabel.setText("Function Selector:");

 999 

1000         colorLabel.setText("Color:");

1001 

1002         windowLabel.setText("Window:");

1003 

1004         xMinLabel.setText("X min:");

1005 

1006         yMinLabel.setText("Y min:");

1007 

1008         yMaxLabel.setText("Y max:");

1009 

1010         xMaxLabel.setText("X max:");

1011 

1012         xMinTF.addKeyListener(new java.awt.event.KeyAdapter() {

1013             public void keyReleased(java.awt.event.KeyEvent evt) {

1014                 xMinTFKeyReleased(evt);

1015             }

1016         });

1017 

1018         yMinTF.addKeyListener(new java.awt.event.KeyAdapter() {

1019             public void keyReleased(java.awt.event.KeyEvent evt) {

1020                 yMinTFKeyReleased(evt);

1021             }

1022         });

1023 

1024         xMaxTF.addKeyListener(new java.awt.event.KeyAdapter() {

1025             public void keyReleased(java.awt.event.KeyEvent evt) {

1026                 xMaxTFKeyReleased(evt);

1027             }

1028         });

1029 

1030         yMaxTF.addKeyListener(new java.awt.event.KeyAdapter() {

1031             public void keyReleased(java.awt.event.KeyEvent evt) {

1032                 yMaxTFKeyReleased(evt);

1033             }

1034         });

1035 

1310         pack();

1311     }// </editor-fold>                        



1966 

1967     // Variables declaration - do not modify                     

1968     private javax.swing.JLabel AddRemoveFunctionLabel;

1969     private javax.swing.JSlider aSlider;

1970     private javax.swing.JTextField aSliderMaxTF;

1971     private javax.swing.JTextField aSliderMidTF;

1972     private javax.swing.JTextField aSliderMinTF;

1973     private javax.swing.JTextField aSliderTF;

1974     private javax.swing.JLabel aValueLabel;

1975     private javax.swing.JButton addButton;

1976     private javax.swing.JSlider bSlider;

1977     private javax.swing.JTextField bSliderMaxTF;

1978     private javax.swing.JTextField bSliderMidTF;

1979     private javax.swing.JTextField bSliderMinTF;

1980     private javax.swing.JTextField bSliderTF;

1981     private javax.swing.JLabel bValueLabel;

1982     private javax.swing.JLabel colorLabel;

1983     private javax.swing.JComboBox<String> colorSelectorComboBox;

1984     private javax.swing.JLabel customPointEntryLabel;

1985     private javax.swing.JComboBox<String> displayFunctionSelectorComboBox;

1986     private javax.swing.JPanel displayPanel;

1987     private javax.swing.JLabel enterXLabel;

1988     private javax.swing.JTextField enterXResultTF;

1989     private javax.swing.JTextField enterXTF;

1990     private javax.swing.JLabel enterYLabel;

1991     private javax.swing.JTextField enterYResultTF;

1992     private javax.swing.JTextField enterYTF;

1993     private javax.swing.JLabel findingValuesLabel;

1994     private javax.swing.JLabel functionTypeLabel;

1995     private javax.swing.JComboBox<String> functionTypeSelectorComboBox;

1996     private javax.swing.JPanel graph;

1997     private javax.swing.JSlider hSlider;

1998     private javax.swing.JTextField hSliderMaxTF;

1999     private javax.swing.JTextField hSliderMidTF;

2000     private javax.swing.JTextField hSliderMinTF;

2001     private javax.swing.JTextField hSliderTF;

2002     private javax.swing.JLabel hValueLabel;

2003     private javax.swing.JSlider kSlider;

2004     private javax.swing.JTextField kSliderMaxTF;

2005     private javax.swing.JTextField kSliderMidTF;

2006     private javax.swing.JTextField kSliderMinTF;

2007     private javax.swing.JTextField kSliderTF;

2008     private javax.swing.JLabel kValueLabel;

2009     private javax.swing.JTabbedPane mainTabs;

2010     private javax.swing.JRadioButton originalRB;

2011     private javax.swing.JButton removeButton;

2012     private javax.swing.JComboBox<String> settingsFunctionSelectorComboBox;

2013     private javax.swing.JTable settingsTable;

2014     private javax.swing.JPanel tableAndSettingsPanel;

2015     private javax.swing.JLabel tableOfValuesLabel;

2016     private javax.swing.JScrollPane tableScrollPane;

2017     private javax.swing.JToggleButton toggleOriginal;

2018     private javax.swing.JToggleButton toggleTransformation;

2019     private javax.swing.JLabel transformationGuideLabel;

2020     private javax.swing.JRadioButton transformationRB;

2021     private javax.swing.JLabel windowLabel;

2022     private javax.swing.JLabel xLabel;

2023     private javax.swing.JLabel xLabel1;

2024     private javax.swing.JLabel xMaxLabel;

2025     private javax.swing.JTextField xMaxTF;

2026     private javax.swing.JLabel xMinLabel;

2027     private javax.swing.JTextField xMinTF;

2028     private javax.swing.JTextField xPointEntryTF;

2029     private javax.swing.JLabel xStepLabel;

2030     private javax.swing.JTextField xStepTF;

2031     private javax.swing.JLabel yLabel;

2032     private javax.swing.JLabel yLabel1;

2033     private javax.swing.JLabel yMaxLabel;

2034     private javax.swing.JTextField yMaxTF;

2035     private javax.swing.JLabel yMinLabel;

2036     private javax.swing.JTextField yMinTF;

2037     private javax.swing.JTextField yPointEntryTF;

2038     // End of variables declaration                   

2039 }

2040