Example #1
0
  /**
   * Opens a file. If the file can be opened, get a drawing time estimate, update recent files list,
   * and repaint the preview tab.
   *
   * @param filename what file to open
   */
  public void LoadGCode(String filename) {
    CloseFile();

    try {
      Scanner scanner = new Scanner(new FileInputStream(filename));
      linesTotal = 0;
      gcode = new ArrayList<String>();
      try {
        while (scanner.hasNextLine()) {
          gcode.add(scanner.nextLine());
          ++linesTotal;
        }
      } finally {
        scanner.close();
      }
    } catch (IOException e) {
      Log("<span style='color:red'>File could not be opened.</span>\n");
      RemoveRecentFile(filename);
      return;
    }

    previewPane.setGCode(gcode);
    fileOpened = true;

    EstimateDrawTime();
    UpdateRecentFiles(filename);
    Halt();
  }
Example #2
0
 // find all available serial ports for the settings->ports menu.
 public String[] ListSerialPorts() {
   @SuppressWarnings("unchecked")
   Enumeration<CommPortIdentifier> ports =
       (Enumeration<CommPortIdentifier>) CommPortIdentifier.getPortIdentifiers();
   ArrayList<String> portList = new ArrayList<String>();
   while (ports.hasMoreElements()) {
     CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
     if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
       portList.add(port.getName());
     }
   }
   portsDetected = (String[]) portList.toArray(new String[0]);
   return portsDetected;
 }