View Javadoc

1   package org.lcsim.plugin.conditions;
2   
3   import java.util.Enumeration;
4   import javax.swing.AbstractButton;
5   import org.freehep.swing.wizard.Finishable;
6   import org.freehep.swing.wizard.HasNextPages;
7   import org.freehep.swing.wizard.WizardPage;
8   import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
9   import org.lcsim.conditions.ConditionsReader;
10  
11  /**
12   *
13   * @author tonyj
14   */
15  class ConditionsWizardPage extends WizardPage implements HasNextPages, Finishable
16  {
17     private WizardPage nextPage;
18     private InteractiveConditionsManagerImplementation cm;
19     private final WizardPage[] pages;
20     private String detectorName;
21     private boolean hepRepPluginInstalled;
22     /** Creates new form ConditionsWizardPanel */
23     ConditionsWizardPage(InteractiveConditionsManagerImplementation cm, String detectorName)
24     {
25        this.cm = cm;
26        this.detectorName = detectorName;
27        try
28        {
29           Class.forName("hep.graphics.heprep.HepRep");
30           hepRepPluginInstalled = true;
31        }
32        catch (Exception x)
33        {
34           hepRepPluginInstalled = false;
35        }
36        pages = hepRepPluginInstalled ? new WizardPage[]{ new ConditionsAliasWizardPage(this) , new HepRepSelectWizardPage(this) } : new WizardPage[]{ new ConditionsAliasWizardPage(this) };
37        initComponents();
38        detectorLabel.setText(detectorName);
39        setNextEnabled(false);
40        setFinishEnabled(false);
41        String lastSelected = cm.getStudio().getUserProperties().getProperty(getClass().getName()+".lastSelected");
42        if (lastSelected != null) 
43        {
44           Enumeration e = buttonGroup1.getElements();
45           while (e.hasMoreElements())
46           {
47              AbstractButton button = (AbstractButton) e.nextElement();
48              if (lastSelected.equals(button.getActionCommand())) 
49              {
50                  button.setSelected(true);
51                  setSelectedButton(button);
52              }
53           }
54        }
55     }
56     
57     public WizardPage getNext()
58     {
59        return nextPage;
60     }
61     public WizardPage[] getNextWizardPages()
62     {
63        return pages;
64     }
65     
66     public void onFinish()
67     {
68        if (noDetectorButton.isSelected())
69        {
70           cm.setConditionsReader(ConditionsReader.createDummy(),detectorName);
71           cm.setDetectorFound(true);
72        }
73        cm.getStudio().getUserProperties().setProperty(getClass().getName()+".lastSelected",buttonGroup1.getSelection().getActionCommand());
74        dispose();
75     }
76     void addAlias(String name) throws ConditionsNotFoundException
77     {
78        cm.addAlias(detectorName,name);
79        cm.setDetectorFound(true);
80     }
81     
82     /** This method is called from within the constructor to
83      * initialize the form.
84      * WARNING: Do NOT modify this code. The content of this method is
85      * always regenerated by the Form Editor.
86      */
87     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
88     private void initComponents()
89     {
90        java.awt.GridBagConstraints gridBagConstraints;
91        javax.swing.JLabel jLabel1;
92        javax.swing.JLabel jLabel3;
93  
94        buttonGroup1 = new javax.swing.ButtonGroup();
95        jLabel1 = new javax.swing.JLabel();
96        detectorLabel = new javax.swing.JLabel();
97        jLabel3 = new javax.swing.JLabel();
98        aliasButton = new javax.swing.JRadioButton();
99        locateButton = new javax.swing.JRadioButton();
100       heprepButton = new javax.swing.JRadioButton();
101       noDetectorButton = new javax.swing.JRadioButton();
102 
103       setLayout(new java.awt.GridBagLayout());
104 
105       setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
106       jLabel1.setText("Sorry, no information could be found on the following detector:");
107       gridBagConstraints = new java.awt.GridBagConstraints();
108       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
109       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110       add(jLabel1, gridBagConstraints);
111 
112       detectorLabel.setText("jLabel2");
113       gridBagConstraints = new java.awt.GridBagConstraints();
114       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
115       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116       gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
117       add(detectorLabel, gridBagConstraints);
118 
119       jLabel3.setText("Please choose one of the following");
120       gridBagConstraints = new java.awt.GridBagConstraints();
121       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
122       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
123       gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
124       add(jLabel3, gridBagConstraints);
125 
126       buttonGroup1.add(aliasButton);
127       aliasButton.setMnemonic('A');
128       aliasButton.setText("Alias this detector to an existing detector");
129       aliasButton.setActionCommand("alias");
130       aliasButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
131       aliasButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
132       aliasButton.addActionListener(new java.awt.event.ActionListener()
133       {
134          public void actionPerformed(java.awt.event.ActionEvent evt)
135          {
136             radioButtonSelected(evt);
137          }
138       });
139 
140       gridBagConstraints = new java.awt.GridBagConstraints();
141       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
143       gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
144       add(aliasButton, gridBagConstraints);
145 
146       buttonGroup1.add(locateButton);
147       locateButton.setMnemonic('G');
148       locateButton.setText("Give location of a conditions database for this detector (not yet implemented)");
149       locateButton.setActionCommand("give");
150       locateButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
151       locateButton.setEnabled(false);
152       locateButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
153       locateButton.addActionListener(new java.awt.event.ActionListener()
154       {
155          public void actionPerformed(java.awt.event.ActionEvent evt)
156          {
157             radioButtonSelected(evt);
158          }
159       });
160 
161       gridBagConstraints = new java.awt.GridBagConstraints();
162       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
163       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
164       gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
165       add(locateButton, gridBagConstraints);
166 
167       buttonGroup1.add(heprepButton);
168       heprepButton.setMnemonic('H');
169       heprepButton.setText("Give location of a HepRep file for this detector");
170       heprepButton.setActionCommand("heprep");
171       heprepButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
172       heprepButton.setEnabled(hepRepPluginInstalled);
173       heprepButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
174       heprepButton.addActionListener(new java.awt.event.ActionListener()
175       {
176          public void actionPerformed(java.awt.event.ActionEvent evt)
177          {
178             radioButtonSelected(evt);
179          }
180       });
181 
182       gridBagConstraints = new java.awt.GridBagConstraints();
183       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
184       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185       gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
186       add(heprepButton, gridBagConstraints);
187 
188       buttonGroup1.add(noDetectorButton);
189       noDetectorButton.setMnemonic('P');
190       noDetectorButton.setText("Proceed with no detector information (limited functionality)");
191       noDetectorButton.setActionCommand("proceed");
192       noDetectorButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
193       noDetectorButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
194       noDetectorButton.addActionListener(new java.awt.event.ActionListener()
195       {
196          public void actionPerformed(java.awt.event.ActionEvent evt)
197          {
198             radioButtonSelected(evt);
199          }
200       });
201 
202       gridBagConstraints = new java.awt.GridBagConstraints();
203       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
204       gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
205       gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 0);
206       add(noDetectorButton, gridBagConstraints);
207 
208    }// </editor-fold>//GEN-END:initComponents
209 
210    private void radioButtonSelected(java.awt.event.ActionEvent evt)//GEN-FIRST:event_radioButtonSelected
211    {//GEN-HEADEREND:event_radioButtonSelected
212       setSelectedButton(evt.getSource());
213    }
214    private void setSelectedButton(Object button)
215    {
216       WizardPage next = null;
217       if (button == aliasButton) next = pages[0];
218       else if (button == heprepButton) next = pages[1];
219       nextPage = next;
220       setNextEnabled(next != null);
221       setFinishEnabled(next == null);
222    }//GEN-LAST:event_radioButtonSelected
223 
224    String getDetectorName()
225    {
226       return detectorName;
227    }
228 
229    InteractiveConditionsManagerImplementation getConditionsManager()
230    {
231       return cm;
232    }
233 
234    
235    
236    // Variables declaration - do not modify//GEN-BEGIN:variables
237    private javax.swing.JRadioButton aliasButton;
238    private javax.swing.ButtonGroup buttonGroup1;
239    private javax.swing.JLabel detectorLabel;
240    private javax.swing.JRadioButton heprepButton;
241    private javax.swing.JRadioButton locateButton;
242    private javax.swing.JRadioButton noDetectorButton;
243    // End of variables declaration//GEN-END:variables
244    
245 }