/*
* 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.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.TitledBorder;
import jhplot.jadraw.JaLineObject;
/** A panel to change the parameters of a line object. */
public class JaxoLineOptionsPanel extends JaxoOptionsPanel
implements ItemListener, ActionListener {
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private JaLineObject theLine;
private int type;
private SpinnerNumberModel modelampin;
private SpinnerNumberModel modelwigin;
private SpinnerNumberModel modelsep;
private SpinnerNumberModel modelstin;
private SpinnerNumberModel modeldsin;
private JCheckBox arrowcb;
private JRadioButton middlerb;
private JRadioButton endrb;
private JCheckBox flipcb;
private JCheckBox symmcb;
private boolean newFlip;
private boolean newArrow;
private boolean newEnd;
private boolean newSymm;
private int newWidth;
private int newHeight;
private int newRelWidth;
private int newRelHeight;
private int newAmp;
private float newFreq;
private int newWiggles;
private float newStroke;
private float newDash;
private float newLength;
private boolean newDLine;
private float newDLSep;
private JCheckBox dlcb;
private JLabel stsep;
private JSpinner spsep;
/** Constructor: pops up a panel that allows to change all the parameters
* of the object.
* @param whichObject An integer (as specified in JaxoMainPanel) that
* specifies the object that is edited.
*/
public JaxoLineOptionsPanel(int whichObject) {
type = whichObject;
setLayout(getGBLayout());
}
/** Checks for ItemEvents that have ocurred on the panel,
* presently only whether the arrow or flip or symm check boxes
* have been clicked.
* @param e The ItemEvent that has ocurred.
*/
public final void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
if (source == arrowcb) {
newArrow = !newArrow;
flipcb.setEnabled(newArrow);
middlerb.setEnabled(newArrow);
if (type == JaxoMainPanel.FLINE) {
endrb.setEnabled(newArrow);
}
} else if (source == flipcb) {
newFlip = !newFlip;
theLine.setInflip(!theLine.isInflip());
} else if (source == middlerb) {
newEnd = false;
} else if (source == endrb) {
newEnd = true;
} else if (source == symmcb) {
newSymm = !newSymm;
} else if (source == dlcb) {
newDLine = !newDLine;
stsep.setEnabled(newDLine);
spsep.setEnabled(newDLine);
}
}
/** Initializes the object parameters in this option panel.
* @param line The JaObject that is being edited.
*/
public final void initParams(JaLineObject line) {
this.theLine = line;
setColor(theLine.getColor());
newArrow = theLine.getArrow();
newFlip = theLine.getFlip();
newEnd = theLine.getEnd();
newWidth = theLine.getSize().width;
newHeight = theLine.getSize().height;
newRelWidth = theLine.getRelSize().width;
newRelHeight = theLine.getRelSize().height;
setXYLineCoord(theLine.getX(), theLine.getY(), newRelWidth,
newRelHeight);
newAmp = theLine.getAmp();
newStroke = theLine.getStroke();
newDash = theLine.getDash();
newLength =
(float) Math.sqrt((newWidth * newWidth) + (newHeight * newHeight));
newFreq = theLine.getFreq();
newWiggles = (int) (newLength / newFreq);
if (type == JaxoMainPanel.GLLINE) {
newWiggles = (int) (((newLength / newFreq) - 1.f) / 0.6f);
}
newSymm = theLine.getSymm();
newDLine = theLine.getDoubleLine();
newDLSep = theLine.getDLSeparation();
if (newDLSep < 0.5) {
newDLSep = JaxoPrefs.getFloatPref(JaxoPrefs.PREF_DLSEP);
}
}
/** Displays this EditPanel.
* @return A boolean variable that indicates if the object has been modified.
*/
public final boolean showPanel() {
boolean changed = false;
String[] optionButtonNames =
{language.getString("Accept"), language.getString("Cancel")};
int n =
JOptionPane.showOptionDialog(this, this, getPanelTitle(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE,
getPanelIcon(), optionButtonNames, optionButtonNames[0]);
if (n == JOptionPane.OK_OPTION) {
theLine.setArrow(newArrow);
theLine.setFlip(newFlip);
Color newColor = getColor();
if (newColor != null) {
theLine.setColor(newColor);
}
newStroke = Math.abs(modelstin.getNumber().floatValue());
newDash = Math.abs(modeldsin.getNumber().floatValue());
if ((type == JaxoMainPanel.PLINE)
|| (type == JaxoMainPanel.ZIGZAG)
|| (type == JaxoMainPanel.GLLINE)) {
newAmp = modelampin.getNumber().intValue();
newWiggles = modelwigin.getNumber().intValue();
newLength =
(float) Math.sqrt((newWidth * newWidth)
+ (newHeight * newHeight));
if (type == JaxoMainPanel.GLLINE) {
newFreq = (float) (newLength / ((newWiggles * 0.6f) + 1));
} else {
newFreq = (float) (newLength / newWiggles);
}
}
theLine.setDoubleLine(newDLine);
newDLSep = modelsep.getNumber().floatValue();
theLine.setDLSeparation(newDLSep);
theLine.setEnd(newEnd);
theLine.setDash(newDash);
theLine.setStroke(newStroke);
theLine.setAmp(newAmp);
theLine.setFreq(newFreq);
theLine.setSymm(newSymm);
setXYRelWAndH(getXin(), getYin(), getXfin(), getYfin());
changed = true;
}
return changed;
}
/** TODO This should really go into JaLineObject. */
private void setXYRelWAndH(int xin, int yin, int xfin, int yfin) {
int relw = xfin - xin;
int relh = yfin - yin;
theLine.setRelWAndH(relw, relh);
if ((relw >= 0) && (relh >= 0)) {
theLine.setLocation(xin, yin);
} else if ((relw >= 0) && (relh < 0)) {
theLine.setLocation(xin, yfin);
} else if ((relw < 0) && (relh >= 0)) {
theLine.setLocation(xfin, yin);
} else if ((relw < 0) && (relh < 0)) {
theLine.setLocation(xfin, yfin);
}
}
private JPanel getLineSymmPanel() {
symmcb = new JCheckBox(language.getString("Yes"));
symmcb.setSelected(newSymm);
symmcb.addItemListener(this);
JPanel lineSymmPanel = new JPanel();
lineSymmPanel.setLayout(new GridLayout(0, 1));
TitledBorder lineSymmTitle =
BorderFactory.createTitledBorder(language.getString("Symmetric_?"));
lineSymmPanel.setBorder(lineSymmTitle);
lineSymmPanel.add(symmcb);
return lineSymmPanel;
}
/** Adds the LineSymmPanel panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addLineSymmPanel(int gridx, int gridy) {
setInsets(0, 5, 5, 0);
setGBConstraints(gridx, gridy);
JPanel lineSymmPanel = getLineSymmPanel();
lineSymmPanel.setPreferredSize(new Dimension(100, 50));
setGBLayout(lineSymmPanel);
add(lineSymmPanel, getGBConstraints());
}
private JPanel getDlPanel() {
dlcb = new JCheckBox(language.getString("Double_line"));
dlcb.setSelected(newDLine);
dlcb.addItemListener(this);
modelsep = new SpinnerNumberModel(newDLSep, 0.5, 5.0, 0.5);
stsep = new JLabel(language.getString("Separation") + ": ");
spsep = new JSpinner(modelsep);
stsep.setEnabled(newDLine);
spsep.setEnabled(newDLine);
JPanel dlP = new JPanel();
GridBagLayout subdl = new GridBagLayout();
GridBagConstraints subcdl = new GridBagConstraints();
dlP.setLayout(subdl);
subcdl.gridx = 0;
subcdl.gridy = 0;
subdl.setConstraints(dlcb, subcdl);
dlP.add(dlcb, subcdl);
subcdl.gridx = 0;
subcdl.gridy = 1;
setInsets(5, 0, 5, 0);
subcdl.insets = getInsets();
subdl.setConstraints(stsep, subcdl);
dlP.add(stsep, subcdl);
subcdl.gridx = 1;
subcdl.gridy = 1;
setInsets(5, 0, 5, 5);
subcdl.insets = getInsets();
spsep.setPreferredSize(new Dimension(50, 20));
subdl.setConstraints(spsep, subcdl);
dlP.add(spsep, subcdl);
JPanel dlPanel = new JPanel();
dlPanel.setLayout(new BoxLayout(dlPanel, BoxLayout.X_AXIS));
TitledBorder dlTitle =
BorderFactory.createTitledBorder(language.getString("Double_line"));
dlPanel.setBorder(dlTitle);
dlPanel.add(dlP);
return dlPanel;
}
/** Adds the DoubleLinePanel panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addDlPanel(int gridx, int gridy) {
setGBConstraints(gridx, gridy);
JPanel dlPanel = getDlPanel();
setGBLayout(dlPanel);
add(dlPanel, getGBConstraints());
}
private JPanel getLineMiddlePanel() {
middlerb = new JRadioButton(language.getString("Middle"));
middlerb.setSelected(!newEnd);
middlerb.addItemListener(this);
endrb = new JRadioButton(language.getString("End"));
endrb.setSelected(newEnd);
endrb.addItemListener(this);
ButtonGroup bg = new ButtonGroup();
bg.add(middlerb);
bg.add(endrb);
JPanel lineMiddlePanel = new JPanel();
lineMiddlePanel.setLayout(new GridLayout(0, 1));
TitledBorder lineMiddleTitle =
BorderFactory.createTitledBorder(language.getString(
"Arrow_Position"));
lineMiddlePanel.setBorder(lineMiddleTitle);
lineMiddlePanel.add(middlerb);
lineMiddlePanel.add(endrb);
middlerb.setEnabled(newArrow);
endrb.setEnabled(newArrow);
if ((type == JaxoMainPanel.SLINE) || (type == JaxoMainPanel.GLINE)) {
endrb.setEnabled(false);
}
return lineMiddlePanel;
}
/** Adds the LineMiddlePanel panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addLineMiddlePanel(int gridx, int gridy) {
setInsets(0, 5, 5, 0);
setGBConstraints(gridx, gridy);
JPanel lineMiddlePanel = getLineMiddlePanel();
lineMiddlePanel.setPreferredSize(new Dimension(150, 70));
setGBLayout(lineMiddlePanel);
add(lineMiddlePanel, getGBConstraints());
}
private JPanel getLineArrowPanel() {
arrowcb = new JCheckBox(language.getString("Arrow"));
arrowcb.setSelected(theLine.getArrow());
arrowcb.addItemListener(this);
flipcb = new JCheckBox(language.getString("Flip"));
flipcb.setSelected(theLine.getFlip());
flipcb.addItemListener(this);
JPanel lineArrowPanel = new JPanel();
lineArrowPanel.setLayout(new GridLayout(0, 1));
TitledBorder lineArrowTitle =
BorderFactory.createTitledBorder(language.getString("Arrow"));
lineArrowPanel.setBorder(lineArrowTitle);
lineArrowPanel.add(arrowcb);
lineArrowPanel.add(flipcb);
flipcb.setEnabled(newArrow);
return lineArrowPanel;
}
/** Adds the LineArrowPanel panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addLineArrowPanel(int gridx, int gridy) {
setInsets(0, 5, 5, 0);
setGBConstraints(gridx, gridy);
JPanel lineArrowPanel = getLineArrowPanel();
lineArrowPanel.setPreferredSize(new Dimension(100, 70));
setGBLayout(lineArrowPanel);
add(lineArrowPanel, getGBConstraints());
}
private JPanel getFinalAwSPanel() {
JPanel finalAwSPanel = new JPanel();
JPanel pampin = new JPanel();
GridBagLayout subgb2 = new GridBagLayout();
GridBagConstraints subc2 = new GridBagConstraints();
pampin.setLayout(subgb2);
modelampin = new SpinnerNumberModel(newAmp, -500.0, 500.0, 1);
JLabel ampin =
new JLabel(language.getString("Amplitude"), JLabel.RIGHT);
JSpinner spampin = new JSpinner(modelampin);
subc2.gridx = 0;
subc2.gridy = 0;
subgb2.setConstraints(ampin, subc2);
pampin.add(ampin, subc2);
subc2.gridx = 1;
subc2.gridy = 0;
setInsets(0, 0, 0, 5);
subc2.insets = getInsets();
spampin.setPreferredSize(new Dimension(60, 20));
subgb2.setConstraints(spampin, subc2);
pampin.add(spampin, subc2);
JPanel pwigin = new JPanel();
GridBagLayout subgb3 = new GridBagLayout();
GridBagConstraints subc3 = new GridBagConstraints();
pampin.setLayout(subgb3);
modelwigin = new SpinnerNumberModel(newWiggles, 0.0, 1000.0, 1);
JLabel wigin =
new JLabel(" " + language.getString("Wiggles"), JLabel.RIGHT);
JSpinner spwigin = new JSpinner(modelwigin);
subc3.gridx = 0;
subc3.gridy = 0;
setInsets(0, 0, 5, 5);
subc3.insets = getInsets();
subgb3.setConstraints(wigin, subc3);
pwigin.add(wigin, subc3);
subc3.gridx = 1;
subc3.gridy = 0;
spwigin.setPreferredSize(new Dimension(60, 20));
subgb3.setConstraints(spwigin, subc3);
pwigin.add(spwigin, subc3);
JPanel awSPanel = new JPanel();
GridBagLayout gb2 = new GridBagLayout();
GridBagConstraints sc2 = new GridBagConstraints();
awSPanel.setLayout(gb2);
sc2.gridx = 0;
sc2.gridy = 0;
gb2.setConstraints(pampin, sc2);
awSPanel.add(pampin, sc2);
sc2.gridx = 0;
sc2.gridy = 1;
setInsets(0, 0, 5, 5);
sc2.insets = getInsets();
gb2.setConstraints(pwigin, sc2);
awSPanel.add(pwigin, sc2);
finalAwSPanel.setLayout(new BoxLayout(finalAwSPanel, BoxLayout.X_AXIS));
TitledBorder awSTitle =
BorderFactory.createTitledBorder(language.getString(
"Amplitude/Wiggles"));
finalAwSPanel.setBorder(awSTitle);
finalAwSPanel.add(awSPanel);
return finalAwSPanel;
}
/** Adds the Amplitude/Wiggle panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addFinalAwSPanel(int gridx, int gridy) {
setInsets(0, 5, 5, 5);
setGBConstraints(gridx, gridy);
JPanel finalAwSPanel = getFinalAwSPanel();
setGBLayout(finalAwSPanel);
add(finalAwSPanel, getGBConstraints());
}
private JPanel getFinalStrSPanel() {
JPanel pstin = new JPanel();
GridBagLayout subgb = new GridBagLayout();
GridBagConstraints subc = new GridBagConstraints();
pstin.setLayout(subgb);
modelstin = new SpinnerNumberModel(newStroke, 0.0, 100.0, 0.2);
JLabel stin =
new JLabel(language.getString("Line_Width"), JLabel.RIGHT);
JSpinner spstin = new JSpinner(modelstin);
subc.gridx = 0;
subc.gridy = 0;
subc.insets = new Insets(0, 5, 0, 5);
subgb.setConstraints(stin, subc);
pstin.add(stin, subc);
subc.gridx = 1;
subc.gridy = 0;
spstin.setPreferredSize(new Dimension(50, 20));
subgb.setConstraints(spstin, subc);
pstin.add(spstin, subc);
JPanel pdsin = new JPanel();
GridBagLayout subgb1 = new GridBagLayout();
GridBagConstraints subc1 = new GridBagConstraints();
pdsin.setLayout(subgb);
modeldsin = new SpinnerNumberModel(newDash, 0.0, 50.0, 0.2);
JLabel dsin =
new JLabel(" " + language.getString("Dash_Size"), JLabel.RIGHT);
pdsin.add(dsin);
JSpinner spdsin = new JSpinner(modeldsin);
subc1.gridx = 0;
subc1.gridy = 0;
subc1.insets = new Insets(0, 5, 5, 5);
subgb1.setConstraints(dsin, subc1);
pdsin.add(dsin, subc1);
subc1.gridx = 1;
subc1.gridy = 0;
spdsin.setPreferredSize(new Dimension(50, 20));
subgb1.setConstraints(spdsin, subc1);
pdsin.add(spdsin, subc1);
if ((type == JaxoMainPanel.FLINE) || (type == JaxoMainPanel.PLINE)
|| (type == JaxoMainPanel.GLLINE)
|| (type == JaxoMainPanel.ZIGZAG)) {
dsin.setEnabled(false);
spdsin.setEnabled(false);
}
JPanel strSPanel = new JPanel();
GridBagLayout gb1 = new GridBagLayout();
GridBagConstraints sc1 = new GridBagConstraints();
strSPanel.setLayout(gb1);
sc1.gridx = 0;
sc1.gridy = 0;
gb1.setConstraints(pstin, sc1);
strSPanel.add(pstin, sc1);
sc1.gridx = 0;
sc1.gridy = 1;
sc1.insets = new Insets(5, 0, 0, 0);
gb1.setConstraints(pdsin, sc1);
strSPanel.add(pdsin, sc1);
JPanel finalStrSPanel = new JPanel();
finalStrSPanel.setLayout(new BoxLayout(finalStrSPanel, BoxLayout.X_AXIS));
TitledBorder strSTitle =
BorderFactory.createTitledBorder(language.getString(
"Width/Dashing"));
finalStrSPanel.setBorder(strSTitle);
finalStrSPanel.add(strSPanel);
return finalStrSPanel;
}
/** Adds the StrokePanel panel to this OptionPanel.
* @param gridx The x position of the panel.
* @param gridy The y position of the panel.
*/
public final void addFinalStrSPanel(int gridx, int gridy) {
setInsets(5, 0, 0, 5);
setGBConstraints(gridx, gridy);
JPanel finalStrSPanel = getFinalStrSPanel();
setGBLayout(finalStrSPanel);
add(finalStrSPanel, getGBConstraints());
}
}
Ads help maintain this website.