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”.

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Code editors in general with JavaFX

  1. Daniel Zimmermann says:

    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?)?

  2. Pingback: JavaFX links of the week, May 25 // JavaFX News, Demos and Insight // FX Experience

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.