/*
* 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.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
/** Responsible for displaying and modifying the buttons of the action
* button menu.
*/
public class JaxoActionButtons extends JPanel implements ActionListener {
private static final String[] ACTION_BUTTON_ICONS =
{"japlot/jaxodraw/icons/undo.png", "japlot/jaxodraw/icons/clear.png", "japlot/jaxodraw/icons/refresh.png"};
private JaxoMainPanel thePanel;
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private int anbts = 3;
private JButton[] actionButtons = new JButton[anbts];
private String[] actionTips =
{
language.getString("Undo_the_last_operation"),
language.getString("Clear_the_screen"),
language.getString("Refresh_the_Screen")
};
private Border raisedetched =
BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
//private Border loweredetched =
// BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
private Border raisedbevel = BorderFactory.createRaisedBevelBorder();
/** Constructor: lays out the action button panel.
* @param mainPanel The JaxoMainPanel that holds this button panel.
*/
public JaxoActionButtons(JaxoMainPanel mainPanel) {
this.thePanel = mainPanel;
JPanel actionButtonPanel = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
actionButtonPanel.setLayout(gridbag);
for (int i = 0; i < anbts; i++) {
actionButtons[i] = new JButton();
actionButtons[i].setIcon(new ImageIcon(JaxoActionButtons.class.getClassLoader()
.getResource(ACTION_BUTTON_ICONS[i])));
actionButtons[i].setToolTipText(actionTips[i]);
actionButtons[i].addActionListener(this);
actionButtons[i].setMinimumSize(new Dimension(40, 40));
actionButtons[i].setPreferredSize(new Dimension(40, 40));
actionButtons[i].setBorder(raisedbevel);
actionButtons[i].setFocusPainted(false);
}
for (int j = 0; j < 1; j++) {
for (int i = 0; i < 3; i++) {
c.gridx = i;
c.gridy = j;
gridbag.setConstraints(actionButtons[i + (3 * j)], c);
actionButtonPanel.add(actionButtons[i + (3 * j)]);
}
}
JPanel finalActionButtonPanel = new JPanel();
finalActionButtonPanel.setLayout(new BorderLayout());
finalActionButtonPanel.setBorder(raisedetched);
finalActionButtonPanel.add(actionButtonPanel, BorderLayout.CENTER);
setLayout(new GridLayout(0, 1));
add(finalActionButtonPanel);
}
/** Executes the appropriate action when a button is pressed.
* @param evt the action event to be processed.
*/
public final void actionPerformed(ActionEvent evt) {
for (int i = 0; i < anbts; i++) {
if (evt.getSource() == actionButtons[i]) {
thePanel.actionEvent(getActionEvent(i));
}
}
}
/** Sets all the buttons as not pressed. */
public final void reset() {
for (int i = 0; i < anbts; i++) {
setButtonBorder(i, raisedbevel);
setButtonBackground(i, null);
}
}
/** Returns the number of buttons in the action button menu.
* @return The number of buttons in the action button menu.
*/
public final int getanbts() {
return anbts;
}
/** Sets the background color of button i to the color bgColor.
* @param i The index of the botton, whose background color is to be set.
* @param bgColor The color to be set.
*/
public final void setButtonBackground(int i, Color bgColor) {
actionButtons[i].setBackground(bgColor);
}
/** Sets the border of the button with index i to the specified border.
* @param i The index of the botton, whose border is to be set.
* @param border The border to be set.
*/
public final void setButtonBorder(int i, Border border) {
actionButtons[i].setBorder(border);
}
/** Sets the tool tip text for the action buttons in different languages.
* @param languageString A string specifying the language to be set.
*/
public final void setLanguage(String languageString) {
language = ResourceBundle.getBundle(languageString);
actionTips[0] = language.getString("Undo_the_last_operation");
actionTips[1] = language.getString("Clear_the_screen");
actionTips[2] = language.getString("Refresh_the_Screen");
for (int i = 0; i < anbts; i++) {
actionButtons[i].setToolTipText(actionTips[i]);
}
}
/** Returns the index of the corresponding event in the JaxoMainPanel for
* the toolbar button i.
* @param i The button whose index is to be returned.
* @return The index of the button i.
*/
public final int getActionEvent(int i) {
int actionEvent = anbts + 1;
if (i == 0) {
actionEvent = JaxoMainPanel.UNDO;
}
if (i == 1) {
actionEvent = JaxoMainPanel.CLEAR;
}
if (i == 2) {
actionEvent = JaxoMainPanel.REFRESH;
}
return actionEvent;
}
}
Ads help maintain this website.