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).

!747
!awt {
!actionListener {
!pcall {

m {
  static S vmName = "This is a JavaX VM."; // Use any vM
  
  p {
    new Console(new String[0]);
  }
  
  !include #1000943 // DelayedUpdate

  static class Console extends WindowAdapter implements WindowListener, ActionListener {
    PipedInputStream pin=new PipedInputStream();
    PipedInputStream pin2=new PipedInputStream();
    PipedInputStream pin3=new PipedInputStream();
    Thread reader, reader2;
    boolean quit;
  
    JFrame frame;
    JTextArea textArea;
    JTextField tfInput;
    StringBuffer buf = new StringBuffer();
    JButton buttonclear, buttonkill, buttonrestart, buttonduplicate, buttonstacktrace;
    String[] args;

    final DelayedUpdate du = new DelayedUpdate(new Runnable() {
      public void run() { try {

        textArea.append(buf.substring(textArea.getText().length()));

      } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});

    public Console(final String[] args) ctex {
      this.args = args;
      // create all components and add them
      frame=new JFrame(args.length == 0 ? "Console Bot Console" : "Console Bot Console - " + join(" ", args));

		/*Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2));
		int x=(int)(frameSize.width/2);
		int y=(int)(frameSize.height/2);
		frame.setBounds(x,y,frameSize.width,frameSize.height);*/

      // put in right-bottom corner
      Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
      int w = 550, h = 200;
      frame.setBounds(r.x+r.width-w, r.y+r.height-h, w, h);

      textArea=new JTextArea();
      textArea.setEditable(false);
      buttonclear = new JButton("clear");
      buttonkill = new JButton("kill");
      buttonrestart = new JButton("restart");
      buttonduplicate = new JButton("duplicate");
      buttonstacktrace = new JButton("status");
      buttonstacktrace.setToolTipText("Show threads & stack traces.");

      JPanel buttons = new JPanel(new GridLayout(1, 5));
      buttons.add(buttonclear);
      buttons.add(buttonkill);
      buttons.add(buttonrestart);
      buttons.add(buttonduplicate);
      buttons.add(buttonstacktrace);

      tfInput = new JTextField();
      tfInput.addActionListener(actionListener {
        S line = tfInput.getText();
        sendToLocalBot(vmName, "send line * to system.in", line);
        tfInput.setText("");
      });
      
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(new JScrollPane(textArea), BorderLayout.CENTER);
      panel.add(tfInput, BorderLayout.SOUTH);
      
      frame.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
          tfInput.requestFocus();
        }
      });
      
      frame.getContentPane().setLayout(new BorderLayout());
      frame.getContentPane().add(panel, BorderLayout.CENTER);
      frame.getContentPane().add(buttons, BorderLayout.SOUTH);
      frame.setVisible(true);
      
      //frame.addWindowListener(this); // disabled for now
      buttonclear.addActionListener(this);
      buttonkill.addActionListener(this);
      buttonrestart.addActionListener(this);
      buttonduplicate.addActionListener(this);
      buttonstacktrace.addActionListener(this);

      quit=false; // signals the Threads that they should exit
      
      if (args.length != 0) {
        print("Starting title updater");
        new Thread("Console Title Updater :)") {
          public void run() {
            if (args.length != 0) {
              int i = 0;
              while (i < args.length && !isSnippetID(args[i])) ++i;
              print("Getting title for " + args[i]);
              String title = getSnippetTitle(args[i]);
              print("Title: " + title);
              if (title != null && title.length() != 0)
                frame.setTitle(title + " [Output]");
            }
          }
        }.start();
      }
      
      System.setIn(pin3);
      
    }

    public synchronized void windowClosed(WindowEvent evt)
    {
      /*quit=true;
      this.notifyAll(); // stop all threads
      try { reader.join(1000);pin.close();   } catch (Exception e){}
      try { reader2.join(1000);pin2.close(); } catch (Exception e){}
      System.exit(0);*/
    }

    public synchronized void windowClosing(WindowEvent evt)
    {
      frame.setVisible(false); // default behaviour of JFrame
      frame.dispose();
    }

    public synchronized void actionPerformed(ActionEvent evt) {
      /*if (evt.getSource() == buttonkill) {
        print("Console: Kill button pressed!");
        // TODO: give threads time to finish, e.g. reportToChat?
        System.exit(0);
      } else if (evt.getSource() == buttonrestart) {
        print("Console: Restart button pressed.");
        nohupJavax(smartJoin(args));
        System.exit(0);
      } else if (evt.getSource() == buttonduplicate) {
        print("Console: Duplicate button pressed.");
        nohupJavax(smartJoin(args));
      } else if (evt.getSource() == buttonstacktrace) {
        listUserThreadsWithStackTraces();
      } else {
        textArea.setText("");
        buf = new StringBuffer();
      }*/
    }

    public void appendText(String s, boolean outNotErr) {
      //if (verbose) oldOut.println("Console appendText " + outNotErr + " " + quote(s));
      buf.append(s);
      du.trigger();
    }
  } // Console
}

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: 701 / 863
Referenced in: #1001731 - Show console for other process (simple version)
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)