/trunk/FAHView-viewer/src/main/java/com/googlecode/fahview/viewer/JmolPanel.java

https://gitlab.com/BGCX067/fahview-svn-to-git · Java · 80 lines · 28 code · 8 blank · 44 comment · 0 complexity · f4da03e356a05f58e7d34664370ca5d9 MD5 · raw file

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