Class JsonFormatterView

All Implemented Interfaces:
Styleable, EventTarget

public class JsonFormatterView extends DefaultCodeEditorView
JSON formatter editor view built on RSyntaxTextArea.

This is a specialised DefaultCodeEditorView for JSON documents: the syntax highlighting is RSyntaxTextArea's own JSON tokenizer with the token colours of the theme (see DefaultCodeEditorView.applyEditorTheme()), and documents are pretty-printed with Gson - the same JSON library and formatting (JsonParser.parseString + setPrettyPrinting). The header shows the brackets-curly glyph, set by the controller when the pane is customized.

The view is created with its two standard constructors, like every other view, and set up with UI.setup(BaseApp, String, Pane, String). It has no buttons of its own: the footer buttons are set on the controller before the stage is shown, see DefaultCodeEditorController.setButtons(java.util.List). The formatter window of the framework (ch.autumo.ui.utils.UI#showJsonFormatter) ships the standard button set: Copy, Clear, Format JSON and Alright.

Extensible by subclassing: the protected hooks of DefaultCodeEditorView (createTextArea, createScrollPane, applyEditorTheme) change the editor's behaviour or look.

  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      Logger.
  • Constructor Details

    • JsonFormatterView

      public JsonFormatterView(BaseApp app, Stage stage)
      JSON formatter view.
      Parameters:
      app - the application
      stage - stage
    • JsonFormatterView

      public JsonFormatterView(BaseApp app, Stage stage, String styleResourcePath)
      JSON formatter view.
      Parameters:
      app - the application
      stage - stage
      styleResourcePath - relative style ('style/style.css') file name or fully qualified resource path
  • Method Details

    • format

      public boolean format()
      Format the current document: pretty-print it with Gson and move the caret to the document start.

      An empty document is formatted to an empty document; a document that cannot be parsed is left untouched. The parse error is printed to the console; the caller may show a dialog ("…couldn't be parsed… Check console output.").

      Returns:
      true if the document was formatted or empty, false if it couldn't be parsed as JSON