|
| 1 | +package com.devkev.gui; |
| 2 | + |
| 3 | +import javax.swing.JFrame; |
| 4 | +import javax.swing.JPanel; |
| 5 | +import javax.swing.border.EmptyBorder; |
| 6 | +import javax.swing.JButton; |
| 7 | +import java.awt.Font; |
| 8 | +import javax.swing.JScrollPane; |
| 9 | +import java.awt.event.ActionListener; |
| 10 | +import java.awt.event.ComponentEvent; |
| 11 | +import java.awt.event.ComponentListener; |
| 12 | +import java.awt.event.KeyEvent; |
| 13 | +import java.awt.event.KeyListener; |
| 14 | +import java.awt.event.WindowEvent; |
| 15 | +import java.awt.event.WindowListener; |
| 16 | +import java.awt.event.ActionEvent; |
| 17 | +import javax.swing.JTextArea; |
| 18 | +import javax.swing.ImageIcon; |
| 19 | + |
| 20 | +public class Console extends JFrame { |
| 21 | + |
| 22 | + private static final long serialVersionUID = 1L; |
| 23 | + private JPanel contentPane; |
| 24 | + private com.devkev.devscript.raw.Process p; |
| 25 | + private Window parent; |
| 26 | + |
| 27 | + volatile boolean waitForEnter = false; |
| 28 | + volatile int inputStart = 0; |
| 29 | + |
| 30 | + public Console(com.devkev.devscript.raw.Process p, Window parent) { |
| 31 | + this.p = p; |
| 32 | + this.parent = parent; |
| 33 | + init(); |
| 34 | + } |
| 35 | + |
| 36 | + private void init() { |
| 37 | + setFont(new Font("Consolas", Font.PLAIN, 12)); |
| 38 | + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
| 39 | + setBounds(100, 100, 500, 239); |
| 40 | + |
| 41 | + contentPane = new JPanel(); |
| 42 | + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 43 | + |
| 44 | + setContentPane(contentPane); |
| 45 | + contentPane.setLayout(null); |
| 46 | + |
| 47 | + JButton terminate = new JButton(""); |
| 48 | + terminate.setIcon(new ImageIcon("C:\\Users\\Philipp\\Desktop\\terminate-active.png")); |
| 49 | + terminate.addActionListener(new ActionListener() { |
| 50 | + public void actionPerformed(ActionEvent arg0) { |
| 51 | + } |
| 52 | + }); |
| 53 | + terminate.setBounds(451, 166, 23, 23); |
| 54 | + contentPane.add(terminate); |
| 55 | + |
| 56 | + JButton rerun = new JButton(""); |
| 57 | + rerun.setIcon(new ImageIcon("C:\\Users\\Philipp\\Desktop\\rerun-active.png")); |
| 58 | + rerun.setBounds(418, 166, 23, 23); |
| 59 | + contentPane.add(rerun); |
| 60 | + |
| 61 | + JScrollPane scrollPane = new JScrollPane(); |
| 62 | + scrollPane.setBounds(10, 11, 464, 144); |
| 63 | + contentPane.add(scrollPane); |
| 64 | + |
| 65 | + JTextArea console = new JTextArea(); |
| 66 | + scrollPane.setViewportView(console); |
| 67 | + |
| 68 | + addKeyListener(new KeyListener() { |
| 69 | + |
| 70 | + @Override |
| 71 | + public void keyTyped(KeyEvent e) { |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void keyReleased(KeyEvent e) { |
| 76 | + if(p.isRunning()) { |
| 77 | + p.setVariable("keyCode", "", false, false); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void keyPressed(KeyEvent e) { |
| 83 | + if(p.isRunning()) { |
| 84 | + //Set the variable "keyPressed" to the char that is pressed |
| 85 | + p.setVariable("keyCode", e.getKeyChar(), false, false); |
| 86 | + } |
| 87 | + } |
| 88 | + }); |
| 89 | + |
| 90 | + addWindowListener(new WindowListener() { |
| 91 | + public void windowClosed(WindowEvent arg0) {} |
| 92 | + public void windowOpened(WindowEvent arg0) {} |
| 93 | + public void windowIconified(WindowEvent arg0) {} |
| 94 | + public void windowDeiconified(WindowEvent arg0) {} |
| 95 | + public void windowDeactivated(WindowEvent arg0) {} |
| 96 | + public void windowClosing(WindowEvent arg0) { |
| 97 | + if(p.isRunning()) { |
| 98 | + System.out.println("Closing running instance"); |
| 99 | + p.kill(p.getMain(), "Interrupted by program"); |
| 100 | + } |
| 101 | + parent.window.setEnabled(true); |
| 102 | + inputStart = 0; |
| 103 | + parent.input.flush(null); |
| 104 | + console.setText(""); |
| 105 | + } |
| 106 | + public void windowActivated(WindowEvent arg0) {} |
| 107 | + }); |
| 108 | + |
| 109 | + addComponentListener(new ComponentListener() { |
| 110 | + @Override |
| 111 | + public void componentResized(ComponentEvent e) { |
| 112 | + console.setSize(parent.window.getRootPane().getWidth() - 10, parent.window.getRootPane().getHeight()-parent.bar.getHeight() - 10); |
| 113 | + console.updateUI(); |
| 114 | + } |
| 115 | + public void componentShown(ComponentEvent e) {} |
| 116 | + public void componentMoved(ComponentEvent e) {} |
| 117 | + public void componentHidden(ComponentEvent e) {} |
| 118 | + }); |
| 119 | + |
| 120 | + } |
| 121 | +} |
0 commit comments