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

   This class builds the button maker 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.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;



public class ButtonMakerGui extends JApplet implements ComponentListener
{
   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 runRestricted = false;
   
   static boolean isVisible = false;
   
   
   private static final int BUTTON_SIZE_X = 100;
   
   private static final int BUTTON_SIZE_Y = 100; 
   
   private static final int SIZE_FACTOR = 2;

   private static final int DEFAULT_CORNER_RADIUS = 0;
   
   private static final int DEFAULT_BORDER_WIDTH = 3;
 
   private static final int FRAME_SIZE_X = 505;
   
   private static final int FRAME_SIZE_Y = 555;
   
   private static final int MAX_SLIDER_VALUE = 100;
   
   private static final int DEFAULT_FONT_HORIZONTAL = 20;
   
   private static final int DEFAULT_FONT_VERTICAL = 30;
   
   private static final int DEFAULT_FONT_SIZE = 13;
   
   private static final double COLOR_FACTOR = 0.01;
  
   private static final String DEFAULT_FONT_TEXT = "";
   
   private static final String DEFAULT_FONT_NAME = "Arial";
   
   private static final String DEFAULT_FONT_STYLE = "Plain";
   
   private static final float DEFAULT_BORDER_HUE = 1.0f;
   
   private static final float DEFAULT_BORDER_BRIGHTNESS = 1.0f;
   
   private static final float DEFAULT_BORDER_SATURATION = 1.0f;
   
   private static final float DEFAULT_FILL_HUE = 1.0f;
   
   private static final float DEFAULT_FILL_BRIGHTNESS = 1.0f;
   
   private static final float DEFAULT_FILL_SATURATION = 0.3f; 
   
   private static final float DEFAULT_FONT_HUE = 1.0f;

   private static final float DEFAULT_FONT_BRIGHTNESS = 1.0f;
   
   private static final float DEFAULT_FONT_SATURATION = 1.0f;
   
   private static final float DEFAULT_GRADIENT_START_HUE = 1.0f;
   
   private static final float DEFAULT_GRADIENT_START_BRIGHTNESS = 1.0f;
   
   private static final float DEFAULT_GRADIENT_START_SATURATION = 0.1f;
   
   private static final float DEFAULT_GRADIENT_END_HUE = 1.0f;
   
   private static final float DEFAULT_GRADIENT_END_BRIGHTNESS = 1.0f;
   
   private static final float DEFAULT_GRADIENT_END_SATURATION = 0.7f;
   
   private static final int DEFAULT_GRADIENT_START_HORIZONTAL = 50;
   
   private static final int DEFAULT_GRADIENT_START_VERTICAL = 0;
   
   private static final int DEFAULT_GRADIENT_END_HORIZONTAL = 50;
   
   private static final int DEFAULT_GRADIENT_END_VERTICAL = 100;
   
   
   //************************************** 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
         {
            try {getToolkit().getSystemClipboard();}
             
            catch (java.security.AccessControlException e) {runRestricted = true;} 


            initialiser(); includeResizeEvent(); setSize(FRAME_SIZE_X, FRAME_SIZE_Y);
         }
      }
   }
 
   
   
   /**
    * Application constructor.
    */
   public ButtonMakerGui()
   {
      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("Button Maker Program"); 
         
         frame.add(contentPane); 
       
         
         setVisibility(); 
      }
 
   }
   
   
   
   /**
    * GUI initializer.
    * ESCA-JAVA0076:
    */
   private void initialiser()
   {
      maker = new ButtonMaker(); maker.setSize(BUTTON_SIZE_X, BUTTON_SIZE_Y);
      
      
      
      // Initialize content pane and layout.
      
      contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout());

      
      
      // Initialize label GUI components.
      
      label = new JLabel(new ImageIcon(maker.getBufferedImage()), JLabel.CENTER);
      
      
      
      // Initialize text field GUI components.
      
      textField = new JTextField(); textField.setBorder(BorderFactory.createEmptyBorder());
      
      textField.addKeyListener(new TextTypeListener());
      
      
      
      // Initialize combo box GUI components.
      
      borderWidthBox = new JComboBox(borderWidthChoices);
 
      borderWidthBox.setPreferredSize(new Dimension(120, 20));
      
      borderWidthBox.setMaximumRowCount(3); borderWidthBox.insertItemAt("Border Width", 0);
      
      borderWidthBox.setSelectedIndex(0); borderWidthBox.addActionListener(new BorderWidthHandler());
     
      
      cornerRadiusBox = new JComboBox(cornerRadiusChoices);
      
      cornerRadiusBox.setPreferredSize(new Dimension(120, 20));
      
      cornerRadiusBox.setMaximumRowCount(3); cornerRadiusBox.insertItemAt("Corner Radius", 0);
      
      cornerRadiusBox.setSelectedIndex(0); cornerRadiusBox.addActionListener(new CornerRadiusHandler());
      
      
      fontNameBox = new JComboBox(fontNameChoices);
      
      fontNameBox.setPreferredSize(new Dimension(143, 20));
      
      fontNameBox.setMaximumRowCount(2); fontNameBox.addActionListener(new FontNameHandler());
       
      
      fontStyleBox = new JComboBox(fontStyleChoices);
      
      fontStyleBox.setPreferredSize(new Dimension(143, 20));
      
      fontStyleBox.setMaximumRowCount(2); fontStyleBox.addActionListener(new FontStyleHandler());
     
      
      fontSizeBox = new JComboBox(fontSizeChoices);
      
      fontSizeBox.setPreferredSize(new Dimension(143, 20));
      
      fontSizeBox.setMaximumRowCount(2); fontSizeBox.addActionListener(new FontSizeHandler());
      
      
      
      // Initialize slider GUI components.
      
      borderHueSlider = new JSlider(); borderHueSlider.setMajorTickSpacing(25); 
      
      borderHueSlider.setMinorTickSpacing(5); borderHueSlider.setValue(100); 
      
      borderHueSlider.addChangeListener(new BorderHueListener());
      
      borderHueSlider.setPaintTicks(true); 
      
      
      borderSaturationSlider = new JSlider(); borderSaturationSlider.setMajorTickSpacing(25); 
      
      borderSaturationSlider.setMinorTickSpacing(5); borderSaturationSlider.setValue(100); 
      
      borderSaturationSlider.addChangeListener(new BorderSaturationListener());
      
      borderSaturationSlider.setPaintTicks(true); 
      
      
      borderBrightnessSlider = new JSlider(); borderBrightnessSlider.setMajorTickSpacing(25); 
      
      borderBrightnessSlider.setMinorTickSpacing(5); borderBrightnessSlider.setValue(100); 
      
      borderBrightnessSlider.addChangeListener(new BorderBrightnessListener());
      
      borderBrightnessSlider.setPaintTicks(true);
      
      
      widthSlider = new JSlider(); widthSlider.setMajorTickSpacing(25); 
      
      widthSlider.setMinorTickSpacing(5); widthSlider.setPaintTicks(true);
      
      widthSlider.addChangeListener(new WidthChangeListener());
      
      
      heightSlider = new JSlider(); heightSlider.setMajorTickSpacing(25);
      
      heightSlider.setMinorTickSpacing(5); heightSlider.setPaintTicks(true);
      
      heightSlider.addChangeListener(new HeightChangeListener());
      
      
      textHueSlider = new JSlider(); textHueSlider.setMajorTickSpacing(25); 
      
      textHueSlider.setMinorTickSpacing(5); textHueSlider.setValue(100); 
      
      textHueSlider.addChangeListener(new TextHueListener());
      
      textHueSlider.setPaintTicks(true); 

      
      textSaturationSlider = new JSlider(); textSaturationSlider.setMajorTickSpacing(25); 
      
      textSaturationSlider.setMinorTickSpacing(5); textSaturationSlider.setValue(100); 
      
      textSaturationSlider.addChangeListener(new TextSaturationListener());
      
      textSaturationSlider.setPaintTicks(true);
      
      
      textBrightnessSlider = new JSlider(); textBrightnessSlider.setMajorTickSpacing(25); 
      
      textBrightnessSlider.setMinorTickSpacing(5); textBrightnessSlider.setValue(100); 
      
      textBrightnessSlider.addChangeListener(new TextBrightnessListener());
      
      textBrightnessSlider.setPaintTicks(true);
      
      
      horizontalSlider = new JSlider(); horizontalSlider.setMajorTickSpacing(25); 
      
      horizontalSlider.setMinorTickSpacing(5); horizontalSlider.setValue(20);
      
      horizontalSlider.addChangeListener(new TextHorizontalListener());
      
      horizontalSlider.setPaintTicks(true); 
      
      
      verticalSlider = new JSlider(); verticalSlider.setMajorTickSpacing(25); 
      
      verticalSlider.setMinorTickSpacing(5); verticalSlider.setValue(30);
      
      verticalSlider.addChangeListener(new TextVerticalListener());
      
      verticalSlider.setPaintTicks(true);
      
      
      fillHueSlider = new JSlider(); fillHueSlider.setMajorTickSpacing(25);
      
      fillHueSlider.setMinorTickSpacing(5); fillHueSlider.setValue(100); 
      
      fillHueSlider.addChangeListener(new FillHueListener());
      
      fillHueSlider.setPaintTicks(true); 
      
      
      fillSaturationSlider = new JSlider(); fillSaturationSlider.setMajorTickSpacing(25); 
      
      fillSaturationSlider.setMinorTickSpacing(5);fillSaturationSlider.setValue(30); 
      
      fillSaturationSlider.addChangeListener(new FillSaturationListener());
      
      fillSaturationSlider.setPaintTicks(true); 
      
      
      fillBrightnessSlider = new JSlider(); fillBrightnessSlider.setMajorTickSpacing(25); 
      
      fillBrightnessSlider.setMinorTickSpacing(5); fillBrightnessSlider.setValue(100); 
      
      fillBrightnessSlider.addChangeListener(new FillBrightnessListener());
      
      fillBrightnessSlider.setPaintTicks(true);
      
      
      
      // Initialize radio button GUI components.
      
      rectangular = new JRadioButton("Square / Rectangle"); rectangular.setFocusPainted(false);
      
      rectangular.setSelected(true); rectangular.addActionListener(new ShapeTypeClass()); 
      
      
      elliptical = new JRadioButton("Circle / Ellipse"); elliptical.setFocusPainted(false); 
      
      elliptical.addActionListener(new ShapeTypeClass());
      
      
      uniformFill = new JRadioButton("Uniform Fill Color"); uniformFill.setFocusPainted(false);
      
      uniformFill.setSelected(true); uniformFill.addActionListener(new UniformFillHandler());
      
      
      gradientFill = new JRadioButton("Gradient Fill Color"); gradientFill.setFocusPainted(false);
      
      gradientFill.addActionListener(new GradientFillHandler());
      
      
      
      // Initialize check box GUI components.
      
      borders = new JCheckBox("Include Button Border"); borders.setFocusPainted(false);
      
      borders.setSelected(true); borders.addItemListener(new BorderAdditionClass());
      
      
      leftRight = new JCheckBox("Left, Right"); leftRight.setFocusPainted(false);
      
      leftRight.addActionListener(new GradientDirectionHandler()); 
      
      
      topBottom = new JCheckBox("Top, Bottom"); topBottom.setFocusPainted(false); 
      
      topBottom.setSelected(true); topBottom.addActionListener(new GradientDirectionHandler()); 
      
      
      topLeftBottomRight = new JCheckBox("Diag, Down"); topLeftBottomRight.setFocusPainted(false);
      
      topLeftBottomRight.addActionListener(new GradientDirectionHandler());
      
      
      bottomLeftTopRight = new JCheckBox("Diag, Up"); bottomLeftTopRight.setFocusPainted(false);
      
      bottomLeftTopRight.addActionListener(new GradientDirectionHandler()); 
      
      
      initialGradientEdit = new JCheckBox("Edit Color Of Initial Gradient");
      
      initialGradientEdit.setFocusPainted(false); initialGradientEdit.setSelected(true);
       
      
      finalGradientEdit = new JCheckBox("Edit Color Of Final Gradient"); 
      
      finalGradientEdit.setFocusPainted(false);
      
      
      separateFiles = new JCheckBox("Separate Files"); separateFiles.setFocusPainted(false);
      
      separateFiles.setSelected(true); separateFiles.setEnabled(false);
      
      
      horizontalStack = new JCheckBox("Horizontal Stack"); horizontalStack.setFocusPainted(false);
      
      horizontalStack.setEnabled(false);
      
      
      verticalStack = new JCheckBox("Vertical Stack"); verticalStack.setFocusPainted(false);
      
      verticalStack.setEnabled(false);
      
      
      gridStack = new JCheckBox("Grid Stack"); gridStack.setFocusPainted(false);
      
      gridStack.setEnabled(false);
      
      
      pngFormat = new JCheckBox("PNG File"); pngFormat.setFocusPainted(false);
      
      pngFormat.setSelected(true); pngFormat.addActionListener(new ImageFormatListener());
     
      
      gifFormat = new JCheckBox("GIF File"); gifFormat.setFocusPainted(false);
      
      gifFormat.addActionListener(new ImageFormatListener());
      
      
      
      // Initialize button group GUI components.
      
      groupType = new ButtonGroup(); 
      
      groupType.add(rectangular); groupType.add(elliptical);
      
      
      groupFill = new ButtonGroup(); 
      
      groupFill.add(uniformFill); groupFill.add(gradientFill);
      
      
      gradientEdit = new ButtonGroup(); 
      
      gradientEdit.add(initialGradientEdit); gradientEdit.add(finalGradientEdit);

      
      groupDirection = new ButtonGroup();
      
      groupDirection.add(leftRight); groupDirection.add(topBottom); 
      
      groupDirection.add(topLeftBottomRight); groupDirection.add(bottomLeftTopRight);
      
      
      imageFormat = new ButtonGroup(); 
      
      imageFormat.add(separateFiles); imageFormat.add(horizontalStack);
      
      imageFormat.add(verticalStack); imageFormat.add(gridStack);
      

      saveFormat = new ButtonGroup(); 
      
      saveFormat.add(pngFormat); saveFormat.add(gifFormat);
      
      
      
      // Initialize button GUI components.
      
      previewFile = new JButton(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerPreviewNormal.png"))
      ); 
          
      
      previewFile.setRolloverIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerPreviewRollover.png"))
      );

      
      previewFile.setPressedIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerPreviewPressed.png"))
      );
      
      
      previewFile.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
      
      previewFile.setPreferredSize(new Dimension(131, 35)); 
      
      previewFile.addActionListener(new PreviewFileHandler());
      
      
      saveFile = new JButton(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerSaveNormal.png"))
      ); 
     
      
      saveFile.setRolloverIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerSaveRollover.png"))
      );

      
      saveFile.setPressedIcon(new ImageIcon(this.getClass().getResource
      (
         "files/images/ButtonMakerSavePressed.png"))
      );   


      saveFile.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
             
      saveFile.setPreferredSize(new Dimension(131, 35)); 
      
      saveFile.addActionListener(new SaveFileHandler());
      
      
      store = new JButton("Store Image"); store.setFocusPainted(false); 
      
      store.addActionListener(new StoreImageHandler());
      
      store.setPreferredSize(new Dimension(142, 20));
      
      
      clear = new JButton("Clear Images"); clear.setFocusPainted(false); 
      
      clear.addActionListener(new ClearImageHandler());
      
      clear.setPreferredSize(new Dimension(142, 20));
      
      
      cycle = new JButton("Cycle Images"); cycle.setFocusPainted(false); 
      
      cycle.addActionListener(new CycleImageHandler());
      
      cycle.setPreferredSize(new Dimension(142, 20));
      
      
      if (runRestricted) {saveFile.setEnabled(false);}
      
      
      
      // Initialize JPanel GUI components.
      
      borderIncludePanel = new JPanel(); borderIncludePanel.setLayout(new FlowLayout());
      
      borderIncludePanel.setBorder(BorderFactory.createTitledBorder("Button Border"));
     
      borderColorPanel = new JPanel(); borderColorPanel.setLayout(new GridLayout(1,2));
      
      borderColorPanel.setBorder(BorderFactory.createTitledBorder("Border Color"));
      
      labelContainer = new JPanel(); labelContainer.setLayout(new FlowLayout());
      
      settingContainer = new JPanel(); settingContainer.setLayout(new FlowLayout());
      
      panelOne = new JPanel(); panelOne.setLayout(new GridLayout(4,1));  
      
      panelTwo = new JPanel(); panelTwo.setLayout(new GridLayout(4,1)); 
      
      panelThree = new JPanel(); panelThree.setLayout(new GridLayout(4,1)); 
      
      panelFour = new JPanel(); panelFour.setLayout(new GridLayout(3,1));
      
      shapePanel = new JPanel(); shapePanel.setLayout(new FlowLayout());
      
      shapePanel.setBorder(BorderFactory.createTitledBorder("Button Type"));
      
      sizePanel = new JPanel(); sizePanel.setLayout(new GridLayout(1,2));
      
      sizePanel.setBorder(BorderFactory.createTitledBorder("Button Size"));
      
      textPanel = new JPanel(); textPanel.setLayout(new GridLayout(1,1));
      
      textPanel.setBorder(BorderFactory.createTitledBorder("Font Text"));
      
      colorPanel = new JPanel(); colorPanel.setLayout(new GridLayout(1,3));
      
      colorPanel.setBorder(BorderFactory.createTitledBorder("Font Color"));
      
      stylePanel = new JPanel(); stylePanel.setLayout(new FlowLayout());
      
      stylePanel.setBorder(BorderFactory.createTitledBorder("Font Style"));
      
      positionPanel = new JPanel(); positionPanel.setLayout(new GridLayout(1,4));
      
      positionPanel.setBorder(BorderFactory.createTitledBorder("Font Position"));
      
      fillPanel = new JPanel(); fillPanel.setLayout(new GridLayout(1,2));
      
      fillPanel.setBorder(BorderFactory.createTitledBorder("Fill Type"));
       
      directionPanel = new JPanel(); directionPanel.setLayout(new GridLayout(1,4));
      
      directionPanel.setBorder(BorderFactory.createTitledBorder("Gradient Direction"));
       
      gradientPanel = new JPanel(); gradientPanel.setLayout(new GridLayout(1,2)); 
      
      gradientPanel.setBorder(BorderFactory.createTitledBorder("Editing Select"));
       
      fillColorPanel = new JPanel(); fillColorPanel.setLayout(new GridLayout(1,3));
      
      fillColorPanel.setBorder(BorderFactory.createTitledBorder("Selected Fill Color"));
      
      imageStorePanel = new JPanel(); imageStorePanel.setLayout(new FlowLayout());
      
      imageStorePanel.setBorder(BorderFactory.createTitledBorder("Template Storing"));
      
      imageFormatPanel = new JPanel(); imageFormatPanel.setLayout(new FlowLayout());
      
      imageFormatPanel.setBorder(BorderFactory.createTitledBorder("Image Formatting"));
      
      imageRenderPanel = new JPanel(); imageRenderPanel.setLayout(new FlowLayout());
      
      imageRenderPanel.setBorder(BorderFactory.createTitledBorder("Image Rendering"));
      

      
      // Add GUI components to JPanels. 
 
      labelContainer.add(label); shapePanel.add(rectangular); shapePanel.add(elliptical); 
      
      shapePanel.add(cornerRadiusBox); borderIncludePanel.add(borders); 
      
      borderIncludePanel.add(borderWidthBox); borderColorPanel.add(borderHueSlider); 
      
      borderColorPanel.add(borderSaturationSlider); borderColorPanel.add(borderBrightnessSlider);
      
      sizePanel.add(widthSlider); sizePanel.add(heightSlider); textPanel.add(textField); 
       
      colorPanel.add(textHueSlider); colorPanel.add(textSaturationSlider); 
      
      colorPanel.add(textBrightnessSlider); stylePanel.add(fontNameBox); stylePanel.add(fontStyleBox); 
      
      stylePanel.add(fontSizeBox); positionPanel.add(horizontalSlider); positionPanel.add(verticalSlider);
      
      fillPanel.add(uniformFill); fillPanel.add(gradientFill); directionPanel.add(leftRight);
      
      directionPanel.add(topBottom); directionPanel.add(topLeftBottomRight);
      
      directionPanel.add(bottomLeftTopRight); gradientPanel.add(initialGradientEdit); 
      
      gradientPanel.add(finalGradientEdit); fillColorPanel.add(fillHueSlider); 
      
      fillColorPanel.add(fillSaturationSlider); fillColorPanel.add(fillBrightnessSlider);
      
      imageStorePanel.add(store); imageStorePanel.add(clear); imageStorePanel.add(cycle);
      
      imageFormatPanel.add(separateFiles); imageFormatPanel.add(horizontalStack); 
      
      imageFormatPanel.add(verticalStack); imageFormatPanel.add(gridStack); 
      
      imageRenderPanel.add(pngFormat); imageRenderPanel.add(gifFormat); 
      
      imageRenderPanel.add(previewFile); imageRenderPanel.add(saveFile);
      
      panelOne.add(shapePanel); panelOne.add(borderIncludePanel); panelOne.add(borderColorPanel); 
      
      panelOne.add(sizePanel); panelTwo.add(textPanel); panelTwo.add(stylePanel); 
      
      panelTwo.add(colorPanel); panelTwo.add(positionPanel); panelThree.add(fillPanel); 
      
      panelThree.add(directionPanel); panelThree.add(gradientPanel); panelThree.add(fillColorPanel);
       
      panelFour.add(imageStorePanel); panelFour.add(imageFormatPanel); panelFour.add(imageRenderPanel);
      
      
      
      // Initialize tab pane GUI components.
      
      tabbedPane = new JTabbedPane(); 
      
      tabbedPane.setPreferredSize(new Dimension(474, 268)); tabbedPane.setFocusable(false); 
      
      tabbedPane.addTab("Shape And Size", panelOne); tabbedPane.addTab("Font And Style", panelTwo);
      
      tabbedPane.addTab("Fill And Gradient", panelThree); tabbedPane.addTab("Format And Saving", panelFour);
     
      
      
      // Add tab pane to setting container.
      
      settingContainer.add(tabbedPane); 
       
       
      
      // Method calls for GUI initialization.
      
      gridBagConstraints(); setDefaults(); refreshImageToolTip();
      
      setColors(); setGraphicIcons(); postToScreen();
   }
   
   
   
   /**
    * Sets the background color.
    */
   private void setColors()
   {
      contentPane.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      labelContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      settingContainer.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      tabbedPane.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      panelOne.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      panelTwo.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      panelThree.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      panelFour.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      shapePanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      sizePanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      fillPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      directionPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      gradientPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      fillColorPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      textPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      colorPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      stylePanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      positionPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borderIncludePanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borderColorPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borders.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borderHueSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borderSaturationSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      borderBrightnessSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      widthSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      heightSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      rectangular.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      elliptical.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      textField.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      textHueSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      textSaturationSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      textBrightnessSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      horizontalSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      verticalSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      uniformFill.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      gradientFill.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      leftRight.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      topBottom.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      topLeftBottomRight.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      bottomLeftTopRight.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      initialGradientEdit.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      finalGradientEdit.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      fillHueSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      fillSaturationSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      fillBrightnessSlider.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      imageStorePanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      imageFormatPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      imageRenderPanel.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      separateFiles.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      horizontalStack.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      verticalStack.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      gridStack.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      pngFormat.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
      
      gifFormat.setBackground
      (
         new Color (ColorFunctions.red(), ColorFunctions.green(), ColorFunctions.blue())
      );
   }
   
   
   
   /**
    * Sets icons for graphical elements.
    */
   private void setGraphicIcons()
   {
      rectangular.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalUnselected.png")));
             
      rectangular.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalSelected.png")));

      rectangular.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledUnselected.png")));

      rectangular.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledSelected.png")));
      
      
      elliptical.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalUnselected.png")));
               
      elliptical.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalSelected.png")));

      elliptical.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledUnselected.png")));

      elliptical.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledSelected.png")));
      
      
      uniformFill.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalUnselected.png")));
                   
      uniformFill.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalSelected.png")));

      uniformFill.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledUnselected.png")));

      uniformFill.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledSelected.png")));
        
      
      gradientFill.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalUnselected.png")));
                       
      gradientFill.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonNormalSelected.png")));

      gradientFill.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledUnselected.png")));

      gradientFill.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/RadioButtonDisabledSelected.png")));
      
      
      borders.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                        
      borders.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
   
      borders.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
   
      borders.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      leftRight.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                            
      leftRight.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
       
      leftRight.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
       
      leftRight.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      topBottom.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                
      topBottom.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
       
      topBottom.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
      
      topBottom.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      topLeftBottomRight.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                   
      topLeftBottomRight.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
          
      topLeftBottomRight.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
         
      topLeftBottomRight.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      bottomLeftTopRight.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                       
      bottomLeftTopRight.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
              
      bottomLeftTopRight.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
             
      bottomLeftTopRight.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      initialGradientEdit.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                           
      initialGradientEdit.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                  
      initialGradientEdit.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                 
      initialGradientEdit.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      finalGradientEdit.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                               
      finalGradientEdit.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                      
      finalGradientEdit.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                     
      finalGradientEdit.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      separateFiles.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                   
      separateFiles.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                          
      separateFiles.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                        
      separateFiles.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      horizontalStack.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                       
      horizontalStack.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                              
      horizontalStack.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                          
      horizontalStack.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      verticalStack.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                           
      verticalStack.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                                  
      verticalStack.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                              
      verticalStack.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      gridStack.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                               
      gridStack.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                                      
      gridStack.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                                  
      gridStack.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      pngFormat.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                                   
      pngFormat.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                                          
      pngFormat.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                                      
      pngFormat.setDisabledSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledSelected.png")));
      
      
      gifFormat.setIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalUnselected.png")));
                                                                       
      gifFormat.setSelectedIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxNormalSelected.png")));
                                              
      gifFormat.setDisabledIcon(new ImageIcon
      (this.getClass().getResource("files/images/CheckBoxDisabledUnselected.png")));
                                          
      gifFormat.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(5,0,0,0);
      
      
      constraints.ipadx = 0; 
      
      constraints.ipady = 0;

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

      constraints.gridwidth = 1;
      
      constraints.weightx = 0; 
      
      constraints.weighty = 1; 
      
      constraints.gridx = 0; 
      
      constraints.gridy = 1;
      
      
      contentPane.add(settingContainer, constraints);
   }
   
   
   //*************************************** END INITIALISATION CODE ***************************************//
   
   
   //************************************* START INTERFACE EVENT CODE **************************************//
   
   
   private class TextTypeListener implements KeyListener
   {
   
      /**
       * This is the text listener.
       */ 
      public void keyReleased(KeyEvent e) 
      {
         setFontText(textField.getText()); 
  
         postToScreen();
      } 
   
      public void keyTyped(KeyEvent e) {}
 
      public void keyPressed(KeyEvent e) {}  
   }
   

   
   private class WidthChangeListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent) 
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            maker.setRows(theJSlider.getValue() * SIZE_FACTOR);
                
            maker.initialiseBufferedImage();         
                
            setGradientCoordinates(); 
            
            refreshImageToolTip();
            
            postToScreen();
         }     
      }
   }
   
   
   
   private class HeightChangeListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            maker.setColumns(theJSlider.getValue() * SIZE_FACTOR);
               
            maker.initialiseBufferedImage();    
               
            setGradientCoordinates(); 
            
            refreshImageToolTip();
            
            postToScreen();
         }     
      }
   }
   
   
   
   private class TextHorizontalListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setFontPositionHorizontal
            
            (getFontHorizontalPosition(theJSlider.getValue()));
                
            postToScreen();
         }     
      }
   }
   
   
   
   private class TextVerticalListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setFontPositionVertical
            
            (getFontVerticalPosition(theJSlider.getValue()));
                
            postToScreen();
         }     
      }
   }
   
   
   
   private class FillHueListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
            
            if (uniformFill.isSelected())
            {
               setFillHue((float)(theJSlider.getValue() * COLOR_FACTOR));
            }
            
            if (gradientFill.isSelected())
            {
               if (initialGradientEdit.isSelected())
               {
                  setGradientStartHue((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
               
               if (finalGradientEdit.isSelected())
               {
                  setGradientEndHue((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
            }
         }
         
         postToScreen();
      }
   }
   
   
   
   private class FillSaturationListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            if (uniformFill.isSelected())
            {
               setFillSaturation((float)(theJSlider.getValue() * COLOR_FACTOR));
            }
            
            if (gradientFill.isSelected())
            {
               if (initialGradientEdit.isSelected())
               {
                  setGradientStartSaturation((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
               
               if (finalGradientEdit.isSelected())
               {
                  setGradientEndSaturation((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
            }
         }
         
         postToScreen();
      }
   }
   
   
   
   private class FillBrightnessListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            if (uniformFill.isSelected())
            {
               setFillBrightness((float)(theJSlider.getValue() * COLOR_FACTOR));
            }
            
            if (gradientFill.isSelected())
            {
               if (initialGradientEdit.isSelected())
               {
                  setGradientStartBrightness((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
               
               if (finalGradientEdit.isSelected())
               {
                  setGradientEndBrightness((float)(theJSlider.getValue() * COLOR_FACTOR));
               }
            }
         }
         
         postToScreen();
      }
   }
   
   
   
   private class TextHueListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setFontHue((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class TextSaturationListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setFontSaturation((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class TextBrightnessListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setFontBrightness((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class BorderHueListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setBorderHue((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class BorderSaturationListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setBorderSaturation((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class BorderBrightnessListener implements ChangeListener 
   {
  
     /**
       * This is the slider listener.
       */
      public void stateChanged(ChangeEvent changeEvent)
      {
        
         Object source = changeEvent.getSource();

         if (source instanceof JSlider) 
         {
            JSlider theJSlider = (JSlider) source;
      
            setBorderBrightness((float)(theJSlider.getValue() * COLOR_FACTOR));
         }
         
         postToScreen();
      }
   }
   
   
   
   private class BorderWidthHandler implements ActionListener 
   {

      /** 
       * Listener for the year box.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         try {setBorderWidth(Integer.parseInt((String)borderWidthBox.getSelectedItem()));}
         
         catch (NumberFormatException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
         
         postToScreen();
         
      }
   
   }
   
   
   
   private class CornerRadiusHandler implements ActionListener 
   {

      /** 
       * Listener for the year box.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         try {setCornerRadius(Integer.parseInt((String)cornerRadiusBox.getSelectedItem()));}
         
         catch (NumberFormatException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
         
         postToScreen();
         
      }
   
   }
   
   
   
   private class GradientDirectionHandler implements ActionListener 
   {

      /** 
       * Listener for the gradient direction check boxes.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         setGradientCoordinates();
         
         postToScreen();
         
      }
   
   }
   
   
   
   private class FontNameHandler implements ActionListener 
   {

      /** 
       * Listener for the font name box.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         try {setFontName((String)fontNameBox.getSelectedItem());}
         
         catch (NumberFormatException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
         
         postToScreen();
         
      }
   
   }
   
   
   
   private class FontStyleHandler implements ActionListener 
   {

      /** 
       * Listener for the font style box.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         try {setFontStyle((String)fontStyleBox.getSelectedItem());}
         
         catch (NumberFormatException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
         
         postToScreen();
         
      }
   
   }
   
   
   
   private class FontSizeHandler implements ActionListener 
   {

      /** 
       * Listener for the font size box.
       * ESCA-JAVA0266:
       */
      public void actionPerformed(ActionEvent event) 
      {
         
         try {setFontSize(Integer.parseInt((String)fontSizeBox.getSelectedItem()));}
         
         catch (NumberFormatException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
         
         postToScreen();
         
      }
   
   }
   
   
   
   /**
    * Image format listener. 
    */
   private class ImageFormatListener implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         if (pngFormat.isSelected())
         {
            maker.setImageFormat("png"); 
         }
         
         if (gifFormat.isSelected())
         {
            maker.setImageFormat("gif"); 
         }
      }
   }
   
   
   
   /**
    * Shape type listener. 
    */
   private class ShapeTypeClass implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         postToScreen();
      }
   }
   
   
   
   /**
    * URL check box listener. 
    */
   private class BorderAdditionClass implements ItemListener
   { 
      public void itemStateChanged(ItemEvent event)
      {
      
         postToScreen();
                
      }
            
   }
   
   
   
   /**
    * Shape type listener. 
    */
   private class GradientFillHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         postToScreen();
      }
   }
   
   
   
   /**
    * Shape type listener. 
    */
   private class UniformFillHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         postToScreen();
      }
   }
   
   
   
   /**
    * Store image listener. 
    */
   private class StoreImageHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         maker.storeImage(); 
         
         enableFormatCheckBox();
         
         widthSlider.setEnabled(false);
         
         heightSlider.setEnabled(false);
         
      }
   }
   
   
   
   /**
    * Clear image listener. 
    */
   private class ClearImageHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
         storageEdit = false;
      
         disableFormatCheckBox(); 
      
         maker.clearStoredImages(); 
         
         widthSlider.setEnabled(true);
         
         heightSlider.setEnabled(true);
         
         disableEnableComponents(true);
      }
   }
   
   
   
   /**
    * Cycle image listener. 
    * ESCA-JAVA0266:
    */
   private class CycleImageHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      { 
         incrementStorageCycle(); 
         
     
         try 
         {
            label.setIcon(new ImageIcon(maker.cycleStoredTemplate(getStorageCycle())));
        
            disableEnableComponents(false); storageEdit = true;
         }
         
         catch (NullPointerException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");} 
            
      }
   }
   
   
   
   /**
    * Preview file listener. 
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private class PreviewFileHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      { 
         incrementStorageCycle(); 
         
         
         try 
         {
            label.setIcon(new ImageIcon(maker.cycleStoredEdited(getStorageCycle())));
            
            disableEnableComponents(false);
         }
         
         catch (NullPointerException e) {System.out.println(Tools.thisPathAndLine() + e + "\n");} 
            
      }
   }
   
   
   
   /**
    * Save file listener. 
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private class SaveFileHandler implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {    
         saveGraphics();
      }
   }
   
   
   
   /**
    * Overrides ComponentListener.
    */
   public void componentMoved(ComponentEvent e) {}
   
   
   public void componentResized(ComponentEvent e) {}
   
   
   public void componentShown(ComponentEvent e) {setContentDisplay(true);}
   
   
   public void componentHidden(ComponentEvent e) {setContentDisplay(false);}
   
   
   //************************************** 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 ****************************************//
   
   
   /**
    * Sets visibility of GUI components.
    * @param visible
    */
   private void disableEnableComponents(boolean visible)
   {
      shapePanel.setVisible(visible);
      
      borderIncludePanel.setVisible(visible);
      
      borderColorPanel.setVisible(visible);
      
      sizePanel.setVisible(visible);
      
      fillPanel.setVisible(visible);
      
      directionPanel.setVisible(visible);
      
      gradientPanel.setVisible(visible);
      
      fillColorPanel.setVisible(visible);  
   }
   
   
   
   /**
    * Refreshes the tool tip text for the graphic image
    * indicating the dimensions of the graphic.
    */
   private void refreshImageToolTip()
   {
      label.setToolTipText(Integer.toString
      (maker.getWidth()) + " By " + Integer.toString(maker.getHeight()));
   }
   
   
   
   /**
    * Adds fill color or a color 
    * gradient to the button graphic.
    */
   private void addFill()
   { 
      if (uniformFill.isSelected())
      {
         maker.setGraphicsBodyColor
         (
            Color.getHSBColor
            (
               getFillHue(), getFillSaturation(), getFillBrightness()
            )
         ); 
      }
      
      else
      {
         maker.setGradient
         (
            Color.getHSBColor
            (
               getGradientStartHue(), getGradientStartSaturation(), getGradientStartBrightness()
            ),
             
            Color.getHSBColor
            (
               getGradientEndHue(), getGradientEndSaturation(), getGradientEndBrightness()
            ),
            
            getGradientStartHorizontal(), getGradientStartVertical(),
            
            getGradientEndHorizontal(), getGradientEndVertical()
         );
      } 
      
      if (rectangular.isSelected())
      {
         maker.fillRectangleRound(getCornerRadius());
      }
      
      else {maker.fillOval();}
   }
   
   
   
   /** 
    * Adds a border to the button graphic.
    */
   private void addBorder()
   {
      if (borders.isSelected())
      {
         maker.setGraphicsBorderColor
         (
            Color.getHSBColor
            (
               getBorderHue(), getBorderSaturation(), getBorderBrightness()
            )
         );
      
         
         if (rectangular.isSelected())
         {
            maker.addRectangleBorder(getBorderWidth(), getCornerRadius());
         }
  
         else {maker.addOvalBorder(getBorderWidth());}
      }
   }
   
   
   
   /**
    * Adds text to the button graphic.
    */
   private void addTextBufferedImage()
   {
      maker.addTextBufferedImage
      (
         getFontText(), getFontName(), 
         
         Color.getHSBColor
         (
            getFontHue(), getFontSaturation(), getFontBrightness()
         ), 
         
         getFontStyle(), getFontSize(), getFontPositionHorizontal(), getFontPositionVertical()
      );   
   }
   
   
   
   /**
    * Adds text to the button graphic.
    */
   private void addTextStoredImage()
   {
      maker.cloneTemplate(getStorageCycle());
   
   
      maker.addTextStoredImage
      (
         getFontText(), getFontName(), 
         
         Color.getHSBColor
         (
            getFontHue(), getFontSaturation(), getFontBrightness()
         ), 
         
         getFontStyle(), getFontSize(), getFontPositionHorizontal(), getFontPositionVertical()
      ); 
      
   }
   
   
   
   /**
    * Renders the image graphic.
    */
   private void run()
   {  
      if (storageEdit) {addTextStoredImage();}

      
      else
      {
         maker.initialiseBufferedImage(); maker.antialias(true);
   
         addFill(); addBorder(); addTextBufferedImage();
      }
   }
   
   
   
   /**
    * Enabled the gradient check boxes determined by
    * how many images are stored as a buffered image.
    */
   private void enableFormatCheckBox()
   {
      final int ONE_IMAGE = 1; final int TWO_IMAGES = 2;
       
      final int THREE_IMAGES = 3; final int FOUR_IMAGES = 4;
       
       
      if (maker.getImageNumberStored() == ONE_IMAGE)
      {
         separateFiles.setEnabled(true);
      }
       
      if ((maker.getImageNumberStored() == TWO_IMAGES) 
      || (maker.getImageNumberStored() == THREE_IMAGES))
      {
         horizontalStack.setEnabled(true);
         
         verticalStack.setEnabled(true);
      }
      
      if (maker.getImageNumberStored() == FOUR_IMAGES)
      {
         gridStack.setEnabled(true);
      }   
   }
   
   
   
   /**
    * Disabled the format check boxes.
    */
   private void disableFormatCheckBox()
   {
      separateFiles.setEnabled(false);
      
      horizontalStack.setEnabled(false);
      
      verticalStack.setEnabled(false);
      
      gridStack.setEnabled(false);
   }
  
   
   
   /**
    * Renders the appropriate combined image.
    */
   private void renderCombinedImage()
   {
      if (horizontalStack.isSelected())
      {
         maker.initialiseCombinedHorizontal();
          
         maker.writeHorizontalStack();
      }
      
      if (verticalStack.isSelected())
      {
         maker.initialiseCombinedVertical();
         
         maker.writeVerticalStack();
      }
       
      if (gridStack.isSelected())
      {
         maker.initialiseCombinedGrid();
         
         maker.writeGridStack();
      }
   }
   
   
   
   /**
    * Saves multiple image graphics as separate files.
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private void multipleSaving()
   {
      try 
      {
         if (maker.getStoredEdited(0) != null)
         {
            maker.saveShapeImage(maker.getStoredEdited(0), "Graphic A");
         }
         
         if (maker.getStoredEdited(1) != null)
         {
            maker.saveShapeImage(maker.getStoredEdited(1), "Graphic B");
         }
         
         if (maker.getStoredEdited(2) != null)
         {
            maker.saveShapeImage(maker.getStoredEdited(2), "Graphic C");
         }
         
         if (maker.getStoredEdited(3) != null)
         {
            maker.saveShapeImage(maker.getStoredEdited(3), "Graphic D");
         }
         
      }
      
      catch (Exception e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
   }
   
   
   
   /**
    * Saves the graphic images to the computer.
    * ESCA-JAVA0166:
    * ESCA-JAVA0266:
    */
   private void saveGraphics()
   {  
      try 
      {  
         if (maker.isStorageOccupied())
         {
            if (separateFiles.isSelected()) 
            {
               multipleSaving();
            }
        
            else
            {
               renderCombinedImage();
         
               maker.saveShapeImage(maker.getCombinedImage(), "Graphic");
            } 
         }
      
         else
         {
            maker.saveShapeImage(maker.getBufferedImage(), "Graphic"); 
         }
      }
      
      catch (Exception e) {System.out.println(Tools.thisPathAndLine() + e + "\n");}
      
   }
   
   
   
   /**
    * Sets the gradient coordinates.
    */
   private void setGradientCoordinates()
   {
      if (leftRight.isSelected())
      {
         setGradientStartHorizontal(0);
         
         setGradientStartVertical(maker.getHeight() / 2);
         
         setGradientEndHorizontal(maker.getWidth());
         
         setGradientEndVertical(maker.getHeight() / 2);
      }
      
      if (topBottom.isSelected())
      {
         setGradientStartVertical(0); 
    
         setGradientStartHorizontal(maker.getWidth() / 2); 
         
         setGradientEndHorizontal(maker.getWidth() / 2);
         
         setGradientEndVertical(maker.getHeight());
      }
      
      if (bottomLeftTopRight.isSelected())
      {
         setGradientEndVertical(0);
      
         setGradientStartHorizontal(0);
         
         setGradientStartVertical(maker.getHeight()); 
      
         setGradientEndHorizontal(maker.getWidth());
      }
      
      if (topLeftBottomRight.isSelected())
      {
         setGradientStartVertical(0); 
      
         setGradientStartHorizontal(0);
         
         setGradientEndVertical(maker.getHeight());
      
         setGradientEndHorizontal(maker.getWidth());
      }
   
   }
   
   
   
   /**
    * Increments the storage cycle.
    */
   private void incrementStorageCycle()
   {
      if (storageCycle < (maker.getImageNumberStored() -1))
      {
         storageCycle ++;
      }
      
      else {storageCycle = 0;}
   }
   
   
   
   /**
    * Posts the updated image to the label.
    * ESCA-JAVA0266:
    * ESCA-JAVA0166:
    */
   private void postToScreen()
   {      
      run(); setLabelGraphic(); label.revalidate();
   }
   
   
   
   /**
    * Sets the defaults for the interface.
    */
   private void setDefaults()
   {
      setFontText(DEFAULT_FONT_TEXT); 
      
      setFontSize(DEFAULT_FONT_SIZE);
      
      setFontName(DEFAULT_FONT_NAME); 
      
      setFontStyle(DEFAULT_FONT_STYLE);
  
      setBorderWidth(DEFAULT_BORDER_WIDTH); 
      
      setCornerRadius(DEFAULT_CORNER_RADIUS);
     
      setBorderHue(DEFAULT_BORDER_HUE); 
      
      setBorderSaturation(DEFAULT_BORDER_SATURATION);
      
      setBorderBrightness(DEFAULT_BORDER_BRIGHTNESS); 
      
      setFillHue(DEFAULT_FILL_HUE);
      
      setFillSaturation(DEFAULT_FILL_SATURATION); 
      
      setFillBrightness(DEFAULT_FILL_BRIGHTNESS);
       
      setFontHue(DEFAULT_FONT_HUE); 
      
      setFontSaturation(DEFAULT_FONT_SATURATION);
      
      setFontBrightness(DEFAULT_FONT_BRIGHTNESS); 
      
      setFontPositionHorizontal(DEFAULT_FONT_HORIZONTAL);
      
      setFontPositionVertical(DEFAULT_FONT_VERTICAL);
      
      setGradientStartHorizontal(DEFAULT_GRADIENT_START_HORIZONTAL);
      
      setGradientStartVertical(DEFAULT_GRADIENT_START_VERTICAL);
      
      setGradientEndHorizontal(DEFAULT_GRADIENT_END_HORIZONTAL);
      
      setGradientEndVertical(DEFAULT_GRADIENT_END_VERTICAL);
      
      setGradientStartHue(DEFAULT_GRADIENT_START_HUE);
      
      setGradientStartSaturation(DEFAULT_GRADIENT_START_SATURATION);
      
      setGradientStartBrightness(DEFAULT_GRADIENT_START_BRIGHTNESS);
      
      setGradientEndHue(DEFAULT_GRADIENT_END_HUE);
      
      setGradientEndSaturation(DEFAULT_GRADIENT_END_SATURATION);
      
      setGradientEndBrightness(DEFAULT_GRADIENT_END_BRIGHTNESS);
   }
   
   
   
   /**
    * 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);
      } 
   }
   

   
   /**
    * Prints the button graphic to the label.
    * ESCA-JAVA0032:
    */
   private void setLabelGraphic()
   {
      
      if (shapePanel.isVisible()) 
      {
         label.setIcon(new ImageIcon(maker.getBufferedImage()));
      }
      
      else 
      {
         label.setIcon(new ImageIcon(maker.getStoredEdited(getStorageCycle())));
      }
   }
   
   
   
   /**
    * Calculates the text horizontal 
    * position for the slider value.
    * @param sliderValue
    * @return
    */
   private int getFontHorizontalPosition(double sliderValue)
   {
      double ratio = (sliderValue / MAX_SLIDER_VALUE);
   
      return ((int)(maker.getWidth() * ratio));  
   }
   
   
   
   /**
    * Calculates the text vertical 
    * position for the slider value.
    * @param sliderValue
    * @return
    */
   private int getFontVerticalPosition(double sliderValue)
   {
      double ratio = (sliderValue / MAX_SLIDER_VALUE);
   
      return ((int)(maker.getHeight() * ratio));  
   }
   
  
   
   /**
    * Sets the font text.
    * @param text
    */
   private void setFontText(String text) {fontText = text;}
   
   
   
   /**
    * Sets the font horizontal position.
    * @param position
    */
   private void setFontPositionHorizontal(int position) {fontPositionHorizontal = position;}
   
   
   
   /**
    * Sets the font vertical position.
    * @param position
    */
   private void setFontPositionVertical(int position) {fontPositionVertical = position;}
   
   
   
   /**
    * Sets the border width.
    * @param width
    */
   private void setBorderWidth(int width) {borderWidth = width;}
   
   
   
   /**
    * Sets the border width.
    * @param radius
    */
   private void setCornerRadius(int radius) {cornerRadius = radius;}
   
   
   
   /**
    * Sets the border hue.
    * @param hue
    */
   private void setBorderHue(float hue) {borderHue = hue;}
   
   
   
   /**
    * Sets the border saturation.
    * @param saturation
    */
   private void setBorderSaturation(float saturation) {borderSaturation = saturation;}
   
   
   
   /**
    * Sets the border brightness.
    * @param brightness
    */
   private void setBorderBrightness(float brightness) {borderBrightness = brightness;}
   
   
   
   /**
    * Sets the font name.
    * @param name
    */
   private void setFontName(String name) {fontName = name;}
   
   
   
   /**
    * Sets the font style.
    * @param style
    */
   private void setFontStyle(String style) {fontStyle = style;}
   
   
   
   /**
    * Sets the font size.
    * @param size
    */
   private void setFontSize(int size) {fontSize = size;}
   
   
   
   /**
    * Sets the font hue.
    * @param hue
    */
   private void setFontHue(float hue) {fontHue = hue;}
   
   
   
   /**
    * Sets the font saturation.
    * @param saturation
    */
   private void setFontSaturation(float saturation) {fontSaturation = saturation;}
   
   
   
   /**
    * Sets the font brightness.
    * @param brightness
    */
   private void setFontBrightness(float brightness) {fontBrightness = brightness;}
   
   
   
   /**
    * Sets the fill hue.
    * @param hue
    */
   private void setFillHue(float hue) {fillHue = hue;}
   
   
   
   /**
    * Sets the fill saturation.
    * @param saturation
    */
   private void setFillSaturation(float saturation) {fillSaturation = saturation;}
   
   
   
   /**
    * Sets the fill brightness.
    * @param brightness
    */
   private void setFillBrightness(float brightness) {fillBrightness = brightness;}
   
   
   
   /**
    * Sets the gradient start hue.
    * @param hue
    */
   private void setGradientStartHue(float hue) {gradientStartHue = hue;}
   
   
   
   /**
    * Sets the gradient start saturation.
    * @param hue
    */
   private void setGradientStartSaturation(float hue) {gradientStartSaturation = hue;}
   
   
   
   /**
    * Sets the gradient start brightness.
    * @param hue
    */
   private void setGradientStartBrightness(float hue) {gradientStartBrightness = hue;}
   
   
   
   /**
    * Sets the gradient end hue.
    * @param hue
    */
   private void setGradientEndHue(float hue) {gradientEndHue = hue;}
   
   
   
   /**
    * Sets the gradient end saturation.
    * @param hue
    */
   private void setGradientEndSaturation(float hue) {gradientEndSaturation = hue;}
   
   
   
   /**
    * Sets the gradient end brightness.
    * @param hue
    */
   private void setGradientEndBrightness(float hue) {gradientEndBrightness = hue;}
   
   
   
   /**
    * Sets the gradient start horizontal position.
    * @param position
    */
   private void setGradientStartHorizontal(int position) {gradientStartHorizontal = position;}
   
   
   
   /**
    * Sets the gradient start vertical position.
    * @param position
    */
   private void setGradientStartVertical(int position) {gradientStartVertical = position;}
   
   
   
   /**
    * Sets the gradient end horizontal position.
    * @param position
    */
   private void setGradientEndHorizontal(int position) {gradientEndHorizontal = position;}
   
   
   
   /**
    * Sets the gradient start horizontal position.
    * @param position
    */
   private void setGradientEndVertical(int position) {gradientEndVertical = position;}
   
   
   
   /**
    * Returns the storage cycle.
    * @return
    */
   private int getStorageCycle() {return storageCycle;}
   
   
   
   /**
    * Returns the font name.
    * @return
    */
   private String getFontName() {return fontName;}
   
   
   
   /**
    * Returns the font style.
    * @return
    */
   private String getFontStyle() {return fontStyle;}
   
   
   
   /**
    * Returns the font size.
    * @return
    */
   private int getFontSize() {return fontSize;}
   
   
   
   /**
    * Returns the font text.
    * @return
    */
   private String getFontText() {return fontText;}
   
   
   
   /**
    * Returns the font horizontal position.
    * @return
    */
   private int getFontPositionHorizontal() {return fontPositionHorizontal;}
   
   
   
   /**
    * Returns the font vertical position.
    * @return
    */
   private int getFontPositionVertical() {return fontPositionVertical;}
   

   
   /**
    * Returns the border width.
    * @return
    */
   private int getBorderWidth() {return borderWidth;}
   
   
   
   /**
    * Returns the corner radius.
    * @return
    */
   private int getCornerRadius() {return cornerRadius;}
   
   
   
   /**
    * Returns the gradient start horizontal position.
    * @return
    */
   private int getGradientStartHorizontal() {return gradientStartHorizontal;}
   
   
   
   /**
    * Returns the gradient start vertical position.
    * @return
    */
   private int getGradientStartVertical() {return gradientStartVertical;}
   
   
   
   /**
    * Returns the gradient end horizontal position.
    * @return
    */
   private int getGradientEndHorizontal() {return gradientEndHorizontal;}
   
   
   
   /**
    * Returns the gradient end vertical position.
    * @return
    */
   private int getGradientEndVertical() {return gradientEndVertical;}
   
   
   
   /**
    * Returns the gradient start hue.
    * @return
    */
   private float getGradientStartHue() {return gradientStartHue;}
   
   
   
   /**
    * Returns the gradient start saturation.
    * @return
    */
   private float getGradientStartSaturation() {return gradientStartSaturation;}
   
   
   
   /**
    * Returns the gradient start brightness.
    * @return
    */
   private float getGradientStartBrightness() {return gradientStartBrightness;}
   
   
   
   /**
    * Returns the gradient end hue.
    * @return
    */
   private float getGradientEndHue() {return gradientEndHue;}
   
   
   
   /**
    * Returns the gradient end saturation.
    * @return
    */
   private float getGradientEndSaturation() {return gradientEndSaturation;}
   
   
   
   /**
    * Returns the gradient end brightness.
    * @return
    */
   private float getGradientEndBrightness() {return gradientEndBrightness;}
   
   
   
   /**
    * Returns the border hue.
    * @return
    */
   private float getBorderHue() {return borderHue;}
   
   
   
   /**
    * Returns the border saturation.
    * @return
    */
   private float getBorderSaturation() {return borderSaturation;}
   
   
   
   /**
    * Returns the border brightness.
    * @return
    */
   private float getBorderBrightness() {return borderBrightness;}
   
   
   
   /**
    * Returns the font hue.
    * @return
    */
   private float getFontHue() {return fontHue;}
   
   
   
   /**
    * Returns the font saturation.
    * @return
    */
   private float getFontSaturation() {return fontSaturation;}
   
   
   
   /**
    * Returns the font brightness.
    * @return
    */
   private float getFontBrightness() {return fontBrightness;}
   
   
   
   /**
    * Returns the fill hue.
    * @return
    */
   private float getFillHue() {return fillHue;}
   
   
   
   /**
    * Returns the fill saturation.
    * @return
    */
   private float getFillSaturation() {return fillSaturation;}
   
   
   
   /**
    * Returns the fill brightness.
    * @return
    */
   private float getFillBrightness() {return fillBrightness;}
   
   
   //***************************************** END PRIVATE METHODS *****************************************//
   
   
   //********************************************** START MAIN *********************************************//
   
  
   /**
    * Main
    * @param a
    */
   public static void main(String[] a)
   {
      isApplication = true;
      
      isVisible = true;
      
      new ButtonMakerGui();
   }
   
   
   //*********************************************** END MAIN **********************************************//
   
   
   /**
    * ESCA-JAVA0007:
    */
   public JFrame frame;
   
   private JLabel label;
   private ButtonMaker maker;
   private boolean storageEdit;
   private JTextField textField;
   private Container contentPane;
   private JTabbedPane tabbedPane;
   private boolean zoomWarningShown;
   private GridBagConstraints constraints;
   private String fontText, fontName, fontStyle;
   private JButton store, clear, cycle, previewFile, saveFile;
   
   private String[] fontNameChoices = {"Arial", "Calibri", "Times New Roman"};
   
   private JCheckBox borders, pngFormat, gifFormat, leftRight, 
   topBottom, topLeftBottomRight, bottomLeftTopRight, initialGradientEdit, 
   finalGradientEdit, separateFiles, horizontalStack, verticalStack, gridStack;
   
   private JRadioButton rectangular, elliptical, uniformFill, gradientFill;
   
   private JSlider widthSlider, heightSlider, borderHueSlider, 
   borderSaturationSlider, borderBrightnessSlider, textHueSlider, 
   textSaturationSlider, textBrightnessSlider, horizontalSlider, 
   verticalSlider, fillHueSlider, fillSaturationSlider, fillBrightnessSlider;
   
   private String[] fontSizeChoices = 

   {"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"};
   
   private String[] fontStyleChoices = {"Bold", "Italic", "Plain", "Bold Italic"};
   
   private String[] borderWidthChoices = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
   
   private float borderHue, borderBrightness, borderSaturation, 
   fillHue, fillBrightness, fillSaturation, gradientStartHue, 
   gradientStartSaturation, gradientStartBrightness, gradientEndHue, 
   gradientEndSaturation, gradientEndBrightness, fontHue, fontSaturation, fontBrightness;
   
   private int storageCycle, fontSize, borderWidth, cornerRadius, 
   fontPositionHorizontal, fontPositionVertical, gradientStartHorizontal, 
   gradientStartVertical, gradientEndHorizontal, gradientEndVertical;
   
   private JPanel labelContainer, settingContainer, panelOne, panelTwo, 
   panelThree, panelFour, shapePanel, borderIncludePanel, borderColorPanel, 
   sizePanel, fillPanel, directionPanel, gradientPanel, fillColorPanel, textPanel, 
   colorPanel, stylePanel, positionPanel, imageStorePanel, imageFormatPanel, imageRenderPanel;
   
   private ButtonGroup groupType, groupFill, groupDirection, gradientEdit, imageFormat, saveFormat;

   private JComboBox borderWidthBox, cornerRadiusBox, fontStyleBox, fontNameBox, fontSizeBox;
   
   private String[] cornerRadiusChoices = {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
   
   
   //********************************************** END CLASS **********************************************//
   
}


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

   This class creates and fills shapes of various colors and gradients.

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



import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;



public class ButtonMaker 
{

   private static String PATH;
   
   
   private static final int MINIMUM_SIZE = 2;
   
   private static final int STORE_ARRAY_SIZE = 4;
   
   
   
   /**
    * Class constructor.
    * ESCA-JAVA0057:
    */
   public ButtonMaker() 
   {
      setImageFormat("png");  
   }
   
   
   //**************************************** START PUBLIC METHODS *****************************************//
   
  
   /**
    * Initializes the buffered image.
    */
   public void initialiseBufferedImage()
   {
      bufferedImage = new BufferedImage
      (
         getWidth() -1, getHeight() -1, BufferedImage.TYPE_INT_ARGB
      );
   
      bufferedImageGraphics = bufferedImage.createGraphics();
   }
   
   
   
   /**
    * Initializes the horizontal stacked image.
    */
   public void initialiseCombinedHorizontal()
   {
      combinedImage = new BufferedImage
      (
         (getWidth() -1) * getImageNumberStored(), 
         
         (getHeight() -1), BufferedImage.TYPE_INT_ARGB
      );
       
      combinedImageGraphics = combinedImage.createGraphics();
      
   }
   
   
  
   /**
    * Initializes the vertical stacked image.
    */
   public void initialiseCombinedVertical()
   {
      combinedImage = new BufferedImage
      (
         getWidth() -1, (getHeight() -1) * getImageNumberStored(), 
         
         BufferedImage.TYPE_INT_ARGB
      );
       
      combinedImageGraphics = combinedImage.createGraphics();
   }
   
   
   
   /**
    * Initializes the grid stacked image.
    */
   public void initialiseCombinedGrid()
   {
      combinedImage = new BufferedImage
      (
         (getWidth() -1) * (getImageNumberStored() / 2), 
         
         (getHeight() -1) * (getImageNumberStored() / 2), 
         
         BufferedImage.TYPE_INT_ARGB
      );
       
      combinedImageGraphics = combinedImage.createGraphics();
   }
   
   
   
   /**
    * Writes the horizontal image graphic.
    */
   public void writeHorizontalStack()
   {
      final short firstTranslation = 0; final short secondTranslation = 1; 
      
      final short thirdTranslation = 2; final short fourthTranslation = 3;
   
   
      if (getStoredTemplate(0) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(0), (getWidth() -1) * firstTranslation, 0, null);
      }
      
      if (getStoredTemplate(1) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(1), (getWidth() -1) * secondTranslation, 0, null);
      }
      
      if (getStoredTemplate(2) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(2), (getWidth() -1) * thirdTranslation , 0, null);
      }
      
      if (getStoredTemplate(3) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(3), (getWidth() -1) * fourthTranslation , 0, null);
      }
   }
   
   
   
   /**
    * Writes the vertical image graphic.
    */
   public void writeVerticalStack()
   {
      final short firstTranslation = 0; final short secondTranslation = 1; 
      
      final short thirdTranslation = 2; final short fourthTranslation = 3;
   
   
      if (getStoredTemplate(0) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(0), 0, (getHeight() -1) * firstTranslation, null);
      }
      
      if (getStoredTemplate(1) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(1), 0, (getHeight() -1) * secondTranslation, null);
      }
      
      if (getStoredTemplate(2) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(2), 0, (getHeight() -1) * thirdTranslation, null);
      }
      
      if (getStoredTemplate(3) != null)
      {
         combinedImageGraphics.drawImage
         (getStoredEdited(3), 0, (getHeight() -1) * fourthTranslation, null);
      }
   }
   
   
   
   /**
    * Writes the grid image graphic.
    */
   public void writeGridStack()
   {
      final short firstTranslation = 0; final short secondTranslation = 1;
   
      
      if (isStorageFilled())
      {
         combinedImageGraphics.drawImage
         (
            getStoredEdited(0), (getWidth() -1) * firstTranslation, 
            
            (getHeight() -1) * firstTranslation, null
         );
         
         combinedImageGraphics.drawImage
         (
            getStoredEdited(1), (getWidth() -1) * secondTranslation, 
            
            (getHeight() -1) * firstTranslation, null
         );
         
         combinedImageGraphics.drawImage
         (
            getStoredEdited(2), (getWidth() -1) * firstTranslation,
            
            (getHeight() -1) * secondTranslation, null
         );
         
         combinedImageGraphics.drawImage 
         (
            getStoredEdited(3), (getWidth() -1) * secondTranslation,
            
            (getHeight() -1) * secondTranslation, null
         );  
      }
   }
   
   
   
   /**
    * Saves the shape graphic to the desktop.
    * @param image
    * @param name
    * @throws Exception
    */
   public void saveShapeImage(BufferedImage image, String name) throws Exception
   {
      PATH = Tools.returnDesktopPath();
   
      Iterator imageWriters = ImageIO.getImageWritersByFormatName(getImageFormat()); 
      
      ImageWriter imageWriter = (ImageWriter) imageWriters.next();
   
      
      File file = new File(PATH + name + "." + getImageFormat());
      
      ImageOutputStream ios = ImageIO.createImageOutputStream(file); 
      
      imageWriter.setOutput(ios); imageWriter.write(image);
      
      ios.close();
 
   }
   
   
   
   /**
    * Clones the template backdrop to the edited image.
    * @param image
    */
   public void cloneTemplate(int image)
   {

      ColorModel model = storedTemplate[image].getColorModel();
      
      boolean isAlphaPremultiplied = model.isAlphaPremultiplied();
      
      WritableRaster raster = storedTemplate[image].copyData(null);
      
      
      storedEdited[image] = 
     
      new BufferedImage(model, raster, isAlphaPremultiplied, null);
      
      
      storedImageGraphics = 
      
      (storedEdited[image]).createGraphics();
      
   }
   
   
   
   /**
    * Adds text to the buffered image.
    * @param text
    * @param name
    * @param color
    * @param style
    * @param size
    * @param locationX
    * @param locationY
    */
   public void addTextStoredImage(String text, String name, 
   Color color, String style, int size, int locationX, int locationY)
   {
      storedImageGraphics.setPaint(color);
      
      storedImageGraphics.setFont(new Font(name, getFontStyle(style), size));
     
      storedImageGraphics.drawString(text, locationX, locationY);

   }
   
   
   
   /**
    * Adds the rectangle border.
    * ESCA-JAVA0029:
    * @param weight
    * @param roundFactor
    */
   public void addRectangleBorder(int weight, int roundFactor)
   {
      setBorderCorrectionFactors(weight);
  
      stroke = new BasicStroke(weight);
      
      bufferedImageGraphics.setStroke(stroke);
      
      
      if (roundFactor > 0)
      {
         bufferedImageGraphics.draw
         (
            new RoundRectangle2D.Double
            (
               getBorderStartFactor(), getBorderStartFactor(), getWidth() - getBorderEndFactor(), 
               
               getHeight() - getBorderEndFactor(), roundFactor, roundFactor
            )
         );
      }
      
      else
      {
         bufferedImageGraphics.draw
         (
            new Rectangle2D.Double
            (
               getBorderStartFactor(), getBorderStartFactor(),
               
               getWidth() - getBorderEndFactor(), getHeight() - getBorderEndFactor()
            )
         );
      }
   }
   
   
   
   /**
    * Adds anti aliasing to smooth border.
    * @param on
    */
   public void antialias(boolean on)
   {
      if (on)
      {
         bufferedImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
      
         RenderingHints.VALUE_ANTIALIAS_ON); 
      }
  
      else
      {
         bufferedImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        
         RenderingHints.VALUE_ANTIALIAS_OFF); 
      } 
   }
   
   
   
   /**
    * Sets the gradient fill.
    * @param start
    * @param end
    * @param startX
    * @param startY
    * @param endX
    * @param endY
    */
   public void setGradient(Color start, Color end, 
   int startX, int startY, int endX, int endY)
   {
      GradientPaint gradient = 
   
      new GradientPaint(startX, startY, start, endX, endY, end);
     
      bufferedImageGraphics.setPaint(gradient); 
   }
   
   
   
   /**
    * Fills a rectangle without a round corner.
    */
   public void fillRectangleSharp()
   { 
      bufferedImageGraphics.fill
      (
         new Rectangle2D.Double
         (
            0, 0, getWidth() -1, getHeight() -1
         )
      );   
   }
   
   
   
   /**
    * Fills a rectangle with a round corner.
    * @param roundFactor
    */
   public void fillRectangleRound(int roundFactor)
   { 
      bufferedImageGraphics.fill
      (
         new RoundRectangle2D.Double
         (
            0, 0, getWidth() -1, getHeight() -1, roundFactor, roundFactor
         )
      );   
   }
   
   
  
   /**
    * Fills an oval.
    */
   public void fillOval()
   {
      bufferedImageGraphics.fill
      (
         new Ellipse2D.Double
         (
            0, 0, getWidth() -1, getHeight() -1
         )
      );  
   }
   
   
   
   /**
    * Adds the oval border.
    * ESCA-JAVA0029:
    * @param weight
    */
   public void addOvalBorder(int weight)
   {  
      stroke = new BasicStroke(weight); 
      
      bufferedImageGraphics.setStroke(stroke);
      
      double fact = weight / 2.0;
      
      
      bufferedImageGraphics.draw
      (
         new Ellipse2D.Double
         (
            fact, fact, getWidth() - weight -1, getHeight() - weight -1
         )
      );  
   }
   
   
   
   /**
    * Adds text to the buffered image.
    * @param text
    * @param name
    * @param color
    * @param style
    * @param size
    * @param locationX
    * @param locationY
    */
   public void addTextBufferedImage(String text, String name, 
   Color color, String style, int size, int locationX, int locationY)
   {
      bufferedImageGraphics.setPaint(color);
      
      bufferedImageGraphics.setFont(new Font(name, getFontStyle(style), size));
     
      bufferedImageGraphics.drawString(text, locationX, locationY);

   }
   
   
   
   /**
    * Store the current image graphic.
    */
   public void storeImage()
   {
      if (getStoredTemplate(0) == null)
      {
         setStoredTemplate(getBufferedImage(), 0);
         
         setStoredEdited(getBufferedImage(), 0);
      }
      
      else if (getStoredTemplate(1) == null)
      {
         setStoredTemplate(getBufferedImage(), 1);
         
         setStoredEdited(getBufferedImage(), 1);
       
      }
      
      else if (getStoredTemplate(2) == null)
      {
         setStoredTemplate(getBufferedImage(), 2);
         
         setStoredEdited(getBufferedImage(), 2);
       
      }
      
      else if (getStoredTemplate(3) == null)
      {
         setStoredTemplate(getBufferedImage(), 3);
         
         setStoredEdited(getBufferedImage(), 3);
         
      }
   }
   
   
   
   /**
    * Clears the stored images.
    */
   public void clearStoredImages()
   {
      setStoredTemplate(null, 0); setStoredTemplate(null, 1);
      
      setStoredTemplate(null, 2); setStoredTemplate(null, 3);
      
      setStoredEdited(null, 0); setStoredEdited(null, 1);
      
      setStoredEdited(null, 2); setStoredEdited(null, 3);
      
     
   }
   
   
   
   /**
    * Set bufferedImageGraphics border color.
    * @param color
    */
   public void setGraphicsBorderColor(Color color)
   {
      borderShade = color;
      
      bufferedImageGraphics.setColor(borderShade);
   }
   
   
   
   /**
    * Set graphics body color.
    * @param color
    */
   public void setGraphicsBodyColor(Color color)
   {
      bodyShade = color;
      
      bufferedImageGraphics.setColor(bodyShade);
   }
   
   
   
   /**
    * Defines the size of the button.
    * @param sizeX
    * @param sizeY
    */
   public void setSize(int sizeX, int sizeY)
   {
      setRows(sizeX); setColumns(sizeY); 
      
      initialiseBufferedImage();
   }
   
   
   
   /**
    * Returns the stored images.
    * @param cycle
    * @return
    */
   public BufferedImage cycleStoredTemplate(int cycle)
   {
      
        return getStoredTemplate(cycle);
         
     
   }
   
   
   
   /**
    * Returns the stored images.
    * @param cycle
    * @return
    */
   public BufferedImage cycleStoredEdited(int cycle)
   {
      
        return getStoredEdited(cycle);
         
     
   }
   
   
   
   /**
    * Tests if all buffered images for storage are used.
    * @return
    */
   public boolean isStorageFilled()
   {
      if ((getStoredTemplate(0) != null) && (getStoredTemplate(1) != null)
      && (getStoredTemplate(2) != null) && (getStoredTemplate(3) != null))
      {
         return true;
      }
      
      else {return false;}
   }
   
   
   
   /**
    * Tests if some buffered images for storage are used.
    * @return
    */
   public boolean isStorageOccupied()
   {
      if ((getStoredTemplate(0) != null) || (getStoredTemplate(1) != null)
      || (getStoredTemplate(2) != null) || (getStoredTemplate(3) != null))
      {
         return true;
      }
      
      else {return false;}
   }
   
   
   
   /**
    * Returns the number of images stored.
    * @return
    */
   public int getImageNumberStored()
   {
      int stored = 0;
      
      if (getStoredTemplate(0) != null) {stored ++;}
      
      if (getStoredTemplate(1) != null) {stored ++;}
      
      if (getStoredTemplate(2) != null) {stored ++;}
      
      if (getStoredTemplate(3) != null) {stored ++;}
      
      
      return stored;
   }
   
   
   
   /**
    * Sets the stored template image.
    * @param image
    * @param index
    */
   public void setStoredTemplate(BufferedImage image, int index)
   {
      storedTemplate[index] = image;
   }
   
   
   
   /**
    * Sets the stored edited image.
    * @param image
    * @param index
    */
   public void setStoredEdited(BufferedImage image, int index)
   {
      storedEdited[index] = image;
   }
   
   
   
   /**
    * Sets the rows in the shape array.
    * @param size
    */
   public void setRows(int size) {if (size <=0) {size = MINIMUM_SIZE;} rows = size;}
   
   
   
   /**
    * Sets the columns in the shape array.
    * @param size
    */
   public void setColumns(int size) {if (size <= 0) {size = MINIMUM_SIZE;} columns = size;}
   
   
   
   /**
    * Set image format.
    * @param format
    */
   public void setImageFormat(String format) {imageFormat = format;}
   

   
   
   /**
    * Gets the rows in the shape array.
    * @return rows
    */
   public int getWidth() {return rows;}
   
   
   
   /**
    * Gets the columns in the shape array.
    * @return columns
    */
   public int getHeight() {return columns;}
   
   
   
   /**
    * Returns the buffered image.
    * @return
    */
   public BufferedImage getBufferedImage() {return bufferedImage;}
   
   
   
   /**
    * Returns the combined image.
    * @return
    */
   public BufferedImage getCombinedImage() {return combinedImage;}
   
   
   
   /**
    * Returns the stored template image.
    * @param index
    * @return
    */
   public BufferedImage getStoredTemplate(int index)
   {
      return storedTemplate[index];
   }
   
   
   
   /**
    * Returns the stored edited image.
    * @param index
    * @return
    */
   public BufferedImage getStoredEdited(int index)
   {
      return storedEdited[index];
   }
   
   
   //***************************************** END PUBLIC METHODS ******************************************//
   
   
   //**************************************** START PRIVATE METHODS ****************************************//
   
   
   /**
    * Converts the style into its integer.
    * @param style
    * @return
    */
   private static int getFontStyle(String style)
   {
      int styleAsInt = 0;
      
      
      if (style.equals("Plain")) {styleAsInt = 0;}
      
      if (style.equals("Bold")) {styleAsInt = 1;}
      
      if (style.equals("Italic")) {styleAsInt = 2;}
      
      if (style.equals("Bold Italic")) {styleAsInt = 3;}
      
      
      return styleAsInt;   
   }
   
   
   
   /**
    * Returns the correct border correction factors.
    * ESCA-JAVA0076:
    * @param value
    */
   private void setBorderCorrectionFactors(int value)
   {
      switch (value)
      {
         case 1: setBorderStartFactor(0); setBorderEndFactor(2); break;
         
         case 2: setBorderStartFactor(1); setBorderEndFactor(4); break;
         
         case 3: setBorderStartFactor(1); setBorderEndFactor(4); break;
         
         case 4: setBorderStartFactor(2); setBorderEndFactor(6); break;
         
         case 5: setBorderStartFactor(2); setBorderEndFactor(6); break;
         
         case 6: setBorderStartFactor(3); setBorderEndFactor(8); break;
         
         case 7: setBorderStartFactor(3); setBorderEndFactor(8); break;
         
         case 8: setBorderStartFactor(4); setBorderEndFactor(10); break;
         
         case 9: setBorderStartFactor(4); setBorderEndFactor(10); break;
         
         default: break;
      }
   }
 
   
   
   /**
    * Sets the border start factor.
    * @param value
    */
   private void setBorderStartFactor(int value) {borderStartFactor = value;}
   
   
   
   /**
    * Sets the border end factor.
    * @param value
    */
   private void setBorderEndFactor(int value) {borderEndFactor = value;}
   
   
   
   /**
    * Gets the image format.
    * @return
    */
   private String getImageFormat() {return imageFormat;}
   
   
   
   /**
    * Returns the border start factor.
    * @return
    */
   private int getBorderStartFactor() {return borderStartFactor;}
   
   
  
   /**
    * Returns the border end horizontal factor.
    * @return
    */
   private int getBorderEndFactor() {return borderEndFactor;}
   
   
   //***************************************** END PRIVATE METHODS *****************************************//
   
   
   private String imageFormat;
   private BasicStroke stroke;
   private Color bodyShade, borderShade;
   
   private BufferedImage bufferedImage, combinedImage;
   
   private int rows, columns, borderStartFactor, borderEndFactor;
  
   private Graphics2D bufferedImageGraphics, combinedImageGraphics, storedImageGraphics;
   
   private BufferedImage[] storedTemplate = new BufferedImage[STORE_ARRAY_SIZE];
   
   private BufferedImage[] storedEdited = new BufferedImage[STORE_ARRAY_SIZE];
   
   
   //********************************************** 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 **********************************************//
   
}