Skip to content

Commit

Permalink
- Documentation updates
Browse files Browse the repository at this point in the history
- Removed redundant elapsed time code from Timer class
  • Loading branch information
Justin Cagle committed May 25, 2020
1 parent c1d73f0 commit ec46fa9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
10 changes: 8 additions & 2 deletions src/AudioEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
import java.io.File;
import java.io.IOException;


/**
* Self-contained audio engine to play an audio clip in the background
* @author Justin Cagle
* @author jcagle2001@msn.com
* @version 1.0
* {@link} https://www.geeksforgeeks.org/play-audio-file-using-java/
*/
public class AudioEngine {
private static Clip clip;

// current status of clip
private static String status = "Not Initialized";

AudioInputStream inputStream;
static String filePath = "StimShot.wav";
protected static String filePath = "StimShot.wav";

/**
* Constructor
Expand Down
13 changes: 4 additions & 9 deletions src/Timer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*
/**
* A simple timer to track how long it's been since we last played a tone
* @author Justin Cagle
* @author jcagle2001@msn.com
* @version 1.0
*/
public class Timer {
long startTime;
Expand All @@ -26,14 +29,6 @@ public void startTimer(){
* @return amount of time since the timer was last started.
*/
public long getElapsedTime() {
return calculateElapsedTime();
}

/**
* Private method that performs the elapsed time calculation
* @return a whole second representation of the elapsed time
*/
private long calculateElapsedTime(){
return elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
}

Expand Down
47 changes: 19 additions & 28 deletions src/TrayGUI.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* Creates the Tray Icon UI for interacting with the program
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;

/**
* Creates the Tray Icon UI for interacting with the program
* @author Justin Cagle
* @author jcagle2001@msn.com
* @version 1.0
*/
public class TrayGUI {
private JPopupMenu menu;
private TrayIcon icon;
Expand Down Expand Up @@ -39,18 +42,13 @@ public class TrayGUI {
createComponents();
}

/**
* Creates the icon image for the tray
* @return formatted icon image
*/
// Creates the icon image for the tray
private Image createImage(){
return new ImageIcon(trayIconPath, "Stim").getImage();
}

/**
* Heavy lifting for creating the UI. Creates and sets the components in the tray menu. Also adds event listeners
* to respond to menu selections.
*/
// Heavy lifting for creating the UI. Creates and sets the components in the tray menu. Also adds event listeners
// to respond to menu selections.
private void createComponents(){
// Create menu components
JMenu setInterval = new JMenu("Repeat Interval");
Expand Down Expand Up @@ -85,6 +83,7 @@ private void createComponents(){
menu.addSeparator();
menu.add(exit);

// Add components to submenu
intervalList.add(interval30sec);
intervalList.add(interval45sec);
intervalList.add(interval1min);
Expand All @@ -100,6 +99,7 @@ private void createComponents(){

initMenu();

// Create Event Listeners
exit.addActionListener(e -> {
isTimeToExit = true;
sysTray.remove(icon);
Expand Down Expand Up @@ -141,49 +141,40 @@ public void mouseReleased(MouseEvent e) {
});
}

/**
* Initializes the menu
*/
// Initializes the menu
private void initMenu(){


try{
sysTray.add(icon);
} catch(AWTException awt){
new ErrorMessage(awt.getMessage(), "Error setting Icon to Tray");
}
}

/**
* Checks to see if it's time to clean up and exit the program loop
* @return Boolean
*/
public Boolean getIsTimeToExit(){
return isTimeToExit;
}

/**
* Deselects all Interval menu selections that are not the currently selected one
* @param selectedItem Item to remain selected
*/
// Deselects all Interval menu selections that are not the currently selected one
private void alterAllOtherStatesInterval(JCheckBoxMenuItem selectedItem){
for(JCheckBoxMenuItem item : intervalList){
item.setSelected(item.getText().equals(selectedItem.getText()));
}
setIntervalOrFile(selectedItem);
}

/**
* Deselects all Tone menu selections that are not the currently selected one
* @param selectedItem Item to remain selected
*/
// Deselects all Tone menu selections that are not the currently selected one
private void alterAllOtherStatesTone(JCheckBoxMenuItem selectedItem){
for(JCheckBoxMenuItem item : toneList){
item.setSelected(item.getText().equals(selectedItem.getText()));
}
setIntervalOrFile(selectedItem);
}

/**
* Sets parameters based on user selection
* @param selection selection to set.
*/
// Sets parameters based on user selection
private void setIntervalOrFile(JCheckBoxMenuItem selection){
switch(selection.getText()){
case "30 seconds" : interval = 30; break;
Expand Down

0 comments on commit ec46fa9

Please sign in to comment.