Exemplo n.º 1
0
  /**
   * removes comments, processes commands drawbot shouldn't have to handle.
   *
   * @param line command to send
   * @return true if the robot is ready for another command to be sent.
   */
  public boolean ProcessLine(String line) {
    // tool change request?
    String[] tokens = line.split("\\s");

    // tool change?
    if (Arrays.asList(tokens).contains("M06") || Arrays.asList(tokens).contains("M6")) {
      for (int i = 0; i < tokens.length; ++i) {
        if (tokens[i].startsWith("T")) {
          JOptionPane.showMessageDialog(
              null, "Please change to tool #" + tokens[i].substring(1) + " and click OK.");
        }
      }
      // still ready to send
      return true;
    }

    // end of program?
    if (tokens[0] == "M02" || tokens[0] == "M2") {
      Halt();
      return false;
    }

    // other machine code to ignore?
    if (tokens[0].startsWith("M")) {
      Log("<font color='pink'>" + line + "</font>\n");
      return true;
    }

    // contains a comment?  if so remove it
    int index = line.indexOf('(');
    if (index != -1) {
      String comment = line.substring(index + 1, line.lastIndexOf(')'));
      line = line.substring(0, index).trim();
      Log("<font color='grey'>* " + comment + "</font\n");
      if (line.length() == 0) {
        // entire line was a comment.
        return true; // still ready to send
      }
    }

    // send relevant part of line to the robot
    SendLineToRobot(line);

    return false;
  }
Exemplo n.º 2
0
  public Container CreateContentPane() {
    // Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    // the preview panel
    previewPane = new DrawPanel();
    previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);

    // status bar
    statusBar = new StatusBar();
    Font f = statusBar.getFont();
    statusBar.setFont(f.deriveFont(Font.BOLD, 15));
    Dimension d = statusBar.getMinimumSize();
    d.setSize(d.getWidth(), d.getHeight() + 30);
    statusBar.setMinimumSize(d);

    // layout
    Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT);
    split.add(previewPane);
    split.add(logPane);
    split.setDividerSize(8);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split, BorderLayout.CENTER);

    // open the file
    if (recentFiles[0].length() > 0) {
      OpenFileOnDemand(recentFiles[0]);
    }

    // connect to the last port
    ListSerialPorts();
    if (Arrays.asList(portsDetected).contains(recentPort)) {
      OpenPort(recentPort);
    }

    return contentPane;
  }