/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.pdfbox.tools.pdfdebugger.ui;

import java.awt.Component;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;

/**
 * @author Khyrul Bashar
 */
public class ZoomMenu
{
    public static final String ZOOM_50_PERCENT = "50%";
    public static final String ZOOM_100_PERCENT = "100%";
    public static final String ZOOM_200_PERCENT = "200%";

    private static ZoomMenu instance;
    private JMenu menu = null;
    private JRadioButtonMenuItem zoom50Item;
    private JRadioButtonMenuItem zoom100Item;
    private JRadioButtonMenuItem zoom200Item;

    private ZoomMenu()
    {
        menu = createZoomMenu();
    }

    public static ZoomMenu getInstance()
    {
        if (instance == null)
        {
            instance = new ZoomMenu();
        }
        return instance;
    }

    public JMenu getMenu()
    {
        return this.menu;
    }

    public void setEnableMenu(boolean isEnable)
    {
        menu.setEnabled(isEnable);
    }

    public ZoomMenu menuListeners(ActionListener listener)
    {
        for (Component comp: menu.getMenuComponents())
        {
            JMenuItem menuItem = (JMenuItem) comp;
            removeActionListeners(menuItem);
            menuItem.addActionListener(listener);
        }
        return instance;
    }

    public void setZoomSelection(String selection)
    {
        if (ZOOM_50_PERCENT.equals(selection))
        {
            zoom50Item.setSelected(true);
        }
        else if (ZOOM_100_PERCENT.equals(selection))
        {
            zoom100Item.setSelected(true);
        }
        else if (ZOOM_200_PERCENT.equals(selection))
        {
            zoom200Item.setSelected(true);
        }
        else
        {
            throw new IllegalArgumentException();
        }
    }

    private void removeActionListeners(JMenuItem menuItem)
    {
        for (ActionListener listener: menuItem.getActionListeners())
        {
            menuItem.removeActionListener(listener);
        }
    }

    private JMenu createZoomMenu()
    {
        menu = new JMenu();
        menu.setText("Zoom");

        zoom50Item = new JRadioButtonMenuItem();
        zoom100Item = new JRadioButtonMenuItem();
        zoom200Item = new JRadioButtonMenuItem();
        zoom100Item.setSelected(true);

        ButtonGroup bg = new ButtonGroup();
        bg.add(zoom50Item);
        bg.add(zoom100Item);
        bg.add(zoom200Item);

        zoom50Item.setText(ZOOM_50_PERCENT);
        zoom100Item.setText(ZOOM_100_PERCENT);
        zoom200Item.setText(ZOOM_200_PERCENT);

        menu.add(zoom50Item);
        menu.add(zoom100Item);
        menu.add(zoom200Item);

        return menu;
    }
}

@@ -1070,16 +1070,261 @@
  Bashar%0A
+ *%0A * A singleton class that provides zoom menu which can be used to show zoom menu in the menubar.%0A * To act upon the menu item selection user of the class must add ActionListener which will check for%0A * the action command and act accordingly.%0A
  */%0Apubl
@@ -1723,16 +1723,52 @@
 0Item;%0A%0A
+    /**%0A     * Constructor.%0A     */%0A
     priv
@@ -1820,32 +1820,121 @@
 mMenu();%0A    %7D%0A%0A
+    /**%0A     * Provides the ZoomMenu instance.%0A     * @return ZoomMenu instance.%0A     */%0A
     public stati
@@ -2093,165 +2093,516 @@
     
-public JMenu getMenu()%0A    %7B%0A        return this.menu;%0A    %7D%0A%0A    public void setEnableMenu(boolean isEnable)%0A    %7B%0A        menu.setEnabled(isEnable);%0A    %7D%0A
+/**%0A     * Provide the JMenu instance of the ZoomMenu.%0A     * @return JMenu instance.%0A     */%0A    public JMenu getMenu()%0A    %7B%0A        return this.menu;%0A    %7D%0A%0A    /**%0A     * Set if the menu should be enabled or disabled.%0A     * @param isEnable boolean instance.%0A     */%0A    public void setEnableMenu(boolean isEnable)%0A    %7B%0A        menu.setEnabled(isEnable);%0A    %7D%0A%0A    /**%0A     * Add the ActionListener for the menuitems.%0A     * @param listener ActionListener.%0A     * @return the ZoomMenu instance.%0A     */
 %0A   
@@ -2912,24 +2912,112 @@
 nce;%0A    %7D%0A%0A
+    /**%0A     * Set the zoom selection.%0A     * @param selection String instance.%0A     */%0A
     public v

add javadocs, as done by Khyrul Bashar in GSoC2015