org.openscience.jmol.app.jmolpanel.PreferencesDialog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmol Show documentation
Show all versions of jmol Show documentation
Jmol: an open-source Java viewer for chemical structures in 3D
/* $RCSfile$
* $Author: hansonr $
* $Date: 2015-06-08 11:10:35 -0500 (Mon, 08 Jun 2015) $
* $Revision: 20563 $
*
* Copyright (C) 2002-2005 The Jmol Development Team
*
* Contact: [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.jmol.app.jmolpanel;
import org.jmol.api.JmolAbstractButton;
import org.jmol.i18n.GT;
import org.jmol.script.T;
import org.jmol.util.Elements;
import org.jmol.util.Logger;
import org.jmol.viewer.JC;
import org.jmol.viewer.Viewer;
import org.openscience.jmol.app.jmolpanel.GuiMap;
import org.openscience.jmol.app.jmolpanel.JmolPanel;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Dictionary;
import java.util.Map;
import java.util.Properties;
import java.util.Hashtable;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import javajs.util.PT;
import javax.swing.JRadioButton;
import javax.swing.BoxLayout;
import javax.swing.JSlider;
import javax.swing.AbstractAction;
import javax.swing.JDialog;
import javax.swing.JCheckBox;
import javax.swing.Box;
import javax.swing.JTabbedPane;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.Action;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.border.TitledBorder;
public class PreferencesDialog extends JDialog implements ActionListener {
private boolean autoBond;
boolean showHydrogens;
boolean showMeasurements;
boolean perspectiveDepth;
boolean showAxes;
boolean showBoundingBox;
boolean axesOrientationRasmol;
boolean openFilePreview;
boolean clearHistory;
int fontScale = 1;
float minBondDistance;
float bondTolerance;
short marBond;
int percentVdwAtom;
int bondingVersion;
JButton bButton, pButton, tButton, eButton, vButton;
private JRadioButton /*pYes, pNo, */abYes, abNo;
private JSlider vdwPercentSlider;
private JSlider bdSlider, bwSlider, btSlider;
private JCheckBox cH, cM;
private JCheckBox cbPerspectiveDepth;
private JCheckBox cbShowAxes, cbShowBoundingBox;
private JCheckBox cbAxesOrientationRasmol;
private JCheckBox cbOpenFilePreview;
private JCheckBox cbClearHistory;
// private JCheckBox cbLargeFont;
private Properties originalSystemProperties;
private Properties jmolDefaultProperties;
Properties currentProperties;
// The actions:
private PrefsAction prefsAction = new PrefsAction();
private Map commands;
final static String[] jmolDefaults = {
"jmolDefaults", "true",
"showHydrogens", "true",
"showMeasurements", "true",
"perspectiveDepth", "true",
"showAxes", "false",
"showBoundingBox", "false",
"axesOrientationRasmol", "false",
"openFilePreview", "true",
"autoBond", "true",
"percentVdwAtom", "" + JC.DEFAULT_PERCENT_VDW_ATOM,
"marBond", "" + JC.DEFAULT_BOND_MILLIANGSTROM_RADIUS,
"minBondDistance", "" + JC.DEFAULT_MIN_BOND_DISTANCE,
"bondTolerance", "" + JC.DEFAULT_BOND_TOLERANCE,
"bondingVersion", "" + Elements.RAD_COV_IONIC_OB1_100_1,
};
final static String[] rasmolOverrides = {
"jmolDefaults", "false",
"percentVdwAtom", "0",
"marBond", "1",
"axesOrientationRasmol", "true",
};
JmolPanel jmol;
Viewer vwr;
GuiMap guimap;
public PreferencesDialog(JmolPanel jmol, JFrame f, GuiMap guimap,
Viewer vwr) {
super(f, false);
this.jmol = jmol;
this.guimap = guimap;
this.vwr = vwr;
initializeProperties();
this.setTitle(GT._("Preferences"));
initVariables();
commands = new Hashtable();
Action[] actions = getActions();
for (int i = 0; i < actions.length; i++) {
Action a = actions[i];
Object name = a.getValue(Action.NAME);
commands.put((name != null) ? name.toString() : null, a);
}
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
JTabbedPane tabs = new JTabbedPane();
JPanel disp = buildDispPanel();
JPanel atoms = buildAtomsPanel();
JPanel bonds = buildBondPanel();
// JPanel vibrate = buildVibratePanel();
tabs.addTab(GT._("Display"), null, disp);
tabs.addTab(GT._("Atoms"), null, atoms);
tabs.addTab(GT._("Bonds"), null, bonds);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
jmolDefaultsButton = new JButton(GT._("Jmol Defaults"));
jmolDefaultsButton.addActionListener(this);
buttonPanel.add(jmolDefaultsButton);
rasmolDefaultsButton = new JButton(GT._("RasMol Defaults"));
rasmolDefaultsButton.addActionListener(this);
buttonPanel.add(rasmolDefaultsButton);
//cancelButton = new JButton(GT._("Cancel"));
//cancelButton.addActionListener(this);
//buttonPanel.add(cancelButton);
applyButton = new JButton(GT._("Apply"));
applyButton.addActionListener(this);
buttonPanel.add(applyButton);
okButton = new JButton(GT._("OK"));
okButton.addActionListener(this);
buttonPanel.add(okButton);
getRootPane().setDefaultButton(okButton);
container.add(tabs, BorderLayout.CENTER);
container.add(buttonPanel, BorderLayout.SOUTH);
getContentPane().add(container);
updateComponents();
pack();
centerDialog();
}
public JPanel buildDispPanel() {
JPanel disp = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
disp.setLayout(gridbag);
GridBagConstraints constraints;
JPanel showPanel = new JPanel();
showPanel.setLayout(new GridLayout(1, 3));
showPanel.setBorder(new TitledBorder(GT._("Show All")));
cH = guimap.newJCheckBox("Prefs.showHydrogens",
vwr.getBoolean(T.showhydrogens));
cH.addItemListener(checkBoxListener);
cM = guimap.newJCheckBox("Prefs.showMeasurements",
vwr.getBoolean(T.showmeasurements));
cM.addItemListener(checkBoxListener);
showPanel.add(cH);
showPanel.add(cM);
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
disp.add(showPanel, constraints);
JPanel fooPanel = new JPanel();
fooPanel.setBorder(new TitledBorder(""));
fooPanel.setLayout(new GridLayout(2, 1));
cbPerspectiveDepth =
guimap.newJCheckBox("Prefs.perspectiveDepth",
vwr.tm.perspectiveDepth);
cbPerspectiveDepth.addItemListener(checkBoxListener);
fooPanel.add(cbPerspectiveDepth);
cbShowAxes =
guimap.newJCheckBox("Prefs.showAxes", vwr.getShowAxes());
cbShowAxes.addItemListener(checkBoxListener);
fooPanel.add(cbShowAxes);
cbShowBoundingBox =
guimap.newJCheckBox("Prefs.showBoundingBox", vwr.getShowBbcage());
cbShowBoundingBox.addItemListener(checkBoxListener);
fooPanel.add(cbShowBoundingBox);
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
disp.add(fooPanel, constraints);
JPanel axesPanel = new JPanel();
axesPanel.setBorder(new TitledBorder(""));
axesPanel.setLayout(new GridLayout(1, 1));
cbAxesOrientationRasmol =
guimap.newJCheckBox("Prefs.axesOrientationRasmol",
vwr.getBoolean(T.axesorientationrasmol));
cbAxesOrientationRasmol.addItemListener(checkBoxListener);
axesPanel.add(cbAxesOrientationRasmol);
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
disp.add(axesPanel, constraints);
JPanel otherPanel = new JPanel();
otherPanel.setBorder(new TitledBorder(""));
otherPanel.setLayout(new GridLayout(2, 1));
cbOpenFilePreview =
guimap.newJCheckBox("Prefs.openFilePreview",
openFilePreview);
cbOpenFilePreview.addItemListener(checkBoxListener);
otherPanel.add(cbOpenFilePreview);
cbClearHistory =
guimap.newJCheckBox("Prefs.clearHistory", clearHistory);
cbClearHistory.addItemListener(checkBoxListener);
otherPanel.add(cbClearHistory);
// cbLargeFont =
// guimap.newJCheckBox("Prefs.largeFont", largeFont);
// cbLargeFont.addItemListener(checkBoxListener);
// otherPanel.add(cbLargeFont);
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
disp.add(otherPanel, constraints);
JLabel filler = new JLabel();
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.gridheight = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
disp.add(filler, constraints);
return disp;
}
public JPanel buildAtomsPanel() {
JPanel atomPanel = new JPanel(new GridBagLayout());
GridBagConstraints constraints;
JPanel sfPanel = new JPanel();
sfPanel.setLayout(new BorderLayout());
sfPanel.setBorder(new TitledBorder(GT._("Default atom size")));
JLabel sfLabel = new JLabel(GT._("(percentage of vanDerWaals radius)"),
SwingConstants.CENTER);
sfPanel.add(sfLabel, BorderLayout.NORTH);
vdwPercentSlider =
new JSlider(SwingConstants.HORIZONTAL, 0, 100, vwr.getInt(T.percentvdwatom));
vdwPercentSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
vdwPercentSlider.setPaintTicks(true);
vdwPercentSlider.setMajorTickSpacing(20);
vdwPercentSlider.setMinorTickSpacing(10);
vdwPercentSlider.setPaintLabels(true);
vdwPercentSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
rebond();
}
});
sfPanel.add(vdwPercentSlider, BorderLayout.CENTER);
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
atomPanel.add(sfPanel, constraints);
JLabel filler = new JLabel();
constraints = new GridBagConstraints();
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.gridheight = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
atomPanel.add(filler, constraints);
return atomPanel;
}
@SuppressWarnings("unchecked")
private Dictionary