Class JShellPanel

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
nz.ac.waikato.cms.gui.core.BasePanel
com.github.fracpete.jshell.JShellPanel
All Implemented Interfaces:
JShellErrorListener, JShellExecListener, com.github.fracpete.processoutput4j.core.StreamingProcessOwner, ImageObserver, MenuContainer, Serializable, Accessible

public class JShellPanel extends nz.ac.waikato.cms.gui.core.BasePanel implements com.github.fracpete.processoutput4j.core.StreamingProcessOwner, JShellErrorListener, JShellExecListener
Panel for performing scripting via jshell. Requires Java 9. See https://docs.oracle.com/javase/9/jshell/
Author:
FracPete (fracpete at gmail dot com)
See Also:
  • Field Details

    • THEMES

      public static final String[] THEMES
      the available themes.
    • DEFAULT_THEME

      public static final String DEFAULT_THEME
      the default theme.
      See Also:
    • m_SplitPane

      protected JSplitPane m_SplitPane
      for splitting code and output.
    • m_ComboBoxThemes

      protected JComboBox<String> m_ComboBoxThemes
      the panel with the themes.
    • m_TextCode

      protected org.fife.ui.rsyntaxtextarea.RSyntaxTextArea m_TextCode
      the text area for the script.
    • m_FileChooserScript

      protected nz.ac.waikato.cms.gui.core.BaseFileChooser m_FileChooserScript
      the filechooser for scripts.
    • m_ButtonScriptLoad

      protected JButton m_ButtonScriptLoad
      the button for loading a script.
    • m_ButtonScriptSave

      protected JButton m_ButtonScriptSave
      the button for saving as script.
    • m_ButtonScriptRun

      protected JButton m_ButtonScriptRun
      the button for executing a script.
    • m_ButtonScriptStop

      protected JButton m_ButtonScriptStop
      the button for stopping a script.
    • m_FileChooserOutput

      protected nz.ac.waikato.cms.gui.core.BaseFileChooser m_FileChooserOutput
      the filechooser for the output.
    • m_ButtonOutputClear

      protected JButton m_ButtonOutputClear
      the button for clearing the output.
    • m_ButtonOutputSave

      protected JButton m_ButtonOutputSave
      the button for saving the output.
    • m_TextOutput

      protected JTextArea m_TextOutput
      for the jshell output.
    • m_Exec

      protected JShellExec m_Exec
      for executing the script.
    • m_JShellPanelListeners

      protected Set<JShellPanelListener> m_JShellPanelListeners
      the listeners that listen for changes.
    • m_RuntimeFlags

      protected List<String> m_RuntimeFlags
      additional runtime flags to supply to JShell (-J).
    • m_RemoteRuntimeFlags

      protected List<String> m_RemoteRuntimeFlags
      additional remote runtime flags to supply to JShell (-R).
    • m_CompilerFlags

      protected List<String> m_CompilerFlags
      additional compiler flags to supply to JShell (-C).
  • Constructor Details

    • JShellPanel

      public JShellPanel()
  • Method Details

    • initialize

      protected void initialize()
      Initializes the members.
      Overrides:
      initialize in class nz.ac.waikato.cms.gui.core.BasePanel
    • initGUI

      protected void initGUI()
      Initializes the widgets.
      Overrides:
      initGUI in class nz.ac.waikato.cms.gui.core.BasePanel
    • finishInit

      protected void finishInit()
      Finishes the initialization.
      Overrides:
      finishInit in class nz.ac.waikato.cms.gui.core.BasePanel
    • updateTheme

      protected boolean updateTheme()
      Updates the theme.
      Returns:
      true if successfully applied
    • setCurrentTheme

      public void setCurrentTheme(String value)
      Sets the current theme.
      Parameters:
      value - the theme to use
      See Also:
    • getCurrentTheme

      public String getCurrentTheme()
      Returns the currently selected theme.
      Returns:
      the current theme
    • setDebug

      public void setDebug(boolean value)
      Sets the debugging flag.
      Parameters:
      value - true if to turn debugging output on
    • getDebug

      public boolean getDebug()
      Returns the debugging flag.
      Returns:
      true if debugging output on
    • isRunning

      public boolean isRunning()
      Returns whether a script is currently running.
      Returns:
      true if a script is running
    • updateButtons

      protected void updateButtons()
      Updates the state of the buttons.
    • loadScript

      public void loadScript()
      Lets the user select a script to load.
    • loadScript

      public void loadScript(File script)
      Loads the specified file.
      Parameters:
      script - the script to load
    • saveScript

      public void saveScript()
      Lets the user save the script to a file.
    • runScript

      public void runScript()
      Executes the script.
    • stopScript

      public void stopScript()
      Stops a running script.
    • clearScriptOutput

      public void clearScriptOutput()
      Clears the output of the script.
    • saveScriptOutput

      public void saveScriptOutput()
      Lets the user save the script output to a file.
    • getCode

      public String getCode()
      Returns the current code.
      Returns:
      the code
    • getOutput

      public String getOutput()
      Returns the current output.
      Returns:
      the output
    • isAvailable

      public boolean isAvailable()
      Checks whether jshell executable is available.
      Returns:
      true if available
    • getOutputType

      public com.github.fracpete.processoutput4j.core.StreamingProcessOutputType getOutputType()
      Returns what output from the process to forward.
      Specified by:
      getOutputType in interface com.github.fracpete.processoutput4j.core.StreamingProcessOwner
      Returns:
      the output type
    • processOutput

      public void processOutput(String line, boolean stdout)
      Processes the incoming line.
      Specified by:
      processOutput in interface com.github.fracpete.processoutput4j.core.StreamingProcessOwner
      Parameters:
      line - the line to process
      stdout - whether stdout or stderr
    • addJShellExecListener

      public void addJShellExecListener(JShellExecListener l)
      Adds the exec listener to the internal list.
      Parameters:
      l - the listener to add
    • removeJShellExecListener

      public void removeJShellExecListener(JShellExecListener l)
      Removes the exec listener to the internal list.
      Parameters:
      l - the listener to remove
    • addJShellPanelListener

      public void addJShellPanelListener(JShellPanelListener l)
      Adds the panel listener to the internal list.
      Parameters:
      l - the listener to add
    • removeJShellExecListener

      public void removeJShellExecListener(JShellPanelListener l)
      Removes the panel listener to the internal list.
      Parameters:
      l - the listener to remove
    • notifyJShellPanelListeners

      public void notifyJShellPanelListeners(JShellPanelEvent e)
      Notifies all the listeners with the specified panel event.
      Parameters:
      e - the event to send
    • jshellErrorOccurred

      public void jshellErrorOccurred(JShellErrorEvent e)
      Gets called when an error occurred.
      Specified by:
      jshellErrorOccurred in interface JShellErrorListener
      Parameters:
      e - the error
    • jshellExecEventOccurred

      public void jshellExecEventOccurred(JShellExecEvent e)
      Gets triggered with any event in the JShellPanel.
      Specified by:
      jshellExecEventOccurred in interface JShellExecListener
      Parameters:
      e - the event
    • setRuntimeFlags

      public void setRuntimeFlags(List<String> value)
      Sets the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).
      Parameters:
      value - the flags
    • getRuntimeFlags

      public List<String> getRuntimeFlags()
      Returns the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).
      Returns:
      the flags
    • setRemoteRuntimeFlags

      public void setRemoteRuntimeFlags(List<String> value)
      Sets the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).
      Parameters:
      value - the flags
    • getRemoteRuntimeFlags

      public List<String> getRemoteRuntimeFlags()
      Returns the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).
      Returns:
      the flags
    • setCompilerFlags

      public void setCompilerFlags(List<String> value)
      Sets the compiler flags to supply to JShell (-C).
      Parameters:
      value - the flags
    • getCompilerFlags

      public List<String> getCompilerFlags()
      Returns the compiler flags to supply to JShell (-C).
      Returns:
      the flags
    • main

      public static void main(String[] args)
      For testing only.
      Parameters:
      args - first argument is interpreted as script