Class Editor

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, EditorInterface

    public class Editor
    extends JPanel
    implements EditorInterface
    L'idee de cette editor, est qu'il ne fait rien lui meme, mais delegue a un autre editeur enregistré. L'enregistrement ce fait par le nom de la classe sous forme de String, ce qui permet d'enregistrer des editeurs qui ne peuvent pas etre chargé car il manque des jars. Par exemple NetBeansEditor qui demande beaucoup de jar, peu ne pas etre chargé convenablement, dans ce cas un autre editeur sera choisi.

    L'ordre d'enregistrement est important. Le premier editor enregistré sera le premier editeur essayé.

    Si l'on souhaite creer un nouvel editeur, il faut implanter EditorInterface et etendre au moins Component

    Si aucun editeur n'est trouvé alors DefaultEditor est utilisé

    Editeur permet d'utiliser Ctrl-s pour sauver le fichier courant quel que soit l'editeur.

    Author:
    poussin
    See Also:
    Serialized Form
    • Field Detail

      • currentEditor

        protected EditorInterface currentEditor
        currentEditor is currently opened editor in this editor
      • openedFile

        protected File openedFile
        current opened file
      • documentListeners

        protected Set<DocumentListener> documentListeners
        All document listener registered on this editor
      • caretListeners

        protected Set<CaretListener> caretListeners
        All caret listener registered on this editor
      • askIfNotSaved

        protected boolean askIfNotSaved
        If the edited file is modifier, before switch to other or close it, ask the user if he want save the modification
      • forceDefault

        protected boolean forceDefault
        force usage of default editor
    • Constructor Detail

      • Editor

        public Editor()
    • Method Detail

      • addKeyBinding

        protected void addKeyBinding()
      • setSyntax

        public void setSyntax​(Editor.EditorSyntaxConstant editorSyntax)
        Force to use syntaxe without file, try to find the better editor for this syntax Work only for regis
        Specified by:
        setSyntax in interface EditorInterface
        Parameters:
        editorSyntax - to use
      • isAskIfNotSaved

        public boolean isAskIfNotSaved()
        Returns:
        the askIfNotSaved
      • setAskIfNotSaved

        public void setAskIfNotSaved​(boolean askIfNotSaved)
        Parameters:
        askIfNotSaved - the askIfNotSaved to set
      • isForceDefault

        public boolean isForceDefault()
        Returns:
        the forceDefault
      • setForceDefault

        public void setForceDefault​(boolean forceDefault)
        Parameters:
        forceDefault - the forceDefault to set
      • getEditor

        public EditorInterface getEditor​(Editor.EditorSyntaxConstant editorSyntaxConstant)
        try to find better editor for this file
        Parameters:
        editorSyntaxConstant - type of syntaxe
        Returns:
        the better editor, or Default Editor
      • getEditor

        public EditorInterface getEditor​(File file)
        try to find better editor for this file
        Parameters:
        file - concerned
        Returns:
        the better editor, or Default Editor
      • setCurrentEditor

        public void setCurrentEditor​(EditorInterface editor)
      • getCurrentEditor

        public EditorInterface getCurrentEditor()
        Returns:
        the currentEditor
      • getOpenedFile

        public File getOpenedFile()
        Returns:
        the openedFile
      • setOpenedFile

        public void setOpenedFile​(File openedFile)
        Parameters:
        openedFile - the openedFile to set
      • close

        public boolean close()
        Closs current file
        Returns:
        the current editor
      • askAndSaveOrCancel

        protected boolean askAndSaveOrCancel()
        ask the user to save the current opened file if necessary (current file is modified)
        Returns:
        false if user awnser Cancel, true otherwize.
      • save

        public boolean save()
        Save current opened file
        Returns:
        true if all is ok
      • accept

        public boolean accept​(File file)
        if return true, this editor support this file type. Default implantation return true
        Specified by:
        accept in interface EditorInterface
        Parameters:
        file - to check
        Returns:
        if return true, this editor support this file type.
      • accept

        public boolean accept​(Editor.EditorSyntaxConstant editorSyntaxConstant)
        if return true, this editor support this syntax type. Default implantation return true
        Specified by:
        accept in interface EditorInterface
        Parameters:
        editorSyntaxConstant - to check
        Returns:
        if return true, this editor support this syntax type.
      • isModified

        public boolean isModified()
        indicate if current opened file has been modified
        Specified by:
        isModified in interface EditorInterface
        Returns:
        true if currend file is modified
      • open

        public boolean open​(File file)
        Replace the current edited file by file passed in argument. When you overide this method, you must call setOpenedFile(File)
        Specified by:
        open in interface EditorInterface
        Parameters:
        file - the file to open
        Returns:
        true if file has been opened
      • saveAs

        public boolean saveAs​(File file)
        Replace the current edited file by file passed in argument
        Specified by:
        saveAs in interface EditorInterface
        Parameters:
        file - the file to open
        Returns:
        true if file has been saved and reopen with new name
      • setText

        public void setText​(String text)
        Description copied from interface: EditorInterface
        Set all text with text in argument.
        Specified by:
        setText in interface EditorInterface
        Parameters:
        text - test to set
      • copy

        public void copy()
        Description copied from interface: EditorInterface
        Copy current current selection into system clipboard.
        Specified by:
        copy in interface EditorInterface
      • cut

        public void cut()
        Description copied from interface: EditorInterface
        Cut current editor selection into system clipboard.
        Specified by:
        cut in interface EditorInterface
      • paste

        public void paste()
        Description copied from interface: EditorInterface
        Paste current clicboard content into editor at caret position.
        Specified by:
        paste in interface EditorInterface