Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

161
LINES

< > BotCompany Repo | #1001729 // Show console for other process (developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1288L/10K/34K).

1  
!747
2  
!awt {
3  
!actionListener {
4  
!pcall {
5  
6  
m {
7  
  static S vmName = "This is a JavaX VM."; // Use any vM
8  
  
9  
  p {
10  
    new Console(new String[0]);
11  
  }
12  
  
13  
  !include #1000943 // DelayedUpdate
14  
15  
  static class Console extends WindowAdapter implements WindowListener, ActionListener {
16  
    PipedInputStream pin=new PipedInputStream();
17  
    PipedInputStream pin2=new PipedInputStream();
18  
    PipedInputStream pin3=new PipedInputStream();
19  
    Thread reader, reader2;
20  
    boolean quit;
21  
  
22  
    JFrame frame;
23  
    JTextArea textArea;
24  
    JTextField tfInput;
25  
    StringBuffer buf = new StringBuffer();
26  
    JButton buttonclear, buttonkill, buttonrestart, buttonduplicate, buttonstacktrace;
27  
    String[] args;
28  
29  
    final DelayedUpdate du = new DelayedUpdate(new Runnable() {
30  
      public void run() { try {
31  
32  
        textArea.append(buf.substring(textArea.getText().length()));
33  
34  
      } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});
35  
36  
    public Console(final String[] args) ctex {
37  
      this.args = args;
38  
      // create all components and add them
39  
      frame=new JFrame(args.length == 0 ? "Console Bot Console" : "Console Bot Console - " + join(" ", args));
40  
41  
		/*Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
42  
		Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2));
43  
		int x=(int)(frameSize.width/2);
44  
		int y=(int)(frameSize.height/2);
45  
		frame.setBounds(x,y,frameSize.width,frameSize.height);*/
46  
47  
      // put in right-bottom corner
48  
      Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
49  
      int w = 550, h = 200;
50  
      frame.setBounds(r.x+r.width-w, r.y+r.height-h, w, h);
51  
52  
      textArea=new JTextArea();
53  
      textArea.setEditable(false);
54  
      buttonclear = new JButton("clear");
55  
      buttonkill = new JButton("kill");
56  
      buttonrestart = new JButton("restart");
57  
      buttonduplicate = new JButton("duplicate");
58  
      buttonstacktrace = new JButton("status");
59  
      buttonstacktrace.setToolTipText("Show threads & stack traces.");
60  
61  
      JPanel buttons = new JPanel(new GridLayout(1, 5));
62  
      buttons.add(buttonclear);
63  
      buttons.add(buttonkill);
64  
      buttons.add(buttonrestart);
65  
      buttons.add(buttonduplicate);
66  
      buttons.add(buttonstacktrace);
67  
68  
      tfInput = new JTextField();
69  
      tfInput.addActionListener(actionListener {
70  
        S line = tfInput.getText();
71  
        sendToLocalBot(vmName, "send line * to system.in", line);
72  
        tfInput.setText("");
73  
      });
74  
      
75  
      JPanel panel = new JPanel(new BorderLayout());
76  
      panel.add(new JScrollPane(textArea), BorderLayout.CENTER);
77  
      panel.add(tfInput, BorderLayout.SOUTH);
78  
      
79  
      frame.addWindowListener(new WindowAdapter() {
80  
        public void windowActivated(WindowEvent e) {
81  
          tfInput.requestFocus();
82  
        }
83  
      });
84  
      
85  
      frame.getContentPane().setLayout(new BorderLayout());
86  
      frame.getContentPane().add(panel, BorderLayout.CENTER);
87  
      frame.getContentPane().add(buttons, BorderLayout.SOUTH);
88  
      frame.setVisible(true);
89  
      
90  
      //frame.addWindowListener(this); // disabled for now
91  
      buttonclear.addActionListener(this);
92  
      buttonkill.addActionListener(this);
93  
      buttonrestart.addActionListener(this);
94  
      buttonduplicate.addActionListener(this);
95  
      buttonstacktrace.addActionListener(this);
96  
97  
      quit=false; // signals the Threads that they should exit
98  
      
99  
      if (args.length != 0) {
100  
        print("Starting title updater");
101  
        new Thread("Console Title Updater :)") {
102  
          public void run() {
103  
            if (args.length != 0) {
104  
              int i = 0;
105  
              while (i < args.length && !isSnippetID(args[i])) ++i;
106  
              print("Getting title for " + args[i]);
107  
              String title = getSnippetTitle(args[i]);
108  
              print("Title: " + title);
109  
              if (title != null && title.length() != 0)
110  
                frame.setTitle(title + " [Output]");
111  
            }
112  
          }
113  
        }.start();
114  
      }
115  
      
116  
      System.setIn(pin3);
117  
      
118  
    }
119  
120  
    public synchronized void windowClosed(WindowEvent evt)
121  
    {
122  
      /*quit=true;
123  
      this.notifyAll(); // stop all threads
124  
      try { reader.join(1000);pin.close();   } catch (Exception e){}
125  
      try { reader2.join(1000);pin2.close(); } catch (Exception e){}
126  
      System.exit(0);*/
127  
    }
128  
129  
    public synchronized void windowClosing(WindowEvent evt)
130  
    {
131  
      frame.setVisible(false); // default behaviour of JFrame
132  
      frame.dispose();
133  
    }
134  
135  
    public synchronized void actionPerformed(ActionEvent evt) {
136  
      /*if (evt.getSource() == buttonkill) {
137  
        print("Console: Kill button pressed!");
138  
        // TODO: give threads time to finish, e.g. reportToChat?
139  
        System.exit(0);
140  
      } else if (evt.getSource() == buttonrestart) {
141  
        print("Console: Restart button pressed.");
142  
        nohupJavax(smartJoin(args));
143  
        System.exit(0);
144  
      } else if (evt.getSource() == buttonduplicate) {
145  
        print("Console: Duplicate button pressed.");
146  
        nohupJavax(smartJoin(args));
147  
      } else if (evt.getSource() == buttonstacktrace) {
148  
        listUserThreadsWithStackTraces();
149  
      } else {
150  
        textArea.setText("");
151  
        buf = new StringBuffer();
152  
      }*/
153  
    }
154  
155  
    public void appendText(String s, boolean outNotErr) {
156  
      //if (verbose) oldOut.println("Console appendText " + outNotErr + " " + quote(s));
157  
      buf.append(s);
158  
      du.trigger();
159  
    }
160  
  } // Console
161  
}

Author comment

Began life as a copy of #1001187

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001729
Snippet name: Show console for other process (developing)
Eternal ID of this version: #1001729/1
Text MD5: 473c7701bc3ad8b2b5b1afd6501138c4
Transpilation MD5: 1ff1acc301b000fc718556802cd175d0
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-10 19:15:54
Source code size: 5675 bytes / 161 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 597 / 733
Referenced in: [show references]