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

   This class builds the area volume 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 java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;



public class AreaVolumeGui extends JApplet implements FocusListener
{
   private static final String copyright = "Copyright (c) 2012 by Alexander Wait - All Rights Reserved";
   
   private static final long serialVersionUID = 1L;
   
   
   private static final int FRAME_SIZE_X = 350;
   
   private static final int FRAME_SIZE_Y = 300;

   
   static boolean isApplication = false; 
   
   static boolean isVisible = false;
   
   
   //************************************** 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(); 
            
            setJMenuBar(menuBar); setSize(FRAME_SIZE_X, FRAME_SIZE_Y);
         }
      }
   }
 
   
   
   /**
    * Application constructor.
    */
   public AreaVolumeGui()
   {
      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("Area Volume Program"); 
         
         frame.setJMenuBar(menuBar); 
         
         frame.add(contentPane); 
         
         
         setVisibility(); 
      }
 
   }
   
   
   
   /**
    * GUI initializer.
    * ESCA-JAVA0076:
    */
   private void initialiser()
   {      
      circle = new Circle(); 
      
      
      // Initialize content pane and layout.
      
      contentPane = getContentPane(); 
      
      contentPane.setLayout(new GridBagLayout());
      
      
      
      // Initialize text area GUI components.
      
      resultDisplay = new JTextArea(); 
      
      resultDisplay.setEditable(false);
      
      resultDisplay.setFont(new Font("Dialog", Font.BOLD, 13));
      
      resultDisplay.setBorder(BorderFactory.createEtchedBorder());
      
     
      
      // Initialize text field GUI components.
      
      firstDimensionField = new JTextField(); 
      
      firstDimensionField.addFocusListener(this);
      
      firstDimensionField.setHorizontalAlignment(JTextField.CENTER);
      
      firstDimensionField.setFont(new Font("Serif", Font.BOLD, 13));

      
      secondDimensionField = new JTextField(); 
      
      secondDimensionField.addFocusListener(this);
      
      secondDimensionField.setHorizontalAlignment(JTextField.CENTER);
      
      secondDimensionField.setFont(new Font("Serif", Font.BOLD, 13));   

      
      thirdDimensionField = new JTextField();  
      
      thirdDimensionField.addFocusListener(this);
      
      thirdDimensionField.setHorizontalAlignment(JTextField.CENTER); 
      
      thirdDimensionField.setFont(new Font("Serif", Font.BOLD, 13)); 



      // Initialize button GUI components.
      
      run = new JButton(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeCalculateNormal.png"))
      );
      
      
      run.setRolloverIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeCalculateRollover.png"))
      );

      
      run.setPressedIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeCalculatePressed.png"))
      );
      
      
      run.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
      
      run.addActionListener(new RunButtonListener());
      
      
      clear = new JButton(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeClearNormal.png"))
      );
      
      
      clear.setRolloverIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeClearRollover.png"))
      );

      
      clear.setPressedIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/AreaVolumeClearPressed.png"))
      );
      
      
      clear.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
      
      clear.addActionListener(new ClearButtonListener());
      
      
      
      // Initialize JPanel GUI components.
      
      buttonPanel = new JPanel(); 
      
      buttonPanel.setLayout (new FlowLayout(FlowLayout.LEADING));
      
      buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      
      
      
      // Add GUI components to JPanels.
      
      buttonPanel.add(run); buttonPanel.add(clear);
  
      
      
      // Method calls for GUI initialization.

      gridBagConstraints(); setMenuComponents(); setMenu(); setColors(); 
   }
   
   
   
   /**
    * Sets the background color.
    */
   private void setColors()
   {
      contentPane.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      buttonPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      firstDimensionField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      secondDimensionField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      thirdDimensionField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      resultDisplay.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
   }
   
   
   
   /**
    * Sets the menu bar components.
    */
   private void setMenuComponents()
   {
      setSelectionElements(); createAttributeMenu(); createDimensionMenu();
      
      menuBar = new JMenuBar(); menuBar.add(createShapeMenu()); 
      
      menuBar.add(attributeMenu); menuBar.add(dimensionMenu);
   }
   
   
   
   /**
    * 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 = 95; 
      
      constraints.ipady = 0;

      constraints.gridwidth = 1;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 0;
      
      
      contentPane.add(firstDimensionField, constraints);
      
      
      
      // Grid bag constraints 2.
      
      constraints.insets = new Insets(10,0,0,0);
      
      
      constraints.ipadx = 95; 
      
      constraints.ipady = 0;

      constraints.gridwidth = 1;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 0; 
      
      constraints.gridx = 1; 
      
      constraints.gridy = 0;
      
      
      contentPane.add(secondDimensionField, constraints);
      
      
      
      // Grid bag constraints 3.
      
      constraints.insets = new Insets(10,0,0,0);
      
      
      constraints.ipadx = 95; 
      
      constraints.ipady = 0;

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

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

      constraints.gridwidth = 3;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 1; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 2;
      
      
      contentPane.add(buttonPanel, constraints);
   }
   
   
   //*************************************** END INITIALISATION CODE ***************************************//
   
   
   //************************************* START INTERFACE EVENT CODE **************************************//
  
   
   /**
    * Run button listener. 
    * ESCA-JAVA0076:
    */
   private class RunButtonListener implements ActionListener
   {

      public void actionPerformed(ActionEvent event)
      {   
         calculationController(); 
         
         outputResult();
      }
   }
   
   
   
   /**
    * Clear button listener. 
    * ESCA-JAVA0076:
    */
   private class ClearButtonListener implements ActionListener
   {

      public void actionPerformed(ActionEvent event)
      {
         resultDisplay.setText(null);
         
         firstDimensionField.setText(null);
         
         secondDimensionField.setText(null);
         
         thirdDimensionField.setText(null);
         
         
         setResult(0);
      }
      
   }

   
   
   /**
    * Shape radio listener. 
    * ESCA-JAVA0076:
    */
   private class ShapeRadioHandler implements ItemListener
   {
      
      public void itemStateChanged(ItemEvent event)
      {
         if (circleRadio.isSelected())
         {
            attributeMenu.add(circumferenceRadio);
            
            attributeMenu.add(areaRadio);
         }
      }
      
   }
   
   
   
   /**
    * Attribute radio listener. 
    * ESCA-JAVA0076:
    */
   private class AttributeRadioHandler implements ItemListener
   {
      
      public void itemStateChanged(ItemEvent event)
      {
         dimensionMenu.removeAll(); 
    
         
         if (circumferenceRadio.isSelected())
         { 
            dimensionMenu.add(radiusCheck);
         }
         
         else if (areaRadio.isSelected())
         {
         
            dimensionMenu.add(circumferenceCheck);
            
            dimensionMenu.add(radiusCheck);
         }
      }
      
   }
   
   
   
   /**
    * Dimension box listener. 
    * ESCA-JAVA0076:
    */
   private class DimensionBoxHandler implements ItemListener
   {
      
      public void itemStateChanged(ItemEvent event)
      {
         if (radiusCheck.isSelected())
         { 
            firstDimensionField.setText("Radius");
         }
         
         else if (circumferenceCheck.isSelected())
         {
            firstDimensionField.setText("Circumference");  
         }
      }
      
   }
   
   
   
   public void focusGained(FocusEvent e) 
   {
      if (firstDimensionField.hasFocus())
      {
         firstDimensionField.setText(null);
      }
      
      if (secondDimensionField.hasFocus())
      {
         secondDimensionField.setText(null);
      }
      
      if (thirdDimensionField.hasFocus())
      {
         thirdDimensionField.setText(null);
      }
      
   }
   
   

   public void focusLost(FocusEvent e) 
   {
      if (firstDimensionField.getText().length() == 0)
      {
         if (radiusCheck.isSelected()) 
         {
            firstDimensionField.setText("Radius");
         }
         
         if (circumferenceCheck.isSelected())
         {
            firstDimensionField.setText("Circumference");
         }
      }
   }
   

   //************************************** 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)
   {
      menuBar.setVisible(shown);
   
      contentPane.setVisible(shown);
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //**************************************** START PRIVATE METHODS ****************************************//
   
   
   /**
    * Controls the calculation.
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private void calculationController()
   {
      try
      {
         if (circleRadio.isSelected())
         {
            double valueOne = Double.parseDouble(firstDimensionField.getText());
       
       
            if (circumferenceRadio.isSelected())
            {
               if (radiusCheck.isSelected())
               {
                  setResult(circle.circumferenceCircleRadius(valueOne));
               }
             
               setAttribute("Circumference");
            }
          
            if (areaRadio.isSelected())
            {
               if (radiusCheck.isSelected())
               {
                  setResult(circle.areaCircleRadius(valueOne));
               }
            
               if (circumferenceCheck.isSelected())
               {
                  setResult(circle.areaCircleCircumference(valueOne));
               }
            
               setAttribute("Area");
            }
          
            setShape("Circle");
         }
      }
      
      catch (Exception e)
      {System.out.println(Tools.thisPathAndLine() + e + "\n");}
      
   }
   
   
   
   /**
    * Outputs the result to the screen.
    */
   private void outputResult()
   {
      resultDisplay.setText
      (
         Tools.returnNewline(1) + Tools.returnSpace(3) + "The " + 
      
         getAttribute() + " of this " + getShape() + " is " +
          
         Tools.returnNewline(2) + Tools.returnSpace(3) + 
          
         Double.toString(getResult())
      );
   }
   
   
   
   /**
    * Sets the selection elements.
    */
   private void setSelectionElements()
   {
      groupSecond = new ButtonGroup(); groupThird = new ButtonGroup();
   

      circumferenceRadio = new JRadioButtonMenuItem("Circumference");
  
      areaRadio = new JRadioButtonMenuItem("Area");
      
      
      groupSecond.add(circumferenceRadio); groupSecond.add(areaRadio);
      
      
      radiusCheck = new JCheckBoxMenuItem("Radius");
      
      circumferenceCheck = new JCheckBoxMenuItem("Circumference");
      
      
      groupThird.add(radiusCheck); groupThird.add(circumferenceCheck);

      
      circumferenceRadio.addItemListener(new AttributeRadioHandler());
      
      areaRadio.addItemListener(new AttributeRadioHandler());
      
      
      radiusCheck.addItemListener(new DimensionBoxHandler());
      
      circumferenceCheck.addItemListener(new DimensionBoxHandler());
   }
   
   

   /**
    * Adds a shape menu. 
    * @return menu
    */
   private JMenu createShapeMenu()
   {

      JMenu menu = new JMenu("Shape"); 
      
      circleRadio = new JRadioButtonMenuItem("Circle");
      
      circleRadio.addItemListener(new ShapeRadioHandler());
     
      
      groupFirst = new ButtonGroup();
      
      groupFirst.add(circleRadio);

      
      menu.add(circleRadio);
      
      return menu;
   }
   
   
   
   /**
    * Sets the menu bar components.
    */
   private void setMenu()
   {
   
      attributeMenu.add(circumferenceRadio);
       
      attributeMenu.add(areaRadio); 
       
       
      dimensionMenu.add(circumferenceCheck);
      
      dimensionMenu.add(radiusCheck);

       
      circleRadio.setSelected(true);  
      
      areaRadio.setSelected(true);
      
      radiusCheck.setSelected(true);
      
      
      setShape("Circle");
      
      setAttribute("Area");
   
   }
   
   
   
   /**
    * Adds a attribute menu.
    */
   private void createAttributeMenu()
   {
      attributeMenu = new JMenu("Attribute");  
   }
   
   
   
   /**
    * Adds a dimension menu.
    */
   private void createDimensionMenu()
   {
      dimensionMenu = new JMenu("Dimension"); 
   }
   
   
   
   /**
    * Sets the type of shape.
    * @param value
    */
   private void setShape(String value)
   {
      shape = value;
   }
   
   
   
   /**
    * Sets the shape attribute.
    * @param value
    */
   private void setAttribute(String value)
   {
      attribute = value;
   }
   
   
   
   /**
    * Sets the result attribute.
    * @param value
    */
   private void setResult(double value)
   {
      result = value;
   }
   
   
   
   /**
    * Gets the type of shape.
    * @return
    */
   private String getShape()
   {
      return shape;
   }
   
   
   
   /**
    * Gets the type of attribute.
    * @return
    */
   private String getAttribute()
   {
      return attribute;
   }
   
   
   
   /**
    * Gets the result attribute.
    * @return
    */
   private double getResult()
   {
      return result;
   }
   
   
   
   /**
    * 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); menuBar.setVisible(false);
      
         
         if (!zoomWarningShown) 
         {
            Message.showMessage(ZOOM_WARNING, "Browser zoom setting", "warning");
            
            zoomWarningShown = true;
         } 
      }
       
      else 
      {
         contentPane.setVisible(true); menuBar.setVisible(true);
      } 
   }
   
   
   //***************************************** END PRIVATE METHODS *****************************************//

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

   
   /**
    * ESCA-JAVA0007:
    */
   public JFrame frame;

   private String shape;
   private Circle circle;
   private double result;
   private JMenuBar menuBar;
   private String attribute;
   private JButton run, clear;
   private JPanel buttonPanel;
   private Container contentPane;
   private JTextArea resultDisplay;
   private boolean zoomWarningShown;
   private GridBagConstraints constraints;
   private JMenu attributeMenu, dimensionMenu;
   private ButtonGroup groupFirst, groupSecond, groupThird;
   private JCheckBoxMenuItem radiusCheck, circumferenceCheck;
   private JRadioButtonMenuItem circleRadio, circumferenceRadio, areaRadio;
   private JTextField firstDimensionField, secondDimensionField, thirdDimensionField;
   

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


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

   This class calculates circumference, area and volume of circular shapes.

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



public class Circle 
{

   //**************************************** START PUBLIC METHODS *****************************************//


   /**
    * Returns the circumference of a circle given radius.
    * @param radius
    * @return
    */
   public double circumferenceCircleRadius(double radius)
   {
      return (2 * Math.PI * radius);
   }



   /**
    * Returns the area of a circle given the radius.
    * @param radius
    * @return
    */
   public double areaCircleRadius(double radius)
   {
      return (Math.PI * Math.pow (radius, 2));
   }
      
  
   
   /**
    * Returns the area of a circle given the circumference.
    * @param circumference
    * @return
    */
   public double areaCircleCircumference(double circumference)
   {
      return (Math.pow (circumference, 2) / (4 * Math.PI));
   }
  
   
   //********************************************** SEPARATOR **********************************************//
       
   
   /**
    * Returns the surface area of a cylinder given radius and height.
    * @param radius
    * @param height
    * @return     
    */
   public double saCylinderRadiusAndHeight(double radius, double height)
   {
      return (2 * Math.PI * Math.pow(radius, 2) + circumferenceCircleRadius(radius) * height);   
   }
   
   

   /**
    * Returns the surface area of a cylinder given circumference and height.
    * @param circumference
    * @param height
    * @return
    */
   public double saCylinderCircumferenceAndHeight(double circumference, double height)
   {
      return (2 * areaCircleCircumference(circumference) + circumference * height);
   }
   
   
    
   /**
    * Returns the volume of a cylinder given the radius and height.
    * @param radius
    * @param height
    * @return
    */
   public double volCylinderRadiusAndHeight(double radius, double height)
   {
      return (Math.PI * Math.pow(radius, 2) * height);
   }
   
   
   
   /**
    * Returns the volume of a cylinder given the circumference and height.
    * @param circumference
    * @param height
    * @return
    */
   public double volCylinderCircumferenceAndHeight(double circumference, double height)
   {
      return (areaCircleCircumference(circumference) * height);
   }
   
   
   //********************************************** SEPARATOR **********************************************//
   
   
   /**
    * Returns the surface area of a cone given radius and height.
    * @param radius
    * @param height
    * @return
    */
   public double saConeRadiusAndHeight(double radius, double height)
   {
      return 
      (
         Math.PI * Math.pow(radius, 2) + Math.PI * radius 
         * Math.sqrt(Math.pow(radius, 2) + Math.pow(height, 2))
      );
   }
     
   
   
   /**
    * Returns the surface area of a cone given radius and slant height.
    * @param radius
    * @param slant
    * @return
    */
   public double saConeRadiusAndSlant(double radius, double slant)
   {
      return (Math.PI * Math.pow(radius, 2) + Math.PI * radius * slant);
   }
   
   
   
   /**
    * Returns the surface area of a cone given circumference and height.
    * @param circumference
    * @param height
    * @return
    */
   public double saConeCircumferenceAndHeight(double circumference, double height)
   {
      return 
      (
         areaCircleCircumference(circumference) + (circumference / Math.PI) 
         * Math.sqrt(Math.pow((circumference / Math.PI), 2)+ Math.pow(height, 2))
      );
   }
    
    
     
   /**
    * Returns the surface area of a cone given circumference and slant height.
    * @param circumference
    * @param slant
    * @return
    */
   public double saConeCircumferenceAndSlant(double circumference, double slant)
   {
      return 
      (
         areaCircleCircumference(circumference) + (circumference / Math.PI) * slant
      );
   }
   
   
   //********************************************** SEPARATOR **********************************************//
   
   
   /**
    * Returns the surface area of a sphere given the radius.
    * @param radius
    * @return
    */
   public double saSphereRadius(double radius)
   {
      return (4 * Math.PI * radius);
   }
  
   
   
   /**
    * Returns the surface area of a sphere given the maximum circumference.
    * @param circumference
    * @return
    */
   public double saSphereMaxCircumference(double circumference)
   {
      return (4 * (circumference / Math.PI));
   }
   
   
   
   /**
    * Returns the volume of a sphere given the radius.
    * @param radius
    * @return
    */
   public double volSphereRadius(double radius)
   {
      return ((4.0 / 3.0) * Math.PI * Math.pow(radius, 3));
   }
   
   
   
   /**
    * Returns the volume of a sphere given the maximum circumference.
    * @param circumference
    * @return
    */
   public double volSphereCircumference(double circumference)
   {
      return ((4.0 / 3.0) * Math.PI * Math.pow((circumference / (2 * Math.PI)), 3));
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //********************************************** 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 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 **********************************************//
   
}