/*
* 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
* misc button menu.
*/
public class JaxoMiscButtons extends JPanel implements ActionListener {
private static final String[] MISC_BUTTON_ICONS =
{
"japlot/jaxodraw/icons/box.png", "japlot/jaxodraw/icons/blob.png", "japlot/jaxodraw/icons/vertexT1.png",
"japlot/jaxodraw/icons/zigzag.png", "japlot/jaxodraw/icons/font_truetype.png", "japlot/jaxodraw/icons/latex.png"
};
private static final int[] MISC_MODES =
{
JaxoMainPanel.BOX, JaxoMainPanel.BLOB, JaxoMainPanel.VERTEX,
JaxoMainPanel.ZIGZAG, JaxoMainPanel.TEXT, JaxoMainPanel.LATEX
};
private JaxoPopupListener popupListener;
private JaxoMainPanel thePanel;
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private int mnbts = 6;
/** An array holding the JButtons of the misc button panel. */
private JButton[] miscButtons = new JButton[mnbts];
private String[] miscFlagModes =
{
language.getString("Box"), language.getString("Blob"),
language.getString("Vertex"), language.getString("Zigzag"),
language.getString("Text"), language.getString("LaTex")
};
private String[] miscTips =
{
language.getString("Draw_a_box"), language.getString("Draw_a_blob"),
language.getString("Draw_a_vertex"),
language.getString("Draw_a_zigzag_line"),
language.getString("Draw_a_text_string"),
language.getString("Draw_a_LaTex_text")
};
private Border raisedbevel = BorderFactory.createRaisedBevelBorder();
private Border loweredbevel = BorderFactory.createLoweredBevelBorder();
private Border raisedetched =
BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
/** Constructor: lays out the misc button panel.
* @param mainPanel The JaxoMainPanel that holds this button panel.
*/
public JaxoMiscButtons(JaxoMainPanel mainPanel) {
this.thePanel = mainPanel;
JPanel miscButtonPanel = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
miscButtonPanel.setLayout(gridbag);
for (int i = 0; i < mnbts; i++) {
miscButtons[i] = new JButton();
miscButtons[i].setIcon(new ImageIcon(JaxoMiscButtons.class.getClassLoader()
.getResource(MISC_BUTTON_ICONS[i])));
miscButtons[i].setToolTipText(miscTips[i]);
miscButtons[i].addActionListener(this);
miscButtons[i].setMinimumSize(new Dimension(40, 40));
miscButtons[i].setPreferredSize(new Dimension(40, 40));
miscButtons[i].setBorder(raisedbevel);
miscButtons[i].setFocusPainted(false);
}
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 3; i++) {
c.gridx = i;
c.gridy = j;
gridbag.setConstraints(miscButtons[i + (3 * j)], c);
miscButtonPanel.add(miscButtons[i + (3 * j)]);
}
}
JPanel finalMiscButtonPanel = new JPanel();
finalMiscButtonPanel.setLayout(new BorderLayout());
finalMiscButtonPanel.setBorder(raisedetched);
finalMiscButtonPanel.add(miscButtonPanel, BorderLayout.CENTER);
setLayout(new GridLayout(0, 1));
add(finalMiscButtonPanel);
popupListener = new JaxoPopupListener(thePanel, 1);
miscButtons[2].addMouseListener(popupListener);
}
/** 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 < mnbts; i++) {
if (evt.getSource() == miscButtons[i]) {
thePanel.miscEvent(MISC_MODES[i]);
thePanel.getCanvas().resetNOfClicks();
}
}
}
/** Sets all the buttons as not pressed. */
public final void reset() {
for (int i = 0; i < mnbts; i++) {
setButtonBorder(i, raisedbevel);
setButtonBackground(i, null);
miscButtons[i].setFocusPainted(false);
}
}
/** Returns the currently selected vertex button.
* @return The button of the currently selected vertex type
*/
public final JButton getVertexButton() {
return miscButtons[2];
}
/** Returns the index of the misc button corresponding to the misc event i.
* @param i A misc event as defined in the JaxoMainPanel.
* @return The index of the misc button corresponding to the edit event i.
*/
public final int getIndex(int i) {
int j = mnbts + 1;
for (int jj = 0; jj < mnbts; jj++) {
if (i == MISC_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));
//setButtonBackground(j, JaxoColor.GrayScale150);
setButtonBorder(j, loweredbevel);
miscButtons[j].setFocusPainted(false);
miscButtons[j].setSelected(true);
}
/** Returns a String with the text to be set in the flag panel
* indicating the current msic mode.
* @param i The index of the misc button, corresponding to the mode
* to be returned.
* @return The String containing the text to be set in the flag
* panel indicating the current misc mode.
*/
public final String getMiscFlagModes(int i) {
return miscFlagModes[i];
}
/** Returns the number of buttons in the misc button menu.
* @return The number of buttons in the misc button menu.
*/
public final int getmnbts() {
return mnbts;
}
/** 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) {
miscButtons[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) {
miscButtons[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) {
miscButtons[i].doClick();
}
/** Sets the tool tip text for the misc buttons in different languages.
* @param languageString A string specifying the language to be set.
*/
public final void setLanguage(String languageString) {
language = ResourceBundle.getBundle(languageString);
miscFlagModes[0] = language.getString("Box");
miscFlagModes[1] = language.getString("Blob");
miscFlagModes[2] = language.getString("Vertex");
miscFlagModes[3] = language.getString("Zigzag");
miscFlagModes[4] = language.getString("Text");
miscFlagModes[5] = language.getString("LaTex");
miscTips[0] = language.getString("Draw_a_box");
miscTips[1] = language.getString("Draw_a_blob");
miscTips[2] = language.getString("Draw_a_vertex");
miscTips[3] = language.getString("Draw_a_zigzag_line");
miscTips[4] = language.getString("Draw_a_text_string");
miscTips[5] = language.getString("Draw_a_LaTex_text");
for (int i = 0; i < mnbts; i++) {
miscButtons[i].setToolTipText(miscTips[i]);
}
popupListener.setLanguage(languageString);
}
/** Updates the vertex pop-up menu.
* @param up Specifies the current vertex type.
*/
public final void updatePop(int up) {
popupListener.updatePop(up);
}
}
Ads help maintain this website.