/*

 * Title: japlot.jaxodraw
 * Description: Graphical user interface for drawing Feynman diagrams
 * @author Daniele Binosi 
 * @author Lukas Theussl  

 Copyright (C) 2003-2006,  Daniele Binosi and Lukas Theussl

 See the file LICENSE in the source distribution home directory
 for a full copy of the GPL (GNU General Public License).

    This file is part of japlot.jaxodraw.

    japlot.jaxodraw is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    japlot.jaxodraw is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 */
package japlot.jaxodraw;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.ResourceBundle;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;


/** A class that displays a pop-up menu if the user right-clicks on a tab. */
public class JaxoZoomPopupMenu extends JPopupMenu implements ActionListener {
    private ResourceBundle language =
        ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
    private JaxoMainPanel thePanel;
    private JMenu zoomFactorM;
    private JRadioButtonMenuItem zoomBFactor1;
    private JRadioButtonMenuItem zoomBFactor2;
    private JRadioButtonMenuItem zoomBFactor3;
    private ButtonGroup zoomFactorGroup;
    private static final int ZOOM_FACTOR_X2 = 2;
    private static final int ZOOM_FACTOR_X4 = 4;
    private static final int ZOOM_FACTOR_X8 = 8;

    /** Constructor: sets all the menu entries and the action listeners.
     * @param mainPanel Instance of the main panel.
     */
    public JaxoZoomPopupMenu(JaxoMainPanel mainPanel) {
        this.thePanel = mainPanel;

        zoomFactorM = new JMenu(language.getString("Zoom_factor"));
        zoomFactorM.addActionListener(this);
        zoomFactorM.setActionCommand("ZoomFactor");

        zoomFactorGroup = new ButtonGroup();

        zoomBFactor1 = new JRadioButtonMenuItem("2x");
        zoomBFactor1.addActionListener(this);
        zoomBFactor1.setActionCommand("2x");
        zoomBFactor2 = new JRadioButtonMenuItem("4x");
        zoomBFactor2.addActionListener(this);
        zoomBFactor2.setActionCommand("4x");
        zoomBFactor3 = new JRadioButtonMenuItem("8x");
        zoomBFactor3.addActionListener(this);
        zoomBFactor3.setActionCommand("8x");

        zoomFactorGroup.add(zoomBFactor1);
        zoomFactorGroup.add(zoomBFactor2);
        zoomFactorGroup.add(zoomBFactor3);
        zoomFactorM.add(zoomBFactor1);
        zoomFactorM.add(zoomBFactor2);
        zoomFactorM.add(zoomBFactor3);

        zoomBFactor1.setSelected(true);

        this.add(zoomFactorM);
    }

    /** Performs the corresponding action if one of the menu entries
     * has been selected.
     * @param evt The action event that specifies the chosen menu item
     */
    public final void actionPerformed(ActionEvent evt) {
        AbstractButton source = (AbstractButton) evt.getSource();

        JaxoZoom zoom = thePanel.getZoom();

        if (source.getActionCommand().equals("2x")) {
            zoom.setZoomFactor(ZOOM_FACTOR_X2);
        } else if (source.getActionCommand().equals("4x")) {
            zoom.setZoomFactor(ZOOM_FACTOR_X4);
        } else if (source.getActionCommand().equals("8x")) {
            zoom.setZoomFactor(ZOOM_FACTOR_X8);
        }
    }

    /** Sets the text for the entries in the popup menu in different languages.
     * @param languageString A string specifying the language to be set.
     */
    public final void setLanguage(String languageString) {
        language = ResourceBundle.getBundle(languageString);
        zoomFactorM.setText(language.getString("Zoom_factor"));
    }
}

 

Ads help maintain this website.