1616import java .awt .event .ActionEvent ;
1717import javax .swing .JTextArea ;
1818import javax .swing .ImageIcon ;
19+ import javax .swing .border .LineBorder ;
20+ import java .awt .Color ;
21+ import javax .swing .JLabel ;
1922
2023public class Console extends JFrame {
2124
@@ -24,46 +27,86 @@ public class Console extends JFrame {
2427 private com .devkev .devscript .raw .Process p ;
2528 private Window parent ;
2629
30+ JTextArea consoleText ;
31+ JScrollPane consolePane ;
32+ JLabel consoleStatus ;
33+
2734 volatile boolean waitForEnter = false ;
2835 volatile int inputStart = 0 ;
2936
3037 public Console (com .devkev .devscript .raw .Process p , Window parent ) {
38+ setTitle ("DevScript Console" );
3139 this .p = p ;
3240 this .parent = parent ;
3341 init ();
3442 }
3543
3644 private void init () {
3745 setFont (new Font ("Consolas" , Font .PLAIN , 12 ));
38- setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
3946 setBounds (100 , 100 , 500 , 239 );
47+ setFocusableWindowState (true );
48+ setEnabled (true );
4049
4150 contentPane = new JPanel ();
4251 contentPane .setBorder (new EmptyBorder (5 , 5 , 5 , 5 ));
43-
52+
4453 setContentPane (contentPane );
4554 contentPane .setLayout (null );
4655
4756 JButton terminate = new JButton ("" );
48- terminate .setIcon (new ImageIcon ("C:\\ Users\\ Philipp\\ Desktop\\ terminate-active.png" ));
57+ terminate .setToolTipText ("Terminate" );
58+ terminate .setBorder (new LineBorder (new Color (0 , 0 , 0 )));
59+ terminate .setIcon (new ImageIcon (Console .class .getResource ("/icon/terminate-active.png" )));
4960 terminate .addActionListener (new ActionListener () {
5061 public void actionPerformed (ActionEvent arg0 ) {
5162 }
5263 });
53- terminate .setBounds (451 , 166 , 23 , 23 );
64+ terminate .setBounds (456 , 5 , 23 , 23 );
65+ terminate .addActionListener (new ActionListener () {
66+ @ Override
67+ public void actionPerformed (ActionEvent e ) {
68+ if (parent .p .isRunning ()) {
69+ parent .p .kill (parent .p .getMain (), "Terminated by DevScript Console" );
70+ consolePane .getVerticalScrollBar ().setValue (consolePane .getVerticalScrollBar ().getMaximum ());
71+ }
72+ }
73+ });
74+
5475 contentPane .add (terminate );
5576
5677 JButton rerun = new JButton ("" );
57- rerun .setIcon (new ImageIcon ("C:\\ Users\\ Philipp\\ Desktop\\ rerun-active.png" ));
58- rerun .setBounds (418 , 166 , 23 , 23 );
78+ rerun .setToolTipText ("Rerun Script" );
79+ rerun .setBorder (new LineBorder (new Color (0 , 0 , 0 )));
80+ rerun .setIcon (new ImageIcon (Console .class .getResource ("/icon/rerun-active.png" )));
81+ rerun .setBounds (429 , 5 , 23 , 23 );
82+ rerun .addActionListener (new ActionListener () {
83+ @ Override
84+ public void actionPerformed (ActionEvent e ) {
85+ if (p .isRunning ()) return ;
86+
87+ consoleText .setText ("" );
88+ toFront ();
89+ setEnabled (true );
90+ consoleStatus .setText ("Running ..." );
91+ setVisible (true );
92+ //window.setEnabled(false);
93+
94+ p .execute (parent .textArea .getText (), true );
95+ p .setVariable ("keyCode" , "" , false , true );
96+ }
97+ });
5998 contentPane .add (rerun );
6099
61- JScrollPane scrollPane = new JScrollPane ();
62- scrollPane .setBounds (10 , 11 , 464 , 144 );
63- contentPane .add (scrollPane );
100+ consolePane = new JScrollPane ();
101+ consolePane .setBounds (5 , 35 , 474 , 159 );
102+ contentPane .add (consolePane );
103+
104+ consoleText = new JTextArea ();
105+ consolePane .setViewportView (consoleText );
64106
65- JTextArea console = new JTextArea ();
66- scrollPane .setViewportView (console );
107+ consoleStatus = new JLabel ("" );
108+ consoleStatus .setBounds (5 , 5 , 414 , 23 );
109+ contentPane .add (consoleStatus );
67110
68111 addKeyListener (new KeyListener () {
69112
@@ -101,16 +144,18 @@ public void windowClosing(WindowEvent arg0) {
101144 parent .window .setEnabled (true );
102145 inputStart = 0 ;
103146 parent .input .flush (null );
104- console .setText ("" );
147+ consoleText .setText ("" );
105148 }
106149 public void windowActivated (WindowEvent arg0 ) {}
107150 });
108151
109152 addComponentListener (new ComponentListener () {
110153 @ Override
111154 public void componentResized (ComponentEvent e ) {
112- console .setSize (parent .window .getRootPane ().getWidth () - 10 , parent .window .getRootPane ().getHeight ()-parent .bar .getHeight () - 10 );
113- console .updateUI ();
155+ consolePane .setSize (getRootPane ().getWidth () - 10 , getRootPane ().getHeight ()-parent .bar .getHeight () - 20 );
156+ terminate .setLocation (getRootPane ().getWidth () - 28 , 5 );
157+ rerun .setLocation (getRootPane ().getWidth () - 58 , 5 );
158+ consolePane .updateUI ();
114159 }
115160 public void componentShown (ComponentEvent e ) {}
116161 public void componentMoved (ComponentEvent e ) {}
0 commit comments