Example #1
0
    def __init__(self, editor):
        self.editor = editor
        self.textAttrib = swing.text.SimpleAttributeSet()
        self.keywordAttrib = swing.text.SimpleAttributeSet()
        self.jesEnvironmentWordAttrib = swing.text.SimpleAttributeSet()
        self.errorLineAttrib = swing.text.SimpleAttributeSet()
        self.highlightLineAttrib = swing.text.SimpleAttributeSet()
        self.commentAttrib = swing.text.SimpleAttributeSet()
        self.stringAttrib = swing.text.SimpleAttributeSet()
        self.lParenAttrib = swing.text.SimpleAttributeSet()
        self.rParenAttrib = swing.text.SimpleAttributeSet()
        self.needToSetEnvironment = 1
        self.fontSize = JESConfig.getInstance().getIntegerProperty(
            JESConfig.CONFIG_FONT)

        swing.text.StyleConstants.setForeground(self.stringAttrib,
                                                JESConstants.STRING_COLOR)
        swing.text.StyleConstants.setFontFamily(self.stringAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(self.commentAttrib,
                                                JESConstants.COMMENT_COLOR)
        swing.text.StyleConstants.setFontFamily(self.commentAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(
            self.jesEnvironmentWordAttrib, JESConstants.ENVIRONMENT_WORD_COLOR)
        swing.text.StyleConstants.setBold(self.jesEnvironmentWordAttrib,
                                          KEYWORD_BOLD)
        swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib,
                                              self.fontSize)
        swing.text.StyleConstants.setFontSize(self.textAttrib, self.fontSize)
        swing.text.StyleConstants.setBackground(self.textAttrib,
                                                awt.Color.white)
        swing.text.StyleConstants.setFontFamily(self.jesEnvironmentWordAttrib,
                                                "Monospaced")
        swing.text.StyleConstants.setFontFamily(self.textAttrib, "Monospaced")

        swing.text.StyleConstants.setForeground(self.keywordAttrib,
                                                JESConstants.KEYWORD_COLOR)
        swing.text.StyleConstants.setBold(self.keywordAttrib, KEYWORD_BOLD)
        swing.text.StyleConstants.setFontSize(self.keywordAttrib,
                                              self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.keywordAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(self.lParenAttrib,
                                                JESConstants.LPAREN_COLOR)
        swing.text.StyleConstants.setBold(self.lParenAttrib,
                                          INVALID_PAREN_BOLD)
        swing.text.StyleConstants.setFontSize(self.lParenAttrib, self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.lParenAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(self.rParenAttrib,
                                                JESConstants.RPAREN_COLOR)
        swing.text.StyleConstants.setBold(self.rParenAttrib,
                                          INVALID_PAREN_BOLD)
        swing.text.StyleConstants.setFontSize(self.rParenAttrib, self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.rParenAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(self.errorLineAttrib,
                                                ERROR_LINE_FONT_COLOR)
        swing.text.StyleConstants.setBackground(self.errorLineAttrib,
                                                ERROR_LINE_BACKGROUND_COLOR)
        swing.text.StyleConstants.setFontFamily(self.errorLineAttrib,
                                                "Monospaced")

        swing.text.StyleConstants.setForeground(self.highlightLineAttrib,
                                                HIGHLIGHT_LINE_FONT_COLOR)
        swing.text.StyleConstants.setBackground(
            self.highlightLineAttrib, HIGHLIGHT_LINE_BACKGROUND_COLOR)
        swing.text.StyleConstants.setFontFamily(self.highlightLineAttrib,
                                                "Monospaced")

        #self.undoEvents = []

        #Sets up the UndoManager which handles all undos/redos
        self.undoManager = swing.undo.UndoManager()
        self.undoManager.setLimit(MAX_UNDO_EVENTS_TO_RETAIN)

        HighlightingStyledDocument.setKeywordStyle(self, self.keywordAttrib)
        HighlightingStyledDocument.setEnvironmentWordStyle(
            self, self.jesEnvironmentWordAttrib)
        HighlightingStyledDocument.setStringStyle(self, self.stringAttrib)
        HighlightingStyledDocument.setLParenStyle(self, self.lParenAttrib)
        HighlightingStyledDocument.setRParenStyle(self, self.rParenAttrib)
        HighlightingStyledDocument.setCommentStyle(self, self.commentAttrib)
        HighlightingStyledDocument.setDefaultStyle(self, self.textAttrib)

        #The following variables are set when showErrorLine is called.  They
        #are then used to unhighlight the line when the next text modification
        #is made.
        self.errorLineStart = -1
        self.errorLineLen = -1
        self.highlightLineStart = -1
        self.highlightLineLen = -1
    def __init__(self, editor):
        self.editor = editor
        self.textAttrib = swing.text.SimpleAttributeSet()
        self.keywordAttrib = swing.text.SimpleAttributeSet()
        self.jesEnvironmentWordAttrib = swing.text.SimpleAttributeSet()
        self.errorLineAttrib = swing.text.SimpleAttributeSet()
        self.highlightLineAttrib = swing.text.SimpleAttributeSet()
        self.commentAttrib = swing.text.SimpleAttributeSet()
        self.stringAttrib = swing.text.SimpleAttributeSet()
        self.lParenAttrib = swing.text.SimpleAttributeSet()
        self.rParenAttrib = swing.text.SimpleAttributeSet()
        self.needToSetEnvironment = 1
        self.fontSize = JESConfig.getInstance().getIntegerProperty( JESConfig.CONFIG_FONT )

        swing.text.StyleConstants.setForeground(self.stringAttrib, JESConstants.STRING_COLOR)
        swing.text.StyleConstants.setFontFamily(self.stringAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.commentAttrib, JESConstants.COMMENT_COLOR)
        swing.text.StyleConstants.setFontFamily(self.commentAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.jesEnvironmentWordAttrib, JESConstants.ENVIRONMENT_WORD_COLOR)
        swing.text.StyleConstants.setBold(self.jesEnvironmentWordAttrib, KEYWORD_BOLD)
        swing.text.StyleConstants.setFontSize(self.jesEnvironmentWordAttrib, self.fontSize)
        swing.text.StyleConstants.setFontSize(self.textAttrib, self.fontSize)
        swing.text.StyleConstants.setBackground(self.textAttrib, awt.Color.white)
        swing.text.StyleConstants.setFontFamily(self.jesEnvironmentWordAttrib, "Monospaced");
        swing.text.StyleConstants.setFontFamily(self.textAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.keywordAttrib, JESConstants.KEYWORD_COLOR)
        swing.text.StyleConstants.setBold(self.keywordAttrib, KEYWORD_BOLD)
        swing.text.StyleConstants.setFontSize(self.keywordAttrib, self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.keywordAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.lParenAttrib, JESConstants.LPAREN_COLOR)
        swing.text.StyleConstants.setBold(self.lParenAttrib, INVALID_PAREN_BOLD)
        swing.text.StyleConstants.setFontSize(self.lParenAttrib, self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.lParenAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.rParenAttrib, JESConstants.RPAREN_COLOR)
        swing.text.StyleConstants.setBold(self.rParenAttrib, INVALID_PAREN_BOLD)
        swing.text.StyleConstants.setFontSize(self.rParenAttrib, self.fontSize)
        swing.text.StyleConstants.setFontFamily(self.rParenAttrib, "Monospaced");

        swing.text.StyleConstants.setForeground(self.errorLineAttrib, ERROR_LINE_FONT_COLOR)
        swing.text.StyleConstants.setBackground(self.errorLineAttrib, ERROR_LINE_BACKGROUND_COLOR)
        swing.text.StyleConstants.setFontFamily(self.errorLineAttrib, "Monospaced")

        swing.text.StyleConstants.setForeground(self.highlightLineAttrib, HIGHLIGHT_LINE_FONT_COLOR)
        swing.text.StyleConstants.setBackground(self.highlightLineAttrib, HIGHLIGHT_LINE_BACKGROUND_COLOR)
        swing.text.StyleConstants.setFontFamily(self.highlightLineAttrib, "Monospaced")


        #self.undoEvents = []

        #Sets up the UndoManager which handles all undos/redos
        self.undoManager = swing.undo.UndoManager()
        self.undoManager.setLimit(MAX_UNDO_EVENTS_TO_RETAIN)

        HighlightingStyledDocument.setKeywordStyle(self, self.keywordAttrib)
        HighlightingStyledDocument.setEnvironmentWordStyle(self, self.jesEnvironmentWordAttrib)
        HighlightingStyledDocument.setStringStyle(self, self.stringAttrib)
        HighlightingStyledDocument.setLParenStyle(self, self.lParenAttrib)
        HighlightingStyledDocument.setRParenStyle(self, self.rParenAttrib)
        HighlightingStyledDocument.setCommentStyle(self, self.commentAttrib)
        HighlightingStyledDocument.setDefaultStyle(self, self.textAttrib)


        #The following variables are set when showErrorLine is called.  They
        #are then used to unhighlight the line when the next text modification
        #is made.
        self.errorLineStart = -1
        self.errorLineLen   = -1
        self.highlightLineStart = -1
        self.highlightLineLen = -1