View Javadoc
1   package info.mikethomas.fahview.viewer.files.xyz;
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 info.mikethomas.fahview.viewer.JmolPanel;
25  import javax.swing.Action;
26  import javax.swing.JComponent;
27  import javax.swing.JToolBar;
28  import org.netbeans.core.spi.multiview.CloseOperationState;
29  import org.netbeans.core.spi.multiview.MultiViewElement;
30  import org.netbeans.core.spi.multiview.MultiViewElementCallback;
31  import org.openide.awt.UndoRedo;
32  import org.openide.util.Lookup;
33  import org.openide.util.NbBundle.Messages;
34  import org.openide.windows.TopComponent;
35  
36  /**
37   * <p>XyzFileVisualElement class.</p>
38   *
39   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
40   * @version $Id: $Id
41   */
42  @MultiViewElement.Registration(
43          displayName = "#LBL_XyzFile_VISUAL",
44          iconBase = "info/mikethomas/fahview/viewer/files/xyz/XyzFile.png",
45          mimeType = "model/x-xyz",
46          persistenceType = TopComponent.PERSISTENCE_NEVER,
47          preferredID = "XyzFileVisual",
48          position = 2000)
49  @Messages("LBL_XyzFile_VISUAL=Visual")
50  public final class XyzFileVisualElement extends JmolPanel implements MultiViewElement {
51  
52      private XyzFileDataObject obj;
53      private JToolBar toolbar = new JToolBar();
54      private transient MultiViewElementCallback callback;
55  
56      /**
57       * <p>Constructor for XyzFileVisualElement.</p>
58       *
59       * @param lkp a {@link org.openide.util.Lookup} object.
60       */
61      public XyzFileVisualElement(Lookup lkp) {
62          obj = lkp.lookup(XyzFileDataObject.class);
63          assert obj != null;
64          initComponents();
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public String getName() {
70          return "XyzFileVisualElement";
71      }
72  
73      /**
74       * This method is called from within the constructor to initialize the form.
75       * WARNING: Do NOT modify this code. The content of this method is always
76       * regenerated by the Form Editor.
77       */
78      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
79      private void initComponents() {
80  
81          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
82          this.setLayout(layout);
83          layout.setHorizontalGroup(
84              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
85              .addGap(0, 400, Short.MAX_VALUE)
86          );
87          layout.setVerticalGroup(
88              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89              .addGap(0, 300, Short.MAX_VALUE)
90          );
91      }// </editor-fold>//GEN-END:initComponents
92  
93      // Variables declaration - do not modify//GEN-BEGIN:variables
94      // End of variables declaration//GEN-END:variables
95      /** {@inheritDoc} */
96      @Override
97      public JComponent getVisualRepresentation() {
98          return this;
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public JComponent getToolbarRepresentation() {
104         return toolbar;
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public Action[] getActions() {
110         return new Action[0];
111     }
112 
113     /** {@inheritDoc} */
114     @Override
115     public Lookup getLookup() {
116         return obj.getLookup();
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     public void componentOpened() {
122         // Set model and get info
123         getViewer().openFile(obj.getPrimaryFile().getPath());
124 //        System.out.println(getViewer().getProperty("readable", "modelInfo", null));
125 //        System.out.println(getViewer().getProperty("readable", "auxiliaryInfo", null));
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     public void componentClosed() {
131     }
132 
133     /** {@inheritDoc} */
134     @Override
135     public void componentShowing() {
136     }
137 
138     /** {@inheritDoc} */
139     @Override
140     public void componentHidden() {
141     }
142 
143     /** {@inheritDoc} */
144     @Override
145     public void componentActivated() {
146     }
147 
148     /** {@inheritDoc} */
149     @Override
150     public void componentDeactivated() {
151     }
152 
153     /** {@inheritDoc} */
154     @Override
155     public UndoRedo getUndoRedo() {
156         return UndoRedo.NONE;
157     }
158 
159     /** {@inheritDoc} */
160     @Override
161     public void setMultiViewCallback(MultiViewElementCallback callback) {
162         this.callback = callback;
163     }
164 
165     /** {@inheritDoc} */
166     @Override
167     public CloseOperationState canCloseElement() {
168         return CloseOperationState.STATE_OK;
169     }
170 }