示例#1
0
  // Method to open a file for sequential read-only.
  private void openFile() {
    // Define local primitive(s).
    String contents = new String();

    // If a file is open, prompt to save the file before dismissing content
    // and reference.
    if (!file.toString().equals("")) {
      // Close the existing file.
      closeFile();
    } // End of if file not null or not equal to a zero String.

    // Open a file.
    fileName = FileIO.findFile(this);

    // If a file name is returned.
    if (fileName != null) {
      // Read file.
      contents = FileIO.openFile(this, fileName);

      // Verify that the JTextAreaPanel is empty.
      if (sender.isTextAreaEmpty()) {
        // Set JTextAreaPanel.
        sender.setText(contents);

      } // End of if JTextAreaPanel is empty.
      else {
        // Reset JTextAreaPanel by replacing the range.
        sender.replaceRange(contents, 0, sender.getText().length());
      } // End of else JTextAreaPanel is not empty.

      // Set file open flag to true.
      fileOpen = true;
    } // End of if a fileName is selected.
  } // End of openFile method.
示例#2
0
  // Method to closeFile().
  private void closeFile() {
    // Dismiss file reference.
    fileName = new File("");

    // If JTextAreaPanel contains text.
    if (!sender.isTextAreaEmpty()) {
      // Clear display area.
      sender.replaceRange(null, 0, sender.getText().length());
    } // End of if check if JTextAreaPanel contains text.
  } // End of closeFile() method.
示例#3
0
  // Define a setMessage() method.
  private void setMessage(JTextAreaPanel out, JTextAreaPanel in) {
    // Try to get incoming message.
    try {
      // Send message text.
      in.setMessage(out.getText());

      // Consume sent message text.
      out.replaceRange(null, 0, out.getText().length());

    } // End of try to get message.

    // Catch BufferEmptyException.
    catch (BufferEmptyException e) {
      // Capture the stack trace into a String.
      setExceptionString(e.fillInStackTrace());

      // Pass message to the JOptionPane manager.
      setExceptionPane(
          "There is nothing in the buffer to send.\n\n" + "Do you want to see the stack trace?");
    } // End of catch on BufferEmptyException.
  } // End of setMessage() method.
示例#4
0
  // Method to saveFile().
  private void saveFile() {
    // If a file name is returned.
    if (fileName != null) {
      // Try block to throw a custom exception.
      try {
        // Save file.
        FileIO.saveFile(this, fileName, sender.getText());

      } // End of try to get message.
      catch (BufferEmptyException e) // Catch InvalidFileReference.
      {
        // Capture the stack trace into a String.
        setExceptionString(e.fillInStackTrace());

        // Pass message to the JOptionPane manager.
        setExceptionPane(
            "There is nothing in the sender panel to write.\n\n"
                + "Do you want to see the stack trace?");
      } // End of catch on BufferEmptyException.
    } // End of if a fileName is selected.
  } // End of saveFile() method.