Пример #1
0
  /**
   * Starts the program
   *
   * @param args the standard arguments. If "competition" is one of them, then the SmartDashboard
   *     will be in competition mode
   * @see main#inCompetition() inCompetition()
   */
  public static void main(final String[] args) {
    // Present a loading bar (it will only show up if this is going slowly)
    final ProgressMonitor monitor =
        new ProgressMonitor(
            null, "Loading SmartDashboard", "Initializing internal code...", 0, 1000);

    // Search the filesystem for extensions (49%)
    FileSniffer.findExtensions(monitor, 0, 490);

    ArgParser argParser = new ArgParser(args, true, true, new String[] {"ip"});
    inCompetition = argParser.hasFlag("competition");
    boolean customIP = false;
    if (argParser.hasValue("ip")) {
      Robot.setHost(argParser.getValue("ip"));
      customIP = true;
    }

    final boolean useTeamNumber = !customIP;
    try {
      SwingUtilities.invokeAndWait(
          new Runnable() {

            public void run() {
              try {

                monitor.setProgress(500);
                monitor.setNote("Setting Theme");
                try {
                  for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                      UIManager.setLookAndFeel(info.getClassName());
                    }
                  }
                } catch (Exception e) {
                }

                // Initialize GUI
                DashboardFrame frame = new DashboardFrame(inCompetition);

                monitor.setProgress(600);
                monitor.setNote("Getting Team Number");
                IntegerProperty team = frame.getPrefs().team;
                while (team.getValue() <= 0) {
                  team.setValue(JOptionPane.showInputDialog("Input Team Number"));
                }
                if (useTeamNumber) {
                  Robot.setTeam(frame.getPrefs().team.getValue());
                }

                frame.pack();
                frame.setVisible(true);

                monitor.setProgress(750);
                monitor.setNote("Loading From Save");

                // Load
                File file = new File(frame.getPrefs().saveFile.getValue());
                if (file.exists()) {
                  frame.load(file.getPath());
                }

                monitor.setProgress(1000);

              } catch (Exception e) {
                e.printStackTrace();

                System.exit(1);
              }
            }
          });
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(2);
    }
  }