Giter VIP home page Giter VIP logo

monacofx's Introduction

MonacoFX

Download

JavaFX editor node based on the powerful Monaco editor that drives VS Code

Using MonacoFX

Using MonacoFX is straightforward. Just create a MonacoFX node and add it to the scene graph. Here's a an example on how to use MonacoFX with syntax highlighting and code folding for an existing language:

public class App extends Application {

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

    @Override
    public void start(Stage primaryStage) throws Exception {

        // create a new monaco editor node
        MonacoFX monacoFX = new MonacoFX();
        StackPane root = new StackPane(monacoFX);

        // set initial text
        monacoFX.getEditor().getDocument().setText(
                "#include <stdio.h>\n" +
                "int main() {\n" +
                "   // printf() displays the string inside quotation\n" +
                "   printf(\"Hello, World!\");\n" +
                "   return 0;\n" +
                "}");

        // use a predefined language like 'c'
        monacoFX.getEditor().setCurrentLanguage("c");
        monacoFX.getEditor().setCurrentTheme("vs-dark");

        // the usual scene & stage setup
        Scene scene = new Scene(root, 800,600);
        primaryStage.setTitle("MonacoFX Demo (running on JDK " + System.getProperty("java.version") + ")");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Visit the MonacoFX tutorial projects and learn more about advanced topics, such as adding custom language support and code folding.

How To Build The Project

1. Dependencies

  • JDK >= 11 (tested with JDK 13)
  • Internet Connection (other dependencies will be downloaded automatically)
  • Optional: IDE with Gradle support

2. Building

IDE

To build the project from an IDE do the following:

  • open the Gradle project
  • call the assemble Gradle task to build the project

Command Line

Building the project from the command line is also possible.

Navigate to the project folder and call the assemble Gradle task to build the project.

Bash (Linux/OS X/Cygwin/other Unix-like OS)
cd Path/To/MonacoFX
./gradlew assemble
Windows (CMD)
cd Path\To\MonacoFX
gradlew assemble

3. Running the sample App

IDE

To run the project from an IDE do the following:

  • open the Gradle project
  • call the run Gradle task to run the project

Command Line

Running the project from the command line is also possible.

Navigate to the project folder and call the run Gradle task to run the project.

Bash (Linux/OS X/Cygwin/other Unix-like OS)
cd Path/To/MonacoFX
./gradlew run
Windows (CMD)
cd Path\To\MonacoFX
gradlew run

monacofx's People

Contributors

jperedadnr avatar kia avatar megacoderx avatar miho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monacofx's Issues

text property doesn't change

When you type in the editor, it doesn't update the text property. So getEditor().getDocument().getText() either returns null or whatever text you manually set with setText().

It makes this whole thing pretty much useless.

Past external code on button

Hello,

i have a listview with a number of variables.
On double click or press a button i want to set a text inside of the editor.
Is their a way to do that?

Get list of supported languages?

I could not seem to find a way to get a list of the languages that MonacoFX has syntax highlighting and code folding for.

I'd like to include a list of supported languages in my application so it would be nice to be able to get that list from the library along with the file extensions that can be used with getEditor().getDocument().setLanguage() method.

Is this currently possible with MonacoFX? If so, how do I do it?

Thank you,

Mike

Max number of attempts reached

ReferenceError: Can't find variable: monaco
Exception in thread "Thread-19" java.lang.RuntimeException: Cannot initialize editor (JS execution not complete). Max number of attempts reached.
at eu.mihosoft.monacofx.MonacoFX.lambda$new$1(MonacoFX.java:83)
at java.base/java.lang.Thread.run(Thread.java:834)

I-Beam mouse pointer is unusually large when running on MacOS

Hello,

I've noticed that when I run my program on MacOS, the i-beam mouse pointer is VERY large when rolling the mouse around inside the MonacoFX document. It is properly sized when running under Windows.

Do you know of any way that this can be changed - some way to re-size the i-beam mouse pointer in MonacoFX?

Thank you,

Mike Sims

Editor does not return the right text.

When i am typing in my textbox, when a key combination is pressed, it should execute the following code:

System.out.println(txtContent.getEditor().getDocument().getText());

(txtContent is the MonaxoFX)

What i type in the textbox is this:
error1

But my console output is like this:
error2

package should not be used as a dir name in /src/main/resources

"package" is a reserved word in java and can cause issues with tools when used as a directory name in the java classpath:

src/main/resources/eu/mihosoft/monacofx/monaco-editor-0.20.0/package

For example, netbeans (gradle projects at least) will hide this directory in the project view b/c of the name.

superclass access check failure when creating new instance of MonacoFX

Hello,

Using Java 16, if I simply create a new JavaFX application in IntelliJ, then add the Maven dependency for MonacoFX, then add this to the module-info.java file:

requires eu.mihosoft.monacofx;

Then add this one line to the starting class (which does run successfully without adding this line):

MonacoFX monacoFX = new MonacoFX();

I receive this error when I try to run the code:

java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.RuntimeException: Exception in Application start method
...
Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.sg.prism.web.NGWebView (in unnamed module @0x1da23d11) cannot access class com.sun.javafx.sg.prism.NGGroup (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.sg.prism to unnamed module @0x1da23d11

Any ideas on how to fix it?

Thank you,

Mike

Result of the document content is not updated

After editing some text in monacofx, I tried to get the result of the document, but for some times, it doesn't represents the whole text by calling Document#getText(). I added a another method to get the text value and this seems to work

public class Document{
...
    public String getValue() {
    	 return (String) editor.call("getValue");
    }
}

In some case this method wasn't called.

 window.setMember("contentChangeListener", new JFunction( args -> {

            String text = (String) editor.call("getValue");
            if(text!=null) {
                setText(text);
                numberOfLinesProperty.setValue(text.split("\\R").length);
            }
            return null;
        }));

RuntimeException "Max number of attempts reached" is not visible for end user

Hello,

we came across a problem with the RuntimeException thrown when maximal number of attempts is reached during initialization.

The exception is thrown in a separate thread during asynchronous initialization. As a result the thread will die and the exception is caught by the JVM. At the end the JVM will print a stack trace to console and terminate the thread.

This behaviour is not feasibly for a GUI application as this error will never find its way to the end user.

I would suggest to offer a new method for registering an UncaughtExceptionHandler (like Thread.UncaughtExceptionHandler). This would allow developers to use their own handler that pops up an exception dialog in their UI.

Thanks and best regards
Thorsten

Copy does not work on OSX

revision: 96bfd47
platform: OSX
Java: Oracle JDK 14
JavaFX: 15-ea+3

Copy using Command-C, the context menu, or the command palette menu on OSX does not work in the editor. Paste (Command-V) does paste the clipboard.

Still maintained?

First of all, I really like this project!
It looks like it is currently not maintained, though. What is the current status of this project? Are contributions welcome?

I would like to add a setFontSize method to the Editor. I think #27 is a great addition too.

Maybe someone from the community is willing to maintain the project, if you are fully occupied with other projects (if you would be ok with that)?

Cheers

Published artifact adds dependency on JavaFX for Windows

When using the library on Mac or Linux, JavaFX 12.0.1-win artifacts are included, which is not convenient.

This happens because the pom has these dependencies:

<dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-graphics</artifactId>
      <version>12.0.1</version>
      <classifier>win</classifier>
      <scope>runtime</scope>
    </dependency>
...

that include the win classifier.

One way to avoid it is to remove the classifiers from the generated pom (see for instance this). Removing the classifier from the pom is not a problem, once in a given platform Maven will resolve the required classifier.

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.