/*
   COPYRIGHT (C) 2010 - 2013 by Alexander Wait. All Rights Reserved.

   This class builds the planner GUI.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-05-05
*/



import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.*;



public class StudyPlannerGui extends JApplet
{
   private static final String copyright = "Copyright (c) 2012 by Alexander Wait - All Rights Reserved";

   private static final long serialVersionUID = 1L;
   
   
   static boolean isApplication = false; 
   
   static boolean isVisible = false;

   
   private static final int FRAME_SIZE_X = 580;
   
   private static final int FRAME_SIZE_Y = 500;


   //************************************** START INITIALISATION CODE **************************************//

   
   /**
    * Browser constructor.
    * ESCA-JAVA0166:
    */
   public void init()
   {
      if (!isApplication) 
      { 
         String copyrightParam = getParameter("copyright");
         
         if ((copyrightParam == null) || !copyrightParam.equals(copyright)) 
         {
            Message.showMessage("Invalid Copyright", "WARNING", "warning"); 
         }       
         
         else if (!getDocumentBase().getHost().equals(Domain.getDomain())) 
         {
            Message.showMessage("Unauthorised Applet Use", "ERROR", "error");
         }
        
         else
         {
            initialiser(); includeResizeEvent(); 
            
            setSize(FRAME_SIZE_X, FRAME_SIZE_Y);   
         }
      }
   }
 
   
   
   /**
    * Application constructor.
    */
   public StudyPlannerGui()
   {
      if (isApplication) 
      {
         initialiser(); 
         
         
         frame = new JFrame(); 
         
         
         frame.setMinimumSize(new Dimension(FRAME_SIZE_X, FRAME_SIZE_Y));
         
         frame.setSize(FRAME_SIZE_X, FRAME_SIZE_Y);
        
         frame.setLocationRelativeTo(null); 
         
         frame.setTitle("Planner Program"); 
         
         frame.add(contentPane); 
         
         
         setVisibility();
      }
   }
   
   
   
   /**
    * GUI initializer.
    * ESCA-JAVA0076:
    */
   private void initialiser()
   { 
      planner = new StudyPlanner(); 
      
      
      
      // Initialize content pane and layout.
      
      contentPane = getContentPane(); 
      
      contentPane.setLayout(new GridBagLayout());
      

      
      // Initialize check box GUI components.
      
      monday = new JCheckBox("MON"); monday.setFocusPainted(false);
      
      tuesday = new JCheckBox("TUE"); tuesday.setFocusPainted(false);
      
      wednesday = new JCheckBox("WED"); wednesday.setFocusPainted(false);
      
      thursday = new JCheckBox("THU"); thursday.setFocusPainted(false);
      
      friday = new JCheckBox("FRI"); friday.setFocusPainted(false);
      
      saturday = new JCheckBox("SAT"); saturday.setFocusPainted(false);
      
      sunday = new JCheckBox("SUN"); sunday.setFocusPainted(false); 
      
      
      
      // Initialize combo box GUI components.
      
      timeStartHour = new JComboBox(DateAndTime.returnHourChoices()); 
     
      timeStartHour.insertItemAt("H", 0); timeStartHour.setMaximumRowCount(2); 
      
      timeStartHour.setSelectedIndex(0); 
      
      
      timeStartMinute = new JComboBox(DateAndTime.returnMinuteChoices()); 
      
      timeStartMinute.insertItemAt("M", 0); timeStartMinute.setMaximumRowCount(2);
      
      timeStartMinute.setSelectedIndex(0); 
       
      
      timeFinishHour = new JComboBox(DateAndTime.returnHourChoices()); 
      
      timeFinishHour.insertItemAt("H", 0); timeFinishHour.setMaximumRowCount(2);
      
      timeFinishHour.setSelectedIndex(0); 
      
      
      timeFinishMinute = new JComboBox(DateAndTime.returnMinuteChoices()); 
      
      timeFinishMinute.insertItemAt("M", 0); timeFinishMinute.setMaximumRowCount(2);
      
      timeFinishMinute.setSelectedIndex(0); 
      
      
      activitySelect = new JComboBox(); activitySelect.insertItemAt("ID", 0);
      
      activitySelect.setMaximumRowCount(2); activitySelect.setSelectedIndex(0); 
      
      
      
      // Initialize text field GUI components.
      
      activityEntryField = new JTextField(); 
      
      activityEntryField.setHorizontalAlignment(JTextField.LEFT);
      
      activityEntryField.setFont(new Font("Serif", Font.BOLD, 13));
      
      activityEntryField.setBorder(BorderFactory.createTitledBorder("Activity"));
      
      
      
      // Initialize text area GUI components.
      
      resultDisplay = new JTextArea();
      
      resultDisplay.setEditable(false); 
      
      resultDisplay.setFont(new Font("Dialog", Font.BOLD, 13));
      
      resultDisplay.setBorder(BorderFactory.createEmptyBorder());
      
      
      
      // Initialize JPanel GUI components.
      
      weekDayContainer = new JPanel(); 
      
      weekDayContainer.setLayout(new FlowLayout());
      
      
      buttonPanel = new JPanel(); 
      
      buttonPanel.setLayout (new FlowLayout(FlowLayout.LEADING));
      
      buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      
      
      timeStartContainer = new JPanel(); 
      
      timeStartContainer.setBorder(BorderFactory.createTitledBorder("Start Time"));
      
      timeStartContainer.setLayout(new BoxLayout(timeStartContainer, BoxLayout.LINE_AXIS));
      
     
      timeFinishContainer = new JPanel();
      
      timeFinishContainer.setBorder(BorderFactory.createTitledBorder("Finish Time"));
      
      timeFinishContainer.setLayout(new BoxLayout(timeFinishContainer, BoxLayout.LINE_AXIS));
      
      
      activitySelectContainer = new JPanel();
      
      activitySelectContainer.setBorder(BorderFactory.createTitledBorder("Remove Activity"));
      
      activitySelectContainer.setLayout(new BoxLayout(activitySelectContainer, BoxLayout.LINE_AXIS));
      
      
      
      // Initialize scroll pane GUI components.
      
      scrollPane = new JScrollPane(resultDisplay, 
      
      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      
      
      
      // Initialize button GUI components.
      
      enter = new JButton(new ImageIcon(this.getClass().getResource
      (
         "files/images/WeeklyPlannerEnterNormal.png"))
      );
      
      
      enter.setRolloverIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/WeeklyPlannerEnterRollover.png"))
      );

      
      enter.setPressedIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/WeeklyPlannerEnterPressed.png"))
      );
      
      
      enter.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
      
      enter.addActionListener(new EnterButtonListener());
      
      
      
      // Add GUI components to containers.
      
      timeStartContainer.add(Box.createRigidArea(new Dimension(10, 0)));
      
      timeStartContainer.add(timeStartHour); 
      
      timeStartContainer.add(Box.createRigidArea(new Dimension(20, 0)));
      
      timeStartContainer.add(timeStartMinute);
      
      timeStartContainer.add(Box.createRigidArea(new Dimension(10, 0)));
      
      
      timeFinishContainer.add(Box.createRigidArea(new Dimension(10, 0)));
      
      timeFinishContainer.add(timeFinishHour);
      
      timeFinishContainer.add(Box.createRigidArea(new Dimension(20, 0)));
      
      timeFinishContainer.add(timeFinishMinute);
      
      timeFinishContainer.add(Box.createRigidArea(new Dimension(10, 0)));
      
      
      activitySelectContainer.add(Box.createRigidArea(new Dimension(100, 0)));
      
      activitySelectContainer.add(activitySelect);
      
      activitySelectContainer.add(Box.createRigidArea(new Dimension(100, 0)));
      
      
      // Add GUI components to JPanels.
      
      buttonPanel.add(enter); weekDayContainer.add(monday); 
      
      weekDayContainer.add(tuesday); weekDayContainer.add(wednesday); 
      
      weekDayContainer.add(thursday); weekDayContainer.add(friday); 
      
      weekDayContainer.add(saturday); weekDayContainer.add(sunday);
      

      
      // Method calls for GUI initialization.

      gridBagConstraints(); setColors(); setGraphicIcons();
   }
   
   
   
   /**
    * Sets the background color.
    */
   private void setColors()
   {
      contentPane.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      resultDisplay.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      weekDayContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      activityEntryField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      timeStartContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      timeFinishContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      activitySelectContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      activityEntryField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      buttonPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      monday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      tuesday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      wednesday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      thursday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      friday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      saturday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      sunday.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
   }
   
   
   
   /**
    * Sets icons for graphical elements.
    */
   private void setGraphicIcons()
   {
      monday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      monday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      monday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      monday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      tuesday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      tuesday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      tuesday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      tuesday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      wednesday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      wednesday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      wednesday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      wednesday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      thursday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      thursday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      thursday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      thursday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      friday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      friday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      friday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      friday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      saturday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      saturday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      saturday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      saturday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      sunday.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                     
      sunday.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));

      sunday.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));

      sunday.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
   }
   
   
   
   /**
    * Sets the grid bag layout.
    * ESCA-JAVA0076:
    */
   private void gridBagConstraints()
   {
   
      // Initialize grid bag layout of GUI.

      constraints = new GridBagConstraints();
      
      constraints.fill = GridBagConstraints.HORIZONTAL;
      
      
      
      // Grid bag constraints 1.
      
      
      constraints.insets = new Insets(10,0,0,0);
      
      
      constraints.ipadx = 500; 
      
      constraints.ipady = 130;

      constraints.gridwidth = 7;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 0;
      
      
      contentPane.add(scrollPane, constraints);
      
      
      
      // Grid bag constraints 2.
      
      constraints.insets = new Insets(0,0,0,0);
      
      
      constraints.ipadx = 25;  
      
      constraints.ipady = 30; 
     
      constraints.gridwidth = 7; 
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 

      constraints.gridx = 0; 
      
      constraints.gridy = 1;
      
      
      contentPane.add(weekDayContainer, constraints);
      
      
      
      // Grid bag constraints 3.

      constraints.insets = new Insets(0,0,30,0); 
      
      
      constraints.ipadx = 0;  
      
      constraints.ipady = 20;

      constraints.gridwidth = 7; 
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 2;
      
      
      contentPane.add(activityEntryField, constraints);
      
      
      
      // Grid bag constraints 4.
      
      constraints.insets = new Insets(0,0,0,0); 
      
      
      constraints.ipadx = 0;
      
      constraints.ipady = 5;
      
      constraints.gridwidth = 2; 
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 3;
      
      
      contentPane.add(timeStartContainer, constraints);
      
      
      
      // Grid bag constraints 5.
      
      constraints.insets = new Insets(0,0,0,0);
      
      
      constraints.ipadx = 0;
      
      constraints.ipady = 5;
      
      constraints.gridwidth = 2; 
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 

      constraints.gridx = 2; 
      
      constraints.gridy = 3;
      
      
      contentPane.add(timeFinishContainer, constraints);
      
      
      
      // Grid bag constraints 6.
      
      constraints.insets = new Insets(0,0,0,0);
      
      
      constraints.ipadx = 0;
      
      constraints.ipady = 5;
      
      constraints.gridwidth = 2;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 5; 
      
      constraints.gridy = 3;
      
      
      contentPane.add(activitySelectContainer, constraints);
      
      
      
      // Grid bag constraints 7.
      
      constraints.anchor = GridBagConstraints.PAGE_END;
      
      constraints.insets = new Insets(0,10,10,0);
      
      
      constraints.ipadx = 0; 
      
      constraints.ipady = 0;
      
      constraints.gridwidth = 7;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 1; 

      constraints.gridx = 0; 
      
      constraints.gridy = 4;
      
      
      contentPane.add(buttonPanel, constraints);   
   }
   
   
   //*************************************** END INITIALISATION CODE ***************************************//
   
   
   //************************************* START INTERFACE EVENT CODE **************************************//

   
   private class EnterButtonListener   
   implements ActionListener
   {

      public void actionPerformed(ActionEvent event)
      {
         if (!activitySelect.getSelectedItem().equals("ID"))
         {
            planner.removeActivity(Integer.parseInt
            (
               (String)activitySelect.getSelectedItem())
            );
            
            planner.timeConsumptionDay("All");
            
            appendToDisplay(); populateActivityBox();
         }
         
         
         if ((!activityEntryField.getText().equals("")) && isTimeSelected())
         {
            addActivities(); 
            
            planner.timeConsumptionDay("All");
            
            appendToDisplay(); populateActivityBox();
         }
      }
   }
   
   
   //************************************** END INTERFACE EVENT CODE ***************************************//
   
   
   //**************************************** START PUBLIC METHODS *****************************************//
   
   
   /**
    * Sets the visibility of the frame.
    */
   public void setVisibility()
   {
   
      if (isVisible) {frame.setVisible(true);}
      
      else {frame.setVisible(false);} 
   }
   
   
   
   /**
    * Displays or Hides contents of GUI.
    * @param shown
    */
   public void setContentDisplay(boolean shown)
   {
      contentPane.setVisible(shown);
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //**************************************** START PRIVATE METHODS ****************************************//
   
   
   /**
    * Returns true if all time settings have been set.
    * @return
    */
   private boolean isTimeSelected()
   {
      boolean hourStartSelected = !timeStartHour.getSelectedItem().equals("H");
      
      boolean minuteStartSelected = !timeStartMinute.getSelectedItem().equals("M");
      
      boolean hourFinishSelected = !timeFinishHour.getSelectedItem().equals("H");
      
      boolean minuteFinishSelected = !timeFinishMinute.getSelectedItem().equals("M");
      
      
      return (hourStartSelected && minuteStartSelected && hourFinishSelected && minuteFinishSelected);
   
   }
   
   
   
   /**
    * Appends the output to the display.
    */
   private void appendToDisplay()
   {
      resultDisplay.append(Tools.returnNewline(1));
       
       
      for (int i = 0; i < planner.returnActivityListLength(); i ++)
      {
         resultDisplay.append
         (
            Tools.returnNewline(1) + Tools.returnSpace(3) + "Activity ID (" + i + ") - " + 
         
            planner.returnActivity(i) + Tools.returnNewline(1)
         );
      }
       
       
      resultDisplay.append(Tools.returnNewline(1));
       
       
      resultDisplay.append
      (
         Tools.returnNewline(1) + Tools.returnSpace(3) + "The weekly time consumption is "  +  
       
         Math.round(planner.getHourConsumption()) + " hours." + Tools.returnNewline(2) +
          
          
         Tools.returnSpace(3) + "You have "  +  Math.round(DateAndTime.getHoursPerWeek() - 
         
         planner.getHourConsumption()) + " hours left to study in a week." + 
          
         Tools.returnNewline(1)
      ); 
   }
   
   
   
   /**
    * Adds the activities to the list.
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private void addActivities()
   {
      try
      {
         String timeStart = (String)timeStartHour.getSelectedItem() + ":" +
                  
         (String)timeStartMinute.getSelectedItem();
          
          
         String timeFinish = (String)timeFinishHour.getSelectedItem() + ":" +
                          
         (String)timeFinishMinute.getSelectedItem();
       
       
         if (monday.isSelected())
         {
            planner.addActivity("Monday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (tuesday.isSelected())
         {
            planner.addActivity("Tuesday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (wednesday.isSelected())
         {
            planner.addActivity("Wednesday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (thursday.isSelected())
         {
            planner.addActivity("Thursday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (friday.isSelected())
         {
            planner.addActivity("Friday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (saturday.isSelected())
         {
            planner.addActivity("Saturday", timeStart, timeFinish, activityEntryField.getText());
         }
          
         if (sunday.isSelected())
         {
            planner.addActivity("Sunday", timeStart, timeFinish, activityEntryField.getText());
         }
      }
      
      catch (Exception e)
      {System.out.println(Tools.thisPathAndLine() + e + "\n");}
   
   }
   
   
   
   /**
    * Populates the remove activity ID box.
    */
   private void populateActivityBox()
   {
      activitySelect.removeAllItems();
      
      activitySelect.insertItemAt("ID", 0);
      
      
      for (int i = 0; i < planner.returnActivityListLength(); i++)
      {
         activitySelect.addItem(Integer.toString(i));
      }
      
      
      activitySelect.setSelectedIndex(0);
   }
   
   
   
   /**
    * Window resize event.
    */
   private void includeResizeEvent()
   {
      this.addComponentListener 
      (
         new ComponentAdapter() 
         {
            public void componentResized(ComponentEvent e) 
            {
               appletDisplayHandler();
            }
          
         }
      ); 
   }
   
   
   
   /**
    * Controls the JApplet component visibility. 
    * ESCA-JAVA0266:
    */
   private void appletDisplayHandler()
   {
      final String ZOOM_WARNING = 
   
      "It appears that web pages in your browser are zoomed out. \n\n" +
      "In order to display the applet, your browser needs to be set \n" +
      "at its default zoom level of 100% or greater. \n\n" +
      "Sorry about that.";
   
   
      if ((getWidth() < FRAME_SIZE_X) || (getHeight() < FRAME_SIZE_Y))
      {
         contentPane.setVisible(false);  
      
         
         if (!zoomWarningShown) 
         {
            Message.showMessage(ZOOM_WARNING, "Browser zoom setting", "warning");
            
            zoomWarningShown = true;
         } 
      }
       
      else 
      {
         contentPane.setVisible(true);
      } 
   }
   
   
   //***************************************** END PRIVATE METHODS *****************************************//

   
   //********************************************** START MAIN *********************************************//
   
   
   /**
    * Main
    * @param a
    */
   public static void main(String[] a)
   {
      isApplication = true;
      
      isVisible = true;
      
      new StudyPlannerGui();
   }
   
   
   //*********************************************** END MAIN **********************************************//

   
   /**
    * ESCA-JAVA0007:
    */
   public JFrame frame;
   
   private JButton enter;
   private StudyPlanner planner;
   private Container contentPane;
   private JScrollPane scrollPane;
   private JTextArea resultDisplay;
   private boolean zoomWarningShown;
   private JTextField activityEntryField;
   private GridBagConstraints constraints;
   
   private JPanel timeStartContainer, timeFinishContainer, 
   buttonPanel, activitySelectContainer, weekDayContainer;
   
   private JCheckBox monday, tuesday, wednesday, thursday, friday, saturday, sunday;
   private JComboBox timeStartHour, timeStartMinute, timeFinishHour, timeFinishMinute, activitySelect;
   
   
   //********************************************** END CLASS **********************************************//
  
}


/*
   COPYRIGHT (C) 2010 - 2013 by Alexander Wait. All Rights Reserved.

   This class adds daily entries and activities to a schedule.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-05-06
*/



import java.util.ArrayList;



public class StudyPlanner 
{

   /**
    * Class Constructor.
    * ESCA-JAVA0057:
    */
   public StudyPlanner() {}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//
   
   
   /**
    * Adds an activity to the list.
    * @param day
    * @param startTime
    * @param finishTime
    * @param activity
    */
   public void addActivity(String day, String startTime, String finishTime, String activity)
   {
      activityList.add(day + "," + startTime + "," + finishTime + "," + activity);
     
   }
   
   
   
   /**
    * Finds the time consumption on a day.
    * @param day
    */
   public void timeConsumptionDay(String day)
   {
      setHourConsumption(0);
   
   
      String[] parts = null; String[] startTime = null; String[] endTime = null;

      
      for (int i = 0; i < activityList.size(); i ++)
      {
         parts = activityList.get(i).split(",");
         
         
         if (parts[0].equals(day) || day.equals("All"))
         {
            startTime = parts[1].split(":"); endTime = parts[2].split(":");
           
            
            hourConsumption += DateAndTime.timeDifferenceHours
            (
               Integer.parseInt(startTime[0]), Integer.parseInt(startTime[1]), 
                       
               Integer.parseInt(endTime[0]), Integer.parseInt(endTime[1])
            );
         }   
      }
   }
   
   
   
   /**
    * Returns an activity.
    * @param activityKey
    * @return
    */
   public String returnActivity(int activityKey)
   {
      return activityList.get(activityKey);
   }
   
   
   
   /**
    * Returns the activity list length.
    * @return
    */
   public int returnActivityListLength()
   {
      return activityList.size();
   }
   

   
   /**
    * Removes an activity from the list.
    * @param activityKey
    */
   public void removeActivity(int activityKey)
   {
      activityList.remove(activityKey);
   }
   
   
   
   /**
    * Returns the hour consumption.
    * @return
    */
   public double getHourConsumption()
   {
      return hourConsumption;
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //**************************************** START PRIVATE METHODS ****************************************//
   
   
   /**
    * Sets the hour consumption.
    * @param value
    */
   private void setHourConsumption(double value)
   {
      hourConsumption = value;
   }
   
   
   //***************************************** END PRIVATE METHODS *****************************************//
   
   
   private double hourConsumption;
   ArrayList activityList = new ArrayList();
   
   
   //********************************************** END CLASS **********************************************//

}


/*
   COPYRIGHT (C) 2010 -2013 by Alexander Wait. All Rights Reserved.

   This class defines colors and color methods.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-05-18
*/



public class ColorFunctions
{

   private static final int HEXADECIMAL_BASE = 16;
   
   private static final int COLOR_COMPONENT_RED = 250;
   
   private static final int COLOR_COMPONENT_GREEN = 250;
   
   private static final int COLOR_COMPONENT_BLUE = 250;
   
   
   
   private ColorFunctions() {}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//

   
   /**
    * Returns the color in hexadecimal format.
    * @param sliderValue
    * @return
    */
   public static String returnHexadecimalColor(int sliderValue)
   {
      String compFirst = ""; String compSecond = ""; int counter = -1;
 
      for (int i = 0; i < HEXADECIMAL_BASE; i ++)
      {
         compFirst = returnComponent(i);

          for (int j = 0; j < HEXADECIMAL_BASE; j ++)
          {
             compSecond = returnComponent(j); counter ++; 
  
             if (counter == sliderValue)
             {
                break;
             }
             
          }
  
          if (counter == sliderValue)
          {
             break;
          }
  
       }
   
       return 
       (
          "#" + compFirst + compSecond + compFirst + 
          
          compSecond + compFirst + compSecond
       );
   
   }
   
   
   
   /**
    * Return the set red color component 
    * for setting the programs background color. 
    * @return
    */
   public static int red()
   {
      return COLOR_COMPONENT_RED;
   }
   
   
   
   /**
    * Return the set green color component 
    * for setting the programs background color. 
    * @return
    */
   public static int green()
   {
      return COLOR_COMPONENT_GREEN;
   }
   
   
   
   /**
    * Return the set blue color component 
    * for setting the programs background color. 
    * @return
    */
   public static int blue()
   {
      return COLOR_COMPONENT_BLUE;
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//


   //**************************************** START PRIVATE METHODS ****************************************//
   
   
   /**
    * Returns the hexadecimal component.
    * ESCA-JAVA0076:
    * @param index
    * @return
    */
   private static String returnComponent(int index)
   {
      String component = "";
  
      switch (index)
      {
         case 10: component = "A"; break; case 11: component = "B"; break;  
         
         case 12: component = "C"; break; case 13: component = "D"; break; 
         
         case 14: component = "E"; break; case 15: component = "F"; break;
   
         default: component = Integer.toString(index); break;
      }
   
      return component;   
   }
   
 
   //***************************************** END PRIVATE METHODS *****************************************//

   
   //********************************************** END CLASS **********************************************//
   
}


/*
   COPYRIGHT (C) 2010 -2013 by Alexander Wait. All Rights Reserved.

   This class returns date and time and provides functions relating to time.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-04-18
*/



import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;



public class DateAndTime 
{

   private static final int DAY_INDEX = 2; 
   private static final int MONTH_INDEX = 1; 
   private static final int YEAR_INDEX = 0; 
   
   private static final int MILLISECONDS_PER_SECOND = 1000;
   private static final int SECONDS_PER_MINUTE = 60;
   private static final int MINUTES_PER_HOUR = 60;
   private static final int HOURS_PER_DAY = 24;
   
   private static final int DAYS_IN_WEEK = 7;
   private static final int DAYS_IN_YEAR = 365;
   private static final int WEEKS_IN_YEAR = 52;   
   private static final int MONTHS_IN_YEAR = 12;
   private static final int FORTNIGHTS_IN_YEAR = 26;
   
   private static Calendar now = Calendar.getInstance();
   
   public static enum Elements {YEAR, MONTH, DAY}
   

   private DateAndTime() {}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//
   
   
   /**
    * Tests and compares two dates.
    * @param dateFirst
    * @param dateSecond
    * @return
    */
   public static boolean dateComparison(String dateFirst, String dateSecond) 
   {
      String[] first = dateFirst.split("[-]", 0); 
      
      String[] second = dateSecond.split("[-]", 0);

      int firstDayInt = Integer.parseInt(first[DAY_INDEX]); 
      
      int firstMonthInt = Integer.parseInt(first[MONTH_INDEX]); 
      
      int firstYearInt = Integer.parseInt(first[YEAR_INDEX]); 
      
      int secondDayInt = Integer.parseInt(second[DAY_INDEX]); 
      
      int secondMonthInt = Integer.parseInt(second[MONTH_INDEX]); 
      
      int secondYearInt = Integer.parseInt(second[YEAR_INDEX]);

      return 
      
        compareDates(firstDayInt, firstMonthInt, 
        firstYearInt, secondDayInt, secondMonthInt, secondYearInt);
   }



   /**
    * Compares two dates to test if one date is more current than the other. 
    * @param fstDay
    * @param fstMonth
    * @param fstYear
    * @param sndDay
    * @param sndMonth
    * @param sndYear
    * @return
    */
   public static boolean compareDates(int fstDay, int fstMonth, 
   int fstYear, int sndDay, int sndMonth, int sndYear)
   {
      if (sndYear > fstYear) {return true;}

      else if (sndYear < fstYear) {return false;}

      else
      {
         if (sndMonth > fstMonth) {return true;}

         else if (sndMonth < fstMonth) {return false;}

         else 
         {
            if (sndDay >= fstDay) {return true;}

            else {return false;}
         }
      }
   }
   
   
   
   /**
    * Returns true if the time given is before current time.
    * @param hour
    * @param minute
    * @param second
    * @return
    */
   public static boolean isBeforeCurrentTime(int hour, int minute, int second)
   {
      
      if (returnHour() > hour) {return true;}
     
      else if (returnHour() < hour) {return false;}
  
      else 
      {
         if (returnMinute() > minute) {return true;}
         
         else if (returnMinute() < minute) {return false;}
       
         else 
         {
            if (returnSecond() > second) {return true;}
        
            else {return false;}
         }
      } 
  
   }
   
   
   
   /**
    * Returns true if the time to be tested is after the reference.
    * @param hour
    * @param minute
    * @param second
    * @param testHour
    * @param testMinute
    * @param testSecond
    * @return
    */
   public static boolean isAfterReferenceTime(int hour, int minute, 
   int second, int testHour, int testMinute, int testSecond)
   {
  
      if (hour < testHour) {return true;}
      
      else if (hour > testHour) {return false;}
   
      else 
      {
    
         if (minute < testMinute) {return true;}
         
         else if (minute > testMinute) {return false;}
         
         else 
         {
      
            if (second < testSecond) {return true;}
        
            else {return false;}
         }
      } 
  
   }
   
   
   
   /**
    * Finds the difference between two times in hours.
    * @param startHour
    * @param startMinute
    * @param endHour
    * @param endMinute
    * @return
    */
   public static double timeDifferenceHours(int startHour, 
   int startMinute, int endHour, int endMinute)
   {
      double endMinutes = endHour * MINUTES_PER_HOUR + endMinute;
      
      double startMinutes = startHour * MINUTES_PER_HOUR + startMinute;
   
      return ((endMinutes - startMinutes) / MINUTES_PER_HOUR);
   }

   
   
   /**
    * Returns true if a specified time is within one of a list of ranges.
    * @param startHour
    * @param startMinute
    * @param startSecond
    * @param finishHour
    * @param finishMinute
    * @param finishSecond
    * @param hour
    * @param minute
    * @param second
    * @param length
    * @return
    */
   public static boolean isOverlapped(ArrayList startHour, 
   ArrayList startMinute, ArrayList startSecond, 
   ArrayList finishHour, ArrayList finishMinute, 
   ArrayList finishSecond, int hour, int minute, 
   int second, int length)
   {

      boolean overlapped = false; 
   
      for (int i = 0; i < length; i ++)
      {
         if (isAfterReferenceTime
         (startHour.get(i), startMinute.get(i), 
         startSecond.get(i), hour, minute, second)
         
         && (!isAfterReferenceTime
         (finishHour.get(i), finishMinute.get(i), 
         finishSecond.get(i), hour, minute, second)))
         {
            overlapped = true;
            
         }
               
      }
      
     return overlapped;
     
   }
   
   
   
   /**
    * Tests if a year is a leap year.
    * @param year
    * @return
    */
   public static boolean isLeapYear(int year)
   {
      boolean leapYear = false;
      
      final int LEAP_DIVISOR_SHORT = 4;
      
      final int LEAP_DIVISOR_MIDDLE = 100;
      
      final int LEAP_DIVISOR_LONG = 400;
      
      
      if ((year % LEAP_DIVISOR_SHORT) == 0)
      {
         if ((year % LEAP_DIVISOR_MIDDLE) != 0)
         {
            leapYear = true;
         }
         
         if (((year % LEAP_DIVISOR_MIDDLE) == 0) 
         && ((year % LEAP_DIVISOR_LONG) == 0))
         {
            leapYear = true;
         }
         
      }
      
     
      return leapYear;

   }
   
   
   
   /**
    * Returns todays date.
    * @param includeTimeMask
    * @return
    */
   public static String returnTodaysDate(boolean includeTimeMask)
   {
      refreshCalendar(); now.getTime();
   
      
      String todaysDate = ""; String timeMask = "00:00:00";
      
      SimpleDateFormat date = new SimpleDateFormat("YYYY-MM-dd");
      
     
      if (includeTimeMask)
      {
         todaysDate = date.format(now.getTime()) + " " + timeMask;
      }
      
      else
      {
         todaysDate = date.format(now.getTime());
      }
      
      
      return todaysDate; 
   }
   
   
   
   /**
    * Returns a specific element of a date string.
    * @param date
    * @param component
    * @return
    */
   public static String returnSplitDate(String date, Elements component)
   {
      String element = null;
      
      
      String[] elementArray = date.split("-");
      
      
      if (component.equals(Elements.YEAR))
      {
         element = elementArray[0];
      }
      
      if (component.equals(Elements.MONTH))
      {
         element = elementArray[1];
      }
      
      if (component.equals(Elements.DAY))
      {
         element = elementArray[2];
      }

      
      return element;
      
   }
   

   
   /**
    * Returns the name of a month expressed as an integer.
    * ESCA-JAVA0076:
    * @param month
    * @return
    */
   public static String returnMonthName(int month)
   {
      String monthName = null;

      
      switch (month)
      {
         case 1: monthName = "January"; break;
         
         case 2: monthName = "February"; break;
         
         case 3: monthName = "March"; break;
         
         case 4: monthName = "April"; break;
         
         case 5: monthName = "May"; break;
           
         case 6: monthName = "June"; break;
         
         case 7: monthName = "July"; break;
         
         case 8: monthName = "August"; break;
         
         case 9: monthName = "September"; break;
         
         case 10: monthName = "October"; break;
         
         case 11: monthName = "November"; break;
         
         case 12: monthName = "December"; break;
      
         default: monthName = "Invalid Input"; break;
      }
      
      
      return monthName;
   }
   
   
   
   /**
    * Returns a list of dates.
    * @param year
    * @param heading
    * @return
    */
   public static String[] returnDateList(int year, String heading)
   {
   
      ArrayList list = new ArrayList();
     
      
      if (heading != null) {list.add(heading);}
      
      
      for (int i = 1; i <= MONTHS_IN_YEAR; i ++)
      {
         int bound = returndaysInMonth(i);
         
         
         if (isLeapYear(year) && (i == 2)) {bound ++;}
         
         
         for (int j = 1; j <= bound; j ++)
         {
            list.add(year + "-" + returnDigitMask(i, 2) + "-" + returnDigitMask(j, 2)); 
         }
        
      }
  
      
      String[] dates = new String[list.size()];
      
      list.toArray(dates);
      
      return dates;
   }
   
   
   
   /**
    * Returns the days of a specified month.
    * ESCA-JAVA0076:
    * @param month
    * @return
    */
   public static int returndaysInMonth(int month)
   {
      int days = -1; final int SHORT = 28; 
   
      final int MIDDLE = 30; final int LONG = 31;
  
      switch (month)
      {
         case 1: days = (LONG); break; case 2: days = (SHORT); break;
         
         case 3: days = (LONG); break; case 4: days = (MIDDLE); break;
         
         case 5: days = (LONG); break; case 6: days = (MIDDLE); break;
         
         case 7: days = (LONG); break; case 8: days = (LONG); break;
         
         case 9: days = (MIDDLE); break; case 10: days = (LONG); break;
         
         case 11: days = (MIDDLE); break; case 12: days = (LONG); break;  
      
         default: return days;         
      }
   
      return days;  
   }
   
   
   
   /**
    * Converts an integer to a mask.
    * ESCA-JAVA0076:
    * @param value
    * @param maxValueLength
    * @return
    */
   public static String returnDigitMask(int value, int maxValueLength)
   {     
      String digit = Integer.toString(value); String trailing = "";
      
      if (digit.length() == maxValueLength)
      {
         return digit;
      }
   
      else
      {
         for (int i = digit.length(); i < maxValueLength; i ++)
         {
            trailing += "0";
         }
     
         return (trailing + digit); 
      } 
   }
   
   
   
   /**
    * Returns the seconds elapsed in counter format (HH:MM:SS).
    * @param counter
    * @param millisecondCount
    * @return
    */
   public static String returnCounterTime(long counter, boolean millisecondCount)
   {
      String counterTime = ""; 
  
  
      setCounterHours((short)0); setCounterMinutes((short)0);
      
      setCounterSeconds((short)0); setCounterMilliseconds((short)0);
  
      
      final int DIGIT_LENGTH = 2; final double MILLIS_DIVISOR = 100;
      
   
      for (int i = 0; i < counter; i ++)
      {
         if (millisecondCount) {counterMilliseconds ++;} 
         
         else {counterSeconds ++;}
         
         
         if (counterMilliseconds == MILLISECONDS_PER_SECOND) 
         
         {setCounterMilliseconds((short)0); counterSeconds ++;}
         
         
         if (counterSeconds == SECONDS_PER_MINUTE) 
         
         {setCounterSeconds((short)0); counterMinutes ++;}
         
         if (counterMinutes == MINUTES_PER_HOUR) 
         
         {setCounterMinutes((short)0); counterHours ++;}
      }
      
      
      if (millisecondCount) 
      {
         counterTime = ":" + (int)Math.floor(getCounterMilliseconds() / MILLIS_DIVISOR);
      }
      
      
      counterTime = 
      (
         returnDigitMask(getCounterHours(), DIGIT_LENGTH) + ":" +
             
         returnDigitMask(getCounterMinutes(), DIGIT_LENGTH) + ":" +
     
         returnDigitMask(getCounterSeconds(), DIGIT_LENGTH) + counterTime
      );
      
      
      return counterTime;
      
   }
   
   
   
   /**
    * Returns the formatted time (24 hour or standard)
    * @param twentyFourHour
    * @return
    */
   public static String returnFormattedTime(boolean twentyFourHour)
   {
      refreshCalendar(); String time = ""; 
      
      
      DateFormat full = new SimpleDateFormat("HH:mm:ss");
      
      DateFormat standard = new SimpleDateFormat("h:mm:ss");
      
      
      if (twentyFourHour) {time = full.format(now.getTime());}
      
      else {time = standard.format(now.getTime());}
  
        
      return time;   
   }
   
   
   
   /**
    * Returns the day at the start of the given year.
    * ESCA-JAVA0076:
    * @param year
    * @return
    */
   public static int returnStartDayAsInt(int year)
   {
      Calendar cal = new GregorianCalendar(year, Calendar.JANUARY, 1);
  
      return (cal.get(Calendar.DAY_OF_WEEK));
   }
   
   
   
   /**
    * Returns the day at the start of the given year.
    * ESCA-JAVA0076:
    * @param year
    * @return
    */
   public static int returnEndDayAsInt(int year)
   {
      Calendar cal = new GregorianCalendar(year, Calendar.DECEMBER, 31);
  
      return (cal.get(Calendar.DAY_OF_WEEK));
   }
   
   
   
   /**
    * Returns the specific day of week as an integer.
    * 1 = Sunday, 2 = Monday, 3 = Tuesday ...
    * ESCA-JAVA0076:
    * @param year
    * @param month
    * @param day
    * @return
    */
   public static int returnDayOfWeekAsInt(int year, int month, int day)
   {
      Calendar cal = null; 

      
      switch (month)
      {
         case 1: cal = new GregorianCalendar(year, Calendar.JANUARY, day); break;
         
         case 2: cal = new GregorianCalendar(year, Calendar.FEBRUARY, day); break;
         
         case 3: cal = new GregorianCalendar(year, Calendar.MARCH, day); break;
         
         case 4: cal = new GregorianCalendar(year, Calendar.APRIL, day); break;
         
         case 5: cal = new GregorianCalendar(year, Calendar.MAY, day); break;  
        
         case 6: cal = new GregorianCalendar(year, Calendar.JUNE, day); break;
         
         case 7: cal = new GregorianCalendar(year, Calendar.JULY, day); break;
         
         case 8: cal = new GregorianCalendar(year, Calendar.AUGUST, day); break;
         
         case 9: cal = new GregorianCalendar(year, Calendar.SEPTEMBER, day); break;
         
         case 10: cal = new GregorianCalendar(year, Calendar.OCTOBER, day); break;
         
         case 11: cal = new GregorianCalendar(year, Calendar.NOVEMBER, day); break;
         
         case 12: cal = new GregorianCalendar(year, Calendar.DECEMBER, day); break;
         
         
         default: return (-1);
      
      }
      
  
      return (cal.get(Calendar.DAY_OF_WEEK));
   }
   
  
   
   /**
    * Returns a list of years between the given 
    * parameter and the current year.
    * @param year
    * @return
    */
   public static String[] returnYearChoices(int year)
   {
     
      int difference = Math.abs(returnYear() - year);
      
      String[] choices = new String[difference +1];
 
  
      if (year < returnYear())
      {
         for (int i = 0; i <= difference; i ++)
         {
            choices[i] = Integer.toString(year + i);
         }
      }
      
      if (year > returnYear())
      {
         for (int i = 0; i <= difference; i ++)
         {
            choices[i] = Integer.toString(returnYear() + i); 
         }
      }
      
      return choices;
      
   }
   

   
   /**
    * Returns a list for seconds.
    * @return
    */
   public static String[] returnSecondChoices()
   {
      
     
      String[] secondList = new String[SECONDS_PER_MINUTE];
   
      for (int i = 0; i < SECONDS_PER_MINUTE; i ++)  
      {
         secondList[i] = Integer.toString(i);
      
      }
      
      return secondList;
   }
   
   
   
   /**
    * Returns a list for minutes.
    * @return
    */
   public static String[] returnMinuteChoices()
   {
      
     
      String[] minuteList = new String[MINUTES_PER_HOUR];
   
      for (int i = 0; i < MINUTES_PER_HOUR; i ++)  
      {
         minuteList[i] = Integer.toString(i);
      
      }
      
      return minuteList;
   }
   
   
   
   /**
    * Returns a list for hours.
    * @return
    */
   public static String[] returnHourChoices()
   {
      String[] hourList = new String[HOURS_PER_DAY];
   
      for (int i = 0; i < HOURS_PER_DAY; i ++)  
      {
         hourList[i] = Integer.toString(i);
      
      }
      
      return hourList;
   }
   
   
   
   /**
    * Returns the current year.
    * @return
    */
   public static int returnYear()
   {
      refreshCalendar(); 

      return (now.get(Calendar.YEAR));
   }
   
   
   
   /**
    * Returns the current year.
    * @return
    */
   public static int returnMonth()
   {
      refreshCalendar(); 
 
      return (now.get(Calendar.MONTH) + 1);
   }
    
   
   
   /**
    * Returns the current year.
    * @return
    */
   public static int returnDay()
   { 
      refreshCalendar(); 
   
      return (now.get(Calendar.DATE));
   }
   
   
   
   /**
    * Returns the hour in double digits.
    * @return
    */
   public static String returnHourDouble()
   {
      return returnDigitMask(returnHour(), 2);
   }
   
   
   
   /**
    * Returns the minute in double digits.
    * @return
    */
   public static String returnMinuteDouble()
   {
      return returnDigitMask(returnMinute(), 2);
   }
   
   
   
   /**
    * Returns the second in double digits.
    * @return
    */
   public static String returnSecondDouble()
   {
      return returnDigitMask(returnSecond(), 2);
   }
   
   
 
   /**
    * Returns the hour.
    * @return
    */
   public static int returnHour()
   {
      refreshCalendar(); 
   
      DateFormat hours = new SimpleDateFormat("HH");
      
      return (Integer.parseInt(hours.format(now.getTime())));
   }

   
   
   /**
    * Returns the minutes.
    * @return
    */
   public static int returnMinute()
   {
      refreshCalendar(); 
   
      DateFormat minutes = new SimpleDateFormat("mm");
      
      return (Integer.parseInt(minutes.format(now.getTime())));
   }
   
   
   
   /**
    * Returns the seconds.
    * @return
    */
   public static int returnSecond()
   {
      refreshCalendar();  
   
      DateFormat seconds = new SimpleDateFormat("ss");
      
      return (Integer.parseInt(seconds.format(now.getTime())));
   }
   
   
   
   /**
    * Returns the current stage of the day as AM or PM.
    * @return
    */
   public static String returnAmOrPm()
   {
      refreshCalendar(); 
     
      DateFormat ampm = new SimpleDateFormat("a");
        
      return (ampm.format(now.getTime()));   
   }
   
   
   
   /**
    * Returns the days in a year.
    * @param year
    * @return
    */
   public static int returnDays(int year)
   {
      if (DateAndTime.isLeapYear(year))
      {
         return getDaysLeapYear();
      }
      
      else
      {
         return DateAndTime.getDaysNormalYear();
      }   
   }
   
   
   
   /**
    * Refreshes the calendar.
    */
   public static void refreshCalendar()
   {
      now = Calendar.getInstance();
   }
   
  
   
   /**
    * Sets the counter hours.
    * @param value
    */
   public static void setCounterHours(short value) {counterHours = value;}
   
   
   
   /**
    * Sets the counter minutes.
    * @param value
    */
   public static void setCounterMinutes(short value) {counterMinutes = value;}
   
   
   
   /**
    * Sets the counter seconds.
    * @param value
    */
   public static void setCounterSeconds(short value) {counterSeconds = value;}
   
   
   
   /**
    * Sets the counter milliseconds.
    * @param value
    */
   public static void setCounterMilliseconds(short value) {counterMilliseconds = value;}
   
   
   
   /**
    * Returns the counter hours.
    * @return
    */
   public static short getCounterHours() {return counterHours;}
   
   
   
   /**
    * Returns the counter minutes.
    * @return
    */
   public static short getCounterMinutes() {return counterMinutes;}
   
   
   
   /**
    * Returns the counter seconds.
    * @return
    */
   public static short getCounterSeconds() {return counterSeconds;}
   
   
   
   /**
    * Returns the counter milliseconds.
    * @return
    */
   public static short getCounterMilliseconds() {return counterMilliseconds;}
   
   
   
   /**
    * Returns the days in a week.
    * @return
    */
   public static int getDaysInWeek() {return DAYS_IN_WEEK;}

   
   /**
    * Returns the days in a year.
    * @return
    */
   public static int getDaysNormalYear() {return DAYS_IN_YEAR;}
   
   
   /**
    * Returns the days in a year.
    * @return
    */
   public static int getDaysLeapYear() {return (DAYS_IN_YEAR + 1);}
   
   
   /**
    * Returns the weeks in a year.
    * @return
    */
   public static int getWeeksInYear() {return WEEKS_IN_YEAR;}
   
   
   /**
    * Returns the fort-nights in a year.
    * @return
    */
   public static int getFortnightsInYear() {return FORTNIGHTS_IN_YEAR;}
   
   
   /**
    * Returns the months in a year.
    * @return
    */
   public static int getMonthsInYear() {return MONTHS_IN_YEAR;}
   
   
   /**
    * Returns the seconds per minute.
    * @return
    */
   public static int getSecondsPerMinute() {return SECONDS_PER_MINUTE;}
   
   
   /**
    * Returns the seconds per minute.
    * @return
    */
   public static int getHoursPerWeek() {return HOURS_PER_DAY * DAYS_IN_WEEK;}
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   
   private static short counterHours, counterMinutes, counterSeconds, counterMilliseconds;
   
   
   //********************************************** END CLASS **********************************************//
 
}


/*
   COPYRIGHT (C) 2010 - 2013 by Alexander Wait. All Rights Reserved.

   This class returns the domain attributes.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-07-06
*/



public class Domain 
{
  
   private static final String DOMAIN = "javaika.com";

   private static final boolean RUN_LOCAL = false; 
   
   private static final boolean prefix = true;
   
   private static final String PORT = "80";
   
   
   private Domain() {}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//
   
   
   /**
    * Returns the domain name.
    * @return
    */
   public static final String getDomain()
   {
      if (prefix)
      {
         return ("www." + DOMAIN);
      }
      
      else
      {
         return (DOMAIN);
      }
   }
   
   
   
   /**
    * Returns the port number.
    * @return
    */
   public static final String getPort()
   {
      if (RUN_LOCAL)
      {
         return (":" + PORT);
         
      }
      
      else {return ("");} 
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //********************************************** END CLASS **********************************************//

}


/*
   COPYRIGHT (C) 2010 - 2013 by Alexander Wait. All Rights Reserved.

   This class displays message dialogs.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2011-07-18
*/



import javax.swing.*;



public class Message
{

   private Message(){}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//


   /**
    * Displays a message dialog.
    * @param text
    * @param heading
    * @param type 
    */
   public static void showMessage(String text, String heading, String type)
   {
      new JOptionPane(); Object[] options = {}; 

      if (type.equals("error"))
      {
         JOptionPane.showOptionDialog(null, text, heading,  
         JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, options, null);
      }

      if (type.equals("information"))
      {
         JOptionPane.showOptionDialog(null, text, heading, 
         JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, null);
      }

      if (type.equals("warning"))
      {
         JOptionPane.showOptionDialog(null, text, heading, 
         JOptionPane.YES_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null);
      }

      if (type.equals("question"))
      {
         JOptionPane.showOptionDialog(null, text, heading, 
         JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
      }
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //********************************************** END CLASS **********************************************//
   
}


/*
   COPYRIGHT (C) 2010 - 2013 by Alexander Wait. All Rights Reserved.

   This class provides handy tools.

   @site http://www.javaika.com
   @author Alexander Wait
   @version 2012-02-01
*/



public class Tools 
{

   private static final int EXCEPTION_LINE_BEAK = 2;
   
   
   private Tools() {}
   
   
   //**************************************** START PUBLIC METHODS *****************************************//


   /**
    * This method returns the line number and path where it's called.
    * The syntax new Exception().getStackTrace()[0].getLineNumber() 
    * will only give the current line number of the source file.
    * @return
    */
   public static String thisPathAndLine()
   {
   
      String lineAndPath = ""; String stackTrace = "";
 
      stackTrace = new Exception().getStackTrace()[1].toString();
      
      
      for (int i = stackTrace.length()-1; i >= 0; i --)
      {
         if (stackTrace.charAt(i) == ')') {continue;} 
        
         else if (stackTrace.charAt(i) == '(') {break;}
        
         else {lineAndPath = (stackTrace.charAt(i) + lineAndPath);}
      }
         
      return lineAndPath + returnNewline(EXCEPTION_LINE_BEAK);
      
   }
   
   
   
   /**
    * Delays execution.
    * @param length
    */
   public static void delay(long length) 
   {
      for (long i = 0; i < length; i ++) {}
   }
   
  
 
   /**
    * This method returns a space.
    * @param length
    * @return
    */
   public static String returnSpace(int length)
   {
      String space = "";
      
      
      for (int i = 0; i < length; i ++)
      {
         space += " ";
      }
      
      return space;
   }
   
   
   
   /**
    * Assigns newlines to a string.
    * @param lines
    * @return
    */
   public static String returnNewline(int lines)
   {
      String newline = "";
      
      
      for (int i = 0; i < lines; i++)
      {
         newline += "\n";
      }
      
      
      return newline;
   
   }
   
   
   
   /**
    * Returns the users desktop path.
    * @return
    */
   public static String returnDesktopPath()
   {
      return (System.getProperty("user.home") + "/Desktop").replace("\\", "/") + "/"; 
   }
   

   //***************************************** END PUBLIC METHODS ******************************************//

   
   //********************************************** END CLASS **********************************************//
   
}