def addSectionReferences(self, parent, editor, sec_references):

        pstring = parent.bodyString()
        rejects = []
        for z in sec_references:
            hs = z.headString().strip()
            spot = pstring.find(hs)
            if spot != -1:
                jp = swing.JPanel(java.awt.BorderLayout())
                jp.setOpaque(0)
                jb = swing.JCheckBox()
                jb.setToolTipText("hide/show")
                jb.setOpaque(0)
                jb.setSelected(1)
                jp.add(jb, java.awt.BorderLayout.NORTH)
                jtp = swing.JTextPane()
                jp.add(jtp)
                jb.actionPerformed = lambda event, jtp=jtp, jp=jp: self.add_remove(
                    jtp, jp)
                jtp.addKeyListener(self.swingmacs.kcb)
                doc = jtp.getDocument()
                jtp.setText(z.bodyString())
                doc.addDocumentListener(
                    self.NodeSyncher(z.copy(), jtp, self.swingmacs, self))
                self.addBorder(jp, z.headString())
                #jtp.setText( z.bodyString() )
                self.scanNode(z, jtp)
                sas = text.SimpleAttributeSet()
                text.StyleConstants.setComponent(sas, jp)
                doc = editor.getDocument()
                doc.setCharacterAttributes(spot, len(hs), sas, 1)
                #self.scanNode( z, jtp )
            else:
                rejects.append(z)
        return rejects
 def colorizeHyperlinks(self):
     '''do to the fact that exited, entered and activated dont execute in the 
        order that is needed we must keep track of what has happened to which element
        and colorize the elements based off of their history'''
     for z in self.entered:
         doc = z.getDocument()
         start = z.getStartOffset()
         end = z.getEndOffset()
         sas = stext.SimpleAttributeSet()
         if z in self.seen_elements:
             stext.StyleConstants.setForeground(sas, java.awt.Color.RED)
         else:
             stext.StyleConstants.setForeground(sas, java.awt.Color.BLUE)
         doc.setCharacterAttributes(start, end - start, sas, 0)
         #doc.setParagraphAttributes( start, end - start, sas , 0 )
     self.entered = []
    def followHyperlink(self, hlEvent):
        aset = element = hlEvent.getSourceElement()
        doc = element.getDocument()
        start = element.getStartOffset()
        end = element.getEndOffset()

        if hlEvent.eventType == ACTIVATED:
            url = hlEvent.URL
            self.seen_elements.append(element)
            self.colorizeHyperlinks()
            self.setPage(url)
        elif hlEvent.eventType == ENTERED:
            self.colorizeHyperlinks()
            self.entered.append(element)
            aset = stext.SimpleAttributeSet()
            stext.StyleConstants.setForeground(aset, java.awt.Color.GREEN)
            doc.setCharacterAttributes(start, end - start, aset, 0)
            #doc.setParagraphAttributes( start, end - start, aset, 0 )
        elif hlEvent.eventType == EXITED:
            self.colorizeHyperlinks()
     def colorizeline2( self, spots ):
                 
 
         dtype = spots[ 2 ]
         begin = spots[ 0 ]
 
         ctokens = self.cdeterminer.getColoredTokens()
         e = stext.Utilities.getParagraphElement( self.editor, begin )
         e2 = stext.Utilities.getParagraphElement( self.editor, spots[ 0 ] + spots[ 1 ] )
         start = e.getStartOffset()
         end = e2.getEndOffset()
         doc = self.editor.getDocument()
         line = doc.getText( start, end - start )
         w_atts = []
         sr1 = "<" + "<"
         sr2 = ">" + ">"
         sec_refs = doc._srs
         comments = self.cdeterminer.getCommentTokens()
         docing = False
         prevtoken = "\n"
         #for z in self.tokenize( line, start ):
         #( String data, int beginspot, String[] commenttokens, Document doc, List<PyTuple> positions )  
 #@+at  
 #         for z in JyLeoTokenizer( line, start, comments, doc, 
 # self.positions ):
 #             #print "'%s'" % z
 #             if docing:
 #                 if z != "@c":
 #                     w_atts.append( ( z, "p" ) )
 #                 else:
 #                     docing = False
 #             if z.startswith( '"' ) or z.startswith( "'" ):
 #                 w_atts.append( (  z , "p" ) )
 #             elif self.iscomment( z, comments ):
 #                 w_atts.append( ( z, "p" ) )
 #             elif z.startswith( sr1 ) and z.endswith( sr2 ):
 #                 guts = z[ 2: -2 ]
 #                 outer = ctokens.get( "<" + "<" )
 #                 if sec_refs.containsKey( guts ):
 #                     scolor = self.cdeterminer.getSectionReferenceColor()
 #                 else:
 #                     scolor = 
 # self.cdeterminer.getUndefinedSectionReferenceColor()
 #                 w_atts.append( ( sr1, outer ) )
 #                 w_atts.append( ( guts, scolor ) )
 #                 w_atts.append( ( sr2, outer ) )
 #             else:
 #                 if z.isspace() or not ctokens.containsKey( z ):
 #                     if z in string.punctuation:
 #                         w_atts.append( ( z, 
 # self.cdeterminer.getPunctuationColor() ) )
 #                     elif z.isspace():
 #                         w_atts.append(( z, "p" ))
 #                     elif z.isnumeric():
 #                         nsas = stext.SimpleAttributeSet()
 #                         stext.StyleConstants.setForeground( nsas, 
 # java.awt.Color.ORANGE )
 #                         w_atts.append( ( z, nsas ) )
 #                     else:
 #                         w_atts.append( ( z, None ) )
 #                 else:
 #                     w_atts.append( ( z, ctokens.get( z ) ) )
 #                     if z == "@" and prevtoken.endswith( "\n" ): docing = 
 # True
 #             prevtoken = z
 #@-at
 #@@c                 
         
         self.super__colorizeline( *spots )
         sas = stext.SimpleAttributeSet()
         stext.StyleConstants.setForeground( sas, java.awt.Color.BLUE )
         self.color( start, w_atts, doc, sas )
         
         #self.positions.sort( self.sortp )
         copyofp = copy.copy( self.positions )
         #print copyofp.__class__
         copyofp.sort( self.sortp )
         scolor = self.cdeterminer.getStringColor()
         scolor2 = self.cdeterminer.getDocColor()
         coloring = None
         colorstart = -1
         #print self.positions
         offsets = []
         comments = self.cdeterminer.getCommentTokens()
         commentcolor = self.cdeterminer.getCommentColor()
         #copyofp = copy.copy( self.positions )
 
         
 
         ignore1 = ignore2 = -1
         #print copyofp
         for z in copyofp:
             try:
                 offset = z[ 0 ].getOffset()
                 if offset > end and not coloring: 
                     #print "RETURNING!!!!!"
                     return
                 item = doc.getText( z[ 0 ].getOffset(), 1 )
                 if item != z[ 1 ]:
                     self.positions.remove( z )
                     if z[ 0 ].getOffset() == spots[ 0 ] and dtype == sevent.DocumentEvent.EventType.REMOVE:
                         start = stext.Utilities.getRowStart( self.editor, spots[ 0 ] )
                         return self.colorizeline( ( start, doc.getLength() - start, None )) 
                     continue
                 if z[ 0 ].getOffset() in offsets:
                     self.positions.remove( z )
                     if dtype == sevent.DocumentEvent.EventType.REMOVE and z[ 0 ].getOffset() == spots[ 0 ]:
                         start = stext.Utilities.getRowStart( self.editor, spots[ 0 ] )
                         return self.colorizeline( ( start, doc.getLength() - start, None )) 
                     continue
                 offsets.append( z[ 0 ].getOffset() )
             except java.lang.Exception, x:
                 self.positions.remove( z )
                 continue
                 
             if not coloring:
                 coloring = z[ 1 ]
                 colorstart = z[ 0 ].getOffset()
                 if colorstart > ignore1 and colorstart < ignore2:
                     #print "IGNORING %s" % coloring
                     coloring = None
                     continue
                 if coloring == '@':
                     end2 = stext.Utilities.getWordEnd( self.editor, colorstart + 1 )
                     start2 = stext.Utilities.getRowStart( self.editor, colorstart )
                     txt = doc.getText( colorstart , end2 - colorstart )
                     if txt.strip() not in ( "@", ) or start2 != colorstart:
                         coloring = None
                         if dtype == sevent.DocumentEvent.EventType.INSERT and colorstart + 1 == spots[ 0 ]:
                             return self.colorizeline( ( colorstart, doc.getLength() - colorstart, None ) )
                 elif coloring and self.ispossiblecomment( coloring, comments ):
                     l1 = len( comments[ 0 ] )
                     txt = doc.getText( colorstart, l1 )
                     if txt == comments[ 0 ]:
                         e = stext.Utilities.getParagraphElement( self.editor, colorstart )
                         end2 = e.getEndOffset()
                         doc.setCharacterAttributes( colorstart, end2 - colorstart, commentcolor, 1 )
                         ignore1 = colorstart;ignore2 = end2
                         coloring = None
                     elif txt == comments[ 1 ]:
                         pass
                     else:
                         coloring = None
                 continue
             if coloring in ( "'", '"' ):
                 if z[ 1 ] == coloring:
                     eoffset = z[ 0 ].getOffset()
                     emarker = stext.Utilities.getRowEnd( self.editor, eoffset )
                     cs = doc.getCharacterElement( colorstart )
                     ce = doc.getCharacterElement( eoffset )
                     if cs.getAttributes().isEqual( scolor )\
                     and ce.getAttributes().isEqual( scolor )\
                     and ( begin < colorstart or begin > emarker ):
                         pass
                     else:
                         doc.setCharacterAttributes( colorstart, eoffset + 1  - colorstart, scolor, 1 )
                     coloring = None
                     if dtype == sevent.DocumentEvent.EventType.INSERT and eoffset == spots[ 0 ]:
                         return self.colorizeline( ( colorstart, doc.getLength() - colorstart, None ) )
             elif coloring in( "@", ):
                 try:
                     offset = z[ 0 ].getOffset()
                     end2 = stext.Utilities.getWordEnd( self.editor, offset + 1 )
                     start2 = stext.Utilities.getRowStart( self.editor, offset )
                     if start2 == offset:
                         txt = doc.getText( start2 , end2 - start2 )
                         if txt.strip() in ("@c", ):
                             cs = doc.getCharacterElement( colorstart + 1 )
                             ce = doc.getCharacterElement( offset )
                             if cs.getAttributes().isEqual( scolor2 )\
                             and ce.getAttributes().isEqual( scolor2 )\
                             and ( begin < colorstart or begin > end2 ):
                                 pass
                             else:
                                 doc.setCharacterAttributes( colorstart + 1, offset - colorstart -1, scolor2, 1 )
                             coloring = None
                             if dtype == sevent.DocumentEvent.EventType.INSERT and start2 + 1 == spots[ 0 ]:
                                 return self.colorizeline( ( start2, doc.getLength() - start2, None ) )
                 except java.lang.Exception, x:
                     pass 
    def addOthers(self, parent, editor, others):

        if others:
            bs = parent.bodyString()
            spot = bs.find("@" + "others")
            whitespace = 0
            if spot == -1 and bs.strip() == "":
                spot = 0
                #if len( bs ) == 0:
                #    bs = " "
                #    #editor.setText( bs )
                whitespace = 1

            if spot != -1:
                opanel = swing.JPanel(java.awt.BorderLayout())
                jp = swing.Box.createVerticalBox()
                jp.setOpaque(0)
                opanel.setOpaque(0)
                jcb = swing.JCheckBox("@others")
                jcb.setToolTipText("hide/show")
                jcb.setOpaque(0)
                jcb.setSelected(1)
                opanel.add(jcb, java.awt.BorderLayout.NORTH)
                opanel.add(jp)
                jcb.actionPerformed = lambda event, jp=jp, opanel=opanel: self.add_remove(
                    jp, opanel)
                sas = text.SimpleAttributeSet()
                text.StyleConstants.setComponent(sas, opanel)
                #doc = editor.getDocument()
                #if not whitespace:
                #    doc.setCharacterAttributes( spot, 7, sas, 1 )
                #else:
                #    doc.setCharacterAttributes( spot, 1, sas , 1 )
                for z in others:
                    jp2 = swing.JPanel(java.awt.BorderLayout())
                    jp2.setOpaque(0)
                    jb = swing.JCheckBox()
                    jb.setToolTipText("hide/show")
                    jb.setOpaque(0)
                    jb.setSelected(1)
                    jp2.add(jb, java.awt.BorderLayout.NORTH)
                    tp = swing.JTextPane()
                    jb.actionPerformed = lambda event, tp=tp, jp2=jp2: self.add_remove(
                        tp, jp2)
                    jp2.add(tp)
                    tp.addKeyListener(self.swingmacs.kcb)
                    bs = z.bodyString()
                    if bs == "":
                        bs = " "
                        p.v.t._bodyString.insert(0, bs)
                    tp.setText(bs)
                    doc = tp.getDocument()
                    doc.addDocumentListener(
                        self.NodeSyncher(z.copy(), tp, self.swingmacs, self))
                    self.addBorder(jp2, z.headString())
                    bs = z.bodyString()
                    jp.add(jp2)
                    self.scanNode(z, tp)

                doc = editor.getDocument()
                if not whitespace:
                    doc.setCharacterAttributes(spot, 7, sas, 1)
                else:
                    doc.setCharacterAttributes(spot, 1, sas, 1)