Package com.monkygames.wox.health.gui

Source Code of com.monkygames.wox.health.gui.BalanceBoardFinderGUI

/*
* See COPYING in top-level directory.
*/
package com.monkygames.wox.health.gui;

// === java imports === //
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// === miglayout imports === //
import net.miginfocom.swing.MigLayout;
// === wox imports === //
import com.monkygames.wox.health.io.*;
import com.monkygames.wox.health.data.Weight;

/**
* Attempts to find the scale.
* The callgraph should look like this<br>
* init -- ScaleThread -- turnOn
* @version 1.0
*/
public class BalanceBoardFinderGUI extends JFrame implements ActionListener{

// ============= Class variables ============== //
    /**
     * The root panel.
     **/
    private JPanel rootPanel;
    /**
     * Contains information to notify the user with.
     **/
    private JLabel infoLabel;
    /**
     * Used for the user to cancel or accept.
     **/
    private JButton actionB;
    /**
     * Used for notifying when the weight has been calc.
     **/
    private HealthGUI healthGUI;
    /**
     * Used for measuring the weight.
     **/
    private Scale scale;
    private boolean scaleFound = false;
// ============= Constructors ============== //
    public BalanceBoardFinderGUI(HealthGUI healthGUI){
  this.healthGUI = healthGUI;
  int w = 300;
  int h = 200;
  setSize(w,h);
  setTitle("Find Scale");
  setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

  setup();

  getContentPane().add(rootPanel);
    }
// ============= Public Methods ============== //
    /**
     * Initialises the gui and pops open.
     **/
    public void init(){
  scale = new Scale();
  actionB.setText("Cancel");
  infoLabel.setText("Turn On Wii Balance Board");
  updateGUI();
  setVisible(true);
  BalanceBoardFinderThread thread = new BalanceBoardFinderThread();
  thread.start();
    }
// ============= Protected Methods ============== //
// ============= Private Methods ============== //
    private void setup(){
  rootPanel = new JPanel(new MigLayout("fill"));
  infoLabel = new JLabel("");
  actionB = new JButton("Cancel");
  actionB.addActionListener(this);

  rootPanel.add(infoLabel,"dock north");
  rootPanel.add(actionB,"dock south");

    }
 
    /**
     * Handles repating the graphics.
     **/
    private void updateGUI(){
  rootPanel.repaint();
  rootPanel.revalidate();
    }
// ============= Implemented Methods ============== //
    public void actionPerformed(ActionEvent evt){
  Object src = evt.getSource();
  if(actionB.getText().equals("Ok") && scaleFound){
      healthGUI.setScale(scale)
  }else{
      // canceled it
      scale.shutdown();
  }
  setVisible(false);
    }
// ============= Extended Methods ============== //
// ============= Internal Classes ============== //
    public class BalanceBoardFinderThread extends Thread{
  public void run(){
      if(scale.initScale()){
    actionB.setText("Ok");
    // found scale
    infoLabel.setText("Scale Found");
    updateGUI();
    scaleFound = true;
      }else{
    // not found
    infoLabel.setText("Unable to connect to Scale");
    updateGUI();
    scaleFound = false;
      }
  }
    }
// ============= Static Methods ============== //

}
/*
* Local variables:
*  c-indent-level: 4
*  c-basic-offset: 4
* End:
*
* vim: ts=8 sts=4 sw=4 noexpandtab
*/ 
TOP

Related Classes of com.monkygames.wox.health.gui.BalanceBoardFinderGUI

TOP
Copyright © 2018 www.massapi.com. 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.