/*

 * 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.awt.event.KeyEvent;

import java.util.ResourceBundle;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;


/** Pops up a menu with the dufferent vertex types whenever the user
 * right clicks on the vertex button.
 */
public class JaxoVertexPopupMenu extends JPopupMenu implements ActionListener {
    private ResourceBundle language =
        ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
    private JaxoMainPanel thePanel;
    private JRadioButtonMenuItem type1BT;
    private JRadioButtonMenuItem type2BT;
    private JRadioButtonMenuItem type3BT;
    private JRadioButtonMenuItem type4BT;
    private JRadioButtonMenuItem type5BT;
    private JRadioButtonMenuItem type6BT;
    private ButtonGroup vertexGroup;

    /** Constructs a new popup menu from the specified panel.
     * @param mainPanel The parent JaxoMainPanel.
     */
    public JaxoVertexPopupMenu(JaxoMainPanel mainPanel) {
        this.thePanel = mainPanel;

        vertexGroup = new ButtonGroup();
        type1BT =
            new JRadioButtonMenuItem(language.getString("Dot"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT1.png")));
        type1BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
                ActionEvent.SHIFT_MASK));
        type2BT =
            new JRadioButtonMenuItem(language.getString("Circle_cross"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT2.png")));
        type2BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
                ActionEvent.SHIFT_MASK));
        type3BT =
            new JRadioButtonMenuItem(language.getString("Square"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT3.png")));
        type3BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                ActionEvent.SHIFT_MASK));
        type4BT =
            new JRadioButtonMenuItem(language.getString("Cross"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT4.png")));
        type4BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
                ActionEvent.SHIFT_MASK));
        type5BT =
            new JRadioButtonMenuItem(language.getString("Triangle"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT5.png")));
        type5BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
                ActionEvent.SHIFT_MASK));
        type6BT =
            new JRadioButtonMenuItem(language.getString("Diamond"),
                new ImageIcon(JaxoOptionsMenu.class.getClassLoader()
                                                   .getResource("japlot/jaxodraw/icons/vertexsT6.png")));
        type6BT.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,
                ActionEvent.SHIFT_MASK));

        type1BT.addActionListener(this);
        type1BT.setActionCommand("Dot");
        type1BT.setSelected(true);
        type2BT.addActionListener(this);
        type2BT.setActionCommand("Circle_cross");
        type3BT.addActionListener(this);
        type3BT.setActionCommand("Square");
        type4BT.addActionListener(this);
        type4BT.setActionCommand("Cross");
        type5BT.addActionListener(this);
        type5BT.setActionCommand("Triangle");
        type6BT.addActionListener(this);
        type6BT.setActionCommand("Diamond");

        vertexGroup.add(type1BT);
        vertexGroup.add(type2BT);
        vertexGroup.add(type3BT);
        vertexGroup.add(type4BT);
        vertexGroup.add(type5BT);
        vertexGroup.add(type6BT);

        this.add(type1BT);
        this.add(type2BT);
        this.add(type3BT);
        this.add(type4BT);
        this.add(type5BT);
        this.add(type6BT);
    }

    /** Specifies the action to be taken when an item from the menu
     * has been selected.
     * @param evt The event to be processed.
     */
    public final void actionPerformed(ActionEvent evt) {
        AbstractButton source = (AbstractButton) evt.getSource();

        if (source.getActionCommand().equals("Dot")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT1);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT1.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT1);
        } else if (source.getActionCommand().equals("Circle_cross")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT2);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT2.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT2);
        } else if (source.getActionCommand().equals("Square")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT3);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT3.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT3);
        } else if (source.getActionCommand().equals("Cross")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT4);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT4.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT4);
        } else if (source.getActionCommand().equals("Triangle")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT5);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT5.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT5);
        } else if (source.getActionCommand().equals("Diamond")) {
            thePanel.setVertexType(JaxoMainPanel.VERTEXT6);
            thePanel.getMbtPanel().getVertexButton().setIcon(new ImageIcon(
                    JaxoOptionsMenu.class.getClassLoader().getResource("japlot/jaxodraw/icons/vertexT6.png")));
            thePanel.getMbtPanel().getVertexButton().doClick();
            thePanel.getOptMenu().setPopVT(JaxoMainPanel.VERTEXT6);
        }
    }

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

        type1BT.setText(language.getString("Dot"));
        type2BT.setText(language.getString("Circle_cross"));
        type3BT.setText(language.getString("Square"));
        type4BT.setText(language.getString("Cross"));
        type5BT.setText(language.getString("Triangle"));
        type6BT.setText(language.getString("Diamond"));
    }

    /** Sets the radio button to the current vertex type in the pop-up menu.
     * @param popvt Specifies the current vertex type.
     */
    public final void setPopupVT(int popvt) {
        if (popvt == JaxoMainPanel.VERTEXT1) {
            type1BT.setSelected(true);
        } else if (popvt == JaxoMainPanel.VERTEXT2) {
            type2BT.setSelected(true);
        } else if (popvt == JaxoMainPanel.VERTEXT3) {
            type3BT.setSelected(true);
        } else if (popvt == JaxoMainPanel.VERTEXT4) {
            type4BT.setSelected(true);
        } else if (popvt == JaxoMainPanel.VERTEXT5) {
            type5BT.setSelected(true);
        } else if (popvt == JaxoMainPanel.VERTEXT6) {
            type6BT.setSelected(true);
        }
    }
}

 

Ads help maintain this website.