OK, sounds like you are all set. Right. If you don't use
allocateSimpleViewer() or allocateViewer(), then the viewer is not fully
initialized. In particular, there is no modelSet yet, and if you try to
right-click or just about any click, I think, it will barf up that
exception. The allocate[Simple]Viewer() method also does a zap() to create
an empty modelSet. In cases where the very next thing is the loading of a
model, you can almost get away with it, but it's still a possibility that
the user will click on the window too soon. Sounds like you are all set.
Such problems will arise if you use the "public" methods of Viewer directly.
That is not recommended for exactly this reason. So if you stick to
JmolViewer or SimpleJmolViewer methods, those are the real "public" ones.
The others are "public" only in the sense that other packages need them.
It's a deficiency of Java that there isn't something intermediate between
"public for use by all applications" and "public for access by methods in
other Jmol packages." The appellations "private" and "protected" just don't
do the job.
In the case that you feel you need one of the Viewer methods that are not
part of JmolViewer or SimpleJmolViewer, please let me know, and I will add
the method to JmolViewer.
What does
o_O
mean?
Bob
On Mon, Oct 5, 2009 at 11:21 AM, Vincent Le Guilloux <
[email protected]> wrote:
> I also have a version of the panel that makes use of SimpleViewer.
>
> And now it's working o_O, I have the popup menu triggered at right
> clic. Here is the code:
>
> public class JmolPanel extends JPanel
> {
> private static final long serialVersionUID = -3661941083797644242L;
>
> private JmolSimpleViewer viewer;
> private JmolAdapter adapter;
>
> public JmolPanel() {
> adapter = new SmarterJmolAdapter();
> viewer = JmolSimpleViewer.allocateSimpleViewer(this, adapter);
> }
>
> public JmolSimpleViewer getViewer() {
> return viewer;
> }
>
> public void executeCmd(String rasmolScript) {
> viewer.evalString(rasmolScript);
> }
>
> public void setStructure(Structure s)
> {
> String pdb = s.toPDB();
> viewer.openStringInline(pdb);
> }
>
> final Dimension currentSize = new Dimension();
> final Rectangle rectClip = new Rectangle();
>
> @Override
> public void paint(Graphics g) {
> getSize(currentSize);
> g.getClipBounds(rectClip);
> viewer.renderScreenImage(g, currentSize, rectClip);
> }
> }
>
> I'm quite dubitative though, I don't understand why it didn't worked
> previously as it was the first tryout, and I think it was quite the
> same piece of code...
>
> Anyway, the previous code that makes use of the Viewer class directly
> is not working cauz there is a nullpointerException thrown when right
> clicking on the panel:
>
> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
> at org.jmol.viewer.Viewer.getSelectionHaloEnabled(Unknown Source)
> at org.jmol.viewer.Viewer.getBooleanProperty(Unknown Source)
> at org.jmol.viewer.Viewer.getBooleanProperty(Unknown Source)
> at org.jmol.popup.JmolPopup.show(Unknown Source)
> at org.jmol.viewer.Viewer.popupMenu(Unknown Source)
> at org.jmol.viewer.MouseManager.mousePressed(Unknown Source)
> at org.jmol.viewer.MouseManager11.mousePressed(Unknown Source)
>
> Anyway, I think I have what I need for the moment, thank you very much
> for your help. No doubt I will come back soon for more information on
> customizing all these stuffs :)
>
> Thanks again.
> Vincent.
>
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9-12, 2009. Register now!
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
--
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
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users