kodejava-2d-api/src/main/java/org/kodejava/example/geom/Plot.java
private boolean readFile(File datafile) {
        int numAllocated = 10;
        int numRead = 0;
        int numDataPoints = 0;
        String[] dataStrings = new String[numAllocated];
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new FileReader(datafile));
            String text;
            while ((text = reader.readLine()) != null) {
                if (numRead >= numAllocated) {
                    numAllocated = 2 * numAllocated;
                    String[] temp = dataStrings;
                    dataStrings = new String[numAllocated];
                    System.arraycopy(temp, 0, dataStrings, 0, numRead);
                }

                dataStrings[numRead] = text;
                numRead = numRead + 1;
            }
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
        } catch (IOException e) {
            System.out.println("IO Exception");
        }
        try {
            if (reader != null)
                reader.close();
        } catch (IOException e) {
            System.out.println("IO Exception on close");
        }

        int thisCase = -2;
        int thisDataPoint = 0;
        for (int i = 0; i < numRead; i++) {
            String[] segments = dataStrings[i].split(" ");
            if (segments[0].equals("Title")) {
                thisCase = titleIndex;
            } else if (segments[0].equals("xTitle")) {
                thisCase = xTitleIndex;
            } else if (segments[0].equals("yTitle")) {
                thisCase = yTitleIndex;
            } else if (segments[0].equals("xLower")) {
                thisCase = xLowerIndex;
            } else if (segments[0].equals("xUpper")) {
                thisCase = xUpperIndex;
            } else if (segments[0].equals("xInterval")) {
                thisCase = xIntervalIndex;
            } else if (segments[0].equals("yLower")) {
                thisCase = yLowerIndex;
            } else if (segments[0].equals("yUpper")) {
                thisCase = yUpperIndex;
            } else if (segments[0].equals("yInterval")) {
                thisCase = yIntervalIndex;
            } else if (segments[0].equals("Data")) {
                thisCase = -1;
                numDataPoints = numRead - i - 1;
                dataFields = new JTextField[2 * numDataPoints];
                points = new Point2D.Float[numDataPoints];
            } else if (thisCase != -1) {
                thisCase = -2;
            }

            if (thisCase >= 0 && segments.length > 1) {
                StringBuilder temp = new StringBuilder(segments[1]);
                for (int j = 2; j < segments.length; j++)
                    temp.append(" ").append(segments[j]);
                paramFields[thisCase].setText(temp.toString());
                thisCase = -2;
            } else if (thisCase == -1 && !segments[0].equals("Data")
                && thisDataPoint < numDataPoints) {
                dataFields[2 * thisDataPoint] = new JTextField(segments[0]);
                dataFields[2 * thisDataPoint + 1] = new JTextField(segments[1]);
                thisDataPoint++;
            }
        }


        frame.getContentPane().remove(panel);
        panel = new JPanel(new GridLayout(9 + numDataPoints, 2));
        for (int i = 0; i < 9; i++) {
            panel.add(paramLabels[i]);
            panel.add(paramFields[i]);
        }
        for (int i = 0; i < numDataPoints; i++) {
            panel.add(dataFields[2 * i]);
            panel.add(dataFields[2 * i + 1]);
        }
        frame.getContentPane().add(panel, "West");

        return true;
    }
// The second section contains the data pairs that will be graphed.
The second section contains the data pairs that will be graphed.
The second section contains the data pairs that will be graphed .
private boolean readFile(File datafile) {
        int numAllocated = 10;
        int numRead = 0;
        int numDataPoints = 0;
        String[] dataStrings = new String[numAllocated];
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(datafile));
            String text;
            while ((text = reader.readLine()) != null) {
                if (numRead >= numAllocated) {
                    numAllocated = 2 * numAllocated;
                    String[] temp = dataStrings;
                    dataStrings = new String[numAllocated];
                    System.arraycopy(temp, 0, dataStrings, 0, numRead);
                }
                dataStrings[numRead] = text;
                numRead = numRead + 1;
            }
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
        } catch (IOException e) {
            System.out.println("IO Exception");
        }
        try {
            if (reader != null)
                reader.close();
        } catch (IOException e) {
            System.out.println("IO Exception on close");
        }
        int thisCase = -2;
        int thisDataPoint = 0;
        for (int i = 0; i < numRead; i++) {
            String[] segments = dataStrings[i].split(" ");
            if (segments[0].equals("Title")) {
                thisCase = titleIndex;
            } else if (segments[0].equals("xTitle")) {
                thisCase = xTitleIndex;
            } else if (segments[0].equals("yTitle")) {
                thisCase = yTitleIndex;
            } else if (segments[0].equals("xLower")) {
                thisCase = xLowerIndex;
            } else if (segments[0].equals("xUpper")) {
                thisCase = xUpperIndex;
            } else if (segments[0].equals("xInterval")) {
                thisCase = xIntervalIndex;
            } else if (segments[0].equals("yLower")) {
                thisCase = yLowerIndex;
            } else if (segments[0].equals("yUpper")) {
                thisCase = yUpperIndex;
            } else if (segments[0].equals("yInterval")) {
                thisCase = yIntervalIndex;
            } else if (segments[0].equals("Data")) {
                thisCase = -1;
                numDataPoints = numRead - i - 1;
                dataFields = new JTextField[2 * numDataPoints];
                points = new Point2D.Float[numDataPoints];
            } else if (thisCase != -1) {
                thisCase = -2;
            }
            if (thisCase >= 0 && segments.length > 1) {
                StringBuilder temp = new StringBuilder(segments[1]);
                for (int j = 2; j < segments.length; j++)
                    temp.append(" ").append(segments[j]);
                paramFields[thisCase].setText(temp.toString());
                thisCase = -2;
            } else if (thisCase == -1 && !segments[0].equals("Data")
                && thisDataPoint < numDataPoints) {
                dataFields[2 * thisDataPoint] = new JTextField(segments[0]);
                dataFields[2 * thisDataPoint + 1] = new JTextField(segments[1]);
                thisDataPoint++;
            }
        }
        frame.getContentPane().remove(panel);
        panel = new JPanel(new GridLayout(9 + numDataPoints, 2));
        for (int i = 0; i < 9; i++) {
            panel.add(paramLabels[i]);
            panel.add(paramFields[i]);
        }
        for (int i = 0; i < numDataPoints; i++) {
            panel.add(dataFields[2 * i]);
            panel.add(dataFields[2 * i + 1]);
        }
        frame.getContentPane().add(panel, "West");
        return true;
    }
private boolean readFile ( File datafile ) { int numAllocated = 10 ; int numRead = 0 ; int numDataPoints = 0 ; String [ ] dataStrings = new String [ numAllocated ] ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( datafile ) ) ; String text ; while ( ( text = reader . readLine ( ) ) != null ) { if ( numRead >= numAllocated ) { numAllocated = 2 * numAllocated ; String [ ] temp = dataStrings ; dataStrings = new String [ numAllocated ] ; System . arraycopy ( temp , 0 , dataStrings , 0 , numRead ) ; } dataStrings [ numRead ] = text ; numRead = numRead + 1 ; } } catch ( FileNotFoundException e ) { System . out . println ( "File not found" ) ; } catch ( IOException e ) { System . out . println ( "IO Exception" ) ; } try { if ( reader != null ) reader . close ( ) ; } catch ( IOException e ) { System . out . println ( "IO Exception on close" ) ; } int thisCase = - 2 ; int thisDataPoint = 0 ; for ( int i = 0 ; i < numRead ; i ++ ) { String [ ] segments = dataStrings [ i ] . split ( " " ) ; if ( segments [ 0 ] . equals ( "Title" ) ) { thisCase = titleIndex ; } else if ( segments [ 0 ] . equals ( "xTitle" ) ) { thisCase = xTitleIndex ; } else if ( segments [ 0 ] . equals ( "yTitle" ) ) { thisCase = yTitleIndex ; } else if ( segments [ 0 ] . equals ( "xLower" ) ) { thisCase = xLowerIndex ; } else if ( segments [ 0 ] . equals ( "xUpper" ) ) { thisCase = xUpperIndex ; } else if ( segments [ 0 ] . equals ( "xInterval" ) ) { thisCase = xIntervalIndex ; } else if ( segments [ 0 ] . equals ( "yLower" ) ) { thisCase = yLowerIndex ; } else if ( segments [ 0 ] . equals ( "yUpper" ) ) { thisCase = yUpperIndex ; } else if ( segments [ 0 ] . equals ( "yInterval" ) ) { thisCase = yIntervalIndex ; } else if ( segments [ 0 ] . equals ( "Data" ) ) { thisCase = - 1 ; numDataPoints = numRead - i - 1 ; dataFields = new JTextField [ 2 * numDataPoints ] ; points = new Point2D . Float [ numDataPoints ] ; } else if ( thisCase != - 1 ) { thisCase = - 2 ; } if ( thisCase >= 0 && segments . length > 1 ) { StringBuilder temp = new StringBuilder ( segments [ 1 ] ) ; for ( int j = 2 ; j < segments . length ; j ++ ) temp . append ( " " ) . append ( segments [ j ] ) ; paramFields [ thisCase ] . setText ( temp . toString ( ) ) ; thisCase = - 2 ; } else if ( thisCase == - 1 && ! segments [ 0 ] . equals ( "Data" ) && thisDataPoint < numDataPoints ) { dataFields [ 2 * thisDataPoint ] = new JTextField ( segments [ 0 ] ) ; dataFields [ 2 * thisDataPoint + 1 ] = new JTextField ( segments [ 1 ] ) ; thisDataPoint ++ ; } } frame . getContentPane ( ) . remove ( panel ) ; panel = new JPanel ( new GridLayout ( 9 + numDataPoints , 2 ) ) ; for ( int i = 0 ; i < 9 ; i ++ ) { panel . add ( paramLabels [ i ] ) ; panel . add ( paramFields [ i ] ) ; } for ( int i = 0 ; i < numDataPoints ; i ++ ) { panel . add ( dataFields [ 2 * i ] ) ; panel . add ( dataFields [ 2 * i + 1 ] ) ; } frame . getContentPane ( ) . add ( panel , "West" ) ; return true ; }
The second section contains the data pairs that will be graphed.
The second section contains the data pairs that will be graphed .