/*
* 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.util.ResourceBundle;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
/** Responsible for choosing the Look and Feel of japlot.jaxodraw. */
public class JaxoLooknFeel {
private ResourceBundle language =
ResourceBundle.getBundle(JaxoPrefs.getPref(JaxoPrefs.PREF_LANGUAGE));
private JRadioButton[] lookAndFeelRB;
private JPanel lafPanel;
/** Brings up a dialog to select a Look and Feel. */
public JaxoLooknFeel() {
String currentLookAndFeel = UIManager.getLookAndFeel().getName();
LookAndFeel thisLaF = UIManager.getLookAndFeel();
ButtonGroup group = new ButtonGroup();
lafPanel = new JPanel(false);
// Get the names of available look and feels
UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels();
int num = info.length;
String[] humanReadableName = new String[num];
String[] className = new String[num];
lookAndFeelRB = new JRadioButton[num];
RadioListener myListener = new RadioListener();
for (int i = 0; i < num; i++) { // create a Radiobutton for each of them
humanReadableName[i] = info[i].getName();
className[i] = info[i].getClassName();
lookAndFeelRB[i] = new JRadioButton(humanReadableName[i]);
try { // check wether this LaF is supported
javax.swing.UIManager.setLookAndFeel(className[i]);
} catch (Exception exc) {
lookAndFeelRB[i].setEnabled(false);
}
try {
javax.swing.UIManager.setLookAndFeel(thisLaF);
} catch (Exception exc) {
// this should work in any case
if (JaxoPrefs.verbose()) {
System.err.println(exc);
}
}
lafPanel.add(lookAndFeelRB[i]);
group.add(lookAndFeelRB[i]);
lookAndFeelRB[i].setActionCommand(humanReadableName[i]);
lookAndFeelRB[i].addActionListener(myListener);
if (humanReadableName[i].equals(currentLookAndFeel)) {
lookAndFeelRB[i].setSelected(true);
}
}
String[] optionButtonNames = {language.getString("OK")};
JOptionPane.showOptionDialog(null, lafPanel,
language.getString("Look_And_Feel"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, optionButtonNames,
optionButtonNames[0]);
}
/** Makes the changes visible on the screen. */
public final void updateState() {
String lnfName = UIManager.getLookAndFeel().getClass().getName();
UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels();
int num = info.length;
for (int i = 0; i < num; i++) {
if (lnfName.equals(info[i].getClassName())) {
lookAndFeelRB[i].setSelected(true);
}
}
}
class RadioListener implements ActionListener {
public final void actionPerformed(ActionEvent e) {
UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels();
int num = info.length;
String[] humanReadableName = new String[num];
String[] className = new String[num];
String chosen = e.getActionCommand();
String newLAF = "";
String newLAFname = "";
for (int i = 0; i < num; i++) {
humanReadableName[i] = info[i].getName();
className[i] = info[i].getClassName();
if (chosen.equals(humanReadableName[i])) {
newLAF = className[i];
newLAFname = humanReadableName[i];
}
}
try {
JaxoPrefs.setPref(JaxoPrefs.PREF_LOOKNFEEL, newLAFname);
UIManager.setLookAndFeel(newLAF);
} catch (Exception exc) {
JRadioButton button = (JRadioButton) e.getSource();
button.setEnabled(false);
updateState();
if (JaxoPrefs.verbose()) {
System.err.println(exc);
}
JOptionPane.showMessageDialog(lafPanel,
newLAFname
+ language.getString(
"_Look_and_Feel_is_not_supported_on_this_platform!"));
}
}
}
}
Ads help maintain this website.