コード例 #1
0
 /** Loads the target file into the components text area, using the indicated character set. */
 protected void loadFile() {
   // do not reload if file has changed
   if (saveAction.isEnabled()) return;
   File file = getTargetFile().getFile();
   Reader reader = null;
   Cursor originalcursor = this.getOwner().getCursor();
   this.getOwner().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   try {
     reader = new InputStreamReader(new FileInputStream(file), getCharset());
     textArea.read(reader, file);
     textArea.setCaretPosition(0);
     wireupSaveButton();
     lineCounter.setLineCount(1);
     undoManager = new UndoHistory();
     undoManager.registerUndoHistory(textArea);
   } catch (IOException iox) {
     logger.error("IOException displaying file " + file.getPath() + ": " + iox.getMessage());
     textArea.setText("");
     textArea.setForeground(Color.RED);
     textArea.setText(iox.getMessage());
   } catch (OutOfMemoryError omu) {
     logger.error(omu.getClass().getName() + ": " + omu.getMessage(), omu);
     textArea.setText("");
     textArea.setForeground(Color.RED);
     String message = getLocalizer().localize("message.document-too-large-for-display");
     textArea.setText(message + "\n(OutOfMemoryError: " + omu.getMessage() + ")");
   } catch (Exception x) {
     String message = x.getClass().getName() + ": " + x.getMessage();
     logger.error(message, x);
     textArea.setText("");
     textArea.setForeground(Color.RED);
     textArea.setText(message);
   } finally {
     this.getOwner().setCursor(originalcursor);
     if (reader != null)
       try {
         reader.close();
       } catch (IOException iox) {
         logger.warn("IOException closing stream: " + iox.getMessage());
       }
   }
 }