Package com.github.fracpete.jshell
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringthe default theme.protected JButtonthe button for clearing the output.protected JButtonthe button for saving the output.protected JButtonthe button for loading a script.protected JButtonthe button for executing a script.protected JButtonthe button for saving as script.protected JButtonthe button for stopping a script.the panel with the themes.additional compiler flags to supply to JShell (-C).protected JShellExecfor executing the script.protected nz.ac.waikato.cms.gui.core.BaseFileChooserthe filechooser for the output.protected nz.ac.waikato.cms.gui.core.BaseFileChooserthe filechooser for scripts.protected Set<JShellPanelListener>the listeners that listen for changes.additional remote runtime flags to supply to JShell (-R).additional runtime flags to supply to JShell (-J).protected JSplitPanefor splitting code and output.protected org.fife.ui.rsyntaxtextarea.RSyntaxTextAreathe text area for the script.protected JTextAreafor the jshell output.static final String[]the available themes.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the exec listener to the internal list.voidAdds the panel listener to the internal list.voidClears the output of the script.protected voidFinishes the initialization.getCode()Returns the current code.Returns the compiler flags to supply to JShell (-C).Returns the currently selected theme.booleangetDebug()Returns the debugging flag.Returns the current output.com.github.fracpete.processoutput4j.core.StreamingProcessOutputTypeReturns what output from the process to forward.Returns the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).Returns the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).protected voidinitGUI()Initializes the widgets.protected voidInitializes the members.booleanChecks whether jshell executable is available.booleanReturns whether a script is currently running.voidGets called when an error occurred.voidGets triggered with any event in the JShellPanel.voidLets the user select a script to load.voidloadScript(File script) Loads the specified file.static voidFor testing only.voidNotifies all the listeners with the specified panel event.voidprocessOutput(String line, boolean stdout) Processes the incoming line.voidRemoves the exec listener to the internal list.voidRemoves the panel listener to the internal list.voidExecutes the script.voidLets the user save the script to a file.voidLets the user save the script output to a file.voidsetCompilerFlags(List<String> value) Sets the compiler flags to supply to JShell (-C).voidsetCurrentTheme(String value) Sets the current theme.voidsetDebug(boolean value) Sets the debugging flag.voidsetRemoteRuntimeFlags(List<String> value) Sets the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).voidsetRuntimeFlags(List<String> value) Sets the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).voidStops a running script.protected voidUpdates the state of the buttons.protected booleanUpdates the theme.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
THEMES
the available themes. -
DEFAULT_THEME
the default theme.- See Also:
-
m_SplitPane
for splitting code and output. -
m_ComboBoxThemes
the panel with the themes. -
m_TextCode
protected org.fife.ui.rsyntaxtextarea.RSyntaxTextArea m_TextCodethe text area for the script. -
m_FileChooserScript
protected nz.ac.waikato.cms.gui.core.BaseFileChooser m_FileChooserScriptthe filechooser for scripts. -
m_ButtonScriptLoad
the button for loading a script. -
m_ButtonScriptSave
the button for saving as script. -
m_ButtonScriptRun
the button for executing a script. -
m_ButtonScriptStop
the button for stopping a script. -
m_FileChooserOutput
protected nz.ac.waikato.cms.gui.core.BaseFileChooser m_FileChooserOutputthe filechooser for the output. -
m_ButtonOutputClear
the button for clearing the output. -
m_ButtonOutputSave
the button for saving the output. -
m_TextOutput
for the jshell output. -
m_Exec
for executing the script. -
m_JShellPanelListeners
the listeners that listen for changes. -
m_RuntimeFlags
additional runtime flags to supply to JShell (-J). -
m_RemoteRuntimeFlags
additional remote runtime flags to supply to JShell (-R). -
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:
initializein classnz.ac.waikato.cms.gui.core.BasePanel
-
initGUI
protected void initGUI()Initializes the widgets.- Overrides:
initGUIin classnz.ac.waikato.cms.gui.core.BasePanel
-
finishInit
protected void finishInit()Finishes the initialization.- Overrides:
finishInitin classnz.ac.waikato.cms.gui.core.BasePanel
-
updateTheme
protected boolean updateTheme()Updates the theme.- Returns:
- true if successfully applied
-
setCurrentTheme
Sets the current theme.- Parameters:
value- the theme to use- See Also:
-
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
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
Returns the current code.- Returns:
- the code
-
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:
getOutputTypein interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Returns:
- the output type
-
processOutput
Processes the incoming line.- Specified by:
processOutputin interfacecom.github.fracpete.processoutput4j.core.StreamingProcessOwner- Parameters:
line- the line to processstdout- whether stdout or stderr
-
addJShellExecListener
Adds the exec listener to the internal list.- Parameters:
l- the listener to add
-
removeJShellExecListener
Removes the exec listener to the internal list.- Parameters:
l- the listener to remove
-
addJShellPanelListener
Adds the panel listener to the internal list.- Parameters:
l- the listener to add
-
removeJShellExecListener
Removes the panel listener to the internal list.- Parameters:
l- the listener to remove
-
notifyJShellPanelListeners
Notifies all the listeners with the specified panel event.- Parameters:
e- the event to send
-
jshellErrorOccurred
Gets called when an error occurred.- Specified by:
jshellErrorOccurredin interfaceJShellErrorListener- Parameters:
e- the error
-
jshellExecEventOccurred
Gets triggered with any event in the JShellPanel.- Specified by:
jshellExecEventOccurredin interfaceJShellExecListener- Parameters:
e- the event
-
setRuntimeFlags
Sets the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).- Parameters:
value- the flags
-
getRuntimeFlags
Returns the runtime flags to supply to JShell (-J), used by JShell (eg -verbose).- Returns:
- the flags
-
setRemoteRuntimeFlags
Sets the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).- Parameters:
value- the flags
-
getRemoteRuntimeFlags
Returns the remote runtime flags to supply to JShell (-R), used by the JVM executing the code (eg -javaagent:...).- Returns:
- the flags
-
setCompilerFlags
Sets the compiler flags to supply to JShell (-C).- Parameters:
value- the flags
-
getCompilerFlags
Returns the compiler flags to supply to JShell (-C).- Returns:
- the flags
-
main
For testing only.- Parameters:
args- first argument is interpreted as script
-