Tomas, you are absolutely correct. You are trying to create a model before
the frame is defined. That's just not possible, and if it was in some
distant past, it shouldn't have been. Here's (in my mind) a more logical
construction of events. In this way there is no model during construction,
and the repaint is not fired until after Test() is initialized. There were
some changes between 11.6 and 11.8 which relate to this, but I would argue
it's not a bug.
package org.jmol;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jmol.adapter.smarter.SmarterJmolAdapter;
import org.jmol.api.JmolAdapter;
import org.jmol.api.JmolViewer;
public class Test extends JPanel {
// Main application
public static void main(String[] args) {
(new Test()).viewer.loadInline(strXyzHOH);
}
public Test() {
adapter = new SmarterJmolAdapter();
viewer = JmolViewer.allocateViewer(this, adapter);
JFrame newFrame = new JFrame();
newFrame.getContentPane().add(this);
newFrame.setSize(300, 300);
newFrame.setVisible(true);
}
private final static String strXyzHOH = "3\nwater\nO 0.0 0.0 0.0\n"
+ "H 0.76923955 -0.59357141 0.0\n" + "H -0.76923955 -0.59357141
0.0\n";
private JmolViewer viewer;
private JmolAdapter adapter;
private Dimension currentSize = new Dimension();
private Rectangle rectClip = new Rectangle();
public void paint(Graphics g) {
getSize(currentSize);
g.getClipBounds(rectClip);
viewer.renderScreenImage(g, currentSize, rectClip);
}
}
On Wed, Dec 9, 2009 at 12:09 AM, Tomas Pluskal <[email protected]> wrote:
> Hi to all Jmol developers!
>
>
> We are using Jmol for an embedded visualization component in our
> MZmine software (http://mzmine.sourceforge.net/).
> I found that our visualization component works well with Jmol 11.6,
> but when I upgraded to Jmol 11.8.12, it stopped working.
> I searched a bit and I found the problem happens when we call
> JmolViewer.loadInline() in the component constructor.
>
> I made the following minimalistic example demonstrating the problem
> (works well with Jmol 11.6, but freezes with Jmol 11.8):
>
> ===============================================
>
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.Rectangle;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import org.jmol.adapter.smarter.SmarterJmolAdapter;
> import org.jmol.api.JmolAdapter;
> import org.jmol.api.JmolViewer;
>
> public class Test extends JPanel {
>
> // Main application
> public static void main(String[] args) {
> JFrame newFrame = new JFrame();
> Test testComponent = new Test();
> newFrame.getContentPane().add(testComponent);
> newFrame.setSize(300, 300);
> newFrame.setVisible(true);
> }
>
> final static String strXyzHOH = "3\nwater\nO 0.0 0.0 0.0\n"
> + "H 0.76923955 -0.59357141 0.0\n"
> + "H -0.76923955 -0.59357141 0.0\n";
>
> JmolViewer viewer;
> JmolAdapter adapter;
> Dimension currentSize = new Dimension();
> Rectangle rectClip = new Rectangle();
>
> public Test() {
> adapter = new SmarterJmolAdapter();
> viewer = JmolViewer.allocateViewer(this, adapter);
> viewer.loadInline(strXyzHOH);
> }
>
> public void paint(Graphics g) {
> getSize(currentSize);
> g.getClipBounds(rectClip);
> viewer.renderScreenImage(g, currentSize, rectClip);
> }
>
> }
>
> ===============================================
>
>
> The problem seems to be that when we call the viewer.loadInline(), the
> thread hangs (deadlocks?) in the RepaintManager class waiting for the
> repaint to be finished, but the repaint is never finished because the
> component is just being constructed.
>
> Is there anything wrong with my way of creating the JmolViewer?
> Why it worked in 11.6 but not in 11.8?
>
> Thanks a lot for any advice!
>
> Best regards,
>
> Tomas
>
>
>
> ===============================================
> Tomas Pluskal
> G0 Cell Unit, Okinawa Institute of Science and Technology
> 12-22 Suzaki, Uruma-shi, Okinawa 904-2234, JAPAN
> TEL: +81-98-921-3966
>
>
>
>
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> Jmol-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
>
--
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107
If nature does not answer first what we want,
it is better to take what answer we get.
-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers