Exemple #1
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      System.exit(-1);
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      System.exit(-1);
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      System.exit(-1);
    }
    // do the replacement.

    for (i = 0; i < COMPONENTS; i++) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "$$$" + (i + 1);
      // get the position of the search string in the content string.
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(str1);
      strBuf.replace(posFound, posFound + str1.length(), sliderValue);
      strContent = new String(strBuf);
    }
    textPane.setText(strContent);
  }
Exemple #2
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    RandomAccessFile access = null;
    String tempFile = "temp" + round + ".html";
    File fp = new File(tempFile);
    boolean firstChoice = true;
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // round += 1;
    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      // System.exit(-1);;
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      // System.exit(-1);;
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      // System.exit(-1);;
    }
    // do the replacement.
    // First having to update the code part that is active in this section before
    // doing variables updated. Look at the current active radiobutton to make decision
    if (secondBox.isSelected() == true) firstChoice = false;
    if (firstChoice == true) {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr2);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr2.length(), tempStr);
      strContent = new String(strBuf);
    } else {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr1);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr1.length(), tempStr);
      strContent = new String(strBuf);
    }
    for (i = COMPONENTS; i > 0; i--) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i - 1);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "JPOT$" + i;
      // get the position of the search string in the content string.
      while ((posFound = strContent.indexOf(str1)) != -1) {
        strBuf = new StringBuffer(strContent);
        strBuf.replace(posFound, posFound + str1.length(), sliderValue);
        strContent = new String(strBuf);
      }
    }

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    try {
      textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
      URL url = new URL("file:" + tempFile + "#gohere");
      textPane.setPage(url);
      delete = fp.delete();
    } catch (IOException ie) {
      System.err.println("Can not get the example html file " + ie);
      // System.exit(-1);;
    }
  }