Code editors in general with JavaFX


Yesterday I did a short demo on how one can build code editors with JavaFX while the talk was at Xtextcon most information apply to any code editor you may want to develop with the runtime components developed as part of e(fx)clipse.

I’ve uploaded the slides to slideshare

The important point is that all this is plain Java! No OSGi involved so eg the Java-Sample I showed looks like this:

public class SampleJavaCode extends Application {
  private final static String[] LEGAL_CONTENT_TYPES = new String[] { 
    IJavaPartitions.JAVA_DOC,
    IJavaPartitions.JAVA_MULTI_LINE_COMMENT, 
    IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
    IJavaPartitions.JAVA_STRING, IJavaPartitions.JAVA_CHARACTER };

  private int count = 0;

  @Override
  public void start(Stage primaryStage) throws Exception {
    BorderPane container = new BorderPane();
    Document document = new Document();
    document.set(
      Util.getFileContent(getClass().getClassLoader().getResource("Sample_big.txt").toURI()));

    JavaSourceConfiguration configuration = new JavaSourceConfiguration();

    SourceViewer viewer = new SourceViewer();

    FastPartitioner partitioner = new FastPartitioner(new FastJavaPartitionScanner(), LEGAL_CONTENT_TYPES);
    document.setDocumentPartitioner(configuration.getConfiguredDocumentPartitioning(viewer), partitioner);
    partitioner.connect(document);

    viewer.configure(configuration);
    viewer.setDocument(document);
    container.setCenter(viewer.getTextWidget());

    Scene s = new Scene(container);
    s.getStylesheets().add(getClass().getResource("dark.css").toExternalForm());
    primaryStage.setScene(s);
    primaryStage.show();
  }

  public static void main(String[] args) {
    Application.launch(args);
  }
}

and looks like this:

bright.css:
blog_screen1

dark.css:
blog_screen2

All sources for the stuff I presented are available in the e(fx)clipse git repository – watch out for projects starting with “org.eclipse.fx.xtext”.

4 thoughts on “Code editors in general with JavaFX

  1. Daniel Zimmermann May 21, 2015 / 12:33 pm

    Do you have an already build version of Compensator lying around somewhere? Or more generally spoken: Do you (via Eclipse foundation or your company) plan to release one? Will it contain a bundled JRE (preferably, no?)?

    • Tom Schindl May 28, 2015 / 11:25 pm

      No not yet – i’m currently head down in company problems

      • Tom Schindl May 28, 2015 / 11:27 pm

        Uups projects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s