Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.michael.tech.api.console;
- import com.michael.tech.api.Time;
- import java.awt.Toolkit;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Michael Risher
- */
- public class RunConsole extends javax.swing.JFrame {
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private static javax.swing.JTextArea console;
- public static javax.swing.JTextField input;
- private javax.swing.JScrollPane jScrollPane1;
- // End of variables declaration//GEN-END:variables
- public static boolean waitForUser = false;
- public static boolean waitingForResponse = false;
- private static boolean EchoTime = true;
- private boolean echoClassPath = false;
- private String classPathName = "";
- /**
- * Creates new Console
- */
- public RunConsole() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jScrollPane1 = new javax.swing.JScrollPane();
- console = new javax.swing.JTextArea();
- input = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- console.setBackground(new java.awt.Color(102, 102, 102));
- console.setColumns(20);
- console.setEditable(false);
- console.setForeground(new java.awt.Color(255, 51, 51));
- console.setLineWrap(true);
- console.setRows(5);
- jScrollPane1.setViewportView(console);
- input.setBackground(new java.awt.Color(102, 102, 102));
- input.setForeground(new java.awt.Color(255, 51, 51));
- input.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- inputActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(input)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(input, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void inputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputActionPerformed
- toConsole(input.getText());
- if(waitingForResponse){
- waitForUser = false;
- }
- input.setText("");
- }//GEN-LAST:event_inputActionPerformed
- /*public static void main(String args[]) {
- // *
- // * Set the Nimbus look and feel
- // *
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- //
- // * If Nimbus (introduced in Java SE 6) is not available, stay with the
- // * default look and feel. For details see
- // * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Run.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Run.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Run.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Run.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- // *
- // * Create and display the form
- // *
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Run().setVisible(true);
- //new TestScreen().setVisible(true);
- }
- });
- }*/
- public static void startConsole(){
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(RunConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(RunConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(RunConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(RunConsole.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- /*
- * Create and display the form
- */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new RunConsole().setVisible(true);
- }
- });
- }
- public static String getConsole(){
- return console.getText();
- }
- /**
- * Set the entire console's text
- * @param s
- */
- public static void setConsole(String s){
- console.setText(s);
- }
- /**
- * add a line to the console using the time stamp
- * @param s
- */
- private static void addConsole(String s){
- //String o = console.getText();
- console.setText( ( console.getText().isEmpty()) ? s : (console.getText() + "\n" + s) );
- }
- /**
- * add a line to the console with the time stamp
- * @param s
- */
- public static void toConsole(String s, boolean timeStamp, boolean classPath, String className){
- if(s.startsWith("/")){
- doCommand(s);
- return;
- }
- Time t = new Time();
- t.getSYSPrint();
- String time = "[" + t.toMilitary() + "] ";
- if(EchoTime || timeStamp){
- addConsole(time + s);
- }
- else if(classPath){
- addConsole(className);
- }
- else{
- addConsole(s);
- }
- }
- public static void toConsole(String s, boolean classPath, String className){
- toConsole(s, false, classPath, className);
- }
- public static void toConsole(String s, boolean timeStamp){
- toConsole(s, timeStamp, false, null);
- }
- public static void toConsole(String s){
- toConsole(s, false, false, null);
- }
- private static void doCommand(String s){
- if(s.equalsIgnoreCase("/copy")){
- setClipboardContents(getConsole());
- addConsole("Copied all of the above text");
- }
- if(s.equalsIgnoreCase("/echo")){
- EchoTime = !EchoTime;
- }
- }
- private static void setClipboardContents(String s){
- StringSelection stringSelection = new StringSelection( s );
- Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
- clip.setContents(stringSelection, null);
- }
- public static String waitForInput(){
- waitForUser = true;
- waitingForResponse = true;
- String s = null;
- while(waitForUser){
- s = input.getText();
- }
- waitingForResponse = false;
- return s;
- }
- public String getClassPathName() {
- return classPathName;
- }
- public void setClassPathName(String classPathName) {
- this.classPathName = classPathName;
- }
- public void setEchoClassPath(boolean echoClassPath) {
- this.echoClassPath = echoClassPath;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement