예제 #1
0
  public AboutPanel() {
    setTitle("About Panel");
    ImageIcon img = new ImageIcon("icons/preferences.jpg");
    setIconImage(img.getImage());
    Container contentPane = getContentPane();
    contentPane.setLayout(new MigLayout());

    setBackground(Color.GRAY);

    int style1 = Font.CENTER_BASELINE;
    Font font = new Font("Arial", style1, 13);

    about = new JLabel();
    about.setFont(font);
    String key = userPrefs.getRegistrationKey();
    if (key == null || key.length() == 0) {
      userPrefs.setRegistrationKey("Community Edition");
    }
    about.setText("<html>WattzAp Community Edition<br/><br/>Version 2.5.1<br/>19th August 2015");
    add(about, "alignx right, span");

    debug = new JCheckBox("Enable Debugging");
    if (userPrefs.isDebug()) {
      debug.setSelected(true);
    } else {
      debug.setSelected(false);
    }
    debug.addActionListener(this);
    add(debug);

    Dimension d = new Dimension(550, 300);
    this.setPreferredSize(d);
    pack();
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  }
예제 #2
0
  public FitImporter(String fileName) {
    FileInputStream fitFile = null;

    try {
      Decode decode = new Decode();
      MesgBroadcaster broadcaster = new MesgBroadcaster(decode);
      decode.addListener((MesgDefinitionListener) this);
      decode.addListener((MesgListener) this);

      fitFile = new FileInputStream(fileName);
      broadcaster.run(fitFile);
      // calculate powers here???
      if (!isPower) {

        for (Telemetry point : data) {
          int p =
              (int)
                  Power.getPower(userPrefs.getTotalWeight(), point.getGradient(), point.getSpeed());

          if (p > userPrefs.getMaxPower() && (p > (last.getPower() * 2.0))) {
            // We are above FTP and power has doubled, remove power
            // spikes
            p = (int) (last.getPower() * 1.05);
          }
          if (p > (userPrefs.getMaxPower() * 4)) {
            // power is 4 x FTP, this is a spike
            p = last.getPower();
          }
          if (p > 0) {
            point.setPower(p);
          } else {
            point.setPower(0);
          }
        } // for
      }
    } catch (Exception fex) {

      try {
        fitFile.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      fex.printStackTrace();
    } finally {
      if (fitFile != null) {
        try {
          fitFile.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
예제 #3
0
  public static void main(String[] args) {
    // Debug
    Level level = setLogLevel();
    // hard coded for debugging, not important, normally libvlc is found on
    // lib path
    NativeLibrary.addSearchPath("libvlc", ".");
    // configure the appender
    String PATTERN = "%r [%t] %p %c %x %m%n";
    String logFile = userPrefs.getWD() + "/logfile.txt";
    FileAppender fileAppender;
    try {
      fileAppender = new FileAppender(new PatternLayout(PATTERN), logFile);
      fileAppender.setThreshold(level);
      fileAppender.activateOptions();
      // add appender to any Logger (here is root)
      Logger.getRootLogger().addAppender(fileAppender);
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } // create appender

    // Turn on Debug window
    if (userPrefs.isDebug()) {
      SwingAppender appender = new SwingAppender(); // create appender
      // configure the appender

      appender.setLayout(new PatternLayout(PATTERN));
      appender.setThreshold(level);
      appender.activateOptions();
      // add appender to any Logger (here is root)
      Logger.getRootLogger().addAppender(appender);
    }

    logger.info("Setting log level => " + level.toString());

    logger.info("Database Version " + userPrefs.getDBVersion());
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }

      EventQueue.invokeLater(new Main());
    } catch (Exception e) {
      // catch everything and log
      logger.error(e.getLocalizedMessage());
      userPrefs.shutDown();
    }
  }
예제 #4
0
  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    logger.debug(command);
    if ("Enable Debugging".equals(command)) {
      userPrefs.setDebug(debug.isSelected());
    }

    this.invalidate();
    this.validate();
    setVisible(true);
  }
예제 #5
0
  @Override
  public void run() {
    MainFrame frame = new MainFrame();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    // frame.setSize(screenSize.width, screenSize.height-100);
    frame.setBounds(userPrefs.getMainBounds());

    // Must be declared above Odometer
    // AdvancedSpeedCadenceListener scListener = null;
    JPanel odo = null;
    try {
      HashMap<String, AntListener> antListeners = new HashMap<String, AntListener>();
      int id = userPrefs.getSCId();
      if (id > 0) {
        AntListener listener = new AdvancedSpeedCadenceListener();
        antListeners.put(listener.getName(), listener);
      }

      id = userPrefs.getSpeedId();
      if (id > 0) {
        AntListener listener = new SpeedListener();
        antListeners.put(listener.getName(), listener);
      }

      id = userPrefs.getCadenceId();
      if (id > 0) {
        AntListener listener = new CadenceListener();
        antListeners.put(listener.getName(), listener);
      }

      id = userPrefs.getHRMId();
      if (id > 0) {
        AntListener listener = new HeartRateListener();
        antListeners.put(listener.getName(), listener);
      }

      id = userPrefs.getPowerId();
      if (id > 0) {
        AntListener listener = new PowerListener();
        antListeners.put(listener.getName(), listener);
      }
      new Ant(antListeners).register();
      odo = new AntOdometer();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          frame,
          "ANT+ " + e.getMessage(),
          userPrefs.messages.getString("warning"),
          JOptionPane.WARNING_MESSAGE);
      logger.error("ANT+ " + e.getMessage());
      new DummySpeedCadenceListener();
      userPrefs.setAntEnabled(true);
      odo = new Odometer();
    }

    // Performs an isregister check, be careful if we move below AboutPanel
    VideoPlayer videoPlayer = new VideoPlayer(frame, odo);
    try {
      videoPlayer.init();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          frame,
          e.getMessage(),
          userPrefs.messages.getString("warning"),
          JOptionPane.INFORMATION_MESSAGE);
      logger.info(e.getMessage());

      videoPlayer = null;
    }

    MigLayout layout = new MigLayout("center", "[]10px[]", "");
    Container contentPane = frame.getContentPane();
    contentPane.setBackground(Color.BLACK);
    contentPane.setLayout(layout);

    // create view
    new Map(frame);
    Profile profile = new Profile(screenSize);
    profile.setVisible(false);

    // Menu Bar
    new MenuBar(frame);

    frame.add(profile, "cell 0 1, grow");
    // by default add to telemetry frame
    frame.add(odo, "cell 0 2, grow");

    ControlPanel cp = new ControlPanel();
    frame.add(cp, "cell 0 3");

    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    // frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setVisible(true);
  }