1414import javax .validation .constraints .Null ;
1515import java .awt .*;
1616import java .awt .event .ActionEvent ;
17+ import java .awt .event .KeyEvent ;
1718import java .beans .PropertyChangeEvent ;
1819import java .beans .PropertyChangeListener ;
1920import java .io .File ;
@@ -35,13 +36,14 @@ public class ScriptingConsolePanel extends JPanel {
3536 private ScriptLogPanel log ;
3637 private ScriptEditor editor ;
3738 private ScriptErrorViewer errorViewer ;
39+ private RunScriptAction actRun ;
3840
3941 protected JPanel buildControlPanel () {
40- final JPanel pnl = new JPanel (new FlowLayout (FlowLayout .CENTER , 0 , 0 ));
41- pnl .setBorder (null );
42+ final var pnl = new JPanel (new FlowLayout (FlowLayout .CENTER , 0 , 0 ));
4243 pnl .setBorder (BorderFactory .createEmptyBorder (2 , 2 , 2 , 2 ));
43- JButton btn = new JButton (new RunScriptAction (editor .getModel (), errorViewer .getModel ()));
44- pnl .add (btn );
44+ actRun = new RunScriptAction (editor .getModel (), errorViewer .getModel ());
45+ final var btnRun = new JButton (actRun );
46+ pnl .add (btnRun );
4547 return pnl ;
4648 }
4749
@@ -77,7 +79,7 @@ protected JSplitPane buildSplitPane() {
7779 return sp ;
7880 }
7981
80- protected void build () {
82+ protected void build (@ NotNull JRootPane root ) {
8183 // make sure errorViewer is built at the beginning
8284 errorViewer = new ScriptErrorViewer ();
8385
@@ -92,6 +94,10 @@ protected void build() {
9294 updateScriptContentType (desc );
9395 });
9496 updateScriptContentType (editor .getModel ().getScriptEngineDescriptor ());
97+ root .registerKeyboardAction (actRun ,
98+ KeyStroke .getKeyStroke (KeyEvent .VK_F5 , 0 ),
99+ JComponent .WHEN_IN_FOCUSED_WINDOW
100+ );
95101 }
96102
97103 protected void warnMissingSyntaxStyle (@ Null ScriptEngineDescriptor desc ) {
@@ -151,8 +157,13 @@ protected void updateScriptContentType(ScriptEngineDescriptor desc) {
151157 }
152158 }
153159
154- public ScriptingConsolePanel () {
155- build ();
160+ /**
161+ * Creates the scripting console pane
162+ *
163+ * @param root the root pane of the window where this panel is going to be added
164+ */
165+ public ScriptingConsolePanel (@ NotNull JRootPane root ) {
166+ build (root );
156167 }
157168
158169 /**
@@ -195,7 +206,7 @@ public RunScriptAction(@NotNull final ScriptEditorModel model, @NotNull final Sc
195206 this .model = model ;
196207 this .errorModel = errorModel ;
197208 putValue (SMALL_ICON , ImageProvider .get ("media-playback-start" , ImageProvider .ImageSizes .SMALLICON ));
198- putValue (SHORT_DESCRIPTION , tr ("Execute the script" ));
209+ putValue (SHORT_DESCRIPTION , tr ("Execute the script (F5) " ));
199210 putValue (NAME , tr ("Run" ));
200211 model .addPropertyChangeListener (this );
201212 updateEnabledState ();
0 commit comments