Example #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.
Example #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.
Example #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.