Revision: 20615
http://sourceforge.net/p/jmol/code/20615
Author: hansonr
Date: 2015-07-01 19:31:54 +0000 (Wed, 01 Jul 2015)
Log Message:
-----------
Modified Paths:
--------------
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogView.java
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java
Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
2015-07-01 15:48:43 UTC (rev 20614)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
2015-07-01 19:31:54 UTC (rev 20615)
@@ -141,14 +141,12 @@
setVisible(true);
break;
case 'm':
- nboMode = NBOService.MODE_MODEL;
+ dialogMode = NBOService.MODE_MODEL;
modules.setSelectedIndex(0);
this.setMinimumSize(new Dimension(450, 550));
this.setSize(new Dimension(450, 550));
this.repaint();
this.revalidate();
- cmdFile = new File(nboService.serverPath);
- cmdFile = new File(cmdFile.getParent() + "/m_test.txt");
buildModel(this.getContentPane());
if (vwr.ms.ac != 0) {
loadModel();
@@ -157,7 +155,7 @@
}
break;
case 'r':
- nboMode = NBOService.MODE_RUN;
+ dialogMode = NBOService.MODE_RUN;
modules.setSelectedIndex(1);
this.setMinimumSize(new Dimension(300, 450));
this.setSize(new Dimension(300, 450));
@@ -172,10 +170,8 @@
}
break;
case 's':
- nboMode = NBOService.MODE_SEARCH;
+ dialogMode = NBOService.MODE_SEARCH;
modules.setSelectedIndex(3);
- cmdFile = new File(nboService.serverPath);
- cmdFile = new File(cmdFile.getParent() + "/s_test.txt");
this.setMinimumSize(new Dimension(1000, 500));
this.setSize(new Dimension(1000, 500));
this.repaint();
@@ -189,14 +185,12 @@
}
break;
case 'v':
- nboMode = NBOService.MODE_VIEW;
+ dialogMode = NBOService.MODE_VIEW;
modules.setSelectedIndex(2);
this.setMinimumSize(new Dimension(650, 400));
this.setSize(new Dimension(650, 400));
this.repaint();
this.revalidate();
- cmdFile = new File(nboService.serverPath);
- cmdFile = new File(cmdFile.getParent() + "/v_test.txt");
buildView(this.getContentPane());
String f = null;
if (vwr.ms.getInfo(vwr.am.cmi, "nboType") != null
@@ -227,7 +221,7 @@
int atomIndex = ((Integer) data[2]).intValue();
if (atomIndex >= 0) {
String st = vwr.ms.at[atomIndex].getInfo();
- switch (nboMode) {
+ switch (dialogMode) {
case NBOService.MODE_MODEL:
if (tf != null && tf2 != null && tf3 == null) {
if (tf.getText().equals("")
Modified:
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
2015-07-01 15:48:43 UTC (rev 20614)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
2015-07-01 19:31:54 UTC (rev 20615)
@@ -111,10 +111,8 @@
protected String jobStem;
- protected File cmdFile;
+ protected int dialogMode;
- protected int nboMode;
-
protected Font nboFont = new Font("Monospaced", Font.BOLD, 14);
/**
@@ -135,9 +133,9 @@
JPanel fp = buildFilePanel();
JPanel top = new JPanel();
top.setPreferredSize(new Dimension(400, 100));
- p.add(buildRightPanel(), BorderLayout.CENTER);
+ //p.add(buildRightPanel(), BorderLayout.CENTER);
p.add(fp, BorderLayout.NORTH);
- p.add(buildRightPanel(), BorderLayout.CENTER);
+ //p.add(buildRightPanel(), BorderLayout.CENTER);
centerDialog(this);
}
@@ -209,7 +207,15 @@
nboInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- rawCmd(null);
+ String cmd = nboInput.getText();
+ if (cmd.startsWith("!")) {
+ cmd = cmd.substring(1);
+ // a synchonous Jmol command
+ String msg = nboService.runScriptNow(cmd);
+ Logger.info(msg);
+ return;
+ }
+ nboService.rawCmdNew(cmd, null, false);
}
});
JPanel showPanel = new JPanel(new BorderLayout());
@@ -225,17 +231,7 @@
}
protected void rawCmd(String cmd) {
- if (cmd == null) {
- cmd = nboInput.getText();
- if (cmd.startsWith("!")) {
- cmd = cmd.substring(1);
- // a synchonous Jmol command
- String msg = nboService.runScriptNow(cmd);
- Logger.info(msg);
- return;
- }
- }
- nboService.rawCmd(cmd);
+ nboService.rawCmdNew(cmd, null, false);
}
protected void connectPressed() {
Modified:
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
2015-07-01 15:48:43 UTC (rev 20614)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
2015-07-01 19:31:54 UTC (rev 20615)
@@ -746,7 +746,6 @@
goRunClicked(DEFAULT_PARAMS, inputFile);
while (!f.exists() || f.length() / 1024 == 0) {
}
- cmdFile = new File(cmdFile.getParent() + "/s_test.txt");
}
//workingPath =
f.toString().substring(0,inputFile.toString().lastIndexOf("."))+".nbo";
//inputFile = new File(workingPath);
@@ -758,7 +757,6 @@
+ ".47"));
while (!f2.exists() || f2.length() / 1024 == 0) {
}
- cmdFile = new File(cmdFile.getParent() + "/s_test.txt");
}
nboService.runScriptNow("load "
+ inputFile.toString().substring(0,
@@ -796,7 +794,7 @@
appendToFile("GLOBAL C_JOBSTEM " + jobStem + sep, sb);
appendToFile("GLOBAL I_BAS_1 " + keywordNumber + sep, sb);
appendToFile("CMD " + get, sb);
- nboMode = NBOService.MODE_SEARCH;
+ dialogMode = NBOService.MODE_SEARCH;
nboService.rawCmdNew("s", sb, true);
String[] st = new String[reqInfo.length() / 20];
for (int i = 0; (i + 1) * 20 <= reqInfo.length(); i++)
@@ -813,7 +811,7 @@
appendToFile("GLOBAL C_JOBSTEM " + jobStem + sep, sb);
appendToFile("GLOBAL I_BAS_1 " + keywordNumber + sep, sb);
appendToFile("CMD r", sb);
- nboMode = NBOService.MODE_SEARCH_7;
+ dialogMode = NBOService.MODE_SEARCH_7;
nboService.rawCmdNew("s", sb, true);
int r = Integer.parseInt(reqInfo.substring(reqInfo.indexOf("-") + 1,
reqInfo.indexOf(")")));
@@ -826,7 +824,7 @@
}
protected void goSearchClicked() {
- nboMode = NBOService.MODE_SEARCH;
+ dialogMode = NBOService.MODE_SEARCH;
if (!keyProp.equals(""))
if (w != null)
w.interrupt();
@@ -889,7 +887,7 @@
w.start();
} else if ((keywordNumber == 1 && op == 12)
|| (keywordNumber == 6 && (op == 9 || op == 10))) {
- nboMode = NBOService.MODE_SEARCH_6;
+ dialogMode = NBOService.MODE_SEARCH_6;
nboService.inRequest = false;
reqInfo = "";
new NBOSearchWorker1(sb).start();
Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogView.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogView.java
2015-07-01 15:48:43 UTC (rev 20614)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogView.java
2015-07-01 19:31:54 UTC (rev 20615)
@@ -26,6 +26,7 @@
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
+import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@@ -918,20 +919,35 @@
@Override
public void valueChanged(ListSelectionEvent e) {
int i = list.getSelectedIndex();
- showOrbJmol(list, i);
+ System.out.println("-----------------------" + iLast + " " + i);
+ if (i == iLast)
+ return;
+ showOrbJmol(list, iLast = i);
}
});
- list.setSelectedIndex(0);
go.setEnabled(true);
p.getViewport().add(list);
p.setMinimumSize(new Dimension(100, 400));
selectPanel.add(p);
selectPanel.repaint();
selectPanel.revalidate();
+ int i = iLast;
+ iLast = -1;
+ if (i > 0 && i < list.getComponentCount())
+ i = 0;
+ final int i0 = i;
+ EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ list.setSelectedIndex(i0);
+ }
+ });
}
+ protected int iLast = -1;
+
private NBOPanel display() {
NBOPanel s = new NBOPanel(this, PANEL_RIGHT);
s.setBorder(new TitledBorder("Display"));
@@ -988,7 +1004,7 @@
sLab.setText("+");
vLab.setText("1, 2");
pLab.setText("1, 2, 3");
- getList("LABEL", "<v_test.txt>");
+ getViewList("LABEL");
}
protected void nboViewAddLine(String line) {
@@ -1028,10 +1044,10 @@
inputFile.getName().lastIndexOf("."));
workPathLabel.setText(jobStem);
workingPath = inputFile.getAbsolutePath();
- basisSel();
tfFolder.setText(inputFile.getParent());
tfName.setText(jobStem);
tfExt.setText(".nbo");
+ basisSel();
}
protected void goViewClicked() {
@@ -1137,7 +1153,7 @@
}
}
- protected void getList(String get, String cmd) {
+ protected void getViewList(String get) {
rawCmd("");
SB sb = new SB();
reqInfo = "";
@@ -1152,7 +1168,6 @@
}
class NBOViewWorker2 extends Thread {
- private String[] st;
private SB sb;
public NBOViewWorker2(SB sb) {
@@ -1164,18 +1179,27 @@
//File f = new File(inputFile.getParent() + "\\" + jobStem + ".bmp");
Thread.currentThread().setName(
"NBOViewThread" + System.currentTimeMillis());
- nboMode = NBOService.MODE_VIEW_4;
+ dialogMode = NBOService.MODE_VIEW_4;
nboService.rawCmdNew("v", sb, true);
- st = new String[reqInfo.length() / 20];
- for (int i = 0; (i + 1) * 20 <= reqInfo.length(); i++)
- st[i] = reqInfo.substring(i * 20, (i + 1) * 20);
done();
}
protected void done() {
+ System.out.println("processing list " + reqInfo);
+ try {
+ String[] st = new String[reqInfo.length() / 20];
+ for (int i = 0; (i + 1) * 20 <= reqInfo.length(); i++)
+ st[i] = reqInfo.substring(i * 20, (i + 1) * 20);
select(st);
- nboMode = NBOService.MODE_VIEW;
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ dialogMode = NBOService.MODE_VIEW;
}
}
+ @Override
+ protected void reset() {
+ iLast = -1;
+ }
}
Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java
2015-07-01 15:48:43 UTC (rev 20614)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java
2015-07-01 19:31:54 UTC (rev 20615)
@@ -62,7 +62,8 @@
static final int MODE_SEARCH_6 = 6;
static final int MODE_SEARCH_7 = 7;
- private int nboMode = MODE_RAW;
+ private static final int MODE_ERR = -1;
+ private int serverMode = MODE_RAW;
private transient Viewer vwr;
@@ -76,7 +77,6 @@
private PrintWriter stdinWriter;
private SB sbRet;
- private String nboAction;
private boolean inData;
protected boolean inRequest, isWorking;
@@ -144,17 +144,20 @@
closeProcess();
startProcess(nboSync);
}
- nboMode = ((Integer) info.get("mode")).intValue();
+ serverMode = ((Integer) info.get("mode")).intValue();
if (stdinWriter == null) {
closeProcess();
sbRet
.append("ERROR: Could not connect to NBOServe -- Use Tools...NBO...
to set up NBOServe");
- nboMode = 0;
+ serverMode = MODE_ERR;
}
- nboAction = (String) info.get("action");
+ String nboAction = (String) info.get("action");
+ if (nboAction == null)
+ System.out.println("HOH");
String s;
- switch (nboMode) {
+ switch (serverMode) {
case MODE_MODEL:
+ // from Jmol script, not dialog
s = (String) info.get("value");
if (nboAction.equals("load")) {
s = "sh " + s;
@@ -173,7 +176,7 @@
break;
}
if (s != null) {
- sendToNBO(nboMode, s);
+ sendToNBO(serverMode, s);
if (nboSync) {
try {
nboServer.waitFor();
@@ -195,47 +198,55 @@
* @param s
*/
private void sendToNBO(int mode, String s) {
- s = (mode == MODE_RAW ? s : mode + "\n" + s + "\nexit"
- + (nboSync ? "\nexit" : ""));
+ s = (mode == MODE_RAW ? s : mode + "\r\n" + s + "\r\n"
+ + (nboSync ? "x\r\n" : ""));
sendCmd(s);
}
private void sendCmd(String s) {
- //vwr.log("sending:\n>>>\n" + s + "\n<<<");
- stdinWriter.println(s);
- stdinWriter.flush();
+ try {
+ stdinWriter.println(s);
+ stdinWriter.flush();
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ // TODO
+ }
}
protected void nboReport(String line) {
- if (Logger.debugging)
- Logger.debug(inData + " " + nboSync + " " + sbRet.length() + " " +
"receiving: " + line);
- if (line.startsWith("DATA ")) {
- if (line.startsWith("DATA \"model")) {
- sbRet.setLength(0);
- nboModel = PT.getQuotedStringAt(line, 0);
- line += " NBO " + nboModel;
- }
- inData = (line.indexOf("exit") < 0);
- if (inData)
- sbRet.append(line + "\n");
- return;
- }
- if (!inData && line.indexOf("NBO") < 0 && nboDialog.nboMode == MODE_MODEL)
- nboDialog.appendModelOutPanel(line);
- if (inData) {
- sbRet.append(line + "\n");
- if (line.indexOf("END") >= 0) {
- inData = false;
- String m = "\"" + nboModel + "\"";
- nboModel = "\0";
- if (!nboSync && line.indexOf(m) >= 0) {
- String s = sbRet.toString();
+ if (Logger.debugging)
+ Logger.debug(inData + " " + nboSync + " " + sbRet.length() + " "
+ + "receiving: " + line);
+ if (line.startsWith("DATA \" \"")) {
+ isWorking = false;
+ } else if (line.startsWith("DATA ")) {
+ if (line.startsWith("DATA \"model")) {
sbRet.setLength(0);
- runScriptQueued(s);
+ nboModel = PT.getQuotedStringAt(line, 0);
+ line += " NBO " + nboModel;
}
+ inData = (line.indexOf("exit") < 0);
+ if (inData)
+ sbRet.append(line + "\n");
return;
}
- }
+ if (!inData && line.indexOf("NBO") < 0
+ && nboDialog.dialogMode == MODE_MODEL)
+ nboDialog.appendModelOutPanel(line);
+ if (inData && sbRet != null) {
+ sbRet.append(line + "\n");
+ if (line.indexOf("END") >= 0) {
+ inData = false;
+ String m = "\"" + nboModel + "\"";
+ nboModel = "\0";
+ if (!nboSync && line.indexOf(m) >= 0) {
+ String s = sbRet.toString();
+ sbRet.setLength(0);
+ runScriptQueued(s);
+ }
+ return;
+ }
+ }
if (nboDialog != null)
nboDialog.nboReport(line);
}
@@ -261,16 +272,18 @@
Thread.sleep(10);
while ((line = nboReader.readLine()) != null) {
Logger.info(line);
- switch (nboDialog.nboMode) {
+ switch (nboDialog.dialogMode) {
case MODE_RUN:
if (line.contains("Job"))
isWorking = false;
break;
case MODE_VIEW_4:
- if (nboDialog != null) {
+ if (nboDialog == null) {
+ isWorking = inRequest = false;
+ } else {
if (line.indexOf("1.") > 0)
inRequest = true;
- if (line.startsWith("DATA")) {
+ if (line.startsWith("DATA") || line.startsWith("END")) {
if (inRequest)
isWorking = false;
inRequest = false;
@@ -278,6 +291,8 @@
if (inRequest)
nboDialog.nboViewAddLine(line);
}
+ if (!isWorking)
+ nboDialog.dialogMode = MODE_RAW;
break;
case MODE_SEARCH:
if (nboDialog != null)
@@ -363,59 +378,85 @@
return (nboServer != null);
}
- synchronized void runScriptQueued(String script) {
+ void runScriptQueued(String script) {
Logger.info("NBO->JMOL ASYNC: " + script);
vwr.script(script);
}
+
+ private Object lock = "";
synchronized String runScriptNow(String script) {
- Logger.info("NBO->JMOL SYNC: " + script);
- return vwr.runScript(script);
+ synchronized (lock) {
+ Logger.info("NBO->JMOL SYNC: " + script);
+ return vwr.runScript(script);
+ }
}
synchronized public SV evaluateJmol(String expr) {
+ synchronized (lock) {
return vwr.evaluateExpressionAsVariable(expr);
+ }
}
synchronized public String evaluateJmolString(String expr) {
+ synchronized (lock) {
return evaluateJmol(expr).asString();
+ }
}
synchronized public String getJmolFilename() {
+ synchronized (lock) {
return evaluateJmolString("getProperty('filename')");
+ }
}
- protected void rawCmdNew(String mode, SB data, boolean doWait) {
- String fname = mode + "_test.txt";
- File cmdFile = new File(new File(serverPath).getParent() + "/" + fname);
- try {
- Logger.info("issuing " + fname + "\n" + data);
- writeToFile(data.toString(), cmdFile);
- isWorking = doWait;
- rawCmd("<" + fname + ">");
- if (doWait) {
- while (isWorking) {
- Thread.sleep(10);
- restartIfNecessary();
+ private Object nbo = "";
+
+
+ protected void rawCmdNew(String cmd, SB data, boolean doWait) {
+ synchronized (nbo) {
+ String fname = null;
+ File cmdFile = null;
+ try {
+ if (data == null) {
+ Logger.info("issuing\n" + cmd);
+ } else {
+ fname = cmd + "_test" + System.currentTimeMillis() + ".txt";
+ cmdFile = new File(new File(serverPath).getParent() + "/" + fname);
+ Logger.info("issuing " + fname + "\n" + data);
+ writeToFile(data.toString(), cmdFile);
+ cmd = "<" + fname + ">";
+ isWorking = doWait;
}
+ Map<String, Object> info = new Hashtable<String, Object>();
+ info.put("mode", Integer.valueOf(NBOService.MODE_RAW));
+ info.put("sync", Boolean.FALSE);
+ info.put("action", "cmd");
+ info.put("value", cmd);
+ if (!processRequest(info)) {
+ nboReport(null);
+ nboReport("not implemented");
+ isWorking = false;
+ }
+ if (doWait) {
+ while (isWorking) {
+ Thread.sleep(10);
+ restartIfNecessary();
+ }
+ }
+ if (cmdFile != null) {
+ cmdFile = new File(new File(serverPath).getParent() + "/" + fname +
"DONE");
+ writeToFile("", cmdFile);
+ }
+
+ } catch (IOException e) {
+ System.out.println("Could not write to " + fname);
+ isWorking = false;
+ } catch (InterruptedException e) {
+ isWorking = false;
}
- } catch (IOException e) {
- System.out.println("Could not write to " + fname);
- } catch (InterruptedException e) {
}
-
- }
- void rawCmd(String cmd) {
- Map<String, Object> info = new Hashtable<String, Object>();
- info.put("mode", Integer.valueOf(NBOService.MODE_RAW));
- info.put("sync", Boolean.FALSE);
- info.put("action", "cmd");
- info.put("value", cmd);
- if (!processRequest(info)) {
- nboReport(null);
- nboReport("not implemented");
- }
}
void writeToFile(String s, File file) throws IOException {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits