XML Syntax Highlighting

Hi, I need help with XML Syntax Highlighting. I try to create simple XML editor, but I have probleblems with Syntax Highlighting.
Is there anyone who can help me?

Here is personal recommendation, this 3rd party syntax highlight component works quite well for many JTextComponents
Check out: http://ostermiller.org/syntax/
ICE

Similar Messages

  • XML Syntax highlighting (again :)

    Hi there,
    I know, that there have been quite a view posts about this topics, but as far as I see, there has been no solution to this.
    So I wanted to ask if someone has implemented a XML Syntax highlighting or knows where to get a tutorial from to accomplish so (inheriting from DefaultStyledDocument...?)
    Sincerely
    Charly

    Hi!
    I have the same need: an XML Syntax Highlighting (coloring).
    I don't need an XML editor, I have a JTextPane that shows XML code and I would like it to be done with a syntax coloring.
    If you have a solution I will really appreciate!
    Thanks
    Gio :-)

  • Help required in syntax highlighting in xml using tool Syntax

    hi
    i am using Syntax tool for syntax highlighting of xml in JTextpane. I use complex html style and i want to change the colors of the displayed xml in the tool under complex html like the internet explorer displays in case of xml i want to make my xml like that..

    Hi,
    use it like this if Fname equals constnat[space] then pass the Constant[space] to Fname else value of Fname as under
    ................................Constant[]------>
    FNAME.............................................Then
    >Equals....................................IF -
    >FNAME
    Constant[].........................................ELSE
    .......................................FNAME---->   
    Constant[]    = Constant [ Space ]
    Sachin

  • XML Schema Syntax highlighting - quicker way than this?

    I have implemented a syntax highlighter for my XML Schema Editor, however it runs quite slowly. Is there a faster way than the method used below:
              while(line.length() > len)
                   if(line.charAt(len) == '<' )
                        append(Color.black, line.charAt(len));
                        len++;
                        if( line.charAt(len) == '/')
                             append(Color.black, line.charAt(len));
                             len++;
                        else if( line.charAt(len) == '!' && line.charAt(len+1) == '-' && line.charAt(len+2) =='-')
                             append(Color.black, line.charAt(len));
                             len++;
                             append(Color.black, line.charAt(len));
                             len++;
                             append(Color.black, line.charAt(len));
                             len++;
                             while(line.charAt(len)!='-')
                                  append(CommentColour, line.charAt(len));
                                  len++;
                             if(line.charAt(len) == '-' && line.charAt(len+1) == '-')
                                  append(Color.black, line.charAt(len));
                                  len++;
                                  append(Color.black, line.charAt(len));
                                  len++;
                        while(line.charAt(len) != '>')
                             if(line.charAt(len) == '"' || line.charAt(len) == '\'')
                                  append(AttributeColour, line.charAt(len));
                                  len++;
                                  while(line.charAt(len) != '"' && line.charAt(len) != '\'')
                                       append(AttributeColour, line.charAt(len));
                                       len++;
                                  append(AttributeColour, line.charAt(len));
                                  len++;
                             if(line.charAt(len) == '/')
                                  append(Color.black, line.charAt(len));
                                  len++;
                             else if(line.charAt(len) == '<')
                                  append(Color.black, line.charAt(len));
                                  len++;
                                            if( line.charAt(len) == '!' && line.charAt(len+1) == '-' && line.charAt(len+2) =='-')
                                                 append(Color.black, line.charAt(len));
                                                 len++;
                                                 append(Color.black, line.charAt(len));
                                                 len++;
                                                 append(Color.black, line.charAt(len));
                                                 len++;
                                                 while(line.charAt(len)!='-')
                                                      append(CommentColour, line.charAt(len));
                                                      len++;
                                                 if(line.charAt(len) == '-' && line.charAt(len+1) == '-')
                                                      append(Color.black, line.charAt(len));
                                                      len++;
                                                      append(Color.black, line.charAt(len));
                                                      len++;
                             else if(line.charAt(len) == '>')
                                  append(Color.black, line.charAt(len));
                                  len++;
                                  while(line.charAt(len)!='<')
                                       append(ElementDetailsColour, line.charAt(len));
                                       len++;
                             else
                                  append(ElementNameColour, line.charAt(len));
                                  len++;
                        if(line.charAt(len) == '>')
                             append(Color.black, line.charAt(len));
                             len++;
                   else
                        append(ElementDetailsColour, line.charAt(len));
                        len++;
              append(Color.black, "\n");
    }line = The string of XML Schema data
    len = the character position within the string.
    Currently it looks at each character and sees if it is one of the defining characters eg '<' and then colours the following text the chosen colour, until it reaches another defining chracter eg '>'
    Is there a faster way? Could I use hashmaps somehow?
    Thanks
    Alex

    1. You may use somewhat cumbersome syntax like:
    choice
    A
    B
    all
    A
    B
    /all
    /choice
    to implement inclusive or.
    2. They (W3 Schema WG) were talking about
    this but decided not to allow it (at least for now). A workaround you may use:
    all
    group ref = group1
    group ref = group2
    /all
    group name=group1
    elem ... maxOccurs = 10
    /group
    Something like that.
    null

  • How to enable syntax highlighting for jspf files on Dreamweaver CS5.5 on Mac

    I ran into an issue where I couldn't get the color coding (color coding style) for java server pages fragments (.jspf) files to show syntax highliting.
    I followed the adobe instructions on Changing and adding file extensions recognized by Dreamweaver without any luck.
    Here is the solution that worked for me:
    On a Mac:
    1. Edit the /Users/YOUR USER/Library/Application Support/Adobe/Dreamweaver CS5.5/en_US/Configuration/DocumentTypes/MMDocumetTypes.xml
    Note: the Adobe instructions tell you to edit /Applications/Adobe Dreamweaver CS5.5/Configuration/DocumentTypes/MMDocumetTypes.xml (Editing this file didn't do anything for me, so you need to change the file above instead)
    Find,
    <documenttype id="JSP" servermodel="JSP" internaltype="Dynamic" winfileextension="jsp,jst" macfileextension="jsp,jst" file="Default.jsp" writebyteordermark="false" mimetype="text/html">
    Replace with,
    <documenttype id="JSP" servermodel="JSP" internaltype="Dynamic" winfileextension="jsp,jst,jspf" macfileextension="jsp,jst,jspf" file="Default.jsp" writebyteordermark="false" mimetype="text/html">
    2. Edit the /Users/YOUR USER/Library/Application Support/Adobe/Dreamweaver CS5.5/en_US/Configuration/Extensions.txt
    In the All: section on top add the jspf extention right after jsp in my example it looked like this
    HTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,JSON,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF, LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,PHP-D IST,PHTML,JSP,WML,TPL,LASSO,JSF,VB,VBS,VTM,VTML,INC,SQL,JAVA,EDML,MASTER,INFO,INSTALL,THEME,CONFIG,MODU LE,PROFILE,ENGINE,SVG:All
    and I added the jspf and it looks like this now,
    HTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,JSON,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF, LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,PHP-D IST,PHTML,JSP,JSPF,WML,TPL,LASSO,JSF,VB,VBS,VTM,VTML,INC,SQL,JAVA,EDML,MASTER,INFO,INSTALL,THEME,CONFIG,MODU LE,PROFILE,ENGINE,SVG:All
    That's it, Quit Dreamweaver and open it up again. Open the .jspf file and see the color coding (syntax highlighting)
    Hope this helps you and seves you time figuring it out. If this helped, do a good thing, next time you figure something out, tell others about it to save their time too, like I did. Enjoy.

    TheGrandNabib wrote:
    I don't seem to have a user Library folder, my only Library folder is on the same level as my Users folder.
    From Locating your personal configuration folder in the Dreamweaver FAQ:
    In Mac OS X (Lion and Mountain Lion), open Finder and press Shift-Cmd-Go. Type ~/Library/Application Support in the dialog box, and click Go. You should then be able to find the configuration folder.

  • How do I enable syntax highlighting for jspf files on Dreamweaver CS6 on Windows?

    I followed the instructions (which I modified for CS6) in this posting: http://blog.metameister.com/blog/2011/04/08/open-new-file-types-and-add-syntax-highlightin g-in-dreamweaver-cs5-on-window…
    but it did not work for CS6.
    How do I enable syntax highlighting for jspf files on Dreamweaver CS6 on Windows 7?
    cheers
    Marvin in Edmonton

    Ok, I figured it out after hunting for a few hours.
    Step 1. Add the File Type
    In Dreamweaver’s toolbar:
    Select Edit > Preferences; 
    under File Types / Editors, add .jspf to the line “Open in Code View:”.
    Step 2. Extensions.txt
    Add file type .jspf to the Extensions.txt files. There are two of these files:
    C:\Users\[username]\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration
    C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration
    Step 3. MMDocumentTypes.xml
    Add jspf to the MMDocumentTypes.xml files. Open this file in Notepad or Text Editor. Do not modify the Dreamweaver configuration files within Dreamweaver.
    There are three MMDocumentTypes.xml files to be modified: 
    C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration\DocumentTypes
    C:\Users\mhaagsma\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration
    C:\Users\mhaagsma\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration\DocumentTypes\
    Step 4. Restart Dreamweaver
    Hopefully the file type will now be recognized and appear with syntax highlighting.

  • DW CS4 Custom Tags & Syntax Highlighting?

    Hi,
    I already created a custom tag in the \Adobe Dreamweaver CS4\configuration\ThirdPartyTags\Tags.xml like this:
    <tagspec tag_name="mytag" tag_type="nonempty" render_contents="true" content_model="marker_model" start_string="(~" end_string="~)" detect_in_attribute="true" parse_attributes="false" icon="mytag.gif" icon_width="16" icon_height="15"></tagspec>
    I read the instructions on 3rd party syntax highlighting here (Dreamweaver Help).
    Whether I misunderstand something or it's not working.
    1) The help speaks of "View > Invisible Elements". In DW CS4 is no menu entry like this - if you mean the menu. However I think this entry is ment: "View > Visueal Aids > Invisible Elements". It's enabled by default.
    2) Under "Edit > Preferences > Highlighting" I activated the Third Party tags color.
    I restarted Dreamweaver to be sure...but no code/tag is highlighted!
    Example HTML: (.html file)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
         <title>Test</title>
    </head>
    <body>
    <input name="(~ TEST ~)" type="text" class=(~ test2 ~) />
    (~Something here ~) This is the first text.
    (~ Partly Input  <input name="dynamic"|VAR ~)
    </body>
    </html>
    From my understanding, everything between the (~ ~) tags/delimiter (including them) should be colored in the 3rd party tag color or not? Also the  open INPUT tag with the name "dynamic" confuses the normal HTML syntax highlighting of DW.  I thought everything between my custom tags is kind of separated from the rest of the code? (the validator doesn't care either what's inside the custom tags).
    Any ideas?
    Cheers!

    I thought everything between my custom tags is kind of separated from the rest of the code? (the validator doesn't care either what's inside the custom tags).
    But it still goes looking for its own tags, which in your case simply isn't closed, hence the confusion.
    I restarted Dreamweaver to be sure...but no code/tag is highlighted!
    Are you sure the checkbox is ticked?
    Mylenium

  • Nano syntax highlighting: catch-all syntax for configuration files

    After years of using nano, I only recently learned that it supports syntax coloring... (Why would they turn that off by default? ) Well, I thought I'll make up for it by making extra good use of it from now on...
    Unfortunately it didn't ship a highlighting syntax for the the kind of files that I use nano the most for: system configuration files.
    So I wrote my own, and after tweaking a bit here and there whenever I encountered a config file for which the highlighting wasn't satisfactory at first, I think the result is now good enough (screenshots below) that it's worth sharing with my fellow Arch users:
    Code & Instructions:
    Here is the syntax definition:
    # config file highlighting
    syntax "conf" "(\.(conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/)"
    # default text
    color magenta "^.*$"
    # special values
    icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"
    # keys
    icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"
    # commands
    color blue "^\s*set\s+\<"
    # punctuation
    color blue "[.]"
    # numbers
    color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"
    # keys
    icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="
    # punctuation
    color blue "/"
    color brightwhite "(\]|[()<>[{},;:=])"
    color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"
    # section headings
    icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
    color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
    color brightcyan "^\s*\$(end)?if(\s|$)"
    # URLs
    icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"
    # XML-like tags
    icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"
    # strings
    color yellow "\"(\\.|[^"])*\"" "'(\\.|[^'])*'"
    # comments
    color white "#.*$"
    color blue "^\s*##.*$"
    color white "^;.*$"
    color white start="<!--" end="-->"
    To install, save the above above code snippet as a file called conf.nanorc in the folder /usr/share/nano/ (or /usr/local/share/nano/ or similar if you feel strongly about the /usr <--> /usr/local separation), and then add the following to the end of the file /etc/nanorc:
    ## Configuration files (catch-all syntax)
    include "/usr/share/nano/conf.nanorc"
    Hints:
    The colors I chose look good (imo) with the terminal background and color settings that I use, but might not look good, or even readable, with yours, so simply change the color names in the code snippet to whatever you prefer - valid color names are:
    If you use a console with white background, you'll have to change at least the white color I chose for comments and punctuation.
    The first code line in the snippet includes a regular expression that defines for which file names this syntax highlighting should be used. Whenever you encounter a config file that is not matched by this, but you would still like to open it with syntax highlighting, you can manually select this syntax with nano's -Y switch, like so:
    nano -Y conf myConfigFile
    Technical Note:
    It's implemented as a single catch-all syntax, since nano chooses which syntax to apply based on the filename, and in the case of config files usually not much can be learned about the content format from the file name extension (.conf can by anything from flat key/value tuples to XML, .ini can be the official INI format or something else, etc...).
    This means that some compromises have been made, so with this highlighting syntax probably no config file looks 100% as good as a highlighting syntax that would be specifically optimized for one kind of config format, but all in all the vast majority of config files should look pretty good.
    Screenshots:
    /etc/rc.conf,  /etc/hosts:
    /etc/pacman.conf,  /etc/group:
    xorg.conf,  some .desktop file:
    httpd.conf (Apache config),  php.ini:
    More screenshots:
    /etc/fonts/fonts.conf (uses XML)
    /etc/inittab
    /etc/fstab
    /etc/inputrc
    /etc/mime.types
    /etc/protocols
    /etc/xinetd.conf
    See Also:
    nano syntax highlighting: GNU makefiles
    Update [2012-01-28]: Made some more improvements to the syntax definition (see post)
    Last edited by sas (2012-02-01 15:26:43)

    doug piston wrote:I deal with alot of .mk files and would love to see it there.
    You mean GNU makefiles?
    I'm afraid they might be out of scope for this generic config-file syntax.
    Logically they're not system config files, and technically they're a pretty specialized and complex format (different "types" of rules, rules spanning multiple lines, rules containing arbitrary Bash code, etc.).
    This is how an .mk file currently looks with this highlighting syntax:
    $ nano -Y conf /usr/lib/httpd/build/rules.mk
    And apart from highlighting variables of the form $$abc or $(abc), I'm not sure how much can be improved here without breaking the highlighting for more conventional config files.
    It would probably be better to create a specialized highlighting syntax just for .mk files.
    EDIT: I sat down and did just that, here's the result: nano syntax highlighting: GNU makefiles, and here is how the above makefile snipped looks with it:
    Last edited by sas (2012-02-01 15:18:52)

  • Syntax highlighting not working with label on if statement in fortran in Visual studio 2010

    I am having a difficult time in figuring out the syntax highlighting in Visual studio. I am using fortran code and there are labels in if statements as follows: 
                if_2003: IF (FRAC_PBED(NNSED,L).LT.0.0.AND.
         +                   FRAC_PBED(NNSED,L).GT.SMALL_NEG_NO) THEN
                  FRAC_PBED(NNSED,L) = 0.0
           TSED_PBED(1,NNSED,L) = 0.0
         END IF if_2003
    So the problem I am having is when I click on the `if` next to label `if_2003`, then I cannot use `CTRL + ]` to move to the ending `if`. If there is no label before `if`, then the shortcut is working fine. I don't know what I could do so that it would start
    behaving as it is supposed to. 
    In the contrary, when I have do loop as follows: 
        do_410: DO NNSED=1,NSTD
             D50AVG(L) = D50AVG(L) + 
             +                 FRAC_ALAY_SURF(NNSED,L)*D50(NNSED)/10000.  ! BASED ON BED COMPOSITION
        C
             TSED_ALAY_SURF(2,NNSED,L)=TSED_ALAY_SURF(1,NNSED,L)
             TSED_ALAY_BUFF(2,NNSED,L)=TSED_ALAY_BUFF(1,NNSED,L)
             TSED_PBED(2,NNSED,L)=TSED_PBED(1,NNSED,L)
                  END DO do_410
    I can move to the end/start of `do` loop using the keyboard shortcut `CTRL + ]`. Any suggestions is appreciated.  
    Regards, Jdbaba

    Hello Jdbaba,
    Based on my research, your post is related to use fortran in Visual Studio:https://software.intel.com/en-us/articles/intel-math-kernel-library-intel-mkl-for-windows-build-intel-mkl-program-with-intel-fortran-in-microsoft-visual-studio This
    technology is provided by Intel. So the question should be consulted on Intel fortran related forum. Not Visual Studio Setup forum, setup forum is about install/uninstall Visual Studio.
    Best regards,  
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • XML syntax error in a JSP page.

    Hi,
    i was trying to include xml syntax in a jsp page in stead of core jsp syntax. it didn't work.But the jsp document with the core jsp syntax works. I'm wondering what's the problem.any help would be really helpful. I'm using Tomcat 3.2.1.
    Thanx in adv,
    Ganesh
    JSP file - NOT WORKING
    <jsp:directive.page import="java.util.Date"/>
    <jsp:declaration>
    private static String loadTime = new Date().toString();
    private static String getLoadTime() { return loadTime; }
    private static String getCurrentTime() { return new Date().toString(); }
    </jsp:declaration>
    <HTML>
    <HEAD><TITLE>XML and JSP</TITLE></HEAD>
    <BODY>
    JSP page is created using XML syntax...<BR>
    This page was loaded into memory at <%= getLoadTime() %>.<BR>
    The current time is <%= getCurrentTime() %>
    </BODY>
    </HTML>
    ERROR :
    Error: 500
    Location: /test/declarations.jsp
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat321\tomcat\work\localhost_8080%2Ftest\_0002fdeclarations_0002ejspdeclarations_jsp_6.java:59: Method getLoadTime() not found in class _0002fdeclarations_0002ejspdeclarations_jsp_6.
    out.print( getLoadTime() );
    ^
    C:\tomcat321\tomcat\work\localhost_8080%2Ftest\_0002fdeclarations_0002ejspdeclarations_jsp_6.java:65: Method getCurrentTime() not found in class _0002fdeclarations_0002ejspdeclarations_jsp_6.
    out.print( getCurrentTime() );
    ^
    2 errors

    Hi,
    any help on this question would be really appreciated..
    Thanx in adv,
    Ganesh

  • Different Styles in PlainView - Syntax Highlighting?

    Hi,
    I've managed to extend PlainView and looking at old JEdit code I have the syntax highlighting working for the most part. However, at certain times while typing the cursor starts to get way ahead of the text it's typing. And as I backspace on the line the cursor eventually gets closer to the character the closer it gets to the start of the line.
    I'm overridding the "drawUnselectedText()" method in PlainView to do the coloring.
    Here's the code, you can see the call to SyntaxUtilities.paintSyntaxLine() which is JEdit's class to do the drawing.
             * Renders the given range in the model as normal unselected text. This
             * is implemented to paint colors based upon the token-to-color
             * translations. To reduce the number of calls to the Graphics object,
             * text is batched up until a color change is detected or the entire
             * requested range has been reached.
             * @param g
             *            the graphics context
             * @param x
             *            the starting X coordinate
             * @param y
             *            the starting Y coordinate
             * @param p0
             *            the beginning position in the model
             * @param p1
             *            the ending position in the model
             * @returns the location of the end of the range
             * @exception BadLocationException
             *                if the range is invalid
            protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
                System.out.println("p0: " + p0 + " p1: " + p1 + " x: " + x + " y: " + y);
                // Get the start of the element
                int lineIndex = doc.getDefaultRootElement().getElementIndex(p0);
                // Get the element for the line
                Element elem = doc.getDefaultRootElement().getElement(lineIndex);
                System.out.println("lineIndex: " + lineIndex + " elemStartIDX: " + elem.getStartOffset() + " elemEndIDX: " + elem.getEndOffset());
                // Get the line text
                doc.getText(p0, p1 - p0, currentLineText);
                // If highlighting, mark the tokens
                if (marker != null) {
                    Token t = marker.markTokens(currentLineText, lineIndex);
                    x = SyntaxUtilities.paintSyntaxLine(currentLineText, t, styles, this, g, x, y, p0, p1);
                    System.out.println("Painted line at: " + x);
                } else {
                    // No highlighting requested, draw normal text
                    Font defaultFont = g.getFont();
                    Color defaultColor = styles[0].getColor(); // Default color of text
                    g.setFont(defaultFont);
                    g.setColor(defaultColor);
                    x = Utilities.drawTabbedText(currentLineText, x, y, g, this, p0);
                // Set the last line processed
                lastLine  = lineIndex;
                return x;
    Here is the code from the paintSyntaxLine() method:
         * Paints the specified line onto the graphics context. Note that this
         * method munges the offset and count values of the segment.
         * @param line
         *            The line segment
         * @param tokens
         *            The token list for the line
         * @param styles
         *            The syntax style list
         * @param expander
         *            The tab expander used to determine tab stops. May be null
         * @param gfx
         *            The graphics context
         * @param x
         *            The x co-ordinate
         * @param y
         *            The y co-ordinate
         * @return The x co-ordinate, plus the width of the painted string
        public static int paintSyntaxLine(Segment line, Token tokens, SyntaxStyle[] styles, TabExpander expander, Graphics gfx, int x, int y, int p0, int p1) {
            Font defaultFont = gfx.getFont();
            Color defaultColor = Color.black;
            FontMetrics fm = gfx.getFontMetrics(defaultFont);
            int offset = 0;
            while (tokens != null && tokens.id != Token.END) {
                int length = tokens.length;
                if (tokens.id == Token.NULL) {
                    if (!defaultColor.equals(gfx.getColor()))
                        gfx.setColor(defaultColor);
                    if (!defaultFont.equals(gfx.getFont()))
                        gfx.setFont(defaultFont);
                } else {
                    styles[tokens.id].setGraphicsFlags(gfx, defaultFont);
    //                fm = gfx.getFontMetrics();//[tokens.id].getStyledFont(defaultFont);
    //                FontMetrics dfm = Toolkit.getDefaultToolkit().getFontMetrics(defaultFont);
    //                System.out.println("Font Info: CharWidth[" + fm.charWidth(line.array[p1])+"], Max Advance[" + fm.getMaxAdvance()+"]");
    //                System.out.println("Default Font Info: CharWidth[" + dfm.charWidth(line.array[p1])+"], DMax Advance[" + dfm.getMaxAdvance()+"]");
    ////                x = fm.charsWidth(line.array, p0, length);
                line.count = length;
                x = Utilities.drawTabbedText(line, x, y, gfx, expander, p0);
                line.offset += length;
                offset += length;
                tokens = tokens.next;
            return x;
    I'm not sure what the problem is..i thought it might be an issue with the View and drawing multiple font styles. Since plain view only deals with a single font color and size. I tried using LabelView but that seems to need a StyledDocument and I had problems when I tried to use DefaultStyledDocument for my syntaxdocument. I was getting strange offset issues when using the Segment class.
    Here's what I posted: http://forum.java.sun.com/thread.jspa?threadID=780801
    I am using PlainDocument because that seemed to be what everyone was using for a syntax editor..since the structure of the document in a Plain Document is less complex.
    I orginally started out using the setCharacterAttributes() method on the DefaultStyledDocument and letting the views draw the text. That all seemed to work except for the "segment offset" issue. And I wasn't sure where the best spot to get the document to redraw subsequent lines in the case of changing a multiline comment, etc.
    So, everything I read about others attempts for syntax highlighters seems to use either StyledEditorKit with a fixed language set with custom parsing and using the setCharacterAttributes method. Or they use the plaindocument approach with a custom view..(which no one seems to share the source) or the project just simply uses the JEditTextArea directly (which we can't do in our product).
    We don't need multiple fonts per-line.. The document will always use one font face (Arial, Helvetica, etc) but may use different styles per word (bold, italic, etc).
    I thought I'd need to use FontMetrics to get the size of the font and such. But there didn't seem to be a difference in measurements based on the style of the font. (i.,e A bold font has the same charWidth('m') size as a regular style.
    At least that's what my test program showed..
    The other thing I noticed is that when the document is successfully colored and I use the mouse to select a region of text, the style of the text reverts back to normal. I'm sure that's because I only override the drawUnselectedText() method.
    Any ideas? Is there anyone who has successfully done this?
    Thanks,
    - Tim

    I just tried using a proportional font in my editor, and now I'm seeing your runaway-caret problem. Specifically, the caret remains in sync with the text as long as no bold characters are encountered, but it gets noticeably farther out of whack with each bold character it passes. I suspect that, when you measured the charWidth, your FontMetrics object wasn't really based on a bold font, because bold versions of proportional fonts are larger. And of course, the model/view conversion methods assume that the same style of the same font is used throughout the document. I've never had to deal with that problem, since I've always used monospaced fonts by preference, and bold versions of monospaced fonts really are the same size as the non-bold versions. I suggest you do the same, because getting this to work with proportional fonts look like a major hassle.

  • Syntax Highlighting for custom file extensions

    Hi everyone.
    I am currently working on a PHP project, and we are using
    *.thtml files for templates. The file isn't supported by
    Dreamweaver, as it's a fictional file extension. First I couldn't
    even open it with Dreamweaver, but after I added it in
    settings/file types, it worked.
    Now my question - how can I activate syntax highlighting for
    this filetype? It contains HTML and PHP, so it should work with the
    same highlighter as all the other file types do..
    Can someone help me out?
    Thanks.
    - Chris

    Got it
    http://alexle.net/archives/119

  • Standard or XML syntax?

    Which syntax is more "trendy"? And what's so special about XML syntax? All the fuss about the <jsp:text> and CDATA when writing output... And what does the jsp:text do in the first place? I read it preservs whitespace, but I didn't see the difference. And why is ${expression} said to be invalid in the J2EE tutorial? Sorry if these are funny questions but I'd really like to know it :-)

    You can find lots of example in this forum.
    Here are some of the recent ones:
    xmlp conditional region if statement inlist
    choose when syntax

  • Syntax highlighted program code in keynote?

    Is there any easy way insert programming code (in my case Ruby code) into a slide so it shows up with syntax highlighting and formating suitable for the code?
    I.E. so it looks like the highlighted code in Textmate or other gui editors?

    TextWrangler (and thus presumably BBEdit) do preserve their syntax colouring when PDFed, as does Taco HTML Edit. My guess is that this is capability is an app-by-app feature.
    If you were desperate for a PDF output to Keynote, you could always copy the text from Textmate and paste it into the freeware TextWrangler. You would likely have to adjust the default syntax colouring to match Textmate, but that would be relatively straightforward.

  • Enable syntax highlighting with configuration file in emacs

    When editing configuration files such as .procmailrc, .fetchmailrc, Emacs won't automatically highlight syntax for me.
    I can enable syntax highlighting in Vim by appending "syntax on"  to the .vimrc.
    I tried adding "global-font-lock-mode t" in the .emacs file, but it didn't solve my problem.
    What is the solution?

    igndenok wrote:
    Some of my config file have this (using conf-unix-mode)
    # this is .somerc
    # -*- conf-unix -*-
    Or using this in your .emacs
    (add-to-list 'auto-mode-alist '("\\.*rc$" . conf-unix-mode))
    I followed your advice, and it does have some syntax highlighting, but less than Vim does.
    For example, Vim will highlight all the names of colors in the .muttrc file, but Emacs doesn't.
    I guess Emacs is not as strong as Vim when it comes to editing configuration files.
    Last edited by yu3k (2011-09-14 10:06:47)

Maybe you are looking for

  • How to move Pictures Folder to a new location.

    I have 4 internal HD's and I would like to dedicate one to be my Pictures HD/Folder. Is it as simple as copying the folder to that drive? I hope so. I use Photoshop and Lightroom only. Just use IPhoto for desktop wall paper folder. Thanks!

  • Compressing photos for the web

    I'm new to mac and iPhoto. When I bring in photos from my camera into iPhoto, their file size is way too big for emailing and the web. (over 1mb) is it possible to compress and edit photos in iPhoto? Or do i have to use another program such as Photos

  • Menu color shift in DVD Studio Pro

    THE PROBLEM: There is a color or gamma shift in DVD SP menu when you play the DVD on a regular monitor and also when you play the DVD image using Apple's DVD Player app. The only thing that is effected is the menu.  The footage, which was compressed 

  • Secure individual notes

    I'd like to suggest a new feature whereby one can select certain notes and mark them as secured, whereby, access to those particular notes requires a password.

  • 2lis_03_um DTP error urjent

    Hi, following steps i did in my extraction of 0IC_c03 info cube 1. Run MCNB to fill setup of BX, OLI1BW FOR BF, OLIZBW for UM 2. In BI iam using BI7.0 dataflow only TRANSFORMATIONS, NO transfer and update rules. 3. i did intialization for BX, EXTRACT