GithubHelp home page GithubHelp logo

dlavor / jsyntaxpane Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jbfaden/jsyntaxpane

0.0 0.0 0.0 587 KB

An updated version of code.google.com/p/jsyntaxpane r096 branch

JavaScript 0.07% Java 68.51% Lex 31.42%

jsyntaxpane's Introduction

JSyntaxPane

JSyntaxPane is a simple to use editorKit that adds syntax highlighting support to a standard JEditorPane. The languages currently supported are C, C++, Java, JavaScript, Groovy, SQL, Python, Ruby, Scala, Bash, XPath, Clojure, Lua, XHTML and XML - full list here

The original project JSyntaxPane can be found on google-code. This was a fork from the 0.9.6 branch with Hanns Holger Rutz's work applied.

The original project is (C)opyright by Ayman Al-Sairafi and released under the Apache License, Version 2.0.

This was forked from https://github.com/nordfalk/jsyntaxpane, so that it could be modified to draw tab characters.

How to use

  1. Load the latest release.

  2. You can build from source, or just take the JSyntaxPane.jar from the dist folder. Add it to your classpath.

3a. Create a standard JEditorPane control and use a JSyntaxPane editorKit property as follows:

    jEditorPane.setEditorKit(new JavaSyntaxKit());

3b. You can also just set ContentType to one of the available editorkits.

    DefaultSyntaxKit.initKit();
    jEditorPane.setContentType("text/java")

To change the default colors, modify the SyntaxStyles class.

#Building JSyntaxPane

For building, you need to install Maven.

To build from the command-line, just cd into the checked out folder and issue the command:

mvn package

The JFlex generated sources will be found in target/generated-sources. The binary jar will be built in the target folder.

Netbeans 6.1+

Choose Tools>Plugins>Available Plugins and choose and install Maven. After installation, just use the IDE's Open Project option to open JSyntaxPane checkedout project (no need to configure dependencies, source directories, Java platform versions etc.)--Maven projects can be directly be opened in Netbeans.

Customizing

JSyntaxPane uses "Lexers" to distinguish different tokens of any supported languages. Each Lexer must implement the Lexer interface. The Lexers provided were all done using the great JFlex. JFlex takes a lexer definition file, and creates a one class lexer. The Lex files for the languages currently supported are in the the JFlex folder of the zip distribution file.

I will not go into too much details about how to write lex files. the JFLex site has a great manual. But in a nutshell, you can copy a provided lex file, modify it to your needs, then run it through JFlex. Put the generated Java file in the jsyntaxpane package, then build. Make sure you modify the %class line and use the same name for the constructor in the block below.

The TokenTypes class is an enum of all supported TokenTypes. You can also add more types if you need. If you do that, also modify the SyntaxStyle and SyntaxStyles class to use those types.

You also need to modify the SyntaxKit class createDefaultDocument method to use your lexer for the given language. You may also want to modify the install method of SyntaxKit to add other default actions for the component. I'm considering an automated method to make all this automated, without changing the SyntaxKit class.

Once you are done, and built your lexer, you can change the SyntaxTester to test your lexer. Modify the Tester class to use your lexer instead of the built in ones. Whenever the caret is moved, the Token under the caret is displayed in the line below. That makes testing very easy.

If you create Lexers, please consider contributing them.

Notes about Revisions

This was forked from https://github.com/nordfalk/jsyntaxpane, so that it could be modified to draw tab characters.

jsyntaxpane's People

Contributors

nordfalk avatar jbfaden avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.