/*
* 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
* edit button menu.
*/
public class JaxoEditButtons extends JPanel implements ActionListener {
private static final String[] EDIT_BUTTON_ICONS =
{
"japlot/jaxodraw/icons/move.png", "japlot/jaxodraw/icons/resize.png", "japlot/jaxodraw/icons/copy.png",
"japlot/jaxodraw/icons/color.png", "japlot/jaxodraw/icons/edit.png", "japlot/jaxodraw/icons/delete.png",
"japlot/jaxodraw/icons/back.png", "japlot/jaxodraw/icons/fore.png", "japlot/jaxodraw/icons/group.png",
"japlot/jaxodraw/icons/ungroup.png", "japlot/jaxodraw/icons/empty.png", "japlot/jaxodraw/icons/empty.png"
};
private static final int[] EDIT_MODES =
{
JaxoMainPanel.MOVE, JaxoMainPanel.RESIZE, JaxoMainPanel.COPY,
JaxoMainPanel.COLOR, JaxoMainPanel.EDIT, JaxoMainPanel.DELETE,
JaxoMainPanel.BACKGROUND, JaxoMainPanel.FOREGROUND, JaxoMainPanel.GROUP,
JaxoMainPanel.UNGROUP, JaxoMainPanel.DUMMIE, JaxoMainPanel.DUMMIE1
};
private JaxoMainPanel thePanel;
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private int enbts = 12;
private JButton[] editButtons = new JButton[enbts];
private String[] editFlagModes =
{
language.getString("Move"), language.getString("Resize"),
language.getString("Copy"), language.getString("Color"),
language.getString("Edit"), language.getString("Delete"),
language.getString("Background"), language.getString("Foreground"),
language.getString("group"), language.getString("Ungroup"), "?1", "?2"
};
private String[] editTips =
{
language.getString("Move_an_object"),
language.getString("Resize_an_object"),
language.getString("Copy_an_object"),
language.getString("Color_an_object"),
language.getString("Edit_an_object"),
language.getString("Delete_an_object"),
language.getString("Put_an_object_in_the_background"),
language.getString("Put_an_object_in_the_foreground"),
language.getString("Group_objects"),
language.getString("Ungroup_objects"), "", ""
};
// private JaxoPopupListener popupListener;
private Border raisedetched =
BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
private Border raisedbevel = BorderFactory.createRaisedBevelBorder();
private Border loweredbevel = BorderFactory.createLoweredBevelBorder();
/** Constructor: lays out the edit button panel.
* @param mainPanel The JaxoMainPanel that holds this button panel.
*/
public JaxoEditButtons(JaxoMainPanel mainPanel) {
this.thePanel = mainPanel;
JPanel editButtonPanel = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
editButtonPanel.setLayout(gridbag);
for (int i = 0; i < enbts; i++) {
editButtons[i] = new JButton();
editButtons[i].setIcon(new ImageIcon(JaxoEditButtons.class.getClassLoader()
.getResource(EDIT_BUTTON_ICONS[i])));
editButtons[i].setToolTipText(editTips[i]);
editButtons[i].addActionListener(this);
editButtons[i].setMinimumSize(new Dimension(40, 40));
editButtons[i].setPreferredSize(new Dimension(40, 40));
editButtons[i].setBorder(raisedbevel);
editButtons[i].setFocusPainted(false);
}
for (int j = 0; j < (enbts / 3); j++) {
for (int i = 0; i < 3; i++) {
c.gridx = i;
c.gridy = j;
gridbag.setConstraints(editButtons[i + (3 * j)], c);
editButtonPanel.add(editButtons[i + (3 * j)]);
}
}
editButtons[10].setEnabled(false);
editButtons[11].setEnabled(false);
JPanel finalEditButtonPanel = new JPanel();
finalEditButtonPanel.setLayout(new BorderLayout());
finalEditButtonPanel.setBorder(raisedetched);
finalEditButtonPanel.add(editButtonPanel, BorderLayout.CENTER);
setLayout(new GridLayout(0, 1));
add(finalEditButtonPanel);
}
/** 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 < enbts; i++) {
if (evt.getSource() == editButtons[i]) {
thePanel.editEvent(EDIT_MODES[i]);
}
}
}
/** Sets all the buttons as not pressed. */
public final void reset() {
for (int i = 0; i < enbts; i++) {
setButtonBorder(i, raisedbevel);
setButtonBackground(i, null);
editButtons[i].setFocusPainted(false);
}
}
/** Returns the index of the edit button corresponding to the edit event i.
* @param i An edit event as defined in the JaxoMainPanel.
* @return The index of the edit button corresponding to the edit event i.
*/
public final int getIndex(int i) {
int j = enbts + 1;
for (int jj = 0; jj < enbts; jj++) {
if (i == EDIT_MODES[jj]) {
j = jj;
}
}
return j;
}
/** Sets the specified button as pressed.
* @param j The index of the button to be pressed.
*/
public final void pressButton(int j) {
setButtonBackground(j, new Color(170, 170, 180));
setButtonBorder(j, loweredbevel);
editButtons[j].setFocusPainted(false);
//editButtons[j].setSelected(true);
}
/** Returns a String with the text to be set in the flag panel
* indicating the current edit mode.
* @param i The index of the edit button, corresponding to the mode
* to be returned.
* @return The String containing the text to be set in the flag panel
* indicating the current edit mode.
*/
public final String getEditFlagModes(int i) {
return editFlagModes[i];
}
/** Returns the number of buttons in the edit button menu.
* @return The number of buttons in the edit button menu.
*/
public final int getenbts() {
return enbts;
}
/** Sets the background color of the button with index 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) {
editButtons[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) {
editButtons[i].setBorder(border);
}
/** Does a clcik on the button with index i.
* @param i The index of the botton to click.
*/
public final void clickButton(int i) {
editButtons[i].doClick();
}
/** Sets the tool tip text for the edit buttons and the flag modes
* in different languages.
* @param languageString A string specifying the language to be set.
*/
public final void setLanguage(String languageString) {
language = ResourceBundle.getBundle(languageString);
editFlagModes[0] = language.getString("Move");
editFlagModes[1] = language.getString("Resize");
editFlagModes[2] = language.getString("Copy");
editFlagModes[3] = language.getString("Color");
editFlagModes[4] = language.getString("Edit");
editFlagModes[5] = language.getString("Delete");
editFlagModes[6] = language.getString("Background");
editFlagModes[7] = language.getString("Foreground");
editFlagModes[8] = language.getString("group");
editFlagModes[9] = language.getString("Ungroup");
editTips[0] = language.getString("Move_an_object");
editTips[1] = language.getString("Resize_an_object");
editTips[2] = language.getString("Copy_an_object");
editTips[3] = language.getString("Color_an_object");
editTips[4] = language.getString("Edit_an_object");
editTips[5] = language.getString("Delete_an_object");
editTips[6] = language.getString("Put_an_object_in_the_background");
editTips[7] = language.getString("Put_an_object_in_the_foreground");
editTips[8] = language.getString("Group_objects");
editTips[9] = language.getString("Ungroup_objects");
for (int i = 0; i < (enbts - 1); i++) {
editButtons[i].setToolTipText(editTips[i]);
}
}
}
Ads help maintain this website.