1 package info.mikethomas.fahview.viewer;
2
3 /*
4 * #%L
5 * This file is part of FAHView-viewer.
6 * %%
7 * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com>
8 * %%
9 * FAHView is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 * %
14 * FAHView is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * %
19 * You should have received a copy of the GNU General Public License
20 * along with FAHView. If not, see <http://www.gnu.org/licenses/>.
21 * #L%
22 */
23
24 import java.awt.Dimension;
25 import java.awt.Graphics;
26 import java.awt.Rectangle;
27 import javax.swing.JPanel;
28 import org.jmol.adapter.smarter.SmarterJmolAdapter;
29 import org.jmol.api.JmolViewer;
30
31 /**
32 * Class to embed Jmol 3D Molecule Viewer into FAHView.
33 *
34 * @see <a href="http://wiki.jmol.org/index.php/Applications_Embedding_Jmol">
35 * Jmol Wiki - Applications Embedding</a>
36 * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
37 * @version $Id: $Id
38 */
39 public class JmolPanel extends JPanel {
40
41 private JmolViewer viewer;
42 private final Dimension currentSize = new Dimension();
43 private final Rectangle rectClip = new Rectangle(); // ignored by Jmol
44
45 /**
46 * Constructor to initialize JmolPanel
47 */
48 public JmolPanel() {
49 setViewer();
50 }
51
52 /**
53 * Set the JPanel to the Jmol viewer
54 */
55 private void setViewer() {
56 viewer = JmolViewer.allocateViewer(this, new SmarterJmolAdapter());
57 }
58
59 /**
60 * Get the Jmol viewer
61 *
62 * @return a {@link org.jmol.api.JmolViewer} object.
63 */
64 public JmolViewer getViewer()
65 {
66 return viewer;
67 }
68
69 /**
70 * {@inheritDoc}
71 *
72 * Override paint to allow Jmol to refresh
73 */
74 @Override
75 public void paint(Graphics g) {
76 getSize(currentSize);
77 g.getClipBounds(rectClip);
78 viewer.renderScreenImage(g, currentSize, rectClip);
79 }
80 }