Package net.sf.robocode.ui.dialog

Examples of net.sf.robocode.ui.dialog.ConsoleDialog


  }

  public void compile(String directory, String fileName) {
    fileName = FileUtil.quoteFileName(fileName);

    ConsoleDialog console;

    if (editor != null) {
      console = new ConsoleDialog(editor, "Compiling", false);
    } else {
      console = new ConsoleDialog();
    }
    console.setSize(500, 400);
    console.setText("Compiling...\n");
    WindowUtil.centerShow(editor, console);

    try {
      StringBuffer command = new StringBuffer(compilerBinary).append(' ').append(compilerOptions).append(' ').append(compilerClassPath).append(' ').append(
          fileName);

      Logger.logMessage("Compile command: " + command);

      ProcessBuilder pb = new ProcessBuilder(command.toString().split(" "));

      pb.redirectErrorStream(true);
      pb.directory(FileUtil.getCwd());
      Process p = pb.start();

      // The waitFor() must done after reading the input and error stream of the process
      console.processStream(p.getInputStream());
      p.waitFor();

      if (p.exitValue() == 0) {
        console.append("Compiled successfully.\n");
        console.setTitle("Compiled successfully.");
      } else {
        console.append("Compile Failed (" + p.exitValue() + ")\n");
        console.setTitle("Compile failed.");
      }
    } catch (IOException e) {
      console.append("Unable to compile!\n");
      console.append("Exception was: " + e.toString() + "\n");
      console.append("Does " + compilerBinary + " exist?\n");
      console.setTitle("Exception while compiling");
    } catch (InterruptedException e) {
      // Immediately reasserts the exception by interrupting the caller thread itself
      Thread.currentThread().interrupt();

      console.append("Compile interrupted.\n");
      console.setTitle("Compile interrupted.");
    }

    Integer codesize = CodeSizeCalculator.getDirectoryCodeSize(new File(directory));
    if (codesize != null) {
      String weightClass = null;

      if (codesize >= 1500) {
        weightClass = "MegaBot  (codesize >= 1500 bytes)";
      } else if (codesize > 750) {
        weightClass = "MiniBot  (codesize < 1500 bytes)";
      } else if (codesize > 250) {
        weightClass = "MicroBot (codesize < 750 bytes)";
      } else {
        weightClass = "NanoBot  (codesize < 250 bytes)";
      }
      StringBuilder sb = new StringBuilder();

      sb.append("\n\n---- Codesize ----\n");
      sb.append("Codesize: ").append(codesize).append(" bytes\n");
      sb.append("Robot weight class: ").append(weightClass).append('\n');
     
      console.append(sb.toString());
    }
  }
View Full Code Here


    return FileUtil.quoteFileName(javalib);
  }

  public boolean configureCompiler(RobocodeEditor editor) {
    ConsoleDialog console = new ConsoleDialog(editor, "Setting up compiler", false);

    console.setSize(500, 400);
    console.getOkButton().setEnabled(false);
    console.setText("Please wait while Robocode sets up a compiler for you...\n\n");
    WindowUtil.centerShow(editor, console);

    console.append("Setting up compiler\n");
    console.append("Java home is " + System.getProperty("java.home") + "\n\n");

    String compilerName = "Java Compiler (javac)";
    String compilerBinary = "javac";
    String compilerOptions = "-deprecation -g -source 1.6 -encoding UTF-8";

    boolean javacOK = testCompiler(compilerName, compilerBinary, console);
    boolean ecjOK = false;

    if (javacOK) {
      int rc = JOptionPane.showConfirmDialog(editor,
          "Robocode has found a working javac (Java Compiler) on this system.\nWould you like to use it?\n"
          + "(If you click No, Robocode will use the build-in Eclipse Compiler for Java (ECJ))",
          "Confirm javac",
          JOptionPane.YES_NO_OPTION,
          JOptionPane.QUESTION_MESSAGE);

      if (rc == JOptionPane.NO_OPTION) {
        javacOK = false;
      }
    }
   
    if (!javacOK) {
      compilerName = "Eclipse Compiler for Java (ECJ)";
      compilerBinary = "java -cp compilers/ecj.jar org.eclipse.jdt.internal.compiler.batch.Main";

      ecjOK = testCompiler("Eclipse Compiler for Java (ECJ)", compilerBinary, console);
    }

    boolean compilerOK = javacOK || ecjOK;

    if (compilerOK) {
      console.append("\nCompiler has been set up successfully.\nClick OK to continue.\n");

    } else {
      final String errorText = "Could not set up a working compiler for Robocode.\n"
          + "Please consult the console window for errors.\n\n"
          + "For help with this, please post to Help forum here:\n"
          + "http://sourceforge.net/projects/robocode/forums/forum/116459";
     
      console.append("\nUnable to set up a working compiler for Robocode.\n");

      JOptionPane.showMessageDialog(editor, errorText, "Error", JOptionPane.ERROR_MESSAGE);

      compilerBinary = "";
      compilerOptions = "";
    }

    getCompilerProperties().setRobocodeVersion(ContainerBase.getComponent(IVersionManagerBase.class).getVersion());
    getCompilerProperties().setCompilerBinary(compilerBinary);
    getCompilerProperties().setCompilerOptions(compilerOptions);
    getCompilerProperties().setCompilerClasspath(COMPILER_CLASSPATH);
    saveCompilerProperties();

    console.scrollToBottom();
    console.getOkButton().setEnabled(true);

    return compilerOK;
  }
View Full Code Here

TOP

Related Classes of net.sf.robocode.ui.dialog.ConsoleDialog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.