Home
Categories
Dictionary
Download
Project Details
Changes Log
License

EditorStateListener


It is possible for an application which uses the JEditor to listen to the modifications of the underlying document by JEditor.addEditorStateListener(EditorStateListener): The state of modification can be modified by edits, but also copy / paste or undo / redo actions.

Note that the JEditor.setUnchanged() method allow to force that the underlying document is unchanged. i It can be useful if you allow to save the content in a file, and you want to specify that the document is in an unchanged state after saving.

Supporting the CTRL+S key

The JEditor itself will do nothing upon typing CTRL+S, it is the responsability of the client application to process the save (or do nothing if it does not want to handle CTRL+S typing. You can do that by llistening to the EditorStateListener.STATE_SAVED event state. For example:
   JEditor editor = new JEditor();
   editor.setText(<the text>);
   editor.addEditorStateListener(new EditorStateListener() {
      public void documentStateChanged(short state) {
        if (state == EditorStateListener.STATE_SAVED) {
          try {
            editor.saveAs(file);
          } catch (IOException ex) {
          }
        }
      }
   });

See also


Categories: Component

Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence