Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* $RCSfile$
* $Author: hansonr $
* $Date: 2014-12-13 22:43:17 -0600 (Sat, 13 Dec 2014) $
* $Revision: 20162 $
*
* 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.gennbo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.util.Stack;
import javajs.util.PT;
import javajs.util.SB;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.jmol.util.Elements;
import org.jmol.viewer.Viewer;
class NBOModel implements NBOFileAcceptor {
// The main menu
protected NBODialog dialog;
//
private Viewer vwr;
/*
* constructor to initialize the fields needed in NOBModel
*/
protected NBOModel(NBODialog dialog) {
this.dialog = dialog;
this.vwr = dialog.vwr;
}
/*
* Different instructions users may choose
* MODEL_ACTION_ALTER: what does it do and possible problem if it has
* MODEL_ACTION_CLIP
* MODEL_ACTION_FUSE
* MODEL_ACTION_LINK
* MODEL_ACTION_MUTATE
* MODEL_ACTION_SWITCH
* MODEL_ACTION_TWIST
* MODEL_ACTION_VALUE
* MODEL_ACTION_3CHB
*/
private final static int MODEL_ACTION_ALTER = 0;
private final static int MODEL_ACTION_CLIP = 1;
private final static int MODEL_ACTION_FUSE = 2;
private final static int MODEL_ACTION_LINK = 3;
private final static int MODEL_ACTION_MUTATE = 4;
private final static int MODEL_ACTION_SWITCH = 5;
private final static int MODEL_ACTION_TWIST = 6;
private final static int MODEL_ACTION_VALUE = 7;
private final static int MODEL_ACTION_3CHB = 8;
private static final int MODEL_ACTION_MAX = 9;
/*
* Functions within Model -> Edit Model panel
* MODEL_ACTION_REBOND
* MODEL_ACTION_SYMMETRY
* MODEL_ACTION_HBOND
*/
private static final int MODEL_ACTION_REBOND = 9;
private static final int MODEL_ACTION_SYMMETRY = 10;
private final static int MODEL_ACTION_HBOND = 11;
/*
* Model operations
*/
static final int MODE_MODEL_EDIT = 21;
static final int MODE_MODEL_NEW = 31;
static final int MODE_MODEL_SAVE = 41;
static final int MODE_MODEL_TO_NBO = 51;
static final int MODE_MODEL_UNDO_REDO= 61;
final static String[] MODEL_ACTIONS = {
"Alter", "Clip", "Fuse", "Link", "Mutate",
"Switch", "Twist", "Value", "3chb", "Rebond",
"Symmetry?", "H-Bonds" };
private static final String[] EDIT_INFO = {
"Edit nuclear charge, bond length, bond angle, or dihedral angle",
"Remove bond between two atoms",
"Delete monovalent atoms and replace with bond",
"Add bond between two atoms",
"Replace atom with a new substituent-group",
"Switch location of two groups",
"Perform rigid torsional twist about dihedral angle",
"Value of nuclear charge, bond length, bond angle, and dihedral angle",
"Create 3-center linkage between two atoms and a ligand",
"Change bonding symmetry around transition metal",
"Display point-group symmetry of current model",
"Show NBOPro6-derived hydrogen bonds"
};
private final static int BOX_COUNT_4 = 4, BOX_COUNT_2 = 2, BOX_COUNT_1 = 1;
private final static int MAX_HISTORY = 5;
/// private static final String LOAD_SCRIPT = ";set zoomlarge false;zoomTo 0.5 {*} 0;";
private NBOFileHandler saveFileHandler;
private Box innerEditBox;
private JTextField jtNIHInput, jtLineFormula, txtCurrVal;
private JComboBox jcSymOps;
private JButton btnRebond, jbClear;
private JLabel atomsLabel;
private Box editBox, editHeaderBox, inputBox, inputHeaderBox, saveBox, saveHeaderBox;
private JTextField[] atomNumBoxes;
private JLabel valueLabel = new JLabel("");
// only used by private listeners
protected JTextField editValueTf;
protected JButton jbApply;
protected JComboBox jComboSave, jComboOpen;
protected JButton undo, redo;
protected Stack undoStack, redoStack;
/**
* identifies which action button as pressed -- for example, MODEL_ACTION_ALTER
*/
private int actionID;
/**
* encodes number of atoms that can be selected
*/
private int boxCount;
/**
* A model is being loaded into Jmol that NBO does not know about yet
*
*/
private boolean notFromNBO;
/**
* A flag to indicate that when the next atom is clicked, the selection should be cleared.
* Set to true each time a non-value option action is processed.
*/
private boolean resetOnAtomClick;
private Box innerLinkOptionBox;
private JRadioButton radLinkBond;
protected void setModelNotFromNBO() {
notFromNBO = true;
}
/*
* set the visability of components in buildModelPanel()
*/
private void showComponents(boolean tf) {
editHeaderBox.setVisible(tf);
editBox.setVisible(tf);
innerLinkOptionBox.setVisible(false);
saveHeaderBox.setVisible(tf);
saveBox.setVisible(tf);
}
void modelSetSaveParametersFromInput(NBOFileHandler nboFileHandler,
String dir, String name, String ext) {
if (saveFileHandler != null && nboFileHandler != saveFileHandler)
saveFileHandler.setTextFields(dir, name,
PT.isOneOf(ext, NBOFileHandler.MODEL_SAVE_FILE_EXTENSIONS) ? ext : "");
}
/*
*Save Model Panel at the bottom of the frame
*/
protected JPanel buildModelPanel() {
resetVariables();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
inputHeaderBox = NBOUtil.createTitleBox(" Input Model ", dialog.new HelpBtn(
"model_input_intro_help.htm"));
panel.add(inputHeaderBox);
inputBox = getInputBox();
panel.add(inputBox);
editHeaderBox = getEditHeader();
panel.add(editHeaderBox).setVisible(false);
editBox = getEditComponent();
panel.add(editBox).setVisible(false);
saveHeaderBox = NBOUtil.createTitleBox(" Save Model ", dialog.new HelpBtn(
"model_save_intro_help.htm"));
panel.add(saveHeaderBox).setVisible(false);
saveBox = getSaveBox();
saveFileHandler = new NBOFileHandler("", NBOFileHandler.MODE_MODEL_SAVE, dialog, this);
saveBox.add(saveFileHandler);
panel.add(saveBox).setVisible(false);
panel.add(Box.createGlue());
if (vwr.ms.ac > 0) {
loadModelToNBO(null, false);
}
return panel;
}
/*
*
*/
private void resetVariables() {
actionID = 0;
boxCount = 0;
notFromNBO = false;
showSelectedOnFileLoad = false;
resetOnAtomClick = true;
// serverMode = 0;
}
/*
* Edit Model horizontal box in the middle
*/
private Box getEditHeader() {
Box topBox = Box.createHorizontalBox();
undo = new JButton("←Undo");
redo = new JButton("Redo→");
undoStack = new Stack();
redoStack = new Stack();
redo.addActionListener(redoAction);
undo.addActionListener(undoAction);
topBox.add(undo);
topBox.add(redo);
topBox.add(dialog.new HelpBtn("model_edit_intro_help.htm"));
return NBOUtil.createTitleBox(" Edit Model ", topBox);
}
/**
* adds use elements to main panel
*
* @return use elements
*/
private Box getInputBox() {
Box inputBox = NBOUtil.createBorderBox(true);
inputBox.setMaximumSize(new Dimension(360, 140));
inputBox.setPreferredSize(new Dimension(360, 140));
inputBox.setMinimumSize(new Dimension(360, 140));
JPanel p2 = new JPanel(new GridLayout(3, 2));
p2.setMaximumSize(new Dimension(360, 90));
p2.setPreferredSize(new Dimension(360, 90));
p2.setMinimumSize(new Dimension(360, 90));
final JRadioButton jrJmolIn = new JRadioButton("NIH/PubChem/PDB");
jrJmolIn.setFont(NBOConfig.monoFont);
final JRadioButton jrLineIn = new JRadioButton("Line Formula");
jrLineIn.setFont(NBOConfig.monoFont);
jrLineIn.setSelected(true);
final JRadioButton jrFileIn = new JRadioButton("File Input");
jrFileIn.setFont(NBOConfig.monoFont);
ButtonGroup rg = new ButtonGroup();
rg.add(jrJmolIn);
rg.add(jrLineIn);
rg.add(jrFileIn);
createInput(jtNIHInput = new JTextField(), jrJmolIn);
createInput(jtLineFormula = new JTextField(), jrLineIn);
jtNIHInput.setFont(NBOConfig.userInputFont);
jtLineFormula.setFont(NBOConfig.userInputFont);
jtLineFormula.add(new JLabel("line formula"));
jComboOpen = new JComboBox(NBOFileHandler.MODEL_OPEN_OPTIONS);
jComboOpen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doComboUseAction(jComboOpen.getSelectedIndex() > 0 ? jComboOpen.getSelectedItem().toString() : null);
}
});
p2.add(jrLineIn);
p2.add(jtLineFormula);
p2.add(jrJmolIn);
p2.add(jtNIHInput);
p2.add(jrFileIn);
p2.add(jComboOpen);
jComboOpen.setSelectedIndex(1);
addFocusListeners(jComboOpen, jrFileIn);
inputBox.add(p2);
dialog.getNewInputFileHandler(NBOFileHandler.MODE_MODEL_OPEN, this);
addFocusListeners(dialog.inputFileHandler.tfDir, jrFileIn);
addFocusListeners(dialog.inputFileHandler.tfExt, jrFileIn);
addFocusListeners(dialog.inputFileHandler.tfName, jrFileIn);
addFocusListeners(dialog.inputFileHandler.btnBrowse, jrFileIn);
inputBox.add(dialog.inputFileHandler);
inputBox.add(Box.createGlue());
return inputBox;
}
protected void doComboUseAction(String item) {
if (dialog.inputFileHandler == null)
return;
if (item == null) {
dialog.inputFileHandler.tfExt.setText("");
// dialog.inputFileHandler.useExt = NBOFileHandler.MODEL_OPEN_FILE_EXTENSIONS;
} else {
item = item.substring(item.indexOf("[") + 2, item.indexOf("]"));
dialog.inputFileHandler.tfExt.setText(item);
// dialog.inputFileHandler.useExt = item;
}
}
private Box getEditComponent() {
Box editBox = NBOUtil.createBorderBox(false);
Box actionBox = Box.createVerticalBox();
final JRadioButton[] jrModelActions = new JRadioButton[MODEL_ACTION_MAX];
ButtonGroup rg = new ButtonGroup();
for (int i = 0; i < MODEL_ACTION_MAX; i++) {
jrModelActions[i] = new JRadioButton(MODEL_ACTIONS[i]);
jrModelActions[i].setToolTipText(EDIT_INFO[i]);
actionBox.add(jrModelActions[i]);
rg.add(jrModelActions[i]);
final int op = i;
jrModelActions[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doModelAction(op);
}
});
}
editBox.add(actionBox);
Box rightBox = Box.createVerticalBox();
createInnerEditBox();
rightBox.add(this.innerEditBox);
Box lowBox = Box.createHorizontalBox();
JButton sym = new JButton(MODEL_ACTIONS[MODEL_ACTION_SYMMETRY]);
sym.setToolTipText(EDIT_INFO[MODEL_ACTION_SYMMETRY]);
sym.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doGetSymmetry();
}
});
lowBox.add(sym);
btnRebond = new JButton(MODEL_ACTIONS[MODEL_ACTION_REBOND]);
btnRebond.setEnabled(false);
btnRebond.setToolTipText(EDIT_INFO[MODEL_ACTION_REBOND]);
btnRebond.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doModelAction(MODEL_ACTION_REBOND);
}
});
lowBox.add(btnRebond);
JButton hbond = new JButton(MODEL_ACTIONS[MODEL_ACTION_HBOND]);
hbond.setToolTipText(EDIT_INFO[MODEL_ACTION_HBOND]);
hbond.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doGetHBonds();
}
});
lowBox.add(hbond);
rightBox.add(lowBox);
editBox.add(rightBox);
//btns[0].doClick();
return editBox;
}
private void createInnerEditBox() {
innerEditBox = Box.createVerticalBox();
innerEditBox.setBorder(BorderFactory.createLoweredBevelBorder());
innerEditBox.setMaximumSize(new Dimension(275, 200));
innerEditBox.setAlignmentX(0.5f);
innerEditBox.setVisible(false);
Box atBox = Box.createHorizontalBox();
atBox.add(atomsLabel = new JLabel("")); // "Atoms:"
atomNumBoxes = new JTextField[4];
for (int i = 0; i < 4; i++) {
atomNumBoxes[i] = new JTextField();
atomNumBoxes[i].setFont(NBOConfig.userInputFont);
atomNumBoxes[i].setMaximumSize(new Dimension(50, 50));
atBox.add(atomNumBoxes[i]).setVisible(false);
final int num = i;
atomNumBoxes[i].addKeyListener(new KeyListener(){
@Override
public void keyTyped(KeyEvent e) {}
@Override
public void keyPressed(KeyEvent e) {}
@Override
public void keyReleased(KeyEvent e) {
editValueTf.setText("");
editValueTf.setEnabled(modelEditGetSelected().length() > 0);
}
});
atomNumBoxes[i].addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
doAtomNumBoxFocus(true, num);
}
@Override
public void focusLost(FocusEvent arg0) {
doAtomNumBoxFocus(false, 0);
}
});
atomNumBoxes[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doSetAtomBoxesFromSelection(null, false);
}
});
}
innerEditBox.add(atBox);
Box box = Box.createHorizontalBox();
box.add(new JLabel("Symmetry Type: "));
jcSymOps = new JComboBox();
jcSymOps.addItem("